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