coar        99/06/22 08:33:20

  Modified:    src      Configuration.tmpl
               src/main http_core.c
               src/modules/standard mod_vhost_alias.c
  Log:
        Jim beat me to the server_rec and ap_mmn fixes, so what's left
        here is just some cleanup from the new module addition; be
        consistent and stylish.  Oh, and fix the location in the
        Configuration.tmpl file.
  
  Revision  Changes    Path
  1.117     +1 -1      apache-1.3/src/Configuration.tmpl
  
  Index: Configuration.tmpl
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/Configuration.tmpl,v
  retrieving revision 1.116
  retrieving revision 1.117
  diff -u -r1.116 -r1.117
  --- Configuration.tmpl        1999/06/22 00:51:27     1.116
  +++ Configuration.tmpl        1999/06/22 15:33:10     1.117
  @@ -219,7 +219,7 @@
   ## based on the host header or local IP address of the request.
   ## See "../htdocs/manual/vhosts/mass.html".
   
  -# AddModule modules/extra/mod_vhost_alias.o
  +# AddModule modules/standard/mod_vhost_alias.o
   
   ##
   ## Config manipulation modules
  
  
  
  1.266     +10 -7     apache-1.3/src/main/http_core.c
  
  Index: http_core.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/http_core.c,v
  retrieving revision 1.265
  retrieving revision 1.266
  diff -u -r1.265 -r1.266
  --- http_core.c       1999/06/22 00:51:30     1.265
  +++ http_core.c       1999/06/22 15:33:14     1.266
  @@ -696,11 +696,14 @@
            struct in_addr *iaddr;
            struct hostent *hptr;
               int old_stat;
  -         old_stat = ap_update_child_status(conn->child_num, SERVER_BUSY_DNS, 
r);
  +         old_stat = ap_update_child_status(conn->child_num,
  +                                           SERVER_BUSY_DNS, r);
            iaddr = &(conn->local_addr.sin_addr);
  -         hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr), 
