]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make http_port optional, allowing for SSL-only operation. Squid will
authorhno <>
Fri, 5 Apr 2002 04:33:26 +0000 (04:33 +0000)
committerhno <>
Fri, 5 Apr 2002 04:33:26 +0000 (04:33 +0000)
refuse to start unless at least one port is defined.

ChangeLog
src/cache_cf.cc
src/cf.data.pre
src/client_side.cc
src/internal.cc
src/main.cc
src/protos.h
src/send-announce.cc
src/tools.cc

index 9ca23e4399b8efd3bba9041d5d5d15a88ffac3dd..b0437e143a6e4c510e43abff536b4148eb7d06de 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ Changes to squid-2.6 ():
        - CARP now plays well with the other peering algorithms
        - Configuration file can be read from an external program
          or preprocessor. See squid.8 man page.
+       - http_port is now optional, allowing for SSL only operation
 
 Changes to squid-2.5 ():
 
index 97afbac3d3ece94747729a484dae8ad47ef7917b..144a016a0912f5999416adfe6f37b845358f12f3 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.403 2002/04/04 21:17:25 hno Exp $
+ * $Id: cache_cf.cc,v 1.404 2002/04/04 21:33:26 hno Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -96,7 +96,9 @@ static void free_denyinfo(acl_deny_info_list ** var);
 static void parse_sockaddr_in_list(sockaddr_in_list **);
 static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *);
 static void free_sockaddr_in_list(sockaddr_in_list **);
+#if 0
 static int check_null_sockaddr_in_list(const sockaddr_in_list *);
+#endif
 #if USE_SSL
 static void parse_https_port_list(https_port_list **);
 static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *);
@@ -367,19 +369,15 @@ configDoConfigure(void)
        if (Config.Accel.port == 0)
            vport_mode = 1;
     }
-    if (Config.Sockaddr.http == NULL)
-       fatal("No http_port specified!");
-    snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)",
+    snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
        uniqueHostname(),
-       (int) ntohs(Config.Sockaddr.http->s.sin_port),
        full_appname_string);
     /*
      * the extra space is for loop detection in client_side.c -- we search
      * for substrings in the Via header.
      */
-    snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)",
+    snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
        uniqueHostname(),
-       (int) ntohs(Config.Sockaddr.http->s.sin_port),
        full_appname_string);
     if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
        Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
@@ -2230,43 +2228,50 @@ parseNeighborType(const char *s)
     return PEER_SIBLING;
 }
 
-static void
-parse_sockaddr_in_list(sockaddr_in_list ** head)
+void
+parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token)
 {
-    char *token;
     char *t;
     char *host;
     const struct hostent *hp;
     unsigned short port;
     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 = (unsigned short) atoi(t + 1);
-           if (0 == port)
-               self_destruct();
-       } else if ((port = atoi(token)) > 0) {
-           /* port */
-       } else {
-           self_destruct();
-       }
-       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
+
+    host = NULL;
+    port = 0;
+    if ((t = strchr(token, ':'))) {
+       /* host:port */
+       host = token;
+       *t = '\0';
+       port = (unsigned short) atoi(t + 1);
+       if (0 == port)
            self_destruct();
-       while (*head)
-           head = &(*head)->next;
-       *head = s;
+    } else if ((port = atoi(token)) > 0) {
+       /* port */
+    } else {
+       self_destruct();
+    }
+    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
+       self_destruct();
+    while (*head)
+       head = &(*head)->next;
+    *head = s;
+}
+
+static void
+parse_sockaddr_in_list(sockaddr_in_list ** head)
+{
+    char *token;
+    while ((token = strtok(NULL, w_space))) {
+       parse_sockaddr_in_list_token(head, token);
     }
 }
 
@@ -2292,11 +2297,13 @@ free_sockaddr_in_list(sockaddr_in_list ** head)
     }
 }
 
+#if 0
 static int
 check_null_sockaddr_in_list(const sockaddr_in_list * s)
 {
     return NULL == s;
 }
+#endif
 
 #if USE_SSL
 static void
index ed933fd28ce42264894df71de956444f3123aaa6..993eb8669ee596c65132b51dec558424f3bad12b 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.252 2002/04/02 20:32:43 hno Exp $
+# $Id: cf.data.pre,v 1.253 2002/04/04 21:33:26 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -56,7 +56,6 @@ COMMENT_END
 NAME: http_port ascii_port
 TYPE: sockaddr_in_list
 DEFAULT: none
