4 * Utility functions which convert the HTTP cookie format we use to and
5 * from user/password/room strings.
14 typedef unsigned char byte; /* Byte type */
17 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
19 void stuff_to_cookie(char *cookie, int session,
20 char *user, char *pass, char *room)
25 sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room);
27 for (i=0; i<strlen(buf); ++i) {
28 sprintf(&cookie[i*2], "%02X", buf[i]);
32 int xtoi(char *in, size_t len)
35 while (isxdigit((byte) *in) && (len-- > 0)) {
38 val += isdigit((unsigned char)c)
40 : (tolower((unsigned char)c) - 'a' + 10);
46 * Extract all that fun stuff out of the cookie.
48 void cookie_to_stuff(char *cookie, int *session,
49 char *user, size_t user_len,
50 char *pass, size_t pass_len,
51 char *room, size_t room_len)
57 len = strlen(cookie) * 2 ;
58 for (i=0; i<len; ++i) {
59 buf[i] = xtoi(&cookie[i*2], 2);
64 *session = extract_int(buf, 0);
66 extract_token(user, buf, 1, '|', user_len);
68 extract_token(pass, buf, 2, '|', pass_len);
70 extract_token(room, buf, 3, '|', room_len);