2 * Copyright (c) 1996-2010 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 as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * String to unset the cookie.
23 * Any date "in the past" will work, so I chose my birthday, right down to
24 * the exact minute. :)
26 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
27 typedef unsigned char byte; /* Byte type used by cookie_to_stuff() */
28 extern const char *get_selected_language(void);
31 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
33 void stuff_to_cookie(int unset_cookies)
39 hprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
43 StrBufAppendPrintf(WCC->HBuf, "Set-cookie: webcit=");
44 snprintf(buf, sizeof(buf), "%d", WCC->wc_session);
45 StrBufHexescAppend(WCC->HBuf, NULL, buf);
46 StrBufHexescAppend(WCC->HBuf, NULL, "|");
47 StrBufHexescAppend(WCC->HBuf, WCC->wc_username, NULL);
48 StrBufHexescAppend(WCC->HBuf, NULL, "|");
49 StrBufHexescAppend(WCC->HBuf, WCC->wc_password, NULL);
50 StrBufHexescAppend(WCC->HBuf, NULL, "|");
51 StrBufHexescAppend(WCC->HBuf, WCC->CurRoom.name, NULL);
52 StrBufHexescAppend(WCC->HBuf, NULL, "|");
53 StrBufHexescAppend(WCC->HBuf, NULL, get_selected_language());
54 StrBufHexescAppend(WCC->HBuf, NULL, "|");
56 if (server_cookie != NULL) {
57 StrBufAppendPrintf(WCC->HBuf,
62 StrBufAppendBufPlain(WCC->HBuf,
63 HKEY("; path=/\r\n"), 0);
69 * Extract all that fun stuff out of the cookie.
71 void cookie_to_stuff(StrBuf *cookie,
78 if (session != NULL) {
79 *session = StrBufExtract_int(cookie, 0, '|');
82 StrBufExtract_token(user, cookie, 1, '|');
85 StrBufExtract_token(pass, cookie, 2, '|');
88 StrBufExtract_token(room, cookie, 3, '|');
90 if (language != NULL) {
91 StrBufExtract_token(language, cookie, 4, '|');