5 * \defgroup CookieConversion Grep Cookies
6 * Utility functions which convert the HTTP cookie format we use to and
7 * from user/password/room strings.
9 * \ingroup WebcitHttpServer
15 #define TRUE 1 /**< for sure? */
16 #define FALSE 0 /**< nope. */
18 typedef unsigned char byte; /**< Byte type */
22 * Pack all session info into one easy-to-digest cookie. Healthy and delicious!
23 * \param cookie cookie string to create???
24 * \param session the session we want to convert into a cookie
25 * \param user the user to be associated with the cookie
26 * \param pass his passphrase
27 * \param room the room he wants to enter
29 void stuff_to_cookie(char *cookie, int session,
30 char *user, char *pass, char *room)
36 sprintf(buf, "%d|%s|%s|%s|", session, user, pass, room);
39 for (i=0; i<len; ++i) {
40 sprintf(&cookie[i*2], "%02X", buf[i]);
45 * \brief Convert unpacked hex string to an integer
46 * \param in Input hex string
47 * \param len the length of the string
48 * \return the corrosponding integer value
50 int xtoi(char *in, size_t len)
54 while (isxdigit((byte) *in) && (len-- > 0))
58 val += isdigit((unsigned char)c)
60 : (tolower((unsigned char)c) - 'a' + 10);
66 * \brief Extract all that fun stuff out of the cookie.
67 * \param cookie the cookie string
68 * \param session the corrosponding session to return
69 * \param user the user string
70 * \param user_len the user stringlength
71 * \param pass the passphrase
72 * \param pass_len length of the passphrase string
73 * \param room the room he is in
74 * \param room_len the length of the room string
76 void cookie_to_stuff(char *cookie, int *session,
77 char *user, size_t user_len,
78 char *pass, size_t pass_len,
79 char *room, size_t room_len)
85 len = strlen(cookie) * 2 ;
86 for (i=0; i<len; ++i) {
87 buf[i] = xtoi(&cookie[i*2], 2);
93 extract_token(t, buf, 0, '|', sizeof t);
94 lprintf(9, "SESS: %s\n", t);
95 extract_token(t, buf, 1, '|', sizeof t);
96 lprintf(9, "USER: %s\n", t);
97 extract_token(t, buf, 2, '|', sizeof t);
98 lprintf(9, "PASS: %s\n", t);
99 extract_token(t, buf, 3, '|', sizeof t);
100 lprintf(9, "ROOM: %s\n", t);
104 *session = extract_int(buf, 0);
106 extract_token(user, buf, 1, '|', user_len);
108 extract_token(pass, buf, 2, '|', pass_len);
110 extract_token(room, buf, 3, '|', room_len);