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"));
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");
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 /* Ok, we're good. Here we go. */
141 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
142 "<SPAN CLASS=\"titlebar\">"
143 "<IMG SRC=\"/static/chat-icon.gif\" WIDTH=16 HEIGHT=16 ALIGN=MIDDLE>"
145 escputs(WC->wc_roomname);
146 wprintf(": real-time chat</SPAN>\n"
147 "</TD></TR></TABLE>\n"
149 "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"about:blank\" "
150 "NAME=\"chat_transcript\">\n"
151 "<!-- Alternate content for non-supporting browsers -->\n"
152 "If you are seeing this message, your browser does not contain\n"
153 "the IFRAME support required for the chat window. Please upgrade\n"
154 "to a supported browser, such as\n"
155 "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
158 "<IFRAME WIDTH=100%% HEIGHT=1 SRC=\"/chat_recv\" "
159 "NAME=\"chat_recv\">\n"
164 "<IFRAME WIDTH=100%% HEIGHT=60 SRC=\"/chat_send\" "
165 "NAME=\"chat_send\">\n"
175 void page_popup(void)
180 /* suppress express message check, do headers but no frames */
181 output_headers(0x08 | 0x03);
183 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
185 extract(pagefrom, &buf[4], 3);
187 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
188 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
190 wprintf("</SPAN></TD></TR></TABLE>\n");
196 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
197 urlescputs(pagefrom);
198 wprintf("\">[ reply ]</A> \n");
200 wprintf("<A HREF=\"javascript:window.close();\">"
201 "[ close window ]</A></B>\n"
205 WC->HaveExpressMessages = 0;
211 * Support function for chat -- make sure the chat socket is connected
214 int setup_chat_socket(void) {
217 int good_chatmode = 0;
219 if (WC->chat_sock < 0) {
221 if (!strcasecmp(ctdlhost, "uds")) {
222 /* unix domain socket */
223 sprintf(buf, "%s/citadel.socket", ctdlport);
224 WC->chat_sock = uds_connectsock(buf);
228 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
231 if (WC->chat_sock < 0) {
235 /* Temporarily swap the serv and chat sockets during chat talk */
237 WC->serv_sock = WC->chat_sock;
242 serv_printf("USER %s", WC->wc_username);
245 serv_printf("PASS %s", WC->wc_password);
248 serv_printf("GOTO %s", WC->wc_roomname);
261 /* Unswap the sockets. */
263 WC->serv_sock = WC->chat_sock;
266 if (!good_chatmode) close(WC->serv_sock);
275 * Receiving side of the chat window. This is implemented in a
276 * tiny hidden IFRAME that just does JavaScript writes to
277 * other frames whenever it refreshes and finds new data.
279 void chat_recv(void) {
283 int end_chat_now = 0;
287 char *output_data = NULL;
291 wprintf("Content-type: text/html\n");
295 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3\">\n"
298 "<BODY BGCOLOR=\"#FFFFFF\">\n"
301 if (setup_chat_socket() != 0) {
302 wprintf("Error setting up chat socket</BODY></HTML>\n");
308 * See if there is any chat data waiting.
310 output_data = strdup("");
313 pf.fd = WC->chat_sock;
316 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
319 /* Temporarily swap the serv and chat sockets during chat talk */
321 WC->serv_sock = WC->chat_sock;
326 if (!strcmp(buf, "000")) {
327 strcpy(buf, ":|exiting chat mode");
331 /* Unswap the sockets. */
333 WC->serv_sock = WC->chat_sock;
336 /* Append our output data */
337 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
338 strcat(output_data, buf);
339 strcat(output_data, "\n");
342 } while ( (got_data) && (!end_chat_now) );
345 close(WC->chat_sock);
346 WC->chat_sock = (-1);
347 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.location.replace('/display_main_menu');\">\n");
350 if (strlen(output_data) > 0) {
352 if (output_data[strlen(output_data)-1] == '\n') {
353 output_data[strlen(output_data)-1] = 0;
356 /* Output our fun to the other frame. */
357 wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
361 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
362 extract_token(buf, output_data, i, '\n');
363 extract_token(cl_user, buf, 0, '|');
364 extract_token(cl_text, buf, 1, '|');
366 wprintf("parent.chat_transcript.document.write('");
367 wprintf("<FONT SIZE=-1><B>");
371 wprintf("</FONT><BR>");
375 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
380 wprintf("</BODY></HTML>\n");
386 * sending side of the chat window
388 void chat_send(void) {
393 wprintf("Content-type: text/html\n");
396 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
399 if (bstr("send_this") != NULL) {
400 strcpy(send_this, bstr("send_this"));
403 strcpy(send_this, "");
406 if (bstr("sendbutton") != NULL) {
408 if (!strcasecmp(bstr("sendbutton"), "Help")) {
409 strcpy(send_this, "/help");
412 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
413 strcpy(send_this, "/quit");
416 if (setup_chat_socket() != 0) {
417 wprintf("Error setting up chat socket</BODY></HTML>\n");
422 /* Temporarily swap the serv and chat sockets during chat talk */
424 WC->serv_sock = WC->chat_sock;
427 serv_puts(send_this);
429 /* Unswap the sockets. */
431 WC->serv_sock = WC->chat_sock;
436 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
437 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
438 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
439 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
440 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
441 wprintf("</FORM>\n");
443 wprintf("</BODY></HTML>\n");