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, 2, 0, 0, 0, 0);
40 wprintf("<div id=\"banner\">\n"
41 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
42 "<SPAN CLASS=\"titlebar\">Send instant message</SPAN>"
43 "</TD></TR></TABLE>\n"
44 "</div>\n<div id=\"content\">\n"
47 wprintf("<center><table border=0 width=99%% bgcolor=\"#ffffff\"><tr><td>\n");
49 wprintf("Send an instant message to: ");
53 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
55 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
57 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
61 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
62 escputs(bstr("closewin"));
65 wprintf("Enter message text:<br />");
67 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
68 "WIDTH=40></TEXTAREA>\n");
70 wprintf("</TD></TR></TABLE><br />\n");
72 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
73 wprintf("<br /><A HREF=\"javascript:window.close();\"Cancel</A>\n");
75 wprintf("</FORM></CENTER>\n");
76 wprintf("</td></tr></table></center>\n");
90 output_headers(1, 1, 2, 0, 0, 0, 0);
91 wprintf("<div id=\"banner\">\n"
92 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
93 "<SPAN CLASS=\"titlebar\">Add or edit an event</SPAN>"
94 "</TD></TR></TABLE>\n"
95 "</div>\n<div id=\"content\">\n"
98 strcpy(recp, bstr("recp"));
99 strcpy(sc, bstr("sc"));
100 strcpy(closewin, bstr("closewin"));
102 if (strcmp(sc, "Send message")) {
103 wprintf("<EM>Message was not sent.</EM><br />\n");
105 serv_printf("SEXP %s|-", recp);
109 text_to_server(bstr("msgtext"), 0);
111 wprintf("<EM>Message has been sent to ");
113 wprintf(".</EM><br />\n");
116 wprintf("<EM>%s</EM><br />\n", &buf[4]);
120 if (!strcasecmp(closewin, "yes")) {
121 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
122 "[ close window ]</A></CENTER>\n");
137 /* First, check to make sure we're still allowed in this room. */
138 serv_printf("GOTO %s", WC->wc_roomname);
141 smart_goto("_BASEROOM_");
145 /* If the chat socket is still open from a previous chat,
146 * close it -- because it might be stale or in the wrong room.
148 if (WC->chat_sock < 0) {
149 close(WC->chat_sock);
150 WC->chat_sock = (-1);
153 /* WebCit Chat works by having transmit, receive, and refresh
154 * frames. Load the frameset.
156 do_template("chatframeset");
164 void page_popup(void)
169 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
171 extract(pagefrom, &buf[4], 3);
173 wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
174 wprintf("<span class=\"titlebar\">Instant message from ");
176 wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
178 wprintf("</font></td></tr>"
179 "<tr><td><div align=center><font color=\"#FFFFFF\">"
180 "<a href=\"javascript:hide_page_popup()\">[ close window ]</a>"
186 WC->HaveInstantMessages = 0;
192 * Support function for chat -- make sure the chat socket is connected
195 int setup_chat_socket(void) {
198 int good_chatmode = 0;
200 if (WC->chat_sock < 0) {
202 if (!strcasecmp(ctdlhost, "uds")) {
203 /* unix domain socket */
204 sprintf(buf, "%s/citadel.socket", ctdlport);
205 WC->chat_sock = uds_connectsock(buf);
209 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
212 if (WC->chat_sock < 0) {
216 /* Temporarily swap the serv and chat sockets during chat talk */
218 WC->serv_sock = WC->chat_sock;
223 serv_printf("USER %s", WC->wc_username);
226 serv_printf("PASS %s", WC->wc_password);
229 serv_printf("GOTO %s", WC->wc_roomname);
242 /* Unswap the sockets. */
244 WC->serv_sock = WC->chat_sock;
247 if (!good_chatmode) close(WC->serv_sock);
256 * Receiving side of the chat window. This is implemented in a
257 * tiny hidden IFRAME that just does JavaScript writes to
258 * other frames whenever it refreshes and finds new data.
260 void chat_recv(void) {
264 int end_chat_now = 0;
268 char *output_data = NULL;
270 output_headers(0, 0, 0, 0, 0, 0, 0);
272 wprintf("Content-type: text/html\n");
276 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
279 "<body bgcolor=\"#FFFFFF\">\n"
282 if (setup_chat_socket() != 0) {
283 wprintf("Error setting up chat socket</BODY></HTML>\n");
289 * See if there is any chat data waiting.
291 output_data = strdup("");
294 pf.fd = WC->chat_sock;
297 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
300 /* Temporarily swap the serv and chat sockets during chat talk */
302 WC->serv_sock = WC->chat_sock;
307 if (!strcmp(buf, "000")) {
308 strcpy(buf, ":|exiting chat mode");
312 /* Unswap the sockets. */
314 WC->serv_sock = WC->chat_sock;
317 /* Append our output data */
318 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
319 strcat(output_data, buf);
320 strcat(output_data, "\n");
323 } while ( (got_data) && (!end_chat_now) );
326 close(WC->chat_sock);
327 WC->chat_sock = (-1);
328 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
331 if (strlen(output_data) > 0) {
333 if (output_data[strlen(output_data)-1] == '\n') {
334 output_data[strlen(output_data)-1] = 0;
337 /* Output our fun to the other frame. */
338 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
342 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
343 extract_token(buf, output_data, i, '\n');
344 extract_token(cl_user, buf, 0, '|');
345 extract_token(cl_text, buf, 1, '|');
347 if (strcasecmp(cl_text, "NOOP")) {
349 wprintf("parent.chat_transcript.document.write('");
351 if (strcasecmp(cl_user, WC->last_chat_user)) {
352 wprintf("<TABLE border=0 WIDTH=100%% "
353 "CELLSPACING=1 CELLPADDING=0 "
354 "BGCOLOR="#FFFFFF">"
355 "<TR><TD></TR></TD></TABLE>"
360 wprintf("<TABLE border=0 WIDTH=100%% "
361 "CELLSPACING=0 CELLPADDING=0 "
362 "BGCOLOR="#EEEEEE">");
366 if (!strcasecmp(cl_user, ":")) {
370 if (strcasecmp(cl_user, WC->last_chat_user)) {
373 if (!strcasecmp(cl_user, WC->wc_username)) {
374 wprintf("<FONT COLOR="#FF0000">");
377 wprintf("<FONT COLOR="#0000FF">");
381 wprintf("</FONT>: </B>");
384 wprintf(" ");
387 if (!strcasecmp(cl_user, ":")) {
391 wprintf("</TD></TR></TABLE>");
394 strcpy(WC->last_chat_user, cl_user);
398 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
403 wprintf("</BODY></HTML>\n");
409 * sending side of the chat window
411 void chat_send(void) {
416 output_headers(0, 0, 0, 0, 0, 0, 0);
417 wprintf("Content-type: text/html\n");
420 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
423 if (bstr("send_this") != NULL) {
424 strcpy(send_this, bstr("send_this"));
427 strcpy(send_this, "");
430 if (bstr("sendbutton") != NULL) {
432 if (!strcasecmp(bstr("sendbutton"), "Help")) {
433 strcpy(send_this, "/help");
436 if (!strcasecmp(bstr("sendbutton"), "List Users")) {
437 strcpy(send_this, "/who");
440 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
441 strcpy(send_this, "/quit");
444 if (setup_chat_socket() != 0) {
445 wprintf("Error setting up chat socket</BODY></HTML>\n");
450 /* Temporarily swap the serv and chat sockets during chat talk */
452 WC->serv_sock = WC->chat_sock;
455 while (strlen(send_this) > 0) {
456 if (strlen(send_this) < 67) {
457 serv_puts(send_this);
458 strcpy(send_this, "");
461 for (i=55; i<67; ++i) {
462 if (send_this[i] == ' ') break;
464 strncpy(buf, send_this, i);
466 strcpy(send_this, &send_this[i]);
471 /* Unswap the sockets. */
473 WC->serv_sock = WC->chat_sock;
478 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
479 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
480 "NAME=\"send_this\">\n", SIZ-10);
482 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
483 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
484 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"List Users\">\n");
485 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
486 wprintf("</FORM>\n");
488 wprintf("</BODY></HTML>\n");