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"));
39 output_headers(1, 1, 0, 0, 0, 0, 0);
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");
81 output_headers(1, 1, 0, 0, 0, 0, 0);
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");
122 /* First, check to make sure we're still allowed in this room. */
123 serv_printf("GOTO %s", WC->wc_roomname);
126 smart_goto("_BASEROOM_");
130 /* If the chat socket is still open from a previous chat,
131 * close it -- because it might be stale or in the wrong room.
133 if (WC->chat_sock < 0) {
134 close(WC->chat_sock);
135 WC->chat_sock = (-1);
138 /* WebCit Chat works by having transmit, receive, and refresh
139 * frames. Load the frameset.
141 do_template("chatframeset");
149 void page_popup(void)
154 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
156 extract(pagefrom, &buf[4], 3);
158 wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
159 wprintf("<span class=\"titlebar\">Instant message from ");
161 wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
163 wprintf("</font></td></tr></table>\n");
166 WC->HaveExpressMessages = 0;
172 * Support function for chat -- make sure the chat socket is connected
175 int setup_chat_socket(void) {
178 int good_chatmode = 0;
180 if (WC->chat_sock < 0) {
182 if (!strcasecmp(ctdlhost, "uds")) {
183 /* unix domain socket */
184 sprintf(buf, "%s/citadel.socket", ctdlport);
185 WC->chat_sock = uds_connectsock(buf);
189 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
192 if (WC->chat_sock < 0) {
196 /* Temporarily swap the serv and chat sockets during chat talk */
198 WC->serv_sock = WC->chat_sock;
203 serv_printf("USER %s", WC->wc_username);
206 serv_printf("PASS %s", WC->wc_password);
209 serv_printf("GOTO %s", WC->wc_roomname);
222 /* Unswap the sockets. */
224 WC->serv_sock = WC->chat_sock;
227 if (!good_chatmode) close(WC->serv_sock);
236 * Receiving side of the chat window. This is implemented in a
237 * tiny hidden IFRAME that just does JavaScript writes to
238 * other frames whenever it refreshes and finds new data.
240 void chat_recv(void) {
244 int end_chat_now = 0;
248 char *output_data = NULL;
250 output_headers(0, 0, 0, 0, 0, 0, 0);
252 wprintf("Content-type: text/html\n");
256 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
259 "<body bgcolor=\"#FFFFFF\">\n"
262 if (setup_chat_socket() != 0) {
263 wprintf("Error setting up chat socket</BODY></HTML>\n");
269 * See if there is any chat data waiting.
271 output_data = strdup("");
274 pf.fd = WC->chat_sock;
277 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
280 /* Temporarily swap the serv and chat sockets during chat talk */
282 WC->serv_sock = WC->chat_sock;
287 if (!strcmp(buf, "000")) {
288 strcpy(buf, ":|exiting chat mode");
292 /* Unswap the sockets. */
294 WC->serv_sock = WC->chat_sock;
297 /* Append our output data */
298 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
299 strcat(output_data, buf);
300 strcat(output_data, "\n");
303 } while ( (got_data) && (!end_chat_now) );
306 close(WC->chat_sock);
307 WC->chat_sock = (-1);
308 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
311 if (strlen(output_data) > 0) {
313 if (output_data[strlen(output_data)-1] == '\n') {
314 output_data[strlen(output_data)-1] = 0;
317 /* Output our fun to the other frame. */
318 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
322 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
323 extract_token(buf, output_data, i, '\n');
324 extract_token(cl_user, buf, 0, '|');
325 extract_token(cl_text, buf, 1, '|');
327 if (strcasecmp(cl_text, "NOOP")) {
329 wprintf("parent.chat_transcript.document.write('");
331 if (strcasecmp(cl_user, WC->last_chat_user)) {
332 wprintf("<TABLE border=0 WIDTH=100%% "
333 "CELLSPACING=1 CELLPADDING=0 "
334 "BGCOLOR="#FFFFFF">"
335 "<TR><TD></TR></TD></TABLE>"
340 wprintf("<TABLE border=0 WIDTH=100%% "
341 "CELLSPACING=0 CELLPADDING=0 "
342 "BGCOLOR="#EEEEEE">");
346 if (!strcasecmp(cl_user, ":")) {
350 if (strcasecmp(cl_user, WC->last_chat_user)) {
353 if (!strcasecmp(cl_user, WC->wc_username)) {
354 wprintf("<FONT COLOR="#FF0000">");
357 wprintf("<FONT COLOR="#0000FF">");
361 wprintf("</FONT>: </B>");
364 wprintf(" ");
367 if (!strcasecmp(cl_user, ":")) {
371 wprintf("</TD></TR></TABLE>");
374 strcpy(WC->last_chat_user, cl_user);
378 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
383 wprintf("</BODY></HTML>\n");
389 * sending side of the chat window
391 void chat_send(void) {
396 output_headers(0, 0, 0, 0, 0, 0, 0);
397 wprintf("Content-type: text/html\n");
400 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
403 if (bstr("send_this") != NULL) {
404 strcpy(send_this, bstr("send_this"));
407 strcpy(send_this, "");
410 if (bstr("sendbutton") != NULL) {
412 if (!strcasecmp(bstr("sendbutton"), "Help")) {
413 strcpy(send_this, "/help");
416 if (!strcasecmp(bstr("sendbutton"), "List Users")) {
417 strcpy(send_this, "/who");
420 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
421 strcpy(send_this, "/quit");
424 if (setup_chat_socket() != 0) {
425 wprintf("Error setting up chat socket</BODY></HTML>\n");
430 /* Temporarily swap the serv and chat sockets during chat talk */
432 WC->serv_sock = WC->chat_sock;
435 while (strlen(send_this) > 0) {
436 if (strlen(send_this) < 67) {
437 serv_puts(send_this);
438 strcpy(send_this, "");
441 for (i=55; i<67; ++i) {
442 if (send_this[i] == ' ') break;
444 strncpy(buf, send_this, i);
446 strcpy(send_this, &send_this[i]);
451 /* Unswap the sockets. */
453 WC->serv_sock = WC->chat_sock;
458 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
459 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
460 "NAME=\"send_this\">\n", SIZ-10);
462 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
463 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
464 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"List Users\">\n");
465 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
466 wprintf("</FORM>\n");
468 wprintf("</BODY></HTML>\n");