5 * \defgroup PageFunc Functions which implement the chat and paging facilities.
11 * \brief display the form for paging (x-messaging) another user
13 void display_page(void)
17 strcpy(recp, bstr("recp"));
19 output_headers(1, 1, 2, 0, 0, 0);
20 wprintf("<div id=\"banner\">\n"
21 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
22 "<SPAN CLASS=\"titlebar\">");
23 wprintf(_("Send instant message"));
25 "</TD></TR></TABLE>\n"
26 "</div>\n<div id=\"content\">\n"
29 wprintf("<div class=\"fix_scrollbar_bug\">"
30 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
32 wprintf(_("Send an instant message to: "));
36 wprintf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
38 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
40 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
44 wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
45 escputs(bstr("closewin"));
48 wprintf(_("Enter message text:"));
51 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
52 "WIDTH=40></TEXTAREA>\n");
54 wprintf("</TD></TR></TABLE><br />\n");
56 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
57 wprintf("<br /><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
59 wprintf("</FORM></CENTER>\n");
60 wprintf("</td></tr></table></div>\n");
65 * \brief page another user
73 output_headers(1, 1, 2, 0, 0, 0);
74 wprintf("<div id=\"banner\">\n"
75 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
76 "<SPAN CLASS=\"titlebar\">");
77 wprintf(_("Add or edit an event"));
79 "</TD></TR></TABLE>\n"
80 "</div>\n<div id=\"content\">\n"
83 strcpy(recp, bstr("recp"));
84 strcpy(closewin, bstr("closewin"));
86 if (strlen(bstr("send_button")) == 0) {
88 wprintf(_("Message was not sent."));
89 wprintf("</EM><br />\n");
91 serv_printf("SEXP %s|-", recp);
92 serv_getln(buf, sizeof buf);
95 text_to_server(bstr("msgtext"), 0);
98 wprintf(_("Message has been sent to "));
100 wprintf(".</EM><br />\n");
103 wprintf("<EM>%s</EM><br />\n", &buf[4]);
107 if (!strcasecmp(closewin, "yes")) {
108 wprintf("<CENTER><a href=\"javascript:window.close();\">");
109 wprintf(_("[ close window ]"));
110 wprintf("</A></CENTER>\n");
119 * \brief multiuser chat
125 /** First, check to make sure we're still allowed in this room. */
126 serv_printf("GOTO %s", WC->wc_roomname);
127 serv_getln(buf, sizeof buf);
129 smart_goto("_BASEROOM_");
134 * If the chat socket is still open from a previous chat,
135 * close it -- because it might be stale or in the wrong room.
137 if (WC->chat_sock < 0) {
138 close(WC->chat_sock);
139 WC->chat_sock = (-1);
143 * WebCit Chat works by having transmit, receive, and refresh
144 * frames. Load the frameset. (This isn't AJAX but the headers
145 * output by begin_ajax_response() happen to be the ones we need.)
147 begin_ajax_response();
148 do_template("chatframeset");
155 * \brief display page popup
156 * If there are instant messages waiting, and we notice that we haven't checked them in
157 * a while, it probably means that we need to open the instant messenger window.
159 void page_popup(void)
163 /** JavaScript function to alert the user that popups are probably blocked */
164 wprintf("<script type=\"text/javascript\"> "
165 "function PopUpFailed() { "
169 _("You have one or more instant messages waiting, but the Citadel Instant Messenger "
170 "window failed to open. This is probably because you have a popup blocker "
171 "installed. Please configure your popup blocker to allow popups from this site "
172 "if you wish to receive instant messages.")
175 /** First, do the check as part of our page load. */
177 serv_getln(buf, sizeof buf);
179 if ((time(NULL) - WC->last_pager_check) > 60) {
180 wprintf("<script type=\"text/javascript\">"
181 " var oWin = window.open('static/instant_messenger.html', "
182 " 'CTDL_MESSENGER', 'width=700,height=400'); "
183 " if (oWin==null || typeof(oWin)==\"undefined\") { "
191 /** Then schedule it to happen again a minute from now if the user is idle. */
192 wprintf("<script type=\"text/javascript\"> "
193 " function HandleSslp(sslg_xmlresponse) { "
194 " sslg_response = sslg_xmlresponse.responseText.substr(0, 1); "
195 " if (sslg_response == 'Y') { "
196 " var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
197 " 'width=700,height=400'); "
198 " if (oWin==null || typeof(oWin)==\"undefined\") { "
203 " function CheckPager() { "
204 " new Ajax.Request('sslg', { method: 'get', parameters: Math.random(), "
205 " onSuccess: HandleSslp } ); "
207 " new PeriodicalExecuter(CheckPager, 30); "
215 * \brief Support function for chat
216 * make sure the chat socket is connected
219 int setup_chat_socket(void) {
222 int good_chatmode = 0;
224 if (WC->chat_sock < 0) {
226 if (!strcasecmp(ctdlhost, "uds")) {
227 /** unix domain socket */
228 sprintf(buf, "%s/citadel.socket", ctdlport);
229 WC->chat_sock = uds_connectsock(buf);
233 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
236 if (WC->chat_sock < 0) {
240 /** Temporarily swap the serv and chat sockets during chat talk */
242 WC->serv_sock = WC->chat_sock;
245 serv_getln(buf, sizeof buf);
247 serv_printf("USER %s", WC->wc_username);
248 serv_getln(buf, sizeof buf);
250 serv_printf("PASS %s", WC->wc_password);
251 serv_getln(buf, sizeof buf);
253 serv_printf("GOTO %s", WC->wc_roomname);
254 serv_getln(buf, sizeof buf);
257 serv_getln(buf, sizeof buf);
266 /** Unswap the sockets. */
268 WC->serv_sock = WC->chat_sock;
271 if (!good_chatmode) close(WC->serv_sock);
280 * \brief Receiving side of the chat window.
281 * This is implemented in a
282 * tiny hidden IFRAME that just does JavaScript writes to
283 * other frames whenever it refreshes and finds new data.
285 void chat_recv(void) {
289 int end_chat_now = 0;
293 char *output_data = NULL;
295 output_headers(0, 0, 0, 0, 0, 0);
297 wprintf("Content-type: text/html; charset=utf-8\n");
301 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
304 "<body bgcolor=\"#FFFFFF\">\n"
307 if (setup_chat_socket() != 0) {
308 wprintf(_("An error occurred while setting up the chat socket."));
309 wprintf("</BODY></HTML>\n");
315 * See if there is any chat data waiting.
317 output_data = strdup("");
320 pf.fd = WC->chat_sock;
323 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
326 /** Temporarily swap the serv and chat sockets during chat talk */
328 WC->serv_sock = WC->chat_sock;
331 serv_getln(buf, sizeof buf);
333 if (!strcmp(buf, "000")) {
335 strcat(buf, _("Now exiting chat mode."));
339 /** Unswap the sockets. */
341 WC->serv_sock = WC->chat_sock;
344 /** Append our output data */
345 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
346 strcat(output_data, buf);
347 strcat(output_data, "\n");
350 } while ( (got_data) && (!end_chat_now) );
353 close(WC->chat_sock);
354 WC->chat_sock = (-1);
355 wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
358 if (strlen(output_data) > 0) {
360 if (output_data[strlen(output_data)-1] == '\n') {
361 output_data[strlen(output_data)-1] = 0;
364 /** Output our fun to the other frame. */
365 wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
369 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
370 extract_token(buf, output_data, i, '\n', sizeof buf);
371 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
372 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
374 if (strcasecmp(cl_text, "NOOP")) {
376 wprintf("parent.chat_transcript.document.write('");
378 if (strcasecmp(cl_user, WC->last_chat_user)) {
379 wprintf("<TABLE border=0 WIDTH=100%% "
380 "CELLSPACING=1 CELLPADDING=0 "
381 "BGCOLOR="#FFFFFF">"
382 "<TR><TD></TR></TD></TABLE>"
387 wprintf("<TABLE border=0 WIDTH=100%% "
388 "CELLSPACING=0 CELLPADDING=0 "
389 "BGCOLOR="#EEEEEE">");
393 if (!strcasecmp(cl_user, ":")) {
397 if (strcasecmp(cl_user, WC->last_chat_user)) {
400 if (!strcasecmp(cl_user, WC->wc_fullname)) {
401 wprintf("<FONT COLOR="#FF0000">");
404 wprintf("<FONT COLOR="#0000FF">");
408 wprintf("</FONT>: </B>");
411 wprintf(" ");
414 if (!strcasecmp(cl_user, ":")) {
418 wprintf("</TD></TR></TABLE>");
421 strcpy(WC->last_chat_user, cl_user);
425 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
430 wprintf("</BODY></HTML>\n");
436 * \brief sending side of the chat window
438 void chat_send(void) {
443 output_headers(0, 0, 0, 0, 0, 0);
444 wprintf("Content-type: text/html; charset=utf-8\n");
447 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
450 if (bstr("send_this") != NULL) {
451 strcpy(send_this, bstr("send_this"));
454 strcpy(send_this, "");
457 if (strlen(bstr("help_button")) > 0) {
458 strcpy(send_this, "/help");
461 if (strlen(bstr("list_button")) > 0) {
462 strcpy(send_this, "/who");
465 if (strlen(bstr("exit_button")) > 0) {
466 strcpy(send_this, "/quit");
469 if (setup_chat_socket() != 0) {
470 wprintf(_("An error occurred while setting up the chat socket."));
471 wprintf("</BODY></HTML>\n");
476 /** Temporarily swap the serv and chat sockets during chat talk */
478 WC->serv_sock = WC->chat_sock;
481 while (strlen(send_this) > 0) {
482 if (strlen(send_this) < 67) {
483 serv_puts(send_this);
484 strcpy(send_this, "");
487 for (i=55; i<67; ++i) {
488 if (send_this[i] == ' ') break;
490 strncpy(buf, send_this, i);
492 strcpy(send_this, &send_this[i]);
497 /** Unswap the sockets. */
499 WC->serv_sock = WC->chat_sock;
502 wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
503 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
504 "NAME=\"send_this\">\n", SIZ-10);
506 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
507 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
508 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
509 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
510 wprintf("</FORM>\n");
512 wprintf("</BODY></HTML>\n");