* use the HexEscAppend thing instead of printf appending...
authorWilfried Göesgens <willi@citadel.org>
Sun, 10 Jan 2010 21:17:44 +0000 (21:17 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 10 Jan 2010 21:17:44 +0000 (21:17 +0000)
* move some cookie logic over

webcit/cookie_conversion.c
webcit/webcit.c
webcit/webcit.h

index 1a3465d3443d624234e3be88d1e8ca8a787dded5..23a751f6ac7026046f9f5af175b29416703b149f 100644 (file)
@@ -4,29 +4,49 @@
 
 #include "webcit.h"
 
+/*
+ * String to unset the cookie.
+ * Any date "in the past" will work, so I chose my birthday, right down to
+ * the exact minute.  :)
+ */
+static char *unset = "; expires=28-May-1971 18:10:00 GMT";
 typedef unsigned char byte;          /* Byte type used by cookie_to_stuff() */
 
 /*
  * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
  */
-void stuff_to_cookie(char *cookie, size_t clen, int session,
-               StrBuf *user, StrBuf *pass, StrBuf *room, const char *language)
+void stuff_to_cookie(int unset_cookies)
 {
+       wcsession *WCC = WC;
        char buf[SIZ];
-       int i;
-       int len;
 
-       len = snprintf(buf, SIZ, "%d|%s|%s|%s|%s|", 
-               session, 
-               ChrPtr(user), 
-               ChrPtr(pass), 
-               ChrPtr(room),
-               language
-       );
+       if (unset_cookies) {
+               hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
+       }
+       else
+       {
+               StrBufAppendPrintf(WCC->HBuf, "Set-cookie: webcit=");
+               snprintf(buf, sizeof(buf), "%d", WCC->wc_session);
+               StrBufHexescAppend(WCC->HBuf, NULL, buf);
+               StrBufHexescAppend(WCC->HBuf, NULL, "|");
+               StrBufHexescAppend(WCC->HBuf, WCC->wc_username, NULL);
+               StrBufHexescAppend(WCC->HBuf, NULL, "|");
+               StrBufHexescAppend(WCC->HBuf, WCC->wc_password, NULL);
+               StrBufHexescAppend(WCC->HBuf, NULL, "|");
+               StrBufHexescAppend(WCC->HBuf, WCC->wc_roomname, NULL);
+               StrBufHexescAppend(WCC->HBuf, NULL, "|");
+               StrBufHexescAppend(WCC->HBuf, NULL, get_selected_language());
+               StrBufHexescAppend(WCC->HBuf, NULL, "|");
 
-       strcpy(cookie, "");
-       for (i=0; (i < len) && (i * 2 < clen); ++i) {
-               snprintf(&cookie[i*2], clen - i * 2, "%02X", buf[i]);
+               if (server_cookie != NULL) {
+                       StrBufAppendPrintf(WCC->HBuf, 
+                                          "; path=/ %s\r\n", 
+                                          server_cookie);
+               }
+               else {
+                       StrBufAppendBufPlain(WCC->HBuf,
+                                            HKEY("; path=/\r\n"), 0);
+               }
        }
 }
 
index d27cd782acdec0d8a00ae011fc3f28472449998c..59347777d3cde9ab85f1a848649ecc0b83f552f7 100644 (file)
 #include "webserver.h"
 
 
-/*
- * String to unset the cookie.
- * Any date "in the past" will work, so I chose my birthday, right down to
- * the exact minute.  :)
- */
-static char *unset = "; expires=28-May-1971 18:10:00 GMT";
 StrBuf *csslocal = NULL;
 HashList *HandlerHash = NULL;
 
@@ -118,7 +112,6 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
                        int cache               /* 1 = allow browser to cache this page             */
 ) {
        wcsession *WCC = WC;
-       char cookie[1024];
        char httpnow[128];
 
        hprintf("HTTP/1.1 200 OK\n");
@@ -159,28 +152,7 @@ void output_headers(       int do_httpheaders,     /* 1 = output HTTP headers
                );
        }
 
-       if (cache < 2) {
-
-               stuff_to_cookie(cookie, 1024, 
-                               WCC->wc_session,
-                               WCC->wc_username,
-                               WCC->wc_password,
-                               WCC->wc_roomname,
-                               get_selected_language()
-                       );
-               
-               if (unset_cookies) {
-                       hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
-               } else {
-                       if (server_cookie != NULL) {
-                               hprintf("Set-cookie: webcit=%s; path=/ %s\r\n", 
-                                       cookie, server_cookie);
-                       }
-                       else {
-                               hprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
-                       }
-               }
-       }
+       if (cache < 2) stuff_to_cookie(unset_cookies);
 
        if (do_htmlhead) {
                begin_burst();
index 34fe3934d1ec42e63b72c5ec0c5cc8116cdd01f1..778722d72410be491041b64d3fa60562add9b083 100644 (file)
@@ -583,13 +583,8 @@ void InitialiseSemaphores(void);
 void begin_critical_section(int which_one);
 void end_critical_section(int which_one);
 
-void stuff_to_cookie(char *cookie, size_t clen,
-               int session,
-               StrBuf *user,
-               StrBuf *pass,
-               StrBuf *room,
-               const char *language
-);
+void stuff_to_cookie(int unset_cookie);
+
 void cookie_to_stuff(StrBuf *cookie,
                int *session,
                StrBuf *user,