* Ditched the frames mode completely. It wasn't working properly in,
[citadel.git] / webcit / cookie_conversion.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <stdio.h>
4 #include <signal.h>
5 #include <sys/types.h>
6 #include <ctype.h>
7 #include <string.h>
8 #include "webcit.h"
9 #include "child.h"
10
11 /*
12  * Pack all session info into one easy-to-digest cookie.  Healthy and delicious!
13  */
14 void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room)
15 {
16         char buf[256];
17         int i;
18
19         sprintf(buf, "%d|%s|%s|%s", session, user, pass, room);
20         strcpy(cookie, "");
21
22         for (i = 0; i < strlen(buf); ++i)
23                 sprintf(&cookie[strlen(cookie)], "%02X", buf[i]);
24
25 }
26
27
28 /*
29  * Extract all that fun stuff out of the cookie.
30  */
31 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
32 {
33         char buf[256];
34         int i;
35
36         for (i = 0; i < strlen(cookie); i = i + 2) {
37                 sscanf(&cookie[i], "%02x", (unsigned int *) &buf[i / 2]);
38                 buf[(i / 2) + 1] = 0;
39         }
40
41         if (session != NULL)
42                 *session = extract_int(buf, 0);
43         if (user != NULL)
44                 extract(user, buf, 1);
45         if (pass != NULL)
46                 extract(pass, buf, 2);
47         if (room != NULL)
48                 extract(room, buf, 3);
49 }