handle server which aren't cgi "Status" aware
[cwebfiles.git] / cwebfiles.h
1 #include <stdlib.h>
2 #include <stdint.h>
3 #include <stdbool.h>
4
5 #define SESSION_FOLDER "/var/run/cwebfiles/sessions/"
6 #define SESSION_LENGTH 60 * 60 * 3 /* unit is seconds; we allow three-hour-sessions */
7
8 #define COOKIE_NAME "WEBFILESESS"
9 #define COOKIE_LENGTH 64
10
11 #define RANDDEV "/dev/urandom"
12
13 #define MYFAULT true
14 #define NOTMYFAULT false
15
16 struct cgi_serialized_session_status {
17   // "man useradd" says 32 chars is the length limit
18   char user_name[33];
19   uid_t uid;
20   time_t start_time;
21 };
22
23 extern struct cgi_serialized_session_status session;
24
25 void unhex(unsigned char *out, char *in, size_t in_len);
26 void hex(char *out, unsigned char *in, size_t in_len);
27 bool checkhex(char *p, size_t l);
28
29 int authenticate_by_cookie(char *cookie);
30 void persist_session(char *cookie);
31 void senderr(char *errmsg, bool myfault);
32 void grabrand(unsigned char *out, size_t len);
33 void login_and_setup();
34
35 #define OUTBUFSIZE 64*1024
36 #define FASTOUTPUT                             \
37   char outbuf[OUTBUFSIZE];                     \
38   setvbuf(stdout, outbuf, _IOFBF, OUTBUFSIZE); \
39