You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Chia-liang Kao <cl...@cirx.org> on 1998/02/12 01:41:48 UTC
[PATCH] Pre-constructed server alias list
Here's a patch for making ServerAlias pre-constructs when
reading config files. Also avoid some is_matchexp called,
by seperating server alias entry with and without wildcards.
Also for PR#1531, this enables multiple ServerAlias.
Btw, as I use indent to make the sources I modified for
the `Apache Style', lots of the source code in core, vhost
are re-indented. Someone should indent all source files
for the styling.
Index: include/httpd.h
===================================================================
RCS file: /cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.184
diff -u -r1.184 httpd.h
--- httpd.h 1998/02/09 13:25:42 1.184
+++ httpd.h 1998/02/12 00:13:24
@@ -754,7 +754,8 @@
char *path; /* Pathname for ServerPath */
int pathlen; /* Length of path */
- char *names; /* Wildcarded names for ServerAlias servers */
+ array_header *names; /* Normal names for ServerAlias servers */
+ array_header *wild_names; /* Wildcarded names for ServerAlias servers */
uid_t server_uid; /* effective user id when calling exec wrapper */
gid_t server_gid; /* effective group id when calling exec wrapper */
Index: main/http_config.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_config.c,v
retrieving revision 1.96
diff -u -r1.96 http_config.c
--- http_config.c 1998/02/06 18:19:56 1.96
+++ http_config.c 1998/02/12 00:13:29
@@ -1175,7 +1175,8 @@
s->next = NULL;
s->is_virtual = 1;
- s->names = NULL;
+ s->names = make_array(p, 4, sizeof(char **));
+ s->wild_names = make_array(p, 4, sizeof(char **));
s->module_config = create_empty_config(p);
s->lookup_defaults = create_per_dir_config(p);
@@ -1284,6 +1285,7 @@
/* NOT virtual host; don't match any real network interface */
s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
s->addrs->host_port = 0; /* matches any port */
+ s->names = s->wild_names = NULL;
s->module_config = create_server_config(p, s);
s->lookup_defaults = create_default_per_dir_config(p);
Index: main/http_core.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_core.c,v
retrieving revision 1.157
diff -u -r1.157 http_core.c
--- http_core.c 1998/02/08 23:15:34 1.157
+++ http_core.c 1998/02/12 00:13:35
@@ -1195,6 +1195,21 @@
return errmsg;
}
+const char *set_server_alias(cmd_parms *cmd, void *dummy, const char *arg)
+{
+ if (!cmd->server->names)
+ return "ServerAlias only used in <VirtualHost>";
+ while (*arg) {
+ char **item, *name = getword_conf(cmd->pool, &arg);
+ if (is_matchexp(name))
+ item = (char **) push_array(cmd->server->wild_names);
+ else
+ item = (char **) push_array(cmd->server->names);
+ *item = name;
+ }
+ return NULL;
+}
+
const char *add_module_command (cmd_parms *cmd, void *dummy, char *arg)
{
const char *err = check_cmd_context(cmd, GLOBAL_ONLY);
@@ -1840,9 +1855,8 @@
{ "ResourceConfig", set_server_string_slot,
(void *)XtOffsetOf (server_rec, srm_confname), RSRC_CONF, TAKE1,
"The filename of the resource config file" },
-{ "ServerAlias", set_server_string_slot,
- (void *)XtOffsetOf (server_rec, names), RSRC_CONF, RAW_ARGS,
- "A name or names alternately used to access the server" },
+{ "ServerAlias", set_server_alias, NULL, RSRC_CONF, RAW_ARGS,
+ "A name or names alternately used to access the server" },
{ "ServerPath", set_serverpath, NULL, RSRC_CONF, TAKE1,
"The pathname the server can be reached at" },
{ "Timeout", set_timeout, NULL, RSRC_CONF, TAKE1, "Timeout duration (sec)"},
Index: http_vhost.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_vhost.c,v
retrieving revision 1.6
diff -u -r1.6 http_vhost.c
--- http_vhost.c 1998/02/01 21:19:30 1.6
+++ http_vhost.c 1998/02/12 00:29:55
@@ -638,7 +638,8 @@
*/
for (src = r->connection->vhost_lookup_data; src; src = src->next) {
- const char *names;
+ int i;
+ array_header *names;
server_addr_rec *sar;
/* We only consider addresses on the name_chain which have a matching
@@ -670,17 +671,24 @@
}
/* search all the aliases from ServerAlias directive */
- names = s->names;
- if (names) {
- while (*names) {
- char *name = getword_conf(r->pool, &names);
-
- if ((is_matchexp(name) && !strcasecmp_match(host, name)) ||
- (!strcasecmp(host, name))) {
+ names = s->names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp(host, name[i]))
goto found;
- }
- }
- }
+ }
+ }
+ names = s->wild_names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp_match(host, name[i]))
+ goto found;
+ }
+ }
}
return;
--
Chia-liang Kao / clkao@cirx.org
Panther Tech Co. , Taichung, Taiwan
http://www.pamud.net/~clkao
`白爛濤濤我不怕' -- IOI 97
Re: [PATCH] Pre-constructed server alias list
Posted by Chia-liang Kao <cl...@pamud.net>.
mod_rewrite also use server_rec->names for vhosts checking.
CLK
on 02/12/98 Thu, Chia-liang Kao <cl...@cirx.org> wrote:
> Here's a patch for making ServerAlias pre-constructed when
> reading config files. Also avoid some is_matchexp called,
> by seperating server alias entry with and without wildcards.
>
> Also for PR#1531, this enables multiple ServerAlias.
>
> Btw, as I use indent to make the sources I modified for
> the `Apache Style', lots of the source code in core, vhost
> are re-indented. Someone should indent all source files
> for the styling.
Index: include/httpd.h
===================================================================
RCS file: /cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.184
diff -u -r1.184 httpd.h
--- httpd.h 1998/02/09 13:25:42 1.184
+++ httpd.h 1998/02/12 00:13:24
@@ -754,7 +754,8 @@
char *path; /* Pathname for ServerPath */
int pathlen; /* Length of path */
- char *names; /* Wildcarded names for ServerAlias servers */
+ array_header *names; /* Normal names for ServerAlias servers */
+ array_header *wild_names; /* Wildcarded names for ServerAlias servers */
uid_t server_uid; /* effective user id when calling exec wrapper */
gid_t server_gid; /* effective group id when calling exec wrapper */
Index: main/http_config.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_config.c,v
retrieving revision 1.96
diff -u -r1.96 http_config.c
--- http_config.c 1998/02/06 18:19:56 1.96
+++ http_config.c 1998/02/12 00:13:29
@@ -1175,7 +1175,8 @@
s->next = NULL;
s->is_virtual = 1;
- s->names = NULL;
+ s->names = make_array(p, 4, sizeof(char **));
+ s->wild_names = make_array(p, 4, sizeof(char **));
s->module_config = create_empty_config(p);
s->lookup_defaults = create_per_dir_config(p);
@@ -1284,6 +1285,7 @@
/* NOT virtual host; don't match any real network interface */
s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
s->addrs->host_port = 0; /* matches any port */
+ s->names = s->wild_names = NULL;
s->module_config = create_server_config(p, s);
s->lookup_defaults = create_default_per_dir_config(p);
Index: main/http_core.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_core.c,v
retrieving revision 1.157
diff -u -r1.157 http_core.c
--- http_core.c 1998/02/08 23:15:34 1.157
+++ http_core.c 1998/02/12 00:13:35
@@ -1195,6 +1195,21 @@
return errmsg;
}
+const char *set_server_alias(cmd_parms *cmd, void *dummy, const char *arg)
+{
+ if (!cmd->server->names)
+ return "ServerAlias only used in <VirtualHost>";
+ while (*arg) {
+ char **item, *name = getword_conf(cmd->pool, &arg);
+ if (is_matchexp(name))
+ item = (char **) push_array(cmd->server->wild_names);
+ else
+ item = (char **) push_array(cmd->server->names);
+ *item = name;
+ }
+ return NULL;
+}
+
const char *add_module_command (cmd_parms *cmd, void *dummy, char *arg)
{
const char *err = check_cmd_context(cmd, GLOBAL_ONLY);
@@ -1840,9 +1855,8 @@
{ "ResourceConfig", set_server_string_slot,
(void *)XtOffsetOf (server_rec, srm_confname), RSRC_CONF, TAKE1,
"The filename of the resource config file" },
-{ "ServerAlias", set_server_string_slot,
- (void *)XtOffsetOf (server_rec, names), RSRC_CONF, RAW_ARGS,
- "A name or names alternately used to access the server" },
+{ "ServerAlias", set_server_alias, NULL, RSRC_CONF, RAW_ARGS,
+ "A name or names alternately used to access the server" },
{ "ServerPath", set_serverpath, NULL, RSRC_CONF, TAKE1,
"The pathname the server can be reached at" },
{ "Timeout", set_timeout, NULL, RSRC_CONF, TAKE1, "Timeout duration (sec)"},
Index: http_vhost.c
===================================================================
RCS file: /cvs/apache-1.3/src/main/http_vhost.c,v
retrieving revision 1.6
diff -u -r1.6 http_vhost.c
--- http_vhost.c 1998/02/01 21:19:30 1.6
+++ http_vhost.c 1998/02/12 00:29:55
@@ -638,7 +638,8 @@
*/
for (src = r->connection->vhost_lookup_data; src; src = src->next) {
- const char *names;
+ int i;
+ array_header *names;
server_addr_rec *sar;
/* We only consider addresses on the name_chain which have a matching
@@ -670,17 +671,24 @@
}
/* search all the aliases from ServerAlias directive */
- names = s->names;
- if (names) {
- while (*names) {
- char *name = getword_conf(r->pool, &names);
-
- if ((is_matchexp(name) && !strcasecmp_match(host, name)) ||
- (!strcasecmp(host, name))) {
+ names = s->names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp(host, name[i]))
goto found;
- }
- }
- }
+ }
+ }
+ names = s->wild_names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp_match(host, name[i]))
+ goto found;
+ }
+ }
}
return;
Index: standard/mod_rewrite.c
===================================================================
RCS file: /cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.66
diff -u -r1.66 mod_rewrite.c
--- mod_rewrite.c 1998/02/02 22:33:40 1.66
+++ mod_rewrite.c 1998/02/12 08:36:37
@@ -3483,8 +3483,7 @@
char **cppHNLtest;
char *ourhostname;
char *ourhostip;
- const char *names;
- char *name;
+ array_header *names;
int i, j;
server_addr_rec *sar;
@@ -3500,7 +3499,9 @@
unsigned short port for redirects
char *path name of ServerPath
int pathlen len of ServerPath
- char *names Wildcarded names for ServerAlias servers
+ array_header *wild_names Wildcarded names for ServerAlias servers
+ array_header *names
+
r->server->addrs->
struct in_addr host_addr The bound address, for this server
short host_port The bound port, for this server
@@ -3542,15 +3543,22 @@
}
/* check for the virtual-server aliases */
- if (r->server->names != NULL && r->server->names[0] != '\0') {
- names = r->server->names;
- while (*names != '\0') {
- name = getword_conf(r->pool, &names);
- if ((is_matchexp(name) &&
- !strcasecmp_match(testhost, name)) ||
- (strcasecmp(testhost, name) == 0) ) {
- return YES;
- }
+ names = r->server->names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp(testhost, name[i]))
+ return YES;
+ }
+ }
+ names = r->server->wild_names;
+ if (names) {
+ char **name = (char **) names->elts;
+ for (i = 0; i < names->nelts; ++i) {
+ if(!name[i]) continue;
+ if (!strcasecmp_match(testhost, name[i]))
+ return YES;
}
}
}
--
Chia-liang Kao / clkao@cirx.org
Panther Tech Co. , Taichung, Taiwan
http://www.pamud.net/~clkao
`白爛濤濤我不怕' -- IOI 97