X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fpaging.c;h=2717d174799e4cb9a7b2d523424ebb0cf600b75c;hb=f6f51307f975c67d86448d5b456f9650dc36d773;hp=92b7351807d060fae7968b6e8a3d4cf4d9751b41;hpb=e739ac98b3d4ec499ac0221bb990b077947e9dd5;p=citadel.git diff --git a/webcit/paging.c b/webcit/paging.c index 92b735180..2717d1747 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -1,4 +1,8 @@ -/* $Id$ */ +/* + * $Id$ + * + * Functions which implement the chat and paging facilities. + */ #include #include @@ -32,10 +36,20 @@ void display_page(void) strcpy(recp, bstr("recp")); - output_headers(3); - - svprintf("BOXTITLE", WCS_STRING, "Page: %s", recp); - do_template("beginbox"); + output_headers(1, 1, 2, 0, 0, 0, 0); + wprintf("
\n" + "
" + "Send instant message" + "
\n" + "
\n
\n" + ); + + wprintf("
" + "
\n"); + + wprintf("Send an instant message to: "); + escputs(recp); + wprintf("
\n"); wprintf("
\n"); @@ -49,18 +63,18 @@ void display_page(void) escputs(bstr("closewin")); wprintf("\">\n"); - wprintf("Enter message text:
"); + wprintf("Enter message text:
"); wprintf("\n"); - wprintf("

\n"); + wprintf("
\n"); wprintf(""); - wprintf("
\n"); + wprintf("
\n"); wprintf("\n"); - do_template("endbox"); + wprintf("
\n"); wDumpContent(1); } @@ -74,14 +88,20 @@ void page_user(void) char buf[SIZ]; char closewin[SIZ]; - output_headers(3); - + output_headers(1, 1, 2, 0, 0, 0, 0); + wprintf("
\n" + "
" + "Add or edit an event" + "
\n" + "
\n
\n" + ); + strcpy(recp, bstr("recp")); strcpy(sc, bstr("sc")); strcpy(closewin, bstr("closewin")); if (strcmp(sc, "Send message")) { - wprintf("Message was not sent.
\n"); + wprintf("Message was not sent.
\n"); } else { serv_printf("SEXP %s|-", recp); serv_gets(buf); @@ -91,10 +111,10 @@ void page_user(void) serv_puts("000"); wprintf("Message has been sent to "); escputs(recp); - wprintf(".
\n"); + wprintf(".
\n"); } else { - wprintf("%s
\n", &buf[4]); + wprintf("%s
\n", &buf[4]); } } @@ -113,26 +133,29 @@ void page_user(void) */ void do_chat(void) { + char buf[SIZ]; - output_headers(1); - - wprintf("
" - "Real-time chat\n" - "
\n" - "\n" - "
\n" - "\n" - ); - wDumpContent(1); + /* First, check to make sure we're still allowed in this room. */ + serv_printf("GOTO %s", WC->wc_roomname); + serv_gets(buf); + if (buf[0] != '2') { + smart_goto("_BASEROOM_"); + return; + } + + /* If the chat socket is still open from a previous chat, + * close it -- because it might be stale or in the wrong room. + */ + if (WC->chat_sock < 0) { + close(WC->chat_sock); + WC->chat_sock = (-1); + } + + /* WebCit Chat works by having transmit, receive, and refresh + * frames. Load the frameset. + */ + do_template("chatframeset"); + return; } @@ -144,32 +167,24 @@ void page_popup(void) char buf[SIZ]; char pagefrom[SIZ]; - /* suppress express message check, do headers but no frames */ - output_headers(0x08 | 0x03); - while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') { extract(pagefrom, &buf[4], 3); - wprintf("" + "" + "
"); - wprintf("Instant message from "); + wprintf("
"); + wprintf("Instant message from "); escputs(pagefrom); - wprintf("
\n"); - + wprintf("
"); fmout(NULL, "LEFT"); + wprintf("
" + "
\n"); } - wprintf("
"); - wprintf("[ reply ]   \n"); - - wprintf("" - "[ close window ]\n" - "
"); - - wDumpContent(1); - WC->HaveExpressMessages = 0; + WC->HaveInstantMessages = 0; } @@ -185,10 +200,6 @@ int setup_chat_socket(void) { if (WC->chat_sock < 0) { - for (i=0; ichatlines[i], ""); - } - if (!strcasecmp(ctdlhost, "uds")) { /* unix domain socket */ sprintf(buf, "%s/citadel.socket", ctdlport); @@ -243,25 +254,30 @@ int setup_chat_socket(void) { /* - * receiving side of the chat window + * Receiving side of the chat window. This is implemented in a + * tiny hidden IFRAME that just does JavaScript writes to + * other frames whenever it refreshes and finds new data. */ void chat_recv(void) { int i; - char name[SIZ]; - char text[SIZ]; struct pollfd pf; int got_data = 0; int end_chat_now = 0; + char buf[SIZ]; + char cl_user[SIZ]; + char cl_text[SIZ]; + char *output_data = NULL; - output_headers(0); + output_headers(0, 0, 0, 0, 0, 0, 0); wprintf("Content-type: text/html\n"); wprintf("\n"); - wprintf("\n" - "\n" - "\n" - "\n" - "" + wprintf("\n" + "\n" + "\n" + "\n" + + "\n" ); if (setup_chat_socket() != 0) { @@ -273,6 +289,7 @@ void chat_recv(void) { /* * See if there is any chat data waiting. */ + output_data = strdup(""); do { got_data = 0; pf.fd = WC->chat_sock; @@ -281,57 +298,109 @@ void chat_recv(void) { if (poll(&pf, 1, 1) > 0) if (pf.revents & POLLIN) { ++got_data; - for (i=0; ichatlines[i], WC->chatlines[i+1]); - } - /* Temporarily swap the serv and chat sockets during chat talk */ i = WC->serv_sock; WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - serv_gets(WC->chatlines[CHATLINES-1]); - if (!strcmp(WC->chatlines[CHATLINES-1], "000")) { + serv_gets(buf); + + if (!strcmp(buf, "000")) { + strcpy(buf, ":|exiting chat mode"); end_chat_now = 1; - strcpy(WC->chatlines[CHATLINES-1], ":|exiting chat mode"); } /* Unswap the sockets. */ i = WC->serv_sock; WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - } - } while ( (got_data) && (!end_chat_now) ); - /* - * Display appropriately. - */ - for (i=0; ichatlines[i]) > 0) { - extract(name, WC->chatlines[i], 0); - extract(text, WC->chatlines[i], 1); - if (!strcasecmp(name, WC->wc_username)) { - wprintf(""); - } - else if (!strcmp(name, ":")) { - wprintf(""); - } - else { - wprintf(""); - } - escputs(name); - wprintf(": "); - escputs(text); - wprintf("
\n"); + /* Append our output data */ + output_data = realloc(output_data, strlen(output_data) + strlen(buf) + 4); + strcat(output_data, buf); + strcat(output_data, "\n"); } - } + + } while ( (got_data) && (!end_chat_now) ); if (end_chat_now) { close(WC->chat_sock); WC->chat_sock = (-1); - wprintf("\n"); + wprintf("\n"); + } + + if (strlen(output_data) > 0) { + + if (output_data[strlen(output_data)-1] == '\n') { + output_data[strlen(output_data)-1] = 0; + } + + /* Output our fun to the other frame. */ + wprintf("last_chat_user)) { + wprintf("" + "
" + ); + + } + + wprintf(""); + + wprintf("
"); + + if (!strcasecmp(cl_user, ":")) { + wprintf(""); + } + + if (strcasecmp(cl_user, WC->last_chat_user)) { + wprintf(""); + + if (!strcasecmp(cl_user, WC->wc_username)) { + wprintf(""); + } + else { + wprintf(""); + } + jsescputs(cl_user); + + wprintf(": "); + } + else { + wprintf("   "); + } + jsescputs(cl_text); + if (!strcasecmp(cl_user, ":")) { + wprintf(""); + } + + wprintf("
"); + wprintf("'); \n"); + + strcpy(WC->last_chat_user, cl_user); + } + } + + wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n"); } + free(output_data); + wprintf("\n"); wDumpContent(0); } @@ -343,8 +412,9 @@ void chat_recv(void) { void chat_send(void) { int i; char send_this[SIZ]; + char buf[SIZ]; - output_headers(0); + output_headers(0, 0, 0, 0, 0, 0, 0); wprintf("Content-type: text/html\n"); wprintf("\n"); wprintf("" @@ -360,6 +430,14 @@ void chat_send(void) { if (bstr("sendbutton") != NULL) { + if (!strcasecmp(bstr("sendbutton"), "Help")) { + strcpy(send_this, "/help"); + } + + if (!strcasecmp(bstr("sendbutton"), "List Users")) { + strcpy(send_this, "/who"); + } + if (!strcasecmp(bstr("sendbutton"), "Exit")) { strcpy(send_this, "/quit"); } @@ -375,7 +453,21 @@ void chat_send(void) { WC->serv_sock = WC->chat_sock; WC->chat_sock = i; - serv_puts(send_this); + while (strlen(send_this) > 0) { + if (strlen(send_this) < 67) { + serv_puts(send_this); + strcpy(send_this, ""); + } + else { + for (i=55; i<67; ++i) { + if (send_this[i] == ' ') break; + } + strncpy(buf, send_this, i); + buf[i] = 0; + strcpy(send_this, &send_this[i]); + serv_puts(buf); + } + } /* Unswap the sockets. */ i = WC->serv_sock; @@ -384,10 +476,13 @@ void chat_send(void) { } - wprintf("Send: "); wprintf("
\n"); - wprintf("\n"); + wprintf("\n", SIZ-10); + wprintf("
"); wprintf("\n"); + wprintf("\n"); + wprintf("\n"); wprintf("\n"); wprintf("
\n");