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");
123 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
124 "<SPAN CLASS=\"titlebar\">"
125 "<IMG SRC=\"/static/chat-icon.gif\" WIDTH=16 HEIGHT=16 ALIGN=MIDDLE>"
127 escputs(WC->wc_roomname);
128 wprintf(": real-time chat</SPAN>\n"
129 "</TD></TR></TABLE>\n"
131 "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"about:blank\" "
132 "NAME=\"chat_transcript\">\n"
133 "<!-- Alternate content for non-supporting browsers -->\n"
134 "If you are seeing this message, your browser does not contain\n"
135 "the IFRAME support required for the chat window. Please upgrade\n"
136 "to a supported browser, such as\n"
137 "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
140 "<IFRAME WIDTH=100%% HEIGHT=1 SRC=\"/chat_recv\" "
141 "NAME=\"chat_recv\">\n"
146 "<IFRAME WIDTH=100%% HEIGHT=60 SRC=\"/chat_send\" "
147 "NAME=\"chat_send\">\n"
157 void page_popup(void)
162 /* suppress express message check, do headers but no frames */
163 output_headers(0x08 | 0x03);
165 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
167 extract(pagefrom, &buf[4], 3);
169 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
170 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
172 wprintf("</SPAN></TD></TR></TABLE>\n");
178 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
179 urlescputs(pagefrom);
180 wprintf("\">[ reply ]</A> \n");
182 wprintf("<A HREF=\"javascript:window.close();\">"
183 "[ close window ]</A></B>\n"
187 WC->HaveExpressMessages = 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;
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.location.replace('/display_main_menu');\">\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 wprintf("parent.chat_transcript.document.write('");
349 wprintf("<FONT SIZE=-1><B>");
353 wprintf("</FONT><BR>");
357 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
362 wprintf("</BODY></HTML>\n");
368 * sending side of the chat window
370 void chat_send(void) {
375 wprintf("Content-type: text/html\n");
378 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
381 if (bstr("send_this") != NULL) {
382 strcpy(send_this, bstr("send_this"));
385 strcpy(send_this, "");
388 if (bstr("sendbutton") != NULL) {
390 if (!strcasecmp(bstr("sendbutton"), "Help")) {
391 strcpy(send_this, "/help");
394 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
395 strcpy(send_this, "/quit");
398 if (setup_chat_socket() != 0) {
399 wprintf("Error setting up chat socket</BODY></HTML>\n");
404 /* Temporarily swap the serv and chat sockets during chat talk */
406 WC->serv_sock = WC->chat_sock;
409 serv_puts(send_this);
411 /* Unswap the sockets. */
413 WC->serv_sock = WC->chat_sock;
418 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
419 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
420 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
421 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Help\">\n");
422 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
423 wprintf("</FORM>\n");
425 wprintf("</BODY></HTML>\n");