ical_ctdl_is_overlap() is now symlinked 3 places.
[citadel.git] / webcit-ng / server / webcit.h
index 7cc853a4de93a013f8a8aba908c59ac2cad5dcc2..916c4e1f0b50a3445b4f66dcb2e6c96835f6ce6b 100644 (file)
@@ -1,9 +1,15 @@
 // webcit.h - "header of headers"
 //
-// Copyright (c) 1996-2023 by the citadel.org team
+// Copyright (c) 1996-2024 by the citadel.org team
 //
-// This program is open source software.  You can redistribute it and/or
-// modify it under the terms of the GNU General Public License, version 3.
+// This program is open source software.  Use, duplication, or
+// disclosure is subject to the GNU General Public License v3.
+
+// uncomment one or more of these to see raw http transactions
+//#define DEBUG_HTTP
+//#define REQUEST_BODY_TO_STDERR
+//#define RESPONSE_BODY_TO_STDERR
+#define DEBUG_XML_PARSE
 
 #define SHOW_ME_VAPPEND_PRINTF
 
@@ -34,6 +40,7 @@
 #include <stdarg.h>
 #include <limits.h>
 #include <iconv.h>
+#include <libical/ical.h>
 #include <libcitadel.h>
 #define OPENSSL_NO_KRB5                                // Work around RedHat's b0rken OpenSSL includes
 #include <openssl/ssl.h>
 #include <openssl/rand.h>
 #include <expat.h>
 #define _(x)   x                               // temporary hack until we add i18n back in
-//#define DEBUG_HTTP                           // uncomment to debug HTTP headers
 
 // XML_StopParser is present in expat 2.x