-DEFAULT_IF_NONE: 3128
 LOC: Config.Sockaddr.http
 DOC_START
        Usage:  port
@@ -72,8 +71,6 @@ DOC_START
        option.  Most likely, you do not need to bind to a specific
        address, so you can use the port number alone.
 
-       The default port number is 3128.
-
        If you are running Squid in accelerator mode, then you
        probably want to listen on port 80 also, or instead.
 
@@ -87,6 +84,11 @@ DOC_START
        and an external interface then we recommend you to specify the
        internal address:port in http_port. This way Squid will only be
        visible on the internal address.
+
+NOCOMMENT_START
+# Squid normally listens to port 3128
+http_port 3128
+NOCOMMENT_END
 DOC_END
 
 NAME: https_port
index acdd173323ea0c2384f810b2a0feea46db887a36..05b2eaf754e8a6f3ac0e8362b6e3508e0b99ee47 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.567 2002/04/01 06:02:15 wessels Exp $
+ * $Id: client_side.cc,v 1.568 2002/04/04 21:33:26 hno Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -1210,7 +1210,7 @@ clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep)
     /* Append X-Cache-Lookup: -- temporary hack, to be removed @?@ @?@ */
     httpHeaderPutStrf(hdr, HDR_X_CACHE_LOOKUP, "%s from %s:%d",
        http->lookup_type ? http->lookup_type : "NONE",
-       getMyHostname(), ntohs(Config.Sockaddr.http->s.sin_port));
+       getMyHostname(), getMyPort());
 #endif
     if (httpReplyBodySize(request->method, rep) < 0) {
        debug(33, 3) ("clientBuildReplyHeader: can't keep-alive, unknown body size\n");
@@ -2501,11 +2501,11 @@ clientReadRequest(int fd, void *data)
            if (!http->flags.internal) {
                if (internalCheck(strBuf(request->urlpath))) {
                    if (internalHostnameIs(request->host) &&
-                       request->port == ntohs(Config.Sockaddr.http->s.sin_port)) {
+                       request->port == getMyPort()) {
                        http->flags.internal = 1;
                    } else if (internalStaticCheck(strBuf(request->urlpath))) {
                        xstrncpy(request->host, internalHostname(), SQUIDHOSTNAMELEN);
-                       request->port = ntohs(Config.Sockaddr.http->s.sin_port);
+                       request->port = getMyPort();
                        http->flags.internal = 1;
                    }
                }
index ead74c444939d1a73c2b56e3ce67eaafe959707b..92024ca5b7324ad90ab79baf09db98d82cafa77c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: internal.cc,v 1.23 2001/01/12 00:37:18 wessels Exp $
+ * $Id: internal.cc,v 1.24 2002/04/04 21:33:26 hno Exp $
  *
  * DEBUG: section 76    Internal Squid Object handling
  * AUTHOR: Duane, Alex, Henrik
@@ -96,7 +96,7 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n
 {
     static MemBuf mb = MemBufNULL;
     static char lc_host[SQUIDHOSTNAMELEN];
-    assert(host && port && name);
+    assert(host && name);
     /* convert host name to lower case */
     xstrncpy(lc_host, host, SQUIDHOSTNAMELEN - 1);
     Tolower(lc_host);
@@ -111,7 +111,7 @@ internalRemoteUri(const char *host, u_short port, const char *dir, const char *n
     memBufReset(&mb);
     memBufPrintf(&mb, "http://%s", lc_host);
     /* append port if not default */
-    if (port != urlDefaultPort(PROTO_HTTP))
+    if (port && port != urlDefaultPort(PROTO_HTTP))
        memBufPrintf(&mb, ":%d", port);
     if (dir)
        memBufPrintf(&mb, "%s", dir);
@@ -127,7 +127,7 @@ char *
 internalLocalUri(const char *dir, const char *name)
 {
     return internalRemoteUri(getMyHostname(),
-       ntohs(Config.Sockaddr.http->s.sin_port), dir, name);
+       0, dir, name);
 }
 
 const char *
index 05e28aa006330ae51235ff1846f753e2fbe85a54..312903ded3e154998ca21876b8d9811dda4187dd 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: main.cc,v 1.347 2002/01/15 16:49:19 hno Exp $
+ * $Id: main.cc,v 1.348 2002/04/04 21:33:27 hno Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -41,7 +41,6 @@ extern void (*failure_notify) (const char *);
 static int opt_send_signal = -1;
 static int opt_no_daemon = 0;
 static int opt_parse_cfg_only = 0;
-static int httpPortNumOverride = 1;
 static int icpPortNumOverride = 1;     /* Want to detect "-u 0" */
 static int configured_once = 0;
 #if MALLOC_DBG
@@ -146,7 +145,7 @@ mainParseOptions(int argc, char *argv[])
            opt_reload_hit_only = 1;
            break;
        case 'a':
-           httpPortNumOverride = atoi(optarg);
+           parse_sockaddr_in_list_token(&Config.Sockaddr.http, optarg);
            break;
        case 'd':
            opt_debug_stderr = atoi(optarg);
@@ -458,9 +457,6 @@ mainInitialize(void)
     squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART);
 
     setEffectiveUser();
-    assert(Config.Sockaddr.http);
-    if (httpPortNumOverride != 1)
-       Config.Sockaddr.http->s.sin_port = htons(httpPortNumOverride);
     if (icpPortNumOverride != 1)
        Config.Port.icp = (u_short) icpPortNumOverride;
 
index 564b496d750c4a2227b831d2174fef10ce4150b6..5ec1b9f1bf1b638c9287a2ebb177e8d4d5fc6c72 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.430 2002/04/01 06:02:16 wessels Exp $
+ * $Id: protos.h,v 1.431 2002/04/04 21:33:27 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -101,6 +101,7 @@ extern void requirePathnameExists(const char *name, const char *path);
 extern void parse_time_t(time_t * var);
 extern void parse_cachedir_options(SwapDir * sd, struct cache_dir_option *options, int reconfiguring);
 extern void dump_cachedir_options(StoreEntry * e, struct cache_dir_option *options, SwapDir * sd);
+extern void parse_sockaddr_in_list_token(sockaddr_in_list **, char *);
 
 
 /*
@@ -1162,6 +1163,7 @@ extern void *linklistShift(link_list **);
 extern int xrename(const char *from, const char *to);
 extern int isPowTen(int);
 extern void parseEtcHosts(void);
+extern int getMyPort(void);
 
 #if USE_HTCP
 extern void htcpInit(void);
index 7fda259b75680acff07ceb6461b35d9b1d7f943b..2958c066e2b107d394850c71737fd21c9c0fabcf 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: send-announce.cc,v 1.62 2001/04/14 00:03:23 hno Exp $
+ * $Id: send-announce.cc,v 1.63 2002/04/04 21:33:27 hno Exp $
  *
  * DEBUG: section 27    Cache Announcer
  * AUTHOR: Duane Wessels
@@ -72,7 +72,7 @@ send_announce(const ipcache_addrs * ia, void *junk)
     assert(Config.Sockaddr.http);
     snprintf(tbuf, 256, "Running on %s %d %d\n",
        getMyHostname(),
-       (int) ntohs(Config.Sockaddr.http->s.sin_port),
+       getMyPort(),
        (int) Config.Port.icp);
     strcat(sndbuf, tbuf);
     if (Config.adminEmail) {
index 083a0c69c08647e93956ca4b15127193698ff2fe..f4f50ad0192add291b009b86c1272d3155b02800 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tools.cc,v 1.214 2002/03/30 16:29:51 hno Exp $
+ * $Id: tools.cc,v 1.215 2002/04/04 21:33:27 hno Exp $
  *
  * DEBUG: section 21    Misc Functions
  * AUTHOR: Harvest Derived
@@ -1021,3 +1021,16 @@ parseEtcHosts(void)
        wordlistDestroy(&hosts);
     }
 }
+
+int
+getMyPort(void)
+{
+#if USE_SSL
+    if (Config.Sockaddr.http)
+       return Config.Sockaddr.http->s.sin_port;
+    else
+       return Config.Sockaddr.https->s.sin_port;
+#else
+    return Config.Sockaddr.http->s.sin_port;
+#endif
+}