* All OS-level includes are now included from webcit.h instead of from
[citadel.git] / webcit / paging.c
index bc3fc936ea56f112423abb1d5e4d0c410a3888a3..c202b3e7b6e3704315908190683b3d64263219f7 100644 (file)
@@ -4,29 +4,8 @@
  * Functions which implement the chat and paging facilities.
  */
 
-#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/poll.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"
 
-
 /*
  * display the form for paging (x-messaging) another user
  */
@@ -104,7 +83,7 @@ void page_user(void)
                wprintf("<EM>Message was not sent.</EM><br />\n");
        } else {
                serv_printf("SEXP %s|-", recp);
-               serv_gets(buf);
+               serv_getln(buf, sizeof buf);
 
                if (buf[0] == '4') {
                        text_to_server(bstr("msgtext"), 0);
@@ -137,7 +116,7 @@ void do_chat(void)
 
        /* First, check to make sure we're still allowed in this room. */
        serv_printf("GOTO %s", WC->wc_roomname);
-       serv_gets(buf);
+       serv_getln(buf, sizeof buf);
        if (buf[0] != '2') {
                smart_goto("_BASEROOM_");
                return;
@@ -167,9 +146,9 @@ void page_popup(void)
        char buf[SIZ];
        char pagefrom[SIZ];
 
-       while (serv_puts("GEXP"), serv_gets(buf), buf[0]=='1') {
+       while (serv_puts("GEXP"), serv_getln(buf, sizeof buf), buf[0]=='1') {
 
-               extract(pagefrom, &buf[4], 3);
+               extract_token(pagefrom, &buf[4], 3, '|', sizeof pagefrom);
 
                wprintf("<table border=1 bgcolor=\"#880000\"><tr><td>");
                wprintf("<span class=\"titlebar\">Instant message from ");
@@ -219,19 +198,19 @@ int setup_chat_socket(void) {
                WC->serv_sock = WC->chat_sock;
                WC->chat_sock = i;
 
-               serv_gets(buf);
+               serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
                        serv_printf("USER %s", WC->wc_username);
-                       serv_gets(buf);
+                       serv_getln(buf, sizeof buf);
                        if (buf[0] == '3') {
                                serv_printf("PASS %s", WC->wc_password);
-                               serv_gets(buf);
+                               serv_getln(buf, sizeof buf);
                                if (buf[0] == '2') {
                                        serv_printf("GOTO %s", WC->wc_roomname);
-                                       serv_gets(buf);
+                                       serv_getln(buf, sizeof buf);
                                        if (buf[0] == '2') {
                                                serv_puts("CHAT");
-                                               serv_gets(buf);
+                                               serv_getln(buf, sizeof buf);
                                                if (buf[0] == '8') {
                                                        good_chatmode = 1;
                                                }
@@ -268,10 +247,9 @@ void chat_recv(void) {
        char cl_text[SIZ];
        char *output_data = NULL;
 
-       lprintf(9, "chat_recv() called\n");
        output_headers(0, 0, 0, 0, 0, 0, 0);
 
-       wprintf("Content-type: text/html\n");
+       wprintf("Content-type: text/html; charset=utf-8\n");
        wprintf("\n");
        wprintf("<html>\n"
                "<head>\n"
@@ -304,7 +282,7 @@ void chat_recv(void) {
                        WC->serv_sock = WC->chat_sock;
                        WC->chat_sock = i;
        
-                       serv_gets(buf);
+                       serv_getln(buf, sizeof buf);
 
                        if (!strcmp(buf, "000")) {
                                strcpy(buf, ":|exiting chat mode");
@@ -325,7 +303,6 @@ void chat_recv(void) {
        } while ( (got_data) && (!end_chat_now) );
 
        if (end_chat_now) {
-               lprintf(9, "exiting chat\n");
                close(WC->chat_sock);
                WC->chat_sock = (-1);
                wprintf("<IMG SRC=\"/static/blank.gif\" onLoad=\"parent.window.close();\">\n");
@@ -338,15 +315,14 @@ void chat_recv(void) {
                }
 
                /* Output our fun to the other frame. */
-               lprintf(9, "output to other frame\n");
                wprintf("<IMG SRC=\"/static/blank.gif\" WIDTH=1 HEIGHT=1\n"
                        "onLoad=\" \n"
                );
 
                for (i=0; i<num_tokens(output_data, '\n'); ++i) {
-                       extract_token(buf, output_data, i, '\n');
-                       extract_token(cl_user, buf, 0, '|');
-                       extract_token(cl_text, buf, 1, '|');
+                       extract_token(buf, output_data, i, '\n', sizeof buf);
+                       extract_token(cl_user, buf, 0, '|', sizeof cl_user);
+                       extract_token(cl_text, buf, 1, '|', sizeof cl_text);
 
                        if (strcasecmp(cl_text, "NOOP")) {
 
@@ -400,7 +376,6 @@ void chat_recv(void) {
                }
 
                wprintf("parent.chat_transcript.scrollTo(999999,999999);\">\n");
-               lprintf(9, "done fun\n");
        }
 
        free(output_data);
@@ -419,7 +394,7 @@ void chat_send(void) {
        char buf[SIZ];
 
        output_headers(0, 0, 0, 0, 0, 0, 0);
-       wprintf("Content-type: text/html\n");
+       wprintf("Content-type: text/html; charset=utf-8\n");
        wprintf("\n");
        wprintf("<HTML>"
                "<BODY onLoad=\"document.chatsendform.send_this.focus();\" >"