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>"
126 "Real-time chat</SPAN>\n"
127 "</TD></TR></TABLE>\n"
128 "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"/chat_recv\" "
129 "NAME=\"chat_recv\">\n"
130 "<!-- Alternate content for non-supporting browsers -->\n"
131 "If you are seeing this message, your browser does not contain\n"
132 "the IFRAME support required for the chat window. Please upgrade\n"
133 "to a supported browser, such as\n"
134 "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
137 "<IFRAME WIDTH=100%% HEIGHT=50 SRC=\"/chat_send\" "
138 "NAME=\"chat_send\">\n"
148 void page_popup(void)
153 /* suppress express message check, do headers but no frames */
154 output_headers(0x08 | 0x03);
156 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
158 extract(pagefrom, &buf[4], 3);
160 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
161 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
163 wprintf("</SPAN></TD></TR></TABLE>\n");
169 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
170 urlescputs(pagefrom);
171 wprintf("\">[ reply ]</A> \n");
173 wprintf("<A HREF=\"javascript:window.close();\">"
174 "[ close window ]</A></B>\n"
178 WC->HaveExpressMessages = 0;
184 * Support function for chat -- make sure the chat socket is connected
187 int setup_chat_socket(void) {
190 int good_chatmode = 0;
192 if (WC->chat_sock < 0) {
194 for (i=0; i<CHATLINES; ++i) {
195 strcpy(WC->chatlines[i], "");
198 if (!strcasecmp(ctdlhost, "uds")) {
199 /* unix domain socket */
200 sprintf(buf, "%s/citadel.socket", ctdlport);
201 WC->chat_sock = uds_connectsock(buf);
205 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
208 if (WC->chat_sock < 0) {
212 /* Temporarily swap the serv and chat sockets during chat talk */
214 WC->serv_sock = WC->chat_sock;
219 serv_printf("USER %s", WC->wc_username);
222 serv_printf("PASS %s", WC->wc_password);
225 serv_printf("GOTO %s", WC->wc_roomname);
239 /* Unswap the sockets. */
241 WC->serv_sock = WC->chat_sock;
244 if (!good_chatmode) close(WC->serv_sock);
253 * receiving side of the chat window
255 void chat_recv(void) {
261 int end_chat_now = 0;
265 wprintf("Content-type: text/html\n");
269 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3\">\n"
271 "<BODY BGCOLOR=\"#FFFFFF\">"
274 if (setup_chat_socket() != 0) {
275 wprintf("Error setting up chat socket</BODY></HTML>\n");
281 * See if there is any chat data waiting.
285 pf.fd = WC->chat_sock;
288 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
291 for (i=0; i<CHATLINES-1; ++i) {
292 strcpy(WC->chatlines[i], WC->chatlines[i+1]);
295 /* Temporarily swap the serv and chat sockets during chat talk */
297 WC->serv_sock = WC->chat_sock;
300 serv_gets(WC->chatlines[CHATLINES-1]);
301 if (!strcmp(WC->chatlines[CHATLINES-1], "000")) {
303 strcpy(WC->chatlines[CHATLINES-1], ":|exiting chat mode");
306 /* Unswap the sockets. */
308 WC->serv_sock = WC->chat_sock;
311 } while ( (got_data) && (!end_chat_now) );
314 * Display appropriately.
316 for (i=0; i<CHATLINES; ++i) {
317 if (strlen(WC->chatlines[i]) > 0) {
318 extract(name, WC->chatlines[i], 0);
319 extract(text, WC->chatlines[i], 1);
320 if (!strcasecmp(name, WC->wc_username)) {
321 wprintf("<FONT COLOR=\"#004400\">");
323 else if (!strcmp(name, ":")) {
324 wprintf("<FONT COLOR=\"#440000\">");
327 wprintf("<FONT COLOR=\"#000044\">");
330 wprintf(": </FONT>");
337 close(WC->chat_sock);
338 WC->chat_sock = (-1);
339 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"top.location.replace('/do_welcome');\">\n");
342 wprintf("</BODY></HTML>\n");
348 * sending side of the chat window
350 void chat_send(void) {
355 wprintf("Content-type: text/html\n");
358 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
361 if (bstr("send_this") != NULL) {
362 strcpy(send_this, bstr("send_this"));
365 strcpy(send_this, "");
368 if (bstr("sendbutton") != NULL) {
370 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
371 strcpy(send_this, "/quit");
374 if (setup_chat_socket() != 0) {
375 wprintf("Error setting up chat socket</BODY></HTML>\n");
380 /* Temporarily swap the serv and chat sockets during chat talk */
382 WC->serv_sock = WC->chat_sock;
385 serv_puts(send_this);
387 /* Unswap the sockets. */
389 WC->serv_sock = WC->chat_sock;
395 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
396 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
397 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
398 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
399 wprintf("</FORM>\n");
401 wprintf("</BODY></HTML>\n");