daemon: cleanup: factor out xstrdup_tolower()

Add xstrdup_tolower(), a helper to get a lower case copy of a
string, and use it in two cases.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
René Scharfe 2008-12-26 11:12:15 +01:00 committed by Junio C Hamano
parent a583971f15
commit 6720e95b30
1 changed files with 13 additions and 21 deletions

View File

@ -397,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)
die("No such service %s", name); die("No such service %s", name);
} }


static char *xstrdup_tolower(const char *str)
{
char *p, *dup = xstrdup(str);
for (p = dup; *p; p++)
*p = tolower(*p);
return dup;
}

/* /*
* Separate the "extra args" information as supplied by the client connection. * Separate the "extra args" information as supplied by the client connection.
*/ */
@ -405,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
char *val; char *val;
int vallen; int vallen;
char *end = extra_args + buflen; char *end = extra_args + buflen;
char *hp;


while (extra_args < end && *extra_args) { while (extra_args < end && *extra_args) {
saw_extended_args = 1; saw_extended_args = 1;
@ -423,7 +430,7 @@ static void parse_extra_args(char *extra_args, int buflen)
tcp_port = xstrdup(port); tcp_port = xstrdup(port);
} }
free(hostname); free(hostname);
hostname = xstrdup(host); hostname = xstrdup_tolower(host);
} }


/* On to the next one */ /* On to the next one */
@ -431,20 +438,11 @@ static void parse_extra_args(char *extra_args, int buflen)
} }
} }


/*
* Replace literal host with lowercase-ized hostname.
*/
hp = hostname;
if (!hp)
return;
for ( ; *hp; hp++)
*hp = tolower(*hp);

/* /*
* Locate canonical hostname and its IP address. * Locate canonical hostname and its IP address.
*/ */
if (hostname) {
#ifndef NO_IPV6 #ifndef NO_IPV6
{
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *ai, *ai0; struct addrinfo *ai, *ai0;
int gai; int gai;
@ -468,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
} }
freeaddrinfo(ai0); freeaddrinfo(ai0);
} }
}
#else #else
{
struct hostent *hent; struct hostent *hent;
struct sockaddr_in sa; struct sockaddr_in sa;
char **ap; char **ap;
@ -491,9 +487,9 @@ static void parse_extra_args(char *extra_args, int buflen)
canon_hostname = xstrdup(hent->h_name); canon_hostname = xstrdup(hent->h_name);
free(ip_address); free(ip_address);
ip_address = xstrdup(addrbuf); ip_address = xstrdup(addrbuf);
}
#endif #endif
} }
}




static int execute(struct sockaddr *addr) static int execute(struct sockaddr *addr)
@ -945,11 +941,7 @@ int main(int argc, char **argv)
char *arg = argv[i]; char *arg = argv[i];


if (!prefixcmp(arg, "--listen=")) { if (!prefixcmp(arg, "--listen=")) {
char *p = arg + 9; listen_addr = xstrdup_tolower(arg + 9);
char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
while (*p)
*ph++ = tolower(*p++);
*ph = 0;
continue; continue;
} }
if (!prefixcmp(arg, "--port=")) { if (!prefixcmp(arg, "--port=")) {