* Added the ability to compose messages with file attachments uploaded from
[citadel.git] / webcit / cookie_conversion.c
1
2 #include <ctype.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <sys/types.h>
9 #include <sys/wait.h>
10 #include <sys/socket.h>
11 #include <sys/time.h>
12 #include <limits.h>
13 #include <netinet/in.h>
14 #include <netdb.h>
15 #include <string.h>
16 #include <pwd.h>
17 #include <errno.h>
18 #include <stdarg.h>
19 #include <pthread.h>
20 #include <signal.h>
21 #include "webcit.h"
22
23 #define TRUE  1
24 #define FALSE 0
25
26 typedef unsigned char byte;           /* Byte type */
27
28 /*
29  * Pack all session info into one easy-to-digest cookie.  Healthy and delicious!
30  */
31 void stuff_to_cookie(char *cookie, int session, char *user, char *pass, char *room)
32 {
33         char buf[SIZ];
34
35         sprintf(buf, "%d|%s|%s|%s", session, user, pass, room);
36         CtdlEncodeBase64(cookie, buf, strlen(buf));
37 }
38
39
40 /*
41  * Extract all that fun stuff out of the cookie.
42  */
43 void cookie_to_stuff(char *cookie, int *session, char *user, char *pass, char *room)
44 {
45         char buf[SIZ];
46
47         CtdlDecodeBase64(buf, cookie, strlen(cookie));
48
49         if (session != NULL)
50                 *session = extract_int(buf, 0);
51         if (user != NULL)
52                 extract(user, buf, 1);
53         if (pass != NULL)
54                 extract(pass, buf, 2);
55         if (room != NULL)
56                 extract(room, buf, 3);
57 }