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 /** First, do the check as part of our page load. */
165 serv_getln(buf, sizeof buf);
167 if ((time(NULL) - WC->last_pager_check) > 60) {
168 wprintf("<script type=\"text/javascript\">"
169 " window.open('static/instant_messenger.html', 'CTDL_MESSENGER', "
170 " 'width=700,height=400');"
176 /** Then schedule it to happen again a minute from now if the user is idle. */
177 wprintf("<script type=\"text/javascript\"> \n"
178 " function HandleSslp(sslg_xmlresponse) { \n"
179 " sslg_response = sslg_xmlresponse.responseText.substr(0, 1); \n"
180 " if (sslg_response == 'Y') { \n"
181 " window.open('static/instant_messenger.html', 'CTDL_MESSENGER', \n"
182 " 'width=700,height=400'); \n"
185 " function CheckPager() { \n"
186 " new Ajax.Request('sslg', { method: 'get', parameters: Math.random(), \n"
187 " onSuccess: HandleSslp } ); \n"
189 " new PeriodicalExecuter(CheckPager, 30); \n"
197 * \brief Support function for chat
198 * make sure the chat socket is connected
201 int setup_chat_socket(void) {
204 int good_chatmode = 0;
206 if (WC->chat_sock < 0) {
208 if (!strcasecmp(ctdlhost, "uds")) {
209 /** unix domain socket */
210 sprintf(buf, "%s/citadel.socket", ctdlport);
211 WC->chat_sock = uds_connectsock(buf);
215 WC->chat_sock = tcp_connectsock(ctdlhost, ctdlport);
218 if (WC->chat_sock < 0) {
222 /** Temporarily swap the serv and chat sockets during chat talk */
224 WC->serv_sock = WC->chat_sock;
227 serv_getln(buf, sizeof buf);
229 serv_printf("USER %s", WC->wc_username);
230 serv_getln(buf, sizeof buf);
232 serv_printf("PASS %s", WC->wc_password);
233 serv_getln(buf, sizeof buf);
235 serv_printf("GOTO %s", WC->wc_roomname);
236 serv_getln(buf, sizeof buf);
239 serv_getln(buf, sizeof buf);
248 /** Unswap the sockets. */
250 WC->serv_sock = WC->chat_sock;
253 if (!good_chatmode) close(WC->serv_sock);
262 * \brief Receiving side of the chat window.
263 * This is implemented in a
264 * tiny hidden IFRAME that just does JavaScript writes to
265 * other frames whenever it refreshes and finds new data.
267 void chat_recv(void) {
271 int end_chat_now = 0;
275 char *output_data = NULL;
277 output_headers(0, 0, 0, 0, 0, 0);
279 wprintf("Content-type: text/html; charset=utf-8\n");
283 "<meta http-equiv=\"refresh\" content=\"3\" />\n"
286 "<body bgcolor=\"#FFFFFF\">\n"
289 if (setup_chat_socket() != 0) {
290 wprintf(_("An error occurred while setting up the chat socket."));
291 wprintf("</BODY></HTML>\n");
297 * See if there is any chat data waiting.
299 output_data = strdup("");
302 pf.fd = WC->chat_sock;
305 if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) {
308 /** Temporarily swap the serv and chat sockets during chat talk */
310 WC->serv_sock = WC->chat_sock;
313 serv_getln(buf, sizeof buf);
315 if (!strcmp(buf, "000")) {
317 strcat(buf, _("Now exiting chat mode."));
321 /** Unswap the sockets. */
323 WC->serv_sock = WC->chat_sock;
326 /** Append our output data */
327 output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4);
328 strcat(output_data, buf);
329 strcat(output_data, "\n");
332 } while ( (got_data) && (!end_chat_now) );
335 close(WC->chat_sock);
336 WC->chat_sock = (-1);
337 wprintf("<img src=\"static/blank.gif\" onLoad=\"parent.window.close();\">\n");
340 if (strlen(output_data) > 0) {
342 if (output_data[strlen(output_data)-1] == '\n') {
343 output_data[strlen(output_data)-1] = 0;
346 /** Output our fun to the other frame. */
347 wprintf("<img src=\"static/blank.gif\" WIDTH=1 HEIGHT=1\n"
351 for (i=0; i<num_tokens(output_data, '\n'); ++i) {
352 extract_token(buf, output_data, i, '\n', sizeof buf);
353 extract_token(cl_user, buf, 0, '|', sizeof cl_user);
354 extract_token(cl_text, buf, 1, '|', sizeof cl_text);
356 if (strcasecmp(cl_text, "NOOP")) {
358 wprintf("parent.chat_transcript.document.write('");
360 if (strcasecmp(cl_user, WC->last_chat_user)) {
361 wprintf("<TABLE border=0 WIDTH=100%% "
362 "CELLSPACING=1 CELLPADDING=0 "
363 "BGCOLOR="#FFFFFF">"
364 "<TR><TD></TR></TD></TABLE>"
369 wprintf("<TABLE border=0 WIDTH=100%% "
370 "CELLSPACING=0 CELLPADDING=0 "
371 "BGCOLOR="#EEEEEE">");
375 if (!strcasecmp(cl_user, ":")) {
379 if (strcasecmp(cl_user, WC->last_chat_user)) {
382 if (!strcasecmp(cl_user, WC->wc_fullname)) {
383 wprintf("<FONT COLOR="#FF0000">");
386 wprintf("<FONT COLOR="#0000FF">");
390 wprintf("</FONT>: </B>");
393 wprintf(" ");
396 if (!strcasecmp(cl_user, ":")) {
400 wprintf("</TD></TR></TABLE>");
403 strcpy(WC->last_chat_user, cl_user);
407 wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
412 wprintf("</BODY></HTML>\n");
418 * \brief sending side of the chat window
420 void chat_send(void) {
425 output_headers(0, 0, 0, 0, 0, 0);
426 wprintf("Content-type: text/html; charset=utf-8\n");
429 "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"
432 if (bstr("send_this") != NULL) {
433 strcpy(send_this, bstr("send_this"));
436 strcpy(send_this, "");
439 if (strlen(bstr("help_button")) > 0) {
440 strcpy(send_this, "/help");
443 if (strlen(bstr("list_button")) > 0) {
444 strcpy(send_this, "/who");
447 if (strlen(bstr("exit_button")) > 0) {
448 strcpy(send_this, "/quit");
451 if (setup_chat_socket() != 0) {
452 wprintf(_("An error occurred while setting up the chat socket."));
453 wprintf("</BODY></HTML>\n");
458 /** Temporarily swap the serv and chat sockets during chat talk */
460 WC->serv_sock = WC->chat_sock;
463 while (strlen(send_this) > 0) {
464 if (strlen(send_this) < 67) {
465 serv_puts(send_this);
466 strcpy(send_this, "");
469 for (i=55; i<67; ++i) {
470 if (send_this[i] == ' ') break;
472 strncpy(buf, send_this, i);
474 strcpy(send_this, &send_this[i]);
479 /** Unswap the sockets. */
481 WC->serv_sock = WC->chat_sock;
484 wprintf("<FORM METHOD=\"POST\" action=\"chat_send\" NAME=\"chatsendform\">\n");
485 wprintf("<INPUT TYPE=\"text\" SIZE=\"80\" MAXLENGTH=\"%d\" "
486 "NAME=\"send_this\">\n", SIZ-10);
488 wprintf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">\n", _("Send"));
489 wprintf("<INPUT TYPE=\"submit\" NAME=\"help_button\" VALUE=\"%s\">\n", _("Help"));
490 wprintf("<INPUT TYPE=\"submit\" NAME=\"list_button\" VALUE=\"%s\">\n", _("List users"));
491 wprintf("<INPUT TYPE=\"submit\" NAME=\"exit_button\" VALUE=\"%s\">\n", _("Exit"));
492 wprintf("</FORM>\n");
494 wprintf("</BODY></HTML>\n");