* Hmmph. Do the session cookie as hex instead of base64. There really
authorArt Cancro <ajc@citadel.org>
Tue, 1 Jun 2004 00:36:43 +0000 (00:36 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 1 Jun 2004 00:36:43 +0000 (00:36 +0000)
  are some characters in the base64 set that make HTTP do nasty things.

webcit/ChangeLog
webcit/cookie_conversion.c

index c16faa9551240d85234742600cddbe861ba65bfe..22508c26c765b3e935cbad63d07cb757e26b533e 100644 (file)
@@ -1,4 +1,8 @@
 $Log$
+Revision 510.7  2004/06/01 00:36:43  ajc
+* Hmmph.  Do the session cookie as hex instead of base64.  There really
+  are some characters in the base64 set that make HTTP do nasty things.
+
 Revision 510.6  2004/05/31 21:43:27  ajc
 * Added "|END" to the session cookie before base64-ing it.  This fixes a
   problem with certain room names causing the webserver to freak out and
@@ -1830,3 +1834,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 22f0a7d6f4e9bc87e84a063cb82295ab2fd10914..6a4d9f2302f55d269f74ec6b2dd79f5b0627cf65 100644 (file)
 typedef unsigned char byte;          /* Byte type */
 
 /*
- * Pack all session info into one easy-to-digest cookie.  Healthy and delicious!
+ * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
  */
-void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room)
+void stuff_to_cookie(char *cookie, int session,
+               char *user, char *pass, char *room)
 {
        char buf[SIZ];
+       int i;
 
-       sprintf(buf, "%d|%s|%s|%s|END", session, user, pass, room);
-       CtdlEncodeBase64(cookie, buf, strlen(buf));
+       sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room);
+       strcpy(cookie, "");
+       for (i=0; i<strlen(buf); ++i) {
+               sprintf(&cookie[i*2], "%02X", buf[i]);
+       }
 }
 
+int xtoi(char *in, size_t len)
+{
+    int val = 0;
+    while (isxdigit((byte) *in) && (len-- > 0)) {
+       char c = *in++;
+       val <<= 4;
+       val += isdigit((unsigned char)c)
+           ? (c - '0')
+           : (tolower((unsigned char)c) - 'a' + 10);
+    }
+    return val;
+}
 
 /*
  * Extract all that fun stuff out of the cookie.
@@ -43,8 +60,14 @@ void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *ro
 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
 {
        char buf[SIZ];
+       int i, len;
 
-       CtdlDecodeBase64(buf, cookie, strlen(cookie));
+       strcpy(buf, "");
+       len = strlen(cookie) * 2 ;
+       for (i=0; i<len; ++i) {
+               buf[i] = xtoi(&cookie[i*2], 2);
+               buf[i+1] = 0;
+       }
 
        if (session != NULL)
                *session = extract_int(buf, 0);