]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
purifying
authorwessels <>
Tue, 3 Jun 1997 01:55:58 +0000 (01:55 +0000)
committerwessels <>
Tue, 3 Jun 1997 01:55:58 +0000 (01:55 +0000)
src/cache_cf.cc
src/comm.cc
src/disk.cc
src/ftp.cc
src/gopher.cc
src/http.cc
src/store_dir.cc
src/wais.cc

index ebe897f16e94de9b2df0b5bdd458d6f8583d891f..2214e0e2a777ea974209993ed7740e9c6d6c96fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cache_cf.cc,v 1.194 1997/06/01 04:23:09 wessels Exp $
+ * $Id: cache_cf.cc,v 1.195 1997/06/02 19:55:58 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -1399,7 +1399,7 @@ configSetFactoryDefaults(void)
     Config.Ftp.icon_suffix = safe_xstrdup(DefaultFtpIconSuffix);
     Config.Ftp.list_width = DefaultFtpListWidth;
     Config.Ftp.list_wrap = DefaultFtpListWrap;
-    Config.Ftp.anon_user = DefaultFtpAnonUser;
+    Config.Ftp.anon_user = safe_xstrdup(DefaultFtpAnonUser);
 }
 
 static void
index becef70fca500158fdd4186954bbb3ecf7267cd5..e9ffa856bfd10ff36496943e0d1057971066486a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: comm.cc,v 1.157 1997/06/02 01:06:10 wessels Exp $
+ * $Id: comm.cc,v 1.158 1997/06/02 19:55:59 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -129,12 +129,23 @@ struct _cwstate {
     void (*free) (void *);
 };
 
+typedef struct {
+    char *host;
+    u_short port;
+    struct sockaddr_in S;
+    CNCB *callback;
+    void *data;
+    int tries;
+    struct in_addr in_addr;
+    int locks;
+} ConnectStateData;
+
 /* GLOBAL */
 FD_ENTRY *fd_table = NULL;     /* also used in disk.c */
 
 /* STATIC */
 static int commBind _PARAMS((int s, struct in_addr, u_short port));
-#ifndef HAVE_POLL
+#if !HAVE_POLL
 static int examine_select _PARAMS((fd_set *, fd_set *));
 #endif
 static void checkTimeouts _PARAMS((void));
@@ -150,11 +161,12 @@ static void CommWriteStateCallbackAndFree _PARAMS((int fd, int code));
 static void commSetTcpNoDelay _PARAMS((int));
 #endif
 static void commSetTcpRcvbuf _PARAMS((int, int));
-static void commConnectFree _PARAMS((int fd, void *data));
+static PF commConnectFree;
 static void commConnectHandle _PARAMS((int fd, void *data));
 static void commHandleWrite _PARAMS((int fd, void *data));
 static int fdIsHttpOrIcp _PARAMS((int fd));
 static IPH commConnectDnsHandle;
+static void commConnectCallback _PARAMS((int fd, ConnectStateData *cs, int status));
 
 static struct timeval zero_tv;
 
@@ -321,6 +333,7 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *
     cs->callback = callback;
     cs->data = data;
     comm_add_close_handler(fd, commConnectFree, cs);
+    cs->locks++;
     ipcache_nbgethostbyname(host, fd, commConnectDnsHandle, cs);
 }
 
@@ -328,28 +341,42 @@ static void
 commConnectDnsHandle(int fd, const ipcache_addrs * ia, void *data)
 {
     ConnectStateData *cs = data;
+    assert(cs->locks == 1);
+    cs->locks--;
     if (ia == NULL) {
        debug(5, 3, "commConnectDnsHandle: Unknown host: %s\n", cs->host);
-       cs->callback(fd, COMM_ERR_DNS, cs->data);
+       commConnectCallback(fd, cs, COMM_ERR_DNS);
        return;
     }
     cs->in_addr = ia->in_addrs[ia->cur];
     commConnectHandle(fd, cs);
 }
 
+static void
+commConnectCallback(int fd, ConnectStateData *cs, int status)
+{
+        CNCB *callback = cs->callback;
+       void *data = cs->data;
+       comm_remove_close_handler(fd, commConnectFree, cs);
+       commConnectFree(fd, cs);
+       callback(fd, status, data);
+}
+
 static void
 commConnectFree(int fd, void *data)
 {
     ConnectStateData *cs = data;
+    if (cs->locks)
+       ipcacheUnregister(cs->host, cs);
     xfree(cs->host);
     xfree(cs);
 }
 
 static int
-commRetryConnect(int fd, ConnectStateData * connectState)
+commRetryConnect(int fd, ConnectStateData * cs)
 {
     int fd2;
-    if (++connectState->tries == 4)
+    if (++cs->tries == 4)
        return 0;
     fd2 = socket(AF_INET, SOCK_STREAM, 0);
     if (fd2 < 0) {
@@ -369,41 +396,35 @@ commRetryConnect(int fd, ConnectStateData * connectState)
 static void
 commConnectHandle(int fd, void *data)
 {
-    ConnectStateData *connectState = data;
-    if (connectState->S.sin_addr.s_addr == 0) {
-       connectState->S.sin_family = AF_INET;
-       connectState->S.sin_addr = connectState->in_addr;
-       connectState->S.sin_port = htons(connectState->port);
+    ConnectStateData *cs = data;
+    if (cs->S.sin_addr.s_addr == 0) {
+       cs->S.sin_family = AF_INET;
+       cs->S.sin_addr = cs->in_addr;
+       cs->S.sin_port = htons(cs->port);
        if (Config.Log.log_fqdn)
-           fqdncache_gethostbyaddr(connectState->S.sin_addr, FQDN_LOOKUP_IF_MISS);
+           fqdncache_gethostbyaddr(cs->S.sin_addr, FQDN_LOOKUP_IF_MISS);
     }
-    switch (comm_connect_addr(fd, &connectState->S)) {
+    switch (comm_connect_addr(fd, &cs->S)) {
     case COMM_INPROGRESS:
-       commSetSelect(fd,
-           COMM_SELECT_WRITE,
-           commConnectHandle,
-           (void *) connectState,
-           0);
+       commSetSelect(fd, COMM_SELECT_WRITE, commConnectHandle, cs, 0);
        break;
     case COMM_OK:
        if (vizSock > -1)
-           vizHackSendPkt(&connectState->S, 2);
-       ipcacheCycleAddr(connectState->host);
-       connectState->callback(fd, COMM_OK, connectState->data);
+           vizHackSendPkt(&cs->S, 2);
+       ipcacheCycleAddr(cs->host);
+       commConnectCallback(fd, cs, COMM_OK);
        break;
     default:
-       if (commRetryConnect(fd, connectState)) {
-           debug(5, 3, "Retrying connection to %s: %s\n",
-               connectState->host, xstrerror());
-           connectState->S.sin_addr.s_addr = 0;
-           ipcacheCycleAddr(connectState->host);
-           ipcache_nbgethostbyname(connectState->host,
-               fd,
-               commConnectDnsHandle,
-               connectState);
+       if (commRetryConnect(fd, cs)) {
+           debug(5, 1, "Retrying connection to %s: %s\n",
+               cs->host, xstrerror());
+           cs->S.sin_addr.s_addr = 0;
+           ipcacheCycleAddr(cs->host);
+           cs->locks++;
+           ipcache_nbgethostbyname(cs->host, fd, commConnectDnsHandle, cs);
        } else {
-           ipcacheRemoveBadAddr(connectState->host, connectState->S.sin_addr);
-           connectState->callback(fd, COMM_ERR_CONNECT, connectState->data);
+           ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr);
+           commConnectCallback(fd, cs, COMM_ERR_CONNECT);
        }
        break;
     }
@@ -632,7 +653,7 @@ comm_set_stall(int fd, int delta)
 }
 
 
-#ifdef HAVE_POLL
+#if HAVE_POLL
 
 /* poll() version by:
  * Stewart Forster <slf@connect.com.au>, and
@@ -779,7 +800,7 @@ fdIsHttpOrIcp(int fd)
     return 0;
 }
 
-#ifdef HAVE_POLL
+#if HAVE_POLL
 /* poll all sockets; call handlers for those that are ready. */
 int
 comm_poll(time_t sec)
@@ -1096,15 +1117,13 @@ comm_add_close_handler(int fd, PF * handler, void *data)
 void
 comm_remove_close_handler(int fd, PF * handler, void *data)
 {
-    struct close_handler *p, *last = NULL;
-
+    struct close_handler *p;
+    struct close_handler *last = NULL;
     /* Find handler in list */
     for (p = fd_table[fd].close_handler; p != NULL; last = p, p = p->next)
        if (p->handler == handler && p->data == data)
            break;              /* This is our handler */
-    if (!p)
-       fatal_dump("comm_remove_close_handler: Handler not found!\n");
-
+    assert(p != NULL);
     /* Remove list entry */
     if (last)
        last->next = p->next;
@@ -1239,7 +1258,7 @@ comm_init(void)
 }
 
 
-#ifndef HAVE_POLL
+#if !HAVE_POLL
 /*
  * examine_select - debug routine.
  *
index 74fe3875b72d2bc30fafcb09f204cd949420b022..6c7b2b9d32ec771c9263f015046742a85a069adf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: disk.cc,v 1.70 1997/05/22 15:51:51 wessels Exp $
+ * $Id: disk.cc,v 1.71 1997/06/02 19:56:01 wessels Exp $
  *
  * DEBUG: section 6     Disk I/O Routines
  * AUTHOR: Harvest Derived
@@ -205,12 +205,9 @@ file_open_complete(void *data, int fd, int errcode)
 void
 file_close(int fd)
 {
-    FD_ENTRY *fde = NULL;
-    if (fd < 0)
-       fatal_dump("file_close: bad file number");
-    fde = &fd_table[fd];
-    if (!fde->open)
-       fatal_dump("file_close: already closed");
+    FD_ENTRY *fde = &fd_table[fd];
+    assert(fd >= 0);
+    assert(fde->open);
     if (BIT_TEST(fde->flags, FD_WRITE_DAEMON)) {
        BIT_SET(fde->flags, FD_CLOSE_REQUEST);
        return;
index bb13b9cbd1cdc2b607a8646d5aa36cb2625a6dd9..0ed1b0684d462d1ad7cf3bc483b5d8169f852d39 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.117 1997/06/02 17:19:25 wessels Exp $
+ * $Id: ftp.cc,v 1.118 1997/06/02 19:56:01 wessels Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -182,8 +182,8 @@ ftpStateFree(int fd, void *data)
     FtpStateData *ftpState = data;
     if (ftpState == NULL)
        return;
-    storeUnlockObject(ftpState->entry);
     storeUnregisterAbort(ftpState->entry);
+    storeUnlockObject(ftpState->entry);
     if (ftpState->reply_hdr) {
        put_free_8k_page(ftpState->reply_hdr);
        ftpState->reply_hdr = NULL;
index f24d35b9711a8faaa68ffbf05712c4d8942e83da..93d472b789333eb2109bfd152d616e46bf1bd564 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: gopher.cc,v 1.82 1997/06/02 05:39:44 wessels Exp $
+ * $Id: gopher.cc,v 1.83 1997/06/02 19:56:02 wessels Exp $
  *
  * DEBUG: section 10    Gopher
  * AUTHOR: Harvest Derived
@@ -191,8 +191,8 @@ gopherStateFree(int fd, void *data)
     if (gopherState == NULL)
        return;
     if (gopherState->entry) {
-       storeUnlockObject(gopherState->entry);
        storeUnregisterAbort(gopherState->entry);
+       storeUnlockObject(gopherState->entry);
     }
     put_free_4k_page(gopherState->buf);
     xfree(gopherState);
index 26092efc62a42d478f9019d3ef54305aa7a35cb4..726a8a41a7ffd0c09ec8d67d33cf95f0ac22329e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http.cc,v 1.167 1997/06/02 05:39:45 wessels Exp $
+ * $Id: http.cc,v 1.168 1997/06/02 19:56:03 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -216,8 +216,8 @@ httpStateFree(int fd, void *data)
     HttpStateData *httpState = data;
     if (httpState == NULL)
        return;
-    storeUnlockObject(httpState->entry);
     storeUnregisterAbort(httpState->entry);
+    storeUnlockObject(httpState->entry);
     if (httpState->reply_hdr) {
        put_free_8k_page(httpState->reply_hdr);
        httpState->reply_hdr = NULL;
index 457a7274ba51a179387f3325254d3382d1b3f76d..10ae731e3881815c26f5323debc59ac31a767ee5 100644 (file)
@@ -343,6 +343,7 @@ storeDirOpenTmpSwapLog(int dirn, int *clean_flag)
        debug(50, 0, "%s: %s\n", swaplog_path, xstrerror());
        fatal("Failed to open swap log for reading");
     }
+    memset(&clean_sb, '\0', sizeof(struct stat));
     if (stat(clean_path, &clean_sb) < 0)
        *clean_flag = 0;
     else if (clean_sb.st_mtime < log_sb.st_mtime)
index 5c6b839d98d8ac288b3b6025575556652f946fff..5a5743df3be955d77866826d1264ba5f92ad311c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: wais.cc,v 1.74 1997/06/02 05:39:51 wessels Exp $
+ * $Id: wais.cc,v 1.75 1997/06/02 19:56:04 wessels Exp $
  *
  * DEBUG: section 24    WAIS Relay
  * AUTHOR: Harvest Derived
@@ -132,8 +132,8 @@ waisStateFree(int fd, void *data)
     WaisStateData *waisState = data;
     if (waisState == NULL)
        return;
-    storeUnlockObject(waisState->entry);
     storeUnregisterAbort(waisState->entry);
+    storeUnlockObject(waisState->entry);
     xfree(waisState);
 }