* wDumpContent() is now responsible for </BODY></HTML> most of the
[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, int nofr) {
15         char buf[256];
16         int i;
17
18         sprintf(buf, "%d|%s|%s|%s|%d", session, user, pass, room, nofr);
19         strcpy(cookie, "");
20         
21         for (i=0; i<strlen(buf); ++i)
22                 sprintf(&cookie[strlen(cookie)], "%02X", buf[i]);
23
24 }
25
26
27 /*
28  * Extract all that fun stuff out of the cookie.
29  */
30 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room, int *nofr) {
31         char buf[256];
32         int i;
33
34         for (i=0; i<strlen(cookie); i=i+2) {
35                 sscanf(&cookie[i], "%02x", (unsigned int *)&buf[i/2]);
36                 buf[(i/2)+1] = 0;
37         }
38
39         if (session != NULL)    *session = extract_int(buf, 0);
40         if (user != NULL)       extract(user, buf, 1);
41         if (pass != NULL)       extract(pass, buf, 2);
42         if (room != NULL)       extract(room, buf, 3);
43         if (nofr != NULL)       *nofr = extract_int(buf, 4);
44 }