webcit.h: regenerated function prototypes using cproto
[citadel.git] / webcit-ng / server / webcit.h
1 // webcit.h - "header of headers"
2 //
3 // Copyright (c) 1996-2023 by the citadel.org team
4 //
5 // This program is open source software.  You can redistribute it and/or
6 // modify it under the terms of the GNU General Public License, version 3.
7
8 #define SHOW_ME_VAPPEND_PRINTF
9
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <ctype.h>
14 #include <syslog.h>
15 #include <string.h>
16 #include <fcntl.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <netdb.h>
23 #include <sys/un.h>
24 #include <sys/poll.h>
25 #include <time.h>
26 #include <sys/time.h>
27 #include <string.h>
28 #include <pwd.h>
29 #include <errno.h>
30 #include <stdarg.h>
31 #include <pthread.h>
32 #include <signal.h>
33 #include <syslog.h>
34 #include <stdarg.h>
35 #include <limits.h>
36 #include <iconv.h>
37 #include <libcitadel.h>
38 #define OPENSSL_NO_KRB5                         // Work around RedHat's b0rken OpenSSL includes
39 #include <openssl/ssl.h>
40 #include <openssl/err.h>
41 #include <openssl/rand.h>
42 #include <expat.h>
43 #define _(x)    x                               // temporary hack until we add i18n back in
44 //#define DEBUG_HTTP                            // uncomment to debug HTTP headers
45
46 // XML_StopParser is present in expat 2.x
47 #if XML_MAJOR_VERSION > 1
48 #define HAVE_XML_STOPPARSER
49 #endif
50
51 struct client_handle {                          // this gets passed up the stack from the webserver to the application code
52         int sock;
53         SSL *ssl_handle;
54 };
55
56 struct keyval {                                 // key/value pair (for array)
57         char *key;
58         char *val;
59 };
60
61 struct http_transaction {                       // The lifetime of an HTTP request goes through this data structure.
62         char *method;                           // The top half is built up by the web server and sent up to the
63         char *url;                              // application stack.  The second half is built up by the application
64         char *http_version;                     // stack and sent back down to the web server, which transmits it to
65         char *site_prefix;                      // the client.
66         Array *request_headers;
67         char *request_body_with_synth_headers;  // This is the request body with some synthetic headers prepended into it.
68         char *request_body;                     // this is just going to be a pointer into request_body_with_synth_headers
69         long request_body_length;
70         Array *request_parms;                   // anything after the "?" in the URL
71         int response_code;
72         char *response_string;
73         Array *response_headers;
74         char *response_body;
75         long response_body_length;
76 };
77
78 #define AUTH_MAX 256                            // Maximum length of an HTTP AUTH header or equivalent cookie data
79 struct ctdlsession {
80         struct ctdlsession *next;
81         int is_bound;                           // Nonzero if this record is currently bound to a running thread
82         int sock;                               // Socket connection to Citadel server
83         char auth[AUTH_MAX];                    // Auth string (empty if not logged in)
84         char whoami[64];                        // Display name of currently logged in user (empty if not logged in)
85         char room[128];                         // What room we are currently in
86         int room_current_view;
87         int room_default_view;
88         int is_trash_folder;                    // nonzero if this room is the user's Trash folder
89         int is_room_aide;                       // nonzero if the user has aide rights to THIS room
90         int can_delete_messages;                // nonzero if the user is permitted to delete messages in THIS room
91         long last_seen;
92         int new_messages;
93         int total_messages;
94         time_t last_access;                     // Timestamp of last request that used this session
95         time_t num_requests_handled;
96         time_t room_mtime;                      // Timestampt of the most recent write activity in this room
97 };
98
99 struct uploaded_file {                          // things that have been uploaded to the server (such as email attachments)
100         char id[10];
101         char filename[256];
102         char content_type[256];
103         long length;
104         FILE *fp;
105 };
106
107 extern char *ssl_cipher_list;
108 extern int is_https;                            // nonzero if we are an HTTPS server today
109 extern char *ctdl_dir;                          // directory where Citadel Server is running
110 void init_ssl(void);
111 void starttls(struct client_handle *);
112 void endtls(struct client_handle *);
113 int client_write_ssl(struct client_handle *ch, char *buf, int nbytes);
114 int client_read_ssl(struct client_handle *ch, char *buf, int nbytes);
115
116 enum {
117         WEBSERVER_HTTP,
118         WEBSERVER_HTTPS,
119         WEBSERVER_UDS
120 };
121
122 #define TRACE syslog(LOG_DEBUG, "\033[3%dmCHECKPOINT: %s:%d\033[0m", ((__LINE__%6)+1), __FILE__, __LINE__)
123 #define SLEEPING                180             // TCP connection timeout
124 #define MAX_WORKER_THREADS      32              // Maximum number of worker threads permitted to exist
125 #define DEFAULT_SSL_CIPHER_LIST "DEFAULT"       // See http://openssl.org/docs/apps/ciphers.html
126 #define WEBSERVER_PORT          80
127 #define WEBSERVER_INTERFACE     "*"
128 #define CTDL_DIR                "/usr/local/citadel"
129 #define DEVELOPER_ID            0
130 #define CLIENT_ID               4
131 #define TARGET                  "webcit02"      /* Window target for inline URL's */
132 #define ROOMNAMELEN             128             // The size of a roomname string
133 #define DAV_MOVE                0               // MOVE=0 COPY=1 don't change these!
134 #define DAV_COPY                1               // they are the values used in the Citadel Server MOVE command
135
136 // The prototypes below this line are generated with `cproto server/*.c >>server/webcit.h`
137
138 /* server/admin_functions.c */
139 void try_login(struct http_transaction *h, struct ctdlsession *c);
140 void logout(struct http_transaction *h, struct ctdlsession *c);
141 void whoami(struct http_transaction *h, struct ctdlsession *c);
142 void biff(struct http_transaction *h, struct ctdlsession *c);
143 void ctdl_a(struct http_transaction *h, struct ctdlsession *c);
144 /* server/caldav_reports.c */
145 void caldav_xml_start(void *data, const char *el, const char **attr);
146 void caldav_xml_end(void *data, const char *el);
147 void caldav_xml_chardata(void *data, const XML_Char *s, int len);
148 StrBuf *fetch_ical(struct ctdlsession *c, long msgnum);
149 void caldav_response(struct http_transaction *h, struct ctdlsession *c, StrBuf *ReportOut, StrBuf *ThisHref);
150 void caldav_report(struct http_transaction *h, struct ctdlsession *c);
151 /* server/calendar_functions.c */
152 void calendar_msglist(struct http_transaction *h, struct ctdlsession *c, char *range);
153 /* server/ctdlclient.c */
154 int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested);
155 int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes);
156 StrBuf *ctdl_readtextmsg(struct ctdlsession *ctdl);
157 ssize_t ctdl_write(struct ctdlsession *ctdl, const void *buf, size_t count);
158 void ctdl_printf(struct ctdlsession *ctdl, const char *format, ...);
159 int uds_connectsock(char *sockpath);
160 void extract_auth(struct http_transaction *h, char *authbuf, int authbuflen);
161 int login_to_citadel(struct ctdlsession *c, char *auth, char *resultbuf);
162 struct ctdlsession *connect_to_citadel(struct http_transaction *h);
163 void disconnect_from_citadel(struct ctdlsession *ctdl);
164 /* server/ctdl_commands.c */
165 void serv_info(struct http_transaction *h, struct ctdlsession *c);
166 void ctdl_c(struct http_transaction *h, struct ctdlsession *c);
167 /* server/ctdlfunctions.c */
168 void ctdl_delete_msgs(struct ctdlsession *c, long *msgnums, int num_msgs);
169 /* server/floor_functions.c */
170 void floor_list(struct http_transaction *h, struct ctdlsession *c);
171 void ctdl_f(struct http_transaction *h, struct ctdlsession *c);
172 /* server/forum_view.c */
173 void setup_for_forum_view(struct ctdlsession *c);
174 JsonValue *json_tokenize_recipients(const char *Key, long keylen, char *recp);
175 void json_render_one_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
176 /* server/html2html.c */
177 void stripquotes(char *s);
178 void extract_charset_from_meta(char *charset, char *meta_http_equiv, char *meta_content);
179 StrBuf *html2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source);
180 void UrlizeText(StrBuf *Target, StrBuf *Source, StrBuf *WrkBuf);
181 void url(char *buf, size_t bufsize);
182 /* server/http.c */
183 int client_write(struct client_handle *ch, char *buf, int nbytes);
184 int client_read(struct client_handle *ch, char *buf, int nbytes);
185 int client_readline(struct client_handle *ch, char *buf, int maxbytes);
186 void client_printf(struct client_handle *ch, const char *format, ...);
187 void add_response_header(struct http_transaction *h, char *key, char *val);
188 void perform_one_http_transaction(struct client_handle *ch);
189 char *header_val(struct http_transaction *h, char *requested_header);
190 char *get_url_param(struct http_transaction *h, char *requested_param);
191 /* server/main.c */
192 int main(int argc, char **argv);
193 /* server/messages.c */
194 long locate_message_by_uid(struct ctdlsession *c, char *uid);
195 void dav_delete_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
196 void dav_move_or_copy_message(struct http_transaction *h, struct ctdlsession *c, long msgnum, int move_or_copy);
197 void dav_get_message(struct http_transaction *h, struct ctdlsession *c, long msgnum);
198 void dav_put_message(struct http_transaction *h, struct ctdlsession *c, char *euid, long old_msgnum);
199 void download_mime_component(struct http_transaction *h, struct ctdlsession *c, long msgnum, char *partnum);
200 /* server/request.c */
201 void do_404(struct http_transaction *h);
202 void do_405(struct http_transaction *h);
203 void do_412(struct http_transaction *h);
204 void do_204(struct http_transaction *h);
205 void do_502(struct http_transaction *h);
206 void request_http_authenticate(struct http_transaction *h);
207 void http_redirect(struct http_transaction *h, char *to_where);
208 void perform_request(struct http_transaction *h);
209 /* server/room_functions.c */
210 int match_etags(char *taglist, long msgnum);
211 void json_stat(struct http_transaction *h, struct ctdlsession *c);
212 void json_mailbox(struct http_transaction *h, struct ctdlsession *c);
213 void json_msglist(struct http_transaction *h, struct ctdlsession *c, char *which);
214 void read_room_info_banner(struct http_transaction *h, struct ctdlsession *c);
215 void set_last_read_pointer(struct http_transaction *h, struct ctdlsession *c);
216 void object_in_room(struct http_transaction *h, struct ctdlsession *c);
217 void report_the_room_itself(struct http_transaction *h, struct ctdlsession *c);
218 void options_the_room_itself(struct http_transaction *h, struct ctdlsession *c);
219 void propfind_the_room_itself(struct http_transaction *h, struct ctdlsession *c);
220 void get_the_room_itself(struct http_transaction *h, struct ctdlsession *c);
221 void the_room_itself(struct http_transaction *h, struct ctdlsession *c);
222 void room_list(struct http_transaction *h, struct ctdlsession *c);
223 void ctdl_r(struct http_transaction *h, struct ctdlsession *c);
224 /* server/static.c */
225 void output_static(struct http_transaction *h);
226 /* server/tcp_sockets.c */
227 int lingering_close(int fd);
228 int webcit_tcp_server(const char *ip_addr, int port_number, int queue_len);
229 int webcit_uds_server(char *sockpath, int queue_len);
230 /* server/text2html.c */
231 StrBuf *text2html(const char *supplied_charset, int treat_as_wiki, char *roomname, long msgnum, StrBuf *Source);
232 StrBuf *variformat2html(StrBuf *Source);
233 /* server/tls.c */
234 void bind_to_key_and_certificate(void);
235 void init_ssl(void);
236 void update_key_and_cert_if_needed(void);
237 void starttls(struct client_handle *ch);
238 void endtls(struct client_handle *ch);
239 int client_write_ssl(struct client_handle *ch, char *buf, int nbytes);
240 int client_read_ssl(struct client_handle *ch, char *buf, int nbytes);
241 /* server/upload.c */
242 void upload_handler(char *name, char *filename, char *partnum, char *disp, void *content, char *cbtype, char *cbcharset, size_t length, char *encoding, char *cbid, void *userdata);
243 void upload_files(struct http_transaction *h, struct ctdlsession *c);
244 void ctdl_p_base(struct http_transaction *h, struct ctdlsession *c);
245 void delete_upload(struct uploaded_file this_one);
246 void dav_delete_upload(struct http_transaction *h, struct ctdlsession *c, struct uploaded_file this_one);
247 struct uploaded_file pop_upload(char *id);
248 void attachment_filter(char *name, char *filename, char *partnum, char *disp, void *content, char *cbtype, char *cbcharset, size_t length, char *encoding, char *cbid, void *userdata);
249 void load_attachments_from_message(struct http_transaction *h, struct ctdlsession *c, char *name);
250 void specific_upload(struct http_transaction *h, struct ctdlsession *c, char *name);
251 void ctdl_p(struct http_transaction *h, struct ctdlsession *c);
252 /* server/user_functions.c */
253 void fetch_user_photo(struct http_transaction *h, struct ctdlsession *c, char *username);
254 void fetch_user_bio(struct http_transaction *h, struct ctdlsession *c, char *username);
255 void object_in_user(struct http_transaction *h, struct ctdlsession *c, char *requested_username);
256 void the_user_itself(struct http_transaction *h, struct ctdlsession *c, char *username);
257 void user_list(struct http_transaction *h, struct ctdlsession *c);
258 void ctdl_u(struct http_transaction *h, struct ctdlsession *c);
259 /* server/util.c */
260 int unescape_input(char *buf);
261 char *http_datestring(time_t xtime);
262 /* server/webserver.c */
263 void spawn_another_worker_thread(int *pointer_to_master_socket);
264 void worker_entry(int *pointer_to_master_socket);
265 int webserver(char *webserver_interface, int webserver_port, int webserver_protocol);