4 * Utility functions which convert the HTTP cookie format we use to and
5 * from user/password/room strings.
15 #include <sys/types.h>
17 #include <sys/socket.h>
20 #include <netinet/in.h>
33 typedef unsigned char byte; /* Byte type */
36 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
38 void stuff_to_cookie(char *cookie, int session,
39 char *user, char *pass, char *room)
44 sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room);
46 for (i=0; i<strlen(buf); ++i) {
47 sprintf(&cookie[i*2], "%02X", buf[i]);
51 int xtoi(char *in, size_t len)
54 while (isxdigit((byte) *in) && (len-- > 0)) {
57 val += isdigit((unsigned char)c)
59 : (tolower((unsigned char)c) - 'a' + 10);
65 * Extract all that fun stuff out of the cookie.
67 void cookie_to_stuff(char *cookie, int *session,
68 char *user, size_t user_len,
69 char *pass, size_t pass_len,
70 char *room, size_t room_len)
76 len = strlen(cookie) * 2 ;
77 for (i=0; i<len; ++i) {
78 buf[i] = xtoi(&cookie[i*2], 2);
83 *session = extract_int(buf, 0);
85 extract_token(user, buf, 1, '|', user_len);
87 extract_token(pass, buf, 2, '|', pass_len);
89 extract_token(room, buf, 3, '|', room_len);