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