]> code.citadel.org Git - citadel.git/blobdiff - webcit/cookie_conversion.c
* Hmmph. Do the session cookie as hex instead of base64. There really
[citadel.git] / webcit / cookie_conversion.c
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);