--------------------- PatchSet 11696 Date: 2007/09/23 14:24:59 Author: adrian Branch: HEAD Tag: (none) Log: Integrate more of Tim Starling's work towards a udp logging daemon; some framework changes. Members: src/cache_cf.c:1.474->1.475 src/logfile.c:1.25->1.26 src/logfile_mod_udp.c:1.1->1.2 src/protos.h:1.536->1.537 src/tools.c:1.259->1.260 Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid/squid/src/cache_cf.c,v retrieving revision 1.474 retrieving revision 1.475 diff -u -r1.474 -r1.475 --- squid/src/cache_cf.c 18 Sep 2007 14:43:32 -0000 1.474 +++ squid/src/cache_cf.c 23 Sep 2007 14:24:59 -0000 1.475 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.474 2007/09/18 14:43:32 adrian Exp $ + * $Id: cache_cf.c,v 1.475 2007/09/23 14:24:59 adrian Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -2646,37 +2646,10 @@ parse_sockaddr_in_list(sockaddr_in_list ** head) { char *token; - char *t; - char *host; - char *tmp; - const struct hostent *hp; - unsigned short port = 0; sockaddr_in_list *s; while ((token = strtok(NULL, w_space))) { - host = NULL; - port = 0; - if ((t = strchr(token, ':'))) { - /* host:port */ - host = token; - *t = '\0'; - port = xatos(t + 1); - if (0 == port) - self_destruct(); - } else if ((port = strtol(token, &tmp, 10)), !*tmp) { - /* port */ - } else { - host = token; - port = 0; - } s = xcalloc(1, sizeof(*s)); - s->s.sin_port = htons(port); - if (NULL == host) - s->s.sin_addr = any_addr; - else if (1 == safe_inet_addr(host, &s->s.sin_addr)) - (void) 0; - else if ((hp = gethostbyname(host))) /* dont use ipcache */ - s->s.sin_addr = inaddrFromHostent(hp); - else + if (!parse_sockaddr(token, &s->s)) self_destruct(); while (*head) head = &(*head)->next; Index: squid/src/logfile.c =================================================================== RCS file: /cvsroot/squid/squid/src/logfile.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- squid/src/logfile.c 23 Sep 2007 13:00:01 -0000 1.25 +++ squid/src/logfile.c 23 Sep 2007 14:24:59 -0000 1.26 @@ -1,5 +1,5 @@ /* - * $Id: logfile.c,v 1.25 2007/09/23 13:00:01 adrian Exp $ + * $Id: logfile.c,v 1.26 2007/09/23 14:24:59 adrian Exp $ * * DEBUG: section 50 Log file handling * AUTHOR: Duane Wessels @@ -59,6 +59,8 @@ ret = logfile_mod_stdio_open(lf, path, bufsz, fatal_flag); } else if (strcmp(type, "daemon") == 0) { ret = logfile_mod_daemon_open(lf, path, bufsz, fatal_flag); + } else if (strcmp(type, "udp") == 0) { + ret = logfile_mod_udp_open(lf, path, bufsz, fatal_flag); #if HAVE_SYSLOG } else if (strcmp(type, "syslog") == 0) { ret = logfile_mod_syslog_open(lf, path, bufsz, fatal_flag); Index: squid/src/logfile_mod_udp.c =================================================================== RCS file: /cvsroot/squid/squid/src/logfile_mod_udp.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- squid/src/logfile_mod_udp.c 23 Sep 2007 13:55:18 -0000 1.1 +++ squid/src/logfile_mod_udp.c 23 Sep 2007 14:24:59 -0000 1.2 @@ -1,5 +1,5 @@ /* - * $Id: logfile_mod_udp.c,v 1.1 2007/09/23 13:55:18 adrian Exp $ + * $Id: logfile_mod_udp.c,v 1.2 2007/09/23 14:24:59 adrian Exp $ * * DEBUG: section 50 Log file handling * AUTHOR: Adrian Chadd @@ -182,7 +182,7 @@ } } if (comm_connect_addr(ll->fd, &addr)) { - if (ll->flags.fatal) { + if (lf->flags.fatal) { fatalf("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerror()); } else { debug(50, 1) ("Unable to connect to %s for UDP log: %s\n", lf->path, xstrerror()); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid/squid/src/protos.h,v retrieving revision 1.536 retrieving revision 1.537 diff -u -r1.536 -r1.537 --- squid/src/protos.h 21 Sep 2007 09:35:42 -0000 1.536 +++ squid/src/protos.h 23 Sep 2007 14:24:59 -0000 1.537 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.536 2007/09/21 09:35:42 adrian Exp $ + * $Id: protos.h,v 1.537 2007/09/23 14:24:59 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1202,6 +1202,7 @@ extern int isPowTen(int); extern void parseEtcHosts(void); extern int getMyPort(void); +extern int parse_sockaddr(char *s, struct sockaddr_in *addr); char *strwordtok(char *buf, char **t); void strwordquote(MemBuf * mb, const char *str); Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid/squid/src/tools.c,v retrieving revision 1.259 retrieving revision 1.260 diff -u -r1.259 -r1.260 --- squid/src/tools.c 31 Aug 2007 21:58:40 -0000 1.259 +++ squid/src/tools.c 23 Sep 2007 14:24:59 -0000 1.260 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.259 2007/08/31 21:58:40 hno Exp $ + * $Id: tools.c,v 1.260 2007/09/23 14:24:59 adrian Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1405,3 +1405,43 @@ { return inet_ntoa(addr); } + +/** + * Parse a socket address (host:port), fill the given sockaddr_in structure + * Returns FALSE on failure, TRUE on success + * Destroys s + */ +int +parse_sockaddr(char *s, struct sockaddr_in *addr) +{ + char *host, *tmp, *colon; + unsigned short port = 0; + const struct hostent *hp; + + host = NULL; + port = 0; + if ((colon = strchr(s, ':'))) { + /* host:port */ + host = s; + *colon = '\0'; + port = xatos(colon + 1); + if (0 == port) + return FALSE; + } else if ((port = strtol(s, &tmp, 10)), !*tmp) { + /* port */ + } else { + host = s; + port = 0; + } + addr->sin_port = htons(port); + if (NULL == host) + addr->sin_addr = any_addr; + else if (1 == safe_inet_addr(host, &addr->sin_addr)) + (void) 0; + else if ((hp = gethostbyname(host))) /* dont use ipcache */ + addr->sin_addr = inaddrFromHostent(hp); + else + return FALSE; + addr->sin_family = AF_INET; + return TRUE; +}