* change_start_page(), LoadStartpage(): check whether the startpage is allowed by...
[citadel.git] / webcit / webcit.h
1 /* $Id$
2  *
3  * Copyright (c) 1987-2010 by the citadel.org team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include "sysdep.h"
21 #include <sys/select.h>
22 #include <ctype.h>
23 #include <stdlib.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #include <stdio.h>
28 #ifdef HAVE_FCNTL_H
29 #include <fcntl.h>
30 #endif
31 #include <signal.h>
32 #include <sys/types.h>
33 #include <sys/wait.h>
34 #include <sys/socket.h>
35 #ifdef HAVE_SYS_TIME_H
36 #include <sys/time.h>
37 #endif
38 #include <sys/stat.h>
39 #ifdef HAVE_LIMITS_H
40 #include <limits.h>
41 #endif
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <sys/un.h>
45 #include <netdb.h>
46 #include <sys/poll.h>
47 #include <string.h>
48 #include <pwd.h>
49 #include <errno.h>
50 #include <stdarg.h>
51 #include <pthread.h>
52 #include <signal.h>
53 #include <sys/utsname.h>
54 #include <libcitadel.h>
55
56 #ifndef INADDR_NONE
57 #define INADDR_NONE 0xffffffff
58 #endif
59
60 #ifdef HAVE_ICONV
61 #include <iconv.h>
62 #endif
63
64 #ifdef ENABLE_NLS
65 #ifdef HAVE_XLOCALE_H
66 #include <xlocale.h>
67 #endif
68 #include <libintl.h>
69 #include <locale.h>
70 #define _(string)       gettext(string)
71 #else
72 #define _(string)       (string)
73 #endif
74
75 #define IsEmptyStr(a) ((a)[0] == '\0')
76 /*
77  * Uncomment to dump an HTTP trace to stderr
78 #define HTTP_TRACING 1
79  */
80
81 #ifdef HTTP_TRACING
82 #undef HAVE_ZLIB_H
83 #undef HAVE_ZLIB
84 #endif
85
86 #ifdef HAVE_ZLIB_H
87 #include <zlib.h>
88 #endif
89
90 #include <libical/ical.h>
91
92 #undef PACKAGE
93 #undef VERSION
94 #undef PACKAGE_NAME
95 #undef PACKAGE_STRING
96 #undef PACKAGE_TARNAME
97 #undef PACKAGE_VERSION
98 #undef PACKAGE_BUGREPORT
99 #include "sysdep.h"
100
101 #include "subst.h"
102 #include "messages.h"
103 #include "paramhandling.h"
104 #include "roomops.h"
105 #include "preferences.h"
106
107 #ifdef HAVE_OPENSSL
108 /* Work around RedHat's b0rken OpenSSL includes */
109 #define OPENSSL_NO_KRB5
110 #include <openssl/ssl.h>
111 #include <openssl/err.h>
112 #include <openssl/rand.h>
113 extern char *ssl_cipher_list;
114 #define DEFAULT_SSL_CIPHER_LIST "DEFAULT"       /* See http://openssl.org/docs/apps/ciphers.html */
115 #endif
116
117
118 #define CALENDAR_ROOM_NAME      "Calendar"
119 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
120
121 #define SIZ                     4096            /* generic buffer size */
122
123 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
124
125 #define SLEEPING                180             /* TCP connection timeout */
126 #define WEBCIT_TIMEOUT          900             /* WebCit session timeout */
127 #define PORT_NUM                2000            /* port number to listen on */
128 #define DEVELOPER_ID            0
129 #define CLIENT_ID               4
130 #define CLIENT_VERSION          780             /* This version of WebCit */
131 #define MINIMUM_CIT_VERSION     780             /* min required Citadel ver */
132 #define LIBCITADEL_MIN          780             /* min required libcitadel ver */
133 #define DEFAULT_HOST            "localhost"     /* Default Citadel server */
134 #define DEFAULT_PORT            "504"
135 #define TARGET                  "webcit01"      /* Target for inline URL's */
136 #define HOUSEKEEPING            15              /* Housekeeping frequency */
137 #define MIN_WORKER_THREADS      5
138 #define MAX_WORKER_THREADS      250
139 #define LISTEN_QUEUE_LENGTH     100             /* listen() backlog queue */
140
141 #define USERCONFIGROOM          "My Citadel Config"
142 #define DEFAULT_MAXMSGS         20
143
144
145 #ifdef LIBCITADEL_VERSION_NUMBER
146 #if LIBCITADEL_VERSION_NUMBER < LIBCITADEL_MIN
147 #error libcitadel is too old.  Please upgrade it before continuing.
148 #endif
149 #endif
150
151
152 /*
153  * Room flags (from Citadel)
154  *
155  * bucket one...
156  */
157 #define QR_PERMANENT    1               /* Room does not purge          */
158 #define QR_INUSE        2               /* Set if in use, clear if avail        */
159 #define QR_PRIVATE      4               /* Set for any type of private room     */
160 #define QR_PASSWORDED   8               /* Set if there's a password too        */
161 #define QR_GUESSNAME    16              /* Set if it's a guessname room */
162 #define QR_DIRECTORY    32              /* Directory room                       */
163 #define QR_UPLOAD       64              /* Allowed to upload                    */
164 #define QR_DOWNLOAD     128             /* Allowed to download          */
165 #define QR_VISDIR       256             /* Visible directory                    */
166 #define QR_ANONONLY     512             /* Anonymous-Only room          */
167 #define QR_ANONOPT      1024            /* Anonymous-Option room                */
168 #define QR_NETWORK      2048            /* Shared network room          */
169 #define QR_PREFONLY     4096            /* Preferred status needed to enter     */
170 #define QR_READONLY     8192            /* Aide status required to post */
171 #define QR_MAILBOX      16384           /* Set if this is a private mailbox     */
172
173 /*
174  * bucket two...
175  */
176 #define QR2_SYSTEM      1               /* System room; hide by default */
177 #define QR2_SELFLIST    2               /* Self-service mailing list mgmt       */
178 #define QR2_COLLABDEL   4               /* Anyone who can post can also delete*/
179 #define QR2_SUBJECTREQ  8               /* Subject strongly recommended */
180 #define QR2_SMTP_PUBLIC 16              /* smtp public postable room */
181 #define QR2_MODERATED   32              /* Listservice aide has to permit posts  */
182
183 /*
184  * user/room access
185  */
186 #define UA_KNOWN        2
187 #define UA_GOTOALLOWED  4
188 #define UA_HASNEWMSGS   8
189 #define UA_ZAPPED       16
190 #define UA_POSTALLOWED          32
191 #define UA_ADMINALLOWED         64
192 #define UA_DELETEALLOWED        128
193 #define UA_ISTRASH              256 /* Only available in room view... */
194
195
196 /*
197  * User flags (from Citadel)
198  */
199 #define US_NEEDVALID    1               /* User needs to be validated           */
200 #define US_PERM         4               /* Permanent user                       */
201 #define US_LASTOLD      16              /* Print last old message with new      */
202 #define US_EXPERT       32              /* Experienced user                     */
203 #define US_UNLISTED     64              /* Unlisted userlog entry               */
204 #define US_NOPROMPT     128             /* Don't prompt after each message      */
205 #define US_PROMPTCTL    256             /* <N>ext & <S>top work at prompt       */
206 #define US_DISAPPEAR    512             /* Use "disappearing msg prompts"       */
207 #define US_REGIS        1024            /* Registered user                      */
208 #define US_PAGINATOR    2048            /* Pause after each screen of text      */
209 #define US_INTERNET     4096            /* Internet mail privileges             */
210 #define US_FLOORS       8192            /* User wants to see floors             */
211 #define US_COLOR        16384           /* User wants ANSI color support        */
212 #define US_USER_SET     (US_LASTOLD | US_EXPERT | US_UNLISTED | \
213                         US_NOPROMPT | US_DISAPPEAR | US_PAGINATOR | \
214                         US_FLOORS | US_COLOR | US_PROMPTCTL )
215
216
217
218
219 #define MAJORCODE(a) (((int)(a / 100) ) * 100)
220
221 #define LISTING_FOLLOWS 100
222 #define CIT_OK          200     
223 #define MORE_DATA       300
224 #define SEND_LISTING    400
225 #define ERROR           500
226 #define BINARY_FOLLOWS  600
227 #define SEND_BINARY     700
228 #define START_CHAT_MODE 800
229 #define ASYNC_MSG       900
230
231 #define MINORCODE(a) (a % 100)
232 #define ASYNC_GEXP                      02      
233 #define INTERNAL_ERROR                  10      
234 #define TOO_BIG                         11      
235 #define ILLEGAL_VALUE                   12      
236 #define NOT_LOGGED_IN                   20      
237 #define CMD_NOT_SUPPORTED               30      
238 #define SERVER_SHUTTING_DOWN            31      
239 #define PASSWORD_REQUIRED               40      
240 #define ALREADY_LOGGED_IN               41      
241 #define USERNAME_REQUIRED               42      
242 #define HIGHER_ACCESS_REQUIRED          50      
243 #define MAX_SESSIONS_EXCEEDED           51      
244 #define RESOURCE_BUSY                   52      
245 #define RESOURCE_NOT_OPEN               53      
246 #define NOT_HERE                        60      
247 #define INVALID_FLOOR_OPERATION         61      
248 #define NO_SUCH_USER                    70      
249 #define FILE_NOT_FOUND                  71      
250 #define ROOM_NOT_FOUND                  72      
251 #define NO_SUCH_SYSTEM                  73      
252 #define ALREADY_EXISTS                  74      
253 #define MESSAGE_NOT_FOUND               75
254 /*
255  * NLI is the string that shows up in a who's online listing for sessions
256  * that are active, but for which no user has yet authenticated.
257  */
258 #define NLI     "(not logged in)"
259
260 /*
261  * Expiry policy for the autopurger
262  */
263 #define EXPIRE_NEXTLEVEL        0       /* Inherit expiration policy    */
264 #define EXPIRE_MANUAL           1       /* Don't expire messages at all */
265 #define EXPIRE_NUMMSGS          2       /* Keep only latest n messages  */
266 #define EXPIRE_AGE              3       /* Expire messages after n days */
267 typedef struct __ExpirePolicy {
268         int loaded; /* has this been loaded from the server? */
269         int expire_mode;
270         int expire_value;
271 }ExpirePolicy;
272 void LoadExpirePolicy(GPEXWhichPolicy which);
273 void SaveExpirePolicyFromHTTP(GPEXWhichPolicy which);
274
275 /*
276  * Linked list of session variables encoded in an x-www-urlencoded content type
277  */
278 typedef struct urlcontent urlcontent;
279 struct urlcontent {
280         char url_key[32];               /* key */
281         StrBuf *url_data;               /* value */
282 };
283
284 /*
285  * Information about the Citadel server to which we are connected
286  */ 
287 typedef struct _serv_info {
288         int serv_pid;                   /* Process ID of the Citadel server */
289         StrBuf *serv_nodename;          /* Node name of the Citadel server */
290         StrBuf *serv_humannode;         /* human readable node name of the Citadel server */
291         StrBuf *serv_fqdn;              /* fully quallified Domain Name (such as uncensored.citadel.org) */
292         StrBuf *serv_software;          /* What version does our connected citadel server use */
293         int serv_rev_level;             /* Whats the citadel server revision */
294         StrBuf *serv_bbs_city;          /* Geographic location of the Citadel server */
295         StrBuf *serv_sysadm;            /* Name of system administrator */
296         StrBuf *serv_moreprompt;        /* Whats the commandline textprompt */
297         int serv_supports_ldap;         /* is the server linked against an ldap tree for adresses? */
298         int serv_newuser_disabled;      /* Has the server disabled self-service new user creation? */
299         StrBuf *serv_default_cal_zone;  /* Default timezone for unspecified calendar items */
300         int serv_supports_sieve;        /* Does the server support Sieve mail filtering? */
301         int serv_fulltext_enabled;      /* Does the server have the full text index enabled? */
302         StrBuf *serv_svn_revision;      /* SVN revision of the server */
303         int serv_supports_openid;       /* Does the server support authentication via OpenID? */
304 } ServInfo;
305
306
307 typedef struct _disp_cal {                                      
308         icalcomponent *cal;             /* cal items for display */
309         long cal_msgnum;                /* cal msgids for display */
310         char *from;                     /* owner of this component */
311         int unread;                     /* already seen by the user? */
312
313         time_t event_start;
314         time_t event_end;
315
316         int multi_day_event;
317         int is_repeat;
318         icalcomponent *SortBy;          /* cal items for display */
319         icalproperty_status Status;
320 } disp_cal;                                             
321
322 typedef struct _IcalEnumMap {
323         const char *Name;
324         long NameLen;
325         icalproperty_kind map;
326 } IcalEnumMap;
327
328 /*
329  * Address book entry (keep it short and sweet, it's just a quickie lookup
330  * which we can use to get to the real meat and bones later)
331  */
332 typedef struct _addrbookent {
333         char ab_name[64];       /* name string */
334         long ab_msgnum;         /* message number of address book entry */
335 } addrbookent;
336
337
338 #define AJAX (1<<0)
339 #define ANONYMOUS (1<<1)
340 #define NEED_URL (1<<2)
341 #define XHTTP_COMMANDS (1<<3)
342 #define BOGUS (1<<4)
343 #define URLNAMESPACE (1<<4)
344 #define LOGCHATTY (1<<5)
345 #define COOKIEUNNEEDED (1<<6)
346 #define ISSTATIC (1<<7)
347 #define FORCE_SESSIONCLOSE (1<<8)
348 #define PARSE_REST_URL (1<<9)
349 #define PROHIBIT_STARTPAGE (1<<10)
350
351 typedef void (*WebcitHandlerFunc)(void);
352 typedef struct  _WebcitHandler{
353         WebcitHandlerFunc F;
354         long Flags;
355         StrBuf *Name;
356         StrBuf *DisplayName;
357 } WebcitHandler;
358
359
360 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, const char *DisplayName, long dslen, WebcitHandlerFunc F, long Flags);
361
362 typedef struct _headereval {
363         ExamineMsgHeaderFunc evaluator;
364         int Type;
365 } headereval;
366
367
368 struct attach_link {
369         char partnum[32];
370         char html[1024];
371 };
372
373
374 enum {
375         eUp,
376         eDown,
377         eNone
378 };
379
380 enum {
381         eGET,
382         ePOST,
383         eOPTIONS,
384         ePROPFIND,
385         ePUT,
386         eDELETE,
387         eHEAD,
388         eMOVE,
389         eCOPY,
390         eNONE
391 };
392 const char *ReqStrs[eNONE];
393
394 #define NO_AUTH 0
395 #define AUTH_COOKIE 1
396 #define AUTH_BASIC 2
397
398
399
400 typedef struct _HdrRefs {
401         long eReqType;                          /* HTTP method */
402         int desired_session;
403         int SessionKey;
404
405         int got_auth;
406         int DontNeedAuth;
407         long ContentLength;
408         time_t if_modified_since;
409         int gzip_ok;                            /* Nonzero if Accept-encoding: gzip */
410         int prohibit_caching;
411         int dav_depth;
412         int Static;
413
414         /* these are references into Hdr->HTTPHeaders, so we don't need to free them. */
415         StrBuf *ContentType;
416         StrBuf *RawCookie;
417         StrBuf *ReqLine;
418         StrBuf *http_host;                      /* HTTP Host: header */
419         StrBuf *browser_host;
420         StrBuf *browser_language;
421         StrBuf *user_agent;
422         StrBuf *plainauth;
423         StrBuf *dav_ifmatch;
424
425         const WebcitHandler *Handler;
426 } HdrRefs;
427
428 typedef struct _ParsedHttpHdrs {
429         int http_sock;                          /* HTTP server socket */
430         const char *Pos;
431         StrBuf *ReadBuf;
432
433         StrBuf *c_username;
434         StrBuf *c_password;
435         StrBuf *c_roomname;
436         StrBuf *c_language;
437         StrBuf *this_page;                      /* URL of current page */
438         StrBuf *PlainArgs; 
439
440         HashList *urlstrings;                   /* variables passed to webcit in a URL */
441         HashList *HTTPHeaders;                  /* the headers the client sent us */
442         int nWildfireHeaders;                   /* how many wildfire headers did we already send? */
443
444         HdrRefs HR;
445 } ParsedHttpHdrs;
446
447
448 /*
449  * One of these is kept for each active Citadel session.
450  * HTTP transactions are bound to one at a time.
451  */
452 typedef struct wcsession wcsession;
453 struct wcsession {
454 /* infrastructural members */
455         wcsession *next;                        /* Linked list */
456         pthread_mutex_t SessionMutex;           /* mutex for exclusive access */
457         int wc_session;                         /* WebCit session ID */
458         int killthis;                           /* Nonzero == purge this session */
459         int is_mobile;                          /* Client is a handheld browser */
460         int ctdl_pid;                           /* Session ID on the Citadel server */
461         int nonce;                              /* session nonce (to prevent session riding) */
462         int SessionKey;
463
464 /* Session local Members */
465         int serv_sock;                          /* Client socket to Citadel server */
466         StrBuf *ReadBuf;                        /* here we keep our stuff while reading linebuffered from the server. */
467         StrBuf *MigrateReadLineBuf;             /* here we buffer legacy server read stuff */
468         const char *ReadPos;                    /* whats our read position in ReadBuf? */
469         int chat_sock;                          /* Client socket to Citadel server - for chat */
470         time_t lastreq;                         /* Timestamp of most recent HTTP */
471         time_t last_pager_check;                /* last time we polled for instant msgs */
472         ServInfo *serv_info;                    /* Information about the citserver we're connected to */
473         int is_ajax;                            /* are we doing an ajax request? */
474
475 /* Request local Members */
476         StrBuf *CLineBuf;                       /* linebuffering client stuff */
477         ParsedHttpHdrs *Hdr;
478         StrBuf *WBuf;                           /* Our output buffer */
479         StrBuf *HBuf;                           /* Our HeaderBuffer */
480
481         HashList *vars;                         /* HTTP variable substitutions for this page */
482         StrBuf *trailing_javascript;            /* extra javascript to be appended to page */
483         char ImportantMessage[SIZ];
484         StrBuf *ImportantMsg;
485         HashList *Directory;                    /* Parts of the directory URL in snippets */
486         const Floor *CurrentFloor;              /**< when Parsing REST, which floor are we on? */
487
488 /* accounting */
489         StrBuf *wc_username;                    /* login name of current user */
490         StrBuf *wc_fullname;                    /* Screen name of current user */
491         StrBuf *wc_password;                    /* Password of current user */
492         StrBuf *httpauth_pass;                  /* only for GroupDAV sessions */
493         int axlevel;                            /* this user's access level */
494         int is_aide;                            /* nonzero == this user is an Aide */
495         int is_room_aide;                       /* nonzero == this user is a Room Aide in this room */
496         int connected;                          /* nonzero == we are connected to Citadel */
497         int logged_in;                          /* nonzero == we are logged in  */
498         int need_regi;                          /* This user needs to register. */
499         int need_vali;                          /* New users require validation. */
500
501 /* Preferences */
502         StrBuf *cs_inet_email;                  /* User's preferred Internet addr. */
503         char reply_to[512];                     /* reply-to address */
504         HashList *hash_prefs;                   /* WebCit preferences for this user */
505         StrBuf *DefaultCharset;                 /* Charset the user preferes */
506         int downloaded_prefs;                   /* Has the client download its prefs yet? */
507         int SavePrefsToServer;                  /* Should we save our preferences to the server at the end of the request? */
508         int selected_language;                  /* Language selected by user */
509         int time_format_cache;                  /* which timeformat does our user like? */
510
511 /* current room related */
512 /*      StrBuf *wc_roomname;                    / * Room we are currently in */
513 /*      unsigned room_flags;                    / * flags associated with the current room */
514 /*      unsigned room_flags2;                   / * flags associated with the current room */
515 /*      int wc_view;                            / * view for the current room */
516 /*      int wc_default_view;                    / * default view for the current room */
517 /*      int wc_is_trash;                        / * nonzero == current room is a Trash folder */
518 /*      int wc_floor;                           / * floor number of current room */
519 /*      int is_mailbox;                         / * the current room is a private mailbox */
520
521         folder CurRoom;                         /* information about our current room */
522         const folder *ThisRoom;                 /* if REST found a room, remember it here. */
523 /* next/previous room thingabob */
524         struct march *march;                    /* march mode room list */
525         char ugname[128];                       /* where does 'ungoto' take us */
526         long uglsn;                             /* last seen message number for ungoto */
527
528 /* Uploading; mime attachments for composing messages */
529         HashList *attachments;                  /* list of attachments for 'enter message' */
530         int upload_length;                      /* content length of http-uploaded data */
531         StrBuf *upload;                         /* pointer to http-uploaded data */
532         char upload_filename[PATH_MAX];         /* filename of http-uploaded data */
533         char upload_content_type[256];          /* content type of http-uploaded data */
534
535         int new_mail;                           /* user has new mail waiting */
536         int remember_new_mail;                  /* last count of new mail messages */
537
538 /* Roomiew control */
539         HashList *Floors;                       /* floors our citserver has hashed numeric for quicker access*/
540         HashList *FloorsByName;                 /* same but hashed by its name */
541         HashList *Rooms;                        /* our directory structure as loaded by LKRA */
542         HashList *summ;                         /* list of messages for mailbox summary view */
543   /** Perhaps these should be within a struct instead */
544         long startmsg;                          /* message number to start at */
545         long maxmsgs;                           /* maximum messages to display */
546         long num_displayed;                     /* number of messages actually displayed */
547         HashList *disp_cal_items;               /* sorted list of calendar items; startdate is the sort criteria. */
548
549
550         char last_chat_user[256];
551
552 /* Iconbar controls */
553         struct __ofolder *cache_fold;           /* cache the iconbar room list */
554         int cache_max_folders;
555         int cache_num_floors;
556         time_t cache_timestamp;
557         long *IBSettingsVec;                    /* which icons should be shown / not shown? */
558         const StrBuf *floordiv_expanded;        /* which floordiv currently expanded */
559
560
561
562 /* cache stuff for templates. TODO: find a smartrer way */
563         HashList *ServCfg;                      /* cache our server config for editing */
564         HashList *InetCfg;                      /* Our inet server config for editing */
565         ExpirePolicy Policy[maxpolicy];
566 };
567
568
569 typedef void (*Header_Evaluator)(StrBuf *Line, ParsedHttpHdrs *hdr);
570
571 typedef struct _HttpHeader {
572         Header_Evaluator H;
573         StrBuf *Val;
574         int HaveEvaluator;
575 } OneHttpHeader;
576
577 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F);
578
579
580 enum {
581         S_SELECT,
582         S_SHUTDOWN,
583         MAX_SEMAPHORES
584 };
585
586
587 #ifndef num_parms
588 #define num_parms(source)               num_tokens(source, '|') 
589 #endif
590
591 /* Per-session data */
592 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
593 extern pthread_key_t MyConKey;
594
595 /* Per-thread SSL context */
596 #ifdef HAVE_OPENSSL
597 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
598 extern pthread_key_t ThreadSSL;
599 extern char ctdl_key_dir[PATH_MAX];
600 extern char file_crpt_file_key[PATH_MAX];
601 extern char file_crpt_file_csr[PATH_MAX];
602 extern char file_crpt_file_cer[PATH_MAX];
603 #endif
604
605 extern char floorlist[128][SIZ];
606 extern char *axdefs[];
607 extern char *ctdlhost, *ctdlport;
608 extern int http_port;
609 extern char *server_cookie;
610 extern int is_https;
611 extern int setup_wizard;
612 extern char wizard_filename[];
613 extern int follow_xff;
614 extern int num_threads;
615
616 void InitialiseSemaphores(void);
617 void begin_critical_section(int which_one);
618 void end_critical_section(int which_one);
619
620 void stuff_to_cookie(int unset_cookie);
621
622 void cookie_to_stuff(StrBuf *cookie,
623                 int *session,
624                 StrBuf *user,
625                 StrBuf *pass,
626                 StrBuf *room,
627                 StrBuf *language
628 );
629 void locate_host(StrBuf *TBuf, int);
630 void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response);
631 void openid_manual_create(void);
632 void display_login(void);
633 void display_openids(void);
634 void do_welcome(void);
635 void do_logout(void);
636 void display_main_menu(void);
637 void display_aide_menu(void);
638 void display_advanced_menu(void);
639 void slrp_highest(void);
640 ServInfo *get_serv_info(StrBuf *, StrBuf *);
641 void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority);
642 void CreateMimeStr(void);
643 int GetConnected(void);
644 void DeleteServInfo(ServInfo **FreeMe);
645 int uds_connectsock(char *);
646 int tcp_connectsock(char *, char *);
647 int serv_getln(char *strbuf, int bufsize);
648 int StrBuf_ServGetln(StrBuf *buf);
649 int GetServerStatus(StrBuf *Line, long* FullState);
650 void serv_puts(const char *string);
651 void who(void);
652 void who_inner_div(void);
653 void ajax_mini_calendar(void);
654 void fmout(char *align);
655 void _fmout(StrBuf *Targt, char *align);
656 void FmOut(StrBuf *Target, char *align, StrBuf *Source);
657 void pullquote_fmout(void);
658 void wDumpContent(int);
659
660
661
662 void UrlescPutStrBuf(const StrBuf *strbuf);
663 void StrEscPuts(const StrBuf *strbuf);
664 void StrEscputs1(const StrBuf *strbuf, int nbsp, int nolinebreaks);
665
666 void urlescputs(const char *);
667 void hurlescputs(const char *);
668 void jsesc(char *, size_t, char *);
669 void jsescputs(char *);
670 void output_headers(    int do_httpheaders,
671                         int do_htmlhead,
672                         int do_room_banner,
673                         int unset_cookies,
674                         int suppress_check,
675                         int cache);
676 void output_custom_content_header(const char *ctype);
677
678 #ifdef UBER_VERBOSE_DEBUGGING
679 #define wc_printf(...) wcc_printf(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
680 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format, ...);
681 #else 
682 void wc_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
683 #endif
684
685 void hprintf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
686 void output_static(const char* What);
687
688 long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks);
689 void escputs(const char *strbuf);
690 void url(char *buf, size_t bufsize);
691 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
692 void escputs1(const char *strbuf, int nbsp, int nolinebreaks);
693 void msgesc(char *target, size_t tlen, char *strbuf);
694 void msgescputs(char *strbuf);
695 void msgescputs1(char *strbuf);
696 void dump_vars(void);
697 void embed_main_menu(void);
698
699 void do_addrbook_view(addrbookent *addrbook, int num_ab);
700 void fetch_ab_name(message_summary *Msg, char **namebuf);
701 void display_vcard(StrBuf *Target, wc_mime_attachment *Mime, char alpha, int full, char **storename, long msgnum);
702 void jsonMessageList(void);
703 void new_summary_view(void);
704 void getseen(void);
705 void text_to_server(char *ptr);
706 void text_to_server_qp(char *ptr);
707 void confirm_delete_msg(void);
708 void display_success(char *);
709 void CheckAuthBasic(ParsedHttpHdrs *hdr);
710 void GetAuthBasic(ParsedHttpHdrs *hdr);
711 void server_to_text(void);
712 void save_edit(char *description, char *enter_cmd, int regoto);
713 void display_edit(char *description, char *check_cmd,
714                   char *read_cmd, char *save_cmd, int with_room_banner);
715 long gotoroom(const StrBuf *gname);
716 void remove_march(const StrBuf *aaa);
717 void dotskip(void);
718 void confirm_delete_room(void);
719 void validate(void);
720 void display_graphics_upload(char *, char *, char *);
721 void do_graphics_upload(char *upl_cmd);
722 void serv_gets(char *strbuf);
723 void serv_write(const char *buf, int nbytes);
724 void serv_putbuf(const StrBuf *string);
725 void serv_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
726 void load_floorlist(StrBuf *Buf);
727 void shutdown_sessions(void);
728 void do_housekeeping(void);
729 void smart_goto(const StrBuf *);
730 void worker_entry(void);
731 void session_loop(void);
732 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
733 void fmt_time(char *buf, size_t siz, time_t thetime);
734 void httpdate(char *buf, time_t thetime);
735 time_t httpdate_to_timestamp(StrBuf *buf);
736 void end_webcit_session(void);
737 void page_popup(void);
738 void http_redirect(const char *);
739 void clear_substs(struct wcsession *wc);
740 void clear_local_substs(void);
741
742
743
744 int lingering_close(int fd);
745 long extract_token(char *dest, const char *source, int parmnum, char separator, int maxlen);
746 void remove_token(char *source, int parmnum, char separator);
747 StrBuf *load_mimepart(long msgnum, char *partnum);
748 void MimeLoadData(wc_mime_attachment *Mime);
749 int pattern2(char *search, char *patn);
750 void do_edit_vcard(long msgnum, char *partnum, 
751                    message_summary *VCMsg,
752                    wc_mime_attachment *VCAtt,
753                    const char *return_to, 
754                    const char *force_room);
755
756 void select_user_to_edit(const char *preselect);
757 void delete_user(char *);
758 void do_change_view(int);
759 void folders(void);
760
761
762
763 void offer_start_page(StrBuf *Target, WCTemplputParams *TP);
764 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext);
765 void output_html(const char *, int, int, StrBuf *, StrBuf *);
766 void do_listsub(void);
767 ssize_t write(int fd, const void *buf, size_t count);
768 void cal_process_attachment(wc_mime_attachment *Mime);
769 void display_calendar(message_summary *Msg, int unread);
770 void display_note(message_summary *Msg, int unread);
771 void updatenote(void);
772 void do_tasks_view(void);
773 int calendar_summary_view(void);
774 void free_march_list(wcsession *wcf);
775 void display_rules_editor_inner_div(void);
776 void generate_uuid(char *);
777 void CtdlMakeTempFileName(char *, int);
778 void address_book_popup(void);
779 void begin_ajax_response(void);
780 void end_ajax_response(void);
781 void initialize_viewdefs(void);
782 void initialize_axdefs(void);
783 void burn_folder_cache(time_t age);
784 void list_all_rooms_by_floor(const char *viewpref);
785 void display_pictureview(void);
786
787 void display_edit_task(void);
788 void display_edit_event(void);
789 icaltimezone *get_default_icaltimezone(void);
790 void display_icaltimetype_as_webform(struct icaltimetype *, char *, int);
791 void icaltime_from_webform(struct icaltimetype *result, char *prefix);
792 void icaltime_from_webform_dateonly(struct icaltimetype *result, char *prefix);
793 void partstat_as_string(char *buf, icalproperty *attendee);
794 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
795 void check_attendee_availability(icalcomponent *supplied_vevent);
796 int ical_ctdl_is_overlap(
797                         struct icaltimetype t1start,
798                         struct icaltimetype t1end,
799                         struct icaltimetype t2start,
800                         struct icaltimetype t2end
801 );
802
803
804 extern char *months[];
805 extern char *days[];
806 int serv_read_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf);
807 int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize);
808 int StrBuf_ServGetBLOBBuffered(StrBuf *buf, long BlobSize);
809 int read_server_text(StrBuf *Buf, long *nLines);
810 long locate_user_vcard_in_this_room(message_summary **VCMsg,
811                                     wc_mime_attachment **VCAtt);
812 void sleeeeeeeeeep(int);
813 void http_transmit_thing(const char *content_type, int is_static);
814 long unescape_input(char *buf);
815 void do_selected_iconbar(void);
816 void spawn_another_worker_thread(void);
817 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs);
818 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs);
819 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]);
820 void tabbed_dialog(int num_tabs, char *tabnames[]);
821 void begin_tab(int tabnum, int num_tabs);
822 void end_tab(int tabnum, int num_tabs);
823 void str_wiki_index(char *s);
824 long guess_calhourformat(void);
825 int get_time_format_cached (void);
826 const char *get_selected_language(void);
827 void display_wiki_pagelist(void);
828
829 #define DATEFMT_FULL 0
830 #define DATEFMT_BRIEF 1
831 #define DATEFMT_RAWDATE 2
832 #define DATEFMT_LOCALEDATE 3
833 void webcit_fmt_date(char *buf, size_t siz, time_t thetime, int Format);
834 int fetch_http(char *url, char *target_buf, int maxbytes);
835 void free_attachments(wcsession *sess);
836 void summary(void);
837
838 int is_mobile_ua(char *user_agent);
839
840 void embed_room_banner(char *, int);
841 HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP);
842 HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP);
843 int SortRoomsByListOrder(const void *room1, const void *room2);
844 /* navbar types that can be passed to embed_room_banner */
845 enum {
846         navbar_none,
847         navbar_default
848 };
849
850 /* actual supported locales */
851 void TmplGettext(StrBuf *Target, WCTemplputParams *TP);
852 void offer_languages(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType);
853 void set_selected_language(const char *);
854 void go_selected_language(void);
855 void stop_selected_language(void);
856
857 #ifdef HAVE_OPENSSL
858 void init_ssl(void);
859 void endtls(void);
860 void ssl_lock(int mode, int n, const char *file, int line);
861 int starttls(int sock);
862 extern SSL_CTX *ssl_ctx;  
863 int client_read_sslbuffer(StrBuf *buf, int timeout);
864 void client_write_ssl(const StrBuf *Buf);
865 #endif
866
867 void utf8ify_rfc822_string(char **buf);
868
869 void begin_burst(void);
870 long end_burst(void);
871
872 extern char *hourname[];        /* Names of hours (12am, 1am, etc.) */
873
874 void http_datestring(char *buf, size_t n, time_t xtime);
875
876
877 /* These should be empty, but we have them for testing */
878 #define DEFAULT_HTTPAUTH_USER   ""
879 #define DEFAULT_HTTPAUTH_PASS   ""
880
881
882 /* Exit codes 101 through 109 are initialization failures so we don't want to
883  * just keep respawning indefinitely.
884  */
885 #define WC_EXIT_BIND            101     /* Can't bind to the port */
886 #define WC_EXIT_SSL             102     /* Can't initialize SSL */
887
888
889 #define WC_TIMEFORMAT_NONE 0
890 #define WC_TIMEFORMAT_AMPM 1
891 #define WC_TIMEFORMAT_24 2
892