Re: [PATCH] daemon: use strbuf for hostname info
- From
René Scharfe <l.s.r@web.de>
- Date
- Mar 7, 2015, 00:20 UTC
- Message-ID
- <54FA4446.5050103@web.de>
- In-Reply-To
- <20150306210627.GA24267@peff.net>
Am 06.03.2015 um 22:06 schrieb Jeff King:
Show 21 quoted lines
> On Fri, Mar 06, 2015 at 09:57:22AM +0100, René Scharfe wrote:
>
>> Convert hostname, canon_hostname, ip_address and tcp_port to strbuf.
>> This allows to get rid of the helpers strbuf_addstr_or_null() and STRARG
>> because a strbuf always represents a valid (initially empty) string.
>> sanitize_client() becomes unused and is removed as well.
>
> Makes sense. I had a feeling that we might have cared about NULL versus
> the empty string somewhere, but I did not see it in the patch below, so
> I think it is fine.
>
>> -static char *sanitize_client(const char *in)
>> -{
>> - struct strbuf out = STRBUF_INIT;
>> - sanitize_client_strbuf(&out, in);
>> - return strbuf_detach(&out, NULL);
>> -}
>
> Not a big deal, but do we want to rename sanitize_client_strbuf to
> sanitize_client? It only had the unwieldy name to distinguish it from
> this one.A patch would look like this. The result is shorter, but no win in terms of vertical space (number of lines).
-- >8 -- Subject: daemon: drop _strbuf suffix of sanitize and canonicalize functions
Now that only the strbuf variants of the functions remain, remove the "_strbuf" part from their names.
Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> --- daemon.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/daemon.c b/daemon.c index c04315e..0412f8c 100644 --- a/daemon.c +++ b/daemon.c @@ -534,7 +534,7 @@ static void parse_host_and_port(char *hostport, char **host, * trailing and leading dots, which means that the client cannot escape * our base path via ".." traversal. */ -static void sanitize_client_strbuf(struct strbuf *out, const char *in) +static void sanitize_client(struct strbuf *out, const char *in) { for (; *in; in++) { if (*in == '/') @@ -549,12 +549,12 @@ static void sanitize_client_strbuf(struct strbuf *out, const char *in) } /* - * Like sanitize_client_strbuf, but we also perform any canonicalization + * Like sanitize_client, but we also perform any canonicalization * to make life easier on the admin. */ -static void canonicalize_client_strbuf(struct strbuf *out, const char *in) +static void canonicalize_client(struct strbuf *out, const char *in) { - sanitize_client_strbuf(out, in); + sanitize_client(out, in); strbuf_tolower(out); } @@ -579,10 +579,10 @@ static void parse_host_arg(char *extra_args, int buflen) parse_host_and_port(val, &host, &port); if (port) { strbuf_reset(&tcp_port); - sanitize_client_strbuf(&tcp_port, port); + sanitize_client(&tcp_port, port); } strbuf_reset(&hostname); - canonicalize_client_strbuf(&hostname, host); + canonicalize_client(&hostname, host); hostname_lookup_done = 0; } @@ -620,8 +620,8 @@ static void lookup_hostname(void) strbuf_reset(&canon_hostname); if (ai->ai_canonname) - sanitize_client_strbuf(&canon_hostname, - ai->ai_canonname); + sanitize_client(&canon_hostname, + ai->ai_canonname); else strbuf_addbuf(&canon_hostname, &ip_address); @@ -645,7 +645,7 @@ static void lookup_hostname(void) addrbuf, sizeof(addrbuf)); strbuf_reset(&canon_hostname); - sanitize_client_strbuf(&canon_hostname, hent->h_name); + sanitize_client(&canon_hostname, hent->h_name); strbuf_reset(&ip_address); strbuf_addstr(&ip_address, addrbuf); }
-- 2.3.1