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("<div id=\"fix_scrollbar_bug\">"
48 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
50 wprintf("Send an instant message to: ");
54 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
56 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
58 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
62 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
63 escputs(bstr("closewin"));
66 wprintf("Enter message text:<br />");
68 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
69 "WIDTH=40></TEXTAREA>\n");
71 wprintf("</TD></TR></TABLE><br />\n");
73 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
74 wprintf("<br /><A HREF=\"javascript:window.close();\"Cancel</A>\n");
76 wprintf("</FORM></CENTER>\n");
77 wprintf("</td></tr></table></div>\n");
91 output_headers(1, 1, 2, 0, 0, 0, 0);
92 wprintf("<div id=\"banner\">\n"
93 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
94 "<SPAN CLASS=\"titlebar\">Add or edit an event</SPAN>"
95 "</TD></TR></TABLE>\n"
96 "</div>\n<div id=\"content\">\n"
99 strcpy(recp, bstr("recp"));
100 strcpy(sc, bstr("sc"));
101 strcpy(closewin, bstr("closewin"));
103 if (strcmp(sc, "Send message")) {
104 wprintf("<EM>Message was not sent.</EM><br />\n");
106 serv_printf("SEXP %s|-", recp);
110 text_to_server(bstr("msgtext"), 0);
112 wprintf("<EM>Message has been sent to ");
114 wprintf(".</EM><br />\n");
117 wprintf("<EM>%s</EM><br />\n", &buf[4]);
121 if (!strcasecmp(closewin, "yes")) {
122 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
123 "[ close window ]</A></CENTER>\n");
138 /* First, check to make sure we're still allowed in this room. */
139 serv_printf("GOTO %s", WC->wc_roomname);
142 smart_goto("_BASEROOM_");
146 /* If the chat socket is still open from a previous chat,
147 * close it -- because it might be stale or in the wrong room.
149 if (WC->chat_sock < 0) {
150 close(WC->chat_sock);
151 WC->chat_sock = (-1);
154 /* WebCit Chat works by having transmit, receive, and refresh
155 * frames. Load the frameset.
157 do_template("chatframeset");
165 void page_popup(void)
170 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
172 extract(pagefrom, &buf[4], 3);
174 wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
175 wprintf("<span class=\"titlebar\">Instant message from ");
177 wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
179 wprintf("</font></td></tr>"
180 "<tr><td><div align=center><font color=\"#FFFFFF\">"
181 "<a href=\"javascript:hide_page_popup()\">[ close window ]</a>"
187 WC->HaveInstantMessages = 0;
193 * Support function for chat -- make sure the chat socket is connected
196 int setup_chat_socket(void) {
199 int good_chatmode = 0;
201 if (WC->chat_sock < 0) {
203 if (!strcasecmp(ctdlhost, "uds")) {
204 /* unix domain socket */
205 sprintf(buf, "%s/citadel.socket", ctdlport);
206 WC->chat_sock = uds_connectsock(buf);
210 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
213 if (WC->chat_sock < 0) {
217 /* Temporarily swap the serv and chat sockets during chat talk */
219 WC->serv_sock = WC->chat_sock;
224 serv_printf("USER %s", WC->wc_username);
227 serv_printf("PASS %s", WC->wc_password);
230 serv_printf("GOTO %s", WC->wc_roomname);
243 /* Unswap the sockets. */
245 WC->serv_sock = WC->chat_sock;
248 if (!good_chatmode) close(WC->serv_sock);
257 * Receiving side of the chat window. This is implemented in a
258 * tiny hidden IFRAME that just does JavaScript writes to
259 * other frames whenever it refreshes and finds new data.
261 void chat_recv(void) {
265 int end_chat_now = 0;
269 char *output_data = NULL;
271 lprintf(9, "chat_recv() called\n");
272 output_headers(0, 0, 0, 0, 0, 0, 0);
274 wprintf("Content-type: text/html\n");
278 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
281 "<body bgcolor=\"#FFFFFF\">\n"
284 if (setup_chat_socket() != 0) {
285 wprintf("Error setting up chat socket</BODY></HTML>\n");
291 * See if there is any chat data waiting.
293 output_data = strdup("");
296 pf.fd = WC->chat_sock;
299 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
302 /* Temporarily swap the serv and chat sockets during chat talk */
304 WC->serv_sock = WC->chat_sock;
309 if (!strcmp(buf, "000")) {
310 strcpy(buf, ":|exiting chat mode");
314 /* Unswap the sockets. */
316 WC->serv_sock = WC->chat_sock;
319 /* Append our output data */
320 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
321 strcat(output_data, buf);
322 strcat(output_data, "\n");
325 } while ( (got_data) && (!end_chat_now) );
328 lprintf(9, "exiting chat\n");
329 close(WC->chat_sock);
330 WC->chat_sock = (-1);
331 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
334 if (strlen(output_data) > 0) {
336 if (output_data[strlen(output_data)-1] == '\n') {
337 output_data[strlen(output_data)-1] = 0;
340 /* Output our fun to the other frame. */
341 lprintf(9, "output to other frame\n");
342 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
346 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
347 extract_token(buf, output_data, i, '\n');
348 extract_token(cl_user, buf, 0, '|');
349 extract_token(cl_text, buf, 1, '|');
351 if (strcasecmp(cl_text, "NOOP")) {
353 wprintf("parent.chat_transcript.document.write('");
355 if (strcasecmp(cl_user, WC->last_chat_user)) {
356 wprintf("<TABLE border=0 WIDTH=100%% "
357 "CELLSPACING=1 CELLPADDING=0 "
358 "BGCOLOR="#FFFFFF">"
359 "<TR><TD></TR></TD></TABLE>"
364 wprintf("<TABLE border=0 WIDTH=100%% "
365 "CELLSPACING=0 CELLPADDING=0 "
366 "BGCOLOR="#EEEEEE">");
370 if (!strcasecmp(cl_user, ":")) {
374 if (strcasecmp(cl_user, WC->last_chat_user)) {
377 if (!strcasecmp(cl_user, WC->wc_username)) {
378 wprintf("<FONT COLOR="#FF0000">");
381 wprintf("<FONT COLOR="#0000FF">");
385 wprintf("</FONT>: </B>");
388 wprintf(" ");
391 if (!strcasecmp(cl_user, ":")) {
395 wprintf("</TD></TR></TABLE>");
398 strcpy(WC->last_chat_user, cl_user);
402 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
403 lprintf(9, "done fun\n");
408 wprintf("</BODY></HTML>\n");
414 * sending side of the chat window
416 void chat_send(void) {
421 output_headers(0, 0, 0, 0, 0, 0, 0);
422 wprintf("Content-type: text/html\n");
425 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
428 if (bstr("send_this") != NULL) {
429 strcpy(send_this, bstr("send_this"));
432 strcpy(send_this, "");
435 if (bstr("sendbutton") != NULL) {
437 if (!strcasecmp(bstr("sendbutton"), "Help")) {
438 strcpy(send_this, "/help");
441 if (!strcasecmp(bstr("sendbutton"), "List Users")) {
442 strcpy(send_this, "/who");
445 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
446 strcpy(send_this, "/quit");
449 if (setup_chat_socket() != 0) {
450 wprintf("Error setting up chat socket</BODY></HTML>\n");
455 /* Temporarily swap the serv and chat sockets during chat talk */
457 WC->serv_sock = WC->chat_sock;
460 while (strlen(send_this) > 0) {
461 if (strlen(send_this) < 67) {
462 serv_puts(send_this);
463 strcpy(send_this, "");
466 for (i=55; i<67; ++i) {
467 if (send_this[i] == ' ') break;
469 strncpy(buf, send_this, i);
471 strcpy(send_this, &send_this[i]);
476 /* Unswap the sockets. */
478 WC->serv_sock = WC->chat_sock;
483 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
484 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
485 "NAME=\"send_this\">\n", SIZ-10);
487 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
488 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
489 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"List Users\">\n");
490 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
491 wprintf("</FORM>\n");
493 wprintf("</BODY></HTML>\n");