3 * Copyright (c) 1996-2012 by the citadel.org team
5 * This program is open source software. You can redistribute it and/or
6 * modify it under the terms of the GNU General Public License, version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 * String to unset the cookie.
18 * Any date "in the past" will work, so I chose my birthday, right down to
19 * the exact minute. :)
21 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
22 typedef unsigned char byte; /* Byte type used by cookie_to_stuff() */
23 extern const char *get_selected_language(void);
26 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
28 void stuff_to_cookie(int unset_cookies) {
33 hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
36 StrBufAppendPrintf(WCC->HBuf, "Set-cookie: webcit=");
37 snprintf(buf, sizeof(buf), "%d", WCC->wc_session);
38 StrBufHexescAppend(WCC->HBuf, NULL, buf);
39 StrBufHexescAppend(WCC->HBuf, NULL, "|");
40 StrBufHexescAppend(WCC->HBuf, WCC->wc_username, NULL);
41 StrBufHexescAppend(WCC->HBuf, NULL, "|");
42 StrBufHexescAppend(WCC->HBuf, WCC->wc_password, NULL);
43 StrBufHexescAppend(WCC->HBuf, NULL, "|");
44 StrBufHexescAppend(WCC->HBuf, WCC->CurRoom.name, NULL);
45 StrBufHexescAppend(WCC->HBuf, NULL, "|");
46 StrBufHexescAppend(WCC->HBuf, NULL, get_selected_language());
47 StrBufHexescAppend(WCC->HBuf, NULL, "|");
49 if (server_cookie != NULL) {
50 StrBufAppendPrintf(WCC->HBuf, ";path=/ \r\n%s\r\n", server_cookie);
53 StrBufAppendBufPlain(WCC->HBuf, HKEY("; path=/\r\n"), 0);
59 * Extract all that fun stuff out of the cookie.
61 void cookie_to_stuff(StrBuf * cookie, int *session, StrBuf * user, StrBuf * pass, StrBuf * room, StrBuf * language) {
62 if (session != NULL) {
63 *session = StrBufExtract_int(cookie, 0, '|');
66 StrBufExtract_token(user, cookie, 1, '|');
69 StrBufExtract_token(pass, cookie, 2, '|');
72 StrBufExtract_token(room, cookie, 3, '|');
74 if (language != NULL) {
75 StrBufExtract_token(language, cookie, 4, '|');