* Moved to the new string tokenizer API
[citadel.git] / webcit / webcit.h
1 /* $Id$ */
2
3 #ifdef HAVE_ZLIB_H
4 #include <zlib.h>
5 #endif
6
7 #ifdef HAVE_ICAL_H
8 #ifdef HAVE_LIBICAL
9 #define WEBCIT_WITH_CALENDAR_SERVICE 1
10 #endif
11 #endif
12
13 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
14 #include <ical.h>
15 #endif
16
17 #ifdef HAVE_OPENSSL
18 /* Work around RedHat's b0rken OpenSSL includes */
19 #define OPENSSL_NO_KRB5
20 #include <openssl/ssl.h>
21 #include <openssl/err.h>
22 #include <openssl/rand.h>
23 #endif
24
25 #define CALENDAR_ROOM_NAME      "Calendar"
26 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
27
28 #define SIZ                     4096            /* generic buffer size */
29
30 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
31
32 #define SLEEPING                180             /* TCP connection timeout */
33 #define WEBCIT_TIMEOUT          900             /* WebCit session timeout */
34 #define PORT_NUM                2000            /* port number to listen on */
35 #define SERVER                  "WebCit v6.10"  /* who's in da house */
36 #define DEVELOPER_ID            0
37 #define CLIENT_ID               4
38 #define CLIENT_VERSION          610             /* This version of WebCit */
39 #define MINIMUM_CIT_VERSION     640             /* min required Citadel vers */
40 #define DEFAULT_HOST            "localhost"     /* Default Citadel server */
41 #define DEFAULT_PORT            "504"
42 #define LB                      (1)             /* Internal escape chars */
43 #define RB                      (2)
44 #define QU                      (3)
45 #define TARGET                  "webcit01"      /* Target for inline URL's */
46 #define HOUSEKEEPING            15              /* Housekeeping frequency */
47 #define MIN_WORKER_THREADS      5
48 #define MAX_WORKER_THREADS      250
49 #define LISTEN_QUEUE_LENGTH     100             /* listen() backlog queue */
50
51 #define USERCONFIGROOM          "My Citadel Config"
52 #define DEFAULT_MAXMSGS         20
53
54
55 /*
56  * Room flags (from Citadel)
57  *
58  * bucket one...
59  */
60 #define QR_PERMANENT    1               /* Room does not purge        */
61 #define QR_INUSE        2               /* Set if in use, clear if avail    */
62 #define QR_PRIVATE      4               /* Set for any type of private room */
63 #define QR_PASSWORDED   8               /* Set if there's a password too    */
64 #define QR_GUESSNAME    16              /* Set if it's a guessname room     */
65 #define QR_DIRECTORY    32              /* Directory room                  */
66 #define QR_UPLOAD       64              /* Allowed to upload            */
67 #define QR_DOWNLOAD     128             /* Allowed to download        */
68 #define QR_VISDIR       256             /* Visible directory            */
69 #define QR_ANONONLY     512             /* Anonymous-Only room        */
70 #define QR_ANONOPT      1024            /* Anonymous-Option room            */
71 #define QR_NETWORK      2048            /* Shared network room        */
72 #define QR_PREFONLY     4096            /* Preferred status needed to enter */
73 #define QR_READONLY     8192            /* Aide status required to post     */
74 #define QR_MAILBOX      16384           /* Set if this is a private mailbox */
75
76 /*
77  * bucket two...
78  */
79 #define QR2_SYSTEM      1               /* System room; hide by default     */
80 #define QR2_SELFLIST    2               /* Self-service mailing list mgmt   */
81
82
83 #define UA_KNOWN                2
84 #define UA_GOTOALLOWED    4
85 #define UA_HASNEWMSGS      8
86 #define UA_ZAPPED              16
87
88
89
90
91
92
93 struct httprequest {
94         struct httprequest *next;
95         char line[SIZ];
96 };
97
98 struct urlcontent {
99         struct urlcontent *next;
100         char url_key[32];
101         char *url_data;
102 };
103
104 struct serv_info {
105         int serv_pid;
106         char serv_nodename[32];
107         char serv_humannode[64];
108         char serv_fqdn[64];
109         char serv_software[64];
110         int serv_rev_level;
111         char serv_bbs_city[64];
112         char serv_sysadm[64];
113         char serv_moreprompt[SIZ];
114         int serv_ok_floors;
115         int serv_supports_ldap;
116 };
117
118
119
120 /*
121  * This struct holds a list of rooms for <G>oto operations.
122  */
123 struct march {
124         struct march *next;
125         char march_name[128];
126         int march_floor;
127         int march_order;
128 };
129
130 /* 
131  * This struct holds a list of rooms for client display.
132  * (oooh, a tree!)
133  */
134 struct roomlisting {
135         struct roomlisting *lnext;
136         struct roomlisting *rnext;
137         char rlname[128];
138         unsigned rlflags;
139         int rlfloor;
140         int rlorder;
141 };
142
143
144
145 /*
146  * Dynamic content for variable substitution in templates
147  */
148 struct wcsubst {
149         struct wcsubst *next;
150         int wcs_type;
151         char wcs_key[32];
152         void *wcs_value;
153         void (*wcs_function)(void);
154 };
155
156 /*
157  * Values for wcs_type
158  */
159 enum {
160         WCS_STRING,
161         WCS_FUNCTION,
162         WCS_SERVCMD
163 };
164
165
166 struct wc_attachment {
167         struct wc_attachment *next;
168         size_t length;
169         char content_type[SIZ];
170         char filename[SIZ];
171         char *data;
172 };
173
174 /*
175  * One of these is kept for each active Citadel session.
176  * HTTP transactions are bound to one at a time.
177  */
178 struct wcsession {
179         struct wcsession *next;         /* Linked list */
180         int wc_session;                 /* WebCit session ID */
181         char wc_username[SIZ];
182         char wc_password[SIZ];
183         char wc_roomname[SIZ];
184         int connected;
185         int logged_in;
186         int axlevel;
187         int is_aide;
188         int is_room_aide;
189         int http_sock;
190         int serv_sock;
191         int chat_sock;
192         unsigned room_flags;
193         int wc_view;
194         int wc_default_view;
195         int wc_floor;
196         char ugname[128];
197         long uglsn;
198         int upload_length;
199         char *upload;
200         char upload_filename[SIZ];
201         char upload_content_type[SIZ];
202         int new_mail;
203         int remember_new_mail;
204         int need_regi;                  /* This user needs to register. */
205         int need_vali;                  /* New users require validation. */
206         char cs_inet_email[SIZ];        /* User's preferred Internet addr. */
207         pthread_mutex_t SessionMutex;   /* mutex for exclusive access */
208         time_t lastreq;                 /* Timestamp of most recent HTTP */
209         int killthis;                   /* Nonzero == purge this session */
210         struct march *march;            /* march mode room list */
211         char reply_to[SIZ];             /* reply-to address */
212         long msgarr[4096];              /* for read operations */
213         int is_wap;                     /* Client is a WAP gateway */
214         struct urlcontent *urlstrings;
215         int HaveInstantMessages;        /* Nonzero if incoming msgs exist */
216         struct wcsubst *vars;
217         char this_page[SIZ];            /* address of current page */
218         char http_host[SIZ];            /* HTTP Host: header */
219         char *preferences;
220 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
221         struct disp_cal {
222                 icalcomponent *cal;             /* cal items for display */
223                 long cal_msgnum;                /* cal msgids for display */
224         } *disp_cal;
225         int num_cal;
226 #endif
227         struct wc_attachment *first_attachment;
228         char ImportantMessage[SIZ];
229         char last_chat_user[SIZ];
230         int ctdl_pid;                   /* Session ID on the Citadel server */
231         char httpauth_user[SIZ];        /* only for GroupDAV sessions */
232         char httpauth_pass[SIZ];        /* only for GroupDAV sessions */
233
234         size_t burst_len;
235         char *burst;
236         int gzip_ok;                    /* Nonzero if Accept-encoding: gzip */
237 };
238
239 #define num_parms(source)               num_tokens(source, '|')
240
241 /* Per-session data */
242 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
243 extern pthread_key_t MyConKey;
244
245 /* Per-thread SSL context */
246 #ifdef HAVE_OPENSSL
247 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
248 extern pthread_key_t ThreadSSL;
249 #endif
250
251 struct serv_info serv_info;
252 extern char floorlist[128][SIZ];
253 extern char *axdefs[];
254 extern char *ctdlhost, *ctdlport;
255 extern char *server_cookie;
256 extern int is_https;
257 extern int setup_wizard;
258 extern char wizard_filename[];
259 void do_setup_wizard(void);
260
261 void stuff_to_cookie(char *cookie, int session,
262                         char *user, char *pass, char *room);
263 void cookie_to_stuff(char *cookie, int *session,
264                 char *user, size_t user_len,
265                 char *pass, size_t pass_len,
266                 char *room, size_t room_len);
267 void locate_host(char *, int);
268 void become_logged_in(char *, char *, char *);
269 void do_login(void);
270 void display_login(char *mesg);
271 void do_welcome(void);
272 void do_logout(void);
273 void display_main_menu(void);
274 void display_aide_menu(void);
275 void display_advanced_menu(void);
276 void slrp_highest(void);
277 void gotonext(void);
278 void ungoto(void);
279 void get_serv_info(char *, char *);
280 int uds_connectsock(char *);
281 int tcp_connectsock(char *, char *);
282 void serv_gets(char *strbuf);
283 void serv_puts(char *string);
284 void whobbs(void);
285 void fmout(FILE *fp, char *align);
286 void wDumpContent(int);
287 void serv_printf(const char *format,...);
288 char *bstr(char *key);
289 void urlesc(char *, char *);
290 void urlescputs(char *);
291 void jsesc(char *, char *);
292 void jsescputs(char *);
293 void output_headers(    int do_httpheaders,
294                         int do_htmlhead,
295                         int do_room_banner,
296                         int unset_cookies,
297                         int refresh30,
298                         int suppress_check,
299                         int cache);
300 void wprintf(const char *format,...);
301 void output_static(char *what);
302 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks);
303 void escputs(char *strbuf);
304 void url(char *buf);
305 void escputs1(char *strbuf, int nbsp, int nolinebreaks);
306 void msgesc(char *target, char *strbuf);
307 void msgescputs(char *strbuf);
308 int extract_int(const char *source, int parmnum);
309 long extract_long(const char *source, int parmnum);
310 void stripout(char *str, char leftboundary, char rightboundary);
311 void dump_vars(void);
312 void embed_main_menu(void);
313 void serv_read(char *buf, int bytes);
314 int haschar(char *, char);
315 void readloop(char *oper);
316 void text_to_server(char *ptr, int convert_to_html);
317 void display_enter(void);
318 void post_message(void);
319 void confirm_delete_msg(void);
320 void delete_msg(void);
321 void confirm_move_msg(void);
322 void move_msg(void);
323 void userlist(void);
324 void showuser(void);
325 void display_page(void);
326 void page_user(void);
327 void do_chat(void);
328 void display_private(char *rname, int req_pass);
329 void goto_private(void);
330 void zapped_list(void);
331 void display_zap(void);
332 void zap(void);
333 void display_success(char *);
334 void display_entroom(void);
335 void entroom(void);
336 void display_editroom(void);
337 void netedit(void);
338 void editroom(void);
339 void display_whok(void);
340 void do_invt_kick(void);
341 void server_to_text(void);
342 void save_edit(char *description, char *enter_cmd, int regoto);
343 void display_edit(char *description, char *check_cmd,
344                   char *read_cmd, char *save_cmd, int with_room_banner);
345 void gotoroom(char *gname);
346 void confirm_delete_room(void);
347 void delete_room(void);
348 void validate(void);
349 void display_graphics_upload(char *, char *, char *);
350 void do_graphics_upload(char *upl_cmd);
351 void serv_read(char *buf, int bytes);
352 void serv_gets(char *strbuf);
353 void serv_write(char *buf, int nbytes);
354 void serv_puts(char *string);
355 void serv_printf(const char *format,...);
356 void load_floorlist(void);
357 void display_reg(int);
358 void display_changepw(void);
359 void changepw(void);
360 void display_edit_node(void);
361 void edit_node(void);
362 void display_netconf(void);
363 void display_confirm_delete_node(void);
364 void delete_node(void);
365 void display_add_node(void);
366 void add_node(void);
367 void terminate_session(void);
368 void edit_me(void);
369 void display_siteconfig(void);
370 void siteconfig(void);
371 void display_generic(void);
372 void do_generic(void);
373 void display_menubar(int);
374 void smart_goto(char *);
375 void worker_entry(void);
376 void session_loop(struct httprequest *);
377 void fmt_date(char *buf, time_t thetime);
378 void fmt_time(char *buf, time_t thetime);
379 void httpdate(char *buf, time_t thetime);
380 void end_webcit_session(void);
381 void page_popup(void);
382 void chat_recv(void);
383 void chat_send(void);
384 void http_redirect(char *);
385 void clear_local_substs(void);
386 void svprintf(char *keyname, int keytype, const char *format,...);
387 void svcallback(char *keyname, void (*fcn_ptr)() );
388 void do_template(void *templatename);
389 int lingering_close(int fd);
390 char *memreadline(char *start, char *buf, int maxlen);
391 int num_tokens (char *source, char tok);
392 void extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
393 void remove_token(char *source, int parmnum, char separator);
394 char *load_mimepart(long msgnum, char *partnum);
395 int pattern2(char *search, char *patn);
396 void do_edit_vcard(long, char *, char *);
397 void edit_vcard(void);
398 void submit_vcard(void);
399 void striplt(char *);
400 void select_user_to_edit(char *message, char *preselect);
401 void delete_user(char *);
402 void display_edituser(char *who, int is_new);
403 void create_user(void);
404 void edituser(void);
405 void do_change_view(int);
406 void change_view(void);
407 void folders(void);
408 void do_stuff_to_msgs(void);
409 void load_preferences(void);
410 void save_preferences(void);
411 void get_preference(char *key, char *value, size_t value_len);
412 void set_preference(char *key, char *value);
413 void knrooms(void);
414 int is_msg_in_mset(char *mset, long msgnum);
415 char *safestrncpy(char *dest, const char *src, size_t n);
416 void display_addressbook(long msgnum, char alpha);
417 void offer_start_page(void);
418 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext);
419 void change_start_page(void);
420 void output_html(void);
421 void display_floorconfig(char *);
422 void delete_floor(void);
423 void create_floor(void);
424 void rename_floor(void);
425 void do_listsub(void);
426 void toggle_self_service(void);
427 void summary(void);
428 ssize_t write(int fd, const void *buf, size_t count);
429 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
430 void display_calendar(long msgnum);
431 void display_task(long msgnum);
432 void display_note(long msgnum);
433 void do_calendar_view(void);
434 void do_tasks_view(void);
435 void free_calendar_buffer(void);
436 void calendar_summary_view(void);
437 int load_msg_ptrs(char *servcmd);
438 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
439 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
440 void free_attachments(struct wcsession *sess);
441 void set_room_policy(void);
442 void display_inetconf(void);
443 void save_inetconf(void);
444 void generate_uuid(char *);
445
446
447 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
448 void display_edit_task(void);
449 void save_task(void);
450 void display_edit_event(void);
451 void save_event(void);
452 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
453 struct icaltimetype icaltime_from_webform(char *prefix);
454 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
455 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
456 void respond_to_request(void);
457 void handle_rsvp(void);
458 void ical_dezonify(icalcomponent *cal);
459 void partstat_as_string(char *buf, icalproperty *attendee);
460 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
461 void check_attendee_availability(icalcomponent *supplied_vevent);
462 void do_freebusy(char *req);
463 #endif
464
465 extern char *months[];
466 extern char *days[];
467 void read_server_binary(char *buffer, size_t total_len);
468 char *read_server_text(void);
469 int goto_config_room(void);
470 long locate_user_vcard(char *username, long usernum);
471 void sleeeeeeeeeep(int);
472 void http_transmit_thing(char *thing, size_t length, char *content_type,
473                          int is_static);
474 void unescape_input(char *buf);
475 void do_iconbar(void);
476 void display_customize_iconbar(void);
477 void commit_iconbar(void);
478 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
479 void spawn_another_worker_thread(void);
480
481 void embed_room_banner(char *, int);
482 /* navbar types that can be passed to embed_room_banner */
483 enum {
484         navbar_none,
485         navbar_default
486 };
487
488
489 #ifdef HAVE_OPENSSL
490 void init_ssl(void);
491 void endtls(void);
492 void ssl_lock(int mode, int n, const char *file, int line);
493 int starttls(int sock);
494 extern SSL_CTX *ssl_ctx;  
495 int client_read_ssl(char *buf, int bytes, int timeout);
496 void client_write_ssl(char *buf, int nbytes);
497 #endif
498
499 #ifdef HAVE_ZLIB
500 #include <zlib.h>
501 int ZEXPORT compress_gzip(Bytef * dest, uLongf * destLen,
502                           const Bytef * source, uLong sourceLen, int level);
503 #endif
504
505
506 void begin_burst(void);
507 void end_burst(void);
508
509 extern char *ascmonths[];
510 void http_datestring(char *buf, size_t n, time_t xtime);
511
512
513 /* Views (from citadel.h) */
514 #define VIEW_BBS                0       /* Traditional Citadel BBS view */
515 #define VIEW_MAILBOX            1       /* Mailbox summary */
516 #define VIEW_ADDRESSBOOK        2       /* Address book view */
517 #define VIEW_CALENDAR           3       /* Calendar view */
518 #define VIEW_TASKS              4       /* Tasks view */
519 #define VIEW_NOTES              5       /* Notes view */
520
521
522 /* These should be empty, but we have them for testing */
523 #define DEFAULT_HTTPAUTH_USER   ""
524 #define DEFAULT_HTTPAUTH_PASS   ""