From 00b2b69add373f168e8729e99f349ec5a3753db3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 11 Oct 2011 11:21:31 -0400 Subject: Fix names of functions that convert strings to addrs Now let's have "lookup" indicate that there can be a hostname resolution, and "parse" indicate that there wasn't. Previously, we had one "lookup" function that did resolution; four "parse" functions, half of which did resolution; and a "from_str()" function that didn't do resolution. That's confusing and error-prone! The code changes in this commit are exactly the result of this perl script, run under "perl -p -i.bak" : s/tor_addr_port_parse/tor_addr_port_lookup/g; s/parse_addr_port(?=[^_])/addr_port_lookup/g; s/tor_addr_from_str/tor_addr_parse/g; This patch leaves aton and pton alone: their naming convention and behavior is is determined by the sockets API. More renaming may be needed. --- src/or/circuituse.c | 4 ++-- src/or/config.c | 32 ++++++++++++++++---------------- src/or/connection.c | 4 ++-- src/or/connection_edge.c | 6 +++--- src/or/dirserv.c | 2 +- src/or/dns.c | 4 ++-- src/or/rendservice.c | 2 +- src/or/routerparse.c | 6 +++--- src/or/transports.c | 4 ++-- 9 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/or') diff --git a/src/or/circuituse.c b/src/or/circuituse.c index 9b9621890f..23efe05348 100644 --- a/src/or/circuituse.c +++ b/src/or/circuituse.c @@ -117,7 +117,7 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ, if (tor_digest_is_zero(digest)) { /* we don't know the digest; have to compare addr:port */ tor_addr_t addr; - int r = tor_addr_from_str(&addr, conn->socks_request->address); + int r = tor_addr_parse(&addr, conn->socks_request->address); if (r < 0 || !tor_addr_eq(&build_state->chosen_exit->addr, &addr) || build_state->chosen_exit->port != conn->socks_request->port) @@ -1454,7 +1454,7 @@ circuit_get_open_circ_or_launch(entry_connection_t *conn, log_info(LD_DIR, "Broken exit digest on tunnel conn. Closing."); return -1; } - if (tor_addr_from_str(&addr, conn->socks_request->address) < 0) { + if (tor_addr_parse(&addr, conn->socks_request->address) < 0) { log_info(LD_DIR, "Broken address %s on tunnel conn. Closing.", escaped_safe_str_client(conn->socks_request->address)); return -1; diff --git a/src/or/config.c b/src/or/config.c index e72630d4df..388c45f5cf 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -2877,7 +2877,7 @@ is_listening_on_low_port(int port_option, return (port_option < 1024); for (l = listen_options; l; l = l->next) { - parse_addr_port(LOG_WARN, l->value, NULL, NULL, &p); + addr_port_lookup(LOG_WARN, l->value, NULL, NULL, &p); if (p<1024) { return 1; } @@ -3573,7 +3573,7 @@ options_validate(or_options_t *old_options, or_options_t *options, REJECT("Failed to parse accounting options. See logs for details."); if (options->HTTPProxy) { /* parse it now */ - if (tor_addr_port_parse(options->HTTPProxy, + if (tor_addr_port_lookup(options->HTTPProxy, &options->HTTPProxyAddr, &options->HTTPProxyPort) < 0) REJECT("HTTPProxy failed to parse or resolve. Please fix."); if (options->HTTPProxyPort == 0) { /* give it a default */ @@ -3587,7 +3587,7 @@ options_validate(or_options_t *old_options, or_options_t *options, } if (options->HTTPSProxy) { /* parse it now */ - if (tor_addr_port_parse(options->HTTPSProxy, + if (tor_addr_port_lookup(options->HTTPSProxy, &options->HTTPSProxyAddr, &options->HTTPSProxyPort) <0) REJECT("HTTPSProxy failed to parse or resolve. Please fix."); if (options->HTTPSProxyPort == 0) { /* give it a default */ @@ -3601,7 +3601,7 @@ options_validate(or_options_t *old_options, or_options_t *options, } if (options->Socks4Proxy) { /* parse it now */ - if (tor_addr_port_parse(options->Socks4Proxy, + if (tor_addr_port_lookup(options->Socks4Proxy, &options->Socks4ProxyAddr, &options->Socks4ProxyPort) <0) REJECT("Socks4Proxy failed to parse or resolve. Please fix."); @@ -3611,7 +3611,7 @@ options_validate(or_options_t *old_options, or_options_t *options, } if (options->Socks5Proxy) { /* parse it now */ - if (tor_addr_port_parse(options->Socks5Proxy, + if (tor_addr_port_lookup(options->Socks5Proxy, &options->Socks5ProxyAddr, &options->Socks5ProxyPort) <0) REJECT("Socks5Proxy failed to parse or resolve. Please fix."); @@ -4684,7 +4684,7 @@ parse_bridge_line(const char *line, int validate_only) addrport = field1; } - if (tor_addr_port_parse(addrport, &addr, &port)<0) { + if (tor_addr_port_lookup(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing Bridge address '%s'", addrport); goto err; } @@ -4827,7 +4827,7 @@ parse_client_transport_line(const char *line, int validate_only) addrport = smartlist_get(items, 2); - if (tor_addr_port_parse(addrport, &addr, &port)<0) { + if (tor_addr_port_lookup(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing transport " "address '%s'", addrport); goto err; @@ -4948,7 +4948,7 @@ parse_server_transport_line(const char *line, int validate_only) addrport = smartlist_get(items, 2); - if (tor_addr_port_parse(addrport, &addr, &port)<0) { + if (tor_addr_port_lookup(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing transport " "address '%s'", addrport); goto err; @@ -5060,7 +5060,7 @@ parse_dir_server_line(const char *line, dirinfo_type_t required_type, } addrport = smartlist_get(items, 0); smartlist_del_keeporder(items, 0); - if (parse_addr_port(LOG_WARN, addrport, &address, NULL, &dir_port)<0) { + if (addr_port_lookup(LOG_WARN, addrport, &address, NULL, &dir_port)<0) { log_warn(LD_CONFIG, "Error parsing DirServer address '%s'", addrport); goto err; } @@ -5228,7 +5228,7 @@ parse_client_port_config(smartlist_t *out, for (; listenaddrs; listenaddrs = listenaddrs->next) { tor_addr_t addr; uint16_t port = 0; - if (tor_addr_port_parse(listenaddrs->value, &addr, &port) < 0) { + if (tor_addr_port_lookup(listenaddrs->value, &addr, &port) < 0) { log_warn(LD_CONFIG, "Unable to parse %sListenAddress '%s'", portname, listenaddrs->value); return -1; @@ -5256,7 +5256,7 @@ parse_client_port_config(smartlist_t *out, port_cfg_t *cfg = tor_malloc_zero(sizeof(port_cfg_t)); cfg->type = listener_type; cfg->port = defaultport; - tor_addr_from_str(&cfg->addr, defaultaddr); + tor_addr_parse(&cfg->addr, defaultaddr); cfg->session_group = SESSION_GROUP_UNSET; cfg->isolation_flags = ISO_DEFAULT; smartlist_add(out, cfg); @@ -5294,11 +5294,11 @@ parse_client_port_config(smartlist_t *out, addrport = smartlist_get(elts, 0); if (!strcmp(addrport, "auto")) { port = CFG_AUTO_PORT; - tor_addr_from_str(&addr, defaultaddr); + tor_addr_parse(&addr, defaultaddr); } else if (!strcasecmpend(addrport, ":auto")) { char *addrtmp = tor_strndup(addrport, strlen(addrport)-5); port = CFG_AUTO_PORT; - if (tor_addr_port_parse(addrtmp, &addr, &ptmp)<0 || ptmp) { + if (tor_addr_port_lookup(addrtmp, &addr, &ptmp)<0 || ptmp) { log_warn(LD_CONFIG, "Invalid address '%s' for %sPort", escaped(addrport), portname); tor_free(addrtmp); @@ -5309,8 +5309,8 @@ parse_client_port_config(smartlist_t *out, "9050" might be a valid address. */ port = (int) tor_parse_long(addrport, 10, 0, 65535, &ok, NULL); if (ok) { - tor_addr_from_str(&addr, defaultaddr); - } else if (tor_addr_port_parse(addrport, &addr, &ptmp) == 0) { + tor_addr_parse(&addr, defaultaddr); + } else if (tor_addr_port_lookup(addrport, &addr, &ptmp) == 0) { if (ptmp == 0) { log_warn(LD_CONFIG, "%sPort line has address but no port", portname); goto err; @@ -5946,7 +5946,7 @@ state_transport_line_is_valid(const char *line) } addrport = smartlist_get(items, 1); - if (tor_addr_port_parse(addrport, &addr, &port) < 0) { + if (tor_addr_port_lookup(addrport, &addr, &port) < 0) { log_warn(LD_CONFIG, "state: Could not parse addrport."); goto err; } diff --git a/src/or/connection.c b/src/or/connection.c index 2bd2d07e94..af0572905d 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1893,7 +1893,7 @@ retry_listeners(smartlist_t *old_conns, int retval = 0; if (default_addr) { - tor_addr_from_str(&dflt_addr, default_addr); + tor_addr_parse(&dflt_addr, default_addr); } else { tor_addr_make_unspec(&dflt_addr); } @@ -1917,7 +1917,7 @@ retry_listeners(smartlist_t *old_conns, port->is_unix_addr = 1; memcpy(port->unix_addr, c->value, len+1); } else { - if (tor_addr_port_parse(c->value, &addr, &portval) < 0) { + if (tor_addr_port_lookup(c->value, &addr, &portval) < 0) { log_warn(LD_CONFIG, "Can't parse/resolve %s %s", c->key, c->value); retval = -1; diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 40426a9b21..3c19f58a78 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -691,7 +691,7 @@ connection_ap_fail_onehop(const char *failed_digest, if (!build_state || !build_state->chosen_exit || !entry_conn->socks_request || !entry_conn->socks_request->address) continue; - if (tor_addr_from_str(&addr, entry_conn->socks_request->address)<0 || + if (tor_addr_parse(&addr, entry_conn->socks_request->address)<0 || !tor_addr_eq(&build_state->chosen_exit->addr, &addr) || build_state->chosen_exit->port != entry_conn->socks_request->port) continue; @@ -1918,7 +1918,7 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn, if (options->ClientRejectInternalAddresses && !conn->use_begindir && !conn->chosen_exit_name && !circ) { tor_addr_t addr; - if (tor_addr_from_str(&addr, socks->address) >= 0 && + if (tor_addr_parse(&addr, socks->address) >= 0 && tor_addr_is_internal(&addr, 0)) { /* If this is an explicit private address with no chosen exit node, * then we really don't want to try to connect to it. That's @@ -2894,7 +2894,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ) END_STREAM_REASON_TORPROTOCOL, NULL); return 0; } - if (parse_addr_port(LOG_PROTOCOL_WARN, + if (addr_port_lookup(LOG_PROTOCOL_WARN, (char*)(cell->payload+RELAY_HEADER_SIZE), &address,NULL,&port)<0) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, diff --git a/src/or/dirserv.c b/src/or/dirserv.c index d22a0538df..96a5913a57 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -3207,7 +3207,7 @@ dirserv_orconn_tls_done(const char *address, log_info(LD_DIRSERV, "Found router %s to be reachable at %s:%d. Yay.", router_describe(ri), address, ri->or_port); - if (tor_addr_from_str(&addr, ri->address) != -1) + if (tor_addr_parse(&addr, ri->address) != -1) addrp = &addr; else log_warn(LD_BUG, "Couldn't parse IP address \"%s\"", ri->address); diff --git a/src/or/dns.c b/src/or/dns.c index 5d86e81fa0..90dd15fcae 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -687,7 +687,7 @@ dns_resolve_impl(edge_connection_t *exitconn, int is_resolve, /* first check if exitconn->_base.address is an IP. If so, we already * know the answer. */ - if (tor_addr_from_str(&addr, exitconn->_base.address) >= 0) { + if (tor_addr_parse(&addr, exitconn->_base.address) >= 0) { if (tor_addr_family(&addr) == AF_INET) { tor_addr_copy(&exitconn->_base.addr, &addr); exitconn->address_ttl = DEFAULT_DNS_TTL; @@ -1198,7 +1198,7 @@ configure_nameservers(int force) #ifdef HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS if (options->OutboundBindAddress) { tor_addr_t addr; - if (tor_addr_from_str(&addr, options->OutboundBindAddress) < 0) { + if (tor_addr_parse(&addr, options->OutboundBindAddress) < 0) { log_warn(LD_CONFIG,"Outbound bind address '%s' didn't parse. Ignoring.", options->OutboundBindAddress); } else { diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 440359a321..32b4dbb93e 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -258,7 +258,7 @@ parse_port_config(const char *string) } else { addrport = smartlist_get(sl,1); if (strchr(addrport, ':') || strchr(addrport, '.')) { - if (tor_addr_port_parse(addrport, &addr, &p)<0) { + if (tor_addr_port_lookup(addrport, &addr, &p)<0) { log_warn(LD_CONFIG,"Unparseable address in hidden service port " "configuration."); goto err; diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 5c553b81fe..dbd9c934f3 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1812,8 +1812,8 @@ authority_cert_parse_from_string(const char *s, const char **end_of_string) struct in_addr in; char *address = NULL; tor_assert(tok->n_args); - /* XXX023 use tor_addr_port_parse() below instead. -RD */ - if (parse_addr_port(LOG_WARN, tok->args[0], &address, NULL, + /* XXX023 use tor_addr_port_lookup() below instead. -RD */ + if (addr_port_lookup(LOG_WARN, tok->args[0], &address, NULL, &cert->dir_port)<0 || tor_inet_aton(address, &in) == 0) { log_warn(LD_DIR, "Couldn't parse dir-address in certificate"); @@ -4982,7 +4982,7 @@ rend_parse_introduction_points(rend_service_descriptor_t *parsed, info->identity_digest, DIGEST_LEN); /* Parse IP address. */ tok = find_by_keyword(tokens, R_IPO_IP_ADDRESS); - if (tor_addr_from_str(&info->addr, tok->args[0])<0) { + if (tor_addr_parse(&info->addr, tok->args[0])<0) { log_warn(LD_REND, "Could not parse introduction point address."); rend_intro_point_free(intro); goto err; diff --git a/src/or/transports.c b/src/or/transports.c index 3c533ccd95..6e8200f407 100644 --- a/src/or/transports.c +++ b/src/or/transports.c @@ -715,7 +715,7 @@ parse_smethod_line(const char *line, managed_proxy_t *mp) } addrport = smartlist_get(items, 2); - if (tor_addr_port_parse(addrport, &addr, &port)<0) { + if (tor_addr_port_lookup(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing transport " "address '%s'", addrport); goto err; @@ -800,7 +800,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp) } addrport = smartlist_get(items, 3); - if (tor_addr_port_parse(addrport, &addr, &port)<0) { + if (tor_addr_port_lookup(addrport, &addr, &port)<0) { log_warn(LD_CONFIG, "Error parsing transport " "address '%s'", addrport); goto err; -- cgit v1.2.3-54-g00ecf