* Rewrote the HTTP engine and application coupling to run in a worker thread
[citadel.git] / webcit / sysmsgs.c
1
2
3 #include <ctype.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <fcntl.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <sys/socket.h>
12 #include <sys/time.h>
13 #include <limits.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <string.h>
17 #include <pwd.h>
18 #include <errno.h>
19 #include <stdarg.h>
20 #include <pthread.h>
21 #include <signal.h>
22 #include "webcit.h"
23
24
25
26
27
28
29
30
31 /*
32  * display the form for editing something (room info, bio, etc)
33  */
34 void display_edit(char *description, char *check_cmd,
35                   char *read_cmd, char *save_cmd)
36 {
37         char buf[256];
38
39         serv_puts(check_cmd);
40         serv_gets(buf);
41
42         if (buf[0] != '2') {
43                 display_error(&buf[4]);
44                 return;
45         }
46         wprintf("HTTP/1.0 200 OK\n");
47         output_headers(1);
48
49         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
50         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
51         wprintf("<B>Edit ");
52         escputs(description);
53         wprintf("</B></FONT></TD></TR></TABLE>\n");
54
55         wprintf("<CENTER>Enter %s below.  Text is formatted to\n", description);
56         wprintf("the <EM>reader's</EM> screen width.  To defeat the\n");
57         wprintf("formatting, indent a line at least one space.  \n");
58         wprintf("<BR>");
59
60         wprintf("<FORM METHOD=\"POST\" ACTION=\"%s\">\n", save_cmd);
61         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">");
62         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
63         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 WIDTH=80>");
64         serv_puts(read_cmd);
65         serv_gets(buf);
66         if (buf[0] == '1')
67                 server_to_text();
68         wprintf("</TEXTAREA><P>\n");
69
70         wprintf("</FORM></CENTER>\n");
71         wDumpContent(1);
72 }
73
74
75 /*
76  * save a screen which was displayed with display_edit()
77  */
78 void save_edit(char *description, char *enter_cmd, int regoto)
79 {
80         char buf[256];
81
82         if (strcmp(bstr("sc"), "Save")) {
83                 wprintf("HTTP/1.0 200 OK\n");
84                 output_headers(1);
85                 wprintf("Cancelled.  %s was not saved.<BR>\n", description);
86                 wDumpContent(1);
87                 return;
88         }
89         serv_puts(enter_cmd);
90         serv_gets(buf);
91         if (buf[0] != '4') {
92                 display_error(&buf[4]);
93                 return;
94         }
95         text_to_server(bstr("msgtext"));
96         serv_puts("000");
97
98         if (regoto) {
99                 smart_goto(WC->wc_roomname);
100         } else {
101                 wprintf("HTTP/1.0 200 OK\n");
102                 output_headers(1);
103                 wprintf("%s has been saved.\n", description);
104                 wDumpContent(1);
105         }
106 }