Rewrite HEX decoding to hopefully be easier to understand and maintain.
authorAlex Graveley <alex@ximian.com>
Tue, 28 Aug 2001 08:45:07 +0000 (08:45 +0000)
committerAlex Graveley <orph@src.gnome.org>
Tue, 28 Aug 2001 08:45:07 +0000 (08:45 +0000)
2001-08-28  Alex Graveley  <alex@ximian.com>

* src/soup-core/soup-transfer.c (soup_transfer_read_chunk):
Rewrite HEX decoding to hopefully be easier to understand and maintain.

* src/soup-core/soup-message.c (redirect_handler): Don't unref the
old context until after we requeue the message using the new
context, as we may still have a connection from the old one.

ChangeLog
libsoup/soup-message.c
libsoup/soup-transfer.c

index b6485ef..71097a0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2001-08-28  Alex Graveley  <alex@ximian.com>
+
+       * src/soup-core/soup-transfer.c (soup_transfer_read_chunk):
+       Rewrite HEX decoding to hopefully be easier to understand and maintain.
+
+       * src/soup-core/soup-message.c (redirect_handler): Don't unref the
+       old context until after we requeue the message using the new
+       context, as we may still have a connection from the old one.
+
 2001-08-27  Alex Graveley  <alex@ximian.com>
 
        * src/soup-core/soup-auth.c (soup_auth_new_digest): Set the
index ffbe270..ddaba57 100644 (file)
@@ -71,15 +71,19 @@ redirect_handler (SoupMessage *msg, gpointer user_data)
        new_url = soup_message_get_response_header (msg, "Location");
 
        if (new_url) {
-               SoupContext *new_ctx = soup_context_get (new_url);
+               SoupContext *new_ctx, *old_ctx;
+
+               new_ctx = soup_context_get (new_url);
                if (!new_ctx) return SOUP_ERROR_MALFORMED_HEADER;
 
-               soup_context_unref (msg->context);
+               old_ctx = msg->context;
                msg->context = new_ctx;
 
                soup_message_queue (msg,
                                    msg->priv->callback, 
                                    msg->priv->user_data);
+
+               soup_context_unref (old_ctx);
        }
 
        return SOUP_ERROR_NONE;
index 3142944..f1a7ef8 100644 (file)
@@ -130,14 +130,22 @@ soup_transfer_read_chunk (SoupReader *r)
                /* 
                 * Convert the size of the next chunk from hex 
                 */
-               while ((tolower (*i) >= 'a' && tolower (*i) <= 'f') ||
-                      (*i >= '0' && *i <= '9'))
-                       len++, i++;
-
-               for (i -= len, j = len - 1; j + 1; i++, j--)
-                       new_len += (*i > '9') ?
-                               (tolower (*i) - 0x57) << (4*j) :
-                               (tolower (*i) - 0x30) << (4*j);
+               while (isxdigit (*i)) {
+                       len++;
+                       i++;
+               }
+
+               i -= len;
+
+               for (j = len - 1; j + 1; j--) {
+                       if (isdigit (*i))
+                               new_len += (*i - 0x30) << (4*j);
+                       else
+                               new_len += (tolower (*i) - 0x57) << (4*j);
+                       i++;
+               }
+
+               g_assert (new_len >= 0);
 
                chunk_idx = chunk_idx + chunk_len;
                chunk_len = new_len;