dgaudet 98/03/12 02:29:14
Modified: src CHANGES src/include http_config.h httpd.h src/main http_config.c util_script.c src/modules/example mod_example.c src/modules/standard mod_alias.c mod_autoindex.c mod_cern_meta.c mod_include.c mod_mime.c mod_mime_magic.c mod_negotiation.c mod_rewrite.c src/os/bs2000 os.c src/os/win32 mod_isapi.c Log: As mentioned a month or two ago there were some implicit assumptions that the values in content_type, handler, content_encoding, ... were lowercase. I'm not referring to mod_negotiation here -- there were other cases where strcmp() was being used. But in addition, mod_negotiation could be convinced to call str_tolower() on r->content_language(s), which could possibly modify a "read-only" string... which wastes at least one memory page per child. Clean all that up by declaring that the content fields in request_rec (and related fields elsewhere) must be lowercase, and must not be modified in place. Naturally I chose this because it's more efficient... rather than going around needlessly pstrdup()ing and strcasecmp()ing everywhere. There are a few other tweaks in here I couldn't resist, along the lines of getting rid of unneeded pstrdup()s. Plus a new function set_string_slot_lower(). Revision Changes Path 1.701 +25 -14 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.700 retrieving revision 1.701 diff -u -r1.700 -r1.701 --- CHANGES 1998/03/11 09:57:23 1.700 +++ CHANGES 1998/03/12 10:28:52 1.701 @@ -1,5 +1,16 @@ Changes with Apache 1.3b6 + *) API: Clarify usage of content_type, handler, content_encoding, + content_language and content_languages fields in request_rec. They + must always be lowercased; and the strings pointed to shouldn't + be modified (you must copy them to modify them). Fix a few bugs + related to this. [Dean Gaudet] + + *) API: Clarification: except for RAW_ARGS, all command handlers can + treat the char * parameters as permanent, and modifiable. There + is no need to pstrdup() them. Clean up some needless pstrdup(). + [Dean Gaudet] + *) Now mod_so keeps track of which module shared objects with which names are loaded and thus avoids multiple loading and unloading and irritating error_log messages. [Ralf S. Engelschall] @@ -94,10 +105,10 @@ *) WIN32: Preserve trailing slash in canonical path (and hence in PATH_INFO). [Paul Sutton, Ben Laurie] - *) USE_PTHREAD_SERIALIZED_ACCEPT has proven unreliable depending on - the rev of Solaris and what mixture of modules are in use. So - it has been disabled, and Solaris is back to using - USE_FCNTL_SERIALIZED_ACCEPT. Users may experiment with + *) PORT: USE_PTHREAD_SERIALIZED_ACCEPT has proven unreliable + depending on the rev of Solaris and what mixture of modules + are in use. So it has been disabled, and Solaris is back to + using USE_FCNTL_SERIALIZED_ACCEPT. Users may experiment with USE_PTHREAD_SERIALIZED_ACCEPT at their own risk, it may speed up static content only servers. Or it may fail unpredictably. [Dean Gaudet] PR#1779, 1854, 1904 @@ -105,11 +116,11 @@ *) mod_test_util_uri.c created which tests the logic in util_uri.c. [Dean Gaudet] - *) Rewrite of absoluteURI handling, and in particular how absoluteURIs - match vhosts. Unless a request is a proxy request, a "http://host" - url is treated as if a similar "Host:" header had been supplied. - This change was made to support future HTTP/1.x protocols which - may require clients to send absoluteURIs for all requests. + *) API: Rewrite of absoluteURI handling, and in particular how + absoluteURIs match vhosts. Unless a request is a proxy request, a + "http://host" url is treated as if a similar "Host:" header had been + supplied. This change was made to support future HTTP/1.x protocols + which may require clients to send absoluteURIs for all requests. In order to achieve this change subtle changes were made to the API. In a request_rec, r->hostlen has been removed. r->unparsed_uri now exists so @@ -123,9 +134,9 @@ managed by the same httpd. [Dean Gaudet] - *) Cleanup of code in http_vhost.c, and remove vhost matching code from - mod_rewrite. The vhost matching is now performed by a globally - available function matches_request_vhost(). [Dean Gaudet] + *) API: Cleanup of code in http_vhost.c, and remove vhost matching + code from mod_rewrite. The vhost matching is now performed by a + globally available function matches_request_vhost(). [Dean Gaudet] *) Reduce memory usage, and speed up ServerAlias support. As a side-effect users can list multiple ServerAlias directives @@ -247,7 +258,7 @@ loop if RLimitMem was used with a small amount of memory -- too small for the signal stack frame to be set up. [Dean Gaudet] - *) Fix problems with absoluteURIs. [Dean Gaudet, + *) Fix problems with absoluteURIs introduced during 1.3b4. [Dean Gaudet, Alvaro Martinez Echevarria <[EMAIL PROTECTED]>] *) Fix multiple UserDir problem introduced during 1.3b4-dev. @@ -309,7 +320,7 @@ (but note /~../.. was handled properly). [Lauri Jesmin <[EMAIL PROTECTED]>] PR#1701 - *) os_is_path_absolute() now takes a const char * instead of a char *. + *) API: os_is_path_absolute() now takes a const char * instead of a char *. [Dean Gaudet] Changes with Apache 1.3b5 1.71 +7 -1 apache-1.3/src/include/http_config.h Index: http_config.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/http_config.h,v retrieving revision 1.70 retrieving revision 1.71 diff -u -r1.70 -r1.71 --- http_config.h 1998/03/05 18:58:34 1.70 +++ http_config.h 1998/03/12 10:28:55 1.71 @@ -60,6 +60,11 @@ /* Command dispatch structures... */ +/* Note that for all of these except RAW_ARGS, the config routine is + * passed a freshly allocated string which can be modified or stored + * or whatever... it's only necessary to do pstrdup() stuff with + * RAW_ARGS. + */ enum cmd_how { RAW_ARGS, /* cmd_func parses command line itself */ TAKE1, /* one argument only */ @@ -162,7 +167,7 @@ /* This structure records the existence of handlers in a module... */ typedef struct { - char *content_type; + const char *content_type; /* MUST be all lower case */ int (*handler) (request_rec *); } handler_rec; @@ -275,6 +280,7 @@ /* Generic command handling function... */ API_EXPORT_NONSTD(const char *) set_string_slot(cmd_parms *, char *, char *); +API_EXPORT_NONSTD(const char *) set_string_slot_lower(cmd_parms *, char *, char *); API_EXPORT_NONSTD(const char *) set_flag_slot(cmd_parms *, char *, int); API_EXPORT_NONSTD(const char *) set_file_slot(cmd_parms *, char *, char *); 1.197 +5 -1 apache-1.3/src/include/httpd.h Index: httpd.h =================================================================== RCS file: /export/home/cvs/apache-1.3/src/include/httpd.h,v retrieving revision 1.196 retrieving revision 1.197 diff -u -r1.196 -r1.197 --- httpd.h 1998/03/11 19:11:09 1.196 +++ httpd.h 1998/03/12 10:28:55 1.197 @@ -174,7 +174,7 @@ #endif /* Define this to be what type you'd like returned for files with unknown */ -/* suffixes */ +/* suffixes. MUST be all lower case. */ #ifndef DEFAULT_CONTENT_TYPE #define DEFAULT_CONTENT_TYPE "text/plain" #endif @@ -642,6 +642,10 @@ table *subprocess_env; table *notes; + /* content_type, handler, content_encoding, content_language, and all + * content_languages MUST be lowercased strings. They may be pointers + * to static strings; they should not be modified in place. + */ char *content_type; /* Break these out --- we dispatch on 'em */ char *handler; /* What we *really* dispatch on */ 1.101 +15 -4 apache-1.3/src/main/http_config.c Index: http_config.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_config.c,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- http_config.c 1998/03/02 06:51:06 1.100 +++ http_config.c 1998/03/12 10:28:57 1.101 @@ -434,7 +434,7 @@ continue; for (handp = modp->handlers; handp->content_type; ++handp) { - if (!strcasecmp(handler, handp->content_type)) { + if (!strcmp(handler, handp->content_type)) { int result = (*handp->handler) (r); if (result != DECLINED) @@ -458,7 +458,7 @@ len = starp - handp->content_type; - if (!len || !strncasecmp(handler, handp->content_type, len)) { + if (!len || !strncmp(handler, handp->content_type, len)) { int result = (*handp->handler) (r); if (result != DECLINED) @@ -906,7 +906,18 @@ /* This one's pretty generic... */ int offset = (int) (long) cmd->info; - *(char **) (struct_ptr + offset) = pstrdup(cmd->pool, arg); + *(char **) (struct_ptr + offset) = arg; + return NULL; +} + +API_EXPORT_NONSTD(const char *) set_string_slot_lower(cmd_parms *cmd, + char *struct_ptr, char *arg) +{ + /* This one's pretty generic... */ + + int offset = (int) (long) cmd->info; + str_tolower(arg); + *(char **) (struct_ptr + offset) = arg; return NULL; } @@ -928,7 +939,7 @@ char *p; int offset = (int) (long) cmd->info; if (os_is_path_absolute(arg)) - p = pstrdup(cmd->pool, arg); + p = arg; else p = make_full_path(cmd->pool, server_root, arg); *(char **) (struct_ptr + offset) = p; 1.101 +1 -0 apache-1.3/src/main/util_script.c Index: util_script.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/util_script.c,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- util_script.c 1998/03/10 06:30:49 1.100 +++ util_script.c 1998/03/12 10:28:58 1.101 @@ -470,6 +470,7 @@ *endp-- = '\0'; r->content_type = pstrdup(r->pool, l); + str_tolower(r->content_type); } else if (!strcasecmp(w, "Status")) { sscanf(l, "%d", &r->status); 1.25 +2 -1 apache-1.3/src/modules/example/mod_example.c Index: mod_example.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/example/mod_example.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- mod_example.c 1998/03/04 02:28:20 1.24 +++ mod_example.c 1998/03/12 10:29:00 1.25 @@ -492,7 +492,8 @@ * where you set the "Content-type" header, and you do so by putting it in * r->content_type, *not* r->headers_out("Content-type"). If you don't * set it, it will be filled in with the server's default type (typically - * "text/plain"). + * "text/plain"). You *must* also ensure that r->content_type is lower + * case. * * We also need to start a timer so the server can know if the connexion * is broken. 1.31 +1 -1 apache-1.3/src/modules/standard/mod_alias.c Index: mod_alias.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_alias.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- mod_alias.c 1998/01/26 19:50:19 1.30 +++ mod_alias.c 1998/03/12 10:29:02 1.31 @@ -327,7 +327,7 @@ if (found) { if (p->handler) { /* Set handler, and leave a note for mod_cgi */ - r->handler = pstrdup(r->pool, p->handler); + r->handler = p->handler; table_setn(r->notes, "alias-forced-type", r->handler); } 1.70 +2 -2 apache-1.3/src/modules/standard/mod_autoindex.c Index: mod_autoindex.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v retrieving revision 1.69 retrieving revision 1.70 diff -u -r1.69 -r1.70 --- mod_autoindex.c 1998/03/06 04:25:45 1.69 +++ mod_autoindex.c 1998/03/12 10:29:03 1.70 @@ -618,8 +618,8 @@ return NULL; } if (r->content_type - && (!strcasecmp(r->content_type, "text/html") - || !strcasecmp(r->content_type, INCLUDES_MAGIC_TYPE)) + && (!strcmp(r->content_type, "text/html") + || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE)) && !r->content_encoding) { if (!(thefile = pfopen(r->pool, r->filename, "r"))) return NULL; 1.25 +1 -0 apache-1.3/src/modules/standard/mod_cern_meta.c Index: mod_cern_meta.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_cern_meta.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- mod_cern_meta.c 1998/01/07 16:46:46 1.24 +++ mod_cern_meta.c 1998/03/12 10:29:03 1.25 @@ -264,6 +264,7 @@ *endp-- = '\0'; r->content_type = pstrdup(r->pool, l); + str_tolower(r->content_type); } else if (!strcasecmp(w, "Status")) { sscanf(l, "%d", &r->status); 1.75 +1 -1 apache-1.3/src/modules/standard/mod_include.c Index: mod_include.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_include.c,v retrieving revision 1.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- mod_include.c 1998/03/10 09:42:45 1.74 +++ mod_include.c 1998/03/12 10:29:04 1.75 @@ -667,7 +667,7 @@ } if (!error_fmt && noexec && rr->content_type - && (strncasecmp(rr->content_type, "text/", 5))) { + && (strncmp(rr->content_type, "text/", 5))) { error_fmt = "unable to include potential exec \"%s\" " "in parsed file %s"; } 1.32 +13 -10 apache-1.3/src/modules/standard/mod_mime.c Index: mod_mime.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- mod_mime.c 1998/02/12 01:09:44 1.31 +++ mod_mime.c 1998/03/12 10:29:05 1.32 @@ -118,7 +118,8 @@ { if (*ext == '.') ++ext; - table_set(m->forced_types, ext, ct); + str_tolower(ct); + table_setn(m->forced_types, ext, ct); return NULL; } @@ -127,7 +128,8 @@ { if (*ext == '.') ++ext; - table_set(m->encoding_types, ext, enc); + str_tolower(enc); + table_setn(m->encoding_types, ext, enc); return NULL; } @@ -136,7 +138,8 @@ { if (*ext == '.') ++ext; - table_set(m->language_types, ext, lang); + str_tolower(lang); + table_setn(m->language_types, ext, lang); return NULL; } @@ -145,7 +148,8 @@ { if (*ext == '.') ++ext; - table_set(m->handlers, ext, hdlr); + str_tolower(hdlr); + table_setn(m->handlers, ext, hdlr); return NULL; } @@ -155,8 +159,7 @@ static const char *set_types_config(cmd_parms *cmd, void *dummy, char *arg) { - set_module_config(cmd->server->module_config, &mime_module, - pstrdup(cmd->pool, arg)); + set_module_config(cmd->server->module_config, &mime_module, arg); return NULL; } @@ -170,9 +173,9 @@ "a language (e.g., fr), followed by one or more file extensions"}, {"AddHandler", add_handler, NULL, OR_FILEINFO, ITERATE2, "a handler name followed by one or more file extensions"}, - {"ForceType", set_string_slot, (void *) XtOffsetOf(mime_dir_config, type), + {"ForceType", set_string_slot_lower, (void *) XtOffsetOf(mime_dir_config, type), OR_FILEINFO, TAKE1, "a media type"}, - {"SetHandler", set_string_slot, (void *) XtOffsetOf(mime_dir_config, handler), + {"SetHandler", set_string_slot_lower, (void *) XtOffsetOf(mime_dir_config, handler), OR_FILEINFO, TAKE1, "a handler name"}, {"TypesConfig", set_types_config, NULL, RSRC_CONF, TAKE1, "the MIME types config file"}, @@ -310,9 +313,9 @@ /* Check for overrides with ForceType/SetHandler */ if (conf->type && strcmp(conf->type, "none")) - r->content_type = pstrdup(r->pool, conf->type); + r->content_type = conf->type; if (conf->handler && strcmp(conf->handler, "none")) - r->handler = pstrdup(r->pool, conf->handler); + r->handler = conf->handler; if (!r->content_type) return DECLINED; 1.27 +8 -2 apache-1.3/src/modules/standard/mod_mime_magic.c Index: mod_mime_magic.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_mime_magic.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- mod_mime_magic.c 1998/03/06 08:52:01 1.26 +++ mod_mime_magic.c 1998/03/12 10:29:05 1.27 @@ -810,10 +810,16 @@ if (state == rsl_subtype || state == rsl_encoding || state == rsl_encoding) { r->content_type = rsl_strdup(r, type_frag, type_pos, type_len); + /* XXX: this could be done at config time I'm sure... but I'm + * confused by all this magic_rsl stuff. -djg */ + str_tolower(r->content_type); } if (state == rsl_encoding) { r->content_encoding = rsl_strdup(r, encoding_frag, encoding_pos, encoding_len); + /* XXX: this could be done at config time I'm sure... but I'm + * confused by all this magic_rsl stuff. -djg */ + str_tolower(r->content_encoding); } /* detect memory allocation errors */ @@ -2075,7 +2081,7 @@ int maglen; char *argv[3]; int silent; - char *encoding; + char *encoding; /* MUST be lowercase */ } compr[] = { { @@ -2121,7 +2127,7 @@ tryit(r, newbuf, newsize); /* set encoding type in the request record */ - r->content_encoding = pstrdup(r->pool, compr[i].encoding); + r->content_encoding = compr[i].encoding; } return 1; } 1.72 +2 -12 apache-1.3/src/modules/standard/mod_negotiation.c Index: mod_negotiation.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_negotiation.c,v retrieving revision 1.71 retrieving revision 1.72 diff -u -r1.71 -r1.72 --- mod_negotiation.c 1998/02/12 02:18:43 1.71 +++ mod_negotiation.c 1998/03/12 10:29:07 1.72 @@ -153,7 +153,7 @@ */ typedef struct accept_rec { - char *type_name; + char *type_name; /* MUST be lowercase */ float quality; float max_bytes; float level; @@ -174,7 +174,7 @@ typedef struct var_rec { request_rec *sub_req; /* May be NULL (is, for map files) */ - char *type_name; + char *type_name; /* MUST be lowercase */ char *file_name; char *content_encoding; array_header *content_languages; /* list of languages for this variant */ @@ -749,7 +749,6 @@ } else if (!strncmp(buffer, "content-encoding:", 17)) { mime_info.content_encoding = get_token(neg->pool, &body, 0); - str_tolower(mime_info.content_encoding); } else if (!strncmp(buffer, "description:", 12)) { mime_info.description = get_token(neg->pool, &body, 0); @@ -861,18 +860,9 @@ mime_info.file_name = pstrdup(neg->pool, dir_entry->d_name); if (sub_req->content_encoding) { mime_info.content_encoding = sub_req->content_encoding; - str_tolower(mime_info.content_encoding); } if (sub_req->content_languages) { - int i; - mime_info.content_languages = sub_req->content_languages; - if (mime_info.content_languages) { - for (i = 0; i < mime_info.content_languages->nelts; ++i) { - str_tolower(((char **) - (mime_info.content_languages->elts))[i]); - } - } } get_entry(neg->pool, &accept_info, sub_req->content_type); 1.91 +1 -0 apache-1.3/src/modules/standard/mod_rewrite.c Index: mod_rewrite.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v retrieving revision 1.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- mod_rewrite.c 1998/03/09 22:43:02 1.90 +++ mod_rewrite.c 1998/03/12 10:29:08 1.91 @@ -820,6 +820,7 @@ else if ( strcasecmp(key, "type") == 0 || strcasecmp(key, "T") == 0 ) { cfg->forced_mimetype = pstrdup(p, val); + str_tolower(cfg->forced_mimetype); } else if ( strcasecmp(key, "env") == 0 || strcasecmp(key, "E") == 0 ) { 1.4 +2 -2 apache-1.3/src/os/bs2000/os.c Index: os.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/os/bs2000/os.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- os.c 1998/02/03 16:55:30 1.3 +++ os.c 1998/03/12 10:29:12 1.4 @@ -76,8 +76,8 @@ convert_to_ascii = (r->content_type == NULL); /* Conversion is applied to text/ files only, if ever. */ - if (r->content_type && strncasecmp(r->content_type, "text/", 5)==0) { - if (strncasecmp(r->content_type, ASCIITEXT_MAGIC_TYPE_PREFIX, + if (r->content_type && strncmp(r->content_type, "text/", 5)==0) { + if (strncmp(r->content_type, ASCIITEXT_MAGIC_TYPE_PREFIX, sizeof(ASCIITEXT_MAGIC_TYPE_PREFIX)-1) == 0) r->content_type = pstrcat(r->pool, "text/", r->content_type+sizeof(ASCIITEXT_MAGIC_TYPE_PREFIX)-1, NULL); 1.8 +1 -0 apache-1.3/src/os/win32/mod_isapi.c Index: mod_isapi.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/os/win32/mod_isapi.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- mod_isapi.c 1998/02/03 07:29:53 1.7 +++ mod_isapi.c 1998/03/12 10:29:13 1.8 @@ -457,6 +457,7 @@ while (endp > value && isspace(*endp)) *endp-- = '\0'; r->content_type = pstrdup (r->pool, value); + str_tolower(r->content_type); } else if (!strcasecmp(data, "Content-Length")) { table_set(r->headers_out, data, value);