mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 15:10:48 +01:00
use control reply lines for protocolinfo
Simplify handle_control_protocolinfo() by using the new reply line abstraction. Part of #30984.
This commit is contained in:
parent
2143bae6c4
commit
a08f43ba04
1 changed files with 17 additions and 9 deletions
|
@ -1285,17 +1285,19 @@ get_esc_cfile(const or_options_t *options)
|
||||||
return esc_cfile;
|
return esc_cfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send the auth methods lines of a PROTOCOLINFO reply. */
|
/** Compose the auth methods line of a PROTOCOLINFO reply. */
|
||||||
static void
|
static void
|
||||||
send_authmethods(control_connection_t *conn)
|
add_authmethods(smartlist_t *reply)
|
||||||
{
|
{
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
char *methods = get_authmethods(options);
|
char *methods = get_authmethods(options);
|
||||||
char *esc_cfile = get_esc_cfile(options);
|
char *esc_cfile = get_esc_cfile(options);
|
||||||
|
|
||||||
control_printf_midreply(conn, 250, "AUTH METHODS=%s%s%s", methods,
|
control_reply_add_str(reply, 250, "AUTH");
|
||||||
esc_cfile ? " COOKIEFILE=" : "",
|
control_reply_append_kv(reply, "METHODS", methods);
|
||||||
esc_cfile ? esc_cfile : "");
|
if (esc_cfile)
|
||||||
|
control_reply_append_kv(reply, "COOKIEFILE", esc_cfile);
|
||||||
|
|
||||||
tor_free(methods);
|
tor_free(methods);
|
||||||
tor_free(esc_cfile);
|
tor_free(esc_cfile);
|
||||||
}
|
}
|
||||||
|
@ -1307,6 +1309,7 @@ handle_control_protocolinfo(control_connection_t *conn,
|
||||||
{
|
{
|
||||||
const char *bad_arg = NULL;
|
const char *bad_arg = NULL;
|
||||||
const smartlist_t *args = cmd_args->args;
|
const smartlist_t *args = cmd_args->args;
|
||||||
|
smartlist_t *reply = NULL;
|
||||||
|
|
||||||
conn->have_sent_protocolinfo = 1;
|
conn->have_sent_protocolinfo = 1;
|
||||||
|
|
||||||
|
@ -1326,10 +1329,15 @@ handle_control_protocolinfo(control_connection_t *conn,
|
||||||
connection_mark_for_close(TO_CONN(conn));
|
connection_mark_for_close(TO_CONN(conn));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
control_write_midreply(conn, 250, "PROTOCOLINFO 1");
|
reply = smartlist_new();
|
||||||
send_authmethods(conn);
|
control_reply_add_str(reply, 250, "PROTOCOLINFO 1");
|
||||||
control_printf_midreply(conn, 250, "VERSION Tor=%s", escaped(VERSION));
|
add_authmethods(reply);
|
||||||
send_control_done(conn);
|
control_reply_add_str(reply, 250, "VERSION");
|
||||||
|
control_reply_append_kv(reply, "Tor", escaped(VERSION));
|
||||||
|
control_reply_add_done(reply);
|
||||||
|
|
||||||
|
control_write_reply_lines(conn, reply);
|
||||||
|
control_reply_free(reply);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue