]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: Guido's 4th set of windows patches.
authorrobertc <>
Wed, 5 Feb 2003 04:57:15 +0000 (04:57 +0000)
committerrobertc <>
Wed, 5 Feb 2003 04:57:15 +0000 (04:57 +0000)
Keywords:

Hi,

This is the 4th of some splitted native Windows patches grouped by
functionality.

Native Windows port enhancements:

- Added native Windows support to cachemgr.cc
- Added native Windows support to dnsserver.cc
- On Windows, fork() is not available, so we need to use a workaround in
store_dir.cc for create store directories sequentially

Regards

Guido

src/cachemgr.cc
src/dnsserver.cc
src/store_dir.cc

index 7e643fb1ee0578ac7a784ebe1a939829705fea07..e56aba7872b24d313fd15bf22fd5f3a627fd3827 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cachemgr.cc,v 1.102 2003/01/23 00:37:16 robertc Exp $
+ * $Id: cachemgr.cc,v 1.103 2003/02/04 21:57:15 robertc Exp $
  *
  * DEBUG: section 0     CGI Cache Manager
  * AUTHOR: Duane Wessels
@@ -171,7 +171,11 @@ static void auth_html(const char *host, int port, const char *user_name);
 static void error_html(const char *msg);
 static char *menu_url(cachemgr_request * req, const char *action);
 static int parse_status_line(const char *sline, const char **statusStr);
+#ifdef _SQUID_MSWIN_
+static cachemgr_request *read_request(char *);
+#else
 static cachemgr_request *read_request(void);
+#endif
 static char *read_get_request(void);
 static char *read_post_request(void);
 
@@ -180,6 +184,45 @@ static void decode_pub_auth(cachemgr_request * req);
 static void reset_auth(cachemgr_request * req);
 static const char *make_auth_header(const cachemgr_request * req);
 
+#ifdef _SQUID_MSWIN_
+static int s_iInitCount = 0;
+int Win32SockInit(void)
+{
+    int iVersionRequested;
+    WSADATA wsaData;
+    int err;
+
+    if (s_iInitCount > 0) {
+       s_iInitCount++;
+       return (0);
+    }
+    else if (s_iInitCount < 0)
+       return (s_iInitCount);
+
+    /* s_iInitCount == 0. Do the initailization */
+    iVersionRequested = MAKEWORD(2, 0);
+    err = WSAStartup((WORD) iVersionRequested, &wsaData);
+    if (err) {
+       s_iInitCount = -1;
+       return (s_iInitCount);
+    }
+    if (LOBYTE(wsaData.wVersion) != 2 ||
+       HIBYTE(wsaData.wVersion) != 0) {
+       s_iInitCount = -2;
+       WSACleanup();
+       return (s_iInitCount);
+    }
+    s_iInitCount++;
+    return (s_iInitCount);
+}
+
+void Win32SockCleanup(void)
+{
+    if (--s_iInitCount == 0)
+       WSACleanup();
+    return;
+}
+#endif /* ifdef _SQUID_MSWIN_ */
 
 static const char *
 safe_str(const char *str)
@@ -404,7 +447,12 @@ static int
 read_reply(int s, cachemgr_request * req)
 {
     char buf[4 * 1024];
+#ifdef _SQUID_MSWIN_
+    int reply;
+    FILE *fp = tmpfile();
+#else
     FILE *fp = fdopen(s, "r");
+#endif
     /* interpretation states */
     enum {
        isStatusLine, isHeaders, isBodyStart, isBody, isForward, isEof, isForwardEof, isSuccess, isError
@@ -421,6 +469,11 @@ read_reply(int s, cachemgr_request * req)
        perror("fdopen");
        return 1;
     }
+#ifdef _SQUID_MSWIN_
+    while ((reply=recv(s,buf,sizeof(buf),0))>0)
+       fwrite(buf,1,reply,fp);
+    rewind(fp);
+#endif
     if (parse_menu)
        action = "menu";
     /* read reply interpreting one line at a time depending on state */
@@ -516,6 +569,9 @@ process_request(cachemgr_request * req)
     static struct sockaddr_in S;
     int s;
     int l;
+#ifdef _SQUID_MSWIN_
+    int answer;
+#endif
     static char buf[2 * 1024];
     if (req == NULL) {
        auth_html(CACHEMGR_HOSTNAME, CACHE_HTTP_PORT, "");
@@ -567,7 +623,13 @@ process_request(cachemgr_request * req)
        make_auth_header(req));
     write(s, buf, l);
     debug(1) fprintf(stderr, "wrote request: '%s'\n", buf);
+#ifdef _SQUID_MSWIN_
+    answer=read_reply(s, req);
+    close(s);
+    return answer;
+#else
     return read_reply(s, req);
+#endif
 }
 
 int
