* Rewrote the HTTP engine and application coupling to run in a worker thread
[citadel.git] / webcit / paging.c
1 /* $Id$ */
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  * display the form for paging (x-messaging) another user
27  */
28 void display_page(void)
29 {
30         char buf[256];
31         char user[256];
32
33         wprintf("HTTP/1.0 200 OK\n");
34         output_headers(1);
35
36         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
37         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
38         wprintf("<B>Page another user</B>\n");
39         wprintf("</FONT></TD></TR></TABLE>\n");
40
41         wprintf("This command sends a near-real-time message to any currently\n");
42         wprintf("logged in user.<BR><BR>\n");
43
44         wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
45
46         wprintf("Select a user to send a message to: <BR>");
47
48         wprintf("<SELECT NAME=\"recp\" SIZE=10>\n");
49         serv_puts("RWHO");
50         serv_gets(buf);
51         if (buf[0] == '1') {
52                 while (serv_gets(buf), strcmp(buf, "000")) {
53                         extract(user, buf, 1);
54                         wprintf("<OPTION>");
55                         escputs(user);
56                         wprintf("\n");
57                 }
58         }
59         wprintf("</SELECT>\n");
60         wprintf("<BR>\n");
61
62         wprintf("Enter message text:<BR>");
63         wprintf("<INPUT TYPE=\"text\" NAME=\"msgtext\" MAXLENGTH=80 SIZE=80>\n");
64         wprintf("<BR><BR>\n");
65
66         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
67         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
68
69         wprintf("</FORM></CENTER>\n");
70         wDumpContent(1);
71 }
72
73 /*
74  * page another user
75  */
76 void page_user(void)
77 {
78         char recp[256];
79         char msgtext[256];
80         char sc[256];
81         char buf[256];
82
83         wprintf("HTTP/1.0 200 OK\n");
84         output_headers(1);
85
86         strcpy(recp, bstr("recp"));
87         strcpy(msgtext, bstr("msgtext"));
88         strcpy(sc, bstr("sc"));
89
90         if (strcmp(sc, "Send message")) {
91                 wprintf("<EM>Message was not sent.</EM><BR>\n");
92         } else {
93                 serv_printf("SEXP %s|%s", recp, msgtext);
94                 serv_gets(buf);
95
96                 if (buf[0] == '2') {
97                         wprintf("<EM>Message has been sent to ");
98                         escputs(recp);
99                         wprintf(".</EM><BR>\n");
100                 } else {
101                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
102                 }
103         }
104         wDumpContent(1);
105 }
106
107
108
109 /*
110  * multiuser chat
111  */
112 void do_chat(void)
113 {
114
115         wprintf("HTTP/1.0 200 OK\n");
116         output_headers(1);
117
118         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
119         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
120         wprintf("<B>Real-time chat</B>\n");
121         wprintf("</FONT></TD></TR></TABLE>\n");
122
123         wprintf("A chat window should be appearing on your screen ");
124         wprintf("momentarily.  When you're ");
125         wprintf("done, type <TT>/quit</TT> to exit.  You can also ");
126         wprintf("type <TT>/help</TT> for more commands.\n");
127
128         wprintf("<applet codebase=\"/static\" ");
129         wprintf("code=\"wcchat\" width=2 height=2>\n");
130         wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
131         wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
132         wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
133         wprintf("so you won't be able to access Chat.  Sorry.\n");
134         wprintf("</applet>\n");
135         wDumpContent(1);
136 }