b3440092078d57d12e5c37f94735645fa82b536d
[citadel.git] / webcit / webcit.h
1 /*
2  * Copyright (c) 1987-2012 by the citadel.org team
3  *
4  * This program is open source software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License version 3.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #include "sysdep.h"
14 #include <sys/select.h>
15 #include <ctype.h>
16 #include <stdlib.h>
17 #ifdef HAVE_UNISTD_H
18 #include <unistd.h>
19 #endif
20 #include <stdio.h>
21 #ifdef HAVE_FCNTL_H
22 #include <fcntl.h>
23 #endif
24 #include <signal.h>
25 #include <sys/types.h>
26 #include <sys/wait.h>
27 #include <sys/socket.h>
28 #ifdef HAVE_SYS_TIME_H
29 #include <sys/time.h>
30 #endif
31 #include <sys/stat.h>
32 #ifdef HAVE_LIMITS_H
33 #include <limits.h>
34 #endif
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 #include <netdb.h>
39 #include <sys/un.h>
40 #include <sys/poll.h>
41 #include <string.h>
42 #include <pwd.h>
43 #include <errno.h>
44 #include <stdarg.h>
45 #include <pthread.h>
46 #include <signal.h>
47 #include <syslog.h>
48 #include <sys/utsname.h>
49 #include <expat.h>
50 #include <libcitadel.h>
51
52 #ifdef HAVE_ICONV
53 #include <iconv.h>
54 #endif
55
56 #ifdef ENABLE_NLS
57 #ifdef HAVE_XLOCALE_H
58 #include <xlocale.h>
59 #endif
60 #include <libintl.h>
61 #include <locale.h>
62 #define _(string)       gettext(string)
63 #else
64 #define _(string)       (string)
65 #endif
66
67 #define IsEmptyStr(a) ((a)[0] == '\0')
68
69 #define DO_DBG_QR 0
70 #define DBG_QR(x) if(DO_DBG_QR) _DBG_QR(x)
71 #define DBG_QR2(x) if(DO_DBG_QR) _DBG_QR2(x)
72
73 #include <zlib.h>
74
75 #include <libical/ical.h>
76
77 #undef PACKAGE
78 #undef VERSION
79 #undef PACKAGE_NAME
80 #undef PACKAGE_STRING
81 #undef PACKAGE_TARNAME
82 #undef PACKAGE_VERSION
83 #undef PACKAGE_BUGREPORT
84
85 typedef struct wcsession wcsession;
86
87 #include "sysdep.h"
88
89 #include "subst.h"
90 #include "messages.h"
91 #include "paramhandling.h"
92 #include "roomops.h"
93 #include "preferences.h"
94
95 #include "tcp_sockets.h"
96 #include "utils.h"
97 #ifdef HAVE_OPENSSL
98 /* Work around RedHat's b0rken OpenSSL includes */
99 #define OPENSSL_NO_KRB5
100 #include <openssl/ssl.h>
101 #include <openssl/err.h>
102 #include <openssl/rand.h>
103 extern char *ssl_cipher_list;
104 #define DEFAULT_SSL_CIPHER_LIST "DEFAULT"       /* See http://openssl.org/docs/apps/ciphers.html */
105 #endif
106
107 #if SIZEOF_SIZE_T == SIZEOF_INT 
108 #define SIZE_T_FMT "%d"
109 #else
110 #define SIZE_T_FMT "%ld"
111 #endif
112
113 #if SIZEOF_LONG_UNSIGNED_INT == SIZEOF_INT
114 #define ULONG_FMT "%d"
115 #else
116 #define ULONG_FMT "%ld"
117 #endif
118
119 #define CALENDAR_ROOM_NAME      "Calendar"
120 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
121
122 #define SIZ                     4096            /* generic buffer size */
123
124 #define TRACE syslog(LOG_DEBUG, "\033[3%dmCHECKPOINT: %s:%d\033[0m", ((__LINE__%6)+1), __FILE__, __LINE__)
125
126 #define SLEEPING                180             /* TCP connection timeout */
127 #define WEBCIT_TIMEOUT          900             /* WebCit session timeout */
128 #define PORT_NUM                2000            /* port number to listen on */
129 #define DEVELOPER_ID            0
130 #define CLIENT_ID               4
131 #define CLIENT_VERSION          813             /* This version of WebCit */
132 #define MINIMUM_CIT_VERSION     813             /* Minimum required version of Citadel server */
133 #define LIBCITADEL_MIN          813             /* Minimum required version of libcitadel */
134 #define DEFAULT_HOST            "localhost"     /* Default Citadel server */
135 #define DEFAULT_PORT            "504"
136 #define TARGET                  "webcit01"      /* Window target for inline URL's */
137 #define HOUSEKEEPING            15              /* Housekeeping frequency */
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
154 #define SRV_STATUS_MSG(ServerLineBuf) (ChrPtr(ServerLineBuf) + 4), (StrLength(ServerLineBuf) - 4)
155 #define MAJORCODE(a) (((int)(a / 100) ) * 100)
156
157 #define LISTING_FOLLOWS 100
158 #define CIT_OK          200     
159 #define MORE_DATA       300
160 #define SEND_LISTING    400
161 #define ERROR           500
162 #define BINARY_FOLLOWS  600
163 #define SEND_BINARY     700
164 #define START_CHAT_MODE 800
165 #define ASYNC_MSG       900
166
167 #define MINORCODE(a) (a % 100)
168 #define ASYNC_GEXP                      02      
169 #define INTERNAL_ERROR                  10      
170 #define TOO_BIG                         11      
171 #define ILLEGAL_VALUE                   12      
172 #define NOT_LOGGED_IN                   20      
173 #define CMD_NOT_SUPPORTED               30      
174 #define SERVER_SHUTTING_DOWN            31      
175 #define PASSWORD_REQUIRED               40      
176 #define ALREADY_LOGGED_IN               41      
177 #define USERNAME_REQUIRED               42      
178 #define HIGHER_ACCESS_REQUIRED          50      
179 #define MAX_SESSIONS_EXCEEDED           51      
180 #define RESOURCE_BUSY                   52      
181 #define RESOURCE_NOT_OPEN               53      
182 #define NOT_HERE                        60      
183 #define INVALID_FLOOR_OPERATION         61      
184 #define NO_SUCH_USER                    70      
185 #define FILE_NOT_FOUND                  71      
186 #define ROOM_NOT_FOUND                  72      
187 #define NO_SUCH_SYSTEM                  73      
188 #define ALREADY_EXISTS                  74      
189 #define MESSAGE_NOT_FOUND               75
190
191 /*
192  * NLI is the string that shows up in a who's online listing for sessions
193  * that are active but do not (yet) have a user logged in.
194  */
195 #define NLI     "(not logged in)"
196
197 /*
198  * Expiry policy for the autopurger
199  */
200 #define EXPIRE_NEXTLEVEL        0       /* Inherit expiration policy    */
201 #define EXPIRE_MANUAL           1       /* Don't expire messages at all */
202 #define EXPIRE_NUMMSGS          2       /* Keep only latest n messages  */
203 #define EXPIRE_AGE              3       /* Expire messages after n days */
204
205 typedef struct __ExpirePolicy {
206         int expire_mode;
207         int expire_value;
208 } ExpirePolicy;
209 void LoadExpirePolicy(GPEXWhichPolicy which);
210 void SaveExpirePolicyFromHTTP(GPEXWhichPolicy which);
211
212 /*
213  * Linked list of session variables encoded in an x-www-urlencoded content type
214  */
215 typedef struct urlcontent urlcontent;
216 struct urlcontent {
217         char url_key[32];               /* key */
218         StrBuf *url_data;               /* value */
219 };
220
221 /*
222  * Information about the Citadel server to which we are connected
223  */ 
224 typedef struct _serv_info {
225         int serv_pid;                   /* Process ID of the Citadel server */
226         StrBuf *serv_nodename;          /* Node name of the Citadel server */
227         StrBuf *serv_humannode;         /* Juman readable node name of the Citadel server */
228         StrBuf *serv_fqdn;              /* Fully qualified Domain Name (such as uncensored.citadel.org) */
229         StrBuf *serv_software;          /* Free form text description of the server software in use */
230         int serv_rev_level;             /* Server version number (times 100) */
231         StrBuf *serv_bbs_city;          /* Geographic location of the Citadel server */
232         StrBuf *serv_sysadm;            /* Name of system administrator */
233         int serv_supports_ldap;         /* is the server linked against an ldap tree for adresses? */
234         int serv_newuser_disabled;      /* Has the server disabled self-service new user creation? */
235         StrBuf *serv_default_cal_zone;  /* Default timezone for unspecified calendar items */
236         int serv_supports_sieve;        /* Server supports Sieve mail filtering */
237         int serv_fulltext_enabled;      /* Full text index is enabled */
238         StrBuf *serv_svn_revision;      /* svn or git revision of the server */
239         int serv_supports_openid;       /* Server supports authentication via OpenID */
240         int serv_supports_guest;        /* Server supports unauthenticated guest logins */
241 } ServInfo;
242
243
244 typedef struct _disp_cal {                                      
245         icalcomponent *cal;             /* cal items for display */
246         long cal_msgnum;                /* cal msgids for display */
247         char *from;                     /* owner of this component */
248         int unread;                     /* already seen by the user? */
249
250         time_t event_start;
251         time_t event_end;
252
253         int multi_day_event;
254         int is_repeat;
255         icalcomponent *SortBy;          /* cal items for display */
256         icalproperty_status Status;
257 } disp_cal;                                             
258
259 typedef struct _IcalEnumMap {
260         const char *Name;
261         long NameLen;
262         icalproperty_kind map;
263 } IcalEnumMap;
264
265 /*
266  * Address book entry (keep it short and sweet, it's just a quickie lookup
267  * which we can use to get to the real meat and bones later)
268  */
269 typedef struct _addrbookent {
270         char ab_name[64];       /* name string */
271         long ab_msgnum;         /* message number of address book entry */
272 } addrbookent;
273
274
275 #define AJAX (1<<0)
276 #define ANONYMOUS (1<<1)
277 #define NEED_URL (1<<2)
278 #define XHTTP_COMMANDS (1<<3)
279 #define BOGUS (1<<4)
280 #define URLNAMESPACE (1<<4)
281 #define LOGCHATTY (1<<5)
282 #define COOKIEUNNEEDED (1<<6)
283 #define ISSTATIC (1<<7)
284 #define FORCE_SESSIONCLOSE (1<<8)
285 #define PARSE_REST_URL (1<<9)
286 #define PROHIBIT_STARTPAGE (1<<10)
287
288
289 #define DATEFMT_FULL 0
290 #define DATEFMT_BRIEF 1
291 #define DATEFMT_RAWDATE 2
292 #define DATEFMT_LOCALEDATE 3
293 void webcit_fmt_date(char *buf, size_t siz, time_t thetime, int Format);
294
295
296 typedef enum _RESTDispatchID {
297         ExistsID,
298         PutID,
299         DeleteID
300 } RESTDispatchID;
301
302 typedef int (*WebcitRESTDispatchID)(RESTDispatchID WhichAction, int IgnoreFloor);
303 typedef void (*WebcitHandlerFunc)(void);
304 typedef struct  _WebcitHandler{
305         WebcitHandlerFunc F;
306         WebcitRESTDispatchID RID;
307         long Flags;
308         StrBuf *Name;
309         StrBuf *DisplayName;
310 } WebcitHandler;
311
312
313 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, const char *DisplayName, long dslen, WebcitHandlerFunc F, long Flags);
314
315 typedef struct _headereval {
316         ExamineMsgHeaderFunc evaluator;
317         int Type;
318 } headereval;
319
320
321 struct attach_link {
322         char partnum[32];
323         char html[1024];
324 };
325
326
327 enum {
328         eUp,
329         eDown,
330         eNone
331 };
332
333 enum {
334         eGET,
335         ePOST,
336         eOPTIONS,
337         ePROPFIND,
338         ePUT,
339         eDELETE,
340         eHEAD,
341         eMOVE,
342         eCOPY,
343         eREPORT,
344         eNONE
345 };
346 extern const char *ReqStrs[eNONE];
347
348 #define NO_AUTH 0
349 #define AUTH_COOKIE 1
350 #define AUTH_BASIC 2
351
352
353
354 typedef struct _HdrRefs {
355         long eReqType;                          /* HTTP method */
356         int desired_session;
357         int SessionKey;
358
359         int got_auth;
360         int DontNeedAuth;
361         long ContentLength;
362         time_t if_modified_since;
363         int gzip_ok;                            /* Nonzero if Accept-encoding: gzip */
364         int prohibit_caching;
365         int dav_depth;
366         int Static;
367
368         /* these are references into Hdr->HTTPHeaders, so we don't need to free them. */
369         StrBuf *ContentType;
370         StrBuf *RawCookie;
371         StrBuf *ReqLine;
372         StrBuf *browser_host;
373         StrBuf *browser_language;
374         StrBuf *user_agent;
375         StrBuf *plainauth;
376         StrBuf *dav_ifmatch;
377
378         const WebcitHandler *Handler;
379 } HdrRefs;
380
381 typedef struct _ParsedHttpHdrs {
382         int http_sock;                          /* HTTP server socket */
383         const char *Pos;
384         StrBuf *ReadBuf;
385
386         StrBuf *c_username;
387         StrBuf *c_password;
388         StrBuf *c_roomname;
389         StrBuf *c_language;
390         StrBuf *this_page;                      /* URL of current page */
391         StrBuf *PlainArgs; 
392         StrBuf *HostHeader;
393
394         HashList *urlstrings;                   /* variables passed to webcit in a URL */
395         HashList *HTTPHeaders;                  /* the headers the client sent us */
396         int nWildfireHeaders;                   /* how many wildfire headers did we already send? */
397
398         HdrRefs HR;
399 } ParsedHttpHdrs;
400
401
402 /*
403  * One of these is kept for each active Citadel session.
404  * HTTP transactions are bound to one at a time.
405  */
406 struct wcsession {
407 /* infrastructural members */
408         wcsession *next;                        /* Linked list */
409         pthread_mutex_t SessionMutex;           /* mutex for exclusive access */
410         int wc_session;                         /* WebCit session ID */
411         int killthis;                           /* Nonzero == purge this session */
412         int ctdl_pid;                           /* Session ID on the Citadel server */
413         int nonce;                              /* session nonce (to prevent session riding) */
414         int inuse;                              /* set to nonzero if bound to a running thread */
415
416 /* Session local Members */
417         int serv_sock;                          /* Client socket to Citadel server */
418         StrBuf *ReadBuf;                        /* linebuffered reads from the server */
419         StrBuf *MigrateReadLineBuf;             /* here we buffer legacy server read stuff */
420         const char *ReadPos;                    /* whats our read position in ReadBuf? */
421         int last_chat_seq;                      /* When in chat - last message seq# we saw */
422         time_t lastreq;                         /* Timestamp of most recent HTTP */
423         time_t last_pager_check;                /* last time we polled for instant msgs */
424         ServInfo *serv_info;                    /* Information about the citserver we're connected to */
425         StrBuf *PushedDestination;              /* Where to go after login, registration, etc. */
426
427 /* Request local Members */
428         StrBuf *CLineBuf;                       /* linebuffering client stuff */
429         ParsedHttpHdrs *Hdr;
430         StrBuf *WBuf;                           /* Our output buffer */
431         StrBuf *HBuf;                           /* Our HeaderBuffer */
432         StrBuf *WFBuf;                          /* Wildfire error logging buffer */
433         StrBuf *trailing_javascript;            /* extra javascript to be appended to page */
434         StrBuf *ImportantMsg;
435         HashList *Directory;                    /* Parts of the directory URL in snippets */
436         const Floor *CurrentFloor;              /* when Parsing REST, which floor are we on? */
437
438 /* accounting */
439         StrBuf *wc_username;                    /* login name of current user */
440         StrBuf *wc_fullname;                    /* Screen name of current user */
441         StrBuf *wc_password;                    /* Password of current user */
442         StrBuf *httpauth_pass;                  /* only for GroupDAV sessions */
443         int axlevel;                            /* this user's access level */
444         int is_aide;                            /* nonzero == this user is an Aide */
445         int connected;                          /* nonzero == we are connected to Citadel */
446         int logged_in;                          /* nonzero == we are logged in  */
447         int need_regi;                          /* This user needs to register. */
448         int need_vali;                          /* New users require validation. */
449
450 /* Preferences */
451         StrBuf *cs_inet_email;                  /* User's preferred Internet addr. */
452         HashList *hash_prefs;                   /* WebCit preferences for this user */
453         StrBuf *DefaultCharset;                 /* Charset the user preferes */
454         int downloaded_prefs;                   /* Has the client download its prefs yet? */
455         int SavePrefsToServer;                  /* Should we save our preferences to the server at the end of the request? */
456         int selected_language;                  /* Language selected by user */
457         int time_format_cache;                  /* which timeformat does our user like? */
458
459         folder CurRoom;                         /* information about our current room */
460         const folder *ThisRoom;                 /* if REST found a room, remember it here. */
461 /* next/previous room thingabob */
462         struct march *march;                    /* march mode room list */
463         char ugname[128];                       /* where does 'ungoto' take us */
464         long uglsn;                             /* last seen message number for ungoto */
465
466 /* Uploading; mime attachments for composing messages */
467         HashList *attachments;                  /* list of attachments for 'enter message' */
468         int upload_length;                      /* content length of http-uploaded data */
469         StrBuf *upload;                         /* pointer to http-uploaded data */
470         StrBuf *upload_filename;                /* filename of http-uploaded data */
471         char upload_content_type[256];          /* content type of http-uploaded data */
472
473         int remember_new_mail;                  /* last count of new mail messages */
474
475 /* Roomiew control */
476         HashList *Floors;                       /* floors our citserver has hashed numeric for quicker access*/
477         HashList *FloorsByName;                 /* same but hashed by its name */
478         HashList *Rooms;                        /* our directory structure as loaded by LKRA */
479         HashList *summ;                         /* list of messages for mailbox summary view */
480   /** Perhaps these should be within a struct instead */
481         long startmsg;                          /* message number to start at */
482         long maxmsgs;                           /* maximum messages to display */
483         long num_displayed;                     /* number of messages actually displayed */
484         HashList *disp_cal_items;               /* sorted list of calendar items; startdate is the sort criteria. */
485
486
487         char last_chat_user[256];
488
489 /* Iconbar controls */
490         int cache_max_folders;
491         int cache_num_floors;
492         long *IBSettingsVec;                    /* which icons should be shown / not shown? */
493         const StrBuf *floordiv_expanded;        /* which floordiv currently expanded */
494         int ib_wholist_expanded;
495         int ib_roomlist_expanded;
496
497 /* our known Sieve scripts; loaded by SIEVE:SCRIPTS iterator. */
498         HashList *KnownSieveScripts;
499
500 /* Transcoding cache buffers; used to avoid to frequent realloc */
501         StrBuf *ConvertBuf1;
502         StrBuf *ConvertBuf2;
503
504 /* cache stuff for templates. TODO: find a smarter way */
505         HashList *ServCfg;                      /* cache our server config for editing */
506         HashList *InetCfg;                      /* Our inet server config for editing */
507         ExpirePolicy Policy[maxpolicy];
508
509 /* used by the blog viewer */
510         int bptlid;                             /* hash of thread currently being rendered */
511 };
512
513
514 typedef void (*Header_Evaluator)(StrBuf *Line, ParsedHttpHdrs *hdr);
515
516 typedef struct _HttpHeader {
517         Header_Evaluator H;
518         StrBuf *Val;
519         int HaveEvaluator;
520 } OneHttpHeader;
521
522 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F);
523
524
525 enum {
526         S_SHUTDOWN,
527         S_SPAWNER,
528         MAX_SEMAPHORES
529 };
530
531 #ifndef num_parms
532 #define num_parms(source)               num_tokens(source, '|') 
533 #endif
534
535 #define site_prefix     (WC ? (WC->Hdr->HostHeader) : NULL)
536
537 /* Per-session data */
538 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
539 extern pthread_key_t MyConKey;
540
541 /* Per-thread SSL context */
542 #ifdef HAVE_OPENSSL
543 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
544 extern pthread_key_t ThreadSSL;
545 extern char ctdl_key_dir[PATH_MAX];
546 extern char file_crpt_file_key[PATH_MAX];
547 extern char file_crpt_file_csr[PATH_MAX];
548 extern char file_crpt_file_cer[PATH_MAX];
549
550 void init_ssl(void);
551 void endtls(void);
552 void ssl_lock(int mode, int n, const char *file, int line);
553 int starttls(int sock);
554 extern SSL_CTX *ssl_ctx;  
555 int client_read_sslbuffer(StrBuf *buf, int timeout);
556 void client_write_ssl(const StrBuf *Buf);
557 #endif
558
559 extern int is_https;
560 extern int follow_xff;
561 extern char *server_cookie;
562 extern char *ctdlhost, *ctdlport;
563 extern char *axdefs[];
564 extern int num_threads_existing;
565 extern int num_threads_executing;
566 extern int setup_wizard;
567 extern char wizard_filename[];
568
569 void InitialiseSemaphores(void);
570 void begin_critical_section(int which_one);
571 void end_critical_section(int which_one);
572
573
574 extern void do_404(void);
575 void http_redirect(const char *);
576
577
578 #ifdef UBER_VERBOSE_DEBUGGING
579 #define wc_printf(...) wcc_printf(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
580 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format, ...);
581 #else 
582 void wc_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
583 #endif
584
585 void hprintf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
586
587 void CheckAuthBasic(ParsedHttpHdrs *hdr);
588 void GetAuthBasic(ParsedHttpHdrs *hdr);
589
590 void sleeeeeeeeeep(int);
591
592 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
593 void fmt_time(char *buf, size_t siz, time_t thetime);
594 void httpdate(char *buf, time_t thetime);
595 time_t httpdate_to_timestamp(StrBuf *buf);
596
597
598
599
600 void end_webcit_session(void);
601
602
603
604
605 void cookie_to_stuff(StrBuf *cookie,
606                 int *session,
607                 StrBuf *user,
608                 StrBuf *pass,
609                 StrBuf *room,
610                 StrBuf *language
611 );
612 void locate_host(StrBuf *TBuf, int);
613 void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response);
614
615 void display_login(void);
616 void display_openids(void);
617 void display_default_landing_page(void);
618 void do_welcome(void);
619
620 void display_reg(int during_login);
621 void display_main_menu(void);
622 void display_aide_menu(void);
623
624 void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority);
625 void CreateMimeStr(void);
626
627
628 void pop_destination(void);
629
630 void FmOut(StrBuf *Target, const char *align, const StrBuf *Source);
631 void wDumpContent(int);
632
633
634 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt);
635
636 void output_headers(    int do_httpheaders,
637                         int do_htmlhead,
638                         int do_room_banner,
639                         int unset_cookies,
640                         int suppress_check,
641                         int cache);
642 void output_custom_content_header(const char *ctype);
643 void cdataout(char *rawdata);
644
645
646 void url(char *buf, size_t bufsize);
647 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
648
649
650 void display_vcard(StrBuf *Target, wc_mime_attachment *Mime, char alpha, int full, char **storename, long msgnum);
651
652 void display_success(const char *successmessage);
653
654 void shutdown_sessions(void);
655
656
657
658 StrBuf *load_mimepart(long msgnum, char *partnum);
659 void MimeLoadData(wc_mime_attachment *Mime);
660 void do_edit_vcard(long msgnum, char *partnum, 
661                    message_summary *VCMsg,
662                    wc_mime_attachment *VCAtt,
663                    const char *return_to, 
664                    const char *force_room);
665
666 void select_user_to_edit(const char *preselect);
667
668 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext);
669 void output_html(const char *, int, int, StrBuf *, StrBuf *);
670
671 ssize_t write(int fd, const void *buf, size_t count);
672 void cal_process_attachment(wc_mime_attachment *Mime);
673
674 void address_book_popup(void);
675 void begin_ajax_response(void);
676 void end_ajax_response(void);
677
678 extern char *months[];
679 extern char *days[];
680 long locate_user_vcard_in_this_room(message_summary **VCMsg,
681                                     wc_mime_attachment **VCAtt);
682 void http_transmit_thing(const char *content_type, int is_static);
683 long unescape_input(char *buf);
684 void check_thread_pool_size(void);
685 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs);
686 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs, StrBuf **Names);
687 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]);
688 void tabbed_dialog(int num_tabs, char *tabnames[]);
689 void begin_tab(int tabnum, int num_tabs);
690 void end_tab(int tabnum, int num_tabs);
691
692 int get_time_format_cached (void);
693 void display_wiki_pagelist(void);
694 void str_wiki_index(char *);
695
696 HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP);
697
698 /* actual supported locales */
699 void TmplGettext(StrBuf *Target, WCTemplputParams *TP);
700
701 void set_selected_language(const char *);
702 void go_selected_language(void);
703 void stop_selected_language(void);
704 const char *get_selected_language(void);
705
706 void utf8ify_rfc822_string(char **buf);
707
708 void begin_burst(void);
709 long end_burst(void);
710
711 void AppendImportantMessage(const char *pch, long len);
712
713 void http_datestring(char *buf, size_t n, time_t xtime);
714
715
716 /* These should be empty, but we have them for testing */
717 #define DEFAULT_HTTPAUTH_USER   ""
718 #define DEFAULT_HTTPAUTH_PASS   ""
719
720
721 /* Exit codes 101 through 109 are initialization failures so we don't want to
722  * just keep respawning indefinitely.
723  */
724 #define WC_EXIT_BIND            101     /* Can't bind to the port */
725 #define WC_EXIT_SSL             102     /* Can't initialize SSL */
726
727
728 #define WC_TIMEFORMAT_NONE 0
729 #define WC_TIMEFORMAT_AMPM 1
730 #define WC_TIMEFORMAT_24 2
731
732 extern int time_to_die;                 /* Nonzero if server is shutting down */
733 extern int DisableGzip;
734
735 /* 
736  * Array type for a blog post.  The first message is the post; the rest are comments
737  */
738 struct blogpost {
739         int top_level_id;
740         long *msgs;             /* Array of msgnums for messages we are displaying */
741         int num_msgs;           /* Number of msgnums stored in 'msgs' */
742         int alloc_msgs;         /* Currently allocated size of array */
743 };
744
745
746 /*
747  * Data which gets returned from a call to blogview_learn_thread_references()
748  */
749 struct bltr {
750         int id;
751         int refs;
752 };
753
754
755 struct bltr blogview_learn_thread_references(long msgnum);
756 void tmplput_blog_permalink(StrBuf *Target, WCTemplputParams *TP);
757 void display_summary_page(void);