9 #define WEBCIT_WITH_CALENDAR_SERVICE 1
13 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
18 /* Work around RedHat's b0rken OpenSSL includes */
19 #define OPENSSL_NO_KRB5
20 #include <openssl/ssl.h>
21 #include <openssl/err.h>
22 #include <openssl/rand.h>
25 #define CALENDAR_ROOM_NAME "Calendar"
26 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
28 #define SIZ 4096 /* generic buffer size */
30 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
32 #define SLEEPING 180 /* TCP connection timeout */
33 #define WEBCIT_TIMEOUT 900 /* WebCit session timeout */
34 #define PORT_NUM 2000 /* port number to listen on */
35 #define SERVER "WebCit v5.24" /* who's in da house */
36 #define DEVELOPER_ID 0
38 #define CLIENT_VERSION 524 /* This version of WebCit */
39 #define MINIMUM_CIT_VERSION 626 /* min required Citadel vers */
40 #define DEFAULT_HOST "localhost" /* Default Citadel server */
41 #define DEFAULT_PORT "504"
42 #define LB (1) /* Internal escape chars */
45 #define TARGET "webcit01" /* Target for inline URL's */
46 #define HOUSEKEEPING 15 /* Housekeeping frequency */
47 #define MIN_WORKER_THREADS 5
48 #define MAX_WORKER_THREADS 250
49 #define LISTEN_QUEUE_LENGTH 100 /* listen() backlog queue */
51 #define USERCONFIGROOM "My Citadel Config"
52 #define DEFAULT_MAXMSGS 20
56 * Room flags (from Citadel)
60 #define QR_PERMANENT 1 /* Room does not purge */
61 #define QR_INUSE 2 /* Set if in use, clear if avail */
62 #define QR_PRIVATE 4 /* Set for any type of private room */
63 #define QR_PASSWORDED 8 /* Set if there's a password too */
64 #define QR_GUESSNAME 16 /* Set if it's a guessname room */
65 #define QR_DIRECTORY 32 /* Directory room */
66 #define QR_UPLOAD 64 /* Allowed to upload */
67 #define QR_DOWNLOAD 128 /* Allowed to download */
68 #define QR_VISDIR 256 /* Visible directory */
69 #define QR_ANONONLY 512 /* Anonymous-Only room */
70 #define QR_ANONOPT 1024 /* Anonymous-Option room */
71 #define QR_NETWORK 2048 /* Shared network room */
72 #define QR_PREFONLY 4096 /* Preferred status needed to enter */
73 #define QR_READONLY 8192 /* Aide status required to post */
74 #define QR_MAILBOX 16384 /* Set if this is a private mailbox */
79 #define QR2_SYSTEM 1 /* System room; hide by default */
80 #define QR2_SELFLIST 2 /* Self-service mailing list mgmt */
84 #define UA_GOTOALLOWED 4
85 #define UA_HASNEWMSGS 8
94 struct httprequest *next;
99 struct urlcontent *next;
106 char serv_nodename[32];
107 char serv_humannode[64];
109 char serv_software[64];
111 char serv_bbs_city[64];
112 char serv_sysadm[64];
113 char serv_moreprompt[SIZ];
115 int serv_supports_ldap;
121 * This struct holds a list of rooms for <G>oto operations.
125 char march_name[128];
131 * This struct holds a list of rooms for client display.
135 struct roomlisting *lnext;
136 struct roomlisting *rnext;
146 * Dynamic content for variable substitution in templates
149 struct wcsubst *next;
153 void (*wcs_function)(void);
157 * Values for wcs_type
166 struct wc_attachment {
167 struct wc_attachment *next;
169 char content_type[SIZ];
175 * One of these is kept for each active Citadel session.
176 * HTTP transactions are bound to one at a time.
179 struct wcsession *next; /* Linked list */
180 int wc_session; /* WebCit session ID */
181 char wc_username[SIZ];
182 char wc_password[SIZ];
183 char wc_roomname[SIZ];
200 char upload_filename[SIZ];
201 char upload_content_type[SIZ];
203 int remember_new_mail;
204 int need_regi; /* This user needs to register. */
205 int need_vali; /* New users require validation. */
206 char cs_inet_email[SIZ]; /* User's preferred Internet addr. */
207 pthread_mutex_t SessionMutex; /* mutex for exclusive access */
208 time_t lastreq; /* Timestamp of most recent HTTP */
209 int killthis; /* Nonzero == purge this session */
210 struct march *march; /* march mode room list */
211 char reply_to[SIZ]; /* reply-to address */
212 long msgarr[4096]; /* for read operations */
214 int is_wap; /* Client is a WAP gateway */
215 struct urlcontent *urlstrings;
216 int HaveExpressMessages; /* Nonzero if incoming msgs exist */
217 struct wcsubst *vars;
218 char this_page[SIZ]; /* address of current page */
219 char http_host[SIZ]; /* HTTP Host: header */
221 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
223 icalcomponent *cal; /* cal items for display */
224 long cal_msgnum; /* cal msgids for display */
228 struct wc_attachment *first_attachment;
229 char ImportantMessage[SIZ];
230 int outside_frameset_allowed; /* nonzero if current req is allowed
231 * outside of the main frameset */
232 char last_chat_user[SIZ];
235 #define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|')
236 #define num_parms(source) num_tokens(source, '|')
238 /* Per-session data */
239 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
240 extern pthread_key_t MyConKey;
242 /* Per-thread SSL context */
244 #define THREADSSL ((SSL *)pthread_getspecific(ThreadSSL))
245 extern pthread_key_t ThreadSSL;
248 struct serv_info serv_info;
249 extern char floorlist[128][SIZ];
250 extern char *axdefs[];
251 extern char *ctdlhost, *ctdlport;
252 extern char *server_cookie;
255 extern struct wcsubst *global_subst;
258 void stuff_to_cookie(char *cookie, int session,
259 char *user, char *pass, char *room);
260 void cookie_to_stuff(char *cookie, int *session,
261 char *user, char *pass, char *room);
262 void locate_host(char *, int);
263 void become_logged_in(char *, char *, char *);
265 void display_login(char *mesg);
266 void do_welcome(void);
267 void do_logout(void);
268 void display_main_menu(void);
269 void display_advanced_menu(void);
270 void slrp_highest(void);
273 void get_serv_info(char *, char *);
274 int uds_connectsock(char *);
275 int tcp_connectsock(char *, char *);
276 void serv_gets(char *strbuf);
277 void serv_puts(char *string);
279 void fmout(FILE *fp, char *align);
280 void wDumpContent(int);
281 void serv_printf(const char *format,...);
282 char *bstr(char *key);
283 void urlesc(char *, char *);
284 void urlescputs(char *);
285 void jsesc(char *, char *);
286 void jsescputs(char *);
287 void output_headers(int);
288 void wprintf(const char *format,...);
289 void output_static(char *what);
290 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks);
291 void escputs(char *strbuf);
293 void escputs1(char *strbuf, int nbsp, int nolinebreaks);
294 void msgesc(char *target, char *strbuf);
295 void msgescputs(char *strbuf);
296 long extract_long(char *source, long int parmnum);
297 int extract_int(char *source, int parmnum);
298 void stripout(char *str, char leftboundary, char rightboundary);
299 void dump_vars(void);
300 void embed_main_menu(void);
301 void serv_read(char *buf, int bytes);
302 int haschar(char *, char);
303 void readloop(char *oper);
304 void text_to_server(char *ptr, int convert_to_html);
305 void display_enter(void);
306 void post_message(void);
307 void confirm_delete_msg(void);
308 void delete_msg(void);
309 void do_stuff_to_one_msg(void);
310 void confirm_move_msg(void);
314 void display_page(void);
315 void page_user(void);
317 void display_private(char *rname, int req_pass);
318 void goto_private(void);
319 void zapped_list(void);
320 void display_zap(void);
322 void display_success(char *);
323 void display_entroom(void);
325 void display_editroom(void);
328 void display_whok(void);
329 void server_to_text(void);
330 void save_edit(char *description, char *enter_cmd, int regoto);
331 void display_edit(char *description, char *check_cmd,
332 char *read_cmd, char *save_cmd, int headers_type);
333 void gotoroom(char *gname);
334 void confirm_delete_room(void);
335 void delete_room(void);
337 void display_graphics_upload(char *, char *, char *);
338 void do_graphics_upload(char *upl_cmd);
339 void serv_read(char *buf, int bytes);
340 void serv_gets(char *strbuf);
341 void serv_write(char *buf, int nbytes);
342 void serv_puts(char *string);
343 void serv_printf(const char *format,...);
344 void load_floorlist(void);
345 void display_reg(int);
346 void display_changepw(void);
348 void display_edit_node(void);
349 void edit_node(void);
350 void display_netconf(void);
351 void display_confirm_delete_node(void);
352 void delete_node(void);
353 void display_add_node(void);
355 void terminate_session(void);
357 void display_siteconfig(void);
358 void siteconfig(void);
359 void display_generic(void);
360 void do_generic(void);
361 void display_menubar(int);
362 void embed_room_banner(char *);
363 void smart_goto(char *);
364 void worker_entry(void);
365 void session_loop(struct httprequest *);
366 void fmt_date(char *buf, time_t thetime);
367 void fmt_time(char *buf, time_t thetime);
368 void httpdate(char *buf, time_t thetime);
369 void end_webcit_session(void);
370 void page_popup(void);
371 void chat_recv(void);
372 void chat_send(void);
373 void http_redirect(char *);
374 void clear_local_substs(void);
375 void svprintf(char *keyname, int keytype, const char *format,...);
376 void svcallback(char *keyname, void (*fcn_ptr)() );
377 void do_template(void *templatename);
378 int lingering_close(int fd);
379 char *memreadline(char *start, char *buf, int maxlen);
380 int num_tokens (char *source, char tok);
381 void extract_token(char *dest, char *source, int parmnum, char separator);
382 void remove_token(char *source, int parmnum, char separator);
383 char *load_mimepart(long msgnum, char *partnum);
384 int pattern2(char *search, char *patn);
385 void do_edit_vcard(long, char *, char *);
386 void edit_vcard(void);
387 void submit_vcard(void);
388 void striplt(char *);
389 void select_user_to_edit(char *message, char *preselect);
390 void display_edituser(char *who, int is_new);
391 void create_user(void);
393 void do_change_view(int);
394 void change_view(void);
396 void do_stuff_to_msgs(void);
397 void load_preferences(void);
398 void save_preferences(void);
399 void get_preference(char *key, char *value);
400 void set_preference(char *key, char *value);
402 int is_msg_in_mset(char *mset, long msgnum);
403 char *safestrncpy(char *dest, const char *src, size_t n);
404 void display_addressbook(long msgnum, char alpha);
405 void offer_start_page(void);
406 void change_start_page(void);
407 void output_html(void);
408 void display_floorconfig(char *);
409 void delete_floor(void);
410 void create_floor(void);
411 void rename_floor(void);
412 void do_listsub(void);
413 void toggle_self_service(void);
415 ssize_t write(int fd, const void *buf, size_t count);
416 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
417 void display_calendar(long msgnum);
418 void display_task(long msgnum);
419 void do_calendar_view(void);
420 void do_tasks_view(void);
421 void free_calendar_buffer(void);
422 void calendar_summary_view(void);
423 int load_msg_ptrs(char *servcmd);
424 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
425 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
426 void free_attachments(struct wcsession *sess);
427 void set_room_policy(void);
428 void display_inetconf(void);
429 void save_inetconf(void);
432 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
433 void display_edit_task(void);
434 void save_task(void);
435 void display_edit_event(void);
436 void save_event(void);
437 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
438 struct icaltimetype icaltime_from_webform(char *prefix);
439 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
440 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
441 void generate_new_uid(char *);
442 void respond_to_request(void);
443 void handle_rsvp(void);
444 void ical_dezonify(icalcomponent *cal);
445 void partstat_as_string(char *buf, icalproperty *attendee);
446 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
447 void check_attendee_availability(icalcomponent *supplied_vevent);
448 void do_freebusy(char *req);
451 extern char *months[];
453 void read_server_binary(char *buffer, size_t total_len);
454 char *read_server_text(void);
455 int goto_config_room(void);
456 long locate_user_vcard(char *username, long usernum);
457 void sleeeeeeeeeep(int);
458 void http_transmit_thing(char *thing, size_t length, char *content_type,
460 void unescape_input(char *buf);
461 void do_iconbar(void);
462 void display_customize_iconbar(void);
463 void commit_iconbar(void);
464 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
465 void spawn_another_worker_thread(void);
472 void ssl_lock(int mode, int n, const char *file, int line);
473 int starttls(int sock);
474 extern SSL_CTX *ssl_ctx;
475 int client_read_ssl(char *buf, int bytes, int timeout);
476 void client_write_ssl(char *buf, int nbytes);
481 /* Views (from citadel.h) */
482 #define VIEW_BBS 0 /* Traditional Citadel BBS view */
483 #define VIEW_MAILBOX 1 /* Mailbox summary */
484 #define VIEW_ADDRESSBOOK 2 /* Address book view */
485 #define VIEW_CALENDAR 3 /* Calendar view */
486 #define VIEW_TASKS 4 /* Tasks view */