-#if XML_MAJOR_VERSION > 1
-#define HAVE_XML_STOPPARSER
+#if XML_MAJOR_VERSION < 2
+#error WebCit requires expat v2.0 or newer.
 #endif
 
 struct client_handle {                         // this gets passed up the stack from the webserver to the application code
@@ -64,7 +70,8 @@ struct http_transaction {                     // The lifetime of an HTTP request goes through this
        char *http_version;                     // stack and sent back down to the web server, which transmits it to
        char *site_prefix;                      // the client.
        Array *request_headers;
-       char *request_body;
+       char *request_body_with_synth_headers;  // This is the request body with some synthetic headers prepended into it.
+       char *request_body;                     // this is just going to be a pointer into request_body_with_synth_headers
        long request_body_length;
        Array *request_parms;                   // anything after the "?" in the URL
        int response_code;
@@ -95,6 +102,14 @@ struct ctdlsession {
        time_t room_mtime;                      // Timestampt of the most recent write activity in this room
 };
 
+struct uploaded_file {                         // things that have been uploaded to the server (such as email attachments)
+       char id[10];
+       char filename[256];
+       char content_type[256];
+       long length;
+       FILE *fp;
+};
+
 extern char *ssl_cipher_list;
 extern int is_https;                           // nonzero if we are an HTTPS server today
 extern char *ctdl_dir;                         // directory where Citadel Server is running
@@ -119,54 +134,175 @@ enum {
 #define CTDL_DIR               "/usr/local/citadel"
 #define DEVELOPER_ID           0
 #define CLIENT_ID              4
-#define TARGET                 "webcit02"      /* Window target for inline URL's */
+#define TARGET                 "webcit02"      // Window target for inline URL's
 #define ROOMNAMELEN            128             // The size of a roomname string
 #define        DAV_MOVE                0               // MOVE=0 COPY=1 don't change these!
 #define DAV_COPY               1               // they are the values used in the Citadel Server MOVE command
 
-void worker_entry(int *);
-void perform_one_http_transaction(struct client_handle *ch);
-void add_response_header(struct http_transaction *h, char *key, char *val);
-void perform_request(struct http_transaction *);
-void do_204(struct http_transaction *);
+
+// FIXME retrieve this from the server
+#define default_zone_name      ""
+
+// Everything below here is generated with this command:
+// cproto -f2 *.c 2>/dev/null |sed 's/^\/\*/\n\/\//g' | sed 's/\ \*\/$//g'
+
+// admin_functions.c
+void try_login(struct http_transaction *, struct ctdlsession *);
+void logout(struct http_transaction *, struct ctdlsession *);
+void whoami(struct http_transaction *, struct ctdlsession *);
+void biff(struct http_transaction *, struct ctdlsession *);
+void ctdl_a(struct http_transaction *, struct ctdlsession *);
+
+// caldav_reports.c
+void caldav_xml_start(void *, const char *, const char **);
+void caldav_xml_end(void *, const char *);
+void caldav_xml_chardata(void *, const XML_Char *, int);
+StrBuf *fetch_ical(struct ctdlsession *, long);
+void cal_multiget_out(long, StrBuf *, StrBuf *, StrBuf *);
+void caldav_report_one_item(struct http_transaction *, struct ctdlsession *, StrBuf *, StrBuf *);
+int caldav_time_range_filter_matches(icalcomponent *, char *, char *);
+int caldav_apply_filters(void *, Array *, int);
+void caldav_report(struct http_transaction *, struct ctdlsession *);
+
+// ctdlclient.c
+int ctdl_read_binary(struct ctdlsession *, char *, int);
+int ctdl_readline(struct ctdlsession *, char *, int);
+StrBuf *ctdl_readtextmsg(struct ctdlsession *);
+ssize_t ctdl_write(struct ctdlsession *, const void *, size_t);
+void ctdl_printf(struct ctdlsession *, const char *, ...);
+int uds_connectsock(char *);
+void extract_auth(struct http_transaction *, char *, int);
+int login_to_citadel(struct ctdlsession *, char *, char *);
+struct ctdlsession *connect_to_citadel(struct http_transaction *);
+void disconnect_from_citadel(struct ctdlsession *);
+
+// ctdl_commands.c
+void serv_info(struct http_transaction *, struct ctdlsession *);
+void ctdl_c(struct http_transaction *, struct ctdlsession *);
+
+// ctdlfunctions.c
+void ctdl_delete_msgs(struct ctdlsession *, long *, int);
+
+// floor_functions.c
+void floor_list(struct http_transaction *, struct ctdlsession *);
+void ctdl_f(struct http_transaction *, struct ctdlsession *);
+
+// forum_view.c
+void setup_for_forum_view(struct ctdlsession *);
+JsonValue *json_tokenize_recipients(const char *, long, char *);
+void json_render_one_message(struct http_transaction *, struct ctdlsession *, long);
+
+// html2html.c
+void stripquotes(char *);
+void extract_charset_from_meta(char *, char *, char *);
+StrBuf *html2html(const char *, int, char *, long, StrBuf *);
+void UrlizeText(StrBuf *, StrBuf *, StrBuf *);
+void url(char *, size_t);
+
+// http.c
+int client_write(struct client_handle *, char *, int);
+int client_read(struct client_handle *, char *, int);
+int client_readline(struct client_handle *, char *, int);
+void client_printf(struct client_handle *, const char *, ...);
+void add_response_header(struct http_transaction *, char *, char *);
+void perform_one_http_transaction(struct client_handle *);
+char *header_val(struct http_transaction *, char *);
+char *get_url_param(struct http_transaction *, char *);
+
+// ical_ctdl_is_overlap.c
+int ical_ctdl_is_overlap(struct icaltimetype, struct icaltimetype, struct icaltimetype, struct icaltimetype);
+
+// ical_dezonify.c
+icaltimezone *get_default_icaltimezone(void);
+void ical_dezonify_backend(icalcomponent *, icalcomponent *, icalproperty *);
+void ical_dezonify_recurse(icalcomponent *, icalcomponent *);
+void ical_dezonify(icalcomponent *);
+
+// main.c
+int main(int, char **);
+
+// messages.c
+long locate_message_by_uid(struct ctdlsession *, char *);
+void dav_delete_message(struct http_transaction *, struct ctdlsession *, long);
+void dav_move_or_copy_message(struct http_transaction *, struct ctdlsession *, long, int);
+void dav_get_message(struct http_transaction *, struct ctdlsession *, long);
+void dav_put_message(struct http_transaction *, struct ctdlsession *, char *, long);
+void download_mime_component(struct http_transaction *, struct ctdlsession *, long, char *);
+
+// request.c
 void do_404(struct http_transaction *);
+void do_405(struct http_transaction *);
 void do_412(struct http_transaction *);
+void do_204(struct http_transaction *);
 void do_502(struct http_transaction *);
-void output_static(struct http_transaction *);
-int uds_connectsock(char *);
-void ctdl_a(struct http_transaction *, struct ctdlsession *);
-void ctdl_f(struct http_transaction *, struct ctdlsession *);
+void request_http_authenticate(struct http_transaction *);
+void http_redirect(struct http_transaction *, char *);
+void perform_request(struct http_transaction *);
+
+// room_functions.c
+Array *get_msglist(struct ctdlsession *, char *);
+int match_etags(char *, long);
+void json_stat(struct http_transaction *, struct ctdlsession *);
+void json_mailbox(struct http_transaction *, struct ctdlsession *);
+void json_msglist(struct http_transaction *, struct ctdlsession *, char *);
+void read_room_info_banner(struct http_transaction *, struct ctdlsession *);
+void set_last_read_pointer(struct http_transaction *, struct ctdlsession *);
+void object_in_room(struct http_transaction *, struct ctdlsession *);
+void report_the_room_itself(struct http_transaction *, struct ctdlsession *);
+void options_the_room_itself(struct http_transaction *, struct ctdlsession *);
+void propfind_the_room_itself(struct http_transaction *, struct ctdlsession *);
+void get_the_room_itself(struct http_transaction *, struct ctdlsession *);
+void the_room_itself(struct http_transaction *, struct ctdlsession *);
+void room_list(struct http_transaction *, struct ctdlsession *);
 void ctdl_r(struct http_transaction *, struct ctdlsession *);
-void ctdl_u(struct http_transaction *, struct ctdlsession *);
+
+// static.c
+void output_static(struct http_transaction *);
+
+// tcp_sockets.c
+int lingering_close(int);
+int webcit_tcp_server(const char *, int, int);
+int webcit_uds_server(char *, int);
+
+// text2html.c
+StrBuf *text2html(const char *, int, char *, long, StrBuf *);
+StrBuf *variformat2html(StrBuf *);
+
+// tls.c
+void bind_to_key_and_certificate(void);
+void init_ssl(void);
+void update_key_and_cert_if_needed(void);
+void starttls(struct client_handle *);
+void endtls(struct client_handle *);
+int client_write_ssl(struct client_handle *, char *, int);
+int client_read_ssl(struct client_handle *, char *, int);
+
+// upload.c
+void upload_handler(char *, char *, char *, char *, void *, char *, char *, size_t, char *, char *, void *);
+void upload_files(struct http_transaction *, struct ctdlsession *);
+void ctdl_p_base(struct http_transaction *, struct ctdlsession *);
+void delete_upload(struct uploaded_file);
+void dav_delete_upload(struct http_transaction *, struct ctdlsession *, struct uploaded_file);
+struct uploaded_file pop_upload(char *);
+void attachment_filter(char *, char *, char *, char *, void *, char *, char *, size_t, char *, char *, void *);
+void load_attachments_from_message(struct http_transaction *, struct ctdlsession *, char *);
+void specific_upload(struct http_transaction *, struct ctdlsession *, char *);
 void ctdl_p(struct http_transaction *, struct ctdlsession *);
-struct ctdlsession *connect_to_citadel(struct http_transaction *);
-void disconnect_from_citadel(struct ctdlsession *);
-char *header_val(struct http_transaction *h, char *requested_header);
-char *get_url_param(struct http_transaction *h, char *requested_param);
+
+// user_functions.c
+void fetch_user_photo(struct http_transaction *, struct ctdlsession *, char *);
+void fetch_user_bio(struct http_transaction *, struct ctdlsession *, char *);
+void object_in_user(struct http_transaction *, struct ctdlsession *, char *);
+void the_user_itself(struct http_transaction *, struct ctdlsession *, char *);
+void user_list(struct http_transaction *, struct ctdlsession *);
+void ctdl_u(struct http_transaction *, struct ctdlsession *);
+
+// util.c
 int unescape_input(char *);
-void http_redirect(struct http_transaction *h, char *to_where);
-char *http_datestring(time_t xtime);
-long *get_msglist(struct ctdlsession *c, char *which_msgs);
-void caldav_report(struct http_transaction *h, struct ctdlsession *c);
-long locate_message_by_uid(struct ctdlsession *c, char *uid);
-void ctdl_delete_msgs(struct ctdlsession *c, long *msgnums, int num_msgs);
-void dav_delete_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
-void dav_get_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
-void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *euid, long old_msgnum);
-void dav_move_or_copy_message(struct http_transaction *h, struct ctdlsession *c, long msgnum, int move_or_copy);
-ssize_t ctdl_write(struct ctdlsession *ctdl, const void *buf, size_t count);
-int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf);
-StrBuf *ctdl_readtextmsg(struct ctdlsession *ctdl);
-StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source);
-void download_mime_component(struct http_transaction *h, struct ctdlsession *c, long msgnum, char *partnum);
-StrBuf *text2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source);
-StrBuf *variformat2html(StrBuf *Source);
-int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes);
-int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested);
-void ctdl_c(struct http_transaction *h, struct ctdlsession *c);
-int webserver(char *webserver_interface, int webserver_port, int webserver_protocol);
-void ctdl_printf(struct ctdlsession *ctdl, const char *format,...);
-int webcit_tcp_server(const char *ip_addr, int port_number, int queue_len);
-void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf);
-void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
-void upload_files(struct http_transaction *h, struct ctdlsession *c);
+char *http_datestring(time_t);
+
+// webserver.c
+void spawn_another_worker_thread(int *);
+void worker_entry(int *);
+int webserver(char *, int, int);
+