X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fpaging.c;h=bb6ad8e2f9774f6593dc56aeeeb425b68b4003e2;hb=a3ba94ad306d781296c53012f732f3a910015263;hp=3dee4f53319e9eca518ce0e03c59a0bda0eace54;hpb=40f1092858d2e65098518ce9ec6183d76ba69c19;p=citadel.git diff --git a/webcit/paging.c b/webcit/paging.c index 3dee4f533..bb6ad8e2f 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -1,14 +1,11 @@ /* * $Id$ */ -/** - * \defgroup PageFunc Functions which implement the chat and paging facilities. - */ -/*@{*/ + #include "webcit.h" -/** - * \brief display the form for paging (x-messaging) another user +/* + * display the form for paging (x-messaging) another user */ void display_page(void) { @@ -17,47 +14,44 @@ void display_page(void) strcpy(recp, bstr("recp")); output_headers(1, 1, 2, 0, 0, 0); - wprintf("
\n" - "
" - ""); - wprintf(_("Send instant message")); - wprintf("" - "
\n" - "
\n
\n" - ); - - wprintf("
" - "
\n"); - - wprintf(_("Send an instant message to: ")); - escputs(recp); - wprintf("
\n"); + wc_printf("
\n"); + wc_printf("

"); + wc_printf(_("Send instant message")); + wc_printf("

"); + wc_printf("
\n"); - wprintf("
\n"); + wc_printf("
\n"); - wprintf("
\n"); + wc_printf("
" + "
\n"); - wprintf("\n"); + wc_printf("
\n"); + + wc_printf("\n"); + wc_printf("\n", WC->nonce); + wc_printf("\n"); - wprintf("\n"); + wc_printf("
\n"); - wprintf(_("Enter message text:")); - wprintf("
"); + wc_printf("\n"); - wprintf("\n"); - wprintf("

\n"); + wc_printf("

