Back to index

webcit  8.12-dfsg
webcit.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1987-2012 by the citadel.org team
00003  *
00004  * This program is open source software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License version 3.
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU General Public License for more details.
00011  */
00012 
00013 #include "sysdep.h"
00014 #include <sys/select.h>
00015 #include <ctype.h>
00016 #include <stdlib.h>
00017 #ifdef HAVE_UNISTD_H
00018 #include <unistd.h>
00019 #endif
00020 #include <stdio.h>
00021 #ifdef HAVE_FCNTL_H
00022 #include <fcntl.h>
00023 #endif
00024 #include <signal.h>
00025 #include <sys/types.h>
00026 #include <sys/wait.h>
00027 #include <sys/socket.h>
00028 #ifdef HAVE_SYS_TIME_H
00029 #include <sys/time.h>
00030 #endif
00031 #include <sys/stat.h>
00032 #ifdef HAVE_LIMITS_H
00033 #include <limits.h>
00034 #endif
00035 #include <sys/socket.h>
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 #include <netdb.h>
00039 #include <sys/un.h>
00040 #include <sys/poll.h>
00041 #include <string.h>
00042 #include <pwd.h>
00043 #include <errno.h>
00044 #include <stdarg.h>
00045 #include <pthread.h>
00046 #include <signal.h>
00047 #include <syslog.h>
00048 #include <sys/utsname.h>
00049 #include <expat.h>
00050 #include <libcitadel.h>
00051 
00052 #ifdef HAVE_ICONV
00053 #include <iconv.h>
00054 #endif
00055 
00056 #ifdef ENABLE_NLS
00057 #ifdef HAVE_XLOCALE_H
00058 #include <xlocale.h>
00059 #endif
00060 #include <libintl.h>
00061 #include <locale.h>
00062 #define _(string)    gettext(string)
00063 #else
00064 #define _(string)    (string)
00065 #endif
00066 
00067 #define IsEmptyStr(a) ((a)[0] == '\0')
00068 
00069 #define DO_DBG_QR 0
00070 #define DBG_QR(x) if(DO_DBG_QR) _DBG_QR(x)
00071 #define DBG_QR2(x) if(DO_DBG_QR) _DBG_QR2(x)
00072 
00073 #include <zlib.h>
00074 
00075 #include <libical/ical.h>
00076 
00077 #undef PACKAGE
00078 #undef VERSION
00079 #undef PACKAGE_NAME
00080 #undef PACKAGE_STRING
00081 #undef PACKAGE_TARNAME
00082 #undef PACKAGE_VERSION
00083 #undef PACKAGE_BUGREPORT
00084 
00085 typedef struct wcsession wcsession;
00086 
00087 #include "sysdep.h"
00088 
00089 #include "subst.h"
00090 #include "messages.h"
00091 #include "paramhandling.h"
00092 #include "roomops.h"
00093 #include "preferences.h"
00094 
00095 #include "tcp_sockets.h"
00096 #include "utils.h"
00097 #ifdef HAVE_OPENSSL
00098 /* Work around RedHat's b0rken OpenSSL includes */
00099 #define OPENSSL_NO_KRB5
00100 #include <openssl/ssl.h>
00101 #include <openssl/err.h>
00102 #include <openssl/rand.h>
00103 extern char *ssl_cipher_list;
00104 #define       DEFAULT_SSL_CIPHER_LIST     "DEFAULT"     /* See http://openssl.org/docs/apps/ciphers.html */
00105 #endif
00106 
00107 #if SIZEOF_SIZE_T == SIZEOF_INT 
00108 #define SIZE_T_FMT "%d"
00109 #else
00110 #define SIZE_T_FMT "%ld"
00111 #endif
00112 
00113 #if SIZEOF_LONG_UNSIGNED_INT == SIZEOF_INT
00114 #define ULONG_FMT "%d"
00115 #else
00116 #define ULONG_FMT "%ld"
00117 #endif
00118 
00119 #define CALENDAR_ROOM_NAME  "Calendar"
00120 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
00121 
00122 #define SIZ                 4096          /* generic buffer size */
00123 
00124 #define TRACE syslog(LOG_DEBUG, "\033[3%dmCHECKPOINT: %s:%d\033[0m", ((__LINE__%6)+1), __FILE__, __LINE__)
00125 
00126 #define SLEEPING            180           /* TCP connection timeout */
00127 #define WEBCIT_TIMEOUT             900           /* WebCit session timeout */
00128 #define PORT_NUM            2000          /* port number to listen on */
00129 #define DEVELOPER_ID        0
00130 #define CLIENT_ID           4
00131 #define CLIENT_VERSION             812           /* This version of WebCit */
00132 #define MINIMUM_CIT_VERSION 812           /* Minimum required version of Citadel server */
00133 #define       LIBCITADEL_MIN              812           /* Minimum required version of libcitadel */
00134 #define DEFAULT_HOST        "localhost"   /* Default Citadel server */
00135 #define DEFAULT_PORT        "504"
00136 #define TARGET                     "webcit01"    /* Window target for inline URL's */
00137 #define HOUSEKEEPING        15            /* Housekeeping frequency */
00138 #define MAX_WORKER_THREADS  250
00139 #define LISTEN_QUEUE_LENGTH 100           /* listen() backlog queue */
00140 
00141 #define USERCONFIGROOM             "My Citadel Config"
00142 #define DEFAULT_MAXMSGS            20
00143 
00144 
00145 #ifdef LIBCITADEL_VERSION_NUMBER
00146 #if LIBCITADEL_VERSION_NUMBER < LIBCITADEL_MIN
00147 #error libcitadel is too old.  Please upgrade it before continuing.
00148 #endif
00149 #endif
00150 
00151 
00152 /*
00153  * Room flags (from Citadel)
00154  *
00155  * bucket one...
00156  */
00157 #define QR_PERMANENT 1             /* Room does not purge                    */
00158 #define QR_INUSE     2             /* Set if in use, clear if avail   */
00159 #define QR_PRIVATE   4             /* Set for any type of private room       */
00160 #define QR_PASSWORDED       8             /* Set if there's a password too   */
00161 #define QR_GUESSNAME 16            /* Set if it's a guessname room           */
00162 #define QR_DIRECTORY 32            /* Directory room                  */
00163 #define QR_UPLOAD    64            /* Allowed to upload               */
00164 #define QR_DOWNLOAD  128           /* Allowed to download                    */
00165 #define QR_VISDIR    256           /* Visible directory               */
00166 #define QR_ANONONLY  512           /* Anonymous-Only room                    */
00167 #define QR_ANONOPT   1024          /* Anonymous-Option room           */
00168 #define QR_NETWORK   2048          /* Shared network room                    */
00169 #define QR_PREFONLY  4096          /* Preferred status needed to enter       */
00170 #define QR_READONLY  8192          /* Aide status required to post           */
00171 #define QR_MAILBOX   16384         /* Set if this is a private mailbox       */
00172 
00173 /*
00174  * bucket two...
00175  */
00176 #define QR2_SYSTEM   1             /* System room; hide by default           */
00177 #define QR2_SELFLIST 2             /* Self-service mailing list mgmt  */
00178 #define QR2_COLLABDEL       4             /* Anyone who can post can also delete    */
00179 #define QR2_SUBJECTREQ  8               /* Subject strongly recommended             */
00180 #define QR2_SMTP_PUBLIC 16              /* smtp public postable room         */
00181 #define QR2_MODERATED       32            /* Listservice aide has to permit posts   */
00182 
00183 /*
00184  * user/room access
00185  */
00186 #define UA_KNOWN            2
00187 #define UA_GOTOALLOWED             4
00188 #define UA_HASNEWMSGS              8
00189 #define UA_ZAPPED           16
00190 #define UA_POSTALLOWED          32
00191 #define UA_ADMINALLOWED         64
00192 #define UA_DELETEALLOWED        128
00193 #define UA_ISTRASH              256       /* Only available in room view... */
00194 
00195 
00196 /*
00197  * User flags (from Citadel)
00198  */
00199 #define US_NEEDVALID 1             /* User needs to be validated             */
00200 #define US_PERM             4             /* Permanent user                  */
00201 #define US_LASTOLD   16            /* Print last old message with new */
00202 #define US_EXPERT    32            /* Experienced user                */
00203 #define US_UNLISTED  64            /* Unlisted userlog entry          */
00204 #define US_NOPROMPT  128           /* Don't prompt after each message */
00205 #define US_PROMPTCTL 256           /* <N>ext & <S>top work at prompt  */
00206 #define US_DISAPPEAR 512           /* Use "disappearing msg prompts"  */
00207 #define US_REGIS     1024          /* Registered user                 */
00208 #define US_PAGINATOR 2048          /* Pause after each screen of text */
00209 #define US_INTERNET  4096          /* Internet mail privileges        */
00210 #define US_FLOORS    8192          /* User wants to see floors        */
00211 #define US_COLOR     16384         /* User wants ANSI color support   */
00212 #define US_USER_SET  (US_LASTOLD | US_EXPERT | US_UNLISTED | \
00213                      US_NOPROMPT | US_DISAPPEAR | US_PAGINATOR | \
00214                      US_FLOORS | US_COLOR | US_PROMPTCTL )
00215 
00216 
00217 
00218 #define SRV_STATUS_MSG(ServerLineBuf) (ChrPtr(ServerLineBuf) + 4), (StrLength(ServerLineBuf) - 4)
00219 #define MAJORCODE(a) (((int)(a / 100) ) * 100)
00220 
00221 #define LISTING_FOLLOWS     100
00222 #define CIT_OK              200    
00223 #define MORE_DATA    300
00224 #define SEND_LISTING        400
00225 #define ERROR               500
00226 #define BINARY_FOLLOWS      600
00227 #define SEND_BINARY  700
00228 #define START_CHAT_MODE     800
00229 #define ASYNC_MSG    900
00230 
00231 #define MINORCODE(a) (a % 100)
00232 #define ASYNC_GEXP                 02     
00233 #define INTERNAL_ERROR                    10     
00234 #define TOO_BIG                    11     
00235 #define ILLEGAL_VALUE                     12     
00236 #define NOT_LOGGED_IN                     20     
00237 #define CMD_NOT_SUPPORTED          30     
00238 #define SERVER_SHUTTING_DOWN              31     
00239 #define PASSWORD_REQUIRED          40     
00240 #define ALREADY_LOGGED_IN          41     
00241 #define USERNAME_REQUIRED          42     
00242 #define HIGHER_ACCESS_REQUIRED            50     
00243 #define MAX_SESSIONS_EXCEEDED             51     
00244 #define RESOURCE_BUSY                     52     
00245 #define RESOURCE_NOT_OPEN          53     
00246 #define NOT_HERE                   60     
00247 #define INVALID_FLOOR_OPERATION    61     
00248 #define NO_SUCH_USER                      70     
00249 #define FILE_NOT_FOUND                    71     
00250 #define ROOM_NOT_FOUND                    72     
00251 #define NO_SUCH_SYSTEM                    73     
00252 #define ALREADY_EXISTS                    74     
00253 #define MESSAGE_NOT_FOUND          75
00254 
00255 /*
00256  * NLI is the string that shows up in a who's online listing for sessions
00257  * that are active but do not (yet) have a user logged in.
00258  */
00259 #define NLI   "(not logged in)"
00260 
00261 /*
00262  * Expiry policy for the autopurger
00263  */
00264 #define EXPIRE_NEXTLEVEL        0       /* Inherit expiration policy    */
00265 #define EXPIRE_MANUAL           1       /* Don't expire messages at all */
00266 #define EXPIRE_NUMMSGS          2       /* Keep only latest n messages  */
00267 #define EXPIRE_AGE              3       /* Expire messages after n days */
00268 
00269 typedef struct __ExpirePolicy {
00270         int expire_mode;
00271         int expire_value;
00272 } ExpirePolicy;
00273 void LoadExpirePolicy(GPEXWhichPolicy which);
00274 void SaveExpirePolicyFromHTTP(GPEXWhichPolicy which);
00275 
00276 /*
00277  * Linked list of session variables encoded in an x-www-urlencoded content type
00278  */
00279 typedef struct urlcontent urlcontent;
00280 struct urlcontent {
00281        char url_key[32];           /* key */
00282        StrBuf *url_data;           /* value */
00283 };
00284 
00285 /*
00286  * Information about the Citadel server to which we are connected
00287  */ 
00288 typedef struct _serv_info {
00289        int serv_pid;               /* Process ID of the Citadel server */
00290        StrBuf *serv_nodename;             /* Node name of the Citadel server */
00291        StrBuf *serv_humannode;             /* Juman readable node name of the Citadel server */
00292        StrBuf *serv_fqdn;          /* Fully qualified Domain Name (such as uncensored.citadel.org) */
00293        StrBuf *serv_software;             /* Free form text description of the server software in use */
00294        int serv_rev_level;         /* Server version number (times 100) */
00295        StrBuf *serv_bbs_city;             /* Geographic location of the Citadel server */
00296        StrBuf *serv_sysadm;        /* Name of system administrator */
00297        int serv_supports_ldap;            /* is the server linked against an ldap tree for adresses? */
00298        int serv_newuser_disabled;  /* Has the server disabled self-service new user creation? */
00299        StrBuf *serv_default_cal_zone;  /* Default timezone for unspecified calendar items */
00300        int serv_supports_sieve;    /* Server supports Sieve mail filtering */
00301        int serv_fulltext_enabled;  /* Full text index is enabled */
00302        StrBuf *serv_svn_revision;  /* svn or git revision of the server */
00303        int serv_supports_openid;   /* Server supports authentication via OpenID */
00304        int serv_supports_guest;    /* Server supports unauthenticated guest logins */
00305 } ServInfo;
00306 
00307 
00308 typedef struct _disp_cal {                              
00309        icalcomponent *cal;         /* cal items for display */
00310        long cal_msgnum;            /* cal msgids for display */
00311        char *from;                     /* owner of this component */
00312        int unread;                     /* already seen by the user? */
00313 
00314        time_t event_start;
00315        time_t event_end;
00316 
00317        int multi_day_event;
00318        int is_repeat;
00319        icalcomponent *SortBy;             /* cal items for display */
00320        icalproperty_status Status;
00321 } disp_cal;                                      
00322 
00323 typedef struct _IcalEnumMap {
00324        const char *Name;
00325        long NameLen;
00326        icalproperty_kind map;
00327 } IcalEnumMap;
00328 
00329 /*
00330  * Address book entry (keep it short and sweet, it's just a quickie lookup
00331  * which we can use to get to the real meat and bones later)
00332  */
00333 typedef struct _addrbookent {
00334        char ab_name[64];    /* name string */
00335        long ab_msgnum;             /* message number of address book entry */
00336 } addrbookent;
00337 
00338 
00339 #define AJAX (1<<0)
00340 #define ANONYMOUS (1<<1)
00341 #define NEED_URL (1<<2)
00342 #define XHTTP_COMMANDS (1<<3)
00343 #define BOGUS (1<<4)
00344 #define URLNAMESPACE (1<<4)
00345 #define LOGCHATTY (1<<5)
00346 #define COOKIEUNNEEDED (1<<6)
00347 #define ISSTATIC (1<<7)
00348 #define FORCE_SESSIONCLOSE (1<<8)
00349 #define PARSE_REST_URL (1<<9)
00350 #define PROHIBIT_STARTPAGE (1<<10)
00351 
00352 
00353 #define DATEFMT_FULL 0
00354 #define DATEFMT_BRIEF 1
00355 #define DATEFMT_RAWDATE 2
00356 #define DATEFMT_LOCALEDATE 3
00357 void webcit_fmt_date(char *buf, size_t siz, time_t thetime, int Format);
00358 
00359 
00360 typedef enum _RESTDispatchID {
00361        ExistsID,
00362        PutID,
00363        DeleteID
00364 } RESTDispatchID;
00365 
00366 typedef int (*WebcitRESTDispatchID)(RESTDispatchID WhichAction, int IgnoreFloor);
00367 typedef void (*WebcitHandlerFunc)(void);
00368 typedef struct  _WebcitHandler{
00369        WebcitHandlerFunc F;
00370        WebcitRESTDispatchID RID;
00371        long Flags;
00372        StrBuf *Name;
00373        StrBuf *DisplayName;
00374 } WebcitHandler;
00375 
00376 
00377 void WebcitAddUrlHandler(const char * UrlString, long UrlSLen, const char *DisplayName, long dslen, WebcitHandlerFunc F, long Flags);
00378 
00379 typedef struct _headereval {
00380        ExamineMsgHeaderFunc evaluator;
00381        int Type;
00382 } headereval;
00383 
00384 
00385 struct attach_link {
00386        char partnum[32];
00387        char html[1024];
00388 };
00389 
00390 
00391 enum {
00392        eUp,
00393        eDown,
00394        eNone
00395 };
00396 
00397 enum {
00398        eGET,
00399        ePOST,
00400        eOPTIONS,
00401        ePROPFIND,
00402        ePUT,
00403        eDELETE,
00404        eHEAD,
00405        eMOVE,
00406        eCOPY,
00407        eREPORT,
00408        eNONE
00409 };
00410 extern const char *ReqStrs[eNONE];
00411 
00412 #define NO_AUTH 0
00413 #define AUTH_COOKIE 1
00414 #define AUTH_BASIC 2
00415 
00416 
00417 
00418 typedef struct _HdrRefs {
00419        long eReqType;                            /* HTTP method */
00420        int desired_session;
00421        int SessionKey;
00422 
00423        int got_auth;
00424        int DontNeedAuth;
00425        long ContentLength;
00426        time_t if_modified_since;
00427        int gzip_ok;                       /* Nonzero if Accept-encoding: gzip */
00428        int prohibit_caching;
00429        int dav_depth;
00430        int Static;
00431 
00432        /* these are references into Hdr->HTTPHeaders, so we don't need to free them. */
00433        StrBuf *ContentType;
00434        StrBuf *RawCookie;
00435        StrBuf *ReqLine;
00436        StrBuf *browser_host;
00437        StrBuf *browser_language;
00438        StrBuf *user_agent;
00439        StrBuf *plainauth;
00440        StrBuf *dav_ifmatch;
00441 
00442        const WebcitHandler *Handler;
00443 } HdrRefs;
00444 
00445 typedef struct _ParsedHttpHdrs {
00446        int http_sock;                            /* HTTP server socket */
00447        const char *Pos;
00448        StrBuf *ReadBuf;
00449 
00450        StrBuf *c_username;
00451        StrBuf *c_password;
00452        StrBuf *c_roomname;
00453        StrBuf *c_language;
00454        StrBuf *this_page;                 /* URL of current page */
00455        StrBuf *PlainArgs; 
00456        StrBuf *HostHeader;
00457 
00458        HashList *urlstrings;                      /* variables passed to webcit in a URL */
00459        HashList *HTTPHeaders;                  /* the headers the client sent us */
00460        int nWildfireHeaders;                   /* how many wildfire headers did we already send? */
00461 
00462        HdrRefs HR;
00463 } ParsedHttpHdrs;
00464 
00465 
00466 /*
00467  * One of these is kept for each active Citadel session.
00468  * HTTP transactions are bound to one at a time.
00469  */
00470 struct wcsession {
00471 /* infrastructural members */
00472        wcsession *next;                   /* Linked list */
00473        pthread_mutex_t SessionMutex;             /* mutex for exclusive access */
00474        int wc_session;                           /* WebCit session ID */
00475        int killthis;                      /* Nonzero == purge this session */
00476        int ctdl_pid;                      /* Session ID on the Citadel server */
00477        int nonce;                         /* session nonce (to prevent session riding) */
00478        int inuse;                         /* set to nonzero if bound to a running thread */
00479 
00480 /* Session local Members */
00481        int serv_sock;                            /* Client socket to Citadel server */
00482        StrBuf *ReadBuf;                        /* linebuffered reads from the server */
00483        StrBuf *MigrateReadLineBuf;             /* here we buffer legacy server read stuff */
00484        const char *ReadPos;                    /* whats our read position in ReadBuf? */
00485        int last_chat_seq;                 /* When in chat - last message seq# we saw */
00486        time_t lastreq;                           /* Timestamp of most recent HTTP */
00487        time_t last_pager_check;           /* last time we polled for instant msgs */
00488        ServInfo *serv_info;               /* Information about the citserver we're connected to */
00489        StrBuf *PushedDestination;         /* Where to go after login, registration, etc. */
00490 
00491 /* Request local Members */
00492        StrBuf *CLineBuf;                       /* linebuffering client stuff */
00493        ParsedHttpHdrs *Hdr;
00494        StrBuf *WBuf;                           /* Our output buffer */
00495        StrBuf *HBuf;                           /* Our HeaderBuffer */
00496        StrBuf *WFBuf;                          /* Wildfire error logging buffer */
00497        StrBuf *trailing_javascript;              /* extra javascript to be appended to page */
00498        StrBuf *ImportantMsg;
00499        HashList *Directory;               /* Parts of the directory URL in snippets */
00500        const Floor *CurrentFloor;              /* when Parsing REST, which floor are we on? */
00501 
00502 /* accounting */
00503        StrBuf *wc_username;               /* login name of current user */
00504        StrBuf *wc_fullname;               /* Screen name of current user */
00505        StrBuf *wc_password;               /* Password of current user */
00506        StrBuf *httpauth_pass;             /* only for GroupDAV sessions */
00507        int axlevel;                       /* this user's access level */
00508        int is_aide;                       /* nonzero == this user is an Aide */
00509        int connected;                            /* nonzero == we are connected to Citadel */
00510        int logged_in;                            /* nonzero == we are logged in  */
00511        int need_regi;                            /* This user needs to register. */
00512        int need_vali;                            /* New users require validation. */
00513 
00514 /* Preferences */
00515        StrBuf *cs_inet_email;             /* User's preferred Internet addr. */
00516        HashList *hash_prefs;                     /* WebCit preferences for this user */
00517        StrBuf *DefaultCharset;                 /* Charset the user preferes */
00518        int downloaded_prefs;                   /* Has the client download its prefs yet? */
00519        int SavePrefsToServer;                  /* Should we save our preferences to the server at the end of the request? */
00520        int selected_language;                    /* Language selected by user */
00521        int time_format_cache;                  /* which timeformat does our user like? */
00522 
00523        folder CurRoom;                         /* information about our current room */
00524        const folder *ThisRoom;                 /* if REST found a room, remember it here. */
00525 /* next/previous room thingabob */
00526        struct march *march;               /* march mode room list */
00527        char ugname[128];                  /* where does 'ungoto' take us */
00528        long uglsn;                        /* last seen message number for ungoto */
00529 
00530 /* Uploading; mime attachments for composing messages */
00531        HashList *attachments;                    /* list of attachments for 'enter message' */
00532        int upload_length;                 /* content length of http-uploaded data */
00533        StrBuf *upload;                           /* pointer to http-uploaded data */
00534        StrBuf *upload_filename;           /* filename of http-uploaded data */
00535        char upload_content_type[256];            /* content type of http-uploaded data */
00536 
00537        int remember_new_mail;                    /* last count of new mail messages */
00538 
00539 /* Roomiew control */
00540        HashList *Floors;                       /* floors our citserver has hashed numeric for quicker access*/
00541        HashList *FloorsByName;                 /* same but hashed by its name */
00542        HashList *Rooms;                        /* our directory structure as loaded by LKRA */
00543        HashList *summ;                         /* list of messages for mailbox summary view */
00545        long startmsg;                          /* message number to start at */
00546        long maxmsgs;                           /* maximum messages to display */
00547         long num_displayed;                     /* number of messages actually displayed */
00548        HashList *disp_cal_items;               /* sorted list of calendar items; startdate is the sort criteria. */
00549 
00550 
00551        char last_chat_user[256];
00552 
00553 /* Iconbar controls */
00554        int cache_max_folders;
00555        int cache_num_floors;
00556        long *IBSettingsVec;                    /* which icons should be shown / not shown? */
00557        const StrBuf *floordiv_expanded;   /* which floordiv currently expanded */
00558        int ib_wholist_expanded;
00559        int ib_roomlist_expanded;
00560 
00561 /* our known Sieve scripts; loaded by SIEVE:SCRIPTS iterator. */
00562        HashList *KnownSieveScripts;
00563 
00564 /* Transcoding cache buffers; used to avoid to frequent realloc */
00565        StrBuf *ConvertBuf1;
00566        StrBuf *ConvertBuf2;
00567 
00568 /* cache stuff for templates. TODO: find a smarter way */
00569        HashList *ServCfg;                      /* cache our server config for editing */
00570        HashList *InetCfg;                      /* Our inet server config for editing */
00571        ExpirePolicy Policy[maxpolicy];
00572 
00573 /* used by the blog viewer */
00574        int bptlid;                        /* hash of thread currently being rendered */
00575 };
00576 
00577 
00578 typedef void (*Header_Evaluator)(StrBuf *Line, ParsedHttpHdrs *hdr);
00579 
00580 typedef struct _HttpHeader {
00581        Header_Evaluator H;
00582        StrBuf *Val;
00583        int HaveEvaluator;
00584 } OneHttpHeader;
00585 
00586 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F);
00587 
00588 
00589 enum {
00590        S_SHUTDOWN,
00591        S_SPAWNER,
00592        MAX_SEMAPHORES
00593 };
00594 
00595 #ifndef num_parms
00596 #define num_parms(source)          num_tokens(source, '|') 
00597 #endif
00598 
00599 #define site_prefix  (WC ? (WC->Hdr->HostHeader) : NULL)
00600 
00601 /* Per-session data */
00602 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
00603 extern pthread_key_t MyConKey;
00604 
00605 /* Per-thread SSL context */
00606 #ifdef HAVE_OPENSSL
00607 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
00608 extern pthread_key_t ThreadSSL;
00609 extern char ctdl_key_dir[PATH_MAX];
00610 extern char file_crpt_file_key[PATH_MAX];
00611 extern char file_crpt_file_csr[PATH_MAX];
00612 extern char file_crpt_file_cer[PATH_MAX];
00613 
00614 void init_ssl(void);
00615 void endtls(void);
00616 void ssl_lock(int mode, int n, const char *file, int line);
00617 int starttls(int sock);
00618 extern SSL_CTX *ssl_ctx;  
00619 int client_read_sslbuffer(StrBuf *buf, int timeout);
00620 void client_write_ssl(const StrBuf *Buf);
00621 #endif
00622 
00623 extern int is_https;
00624 extern int follow_xff;
00625 extern char *server_cookie;
00626 extern char *ctdlhost, *ctdlport;
00627 extern char *axdefs[];
00628 extern int num_threads_existing;
00629 extern int num_threads_executing;
00630 extern int setup_wizard;
00631 extern char wizard_filename[];
00632 
00633 void InitialiseSemaphores(void);
00634 void begin_critical_section(int which_one);
00635 void end_critical_section(int which_one);
00636 
00637 
00638 extern void do_404(void);
00639 void http_redirect(const char *);
00640 
00641 
00642 #ifdef UBER_VERBOSE_DEBUGGING
00643 #define wc_printf(...) wcc_printf(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
00644 void wcc_printf(const char *FILE, const char *FUNCTION, long LINE, const char *format, ...);
00645 #else 
00646 void wc_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
00647 #endif
00648 
00649 void hprintf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
00650 
00651 void CheckAuthBasic(ParsedHttpHdrs *hdr);
00652 void GetAuthBasic(ParsedHttpHdrs *hdr);
00653 
00654 void sleeeeeeeeeep(int);
00655 
00656 size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm);
00657 void fmt_time(char *buf, size_t siz, time_t thetime);
00658 void httpdate(char *buf, time_t thetime);
00659 time_t httpdate_to_timestamp(StrBuf *buf);
00660 
00661 
00662 
00663 
00664 void end_webcit_session(void);
00665 
00666 
00667 
00668 
00669 void cookie_to_stuff(StrBuf *cookie,
00670               int *session,
00671               StrBuf *user,
00672               StrBuf *pass,
00673               StrBuf *room,
00674               StrBuf *language
00675 );
00676 void locate_host(StrBuf *TBuf, int);
00677 void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_response);
00678 
00679 void display_login(void);
00680 void display_openids(void);
00681 void display_default_landing_page(void);
00682 void do_welcome(void);
00683 
00684 void display_reg(int during_login);
00685 void display_main_menu(void);
00686 void display_aide_menu(void);
00687 
00688 void RegisterEmbeddableMimeType(const char *MimeType, long MTLen, int Priority);
00689 void CreateMimeStr(void);
00690 
00691 
00692 void pop_destination(void);
00693 
00694 void FmOut(StrBuf *Target, const char *align, const StrBuf *Source);
00695 void wDumpContent(int);
00696 
00697 
00698 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt);
00699 
00700 void output_headers(    int do_httpheaders,
00701                      int do_htmlhead,
00702                      int do_room_banner,
00703                      int unset_cookies,
00704                      int suppress_check,
00705                      int cache);
00706 void output_custom_content_header(const char *ctype);
00707 void cdataout(char *rawdata);
00708 
00709 
00710 void url(char *buf, size_t bufsize);
00711 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
00712 
00713 
00714 void display_vcard(StrBuf *Target, wc_mime_attachment *Mime, char alpha, int full, char **storename, long msgnum);
00715 
00716 void display_success(const char *successmessage);
00717 
00718 void shutdown_sessions(void);
00719 
00720 
00721 
00722 StrBuf *load_mimepart(long msgnum, char *partnum);
00723 void MimeLoadData(wc_mime_attachment *Mime);
00724 void do_edit_vcard(long msgnum, char *partnum, 
00725                  message_summary *VCMsg,
00726                  wc_mime_attachment *VCAtt,
00727                  const char *return_to, 
00728                  const char *force_room);
00729 
00730 void select_user_to_edit(const char *preselect);
00731 
00732 void convenience_page(const char *titlebarcolor, const char *titlebarmsg, const char *messagetext);
00733 void output_html(const char *, int, int, StrBuf *, StrBuf *);
00734 
00735 ssize_t write(int fd, const void *buf, size_t count);
00736 void cal_process_attachment(wc_mime_attachment *Mime);
00737 
00738 void address_book_popup(void);
00739 void begin_ajax_response(void);
00740 void end_ajax_response(void);
00741 
00742 extern char *months[];
00743 extern char *days[];
00744 long locate_user_vcard_in_this_room(message_summary **VCMsg,
00745                                 wc_mime_attachment **VCAtt);
00746 void http_transmit_thing(const char *content_type, int is_static);
00747 long unescape_input(char *buf);
00748 void check_thread_pool_size(void);
00749 void StrEndTab(StrBuf *Target, int tabnum, int num_tabs);
00750 void StrBeginTab(StrBuf *Target, int tabnum, int num_tabs, StrBuf **Names);
00751 void StrTabbedDialog(StrBuf *Target, int num_tabs, StrBuf *tabnames[]);
00752 void tabbed_dialog(int num_tabs, char *tabnames[]);
00753 void begin_tab(int tabnum, int num_tabs);
00754 void end_tab(int tabnum, int num_tabs);
00755 
00756 int get_time_format_cached (void);
00757 void display_wiki_pagelist(void);
00758 void str_wiki_index(char *);
00759 
00760 HashList *GetRoomListHashLKRA(StrBuf *Target, WCTemplputParams *TP);
00761 
00762 /* actual supported locales */
00763 void TmplGettext(StrBuf *Target, WCTemplputParams *TP);
00764 
00765 void set_selected_language(const char *);
00766 void go_selected_language(void);
00767 void stop_selected_language(void);
00768 const char *get_selected_language(void);
00769 
00770 void utf8ify_rfc822_string(char **buf);
00771 
00772 void begin_burst(void);
00773 long end_burst(void);
00774 
00775 void AppendImportantMessage(const char *pch, long len);
00776 
00777 void http_datestring(char *buf, size_t n, time_t xtime);
00778 
00779 
00780 /* These should be empty, but we have them for testing */
00781 #define DEFAULT_HTTPAUTH_USER      ""
00782 #define DEFAULT_HTTPAUTH_PASS      ""
00783 
00784 
00785 /* Exit codes 101 through 109 are initialization failures so we don't want to
00786  * just keep respawning indefinitely.
00787  */
00788 #define WC_EXIT_BIND        101    /* Can't bind to the port */
00789 #define WC_EXIT_SSL         102    /* Can't initialize SSL */
00790 
00791 
00792 #define WC_TIMEFORMAT_NONE 0
00793 #define WC_TIMEFORMAT_AMPM 1
00794 #define WC_TIMEFORMAT_24 2
00795 
00796 extern int time_to_die;                   /* Nonzero if server is shutting down */
00797 extern int DisableGzip;
00798 
00799 /* 
00800  * Array type for a blog post.  The first message is the post; the rest are comments
00801  */
00802 struct blogpost {
00803        int top_level_id;
00804        long *msgs;          /* Array of msgnums for messages we are displaying */
00805        int num_msgs;        /* Number of msgnums stored in 'msgs' */
00806        int alloc_msgs;             /* Currently allocated size of array */
00807 };
00808 
00809 
00810 /*
00811  * Data which gets returned from a call to blogview_learn_thread_references()
00812  */
00813 struct bltr {
00814        int id;
00815        int refs;
00816 };
00817 
00818 
00819 struct bltr blogview_learn_thread_references(long msgnum);
00820 void tmplput_blog_permalink(StrBuf *Target, WCTemplputParams *TP);
00821 void display_summary_page(void);