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 /* suppress express message check, do headers but no banner */
155 output_headers(1, 1, 0, 0, 0, 1, 0);
157 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
159 extract(pagefrom, &buf[4], 3);
161 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
162 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
164 wprintf("</SPAN></TD></TR></TABLE>\n");
170 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
171 urlescputs(pagefrom);
172 wprintf("\">[ reply ]</A> \n");
174 wprintf("<A HREF=\"javascript:window.close();\">"
175 "[ close window ]</A></B>\n"
179 WC->HaveExpressMessages = 0;
185 * Support function for chat -- make sure the chat socket is connected
188 int setup_chat_socket(void) {
191 int good_chatmode = 0;
193 if (WC->chat_sock < 0) {
195 if (!strcasecmp(ctdlhost, "uds")) {
196 /* unix domain socket */
197 sprintf(buf, "%s/citadel.socket", ctdlport);
198 WC->chat_sock = uds_connectsock(buf);
202 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
205 if (WC->chat_sock < 0) {
209 /* Temporarily swap the serv and chat sockets during chat talk */
211 WC->serv_sock = WC->chat_sock;
216 serv_printf("USER %s", WC->wc_username);
219 serv_printf("PASS %s", WC->wc_password);
222 serv_printf("GOTO %s", WC->wc_roomname);
235 /* Unswap the sockets. */
237 WC->serv_sock = WC->chat_sock;
240 if (!good_chatmode) close(WC->serv_sock);
249 * Receiving side of the chat window. This is implemented in a
250 * tiny hidden IFRAME that just does JavaScript writes to
251 * other frames whenever it refreshes and finds new data.
253 void chat_recv(void) {
257 int end_chat_now = 0;
261 char *output_data = NULL;
263 output_headers(0, 0, 0, 0, 0, 0, 0);
265 wprintf("Content-type: text/html\n");
269 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
272 "<body bgcolor=\"#FFFFFF\">\n"
275 if (setup_chat_socket() != 0) {
276 wprintf("Error setting up chat socket</BODY></HTML>\n");
282 * See if there is any chat data waiting.
284 output_data = strdup("");
287 pf.fd = WC->chat_sock;
290 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
293 /* Temporarily swap the serv and chat sockets during chat talk */
295 WC->serv_sock = WC->chat_sock;
300 if (!strcmp(buf, "000")) {
301 strcpy(buf, ":|exiting chat mode");
305 /* Unswap the sockets. */
307 WC->serv_sock = WC->chat_sock;
310 /* Append our output data */
311 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
312 strcat(output_data, buf);
313 strcat(output_data, "\n");
316 } while ( (got_data) && (!end_chat_now) );
319 close(WC->chat_sock);
320 WC->chat_sock = (-1);
321 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
324 if (strlen(output_data) > 0) {
326 if (output_data[strlen(output_data)-1] == '\n') {
327 output_data[strlen(output_data)-1] = 0;
330 /* Output our fun to the other frame. */
331 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
335 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
336 extract_token(buf, output_data, i, '\n');
337 extract_token(cl_user, buf, 0, '|');
338 extract_token(cl_text, buf, 1, '|');
340 if (strcasecmp(cl_text, "NOOP")) {
342 wprintf("parent.chat_transcript.document.write('");
344 if (strcasecmp(cl_user, WC->last_chat_user)) {
345 wprintf("<TABLE border=0 WIDTH=100%% "
346 "CELLSPACING=1 CELLPADDING=0 "
347 "BGCOLOR="#FFFFFF">"
348 "<TR><TD></TR></TD></TABLE>"
353 wprintf("<TABLE border=0 WIDTH=100%% "
354 "CELLSPACING=0 CELLPADDING=0 "
355 "BGCOLOR="#EEEEEE">");
359 if (!strcasecmp(cl_user, ":")) {
363 if (strcasecmp(cl_user, WC->last_chat_user)) {
366 if (!strcasecmp(cl_user, WC->wc_username)) {
367 wprintf("<FONT COLOR="#FF0000">");
370 wprintf("<FONT COLOR="#0000FF">");
374 wprintf("</FONT>: </B>");
377 wprintf(" ");
380 if (!strcasecmp(cl_user, ":")) {
384 wprintf("</TD></TR></TABLE>");
387 strcpy(WC->last_chat_user, cl_user);
391 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
396 wprintf("</BODY></HTML>\n");
402 * sending side of the chat window
404 void chat_send(void) {
409 output_headers(0, 0, 0, 0, 0, 0, 0);
410 wprintf("Content-type: text/html\n");
413 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
416 if (bstr("send_this") != NULL) {
417 strcpy(send_this, bstr("send_this"));
420 strcpy(send_this, "");
423 if (bstr("sendbutton") != NULL) {
425 if (!strcasecmp(bstr("sendbutton"), "Help")) {
426 strcpy(send_this, "/help");
429 if (!strcasecmp(bstr("sendbutton"), "List Users")) {
430 strcpy(send_this, "/who");
433 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
434 strcpy(send_this, "/quit");
437 if (setup_chat_socket() != 0) {
438 wprintf("Error setting up chat socket</BODY></HTML>\n");
443 /* Temporarily swap the serv and chat sockets during chat talk */
445 WC->serv_sock = WC->chat_sock;
448 while (strlen(send_this) > 0) {
449 if (strlen(send_this) < 67) {
450 serv_puts(send_this);
451 strcpy(send_this, "");
454 for (i=55; i<67; ++i) {
455 if (send_this[i] == ' ') break;
457 strncpy(buf, send_this, i);
459 strcpy(send_this, &send_this[i]);
464 /* Unswap the sockets. */
466 WC->serv_sock = WC->chat_sock;
471 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
472 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
473 "NAME=\"send_this\">\n", SIZ-10);
475 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
476 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
477 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"List Users\">\n");
478 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
479 wprintf("</FORM>\n");
481 wprintf("</BODY></HTML>\n");