5 * \defgroup PageFunc Functions which implement the chat and paging facilities.
12 * \brief display the form for paging (x-messaging) another user
14 void display_page(void)
18 strcpy(recp, bstr("recp"));
20 output_headers(1, 1, 2, 0, 0, 0);
21 wprintf("<div id=\"banner\">\n"
22 "<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>"
23 "<SPAN CLASS=\"titlebar\">");
24 wprintf(_("Send instant message"));
26 "</TD></TR></TABLE>\n"
27 "</div>\n<div id=\"content\">\n"
30 wprintf("<div class=\"fix_scrollbar_bug\">"
31 "<table border=0 width=100%% bgcolor=\"#ffffff\"><tr><td>\n");
33 wprintf(_("Send an instant message to: "));
37 wprintf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
39 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
41 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
45 wprintf(_("Enter message text:"));
48 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
49 "WIDTH=40></TEXTAREA>\n");
51 wprintf("</TD></TR></TABLE><br />\n");
53 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
54 wprintf("<br /><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
56 wprintf("</FORM></CENTER>\n");
57 wprintf("</td></tr></table></div>\n");
62 * \brief page another user
69 safestrncpy(recp, bstr("recp"), sizeof recp);
71 if (strlen(bstr("send_button")) == 0) {
72 safestrncpy(WC->ImportantMessage,
73 _("Message was not sent."),
74 sizeof WC->ImportantMessage
77 serv_printf("SEXP %s|-", recp);
78 serv_getln(buf, sizeof buf);
81 text_to_server(bstr("msgtext"));
83 stresc(buf, recp, 0, 0);
84 snprintf(WC->ImportantMessage,
85 sizeof WC->ImportantMessage,
87 _("Message has been sent to "),
92 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
102 * \brief multiuser chat
108 /** First, check to make sure we're still allowed in this room. */
109 serv_printf("GOTO %s", WC->wc_roomname);
110 serv_getln(buf, sizeof buf);
112 smart_goto("_BASEROOM_");
117 * If the chat socket is still open from a previous chat,
118 * close it -- because it might be stale or in the wrong room.
120 if (WC->chat_sock < 0) {
121 close(WC->chat_sock);
122 WC->chat_sock = (-1);
126 * WebCit Chat works by having transmit, receive, and refresh
127 * frames. Load the frameset. (This isn't AJAX but the headers
128 * output by begin_ajax_response() happen to be the ones we need.)
130 begin_ajax_response();
131 do_template("chatframeset");
138 * \brief display page popup
139 * If there are instant messages waiting, and we notice that we haven't checked them in
140 * a while, it probably means that we need to open the instant messenger window.
142 void page_popup(void)
146 /** JavaScript function to alert the user that popups are probably blocked */
147 wprintf("<script type=\"text/javascript\"> "
148 "function PopUpFailed() { "
152 _("You have one or more instant messages waiting, but the Citadel Instant Messenger "
153 "window failed to open. This is probably because you have a popup blocker "
154 "installed. Please configure your popup blocker to allow popups from this site "
155 "if you wish to receive instant messages.")
158 /** First, do the check as part of our page load. */
160 serv_getln(buf, sizeof buf);
162 if ((time(NULL) - WC->last_pager_check) > 60) {
163 wprintf("<script type=\"text/javascript\">"
164 " var oWin = window.open('static/instant_messenger.html', "
165 " 'CTDL_MESSENGER', 'width=700,height=400'); "
166 " if (oWin==null || typeof(oWin)==\"undefined\") { "
174 /** Then schedule it to happen again a minute from now if the user is idle. */
175 wprintf("<script type=\"text/javascript\"> "
176 " function HandleSslp(sslg_xmlresponse) { "
177 " sslg_response = sslg_xmlresponse.responseText.substr(0, 1); "
178 " if (sslg_response == 'Y') { "
179 " var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
180 " 'width=700,height=400'); "
181 " if (oWin==null || typeof(oWin)==\"undefined\") { "
186 " function CheckPager() { "
187 " new Ajax.Request('sslg', { method: 'get', parameters: Math.random(), "
188 " onSuccess: HandleSslp } ); "
190 " new PeriodicalExecuter(CheckPager, 30); "
198 * \brief Support function for chat
199 * make sure the chat socket is connected
202 int setup_chat_socket(void) {
205 int good_chatmode = 0;
207 if (WC->chat_sock < 0) {
209 if (!strcasecmp(ctdlhost, "uds")) {
210 /** unix domain socket */
211 sprintf(buf, "%s/citadel.socket", ctdlport);
212 WC->chat_sock = uds_connectsock(buf);
216 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
219 if (WC->chat_sock < 0) {
223 /** Temporarily swap the serv and chat sockets during chat talk */
225 WC->serv_sock = WC->chat_sock;
228 serv_getln(buf, sizeof buf);
230 serv_printf("USER %s", WC->wc_username);
231 serv_getln(buf, sizeof buf);
233 serv_printf("PASS %s", WC->wc_password);
234 serv_getln(buf, sizeof buf);
236 serv_printf("GOTO %s", WC->wc_roomname);
237 serv_getln(buf, sizeof buf);
240 serv_getln(buf, sizeof buf);
249 /** Unswap the sockets. */
251 WC->serv_sock = WC->chat_sock;
254 if (!good_chatmode) close(WC->serv_sock);
263 * \brief Receiving side of the chat window.
264 * This is implemented in a
265 * tiny hidden IFRAME that just does JavaScript writes to
266 * other frames whenever it refreshes and finds new data.
268 void chat_recv(void) {
272 int end_chat_now = 0;
276 char *output_data = NULL;
278 output_headers(0, 0, 0, 0, 0, 0);
280 wprintf("Content-type: text/html; charset=utf-8\n");
284 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
287 "<body bgcolor=\"#FFFFFF\">\n"
290 if (setup_chat_socket() != 0) {
291 wprintf(_("An error occurred while setting up the chat socket."));
292 wprintf("</BODY></HTML>\n");
298 * See if there is any chat data waiting.
300 output_data = strdup("");
303 pf.fd = WC->chat_sock;
306 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
309 /** Temporarily swap the serv and chat sockets during chat talk */
311 WC->serv_sock = WC->chat_sock;
314 serv_getln(buf, sizeof buf);
316 if (!strcmp(buf, "000")) {
318 strcat(buf, _("Now exiting chat mode."));
322 /** Unswap the sockets. */
324 WC->serv_sock = WC->chat_sock;
327 /** Append our output data */
328 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
329 strcat(output_data, buf);
330 strcat(output_data, "\n");
333 } while ( (got_data) && (!end_chat_now) );
336 close(WC->chat_sock);
337 WC->chat_sock = (-1);
338 wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
341 if (strlen(output_data) > 0) {
343 if (output_data[strlen(output_data)-1] == '\n') {
344 output_data[strlen(output_data)-1] = 0;
347 /** Output our fun to the other frame. */
348 wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
352 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
353 extract_token(buf, output_data, i, '\n', sizeof buf);
354 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
355 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
357 if (strcasecmp(cl_text, "NOOP")) {
359 wprintf("parent.chat_transcript.document.write('");
361 if (strcasecmp(cl_user, WC->last_chat_user)) {
362 wprintf("<TABLE border=0 WIDTH=100%% "
363 "CELLSPACING=1 CELLPADDING=0 "
364 "BGCOLOR="#FFFFFF">"
365 "<TR><TD></TR></TD></TABLE>"
370 wprintf("<TABLE border=0 WIDTH=100%% "
371 "CELLSPACING=0 CELLPADDING=0 "
372 "BGCOLOR="#EEEEEE">");
376 if (!strcasecmp(cl_user, ":")) {
380 if (strcasecmp(cl_user, WC->last_chat_user)) {
383 if (!strcasecmp(cl_user, WC->wc_fullname)) {
384 wprintf("<FONT COLOR="#FF0000">");
387 wprintf("<FONT COLOR="#0000FF">");
391 wprintf("</FONT>: </B>");
394 wprintf(" ");
397 if (!strcasecmp(cl_user, ":")) {
401 wprintf("</TD></TR></TABLE>");
404 strcpy(WC->last_chat_user, cl_user);
408 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
413 wprintf("</BODY></HTML>\n");
419 * \brief sending side of the chat window
421 void chat_send(void) {
426 output_headers(0, 0, 0, 0, 0, 0);
427 wprintf("Content-type: text/html; charset=utf-8\n");
430 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
433 if (bstr("send_this") != NULL) {
434 strcpy(send_this, bstr("send_this"));
437 strcpy(send_this, "");
440 if (strlen(bstr("help_button")) > 0) {
441 strcpy(send_this, "/help");
444 if (strlen(bstr("list_button")) > 0) {
445 strcpy(send_this, "/who");
448 if (strlen(bstr("exit_button")) > 0) {
449 strcpy(send_this, "/quit");
452 if (setup_chat_socket() != 0) {
453 wprintf(_("An error occurred while setting up the chat socket."));
454 wprintf("</BODY></HTML>\n");
459 /** Temporarily swap the serv and chat sockets during chat talk */
461 WC->serv_sock = WC->chat_sock;
464 while (strlen(send_this) > 0) {
465 if (strlen(send_this) < 67) {
466 serv_puts(send_this);
467 strcpy(send_this, "");
470 for (i=55; i<67; ++i) {
471 if (send_this[i] == ' ') break;
473 strncpy(buf, send_this, i);
475 strcpy(send_this, &send_this[i]);
480 /** Unswap the sockets. */
482 WC->serv_sock = WC->chat_sock;
485 wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
486 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
487 "NAME=\"send_this\">\n", SIZ-10);
489 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
490 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
491 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
492 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
493 wprintf("</FORM>\n");
495 wprintf("</BODY></HTML>\n");