AF_INET);
  +         hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr),
  +                              AF_INET);
            if (hptr != NULL) {
  -             conn->local_host = ap_pstrdup(conn->pool, (void *)hptr->h_name);
  +             conn->local_host = ap_pstrdup(conn->pool,
  +                                           (void *)hptr->h_name);
                ap_str_tolower(conn->local_host);
            }
            else {
  @@ -724,7 +727,7 @@
       port = r->server->port ? r->server->port : ap_default_port(r);
   
       if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
  -     || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
  +     || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
           return r->hostname ? ntohs(r->connection->local_addr.sin_port)
                           : port;
       }
  @@ -2144,13 +2147,13 @@
        return err;
       }
   
  -    if (!strcasecmp(arg, "on")) {
  +    if (strcasecmp(arg, "on") == 0) {
           d->use_canonical_name = USE_CANONICAL_NAME_ON;
       }
  -    else if (!strcasecmp(arg, "off")) {
  +    else if (strcasecmp(arg, "off") == 0) {
           d->use_canonical_name = USE_CANONICAL_NAME_OFF;
       }
  -    else if (!strcasecmp(arg, "dns")) {
  +    else if (strcasecmp(arg, "dns") == 0) {
           d->use_canonical_name = USE_CANONICAL_NAME_DNS;
       }
       else {
  
  
  
  1.2       +116 -75   apache-1.3/src/modules/standard/mod_vhost_alias.c
  
  Index: mod_vhost_alias.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_vhost_alias.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- mod_vhost_alias.c 1999/06/22 00:51:38     1.1
  +++ mod_vhost_alias.c 1999/06/22 15:33:17     1.2
  @@ -82,26 +82,30 @@
   module MODULE_VAR_EXPORT vhost_alias_module;
   
   
  -/* basic configuration things */
  +/*
  + * basic configuration things
  + * we abbreviate "mod_vhost_alias" to "mva" for shorter names
  + */
   
   typedef enum {
       VHOST_ALIAS_UNSET, VHOST_ALIAS_NONE, VHOST_ALIAS_NAME, VHOST_ALIAS_IP
  -} vhost_alias_mode;
  +} mva_mode_e;
   
  -typedef struct vhost_alias_server_conf {
  +/*
  + * Per-server module config record.
  + */
  +typedef struct mva_sconf_t {
       char *doc_root;
       char *cgi_root;
  -    vhost_alias_mode doc_root_mode;
  -    vhost_alias_mode cgi_root_mode;
  -} vhost_alias_server_conf;
  -
  +    mva_mode_e doc_root_mode;
  +    mva_mode_e cgi_root_mode;
  +} mva_sconf_t;
   
  -static void *vhost_alias_create_config(pool *p, server_rec *s)
  +static void *mva_create_server_config(pool *p, server_rec *s)
   {
  -    vhost_alias_server_conf *conf =
  -     (vhost_alias_server_conf *)
  -     ap_pcalloc(p, sizeof(vhost_alias_server_conf));
  +    mva_sconf_t *conf;
   
  +    conf = (mva_sconf_t *) ap_pcalloc(p, sizeof(mva_sconf_t));
       conf->doc_root = NULL;
       conf->cgi_root = NULL;
       conf->doc_root_mode = VHOST_ALIAS_UNSET;
  @@ -109,13 +113,13 @@
       return conf;
   }
   
  -static void *vhost_alias_merge_config(pool *p, void *parentv, void *childv)
  +static void *mva_merge_server_config(pool *p, void *parentv, void *childv)
   {
  -    vhost_alias_server_conf *parent = (vhost_alias_server_conf *)parentv;
  -    vhost_alias_server_conf *child = (vhost_alias_server_conf *)childv;
  -    vhost_alias_server_conf *conf =
  -     (vhost_alias_server_conf *) ap_pcalloc(p, sizeof(*conf));
  +    mva_sconf_t *parent = (mva_sconf_t *) parentv;
  +    mva_sconf_t *child = (mva_sconf_t *) childv;
  +    mva_sconf_t *conf;
   
  +    conf = (mva_sconf_t *) ap_pcalloc(p, sizeof(*conf));
       if (child->doc_root_mode == VHOST_ALIAS_UNSET) {
        conf->doc_root_mode = parent->doc_root_mode;
        conf->doc_root = parent->doc_root;
  @@ -138,48 +142,51 @@
   
   /*
    * These are just here to tell us what vhost_alias_set should do.
  + * We don't put anything into them; we just use the cell addresses.
    */
  -static int
  -    vhost_alias_set_doc_root_ip,
  +static int vhost_alias_set_doc_root_ip,
       vhost_alias_set_cgi_root_ip,
       vhost_alias_set_doc_root_name,
       vhost_alias_set_cgi_root_name;
   
   static const char *vhost_alias_set(cmd_parms *cmd, void *dummy, char *map)
   {
  -    vhost_alias_server_conf *conf =
  -     (vhost_alias_server_conf *)
  -     ap_get_module_config(cmd->server->module_config, &vhost_alias_module);
  -    vhost_alias_mode mode, *pmode;
  +    mva_sconf_t *conf;
  +    mva_mode_e mode, *pmode;
       char **pmap;
       char *p;
     
  +    conf = (mva_sconf_t *) ap_get_module_config(cmd->server->module_config,
  +                                             &vhost_alias_module);
       /* there ought to be a better way of doing this */
       if (&vhost_alias_set_doc_root_ip == cmd->info) {
        mode = VHOST_ALIAS_IP;
        pmap = &conf->doc_root;
        pmode = &conf->doc_root_mode;
  -    } else
  -    if (&vhost_alias_set_cgi_root_ip == cmd->info) {
  +    }
  +    else if (&vhost_alias_set_cgi_root_ip == cmd->info) {
        mode = VHOST_ALIAS_IP;
        pmap = &conf->cgi_root;
        pmode = &conf->cgi_root_mode;
  -    } else
  -    if (&vhost_alias_set_doc_root_name == cmd->info) {
  +    }
  +    else if (&vhost_alias_set_doc_root_name == cmd->info) {
        mode = VHOST_ALIAS_NAME;
        pmap = &conf->doc_root;
        pmode = &conf->doc_root_mode;
  -    } else
  -    if (&vhost_alias_set_cgi_root_name == cmd->info) {
  +    }
  +    else if (&vhost_alias_set_cgi_root_name == cmd->info) {
        mode = VHOST_ALIAS_NAME;
        pmap = &conf->cgi_root;
        pmode = &conf->cgi_root_mode;
  -    } else
  +    }
  +    else {
        return "INTERNAL ERROR: unknown command info";
  +    }
   
       if (*map != '/') {
  -     if (strcasecmp(map, "none"))
  +     if (strcasecmp(map, "none")) {
            return "format string must start with '/' or be 'none'";
  +     }
        *pmap = NULL;
        *pmode = VHOST_ALIAS_NONE;
        return NULL;
  @@ -188,46 +195,56 @@
       /* sanity check */
       p = map;
       while (*p != '\0') {
  -     if (*p++ != '%')
  +     if (*p++ != '%') {
            continue;
  +     }
        /* we just found a '%' */
        if (*p == 'p' || *p == '%') {
            ++p;
            continue;
        }
        /* optional dash */
  -     if (*p == '-')
  +     if (*p == '-') {
            ++p;
  +     }
        /* digit N */
  -     if (ap_isdigit(*p))
  +     if (ap_isdigit(*p)) {
            ++p;
  -     else
  +     }
  +     else {
            return "syntax error in format string";
  +     }
        /* optional plus */
  -     if (*p == '+')
  +     if (*p == '+') {
            ++p;
  +     }
        /* do we end here? */
  -     if (*p != '.')
  +     if (*p != '.') {
            continue;
  +     }
        ++p;
        /* optional dash */
  -     if (*p == '-')
  +     if (*p == '-') {
            ++p;
  +     }
        /* digit M */
  -     if (ap_isdigit(*p))
  +     if (ap_isdigit(*p)) {
            ++p;
  -     else
  +     }
  +     else {
            return "syntax error in format string";
  +     }
        /* optional plus */
  -     if (*p == '+')
  +     if (*p == '+') {
            ++p;
  +     }
       }
       *pmap = map;
       *pmode = mode;
       return NULL;
   }
   
  -static const command_rec vhost_alias_commands[] =
  +static const command_rec mva_commands[] =
   {
       {"VirtualScriptAlias", vhost_alias_set, &vhost_alias_set_cgi_root_name,
        RSRC_CONF, TAKE1, "how to create a ScriptAlias based on the host"},
  @@ -251,10 +268,12 @@
       /* XXX: what if size > HUGE_STRING_LEN? */
       if (*pdest + size > buf + HUGE_STRING_LEN) {
        **pdest = '\0';
  -     if (r->filename)
  +     if (r->filename) {
            r->filename = ap_pstrcat(r->pool, r->filename, buf, NULL);
  -     else
  +     }
  +     else {
            r->filename = ap_pstrdup(r->pool, buf);
  +     }
        *pdest = buf;
       }
   }
  @@ -277,9 +296,11 @@
   
       ndots = 0;
       dots[ndots++] = name-1; /* slightly naughty */
  -    for (p = name; *p; ++p)
  -     if (*p == '.' && ndots < MAXDOTS)
  +    for (p = name; *p; ++p){
  +     if (*p == '.' && ndots < MAXDOTS) {
            dots[ndots++] = p;
  +     }
  +    }
       dots[ndots] = p;
   
       r->filename = NULL;
  @@ -321,9 +342,13 @@
        if (*map == '+') ++map, Np = 1;
        if (*map == '.') {
            ++map;
  -         if (*map == '-') ++map, Md = 1;
  +         if (*map == '-') {
  +             ++map, Md = 1;
  +         }
            M = *map++ - '0';
  -         if (*map == '+') ++map, Mp = 1;
  +         if (*map == '+') {
  +             ++map, Mp = 1;
  +         }
        }
        /* note that N and M are one-based indices, not zero-based */
        start = dots[0]+1; /* ptr to the first character */
  @@ -332,13 +357,17 @@
            if (N > ndots) {
                start = "_";
                end = start+1;
  -         } else if (!Nd) {
  +         }
  +         else if (!Nd) {
                start = dots[N-1]+1;
  -             if (!Np)
  +             if (!Np) {
                    end = dots[N];
  -         } else {
  -             if (!Np)
  +             }
  +         }
  +         else {
  +             if (!Np) {
                    start = dots[ndots-N]+1;
  +             }
                end = dots[ndots-N+1];
            }
        }
  @@ -346,39 +375,47 @@
            if (M > end - start) {
                start = "_";
                end = start+1;
  -         } else if (!Md) {
  +         }
  +         else if (!Md) {
                start = start+M-1;
  -             if (!Mp)
  +             if (!Mp) {
                    end = start+1;
  -         } else {
  -             if (!Mp)
  +             }
  +         }
  +         else {
  +             if (!Mp) {
                    start = end-M;
  +             }
                end = end-M+1;
            }
        }
        vhost_alias_checkspace(r, buf, &dest, end - start);
  -     for (p = start; p < end; ++p)
  +     for (p = start; p < end; ++p) {
            *dest++ = ap_tolower(*p);
  +     }
       }
       *dest = '\0';
       /* no double slashes */
  -    if (last == '/') 
  +    if (last == '/') {
        ++uri;
  -    if (r->filename)
  +    }
  +    if (r->filename) {
        r->filename = ap_pstrcat(r->pool, r->filename, buf, uri, NULL);
  -    else
  +    }
  +    else {
        r->filename = ap_pstrcat(r->pool, buf, uri, NULL);
  +    }
   }
   
  -static int vhost_alias_translate(request_rec *r)
  +static int mva_translate(request_rec *r)
   {
  -    vhost_alias_server_conf *conf =
  -     (vhost_alias_server_conf *)
  -     ap_get_module_config(r->server->module_config, &vhost_alias_module);
  +    mva_sconf_t *conf;
       const char *name, *map, *uri;
  -    vhost_alias_mode mode;
  +    mva_mode_e mode;
       int cgi;
     
  +    conf = (mva_sconf_t *) ap_get_module_config(r->server->module_config,
  +                                           &vhost_alias_module);
       if (!strncmp(r->uri, "/cgi-bin/", 9)) {
        mode = conf->cgi_root_mode;
        map = conf->cgi_root;
  @@ -388,21 +425,26 @@
         * call if the mode is wrong
         */
        cgi = 1;
  -    } else if (r->uri[0] == '/') {
  +    }
  +    else if (r->uri[0] == '/') {
        mode = conf->doc_root_mode;
        map = conf->doc_root;
        uri = r->uri;
        cgi = 0;
  -    } else
  +    }
  +    else {
        return DECLINED;
  +    }
     
  -    if (mode == VHOST_ALIAS_NAME)
  +    if (mode == VHOST_ALIAS_NAME) {
        name = ap_get_server_name(r);
  -    else
  -    if (mode == VHOST_ALIAS_IP)
  +    }
  +    else if (mode == VHOST_ALIAS_IP) {
        name = r->connection->local_ip;
  -    else
  +    }
  +    else {
        return DECLINED;
  +    }
   
       vhost_alias_interpolate(r, name, map, uri);
   
  @@ -422,11 +464,11 @@
       NULL,                    /* initializer */
       NULL,                    /* dir config creater */
       NULL,                    /* dir merger --- default is to override */
  -    vhost_alias_create_config,       /* server config */
  -    vhost_alias_merge_config,        /* merge server configs */
  -    vhost_alias_commands,    /* command table */
  +    mva_create_server_config,        /* server config */
  +    mva_merge_server_config, /* merge server configs */
  +    mva_commands,            /* command table */
       NULL,                    /* handlers */
  -    vhost_alias_translate,   /* filename translation */
  +    mva_translate,           /* filename translation */
       NULL,                    /* check_user_id */
       NULL,                    /* check auth */
       NULL,                    /* check access */
  @@ -438,4 +480,3 @@
       NULL,                    /* child_exit */
       NULL                     /* post read-request */
   };
  -
  
  
  

Reply via email to