4 * Functions which implement the chat and paging facilities.
10 * display the form for paging (x-messaging) another user
12 void display_page(void)
16 strcpy(recp, bstr("recp"));
18 output_headers(1, 1, 2, 0, 0, 0, 0);
19 wprintf("<div id=\"banner\">\n"
20 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
21 "<SPAN CLASS=\"titlebar\">Send instant message</SPAN>"
22 "</TD></TR></TABLE>\n"
23 "</div>\n<div id=\"content\">\n"
26 wprintf("<div id=\"fix_scrollbar_bug\">"
27 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
29 wprintf("Send an instant message to: ");
33 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
35 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
37 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
41 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
42 escputs(bstr("closewin"));
45 wprintf("Enter message text:<br />");
47 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
48 "WIDTH=40></TEXTAREA>\n");
50 wprintf("</TD></TR></TABLE><br />\n");
52 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
53 wprintf("<br /><A HREF=\"javascript:window.close();\"Cancel</A>\n");
55 wprintf("</FORM></CENTER>\n");
56 wprintf("</td></tr></table></div>\n");
70 output_headers(1, 1, 2, 0, 0, 0, 0);
71 wprintf("<div id=\"banner\">\n"
72 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
73 "<SPAN CLASS=\"titlebar\">Add or edit an event</SPAN>"
74 "</TD></TR></TABLE>\n"
75 "</div>\n<div id=\"content\">\n"
78 strcpy(recp, bstr("recp"));
79 strcpy(sc, bstr("sc"));
80 strcpy(closewin, bstr("closewin"));
82 if (strcmp(sc, "Send message")) {
83 wprintf("<EM>Message was not sent.</EM><br />\n");
85 serv_printf("SEXP %s|-", recp);
86 serv_getln(buf, sizeof buf);
89 text_to_server(bstr("msgtext"), 0);
91 wprintf("<EM>Message has been sent to ");
93 wprintf(".</EM><br />\n");
96 wprintf("<EM>%s</EM><br />\n", &buf[4]);
100 if (!strcasecmp(closewin, "yes")) {
101 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
102 "[ close window ]</A></CENTER>\n");
117 /* First, check to make sure we're still allowed in this room. */
118 serv_printf("GOTO %s", WC->wc_roomname);
119 serv_getln(buf, sizeof buf);
121 smart_goto("_BASEROOM_");
125 /* If the chat socket is still open from a previous chat,
126 * close it -- because it might be stale or in the wrong room.
128 if (WC->chat_sock < 0) {
129 close(WC->chat_sock);
130 WC->chat_sock = (-1);
133 /* WebCit Chat works by having transmit, receive, and refresh
134 * frames. Load the frameset.
136 do_template("chatframeset");
144 void page_popup(void)
149 while (serv_puts("GEXP"), serv_getln(buf, sizeof buf), buf[0]=='1') {
151 extract_token(pagefrom, &buf[4], 3, '|', sizeof pagefrom);
153 wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
154 wprintf("<span class=\"titlebar\">Instant message from ");
156 wprintf("</span></td></tr><tr><td><font color=\"#FFFFFF\">");
158 wprintf("</font></td></tr>"
159 "<tr><td><div align=center><font color=\"#FFFFFF\">"
160 "<a href=\"javascript:hide_page_popup()\">[ close window ]</a>"
166 WC->HaveInstantMessages = 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;
201 serv_getln(buf, sizeof buf);
203 serv_printf("USER %s", WC->wc_username);
204 serv_getln(buf, sizeof buf);
206 serv_printf("PASS %s", WC->wc_password);
207 serv_getln(buf, sizeof buf);
209 serv_printf("GOTO %s", WC->wc_roomname);
210 serv_getln(buf, sizeof buf);
213 serv_getln(buf, sizeof buf);
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; charset=utf-8\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;
285 serv_getln(buf, sizeof buf);
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', sizeof buf);
324 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
325 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
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; charset=utf-8\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");