a19416dcc8173bcb8efe4b0e36f68eb1ce31ced1
[citadel.git] / webcit / webcit.h
1 /* $Id$ */
2
3 #ifdef HAVE_ZLIB_H
4 #include <zlib.h>
5 #endif
6
7
8 #ifdef HAVE_ICAL_H
9 #ifdef HAVE_LIBICAL
10 #define WEBCIT_WITH_CALENDAR_SERVICE 1
11 #endif
12 #endif
13
14 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
15 #include <ical.h>
16 #endif
17
18 #define CALENDAR_ROOM_NAME      "Calendar"
19 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
20
21 #define SIZ                     4096            /* generic buffer size */
22
23 #define TRACE fprintf(stderr, "Checkpoint: %s, %d\n", __FILE__, __LINE__)
24
25 #define SLEEPING                180             /* TCP connection timeout */
26 #define WEBCIT_TIMEOUT          900             /* WebCit session timeout */
27 #define PORT_NUM                2000            /* port number to listen on */
28 #define SERVER                  "WebCit v5.06"  /* who's in da house */
29 #define DEVELOPER_ID            0
30 #define CLIENT_ID               4
31 #define CLIENT_VERSION          506             /* This version of WebCit */
32 #define MINIMUM_CIT_VERSION     611             /* min required Citadel vers */
33 #define DEFAULT_HOST            "localhost"     /* Default Citadel server */
34 #define DEFAULT_PORT            "504"
35 #define LB                      (1)             /* Internal escape chars */
36 #define RB                      (2)
37 #define QU                      (3)
38 #define TARGET                  "webcit01"      /* Target for inline URL's */
39 #define HOUSEKEEPING            15              /* Housekeeping frequency */
40 #define MIN_WORKER_THREADS      5
41 #define MAX_WORKER_THREADS      250
42 #define LISTEN_QUEUE_LENGTH     100             /* listen() backlog queue */
43
44 #define USERCONFIGROOM          "My Citadel Config"
45
46
47 /*
48  * Room flags (from Citadel)
49  *
50  * bucket one...
51  */
52 #define QR_PERMANENT    1               /* Room does not purge              */
53 #define QR_INUSE        2               /* Set if in use, clear if avail    */
54 #define QR_PRIVATE      4               /* Set for any type of private room */
55 #define QR_PASSWORDED   8               /* Set if there's a password too    */
56 #define QR_GUESSNAME    16              /* Set if it's a guessname room     */
57 #define QR_DIRECTORY    32              /* Directory room                   */
58 #define QR_UPLOAD       64              /* Allowed to upload                */
59 #define QR_DOWNLOAD     128             /* Allowed to download              */
60 #define QR_VISDIR       256             /* Visible directory                */
61 #define QR_ANONONLY     512             /* Anonymous-Only room              */
62 #define QR_ANONOPT      1024            /* Anonymous-Option room            */
63 #define QR_NETWORK      2048            /* Shared network room              */
64 #define QR_PREFONLY     4096            /* Preferred status needed to enter */
65 #define QR_READONLY     8192            /* Aide status required to post     */
66 #define QR_MAILBOX      16384           /* Set if this is a private mailbox */
67
68 /*
69  * bucket two...
70  */
71 #define QR2_SYSTEM      1               /* System room; hide by default     */
72 #define QR2_SELFLIST    2               /* Self-service mailing list mgmt   */
73
74
75 #define UA_KNOWN                2
76 #define UA_GOTOALLOWED          4
77 #define UA_HASNEWMSGS           8
78 #define UA_ZAPPED               16
79
80
81
82
83
84
85 struct httprequest {
86         struct httprequest *next;
87         char line[SIZ];
88 };
89
90 struct urlcontent {
91         struct urlcontent *next;
92         char url_key[32];
93         char *url_data;
94 };
95
96 struct serv_info {
97         int serv_pid;
98         char serv_nodename[32];
99         char serv_humannode[64];
100         char serv_fqdn[64];
101         char serv_software[64];
102         int serv_rev_level;
103         char serv_bbs_city[64];
104         char serv_sysadm[64];
105         char serv_moreprompt[SIZ];
106         int serv_ok_floors;
107         int serv_supports_ldap;
108 };
109
110
111
112 /*
113  * This struct holds a list of rooms for <G>oto operations.
114  */
115 struct march {
116         struct march *next;
117         char march_name[128];
118         int march_floor;
119         int march_order;
120 };
121
122 /* 
123  * This struct holds a list of rooms for client display.
124  * (oooh, a tree!)
125  */
126 struct roomlisting {
127         struct roomlisting *lnext;
128         struct roomlisting *rnext;
129         char rlname[128];
130         unsigned rlflags;
131         int rlfloor;
132         int rlorder;
133 };
134
135
136
137 /*
138  * Dynamic content for variable substitution in templates
139  */
140 struct wcsubst {
141         struct wcsubst *next;
142         int wcs_type;
143         char wcs_key[32];
144         void *wcs_value;
145         void (*wcs_function)(void);
146 };
147
148 /*
149  * Values for wcs_type
150  */
151 enum {
152         WCS_STRING,
153         WCS_FUNCTION,
154         WCS_SERVCMD
155 };
156
157
158 struct wc_attachment {
159         struct wc_attachment *next;
160         size_t length;
161         char content_type[SIZ];
162         char filename[SIZ];
163         char *data;
164 };
165
166 /*
167  * One of these is kept for each active Citadel session.
168  * HTTP transactions are bound to one at a time.
169  */
170 struct wcsession {
171         struct wcsession *next;         /* Linked list */
172         int wc_session;                 /* WebCit session ID */
173         char wc_username[SIZ];
174         char wc_password[SIZ];
175         char wc_roomname[SIZ];
176         int connected;
177         int logged_in;
178         int axlevel;
179         int is_aide;
180         int is_room_aide;
181         int http_sock;
182         int serv_sock;
183         int chat_sock;
184         unsigned room_flags;
185         int wc_view;
186         int wc_default_view;
187         char ugname[128];
188         long uglsn;
189         int upload_length;
190         char *upload;
191         char upload_filename[SIZ];
192         char upload_content_type[SIZ];
193         int new_mail;
194         int remember_new_mail;
195         int need_regi;                  /* This user needs to register. */
196         int need_vali;                  /* New users require validation. */
197         char cs_inet_email[SIZ];        /* User's preferred Internet addr. */
198         pthread_mutex_t SessionMutex;   /* mutex for exclusive access */
199         time_t lastreq;                 /* Timestamp of most recent HTTP */
200         int killthis;                   /* Nonzero == purge this session */
201         struct march *march;            /* march mode room list */
202         char reply_to[SIZ];             /* reply-to address */
203         long msgarr[4096];              /* for read operations */
204         int fake_frames;
205         int is_wap;                     /* Client is a WAP gateway */
206         struct urlcontent *urlstrings;
207         int HaveExpressMessages;        /* Nonzero if incoming msgs exist */
208         struct wcsubst *vars;
209         char this_page[SIZ];            /* address of current page */
210         char http_host[SIZ];            /* HTTP Host: header */
211         char *preferences;
212 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
213         icalcomponent **disp_cal;       /* store calendar items for display */
214         long *cal_msgnum;               /* store calendar msgids for display */
215         int num_cal;
216 #endif
217         struct wc_attachment *first_attachment;
218         char ImportantMessage[SIZ];
219         int outside_frameset_allowed;   /* nonzero if current req is allowed
220                                          * outside of the main frameset */
221         char last_chat_user[SIZ];
222 };
223
224 #define extract(dest,source,parmnum)    extract_token(dest,source,parmnum,'|')
225 #define num_parms(source)               num_tokens(source, '|')
226
227 #define WC ((struct wcsession *)pthread_getspecific(MyConKey))
228 extern pthread_key_t MyConKey;
229
230 struct serv_info serv_info;
231 extern char floorlist[128][SIZ];
232 extern char *axdefs[];
233 extern char *ctdlhost, *ctdlport;
234 extern char *server_cookie;
235
236 extern struct wcsubst *global_subst;
237
238
239 void stuff_to_cookie(char *cookie, int session,
240                         char *user, char *pass, char *room);
241 void cookie_to_stuff(char *cookie, int *session,
242                         char *user, char *pass, char *room);
243 void locate_host(char *, int);
244 void become_logged_in(char *, char *, char *);
245 void do_login(void);
246 void display_login(char *mesg);
247 void do_welcome(void);
248 void do_logout(void);
249 void display_main_menu(void);
250 void display_advanced_menu(void);
251 void slrp_highest(void);
252 void gotonext(void);
253 void ungoto(void);
254 void get_serv_info(char *, char *);
255 int uds_connectsock(char *);
256 int tcp_connectsock(char *, char *);
257 void serv_gets(char *strbuf);
258 void serv_puts(char *string);
259 void whobbs(void);
260 void fmout(FILE *fp, char *align);
261 void wDumpContent(int);
262 void serv_printf(const char *format,...);
263 char *bstr(char *key);
264 void urlesc(char *, char *);
265 void urlescputs(char *);
266 void jsesc(char *, char *);
267 void jsescputs(char *);
268 void output_headers(int);
269 void wprintf(const char *format,...);
270 void output_static(char *what);
271 void stresc(char *target, char *strbuf, int nbsp);
272 void escputs(char *strbuf);
273 void url(char *buf);
274 void escputs1(char *strbuf, int nbsp);
275 long extract_long(char *source, long int parmnum);
276 int extract_int(char *source, int parmnum);
277 void stripout(char *str, char leftboundary, char rightboundary);
278 void dump_vars(void);
279 void embed_main_menu(void);
280 void serv_read(char *buf, int bytes);
281 int haschar(char *, char);
282 void readloop(char *oper);
283 void text_to_server(char *ptr, int convert_to_html);
284 void display_enter(void);
285 void post_message(void);
286 void confirm_delete_msg(void);
287 void delete_msg(void);
288 void confirm_move_msg(void);
289 void move_msg(void);
290 void userlist(void);
291 void showuser(void);
292 void display_page(void);
293 void page_user(void);
294 void do_chat(void);
295 void display_private(char *rname, int req_pass);
296 void goto_private(void);
297 void zapped_list(void);
298 void display_zap(void);
299 void zap(void);
300 void display_success(char *);
301 void display_entroom(void);
302 void entroom(void);
303 void display_editroom(void);
304 void netedit(void);
305 void editroom(void);
306 void display_whok(void);
307 void server_to_text(void);
308 void save_edit(char *description, char *enter_cmd, int regoto);
309 void display_edit(char *description, char *check_cmd,
310                   char *read_cmd, char *save_cmd, int headers_type);
311 void gotoroom(char *gname, int display_name);
312 void confirm_delete_room(void);
313 void delete_room(void);
314 void validate(void);
315 void display_graphics_upload(char *, char *, char *);
316 void do_graphics_upload(char *upl_cmd);
317 void serv_read(char *buf, int bytes);
318 void serv_gets(char *strbuf);
319 void serv_write(char *buf, int nbytes);
320 void serv_puts(char *string);
321 void serv_printf(const char *format,...);
322 void load_floorlist(void);
323 void display_reg(int);
324 void display_changepw(void);
325 void changepw(void);
326 void display_edit_node(void);
327 void edit_node(void);
328 void display_netconf(void);
329 void display_confirm_delete_node(void);
330 void delete_node(void);
331 void display_add_node(void);
332 void add_node(void);
333 void terminate_session(void);
334 void edit_me(void);
335 void display_siteconfig(void);
336 void siteconfig(void);
337 void display_generic(void);
338 void do_generic(void);
339 void display_menubar(int);
340 void embed_room_banner(char *);
341 void smart_goto(char *);
342 void worker_entry(void);
343 void session_loop(struct httprequest *);
344 void fmt_date(char *buf, time_t thetime);
345 void fmt_time(char *buf, time_t thetime);
346 void httpdate(char *buf, time_t thetime);
347 void end_webcit_session(void);
348 void page_popup(void);
349 void chat_recv(void);
350 void chat_send(void);
351 void http_redirect(char *);
352 void clear_local_substs(void);
353 void svprintf(char *keyname, int keytype, const char *format,...);
354 void svcallback(char *keyname, void (*fcn_ptr)() );
355 void do_template(void *templatename);
356 int lingering_close(int fd);
357 char *memreadline(char *start, char *buf, int maxlen);
358 int num_tokens (char *source, char tok);
359 void extract_token(char *dest, char *source, int parmnum, char separator);
360 void remove_token(char *source, int parmnum, char separator);
361 char *load_mimepart(long msgnum, char *partnum);
362 int pattern2(char *search, char *patn);
363 void do_edit_vcard(long, char *, char *);
364 void edit_vcard(void);
365 void submit_vcard(void);
366 void striplt(char *);
367 void select_user_to_edit(char *message, char *preselect);
368 void display_edituser(char *who, int is_new);
369 void create_user(void);
370 void edituser(void);
371 void do_change_view(int);
372 void change_view(void);
373 void folders(void);
374 void do_stuff_to_msgs(void);
375 void load_preferences(void);
376 void save_preferences(void);
377 void get_preference(char *key, char *value);
378 void set_preference(char *key, char *value);
379 void knrooms(void);
380 int is_msg_in_mset(char *mset, long msgnum);
381 char *safestrncpy(char *dest, const char *src, size_t n);
382 void display_addressbook(long msgnum, char alpha);
383 void offer_start_page(void);
384 void change_start_page(void);
385 void output_html(void);
386 void display_floorconfig(char *);
387 void delete_floor(void);
388 void create_floor(void);
389 void rename_floor(void);
390 void do_listsub(void);
391 void toggle_self_service(void);
392 void summary(void);
393 ssize_t write(int fd, const void *buf, size_t count);
394 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum);
395 void display_calendar(long msgnum);
396 void display_task(long msgnum);
397 void do_calendar_view(void);
398 void free_calendar_buffer(void);
399 void calendar_summary_view(void);
400 int load_msg_ptrs(char *servcmd);
401 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
402 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
403 void free_attachments(struct wcsession *sess);
404
405
406 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
407 void display_edit_task(void);
408 void save_task(void);
409 void display_edit_event(void);
410 void save_event(void);
411 void display_icaltimetype_as_webform(struct icaltimetype *, char *);
412 struct icaltimetype icaltime_from_webform(char *prefix);
413 void display_edit_individual_event(icalcomponent *supplied_vtodo, long msgnum);
414 void save_individual_event(icalcomponent *supplied_vtodo, long msgnum);
415 void generate_new_uid(char *);
416 void respond_to_request(void);
417 void handle_rsvp(void);
418 void ical_dezonify(icalcomponent *cal);
419 void partstat_as_string(char *buf, icalproperty *attendee);
420 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp);
421 void check_attendee_availability(icalcomponent *supplied_vevent);
422 void do_freebusy(char *req);
423 #endif
424
425 extern char *months[];
426 extern char *days[];
427 void read_server_binary(char *buffer, size_t total_len);
428 char *read_server_text(void);
429 int goto_config_room(void);
430 long locate_user_vcard(char *username, long usernum);
431 void sleeeeeeeeeep(int);
432 void http_transmit_thing(char *thing, size_t length, char *content_type,
433                          int is_static);
434 void unescape_input(char *buf);
435 void do_iconbar(void);
436 void display_customize_iconbar(void);
437 void commit_iconbar(void);
438 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
439 void spawn_another_worker_thread(void);