@@ -575,16 +637,31 @@ main(int argc, char *argv[])
 {
     char *s;
     cachemgr_request *req;
+#ifdef _SQUID_MSWIN_
+    int answer;
+#endif
     safe_inet_addr("255.255.255.255", &no_addr);
     now = time(NULL);
+#ifdef _SQUID_MSWIN_
+    Win32SockInit();
+    if ((s = strrchr(argv[0], '\\')))
+#else
     if ((s = strrchr(argv[0], '/')))
+#endif
        progname = xstrdup(s + 1);
     else
        progname = xstrdup(argv[0]);
     if ((s = getenv("SCRIPT_NAME")) != NULL)
        script_name = xstrdup(s);
+#ifdef _SQUID_MSWIN_
+    req = read_request(NULL);
+    answer=process_request(req);
+    Win32SockCleanup();
+    return answer;
+#else
     req = read_request();
     return process_request(req);
+#endif
 }
 
 static char *
@@ -616,10 +693,16 @@ read_get_request(void)
     return xstrdup(s);
 }
 
+#ifdef _SQUID_MSWIN_
+static cachemgr_request *
+read_request(char* buf)
+{
+#else
 static cachemgr_request *
 read_request(void)
 {
     char *buf;
+#endif
     cachemgr_request *req;
     char *s;
     char *t;
@@ -630,7 +713,11 @@ read_request(void)
        (void) 0;
     else
        return NULL;
+#ifdef _SQUID_MSWIN_
+    if (strlen(buf) == 0 || strlen(buf) == 4000)
+#else
     if (strlen(buf) == 0)
+#endif
        return NULL;
     req = (cachemgr_request *)xcalloc(1, sizeof(cachemgr_request));
     for (s = strtok(buf, "&"); s != NULL; s = strtok(NULL, "&")) {
index e7436629ab24f655820da726764f14596a8a03d7..c353d2ef7a06599df3359ac4f07747fab731d9c8 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: dnsserver.cc,v 1.62 2003/01/23 00:37:20 robertc Exp $
+ * $Id: dnsserver.cc,v 1.63 2003/02/04 21:57:15 robertc Exp $
  *
  * DEBUG: section 0     DNS Resolver
  * AUTHOR: Harvest Derived
 #include "util.h"
 #include "snprintf.h"
 
-#if !defined(_SQUID_AIX_)
+#if !defined(_SQUID_AIX_) && !defined(_SQUID_MSWIN_)
 extern int h_errno;
 #endif
 
@@ -340,6 +340,14 @@ main(int argc, char *argv[])
        }
     }
 
+#ifdef _SQUID_MSWIN_
+    {
+       WSADATA wsaData;
+
+       WSAStartup(2, &wsaData);
+    }
+    fflush(stderr);
+#endif
     for (;;) {
        memset(request, '\0', REQ_SZ);
        if (fgets(request, REQ_SZ, stdin) == NULL)
index 01fc38a0fcc15463748e529d4e0a438d7664b40a..038a1016e612b47370b4e86e0bcdbcfe7013cb39 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir.cc,v 1.141 2003/01/23 00:37:26 robertc Exp $
+ * $Id: store_dir.cc,v 1.142 2003/02/04 21:57:15 robertc Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -77,12 +77,22 @@ void
 storeCreateSwapDirectories(void)
 {
     int i;
+/* 
+ * On Windows, fork() is not available.
+ * The following is a workaround for create store directories sequentially
+ * when running on native Windows port.
+ */
+#ifndef _SQUID_MSWIN_
     pid_t pid;
     int status;
+#endif
     for (i = 0; i < Config.cacheSwap.n_configured; i++) {
+#ifndef _SQUID_MSWIN_
        if (fork())
            continue;
+#endif
        INDEXSD(i)->newFileSystem();
+#ifndef _SQUID_MSWIN_
        exit(0);
     }
     do {
@@ -92,6 +102,9 @@ storeCreateSwapDirectories(void)
        pid = waitpid(-1, &status, 0);
 #endif
     } while (pid > 0 || (pid < 0 && errno == EINTR));
+#else
+    }
+#endif
 }
 
 /*