Hi,

Over time I've made some changes to some of the kannel libraries that I thought I might contribute for inclusion into the current CVS. Attached is a unified diff of these against the latest CVS.

Short explanation:

1. date.c - The function for making iso dates seems to have not been outputing these right, hence causing errors in some applications that depends on this.
Small fix. Check it out and let me know if it has issues.
2. mime.[ch] - several changes:
- Making the mime boundary string a bit more 'safe': Added random numbers and chars to it.
- When converting Octstr * to MIMEEntity *, a safer way to detect if each mime entity ends with \r\n or just \n
- Corrected mis-spelling in comment.
3. wsp_headers.[ch] - Various changes
- Exposed a few more functions (i.e. changed from static) as they are useful in other applications. Added wsp_ prefix to these.
- Detection of WSP_QUOTE and '"' as well in wsp_field_value(). At least one application barfed on this as it produced quote literal
- wsp_strip_parameters was not dealing correctly with " enclosed values. Kept getting stray " at the beginning.



These work well for me.
? gateway/gwlib/gw_uuid_types.h
Index: gateway/gwlib/date.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/date.c,v
retrieving revision 1.14
diff -u -r1.14 date.c
--- gateway/gwlib/date.c        15 Nov 2003 13:14:23 -0000      1.14
+++ gateway/gwlib/date.c        20 Jan 2004 11:07:56 -0000
@@ -272,7 +272,7 @@
 
     tm = gw_localtime((time_t) unixtime);
     
-    return octstr_format("%d-%02d-%02d %02d:%02d:%02d", 
+    return octstr_format("%d-%02d-%02dT%02d:%02d:%02dZ", 
         tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, 
tm.tm_sec);    
 }
 
Index: gateway/gwlib/mime.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/mime.c,v
retrieving revision 1.6
diff -u -r1.6 mime.c
--- gateway/gwlib/mime.c        15 Nov 2003 13:14:23 -0000      1.6
+++ gateway/gwlib/mime.c        20 Jan 2004 11:08:00 -0000
@@ -158,7 +158,6 @@
 {
     Octstr *mime, *value, *boundary;
     List *headers;
-    char *bound = "kannel_MIME_boundary";
     long i;
 
     gw_assert(m != NULL && m->headers != NULL);
@@ -192,7 +191,9 @@
     value = http_header_value(headers, octstr_imm("Content-Type"));
     boundary = http_get_header_parameter(value, octstr_imm("boundary"));
     if (boundary == NULL) {
-        boundary = octstr_create(bound);
+      boundary = octstr_format("_MIME_boundary-%d-%ld_%c_%c_bd%d", 
+                       random(), (long)time(NULL), 'A' + (random()%26), 
+                              'a'+(random() % 26), random());
         octstr_append(value, octstr_imm("; boundary="));
         octstr_append(value, boundary);
         http_header_remove_all(headers, "Content-Type");
@@ -324,9 +325,17 @@
 
             /* we have still two linefeeds at the beginning and end that we 
              * need to remove, these are from the seperator. 
-             * XXX we don't know if it is \n or \r\n?! */
-            octstr_delete(entity, 0, 2);
-            octstr_delete(entity, octstr_len(entity) - 4, 4);
+             * We check if it is \n or \r\n?! */
+           if (octstr_get_char(entity, 0) == '\r')
+                octstr_delete(entity, 0, 2);         
+           else
+                octstr_delete(entity, 0, 1);
+
+           if (octstr_get_char(entity, octstr_len(entity) - 2) == '\r')
+                octstr_delete(entity, octstr_len(entity) - 4, 4);
+           else
+                octstr_delete(entity, octstr_len(entity) - 2, 2);
+
 
             debug("mime.parse",0,"MIME multipart: Parsing entity:");
             octstr_dump(entity, 0);
Index: gateway/gwlib/mime.h
===================================================================
RCS file: /home/cvs/gateway/gwlib/mime.h,v
retrieving revision 1.5
diff -u -r1.5 mime.h
--- gateway/gwlib/mime.h        9 Dec 2003 00:10:52 -0000       1.5
+++ gateway/gwlib/mime.h        20 Jan 2004 11:08:08 -0000
@@ -97,7 +97,7 @@
     List *headers;
     List *multiparts;
     Octstr *body;
-    struct MIMEEntity *start;   /* in case multipart/replated */
+    struct MIMEEntity *start;   /* in case multipart/related */
 } MIMEEntity;
 
 
Index: gateway/wap/wsp_headers.c
===================================================================
RCS file: /home/cvs/gateway/wap/wsp_headers.c,v
retrieving revision 1.15
diff -u -r1.15 wsp_headers.c
--- gateway/wap/wsp_headers.c   9 Dec 2003 13:53:43 -0000       1.15
+++ gateway/wap/wsp_headers.c   20 Jan 2004 11:08:41 -0000
@@ -122,7 +122,8 @@
     } else if (val > 127) {
         *well_known_value = val - 128;
         return WSP_FIELD_VALUE_ENCODED;
-    } else if (val == WSP_QUOTE) {  /* 127 */
+    } else if (val == WSP_QUOTE || 
+              val == '"') {  /* 127 or the ordinary quote. */
         *well_known_value = -1;
         /* We already consumed the Quote */
         return WSP_FIELD_VALUE_NUL_STRING;
@@ -508,7 +509,7 @@
 }
 
 /* Accept-general-form is defined in 8.4.2.7 */
