From 553d86929127eaedf0d7c9e8527447e99faf1fc9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 10 Jan 2010 21:17:44 +0000 Subject: [PATCH] * use the HexEscAppend thing instead of printf appending... * move some cookie logic over --- webcit/cookie_conversion.c | 48 +++++++++++++++++++++++++++----------- webcit/webcit.c | 30 +----------------------- webcit/webcit.h | 9 ++----- 3 files changed, 37 insertions(+), 50 deletions(-) diff --git a/webcit/cookie_conversion.c b/webcit/cookie_conversion.c index 1a3465d34..23a751f6a 100644 --- a/webcit/cookie_conversion.c +++ b/webcit/cookie_conversion.c @@ -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); + } } } diff --git a/webcit/webcit.c b/webcit/webcit.c index d27cd782a..59347777d 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -13,12 +13,6 @@ #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(); diff --git a/webcit/webcit.h b/webcit/webcit.h index 34fe3934d..778722d72 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -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, -- 2.30.2