]> code.citadel.org Git - citadel.git/blobdiff - webcit/webcit.c
* Discovered that Prototype makes it easy to auto-refresh, so I switched
[citadel.git] / webcit / webcit.c
index cf184f1b980e2474a92ffde7b4f802c06ba5d7b3..82422c2c573fe8b8e2d5aec80c1baaf3c6cd201c 100644 (file)
@@ -304,6 +304,8 @@ void msgesc(char *target, char *strbuf)
                        strcat(target, " ");
                else if (strbuf[a] == '\r')
                        strcat(target, " ");
+               else if (strbuf[a] == '\'')
+                       strcat(target, "'");
                else {
                        strncat(target, &strbuf[a], 1);
                }
@@ -334,14 +336,13 @@ void output_headers(      int do_httpheaders,     /* 1 = output HTTP headers
                                                /*     <div id="content"> either.                   */
 
                        int unset_cookies,      /* 1 = session is terminating, so unset the cookies */
-                       int refresh30,          /* 1 = automatically refresh page every 30 seconds  */
                        int suppress_check,     /* 1 = suppress check for instant messages          */
                        int cache               /* 1 = allow browser to cache this page             */
 ) {
        char cookie[SIZ];
        char httpnow[SIZ];
 
-       wprintf("HTTP/1.0 200 OK\n");
+       wprintf("HTTP/1.1 200 OK\n");
        httpdate(httpnow, time(NULL));
 
        if (do_httpheaders) {
@@ -380,16 +381,6 @@ void output_headers(       int do_httpheaders,     /* 1 = output HTTP headers
        if (do_htmlhead) {
                /* wprintf("\n"); */
                begin_burst();
-
-               if (refresh30) {
-                       svprintf("REFRESHTAG", WCS_STRING, "%s",
-                               "<meta http-equiv=\"refresh\" content=\"30\" />\n");
-               }
-               else {
-                       svprintf("REFRESHTAG", WCS_STRING, "%s",
-                               "<meta http-equiv=\"refresh\" content=\"500363689;\" />\n");
-               }
-
                do_template("head");
        }
 
@@ -433,7 +424,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
  * Generic function to do an HTTP redirect.  Easy and fun.
  */
 void http_redirect(char *whichpage) {
-       wprintf("HTTP/1.0 302 Moved Temporarily\n");
+       wprintf("HTTP/1.1 302 Moved Temporarily\n");
        wprintf("Location: %s\r\n", whichpage);
        wprintf("URI: %s\r\n", whichpage);
        wprintf("Content-type: text/html; charset=utf-8\r\n\r\n");
@@ -462,7 +453,7 @@ void check_for_instant_messages()
 void http_transmit_thing(char *thing, size_t length, char *content_type,
                         int is_static) {
 
-       output_headers(0, 0, 0, 0, 0, 0, is_static);
+       output_headers(0, 0, 0, 0, 0, is_static);
 
        wprintf("Content-type: %s\r\n"
                "Server: %s\r\n"
@@ -518,7 +509,7 @@ void output_static(char *what)
        sprintf(buf, "static/%s", what);
        fp = fopen(buf, "rb");
        if (fp == NULL) {
-               wprintf("HTTP/1.0 404 %s\n", strerror(errno));
+               wprintf("HTTP/1.1 404 %s\n", strerror(errno));
                wprintf("Content-Type: text/plain\r\n");
                wprintf("\r\n");
                wprintf("Cannot open %s: %s\n", what, strerror(errno));
@@ -622,15 +613,15 @@ void output_mimepart()
                bytes = extract_long(&buf[4], 0);
                content = malloc(bytes + 2);
                extract_token(content_type, &buf[4], 3, '|', sizeof content_type);
-               output_headers(0, 0, 0, 0, 0, 0, 0);
+               output_headers(0, 0, 0, 0, 0, 0);
                read_server_binary(content, bytes);
                serv_puts("CLOS");
                serv_getln(buf, sizeof buf);
                http_transmit_thing(content, bytes, content_type, 0);
                free(content);
        } else {
-               wprintf("HTTP/1.0 404 %s\n", &buf[4]);
-               output_headers(0, 0, 0, 0, 0, 0, 0);
+               wprintf("HTTP/1.1 404 %s\n", &buf[4]);
+               output_headers(0, 0, 0, 0, 0, 0);
                wprintf("Content-Type: text/plain\r\n");
                wprintf("\r\n");
                wprintf(_("An error occurred while retrieving this part: %s\n"), &buf[4]);
@@ -675,8 +666,8 @@ char *load_mimepart(long msgnum, char *partnum)
  */
 void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
 {
-       wprintf("HTTP/1.0 200 OK\n");
-       output_headers(1, 1, 2, 0, 0, 0, 0);
+       wprintf("HTTP/1.1 200 OK\n");
+       output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
        wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#%s\"><TR><TD>", titlebarcolor);
        wprintf("<SPAN CLASS=\"titlebar\">%s</SPAN>\n", titlebarmsg);
@@ -693,7 +684,7 @@ void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext)
  * Display a blank page.
  */
 void blank_page(void) {
-       output_headers(1, 1, 0, 0, 1, 0, 0);
+       output_headers(1, 1, 0, 0, 0, 0);
        wDumpContent(2);
 }
 
@@ -716,6 +707,11 @@ void offer_start_page(void) {
        wprintf("\"><FONT SIZE=-2 COLOR=\"#AAAAAA\">");
        wprintf(_("Make this my start page"));
        wprintf("</FONT></A>");
+       wprintf("<br/><a href=\"/rss?room=");
+       urlescputs(WC->wc_roomname);
+       wprintf("\" title=\"RSS 2.0 feed for ");
+       escputs(WC->wc_roomname);
+       wprintf("\"><img alt=\"RSS\" border=\"0\" src=\"/static/xml_button.gif\"/></a>\n");
 }
 
 
@@ -734,7 +730,7 @@ void change_start_page(void) {
 
        set_preference("startpage", bstr("startpage"), 1);
 
-       output_headers(1, 1, 0, 0, 0, 0, 0);
+       output_headers(1, 1, 0, 0, 0, 0);
        do_template("newstartpage");
        wDumpContent(1);
 }
@@ -752,7 +748,7 @@ void display_success(char *successmessage)
 /* This is probably temporary and should be revisited */
 void authorization_required(const char *message)
 {
-       wprintf("HTTP/1.0 401 Authorization Required\r\n");
+       wprintf("HTTP/1.1 401 Authorization Required\r\n");
        wprintf("WWW-Authenticate: Basic realm=\"\"\r\n", serv_info.serv_humannode);
        wprintf("Content-Type: text/html\r\n\r\n");
        wprintf("<h1>");
@@ -802,6 +798,25 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
 
 }
 
+/*
+ * Convenience functions to wrap around asynchronous ajax responses
+ */
+void begin_ajax_response(void) {
+        output_headers(0, 0, 0, 0, 0, 0);
+
+        wprintf("Content-type: text/html; charset=UTF-8\r\n"
+                "Server: %s\r\n"
+                "Connection: close\r\n"
+                "Pragma: no-cache\r\n"
+                "Cache-Control: no-cache\r\n",
+                SERVER);
+        begin_burst();
+}
+
+void end_ajax_response(void) {
+        wprintf("\r\n");
+        wDumpContent(0);
+}
 
 
 
@@ -1141,7 +1156,9 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "who")) {
                who();
        } else if (!strcasecmp(action, "who_inner_html")) {
-               who_inner_html();
+               begin_ajax_response();
+               who_inner_div();
+               end_ajax_response();
        } else if (!strcasecmp(action, "knrooms")) {
                knrooms();
        } else if (!strcasecmp(action, "gotonext")) {
@@ -1334,6 +1351,10 @@ void session_loop(struct httprequest *req)
 #endif
        } else if (!strcasecmp(action, "summary")) {
                summary();
+       } else if (!strcasecmp(action, "summary_inner_div")) {
+               begin_ajax_response();
+               summary_inner_div();
+               end_ajax_response();
        } else if (!strcasecmp(action, "iconbar")) {
                do_iconbar();
        } else if (!strcasecmp(action, "display_customize_iconbar")) {
@@ -1353,9 +1374,13 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "set_preferences")) {
                set_preferences();
        } else if (!strcasecmp(action, "recp_autocomplete")) {
-               recp_autocomplete();
+               recp_autocomplete(bstr("recp"));
+       } else if (!strcasecmp(action, "cc_autocomplete")) {
+               recp_autocomplete(bstr("cc"));
+       } else if (!strcasecmp(action, "bcc_autocomplete")) {
+               recp_autocomplete(bstr("bcc"));
        } else if (!strcasecmp(action, "diagnostics")) {
-               output_headers(1, 1, 1, 0, 0, 0, 0);
+               output_headers(1, 1, 1, 0, 0, 0);
                wprintf("Session: %d<hr />\n", WC->wc_session);
                wprintf("Command: <br /><PRE>\n");
                escputs(cmd);