-static Octstr *unpack_accept_general_form(ParseContext *context)
+Octstr *wsp_unpack_accept_general_form(ParseContext *context)
 {
     Octstr *decoded = NULL;
     int ret;
@@ -552,7 +553,7 @@
 }
 
 /* Accept-charset-general-form is defined in 8.4.2.8 */
-static Octstr *unpack_accept_charset_general_form(ParseContext *context)
+Octstr *wsp_unpack_accept_charset_general_form(ParseContext *context)
 {
     Octstr *decoded = NULL;
     int ret;
@@ -1171,11 +1172,11 @@
             /* Content-general-form and Accept-general-form
              * are defined separately in WSP, but their
              * definitions are equivalent. */
-            decoded = unpack_accept_general_form(context);
+            decoded = wsp_unpack_accept_general_form(context);
             break;
 
         case WSP_HEADER_ACCEPT_CHARSET:
-            decoded = unpack_accept_charset_general_form(context);
+            decoded = wsp_unpack_accept_charset_general_form(context);
             break;
 
         case WSP_HEADER_ACCEPT_LANGUAGE:
@@ -1423,7 +1424,8 @@
 static int pack_transfer_encoding(Octstr *packet, Octstr *value);
 static int pack_uri(Octstr *packet, Octstr *value);
 static int pack_warning(Octstr *packet, Octstr *value);
-static int pack_content_type(Octstr *packet, Octstr *value);
+
+
 
 /* these are used in MMS encapsulation code too */
 
@@ -1450,7 +1452,7 @@
         { WSP_HEADER_CONTENT_LOCATION, pack_uri, 0 },
         { WSP_HEADER_CONTENT_MD5, pack_md5, 0 },
         { WSP_HEADER_CONTENT_RANGE, pack_content_range, 0 },
-        { WSP_HEADER_CONTENT_TYPE, pack_content_type, 0 },
+        { WSP_HEADER_CONTENT_TYPE, wsp_pack_content_type, 0 },
         { WSP_HEADER_DATE, wsp_pack_date, 0 },
         { WSP_HEADER_ETAG, wsp_pack_text, 0 },
         { WSP_HEADER_EXPIRES, pack_expires, 0 },
@@ -1586,16 +1588,21 @@
         pos = end;
 
         if (octstr_get_char(value, pos) == '=') {
+            int istring = 0;
             pos++;
             while (isspace(octstr_get_char(value, pos)))
                 pos++;
-            if (octstr_get_char(value, pos) == '"')
-                end = pos + http_header_quoted_string_len(value, pos);
-            else
+            if (octstr_get_char(value, pos) == '"') {
+                end = pos + http_header_quoted_string_len(value, pos) - 1;
+               pos++; /* Skip over '"' */
+               istring = 1;
+            } else
                 end = octstr_search_char(value, ';', pos);
             if (end < 0)
                 end = octstr_len(value);
-            val = octstr_copy(value, pos, end - pos);
+           val = octstr_copy(value, pos, end - pos);
+           if (istring)
+                end++;
             octstr_strip_blanks(val);
             pos = end;
             pos = octstr_search_char(value, ';', pos);
@@ -1761,7 +1768,7 @@
     octstr_append(packed, encoded);
 }
 
-static void pack_long_integer(Octstr *packed, unsigned long integer)
+void wsp_pack_long_integer(Octstr *packed, unsigned long integer)
 {
     long oldlen = octstr_len(packed);
     unsigned char octet;
@@ -1797,7 +1804,7 @@
     if (integer <= MAX_SHORT_INTEGER)
         wsp_pack_short_integer(packed, integer);
     else
-        pack_long_integer(packed, integer);
+        wsp_pack_long_integer(packed, integer);
 }
 
 int wsp_pack_integer_string(Octstr *packed, Octstr *value)
@@ -2175,7 +2182,7 @@
         return -1;
     }
 
