11 #include <sys/socket.h>
15 #include <netinet/in.h>
27 * display the form for paging (x-messaging) another user
29 void display_page(void)
33 strcpy(recp, bstr("recp"));
37 svprintf("BOXTITLE", WCS_STRING, "Page: %s", recp);
38 do_template("beginbox");
40 wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
42 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
44 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
48 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
49 escputs(bstr("closewin"));
52 wprintf("Enter message text:<BR>");
54 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
55 "WIDTH=40></TEXTAREA>\n");
57 wprintf("</TD></TR></TABLE><BR>\n");
59 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
60 wprintf("<BR><A HREF=\"javascript:window.close();\"Cancel</A>\n");
62 wprintf("</FORM></CENTER>\n");
63 do_template("endbox");
79 strcpy(recp, bstr("recp"));
80 strcpy(sc, bstr("sc"));
81 strcpy(closewin, bstr("closewin"));
83 if (strcmp(sc, "Send message")) {
84 wprintf("<EM>Message was not sent.</EM><BR>\n");
86 serv_printf("SEXP %s|-", recp);
90 text_to_server(bstr("msgtext"), 0);
92 wprintf("<EM>Message has been sent to ");
94 wprintf(".</EM><BR>\n");
97 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
101 if (!strcasecmp(closewin, "yes")) {
102 wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
103 "[ close window ]</A></CENTER>\n");
119 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
120 "<SPAN CLASS=\"titlebar\">Real-time chat</SPAN>\n"
121 "</TD></TR></TABLE>\n"
122 "<IFRAME WIDTH=100%% HEIGHT=200 SRC=\"/chat_recv\" "
123 "NAME=\"chat_recv\">\n"
124 "<!-- Alternate content for non-supporting browsers -->\n"
125 "If you are seeing this message, your browser does not contain\n"
126 "the IFRAME support required for the chat window. Please upgrade\n"
127 "to a supported browser, such as\n"
128 "<A HREF=\"http://www.mozilla.org\">Mozilla</A>.\n"
131 "<IFRAME WIDTH=100%% HEIGHT=50 SRC=\"/chat_send\" "
132 "NAME=\"chat_send\">\n"
142 void page_popup(void)
147 /* suppress express message check, do headers but no frames */
148 output_headers(0x08 | 0x03);
150 while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
152 extract(pagefrom, &buf[4], 3);
154 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
155 wprintf("<SPAN CLASS=\"titlebar\">Instant message from ");
157 wprintf("</SPAN></TD></TR></TABLE>\n");
163 wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
164 urlescputs(pagefrom);
165 wprintf("\">[ reply ]</A> \n");
167 wprintf("<A HREF=\"javascript:window.close();\">"
168 "[ close window ]</A></B>\n"
172 WC->HaveExpressMessages = 0;
178 * Support function for chat -- make sure the chat socket is connected
181 int setup_chat_socket(void) {
184 int good_chatmode = 0;
186 if (WC->chat_sock < 0) {
188 for (i=0; i<CHATLINES; ++i) {
189 strcpy(WC->chatlines[i], "");
192 if (!strcasecmp(ctdlhost, "uds")) {
193 /* unix domain socket */
194 sprintf(buf, "%s/citadel.socket", ctdlport);
195 WC->chat_sock = uds_connectsock(buf);
199 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
202 if (WC->chat_sock < 0) {
206 /* Temporarily swap the serv and chat sockets during chat talk */
208 WC->serv_sock = WC->chat_sock;
213 serv_printf("USER %s", WC->wc_username);
216 serv_printf("PASS %s", WC->wc_password);
219 serv_printf("GOTO %s", WC->wc_roomname);
232 /* Unswap the sockets. */
234 WC->serv_sock = WC->chat_sock;
237 if (!good_chatmode) close(WC->serv_sock);
246 * receiving side of the chat window
248 void chat_recv(void) {
254 int end_chat_now = 0;
258 wprintf("Content-type: text/html\n");
262 "<META HTTP-EQUIV=\"refresh\" CONTENT=\"3\">\n"
267 if (setup_chat_socket() != 0) {
268 wprintf("Error setting up chat socket</BODY></HTML>\n");
274 * See if there is any chat data waiting.
278 pf.fd = WC->chat_sock;
281 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
284 for (i=0; i<CHATLINES-1; ++i) {
285 strcpy(WC->chatlines[i], WC->chatlines[i+1]);
288 /* Temporarily swap the serv and chat sockets during chat talk */
290 WC->serv_sock = WC->chat_sock;
293 serv_gets(WC->chatlines[CHATLINES-1]);
294 if (!strcmp(WC->chatlines[CHATLINES-1], "000")) {
296 strcpy(WC->chatlines[CHATLINES-1], ":|exiting chat mode");
299 /* Unswap the sockets. */
301 WC->serv_sock = WC->chat_sock;
304 } while ( (got_data) && (!end_chat_now) );
307 * Display appropriately.
309 for (i=0; i<CHATLINES; ++i) {
310 if (strlen(WC->chatlines[i]) > 0) {
311 extract(name, WC->chatlines[i], 0);
312 extract(text, WC->chatlines[i], 1);
313 if (!strcasecmp(name, WC->wc_username)) {
314 wprintf("<FONT COLOR=\"#00FF00\">");
316 else if (!strcmp(name, ":")) {
317 wprintf("<FONT COLOR=\"#FF0000\">");
320 wprintf("<FONT COLOR=\"#0000FF\">");
323 wprintf(": </FONT>");
330 close(WC->chat_sock);
331 WC->chat_sock = (-1);
332 wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"top.location.replace('/do_welcome');\">\n");
335 wprintf("</BODY></HTML>\n");
341 * sending side of the chat window
343 void chat_send(void) {
348 wprintf("Content-type: text/html\n");
351 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
354 if (bstr("send_this") != NULL) {
355 strcpy(send_this, bstr("send_this"));
358 strcpy(send_this, "");
361 if (bstr("sendbutton") != NULL) {
363 if (!strcasecmp(bstr("sendbutton"), "Exit")) {
364 strcpy(send_this, "/quit");
367 if (setup_chat_socket() != 0) {
368 wprintf("Error setting up chat socket</BODY></HTML>\n");
373 /* Temporarily swap the serv and chat sockets during chat talk */
375 WC->serv_sock = WC->chat_sock;
378 serv_puts(send_this);
380 /* Unswap the sockets. */
382 WC->serv_sock = WC->chat_sock;
388 wprintf("<FORM METHOD=\"POST\" ACTION=\"/chat_send\" NAME=\"chatsendform\">\n");
389 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"80\" NAME=\"send_this\">\n");
390 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Send\">\n");
391 wprintf("<INPUT TYPE=\"submit\" NAME=\"sendbutton\" VALUE=\"Exit\">\n");
392 wprintf("</FORM>\n");
394 wprintf("</BODY></HTML>\n");