\n"); - wprintf("", _("Send message")); - wprintf("
\n", _("Cancel")); + wc_printf("", _("Send message")); + wc_printf("
\n", _("Cancel")); - wprintf("\n"); - wprintf("
\n"); + wc_printf("\n"); + wc_printf("
\n"); wDumpContent(1); } @@ -66,51 +60,37 @@ void display_page(void) */ void page_user(void) { - char recp[SIZ]; - char buf[SIZ]; - char closewin[SIZ]; + char recp[256]; + char buf[256]; - output_headers(1, 1, 2, 0, 0, 0); - wprintf("
\n" - "
" - ""); - wprintf(_("Add or edit an event")); - wprintf("" - "
\n" - "
\n
\n" - ); - - strcpy(recp, bstr("recp")); - strcpy(closewin, bstr("closewin")); + safestrncpy(recp, bstr("recp"), sizeof recp); - if (strlen(bstr("send_button")) == 0) { - wprintf(""); - wprintf(_("Message was not sent.")); - wprintf("
\n"); + if (!havebstr("send_button")) { + safestrncpy(WC->ImportantMessage, + _("Message was not sent."), + sizeof WC->ImportantMessage + ); } else { serv_printf("SEXP %s|-", recp); serv_getln(buf, sizeof buf); if (buf[0] == '4') { - text_to_server(bstr("msgtext"), 0); + text_to_server(bstr("msgtext")); serv_puts("000"); - wprintf(""); - wprintf(_("Message has been sent to ")); - escputs(recp); - wprintf(".
\n"); + stresc(buf, 256, recp, 0, 0); + snprintf(WC->ImportantMessage, + sizeof WC->ImportantMessage, + "%s%s.", + _("Message has been sent to "), + buf + ); } else { - wprintf("%s
\n", &buf[4]); + safestrncpy(WC->ImportantMessage, &buf[4], sizeof WC->ImportantMessage); } } - - if (!strcasecmp(closewin, "yes")) { - wprintf("
"); - wprintf(_("[ close window ]")); - wprintf("
\n"); - } - wDumpContent(1); + url_do_template(); } @@ -123,10 +103,13 @@ void do_chat(void) char buf[SIZ]; /** First, check to make sure we're still allowed in this room. */ - serv_printf("GOTO %s", WC->wc_roomname); + serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name)); serv_getln(buf, sizeof buf); if (buf[0] != '2') { - smart_goto("_BASEROOM_"); + StrBuf *Buf; + Buf = NewStrBufPlain(HKEY("_BASEROOM_")); + smart_goto(Buf); + FreeStrBuf(&Buf); return; } @@ -145,7 +128,7 @@ void do_chat(void) * output by begin_ajax_response() happen to be the ones we need.) */ begin_ajax_response(); - do_template("chatframeset"); + do_template("chatframeset", NULL); end_ajax_response(); return; } @@ -156,57 +139,22 @@ void do_chat(void) * 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 page_popup(void) +int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP) { + int len; char buf[SIZ]; /** JavaScript function to alert the user that popups are probably blocked */ - wprintf("\n", - _("You have one or more instant messages waiting, but the Citadel Instant Messenger " - "window failed to open. This is probably because you have a popup blocker " - "installed. Please configure your popup blocker to allow popups from this site " - "if you wish to receive instant messages.") - ); - /** First, do the check as part of our page load. */ serv_puts("NOOP"); - serv_getln(buf, sizeof buf); - if (buf[3] == '*') { + len = serv_getln(buf, sizeof buf); + if ((len >= 3) && (buf[3] == '*')) { if ((time(NULL) - WC->last_pager_check) > 60) { - wprintf("" - ); + return 1; } } - + return 0; /** Then schedule it to happen again a minute from now if the user is idle. */ - wprintf(" " - ); } @@ -244,13 +192,13 @@ int setup_chat_socket(void) { serv_getln(buf, sizeof buf); if (buf[0] == '2') { - serv_printf("USER %s", WC->wc_username); + serv_printf("USER %s", ChrPtr(WC->wc_username)); serv_getln(buf, sizeof buf); if (buf[0] == '3') { - serv_printf("PASS %s", WC->wc_password); + serv_printf("PASS %s", ChrPtr(WC->wc_password)); serv_getln(buf, sizeof buf); if (buf[0] == '2') { - serv_printf("GOTO %s", WC->wc_roomname); + serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name)); serv_getln(buf, sizeof buf); if (buf[0] == '2') { serv_puts("CHAT"); @@ -294,9 +242,9 @@ void chat_recv(void) { output_headers(0, 0, 0, 0, 0, 0); - wprintf("Content-type: text/html; charset=utf-8\n"); - wprintf("\n"); - wprintf("\n" + hprintf("Content-type: text/html; charset=utf-8\r\n"); + begin_burst(); + wc_printf("\n" "\n" "\n" "\n" @@ -305,8 +253,8 @@ void chat_recv(void) { ); if (setup_chat_socket() != 0) { - wprintf(_("An error occurred while setting up the chat socket.")); - wprintf("\n"); + wc_printf(_("An error occurred while setting up the chat socket.")); + wc_printf("\n"); wDumpContent(0); return; } @@ -320,7 +268,7 @@ void chat_recv(void) { pf.fd = WC->chat_sock; pf.events = POLLIN; pf.revents = 0; - if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) { + if ((poll(&pf, 1, 1) > 0) && (pf.revents & POLLIN)) { ++got_data; /** Temporarily swap the serv and chat sockets during chat talk */ @@ -352,17 +300,18 @@ void chat_recv(void) { if (end_chat_now) { close(WC->chat_sock); WC->chat_sock = (-1); - wprintf("\n"); + wc_printf("\n"); } - if (strlen(output_data) > 0) { - - if (output_data[strlen(output_data)-1] == '\n') { - output_data[strlen(output_data)-1] = 0; + if (!IsEmptyStr(output_data)) { + int len; + len = strlen(output_data); + if (output_data[len-1] == '\n') { + output_data[len-1] = 0; } /** Output our fun to the other frame. */ - wprintf("last_chat_user)) { - wprintf("" "
" @@ -384,50 +333,50 @@ void chat_recv(void) { } - wprintf(""); - wprintf("
"); + wc_printf("
"); if (!strcasecmp(cl_user, ":")) { - wprintf(""); + wc_printf(""); } if (strcasecmp(cl_user, WC->last_chat_user)) { - wprintf(""); + wc_printf(""); - if (!strcasecmp(cl_user, WC->wc_fullname)) { - wprintf(""); + if (!strcasecmp(cl_user, ChrPtr(WC->wc_fullname))) { + wc_printf(""); } else { - wprintf(""); + wc_printf(""); } jsescputs(cl_user); - wprintf(": "); + wc_printf(": "); } else { - wprintf("   "); + wc_printf("   "); } jsescputs(cl_text); if (!strcasecmp(cl_user, ":")) { - wprintf(""); + wc_printf(""); } - wprintf("
"); - wprintf("'); \n"); + wc_printf(""); + wc_printf("'); \n"); strcpy(WC->last_chat_user, cl_user); } } - wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n"); + wc_printf("parent.chat_transcript.scrollTo(999999,999999);\">\n"); } free(output_data); - wprintf("\n"); + wc_printf("\n"); wDumpContent(0); } @@ -441,34 +390,34 @@ void chat_send(void) { char buf[SIZ]; output_headers(0, 0, 0, 0, 0, 0); - wprintf("Content-type: text/html; charset=utf-8\n"); - wprintf("\n"); - wprintf("" + hprintf("Content-type: text/html; charset=utf-8\r\n"); + begin_burst(); + wc_printf("" "" ); - if (bstr("send_this") != NULL) { + if (havebstr("send_this")) { strcpy(send_this, bstr("send_this")); } else { strcpy(send_this, ""); } - if (strlen(bstr("help_button")) > 0) { + if (havebstr("help_button")) { strcpy(send_this, "/help"); } - if (strlen(bstr("list_button")) > 0) { + if (havebstr("list_button")) { strcpy(send_this, "/who"); } - if (strlen(bstr("exit_button")) > 0) { + if (havebstr("exit_button")) { strcpy(send_this, "/quit"); } if (setup_chat_socket() != 0) { - wprintf(_("An error occurred while setting up the chat socket.")); - wprintf("\n"); + wc_printf(_("An error occurred while setting up the chat socket.")); + wc_printf("\n"); wDumpContent(0); return; } @@ -478,7 +427,7 @@ void chat_send(void) { WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - while (strlen(send_this) > 0) { + while (!IsEmptyStr(send_this)) { if (strlen(send_this) < 67) { serv_puts(send_this); strcpy(send_this, ""); @@ -499,18 +448,58 @@ void chat_send(void) { WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - wprintf("
\n"); - wprintf("\n"); + wc_printf("\n", WC->nonce); + wc_printf("\n", SIZ-10); - wprintf("
"); - wprintf("\n", _("Send")); - wprintf("\n", _("Help")); - wprintf("\n", _("List users")); - wprintf("\n", _("Exit")); - wprintf("
\n"); - - wprintf("\n"); + wc_printf("
"); + wc_printf("\n", _("Send")); + wc_printf("\n", _("Help")); + wc_printf("\n", _("List users")); + wc_printf("\n", _("Exit")); + wc_printf("\n"); + + wc_printf("\n"); wDumpContent(0); } -/*@}*/ + +void ajax_send_instant_message(void) { + char recp[256]; + char buf[256]; + + safestrncpy(recp, bstr("recp"), sizeof recp); + + serv_printf("SEXP %s|-", recp); + serv_getln(buf, sizeof buf); + + if (buf[0] == '4') { + text_to_server(bstr("msg")); + serv_puts("000"); + } + + escputs(buf); /* doesn't really matter what we return - the client ignores it */ +} + + +void +InitModule_PAGING +(void) +{ + WebcitAddUrlHandler(HKEY("display_page"), "", 0, display_page, 0); + WebcitAddUrlHandler(HKEY("page_user"), "", 0, page_user, 0); + WebcitAddUrlHandler(HKEY("chat"), "", 0, do_chat, 0); + WebcitAddUrlHandler(HKEY("chat_recv"), "", 0, chat_recv, 0); + WebcitAddUrlHandler(HKEY("chat_send"), "", 0, chat_send, 0); + WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), "", 0, ajax_send_instant_message, AJAX); + RegisterConditional(HKEY("COND:PAGE:WAITING"), 0, Conditional_PAGE_WAITING, CTX_NONE); +} + + +void +SessionDestroyModule_CHAT +(wcsession *sess) +{ + if (sess->chat_sock > 0) + close(sess->chat_sock); +}