]> code.citadel.org Git - citadel.git/blobdiff - webcit/cookie_conversion.c
* Added "|END" to the session cookie before base64-ing it. This fixes a
[citadel.git] / webcit / cookie_conversion.c
index 5f139fdf54f6b9d6c9ec6af6b5418462330579d2..22f0a7d6f4e9bc87e84a063cb82295ab2fd10914 100644 (file)
 #include <signal.h>
 #include "webcit.h"
 
+#define TRUE  1
+#define FALSE 0
+
+typedef unsigned char byte;          /* Byte type */
+
 /*
  * 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)
 {
-       char buf[256];
-       int i;
-
-       sprintf(buf, "%d|%s|%s|%s", session, user, pass, room);
-       strcpy(cookie, "");
-
-       for (i = 0; i < strlen(buf); ++i)
-               sprintf(&cookie[strlen(cookie)], "%02X", buf[i]);
+       char buf[SIZ];
 
+       sprintf(buf, "%d|%s|%s|%s|END", session, user, pass, room);
+       CtdlEncodeBase64(cookie, buf, strlen(buf));
 }
 
 
@@ -42,13 +42,9 @@ 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[256];
-       int i;
+       char buf[SIZ];
 
-       for (i = 0; i < strlen(cookie); i = i + 2) {
-               sscanf(&cookie[i], "%02x", (unsigned int *) &buf[i / 2]);
-               buf[(i / 2) + 1] = 0;
-       }
+       CtdlDecodeBase64(buf, cookie, strlen(cookie));
 
        if (session != NULL)
                *session = extract_int(buf, 0);