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 class=\"paging_banner\"><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 class=\"paging_background\"><tr><td>\n");
33 wprintf(_("Send an instant message to: "));
37 wprintf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
38 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
40 wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
42 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
46 wprintf(_("Enter message text:"));
49 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
50 "WIDTH=40></TEXTAREA>\n");
52 wprintf("</TD></TR></TABLE><br />\n");
54 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
55 wprintf("<br /><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
57 wprintf("</FORM></CENTER>\n");
58 wprintf("</td></tr></table></div>\n");
63 * \brief page another user
70 safestrncpy(recp, bstr("recp"), sizeof recp);
72 if (IsEmptyStr(bstr("send_button"))) {
73 safestrncpy(WC->ImportantMessage,
74 _("Message was not sent."),
75 sizeof WC->ImportantMessage
78 serv_printf("SEXP %s|-", recp);
79 serv_getln(buf, sizeof buf);
82 text_to_server(bstr("msgtext"));
84 stresc(buf, recp, 0, 0);
85 snprintf(WC->ImportantMessage,
86 sizeof WC->ImportantMessage,
88 _("Message has been sent to "),
93 safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage);
103 * \brief multiuser chat
109 /** First, check to make sure we're still allowed in this room. */
110 serv_printf("GOTO %s", WC->wc_roomname);
111 serv_getln(buf, sizeof buf);
113 smart_goto("_BASEROOM_");
118 * If the chat socket is still open from a previous chat,
119 * close it -- because it might be stale or in the wrong room.
121 if (WC->chat_sock < 0) {
122 close(WC->chat_sock);
123 WC->chat_sock = (-1);
127 * WebCit Chat works by having transmit, receive, and refresh
128 * frames. Load the frameset. (This isn't AJAX but the headers
129 * output by begin_ajax_response() happen to be the ones we need.)
131 begin_ajax_response();
132 do_template("chatframeset");
139 * \brief display page popup
140 * If there are instant messages waiting, and we notice that we haven't checked them in
141 * a while, it probably means that we need to open the instant messenger window.
143 void page_popup(void)
147 /** JavaScript function to alert the user that popups are probably blocked */
148 wprintf("<script type=\"text/javascript\"> "
149 "function PopUpFailed() { "
153 _("You have one or more instant messages waiting, but the Citadel Instant Messenger "
154 "window failed to open. This is probably because you have a popup blocker "
155 "installed. Please configure your popup blocker to allow popups from this site "
156 "if you wish to receive instant messages.")
159 /** First, do the check as part of our page load. */
161 serv_getln(buf, sizeof buf);
163 if ((time(NULL) - WC->last_pager_check) > 60) {
164 wprintf("<script type=\"text/javascript\">"
165 " var oWin = window.open('static/instant_messenger.html', "
166 " 'CTDL_MESSENGER', 'width=700,height=400'); "
167 " if (oWin==null || typeof(oWin)==\"undefined\") { "
175 /** Then schedule it to happen again a minute from now if the user is idle. */
176 wprintf("<script type=\"text/javascript\"> "
177 " function HandleSslp(sslg_xmlresponse) { "
178 " sslg_response = sslg_xmlresponse.responseText.substr(0, 1); "
179 " if (sslg_response == 'Y') { "
180 " var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
181 " 'width=700,height=400'); "
182 " if (oWin==null || typeof(oWin)==\"undefined\") { "
187 " function CheckPager() { "
188 " new Ajax.Request('sslg', { method: 'get', parameters: CtdlRandomString(), "
189 " onSuccess: HandleSslp } ); "
191 " new PeriodicalExecuter(CheckPager, 30); "
199 * \brief Support function for chat
200 * make sure the chat socket is connected
203 int setup_chat_socket(void) {
206 int good_chatmode = 0;
208 if (WC->chat_sock < 0) {
210 if (!strcasecmp(ctdlhost, "uds")) {
211 /** unix domain socket */
212 sprintf(buf, "%s/citadel.socket", ctdlport);
213 WC->chat_sock = uds_connectsock(buf);
217 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
220 if (WC->chat_sock < 0) {
224 /** Temporarily swap the serv and chat sockets during chat talk */
226 WC->serv_sock = WC->chat_sock;
229 serv_getln(buf, sizeof buf);
231 serv_printf("USER %s", WC->wc_username);
232 serv_getln(buf, sizeof buf);
234 serv_printf("PASS %s", WC->wc_password);
235 serv_getln(buf, sizeof buf);
237 serv_printf("GOTO %s", WC->wc_roomname);
238 serv_getln(buf, sizeof buf);
241 serv_getln(buf, sizeof buf);
250 /** Unswap the sockets. */
252 WC->serv_sock = WC->chat_sock;
255 if (!good_chatmode) close(WC->serv_sock);
264 * \brief Receiving side of the chat window.
265 * This is implemented in a
266 * tiny hidden IFRAME that just does JavaScript writes to
267 * other frames whenever it refreshes and finds new data.
269 void chat_recv(void) {
273 int end_chat_now = 0;
277 char *output_data = NULL;
279 output_headers(0, 0, 0, 0, 0, 0);
281 wprintf("Content-type: text/html; charset=utf-8\n");
285 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
288 "<body bgcolor=\"#FFFFFF\">\n"
291 if (setup_chat_socket() != 0) {
292 wprintf(_("An error occurred while setting up the chat socket."));
293 wprintf("</BODY></HTML>\n");
299 * See if there is any chat data waiting.
301 output_data = strdup("");
304 pf.fd = WC->chat_sock;
307 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
310 /** Temporarily swap the serv and chat sockets during chat talk */
312 WC->serv_sock = WC->chat_sock;
315 serv_getln(buf, sizeof buf);
317 if (!strcmp(buf, "000")) {
319 strcat(buf, _("Now exiting chat mode."));
323 /** Unswap the sockets. */
325 WC->serv_sock = WC->chat_sock;
328 /** Append our output data */
329 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
330 strcat(output_data, buf);
331 strcat(output_data, "\n");
334 } while ( (got_data) && (!end_chat_now) );
337 close(WC->chat_sock);
338 WC->chat_sock = (-1);
339 wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
342 if (!IsEmptyStr(output_data)) {
344 len = strlen(output_data);
345 if (output_data[len-1] == '\n') {
346 output_data[len-1] = 0;
349 /** Output our fun to the other frame. */
350 wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
354 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
355 extract_token(buf, output_data, i, '\n', sizeof buf);
356 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
357 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
359 if (strcasecmp(cl_text, "NOOP")) {
361 wprintf("parent.chat_transcript.document.write('");
363 if (strcasecmp(cl_user, WC->last_chat_user)) {
364 wprintf("<TABLE border=0 WIDTH=100%% "
365 "CELLSPACING=1 CELLPADDING=0 "
366 "BGCOLOR="#FFFFFF">"
367 "<TR><TD></TR></TD></TABLE>"
372 wprintf("<TABLE border=0 WIDTH=100%% "
373 "CELLSPACING=0 CELLPADDING=0 "
374 "BGCOLOR="#EEEEEE">");
378 if (!strcasecmp(cl_user, ":")) {
382 if (strcasecmp(cl_user, WC->last_chat_user)) {
385 if (!strcasecmp(cl_user, WC->wc_fullname)) {
386 wprintf("<FONT COLOR="#FF0000">");
389 wprintf("<FONT COLOR="#0000FF">");
393 wprintf("</FONT>: </B>");
396 wprintf(" ");
399 if (!strcasecmp(cl_user, ":")) {
403 wprintf("</TD></TR></TABLE>");
406 strcpy(WC->last_chat_user, cl_user);
410 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
415 wprintf("</BODY></HTML>\n");
421 * \brief sending side of the chat window
423 void chat_send(void) {
428 output_headers(0, 0, 0, 0, 0, 0);
429 wprintf("Content-type: text/html; charset=utf-8\n");
432 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
435 if (bstr("send_this") != NULL) {
436 strcpy(send_this, bstr("send_this"));
439 strcpy(send_this, "");
442 if (!IsEmptyStr(bstr("help_button"))) {
443 strcpy(send_this, "/help");
446 if (!IsEmptyStr(bstr("list_button"))) {
447 strcpy(send_this, "/who");
450 if (!IsEmptyStr(bstr("exit_button"))) {
451 strcpy(send_this, "/quit");
454 if (setup_chat_socket() != 0) {
455 wprintf(_("An error occurred while setting up the chat socket."));
456 wprintf("</BODY></HTML>\n");
461 /** Temporarily swap the serv and chat sockets during chat talk */
463 WC->serv_sock = WC->chat_sock;
466 while (!IsEmptyStr(send_this)) {
467 if (strlen(send_this) < 67) {
468 serv_puts(send_this);
469 strcpy(send_this, "");
472 for (i=55; i<67; ++i) {
473 if (send_this[i] == ' ') break;
475 strncpy(buf, send_this, i);
477 strcpy(send_this, &send_this[i]);
482 /** Unswap the sockets. */
484 WC->serv_sock = WC->chat_sock;
487 wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
488 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
489 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
490 "NAME=\"send_this\">\n", SIZ-10);
492 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
493 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
494 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
495 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
496 wprintf("</FORM>\n");
498 wprintf("</BODY></HTML>\n");