4 * Functions which implement the chat and paging facilities.
13 #include <sys/types.h>
15 #include <sys/socket.h>
19 #include <netinet/in.h>
31 * display the form for paging (x-messaging) another user
33 void display_page(void)
37 strcpy(recp, bstr("recp"));
41 svprintf("BOXTITLE", WCS_STRING, "Page: %s", recp);
42 do_template("beginbox");
44 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
46 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
48 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
52 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
53 escputs(bstr("closewin"));
56 wprintf("Enter message text:<BR>");
58 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
59 "WIDTH=40></TEXTAREA>\n");
61 wprintf("</TD></TR></TABLE><BR>\n");
63 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
64 wprintf("<BR><A HREF=\"javascript:window.close();\"Cancel</A>\n");
66 wprintf("</FORM></CENTER>\n");
67 do_template("endbox");
83 strcpy(recp, bstr("recp"));
84 strcpy(sc, bstr("sc"));
85 strcpy(closewin, bstr("closewin"));
87 if (strcmp(sc, "Send message")) {
88 wprintf("<EM>Message was not sent.</EM><BR>\n");
90 serv_printf("SEXP %s|-", recp);
94 text_to_server(bstr("msgtext"), 0);
96 wprintf("<EM>Message has been sent to ");
98 wprintf(".</EM><BR>\n");
101 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
105 if (!strcasecmp(closewin, "yes")) {
106 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
107 "[ close window ]</A></CENTER>\n");
123 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
124 "<SPAN CLASS=\"titlebar\">Real-time chat</SPAN>\n"
125 "</TD></TR></TABLE>\n"
126 "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"/chat_recv\" "
127 "NAME=\"chat_recv\">\n"
128 "<!-- Alternate content for non-supporting browsers -->\n"
129 "If you are seeing this message, your browser does not contain\n"
130 "the IFRAME support required for the chat window. Please upgrade\n"
131 "to a supported browser, such as\n"
132 "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
135 "<IFRAME WIDTH=100%% HEIGHT=50 SRC=\"/chat_send\" "
136 "NAME=\"chat_send\">\n"
146 void page_popup(void)
151 /* suppress express message check, do headers but no frames */
152 output_headers(0x08 | 0x03);
154 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
156 extract(pagefrom, &buf[4], 3);
158 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
159 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
161 wprintf("</SPAN></TD></TR></TABLE>\n");
167 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
168 urlescputs(pagefrom);
169 wprintf("\">[ reply ]</A> \n");
171 wprintf("<A HREF=\"javascript:window.close();\">"
172 "[ close window ]</A></B>\n"
176 WC->HaveExpressMessages = 0;
182 * Support function for chat -- make sure the chat socket is connected
185 int setup_chat_socket(void) {
188 int good_chatmode = 0;
190 if (WC->chat_sock < 0) {
192 for (i=0; i<CHATLINES; ++i) {
193 strcpy(WC->chatlines[i], "");
196 if (!strcasecmp(ctdlhost, "uds")) {
197 /* unix domain socket */
198 sprintf(buf, "%s/citadel.socket", ctdlport);
199 WC->chat_sock = uds_connectsock(buf);
203 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
206 if (WC->chat_sock < 0) {
210 /* Temporarily swap the serv and chat sockets during chat talk */
212 WC->serv_sock = WC->chat_sock;
217 serv_printf("USER %s", WC->wc_username);
220 serv_printf("PASS %s", WC->wc_password);
223 serv_printf("GOTO %s", WC->wc_roomname);
236 /* Unswap the sockets. */
238 WC->serv_sock = WC->chat_sock;
241 if (!good_chatmode) close(WC->serv_sock);
250 * receiving side of the chat window
252 void chat_recv(void) {
258 int end_chat_now = 0;
262 wprintf("Content-type: text/html\n");
266 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3\">\n"
268 "<BODY BGCOLOR=\"#FFFFFF\">"
271 if (setup_chat_socket() != 0) {
272 wprintf("Error setting up chat socket</BODY></HTML>\n");
278 * See if there is any chat data waiting.
282 pf.fd = WC->chat_sock;
285 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
288 for (i=0; i<CHATLINES-1; ++i) {
289 strcpy(WC->chatlines[i], WC->chatlines[i+1]);
292 /* Temporarily swap the serv and chat sockets during chat talk */
294 WC->serv_sock = WC->chat_sock;
297 serv_gets(WC->chatlines[CHATLINES-1]);
298 if (!strcmp(WC->chatlines[CHATLINES-1], "000")) {
300 strcpy(WC->chatlines[CHATLINES-1], ":|exiting chat mode");
303 /* Unswap the sockets. */
305 WC->serv_sock = WC->chat_sock;
308 } while ( (got_data) && (!end_chat_now) );
311 * Display appropriately.
313 for (i=0; i<CHATLINES; ++i) {
314 if (strlen(WC->chatlines[i]) > 0) {
315 extract(name, WC->chatlines[i], 0);
316 extract(text, WC->chatlines[i], 1);
317 if (!strcasecmp(name, WC->wc_username)) {
318 wprintf("<FONT COLOR=\"#004400\">");
320 else if (!strcmp(name, ":")) {
321 wprintf("<FONT COLOR=\"#440000\">");
324 wprintf("<FONT COLOR=\"#000044\">");
327 wprintf(": </FONT>");
334 close(WC->chat_sock);
335 WC->chat_sock = (-1);
336 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"top.location.replace('/do_welcome');\">\n");
339 wprintf("</BODY></HTML>\n");
345 * sending side of the chat window
347 void chat_send(void) {
352 wprintf("Content-type: text/html\n");
355 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
358 if (bstr("send_this") != NULL) {
359 strcpy(send_this, bstr("send_this"));
362 strcpy(send_this, "");
365 if (bstr("sendbutton") != NULL) {
367 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
368 strcpy(send_this, "/quit");
371 if (setup_chat_socket() != 0) {
372 wprintf("Error setting up chat socket</BODY></HTML>\n");
377 /* Temporarily swap the serv and chat sockets during chat talk */
379 WC->serv_sock = WC->chat_sock;
382 serv_puts(send_this);
384 /* Unswap the sockets. */
386 WC->serv_sock = WC->chat_sock;
392 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
393 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
394 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
395 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
396 wprintf("</FORM>\n");
398 wprintf("</BODY></HTML>\n");