* inetconf.c: added. Not finished yet.
[citadel.git] / webcit / webcit.c
index a4363adc5fc02cfb1a17264e308555414a639dac..fa577a5be5e12ad0f0a17fb5ac17a34d9422aabd 100644 (file)
@@ -161,7 +161,7 @@ void wprintf(const char *format,...)
        vsprintf(wbuf, format, arg_ptr);
        va_end(arg_ptr);
 
-       write(WC->http_sock, wbuf, strlen(wbuf));
+       client_write(wbuf, strlen(wbuf));
 }
 
 
@@ -186,7 +186,7 @@ void wDumpContent(int print_standard_html_footer)
  * Copy a string, escaping characters which have meaning in HTML.  If
  * nbsp is nonzero, spaces are converted to non-breaking spaces.
  */
-void stresc(char *target, char *strbuf, int nbsp)
+void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks)
 {
        int a;
        strcpy(target, "");
@@ -208,24 +208,31 @@ void stresc(char *target, char *strbuf, int nbsp)
                        strcat(target, ">");
                else if (strbuf[a] == QU)
                        strcat(target, "\"");
-               else if ((strbuf[a] == 32) && (nbsp == 1)) {
+               else if ((strbuf[a] == 32) && (nbsp == 1))
                        strcat(target, " ");
-               } else {
+               else if ((strbuf[a] == '\n') && (nolinebreaks))
+                       strcat(target, "");     /* nothing */
+               else if ((strbuf[a] == '\r') && (nolinebreaks))
+                       strcat(target, "");     /* nothing */
+               else
                        strncat(target, &strbuf[a], 1);
-               }
        }
 }
 