-    pack_long_integer(packed, timeval);
+    wsp_pack_long_integer(packed, timeval);
     return 0;
 }
 
@@ -2600,7 +2607,7 @@
     return -1;
 }
 
-static int pack_content_type(Octstr *packed, Octstr *value)
+int wsp_pack_content_type(Octstr *packed, Octstr *value)
 {
     /* The expansion of Content-type-value works out to be
      * equivalent to Accept-value. */ 
@@ -2617,7 +2624,7 @@
        /* Responses with an invalid Expires header should be treated
        as already expired.  If we just skip this header, then the client
        won't know that.  So we encode one with a date far in the past. */
-       pack_long_integer(packed, LONG_AGO_VALUE);
+       wsp_pack_long_integer(packed, LONG_AGO_VALUE);
        ret = 0;
     }
 
@@ -2839,7 +2846,7 @@
         content_type = octstr_create("application/octet-stream");
     }
     octstr_strip_blanks(content_type);
-    pack_content_type(packed, content_type);
+    wsp_pack_content_type(packed, content_type);
     octstr_destroy(content_type);
 }
 
@@ -2910,7 +2917,7 @@
     return -1;
 }
 
-static int pack_application_header(Octstr *packed,
+int wsp_pack_application_header(Octstr *packed,
                                    Octstr *fieldname, Octstr *value)
 {
     if (!is_token(fieldname)) {
@@ -2961,7 +2968,7 @@
         if (separate_content_type && fieldnum == WSP_HEADER_CONTENT_TYPE) {
            /* already handled */
         } else if (fieldnum < 0) {
-            if (pack_application_header(packed, fieldname, value) < 0)
+            if (wsp_pack_application_header(packed, fieldname, value) < 0)
                 errors = 1;
         } else {
             if (pack_known_header(packed, fieldnum, value) < 0)
Index: gateway/wap/wsp_headers.h
===================================================================
RCS file: /home/cvs/gateway/wap/wsp_headers.h,v
retrieving revision 1.7
diff -u -r1.7 wsp_headers.h
--- gateway/wap/wsp_headers.h   9 Dec 2003 13:53:43 -0000       1.7
+++ gateway/wap/wsp_headers.h   20 Jan 2004 11:08:42 -0000
@@ -149,6 +149,12 @@
 int wsp_pack_list(Octstr *packed, long fieldnum, List *elements, int i);
 void wsp_pack_short_integer(Octstr *packed, unsigned long integer);
 void wsp_pack_separate_content_type(Octstr *packed, List *headers);
+Octstr *wsp_unpack_accept_general_form(ParseContext *context);
+Octstr *wsp_unpack_accept_charset_general_form(ParseContext *context);
+int wsp_pack_content_type(Octstr *packet, Octstr *value);
+int wsp_pack_application_header(Octstr *packed,
+                               Octstr *fieldname, Octstr *value);
+void wsp_pack_long_integer(Octstr *packed, unsigned long integer);
 
 /* Return an HTTPHeader linked list which must be freed by the caller
  * (see http.h for details of HTTPHeaders). Cannot fail.

Reply via email to