5 * \defgroup MainServer This is the main transaction loop of the web service. It maintains a
6 * persistent session to the Citadel server, handling HTTP WebCit requests as
7 * they arrive and presenting a user interface.
8 * \ingroup WebcitHttpServer
13 #include "webserver.h"
14 #include "mime_parser.h"
17 * String to unset the cookie.
18 * Any date "in the past" will work, so I chose my birthday, right down to
19 * the exact minute. :)
21 static char *unset = "; expires=28-May-1971 18:10:00 GMT";
24 * \brief remove escaped strings from i.e. the url string (like %20 for blanks)
25 * \param buf the buffer to examine
27 void unescape_input(char *buf)
35 while ((isspace(buf[buflen - 1])) && (buflen > 0)){
40 for (a = 0; a < buflen; ++a) {
48 sscanf(hex, "%02x", &b);
50 memmove(&buf[a + 1], &buf[a + 3], buflen - a - 2);
59 * \brief Extract variables from the URL.
60 * \param url URL supplied by the HTTP parser
62 void addurls(char *url)
70 while (!IsEmptyStr(up)) {
72 /** locate the = sign */
73 safestrncpy(buf, up, sizeof buf);
75 for (a = 255; a >= 0; --a)
82 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
83 u->next = WC->urlstrings;
85 safestrncpy(u->url_key, buf, sizeof u->url_key);
87 /** now chop that part off */
88 for (a = 0; a <= b; ++a)
91 /** locate "&" and "?" delimiters */
94 for (a = 0; a < len; ++a) {
95 if ( (ptr[0] == '&') || (ptr[0] == '?') ) {
105 u->url_data = malloc(len + 2);
106 safestrncpy(u->url_data, up, b + 1);
108 unescape_input(u->url_data);
112 /* lprintf(9, "%s = %s\n", u->url_key, u->url_data); */
117 * \brief free urlstring memory
121 struct urlcontent *u;
123 while (WC->urlstrings != NULL) {
124 free(WC->urlstrings->url_data);
125 u = WC->urlstrings->next;
126 free(WC->urlstrings);
132 * \brief Diagnostic function to display the contents of all variables
136 struct urlcontent *u;
138 for (u = WC->urlstrings; u != NULL; u = u->next) {
139 wprintf("%38s = %s\n", u->url_key, u->url_data);
144 * \brief Return the value of a variable supplied to the current web page (from the url or a form)
145 * \param key The name of the variable we want
147 char *bstr(char *key)
149 struct urlcontent *u;
151 for (u = WC->urlstrings; u != NULL; u = u->next) {
152 if (!strcasecmp(u->url_key, key))
153 return (u->url_data);
159 * \brief web-printing funcion. uses our vsnprintf wrapper
160 * \param format printf format string
161 * \param ... the varargs to put into formatstring
163 void wprintf(const char *format,...)
168 va_start(arg_ptr, format);
169 vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
172 client_write(wbuf, strlen(wbuf));
177 * \brief wrap up an HTTP session, closes tags, etc.
178 * \todo multiline params?
179 * \param print_standard_html_footer should be set to 0 to transmit only, 1 to
180 * append the main menu and closing tags, or 2 to
181 * append the closing tags only.
183 void wDumpContent(int print_standard_html_footer)
185 if (print_standard_html_footer) {
186 wprintf("</div>\n"); /* end of "text" div */
187 do_template("trailing");
190 /* If we've been saving it all up for one big output burst,
191 * go ahead and do that now.
198 * \brief Copy a string, escaping characters which have meaning in HTML.
199 * \param target target buffer
200 * \param strbuf source buffer
201 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
202 * \param nolinebreaks if set, linebreaks are removed from the string.
204 void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
209 len = strlen(strbuf);
210 for (a = 0; a < len; ++a) {
211 if (strbuf[a] == '<')
212 strcat(target, "<");
213 else if (strbuf[a] == '>')
214 strcat(target, ">");
215 else if (strbuf[a] == '&')
216 strcat(target, "&");
217 else if (strbuf[a] == '\"')
218 strcat(target, """);
219 else if (strbuf[a] == '\'')
220 strcat(target, "'");
221 else if (strbuf[a] == LB)
223 else if (strbuf[a] == RB)
225 else if (strbuf[a] == QU)
226 strcat(target, "\"");
227 else if ((strbuf[a] == 32) && (nbsp == 1))
228 strcat(target, " ");
229 else if ((strbuf[a] == '\n') && (nolinebreaks))
230 strcat(target, ""); /* nothing */
231 else if ((strbuf[a] == '\r') && (nolinebreaks))
232 strcat(target, ""); /* nothing */
234 strncat(target, &strbuf[a], 1);
240 * \param strbuf what???
241 * \param nbsp If nonzero, spaces are converted to non-breaking spaces.
242 * \param nolinebreaks if set, linebreaks are removed from the string.
244 void escputs1(char *strbuf, int nbsp, int nolinebreaks)
248 if (strbuf == NULL) return;
249 buf = malloc( (3 * strlen(strbuf)) + SIZ );
250 stresc(buf, strbuf, nbsp, nolinebreaks);
256 * \brief static wrapper for ecsputs1
257 * \param strbuf buffer to print escaped to client
259 void escputs(char *strbuf)
261 escputs1(strbuf, 0, 0);
265 * \brief Escape a string for feeding out as a URL.
266 * \param outbuf the output buffer
267 * \param strbuf the input buffer
269 void urlesc(char *outbuf, char *strbuf)
271 int a, b, c, len, eclen, olen;
272 char *ec = " #&;`'|*?-~<>^()[]{}/$\"\\";
275 len = strlen(strbuf);
278 for (a = 0; a < len; ++a) {
280 for (b = 0; b < eclen; ++b) {
281 if (strbuf[a] == ec[b])
285 sprintf(&outbuf[olen], "%%%02x", strbuf[a]);
289 outbuf[olen ++] = strbuf[a];
295 * \brief urlescape buffer and print it to the client
296 * \param strbuf buffer to urlescape
298 void urlescputs(char *strbuf)
302 urlesc(outbuf, strbuf);
303 wprintf("%s", outbuf);
308 * \brief Copy a string, escaping characters for JavaScript strings.
309 * \param target output string
310 * \param strbuf input string
312 void jsesc(char *target, char *strbuf)
317 len = strlen (strbuf);
318 for (a = 0; a < len; ++a) {
319 if (strbuf[a] == '<')
321 else if (strbuf[a] == '>')
323 else if (strbuf[a] == '\"')
324 strcat(target, """);
325 else if (strbuf[a] == '&')
326 strcat(target, "&;");
327 else if (strbuf[a] == '\'')
328 strcat(target, "\\'");
330 strncat(target, &strbuf[a], 1);
336 * \brief escape and print java script
337 * \param strbuf the js code
339 void jsescputs(char *strbuf)
343 jsesc(outbuf, strbuf);
344 wprintf("%s", outbuf);
348 * \brief Copy a string, escaping characters for message text hold
349 * \param target target buffer
350 * \param strbuf source buffer
352 void msgesc(char *target, char *strbuf)
357 len = strlen(strbuf);
358 for (a = 0; a < len; ++a) {
359 if (strbuf[a] == '\n')
361 else if (strbuf[a] == '\r')
363 else if (strbuf[a] == '\'')
364 strcat(target, "'");
366 strncat(target, &strbuf[a], 1);
372 * \brief print a string to the client after cleaning it with msgesc()
373 * \param strbuf string to be printed
375 void msgescputs(char *strbuf) {
378 if (strbuf == NULL) return;
379 outbuf = malloc( (3 * strlen(strbuf)) + SIZ);
380 msgesc(outbuf, strbuf);
381 wprintf("%s", outbuf);
389 * \brief Output all that important stuff that the browser will want to see
391 void output_headers( int do_httpheaders, /**< 1 = output HTTP headers */
392 int do_htmlhead, /**< 1 = output HTML <head> section and <body> opener */
394 int do_room_banner, /**< 0=no, 1=yes,
395 * 2 = I'm going to embed my own, so don't open the
396 * <div id="content"> either.
399 int unset_cookies, /**< 1 = session is terminating, so unset the cookies */
400 int suppress_check, /**< 1 = suppress check for instant messages */
401 int cache /**< 1 = allow browser to cache this page */
406 wprintf("HTTP/1.1 200 OK\n");
407 http_datestring(httpnow, sizeof httpnow, time(NULL));
409 if (do_httpheaders) {
410 wprintf("Content-type: text/html; charset=utf-8\r\n"
412 "Connection: close\r\n",
413 SERVER, serv_info.serv_software
418 wprintf("Pragma: public\r\n"
419 "Cache-Control: max-age=3600, must-revalidate\r\n"
420 "Last-modified: %s\r\n",
425 wprintf("Pragma: no-cache\r\n"
426 "Cache-Control: no-store\r\n"
430 stuff_to_cookie(cookie, WC->wc_session, WC->wc_username,
431 WC->wc_password, WC->wc_roomname);
434 wprintf("Set-cookie: webcit=%s; path=/\r\n", unset);
436 wprintf("Set-cookie: webcit=%s; path=/\r\n", cookie);
437 if (server_cookie != NULL) {
438 wprintf("%s\n", server_cookie);
444 if (!access("static.local/webcit.css", R_OK)) {
445 svprintf("CSSLOCAL", WCS_STRING,
446 "<link href=\"static.local/webcit.css\" rel=\"stylesheet\" type=\"text/css\">"
456 /** check for ImportantMessages (these display in a div overlaying the main screen) */
457 if (!IsEmptyStr(WC->ImportantMessage)) {
458 wprintf("<div id=\"important_message\">\n");
459 wprintf("<span class=\"imsg\">"
460 "%s</span><br />\n", WC->ImportantMessage);
462 wprintf("<script type=\"text/javascript\">\n"
463 " setTimeout('hide_imsg_popup()', 3000); \n"
465 safestrncpy(WC->ImportantMessage, "", sizeof WC->ImportantMessage);
468 if ( (WC->logged_in) && (!unset_cookies) ) {
469 wprintf("<div id=\"iconbar\">");
470 do_selected_iconbar();
471 /** check for instant messages (these display in a new window) */
476 if (do_room_banner == 1) {
477 wprintf("<div id=\"banner\">\n");
478 embed_room_banner(NULL, navbar_default);
483 if (do_room_banner == 1) {
484 wprintf("<div id=\"content\">\n");
490 * \brief Generic function to do an HTTP redirect. Easy and fun.
491 * \param whichpage target url to 302 to
493 void http_redirect(char *whichpage) {
494 wprintf("HTTP/1.1 302 Moved Temporarily\n");
495 wprintf("Location: %s\r\n", whichpage);
496 wprintf("URI: %s\r\n", whichpage);
497 wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
498 wprintf("<html><body>");
499 wprintf("Go <a href=\"%s\">here</A>.", whichpage);
500 wprintf("</body></html>\n");
506 * \brief Output a piece of content to the web browser
508 void http_transmit_thing(char *thing, size_t length, char *content_type,
511 output_headers(0, 0, 0, 0, 0, is_static);
513 wprintf("Content-type: %s\r\n"
515 "Connection: close\r\n",
520 /** If we can send the data out compressed, please do so. */
522 char *compressed_data = NULL;
523 uLongf compressed_len;
525 compressed_len = (uLongf) ((length * 101) / 100) + 100;
526 compressed_data = malloc(compressed_len);
528 if (compress_gzip((Bytef *) compressed_data,
531 (uLongf) length, Z_BEST_SPEED) == Z_OK) {
532 wprintf("Content-encoding: gzip\r\n"
533 "Content-length: %ld\r\n"
535 (long) compressed_len
537 client_write(compressed_data, (size_t)compressed_len);
538 free(compressed_data);
544 /** No compression ... just send it out as-is */
545 wprintf("Content-length: %ld\r\n"
549 client_write(thing, (size_t)length);
555 * \brief dump out static pages from disk
556 * \param what the file urs to print
558 void output_static(char *what)
564 char content_type[128];
567 fp = fopen(what, "rb");
569 lprintf(9, "output_static('%s') -- NOT FOUND --\n", what);
570 wprintf("HTTP/1.1 404 %s\n", strerror(errno));
571 wprintf("Content-Type: text/plain\r\n");
573 wprintf("Cannot open %s: %s\n", what, strerror(errno));
576 if (!strncasecmp(&what[len - 4], ".gif", 4))
577 safestrncpy(content_type, "image/gif", sizeof content_type);
578 else if (!strncasecmp(&what[len - 4], ".txt", 4))
579 safestrncpy(content_type, "text/plain", sizeof content_type);
580 else if (!strncasecmp(&what[len - 4], ".css", 4))
581 safestrncpy(content_type, "text/css", sizeof content_type);
582 else if (!strncasecmp(&what[len - 4], ".jpg", 4))
583 safestrncpy(content_type, "image/jpeg", sizeof content_type);
584 else if (!strncasecmp(&what[len - 4], ".png", 4))
585 safestrncpy(content_type, "image/png", sizeof content_type);
586 else if (!strncasecmp(&what[len - 4], ".ico", 4))
587 safestrncpy(content_type, "image/x-icon", sizeof content_type);
588 else if (!strncasecmp(&what[len - 5], ".html", 5))
589 safestrncpy(content_type, "text/html", sizeof content_type);
590 else if (!strncasecmp(&what[len - 4], ".htm", 4))
591 safestrncpy(content_type, "text/html", sizeof content_type);
592 else if (!strncasecmp(&what[len - 4], ".wml", 4))
593 safestrncpy(content_type, "text/vnd.wap.wml", sizeof content_type);
594 else if (!strncasecmp(&what[len - 5], ".wmls", 5))
595 safestrncpy(content_type, "text/vnd.wap.wmlscript", sizeof content_type);
596 else if (!strncasecmp(&what[len - 5], ".wmlc", 5))
597 safestrncpy(content_type, "application/vnd.wap.wmlc", sizeof content_type);
598 else if (!strncasecmp(&what[len - 6], ".wmlsc", 6))
599 safestrncpy(content_type, "application/vnd.wap.wmlscriptc", sizeof content_type);
600 else if (!strncasecmp(&what[len - 5], ".wbmp", 5))
601 safestrncpy(content_type, "image/vnd.wap.wbmp", sizeof content_type);
602 else if (!strncasecmp(&what[len - 3], ".js", 3))
603 safestrncpy(content_type, "text/javascript", sizeof content_type);
605 safestrncpy(content_type, "application/octet-stream", sizeof content_type);
607 fstat(fileno(fp), &statbuf);
608 bytes = statbuf.st_size;
609 bigbuffer = malloc(bytes + 2);
610 fread(bigbuffer, bytes, 1, fp);
613 lprintf(9, "output_static('%s') %s\n", what, content_type);
614 http_transmit_thing(bigbuffer, (size_t)bytes, content_type, 1);
617 if (!strcasecmp(bstr("force_close_session"), "yes")) {
618 end_webcit_session();
624 * \brief When the browser requests an image file from the Citadel server,
625 * this function is called to transmit it.
630 char *xferbuf = NULL;
633 serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
634 serv_getln(buf, sizeof buf);
636 bytes = extract_long(&buf[4], 0);
637 xferbuf = malloc(bytes + 2);
639 /** Read it from the server */
640 read_server_binary(xferbuf, bytes);
642 serv_getln(buf, sizeof buf);
644 /** Write it to the browser */
645 http_transmit_thing(xferbuf, (size_t)bytes, "image/gif", 0);
650 * Instead of an ugly 404, send a 1x1 transparent GIF
651 * when there's no such image on the server.
653 output_static("static/blank.gif");
661 * \brief Generic function to output an arbitrary MIME part from an arbitrary
662 * message number on the server.
664 * \param msgnum Number of the item on the citadel server
665 * \param partnum The MIME part to be output
666 * \param force_download Nonzero to force set the Content-Type: header
667 * to "application/octet-stream"
669 void mimepart(char *msgnum, char *partnum, int force_download)
673 char content_type[256];
674 char *content = NULL;
676 serv_printf("OPNA %s|%s", msgnum, partnum);
677 serv_getln(buf, sizeof buf);
679 bytes = extract_long(&buf[4], 0);
680 content = malloc(bytes + 2);
681 if (force_download) {
682 strcpy(content_type, "application/octet-stream");
685 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
687 output_headers(0, 0, 0, 0, 0, 0);
688 read_server_binary(content, bytes);
690 serv_getln(buf, sizeof buf);
691 http_transmit_thing(content, bytes, content_type, 0);
694 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
695 output_headers(0, 0, 0, 0, 0, 0);
696 wprintf("Content-Type: text/plain\r\n");
698 wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
705 * \brief Read any MIME part of a message, from the server, into memory.
706 * \param msgnum number of the message on the citadel server
707 * \param partnum the MIME part to be loaded
709 char *load_mimepart(long msgnum, char *partnum)
713 char content_type[SIZ];
716 serv_printf("DLAT %ld|%s", msgnum, partnum);
717 serv_getln(buf, sizeof buf);
719 bytes = extract_long(&buf[4], 0);
720 extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
722 content = malloc(bytes + 2);
723 serv_read(content, bytes);
725 content[bytes] = 0; /* null terminate for good measure */
736 * \brief Convenience functions to display a page containing only a string
737 * \param titlebarcolor color of the titlebar of the frame
738 * \param titlebarmsg text to display in the title bar
739 * \param messagetext body of the box
741 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
743 wprintf("HTTP/1.1 200 OK\n");
744 output_headers(1, 1, 2, 0, 0, 0);
745 wprintf("<div id=\"banner\">\n");
746 wprintf("<table width=100%% border=0 bgcolor=\"#%s\"><tr><td>", titlebarcolor);
747 wprintf("<span class=\"titlebar\">%s</span>\n", titlebarmsg);
748 wprintf("</td></tr></table>\n");
749 wprintf("</div>\n<div id=\"content\">\n");
750 escputs(messagetext);
758 * \brief Display a blank page.
760 void blank_page(void) {
761 output_headers(1, 1, 0, 0, 0, 0);
767 * \brief A template has been requested
769 void url_do_template(void) {
770 do_template(bstr("template"));
776 * \brief Offer to make any page the user's "start page."
778 void offer_start_page(void) {
779 wprintf("<a href=\"change_start_page?startpage=");
780 urlescputs(WC->this_page);
782 wprintf(_("Make this my start page"));
785 wprintf("<br/><a href=\"rss?room=");
786 urlescputs(WC->wc_roomname);
787 wprintf("\" title=\"RSS 2.0 feed for ");
788 escputs(WC->wc_roomname);
789 wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"static/xml_button.gif\"/></a>\n");
795 * \brief Change the user's start page
797 void change_start_page(void) {
799 if (bstr("startpage") == NULL) {
800 safestrncpy(WC->ImportantMessage,
801 _("You no longer have a start page selected."),
802 sizeof WC->ImportantMessage);
807 set_preference("startpage", bstr("startpage"), 1);
809 output_headers(1, 1, 0, 0, 0, 0);
810 do_template("newstartpage");
817 * \brief convenience function to indicate success
818 * \param successmessage the mesage itself
820 void display_success(char *successmessage)
822 convenience_page("007700", "OK", successmessage);
827 * \brief Authorization required page
828 * This is probably temporary and should be revisited
829 * \param message message to put in header
831 void authorization_required(const char *message)
833 wprintf("HTTP/1.1 401 Authorization Required\r\n");
834 wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
835 wprintf("Content-Type: text/html\r\n\r\n");
837 wprintf(_("Authorization Required"));
838 wprintf("</h1>\r\n");
839 wprintf(_("The resource you requested requires a valid username and password. "
840 "You could not be logged in: %s\n"), message);
845 * \brief This function is called by the MIME parser to handle data uploaded by
846 * the browser. Form data, uploaded files, and the data from HTTP PUT
847 * operations (such as those found in GroupDAV) all arrive this way.
849 * \param name Name of the item being uploaded
850 * \param filename Filename of the item being uploaded
851 * \param partnum MIME part identifier (not needed)
852 * \param disp MIME content disposition (not needed)
853 * \param content The actual data
854 * \param cbtype MIME content-type
855 * \param cbcharset Character set
856 * \param length Content length
857 * \param encoding MIME encoding type (not needed)
858 * \param userdata Not used here
860 void upload_handler(char *name, char *filename, char *partnum, char *disp,
861 void *content, char *cbtype, char *cbcharset,
862 size_t length, char *encoding, void *userdata)
864 struct urlcontent *u;
866 lprintf(9, "upload_handler() name=%s, type=%s, len=%d\n", name, cbtype, length);
869 if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
870 u = (struct urlcontent *) malloc(sizeof(struct urlcontent));
871 u->next = WC->urlstrings;
873 safestrncpy(u->url_key, name, sizeof(u->url_key));
874 u->url_data = malloc(length + 1);
875 memcpy(u->url_data, content, length);
876 u->url_data[length] = 0;
877 /* lprintf(9, "Key: <%s> Data: <%s>\n", u->url_key, u->url_data); */
880 /** Uploaded files */
881 if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
882 WC->upload = malloc(length);
883 if (WC->upload != NULL) {
884 WC->upload_length = length;
885 safestrncpy(WC->upload_filename, filename,
886 sizeof(WC->upload_filename));
887 safestrncpy(WC->upload_content_type, cbtype,
888 sizeof(WC->upload_content_type));
889 memcpy(WC->upload, content, length);
892 lprintf(3, "malloc() failed: %s\n", strerror(errno));
899 * \brief Convenience functions to wrap around asynchronous ajax responses
901 void begin_ajax_response(void) {
902 output_headers(0, 0, 0, 0, 0, 0);
904 wprintf("Content-type: text/html; charset=UTF-8\r\n"
906 "Connection: close\r\n"
907 "Pragma: no-cache\r\n"
908 "Cache-Control: no-cache\r\n",
914 * \brief print ajax response footer
916 void end_ajax_response(void) {
922 * \brief Wraps a Citadel server command in an AJAX transaction.
924 void ajax_servcmd(void)
931 begin_ajax_response();
933 serv_printf("%s", bstr("g_cmd"));
934 serv_getln(buf, sizeof buf);
935 wprintf("%s\n", buf);
938 serv_printf("\n\n000");
940 if ((buf[0] == '1') || (buf[0] == '8')) {
941 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
942 wprintf("%s\n", gcontent);
947 text_to_server(bstr("g_input"));
953 serv_read(junk, len);
959 memset(junk, 0, len);
960 serv_write(junk, len);
967 * This is kind of an ugly hack, but this is the only place it can go.
968 * If the command was GEXP, then the instant messenger window must be
969 * running, so reset the "last_pager_check" watchdog timer so
970 * that page_popup() doesn't try to open it a second time.
972 if (!strncasecmp(bstr("g_cmd"), "GEXP", 4)) {
973 WC->last_pager_check = time(NULL);
979 * \brief Helper function for the asynchronous check to see if we need
980 * to open the instant messenger window.
982 void seconds_since_last_gexp(void)
986 begin_ajax_response();
987 if ( (time(NULL) - WC->last_pager_check) < 30) {
992 serv_getln(buf, sizeof buf);
1000 end_ajax_response();
1007 * \brief Entry point for WebCit transaction
1009 void session_loop(struct httprequest *req)
1017 char request_method[128];
1018 char pathname[1024];
1019 int a, b, nBackDots, nEmpty;
1020 int ContentLength = 0;
1022 char ContentType[512];
1023 char *content = NULL;
1024 char *content_end = NULL;
1025 struct httprequest *hptr;
1026 char browser_host[256];
1027 char user_agent[256];
1033 * We stuff these with the values coming from the client cookies,
1034 * so we can use them to reconnect a timed out session if we have to.
1036 char c_username[SIZ];
1037 char c_password[SIZ];
1038 char c_roomname[SIZ];
1039 char c_httpauth_string[SIZ];
1040 char c_httpauth_user[SIZ];
1041 char c_httpauth_pass[SIZ];
1044 safestrncpy(c_username, "", sizeof c_username);
1045 safestrncpy(c_password, "", sizeof c_password);
1046 safestrncpy(c_roomname, "", sizeof c_roomname);
1047 safestrncpy(c_httpauth_string, "", sizeof c_httpauth_string);
1048 safestrncpy(c_httpauth_user, DEFAULT_HTTPAUTH_USER, sizeof c_httpauth_user);
1049 safestrncpy(c_httpauth_pass, DEFAULT_HTTPAUTH_PASS, sizeof c_httpauth_pass);
1050 strcpy(browser_host, "");
1052 WC->upload_length = 0;
1058 if (hptr == NULL) return;
1060 safestrncpy(cmd, hptr->line, sizeof cmd);
1062 extract_token(request_method, cmd, 0, ' ', sizeof request_method);
1063 extract_token(pathname, cmd, 1, ' ', sizeof pathname);
1065 /** Figure out the action */
1067 sizes[0] = sizeof action;
1070 index[a] = arg[a-1];
1071 sizes[a] = sizeof arg[a-1];
1073 //// index[9] = &foo; todo
1076 for ( a = 0; a < 9; ++a)
1078 extract_token(index[a], pathname, a + 1, '/', sizes[a]);
1079 if (strstr(index[a], "?")) *strstr(index[a], "?") = 0;
1080 if (strstr(index[a], "&")) *strstr(index[a], "&") = 0;
1081 if (strstr(index[a], " ")) *strstr(index[a], " ") = 0;
1082 if ((index[a][0] == '.') && (index[a][1] == '.'))
1084 if (index[a][0] == '\0')
1088 while (hptr != NULL) {
1089 safestrncpy(buf, hptr->line, sizeof buf);
1090 /* lprintf(9, "HTTP HEADER: %s\n", buf); */
1093 if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
1094 safestrncpy(cookie, &buf[15], sizeof cookie);
1095 cookie_to_stuff(cookie, NULL,
1096 c_username, sizeof c_username,
1097 c_password, sizeof c_password,
1098 c_roomname, sizeof c_roomname);
1100 else if (!strncasecmp(buf, "Authorization: Basic ", 21)) {
1101 CtdlDecodeBase64(c_httpauth_string, &buf[21], strlen(&buf[21]));
1102 extract_token(c_httpauth_user, c_httpauth_string, 0, ':', sizeof c_httpauth_user);
1103 extract_token(c_httpauth_pass, c_httpauth_string, 1, ':', sizeof c_httpauth_pass);
1105 else if (!strncasecmp(buf, "Content-length: ", 16)) {
1106 ContentLength = atoi(&buf[16]);
1108 else if (!strncasecmp(buf, "Content-type: ", 14)) {
1109 safestrncpy(ContentType, &buf[14], sizeof ContentType);
1111 else if (!strncasecmp(buf, "User-agent: ", 12)) {
1112 safestrncpy(user_agent, &buf[12], sizeof user_agent);
1114 else if (!strncasecmp(buf, "X-Forwarded-Host: ", 18)) {
1116 safestrncpy(WC->http_host, &buf[18], sizeof WC->http_host);
1119 else if (!strncasecmp(buf, "Host: ", 6)) {
1120 if (IsEmptyStr(WC->http_host)) {
1121 safestrncpy(WC->http_host, &buf[6], sizeof WC->http_host);
1124 else if (!strncasecmp(buf, "X-Forwarded-For: ", 17)) {
1125 safestrncpy(browser_host, &buf[17], sizeof browser_host);
1126 while (num_tokens(browser_host, ',') > 1) {
1127 remove_token(browser_host, 0, ',');
1129 striplt(browser_host);
1131 /** Only WAP gateways explicitly name this content-type */
1132 else if (strstr(buf, "text/vnd.wap.wml")) {
1137 if (ContentLength > 0) {
1138 content = malloc(ContentLength + SIZ);
1139 memset(content, 0, ContentLength + SIZ);
1140 sprintf(content, "Content-type: %s\n"
1141 "Content-length: %d\n\n",
1142 ContentType, ContentLength);
1143 body_start = strlen(content);
1145 /** Read the entire input data at once. */
1146 client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
1148 if (!strncasecmp(ContentType, "application/x-www-form-urlencoded", 33)) {
1149 addurls(&content[body_start]);
1150 } else if (!strncasecmp(ContentType, "multipart", 9)) {
1151 content_end = content + ContentLength + body_start;
1152 mime_parser(content, content_end, *upload_handler, NULL, NULL, NULL, 0);
1158 /** make a note of where we are in case the user wants to save it */
1159 safestrncpy(WC->this_page, cmd, sizeof(WC->this_page));
1160 remove_token(WC->this_page, 2, ' ');
1161 remove_token(WC->this_page, 0, ' ');
1163 /** If there are variables in the URL, we must grab them now */
1165 for (a = 0; a < len; ++a) {
1166 if ((cmd[a] == '?') || (cmd[a] == '&')) {
1167 for (b = a; b < len; ++b) {
1168 if (isspace(cmd[b])){
1173 addurls(&cmd[a + 1]);
1179 /** If it's a "force 404" situation then display the error and bail. */
1180 if (!strcmp(action, "404")) {
1181 wprintf("HTTP/1.1 404 Not found\r\n");
1182 wprintf("Content-Type: text/plain\r\n");
1184 wprintf("Not found\r\n");
1185 goto SKIP_ALL_THIS_CRAP;
1188 /** Static content can be sent without connecting to Citadel. */
1190 for (a=0; a<ndirs; ++a) {
1191 if (!strcasecmp(action, (char*)static_content_dirs[a])) { /* map web to disk location */
1199 snprintf(buf, sizeof buf, "%s/%s/%s/%s/%s/%s/%s/%s",
1200 static_dirs[n_static],
1201 index[1], index[2], index[3], index[4], index[5], index[6], index[7]);
1202 for (a=0; a<8; ++a) {
1203 if (buf[strlen(buf)-1] == '/') {
1204 buf[strlen(buf)-1] = 0;
1207 for (a = 0; a < strlen(buf); ++a) {
1208 if (isspace(buf[a])) {
1216 lprintf(9, "Suspicious request. Ignoring.");
1217 wprintf("HTTP/1.1 404 Security check failed\r\n");
1218 wprintf("Content-Type: text/plain\r\n");
1220 wprintf("Security check failed.\r\n");
1222 goto SKIP_ALL_THIS_CRAP; /* Don't try to connect */
1225 /* If the client sent a nonce that is incorrect, kill the request. */
1226 if (strlen(bstr("nonce")) > 0) {
1227 lprintf(9, "Comparing supplied nonce %s to session nonce %ld\n",
1228 bstr("nonce"), WC->nonce);
1229 if (atoi(bstr("nonce")) != WC->nonce) {
1230 lprintf(9, "Ignoring request with mismatched nonce.\n");
1231 wprintf("HTTP/1.1 404 Security check failed\r\n");
1232 wprintf("Content-Type: text/plain\r\n");
1234 wprintf("Security check failed.\r\n");
1235 goto SKIP_ALL_THIS_CRAP;
1240 * If we're not connected to a Citadel server, try to hook up the
1243 if (!WC->connected) {
1244 if (!strcasecmp(ctdlhost, "uds")) {
1245 /* unix domain socket */
1246 sprintf(buf, "%s/citadel.socket", ctdlport);
1247 WC->serv_sock = uds_connectsock(buf);
1251 WC->serv_sock = tcp_connectsock(ctdlhost, ctdlport);
1254 if (WC->serv_sock < 0) {
1256 goto SKIP_ALL_THIS_CRAP;
1260 serv_getln(buf, sizeof buf); /** get the server welcome message */
1263 * From what host is our user connecting? Go with
1264 * the host at the other end of the HTTP socket,
1265 * unless we are following X-Forwarded-For: headers
1266 * and such a header has already turned up something.
1268 if ( (!follow_xff) || (strlen(browser_host) == 0) ) {
1269 locate_host(browser_host, WC->http_sock);
1272 get_serv_info(browser_host, user_agent);
1273 if (serv_info.serv_rev_level < MINIMUM_CIT_VERSION) {
1274 wprintf(_("You are connected to a Citadel "
1275 "server running Citadel %d.%02d. \n"
1276 "In order to run this version of WebCit "
1277 "you must also have Citadel %d.%02d or"
1279 serv_info.serv_rev_level / 100,
1280 serv_info.serv_rev_level % 100,
1281 MINIMUM_CIT_VERSION / 100,
1282 MINIMUM_CIT_VERSION % 100
1284 end_webcit_session();
1285 goto SKIP_ALL_THIS_CRAP;
1291 * Functions which can be performed without logging in
1293 if (!strcasecmp(action, "listsub")) {
1295 goto SKIP_ALL_THIS_CRAP;
1297 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1298 if (!strcasecmp(action, "freebusy")) {
1300 goto SKIP_ALL_THIS_CRAP;
1305 * If we're not logged in, but we have HTTP Authentication data,
1306 * try logging in to Citadel using that.
1308 if ((!WC->logged_in)
1309 && (strlen(c_httpauth_user) > 0)
1310 && (strlen(c_httpauth_pass) > 0)) {
1311 serv_printf("USER %s", c_httpauth_user);
1312 serv_getln(buf, sizeof buf);
1313 if (buf[0] == '3') {
1314 serv_printf("PASS %s", c_httpauth_pass);
1315 serv_getln(buf, sizeof buf);
1316 if (buf[0] == '2') {
1317 become_logged_in(c_httpauth_user,
1318 c_httpauth_pass, buf);
1319 safestrncpy(WC->httpauth_user, c_httpauth_user, sizeof WC->httpauth_user);
1320 safestrncpy(WC->httpauth_pass, c_httpauth_pass, sizeof WC->httpauth_pass);
1322 /** Should only display when password is wrong */
1323 authorization_required(&buf[4]);
1324 goto SKIP_ALL_THIS_CRAP;
1329 /** This needs to run early */
1330 if (!strcasecmp(action, "rss")) {
1331 display_rss(bstr("room"), request_method);
1332 goto SKIP_ALL_THIS_CRAP;
1336 * The GroupDAV stuff relies on HTTP authentication instead of
1337 * our session's authentication.
1339 if (!strncasecmp(action, "groupdav", 8)) {
1340 groupdav_main(req, ContentType, /* do GroupDAV methods */
1341 ContentLength, content+body_start);
1342 if (!WC->logged_in) {
1343 WC->killthis = 1; /* If not logged in, don't */
1344 } /* keep the session active */
1345 goto SKIP_ALL_THIS_CRAP;
1350 * Automatically send requests with any method other than GET or
1351 * POST to the GroupDAV code as well.
1353 if ((strcasecmp(request_method, "GET")) && (strcasecmp(request_method, "POST"))) {
1354 groupdav_main(req, ContentType, /** do GroupDAV methods */
1355 ContentLength, content+body_start);
1356 if (!WC->logged_in) {
1357 WC->killthis = 1; /** If not logged in, don't */
1358 } /** keep the session active */
1359 goto SKIP_ALL_THIS_CRAP;
1363 * If we're not logged in, but we have username and password cookies
1364 * supplied by the browser, try using them to log in.
1366 if ((!WC->logged_in)
1367 && (!IsEmptyStr(c_username))
1368 && (!IsEmptyStr(c_password))) {
1369 serv_printf("USER %s", c_username);
1370 serv_getln(buf, sizeof buf);
1371 if (buf[0] == '3') {
1372 serv_printf("PASS %s", c_password);
1373 serv_getln(buf, sizeof buf);
1374 if (buf[0] == '2') {
1375 become_logged_in(c_username, c_password, buf);
1380 * If we don't have a current room, but a cookie specifying the
1381 * current room is supplied, make an effort to go there.
1383 if ((IsEmptyStr(WC->wc_roomname)) && (!IsEmptyStr(c_roomname))) {
1384 serv_printf("GOTO %s", c_roomname);
1385 serv_getln(buf, sizeof buf);
1386 if (buf[0] == '2') {
1387 safestrncpy(WC->wc_roomname, c_roomname, sizeof WC->wc_roomname);
1391 if (!strcasecmp(action, "image")) {
1395 * All functions handled below this point ... make sure we log in
1396 * before doing anything else!
1398 } else if ((!WC->logged_in) && (!strcasecmp(action, "login"))) {
1400 } else if (!WC->logged_in) {
1401 display_login(NULL);
1405 * Various commands...
1408 else if (!strcasecmp(action, "do_welcome")) {
1410 } else if (!strcasecmp(action, "blank")) {
1412 } else if (!strcasecmp(action, "do_template")) {
1414 } else if (!strcasecmp(action, "display_aide_menu")) {
1415 display_aide_menu();
1416 } else if (!strcasecmp(action, "display_main_menu")) {
1417 display_main_menu();
1418 } else if (!strcasecmp(action, "who")) {
1420 } else if (!strcasecmp(action, "sslg")) {
1421 seconds_since_last_gexp();
1422 } else if (!strcasecmp(action, "who_inner_html")) {
1423 begin_ajax_response();
1425 end_ajax_response();
1426 } else if (!strcasecmp(action, "wholist_section")) {
1427 begin_ajax_response();
1429 end_ajax_response();
1430 } else if (!strcasecmp(action, "new_messages_html")) {
1431 begin_ajax_response();
1432 new_messages_section();
1433 end_ajax_response();
1434 } else if (!strcasecmp(action, "tasks_inner_html")) {
1435 begin_ajax_response();
1437 end_ajax_response();
1438 } else if (!strcasecmp(action, "calendar_inner_html")) {
1439 begin_ajax_response();
1441 end_ajax_response();
1442 } else if (!strcasecmp(action, "iconbar_ajax_menu")) {
1443 begin_ajax_response();
1445 end_ajax_response();
1446 } else if (!strcasecmp(action, "iconbar_ajax_rooms")) {
1447 begin_ajax_response();
1448 do_iconbar_roomlist();
1449 end_ajax_response();
1450 } else if (!strcasecmp(action, "knrooms")) {
1452 } else if (!strcasecmp(action, "gotonext")) {
1455 } else if (!strcasecmp(action, "skip")) {
1457 } else if (!strcasecmp(action, "ungoto")) {
1459 } else if (!strcasecmp(action, "dotgoto")) {
1460 if (WC->wc_view != VIEW_MAILBOX) { /* dotgoto acts like dotskip when we're in a mailbox view */
1463 smart_goto(bstr("room"));
1464 } else if (!strcasecmp(action, "dotskip")) {
1465 smart_goto(bstr("room"));
1466 } else if (!strcasecmp(action, "termquit")) {
1468 } else if (!strcasecmp(action, "readnew")) {
1469 readloop("readnew");
1470 } else if (!strcasecmp(action, "readold")) {
1471 readloop("readold");
1472 } else if (!strcasecmp(action, "readfwd")) {
1473 readloop("readfwd");
1474 } else if (!strcasecmp(action, "headers")) {
1475 readloop("headers");
1476 } else if (!strcasecmp(action, "do_search")) {
1477 readloop("do_search");
1478 } else if (!strcasecmp(action, "msg")) {
1479 embed_message(index[1]);
1480 } else if (!strcasecmp(action, "printmsg")) {
1481 print_message(index[1]);
1482 } else if (!strcasecmp(action, "msgheaders")) {
1483 display_headers(index[1]);
1484 } else if (!strcasecmp(action, "wiki")) {
1485 display_wiki_page();
1486 } else if (!strcasecmp(action, "display_enter")) {
1488 } else if (!strcasecmp(action, "post")) {
1490 } else if (!strcasecmp(action, "move_msg")) {
1492 } else if (!strcasecmp(action, "delete_msg")) {
1494 } else if (!strcasecmp(action, "userlist")) {
1496 } else if (!strcasecmp(action, "showuser")) {
1498 } else if (!strcasecmp(action, "display_page")) {
1500 } else if (!strcasecmp(action, "page_user")) {
1502 } else if (!strcasecmp(action, "chat")) {
1504 } else if (!strcasecmp(action, "display_private")) {
1505 display_private("", 0);
1506 } else if (!strcasecmp(action, "goto_private")) {
1508 } else if (!strcasecmp(action, "zapped_list")) {
1510 } else if (!strcasecmp(action, "display_zap")) {
1512 } else if (!strcasecmp(action, "zap")) {
1514 } else if (!strcasecmp(action, "display_entroom")) {
1516 } else if (!strcasecmp(action, "entroom")) {
1518 } else if (!strcasecmp(action, "display_whok")) {
1520 } else if (!strcasecmp(action, "do_invt_kick")) {
1522 } else if (!strcasecmp(action, "display_editroom")) {
1524 } else if (!strcasecmp(action, "netedit")) {
1526 } else if (!strcasecmp(action, "editroom")) {
1528 } else if (!strcasecmp(action, "display_editinfo")) {
1529 display_edit(_("Room info"), "EINF 0", "RINF", "editinfo", 1);
1530 } else if (!strcasecmp(action, "editinfo")) {
1531 save_edit(_("Room info"), "EINF 1", 1);
1532 } else if (!strcasecmp(action, "display_editbio")) {
1533 sprintf(buf, "RBIO %s", WC->wc_fullname);
1534 display_edit(_("Your bio"), "NOOP", buf, "editbio", 3);
1535 } else if (!strcasecmp(action, "editbio")) {
1536 save_edit(_("Your bio"), "EBIO", 0);
1537 } else if (!strcasecmp(action, "confirm_move_msg")) {
1539 } else if (!strcasecmp(action, "delete_room")) {
1541 } else if (!strcasecmp(action, "validate")) {
1543 } else if (!strcasecmp(action, "display_editpic")) {
1544 display_graphics_upload(_("your photo"),
1547 } else if (!strcasecmp(action, "editpic")) {
1548 do_graphics_upload("UIMG 1|_userpic_");
1549 } else if (!strcasecmp(action, "display_editroompic")) {
1550 display_graphics_upload(_("the icon for this room"),
1553 } else if (!strcasecmp(action, "editroompic")) {
1554 do_graphics_upload("UIMG 1|_roompic_");
1555 } else if (!strcasecmp(action, "delete_floor")) {
1557 } else if (!strcasecmp(action, "rename_floor")) {
1559 } else if (!strcasecmp(action, "create_floor")) {
1561 } else if (!strcasecmp(action, "display_editfloorpic")) {
1562 sprintf(buf, "UIMG 0|_floorpic_|%s",
1563 bstr("which_floor"));
1564 display_graphics_upload(_("the icon for this floor"),
1567 } else if (!strcasecmp(action, "editfloorpic")) {
1568 sprintf(buf, "UIMG 1|_floorpic_|%s",
1569 bstr("which_floor"));
1570 do_graphics_upload(buf);
1571 } else if (!strcasecmp(action, "display_reg")) {
1573 } else if (!strcasecmp(action, "display_changepw")) {
1575 } else if (!strcasecmp(action, "changepw")) {
1577 } else if (!strcasecmp(action, "display_edit_node")) {
1578 display_edit_node();
1579 } else if (!strcasecmp(action, "edit_node")) {
1581 } else if (!strcasecmp(action, "display_netconf")) {
1583 } else if (!strcasecmp(action, "display_confirm_delete_node")) {
1584 display_confirm_delete_node();
1585 } else if (!strcasecmp(action, "delete_node")) {
1587 } else if (!strcasecmp(action, "display_add_node")) {
1589 } else if (!strcasecmp(action, "add_node")) {
1591 } else if (!strcasecmp(action, "terminate_session")) {
1593 terminate_session();
1594 } else if (!strcasecmp(action, "edit_me")) {
1596 } else if (!strcasecmp(action, "display_siteconfig")) {
1597 display_siteconfig();
1598 } else if (!strcasecmp(action, "chat_recv")) {
1600 } else if (!strcasecmp(action, "chat_send")) {
1602 } else if (!strcasecmp(action, "siteconfig")) {
1604 } else if (!strcasecmp(action, "display_generic")) {
1606 } else if (!strcasecmp(action, "do_generic")) {
1608 } else if (!strcasecmp(action, "ajax_servcmd")) {
1610 } else if (!strcasecmp(action, "display_menubar")) {
1612 } else if (!strcasecmp(action, "mimepart")) {
1613 mimepart(index[1], index[2], 0);
1614 } else if (!strcasecmp(action, "mimepart_download")) {
1615 mimepart(index[1], index[2], 1);
1616 } else if (!strcasecmp(action, "edit_vcard")) {
1618 } else if (!strcasecmp(action, "submit_vcard")) {
1620 } else if (!strcasecmp(action, "select_user_to_edit")) {
1621 select_user_to_edit(NULL, NULL);
1622 } else if (!strcasecmp(action, "display_edituser")) {
1623 display_edituser(NULL, 0);
1624 } else if (!strcasecmp(action, "edituser")) {
1626 } else if (!strcasecmp(action, "create_user")) {
1628 } else if (!strcasecmp(action, "changeview")) {
1630 } else if (!strcasecmp(action, "change_start_page")) {
1631 change_start_page();
1632 } else if (!strcasecmp(action, "display_floorconfig")) {
1633 display_floorconfig(NULL);
1634 } else if (!strcasecmp(action, "toggle_self_service")) {
1635 toggle_self_service();
1636 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
1637 } else if (!strcasecmp(action, "display_edit_task")) {
1638 display_edit_task();
1639 } else if (!strcasecmp(action, "save_task")) {
1641 } else if (!strcasecmp(action, "display_edit_event")) {
1642 display_edit_event();
1643 } else if (!strcasecmp(action, "save_event")) {
1645 } else if (!strcasecmp(action, "respond_to_request")) {
1646 respond_to_request();
1647 } else if (!strcasecmp(action, "handle_rsvp")) {
1650 } else if (!strcasecmp(action, "summary")) {
1652 } else if (!strcasecmp(action, "summary_inner_div")) {
1653 begin_ajax_response();
1654 summary_inner_div();
1655 end_ajax_response();
1656 } else if (!strcasecmp(action, "display_customize_iconbar")) {
1657 display_customize_iconbar();
1658 } else if (!strcasecmp(action, "commit_iconbar")) {
1660 } else if (!strcasecmp(action, "set_room_policy")) {
1662 } else if (!strcasecmp(action, "display_inetconf")) {
1664 } else if (!strcasecmp(action, "save_inetconf")) {
1666 } else if (!strcasecmp(action, "display_smtpqueue")) {
1667 display_smtpqueue();
1668 } else if (!strcasecmp(action, "display_smtpqueue_inner_div")) {
1669 display_smtpqueue_inner_div();
1670 } else if (!strcasecmp(action, "display_sieve")) {
1672 } else if (!strcasecmp(action, "save_sieve")) {
1674 } else if (!strcasecmp(action, "display_add_remove_scripts")) {
1675 display_add_remove_scripts(NULL);
1676 } else if (!strcasecmp(action, "create_script")) {
1678 } else if (!strcasecmp(action, "delete_script")) {
1680 } else if (!strcasecmp(action, "setup_wizard")) {
1682 } else if (!strcasecmp(action, "display_preferences")) {
1683 display_preferences();
1684 } else if (!strcasecmp(action, "set_preferences")) {
1686 } else if (!strcasecmp(action, "recp_autocomplete")) {
1687 recp_autocomplete(bstr("recp"));
1688 } else if (!strcasecmp(action, "cc_autocomplete")) {
1689 recp_autocomplete(bstr("cc"));
1690 } else if (!strcasecmp(action, "bcc_autocomplete")) {
1691 recp_autocomplete(bstr("bcc"));
1692 } else if (!strcasecmp(action, "display_address_book_middle_div")) {
1693 display_address_book_middle_div();
1694 } else if (!strcasecmp(action, "display_address_book_inner_div")) {
1695 display_address_book_inner_div();
1696 } else if (!strcasecmp(action, "set_floordiv_expanded")) {
1697 set_floordiv_expanded(index[1]);
1698 } else if (!strcasecmp(action, "diagnostics")) {
1699 output_headers(1, 1, 1, 0, 0, 0);
1700 wprintf("Session: %d<hr />\n", WC->wc_session);
1701 wprintf("Command: <br /><PRE>\n");
1703 wprintf("</PRE><hr />\n");
1704 wprintf("Variables: <br /><PRE>\n");
1706 wprintf("</PRE><hr />\n");
1708 } else if (!strcasecmp(action, "updatenote")) {
1710 } else if (!strcasecmp(action, "display_room_directory")) {
1711 display_room_directory();
1712 } else if (!strcasecmp(action, "download_file")) {
1713 download_file(index[1]);
1714 } else if (!strcasecmp(action, "upload_file")) {
1718 /** When all else fais, display the main menu. */
1720 display_main_menu();
1725 if (content != NULL) {
1730 if (WC->upload_length > 0) {
1732 WC->upload_length = 0;