-/* $Id$ */
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <limits.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <string.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <pthread.h>
-#include <signal.h>
-#include "webcit.h"
+/*
+ * This module handles instant message related functions.
+ *
+ * Copyright (c) 1996-2012 by the citadel.org team
+ *
+ * This program is open source software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+#include "webcit.h"
/*
* display the form for paging (x-messaging) another user
strcpy(recp, bstr("recp"));
- output_headers(3);
+ output_headers(1, 1, 1, 0, 0, 0);
+ wc_printf("<div id=\"room_banner_override\">\n");
+ wc_printf("<h1>");
+ wc_printf(_("Send instant message"));
+ wc_printf("</h1>");
+ wc_printf("</div>\n");
- wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Page another user</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
+ wc_printf("<div id=\"content\" class=\"service\">\n");
- wprintf("<CENTER>This will send a page (instant message) "
- "to %s.\n", recp);
+ wc_printf("<table class=\"paging_background\"><tr><td>\n");
- wprintf("<FORM METHOD=\"POST\" ACTION=\"/page_user\">\n");
+ wc_printf(_("Send an instant message to: "));
+ escputs(recp);
+ wc_printf("<br>\n");
+ wc_printf("<FORM METHOD=\"POST\" action=\"page_user\">\n");
+ wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
+ wc_printf("<input type=\"hidden\" name=\"template\" value=\"who\">\n");
- wprintf("<TABLE border=0 width=100%%><TR><TD>\n");
+ wc_printf("<TABLE border=0 width=100%%><TR><TD>\n");
- wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
+ wc_printf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"");
escputs(recp);
- wprintf("\">\n");
+ wc_printf("\">\n");
- wprintf("<INPUT TYPE=\"hidden\" NAME=\"closewin\" VALUE=\"");
- escputs(bstr("closewin"));
- wprintf("\">\n");
+ wc_printf(_("Enter message text:"));
+ wc_printf("<br>");
- wprintf("Enter message text:<BR>");
-
- wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
+ wc_printf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=5 COLS=40 "
"WIDTH=40></TEXTAREA>\n");
- wprintf("</TD></TR></TABLE><BR>\n");
+ wc_printf("</TD></TR></TABLE><br>\n");
- wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send message\">");
- wprintf("<BR><A HREF=\"javascript:window.close();\"Cancel</A>\n");
+ wc_printf("<INPUT TYPE=\"submit\" NAME=\"send_button\" VALUE=\"%s\">", _("Send message"));
+ wc_printf("<br><a href=\"javascript:window.close();\"%s</A>\n", _("Cancel"));
- wprintf("</FORM></CENTER>\n");
+ wc_printf("</FORM></CENTER>\n");
+ wc_printf("</td></tr></table>\n");
wDumpContent(1);
}
*/
void page_user(void)
{
- char recp[SIZ];
- char sc[SIZ];
- char buf[SIZ];
- char closewin[SIZ];
-
- output_headers(1);
+ char recp[256];
+ StrBuf *Line;
- strcpy(recp, bstr("recp"));
- strcpy(sc, bstr("sc"));
- strcpy(closewin, bstr("closewin"));
+ safestrncpy(recp, bstr("recp"), sizeof recp);
- if (strcmp(sc, "Send message")) {
- wprintf("<EM>Message was not sent.</EM><BR>\n");
+ if (!havebstr("send_button")) {
+ AppendImportantMessage(_("Message was not sent."), -1);
} else {
+ Line = NewStrBuf();
serv_printf("SEXP %s|-", recp);
- serv_gets(buf);
-
- if (buf[0] == '4') {
+ StrBuf_ServGetln(Line);
+ if (GetServerStatusMsg(Line, NULL, 0, 0) == 4) {
+ char buf[256];
text_to_server(bstr("msgtext"));
serv_puts("000");
- wprintf("<EM>Message has been sent to ");
- escputs(recp);
- wprintf(".</EM><BR>\n");
+ stresc(buf, 256, recp, 0, 0);
+ AppendImportantMessage(buf, -1);
+ AppendImportantMessage(_("Message has been sent to "), -1);
}
- else {
- wprintf("<EM>%s</EM><BR>\n", &buf[4]);
- }
- }
-
- if (!strcasecmp(closewin, "yes")) {
- wprintf("<CENTER><A HREF=\"javascript:window.close();\">"
- "[ close window ]</A></CENTER>\n");
}
- wDumpContent(1);
+ url_do_template();
}
/*
- * multiuser chat
+ * display page popup
+ * If there are instant messages waiting, and we notice that we haven't checked them in
+ * a while, it probably means that we need to open the instant messenger window.
*/
-void do_chat(void)
+int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP)
{
+ int len;
+ char buf[SIZ];
- output_headers(1);
-
- wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Real-time chat</B>\n");
- wprintf("</FONT></TD></TR></TABLE>\n");
-
- wprintf("A chat window should be appearing on your screen ");
- wprintf("momentarily. When you're ");
- wprintf("done, type <TT>/quit</TT> to exit. You can also ");
- wprintf("type <TT>/help</TT> for more commands.\n");
-
- wprintf("<applet codebase=\"/static\" ");
- wprintf("code=\"wcchat\" width=2 height=2>\n");
- wprintf("<PARAM NAME=username VALUE=\"%s\">\n", WC->wc_username);
- wprintf("<PARAM NAME=password VALUE=\"%s\">\n", WC->wc_password);
- wprintf("<PARAM NAME=roomname VALUE=\"%s\">\n", WC->wc_roomname);
- wprintf("<H2>Oops!</H2>Looks like your browser doesn't support Java, ");
- wprintf("so you won't be able to access Chat. Sorry.\n");
- wprintf("</applet>\n");
- wDumpContent(1);
+ /** JavaScript function to alert the user that popups are probably blocked */
+ /** First, do the check as part of our page load. */
+ serv_puts("NOOP");
+ len = serv_getln(buf, sizeof buf);
+ if ((len >= 3) && (buf[3] == '*')) {
+ if ((time(NULL) - WC->last_pager_check) > 60) {
+ return 1;
+ }
+ }
+ return 0;
+ /* Then schedule it to happen again a minute from now if the user is idle. */
}
-/*
- *
- */
-void page_popup(void)
-{
- char buf[SIZ];
- char pagefrom[SIZ];
-
- /* suppress express message check, do headers but no fake frames */
- output_headers(0x08 | 0x03);
+void ajax_send_instant_message(void) {
+ char recp[256];
+ char buf[256];
- while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
+ safestrncpy(recp, bstr("recp"), sizeof recp);
- extract(pagefrom, &buf[4], 3);
+ serv_printf("SEXP %s|-", recp);
+ serv_getln(buf, sizeof buf);
- wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
- wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\""
- "<B>Express message from ");
- escputs(pagefrom);
- wprintf("</B></FONT></TD></TR></TABLE>\n");
-
- fmout(NULL);
+ if (buf[0] == '4') {
+ text_to_server(bstr("msg"));
+ serv_puts("000");
}
- wprintf("<CENTER>");
- wprintf("<A HREF=\"/display_page&closewin=yes&recp=");
- urlescputs(pagefrom);
- wprintf("\">[ reply ]</A> \n");
+ escputs(buf); /* doesn't really matter what we return - the client ignores it */
+}
- wprintf("<A HREF=\"javascript:window.close();\">"
- "[ close window ]</A></B>\n"
- "</CENTER>");
- wDumpContent(1);
- WC->HaveExpressMessages = 0;
+void
+InitModule_PAGING
+(void)
+{
+ WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0);
+ WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0);
+ WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX);
+ RegisterConditional("COND:PAGE:WAITING", 0, Conditional_PAGE_WAITING, CTX_NONE);
}
+void
+SessionDestroyModule_PAGING
+(wcsession *sess)
+{
+ /* nothing here anymore */
+}