10 #include <sys/socket.h>
13 #include <netinet/in.h>
26 typedef unsigned char byte; /* Byte type */
29 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
31 void stuff_to_cookie(char *cookie, int session,
32 char *user, char *pass, char *room)
37 sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room);
39 for (i=0; i<strlen(buf); ++i) {
40 sprintf(&cookie[i*2], "%02X", buf[i]);
44 int xtoi(char *in, size_t len)
47 while (isxdigit((byte) *in) && (len-- > 0)) {
50 val += isdigit((unsigned char)c)
52 : (tolower((unsigned char)c) - 'a' + 10);
58 * Extract all that fun stuff out of the cookie.
60 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
66 len = strlen(cookie) * 2 ;
67 for (i=0; i<len; ++i) {
68 buf[i] = xtoi(&cookie[i*2], 2);
73 *session = extract_int(buf, 0);
75 extract(user, buf, 1);
77 extract(pass, buf, 2);
79 extract(room, buf, 3);