7 typedef unsigned char byte; /* Byte type used by cookie_to_stuff() */
10 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
12 void stuff_to_cookie(char *cookie, size_t clen, int session,
13 StrBuf *user, StrBuf *pass, StrBuf *room, char *language)
19 len = snprintf(buf, SIZ, "%d|%s|%s|%s|%s|",
28 for (i=0; (i < len) && (i * 2 < clen); ++i) {
29 snprintf(&cookie[i*2], clen - i * 2, "%02X", buf[i]);
34 * Convert unpacked hex string to an integer
36 int xtoi(const char *in, size_t len)
40 while (!IsEmptyStr(in) && isxdigit((byte) *in) && (len-- > 0))
44 if (!isdigit((unsigned char)c)) {
45 c = tolower((unsigned char) c);
46 if ((c < 'a') || (c > 'f'))
57 * Extract all that fun stuff out of the cookie.
59 void cookie_to_stuff(StrBuf *cookie,
66 if (session != NULL) {
67 *session = StrBufExtract_int(cookie, 0, '|');
70 StrBufExtract_token(user, cookie, 1, '|');
73 StrBufExtract_token(pass, cookie, 2, '|');
76 StrBufExtract_token(room, cookie, 3, '|');
78 if (language != NULL) {
79 StrBufExtract_token(language, cookie, 4, '|');