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