You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Jagielski <ji...@jaguNET.com> on 2000/02/19 22:05:59 UTC

[PATCH] PR5766

OK... this seems to do the job for me. Could others give it a look
over to make sure I didn't make any brain-dead mistakes... Working
on little sleep :(


Index: src/include/ap_mmn.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/include/ap_mmn.h,v
retrieving revision 1.43
diff -u -r1.43 ap_mmn.h
--- ap_mmn.h	2000/01/12 15:54:56	1.43
+++ ap_mmn.h	2000/02/19 20:57:39
@@ -226,6 +226,7 @@
  *                        ap_base64encode_len(), ap_base64decode(),
  *                        ap_base64decode_binary(), ap_base64decode_len(),
  *                        ap_pbase64decode(), ap_pbase64encode()
+ * 19990320.7           - add ap_strcasestr()
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503133UL /* "AP13" */
@@ -233,7 +234,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 19990320
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 6                     /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 7                     /* 0...n */
 #define MODULE_MAGIC_NUMBER MODULE_MAGIC_NUMBER_MAJOR	/* backward compat */
 
 /* Useful for testing for features. */
Index: src/include/httpd.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.304
diff -u -r1.304 httpd.h
--- httpd.h	2000/02/02 20:43:43	1.304
+++ httpd.h	2000/02/19 20:57:40
@@ -1008,6 +1008,7 @@
 API_EXPORT(int) ap_is_matchexp(const char *str);
 API_EXPORT(int) ap_strcmp_match(const char *str, const char *exp);
 API_EXPORT(int) ap_strcasecmp_match(const char *str, const char *exp);
+API_EXPORT(char *) ap_strcasestr(const char *s1, const char *s2);
 API_EXPORT(char *) ap_pbase64decode(pool *p, const char *bufcoded);
 API_EXPORT(char *) ap_pbase64encode(pool *p, char *string); 
 API_EXPORT(char *) ap_uudecode(pool *p, const char *bufcoded);
Index: src/main/http_protocol.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/http_protocol.c,v
retrieving revision 1.288
diff -u -r1.288 http_protocol.c
--- http_protocol.c	2000/02/08 00:34:36	1.288
+++ http_protocol.c	2000/02/19 20:57:42
@@ -112,22 +112,30 @@
  *    - return type
  */
 static const char *make_content_type(request_rec *r, const char *type) {
-    const char *i;
+    char *needcset[] = {
+	"text/plain",
+	"text/html",
+	NULL };
+    char **pcset;
     core_dir_config *conf = (core_dir_config *)ap_get_module_config(
 	r->per_dir_config, &core_module);
     if (!type) type = ap_default_type(r);
     if (conf->add_default_charset != ADD_DEFAULT_CHARSET_ON) return type;
 
-    i = type;
-    while (*i && *i != ';') i++;
-    if (*i && *i == ';') {
+    if (ap_strcasestr(type, "charset=") != NULL) {
 	/* already has parameter, do nothing */
-	/* XXX should check for actual charset=, but then we need real 
-	 * parsing code 
-	 */
+	/* XXX we don't check the validity */
+	;
     } else {
-	type = ap_pstrcat(r->pool, type, "; charset=", 
-	    conf->add_default_charset_name, NULL);
+    	/* see if it makes sense to add the charset. At present,
+	 * we only add it if the Content-type is one of needcset[]
+	 */
+	for (pcset = needcset; *pcset ; pcset++)
+	    if (ap_strcasestr(type, *pcset) != NULL) {
+		type = ap_pstrcat(r->pool, type, "; charset=", 
+		    conf->add_default_charset_name, NULL);
+		break;
+	    }
     }
     return type;
 }
Index: src/main/util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.177
diff -u -r1.177 util.c
--- util.c	2000/02/02 20:43:51	1.177
+++ util.c	2000/02/19 20:57:45
@@ -303,6 +303,38 @@
     return 0;
 }
 
+/*
+ * Similar to standard strstr() but we ignore case in this version.
+ * Based on the strstr() implementation further below.
+ */
+API_EXPORT(char *) ap_strcasestr(const char *s1, const char *s2)
+{
+    char *p1, *p2;
+    if (*s2 == '\0') {
+	/* an empty s2 */
+        return((char *)s1);
+    }
+    while(1) {
+	for ( ; (*s1 != '\0') && (ap_tolower(*s1) != ap_tolower(*s2)); s1++);
+	if (*s1 == '\0') return(NULL);
+	/* found first character of s2, see if the rest matches */
+        p1 = (char *)s1;
+        p2 = (char *)s2;
+        while (ap_tolower(*++p1) == ap_tolower(*++p2)) {
+            if (*p1 == '\0') {
+                /* both strings ended together */
+                return((char *)s1);
+            }
+        }
+        if (*p2 == '\0') {
+            /* second string ended, a match */
+            break;
+        }
+	/* didn't find a match here, try starting at next character in s1 */
+        s1++;
+    }
+    return((char *)s1);
+}
 /* 
  * Apache stub function for the regex libraries regexec() to make sure the
  * whole regex(3) API is available through the Apache (exported) namespace.
-- 
===========================================================================
   Jim Jagielski   [|]   jim@jaguNET.com   [|]   http://www.jaguNET.com/
                "Are you suggesting coconuts migrate??"