-void escputs1(char *strbuf, int nbsp)
+void escputs1(char *strbuf, int nbsp, int nolinebreaks)
 {
-       char buf[1024];
-       stresc(buf, strbuf, nbsp);
+       char *buf;
+
+       if (strbuf == NULL) return;
+       buf = malloc(2 * strlen(strbuf));
+       stresc(buf, strbuf, nbsp, nolinebreaks);
        wprintf("%s", buf);
+       free(buf);
 }
 
 void escputs(char *strbuf)
 {
-       escputs1(strbuf, 0);
+       escputs1(strbuf, 0, 0);
 }
 
 /*
@@ -262,6 +269,71 @@ void urlescputs(char *strbuf)
 }
 
 
+/*
+ * Copy a string, escaping characters for JavaScript strings.
+ */
+void jsesc(char *target, char *strbuf)
+{
+       int a;
+       strcpy(target, "");
+
+       for (a = 0; a < strlen(strbuf); ++a) {
+               if (strbuf[a] == '<')
+                       strcat(target, "[");
+               else if (strbuf[a] == '>')
+                       strcat(target, "]");
+               else if (strbuf[a] == '\"')
+                       strcat(target, "&quot;");
+               else if (strbuf[a] == '&')
+                       strcat(target, "&amp;;");
+               else if (strbuf[a] == '\'') 
+                       strcat(target, "\\'");
+               else {
+                       strncat(target, &strbuf[a], 1);
+               }
+       }
+}
+
+void jsescputs(char *strbuf)
+{
+       char outbuf[SIZ];
+       
+       jsesc(outbuf, strbuf);
+       wprintf("%s", outbuf);
+}
+
+/*
+ * Copy a string, escaping characters for message text hold
+ */
+void msgesc(char *target, char *strbuf)
+{
+       int a;
+       strcpy(target, "");
+
+       for (a = 0; a < strlen(strbuf); ++a) {
+               if (strbuf[a] == '\'') 
+                       strcat(target, "\\'");
+               else if (strbuf[a] == '\n')
+                       strcat(target, " ");
+               else if (strbuf[a] == '\r')
+                       strcat(target, " ");
+               else {
+                       strncat(target, &strbuf[a], 1);
+               }
+       }
+}
+
+void msgescputs(char *strbuf) {
+       char *outbuf;
+
+       if (strbuf == NULL) return;
+       outbuf = malloc(2 * strlen(strbuf));
+       msgesc(outbuf, strbuf);
+       wprintf("%s", outbuf);
+       free(outbuf);
+}
+
+
 
 
 /*
@@ -429,7 +501,7 @@ void http_transmit_thing(char *thing, size_t length, char *content_type,
                (long) length,
                SERVER
        );
-       write(WC->http_sock, thing, (size_t)length);
+       client_write(thing, (size_t)length);
 }
 
 
@@ -463,8 +535,12 @@ void output_static(char *what)
                        strcpy(content_type, "image/jpeg");
                else if (!strncasecmp(&what[strlen(what) - 4], ".png", 4))
                        strcpy(content_type, "image/png");
+               else if (!strncasecmp(&what[strlen(what) - 4], ".ico", 4))
+                       strcpy(content_type, "image/x-icon");
                else if (!strncasecmp(&what[strlen(what) - 5], ".html", 5))
                        strcpy(content_type, "text/html");
+               else if (!strncasecmp(&what[strlen(what) - 4], ".htm", 4))
+                       strcpy(content_type, "text/html");
                else if (!strncasecmp(&what[strlen(what) - 4], ".wml", 4))
                        strcpy(content_type, "text/vnd.wap.wml");
                else if (!strncasecmp(&what[strlen(what) - 5], ".wmls", 5))
@@ -474,9 +550,11 @@ void output_static(char *what)
                else if (!strncasecmp(&what[strlen(what) - 6], ".wmlsc", 6))
                        strcpy(content_type, "application/vnd.wap.wmlscriptc");
                else if (!strncasecmp(&what[strlen(what) - 5], ".wbmp", 5))
-                       wprintf("Content-type: image/vnd.wap.wbmp");
+                       strcpy(content_type, "image/vnd.wap.wbmp");
+               else if (!strncasecmp(&what[strlen(what) - 3], ".js", 3))
+                       strcpy(content_type, "text/javascript");
                else
-                       wprintf("Content-type: application/octet-stream");
+                       strcpy(content_type, "application/octet-stream");
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
@@ -762,7 +840,7 @@ void session_loop(struct httprequest *req)
        char buf[SIZ];
        int a, b;
        int ContentLength = 0;
-       int BytesRead;
+       int BytesRead = 0;
        char ContentType[512];
        char *content;
        char *content_end;
@@ -830,6 +908,7 @@ void session_loop(struct httprequest *req)
                                ContentType, ContentLength);
                body_start = strlen(content);
 
+/***** old version
                BytesRead = 0;
                while (BytesRead < ContentLength) {
                        a=read(WC->http_sock, &content[BytesRead+body_start],
@@ -837,6 +916,10 @@ void session_loop(struct httprequest *req)
                        if (a <= 0) BytesRead = ContentLength;
                        else BytesRead += a;
                }
+*******/
+
+               /* Now we're daring and read it all at once. */
+               client_read(WC->http_sock, &content[BytesRead+body_start], ContentLength);
 
                if (!strncasecmp(ContentType,
                              "application/x-www-form-urlencoded", 33)) {
@@ -1123,6 +1206,10 @@ void session_loop(struct httprequest *req)
                edit_me();
        } else if (!strcasecmp(action, "display_siteconfig")) {
                display_siteconfig();
+       } else if (!strcasecmp(action, "chat_recv")) {
+               chat_recv();
+       } else if (!strcasecmp(action, "chat_send")) {
+               chat_send();
        } else if (!strcasecmp(action, "page_popup")) {
                page_popup();
        } else if (!strcasecmp(action, "siteconfig")) {
@@ -1142,7 +1229,7 @@ void session_loop(struct httprequest *req)
        } else if (!strcasecmp(action, "select_user_to_edit")) {
                select_user_to_edit(NULL, NULL);
        } else if (!strcasecmp(action, "display_edituser")) {
-               display_edituser(NULL);
+               display_edituser(NULL, 0);
        } else if (!strcasecmp(action, "edituser")) {
                edituser();
        } else if (!strcasecmp(action, "create_user")) {
@@ -1179,6 +1266,12 @@ void session_loop(struct httprequest *req)
                display_customize_iconbar();
        } else if (!strcasecmp(action, "commit_iconbar")) {
                commit_iconbar();
+       } else if (!strcasecmp(action, "set_room_policy")) {
+               set_room_policy();
+       } else if (!strcasecmp(action, "display_inetconf")) {
+               display_inetconf();
+       } else if (!strcasecmp(action, "save_inetconf")) {
+               save_inetconf();
        } else if (!strcasecmp(action, "diagnostics")) {
                output_headers(1);