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 style=\"margin-right:1px\">"
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 output_headers(0, 0, 0, 0, 0, 0, 0);
273 wprintf("Content-type: text/html\n");
277 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
280 "<body bgcolor=\"#FFFFFF\">\n"
283 if (setup_chat_socket() != 0) {
284 wprintf("Error setting up chat socket</BODY></HTML>\n");
290 * See if there is any chat data waiting.
292 output_data = strdup("");
295 pf.fd = WC->chat_sock;
298 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
301 /* Temporarily swap the serv and chat sockets during chat talk */
303 WC->serv_sock = WC->chat_sock;
308 if (!strcmp(buf, "000")) {
309 strcpy(buf, ":|exiting chat mode");
313 /* Unswap the sockets. */
315 WC->serv_sock = WC->chat_sock;
318 /* Append our output data */
319 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
320 strcat(output_data, buf);
321 strcat(output_data, "\n");
324 } while ( (got_data) && (!end_chat_now) );
327 close(WC->chat_sock);
328 WC->chat_sock = (-1);
329 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
332 if (strlen(output_data) > 0) {
334 if (output_data[strlen(output_data)-1] == '\n') {
335 output_data[strlen(output_data)-1] = 0;
338 /* Output our fun to the other frame. */
339 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
343 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
344 extract_token(buf, output_data, i, '\n');
345 extract_token(cl_user, buf, 0, '|');
346 extract_token(cl_text, buf, 1, '|');
348 if (strcasecmp(cl_text, "NOOP")) {
350 wprintf("parent.chat_transcript.document.write('");
352 if (strcasecmp(cl_user, WC->last_chat_user)) {
353 wprintf("<TABLE border=0 WIDTH=100%% "
354 "CELLSPACING=1 CELLPADDING=0 "
355 "BGCOLOR="#FFFFFF">"
356 "<TR><TD></TR></TD></TABLE>"
361 wprintf("<TABLE border=0 WIDTH=100%% "
362 "CELLSPACING=0 CELLPADDING=0 "
363 "BGCOLOR="#EEEEEE">");
367 if (!strcasecmp(cl_user, ":")) {
371 if (strcasecmp(cl_user, WC->last_chat_user)) {
374 if (!strcasecmp(cl_user, WC->wc_username)) {
375 wprintf("<FONT COLOR="#FF0000">");
378 wprintf("<FONT COLOR="#0000FF">");
382 wprintf("</FONT>: </B>");
385 wprintf(" ");
388 if (!strcasecmp(cl_user, ":")) {
392 wprintf("</TD></TR></TABLE>");
395 strcpy(WC->last_chat_user, cl_user);
399 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
404 wprintf("</BODY></HTML>\n");
410 * sending side of the chat window
412 void chat_send(void) {
417 output_headers(0, 0, 0, 0, 0, 0, 0);
418 wprintf("Content-type: text/html\n");
421 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
424 if (bstr("send_this") != NULL) {
425 strcpy(send_this, bstr("send_this"));
428 strcpy(send_this, "");
431 if (bstr("sendbutton") != NULL) {
433 if (!strcasecmp(bstr("sendbutton"), "Help")) {
434 strcpy(send_this, "/help");
437 if (!strcasecmp(bstr("sendbutton"), "List Users")) {
438 strcpy(send_this, "/who");
441 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
442 strcpy(send_this, "/quit");
445 if (setup_chat_socket() != 0) {
446 wprintf("Error setting up chat socket</BODY></HTML>\n");
451 /* Temporarily swap the serv and chat sockets during chat talk */
453 WC->serv_sock = WC->chat_sock;
456 while (strlen(send_this) > 0) {
457 if (strlen(send_this) < 67) {
458 serv_puts(send_this);
459 strcpy(send_this, "");
462 for (i=55; i<67; ++i) {
463 if (send_this[i] == ' ') break;
465 strncpy(buf, send_this, i);
467 strcpy(send_this, &send_this[i]);
472 /* Unswap the sockets. */
474 WC->serv_sock = WC->chat_sock;
479 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
480 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
481 "NAME=\"send_this\">\n", SIZ-10);
483 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
484 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
485 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"List Users\">\n");
486 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
487 wprintf("</FORM>\n");
489 wprintf("</BODY></HTML>\n");