]> code.citadel.org Git - citadel.git/commitdiff
* Added MSG4 support to client-side IPC
authorArt Cancro <ajc@citadel.org>
Tue, 3 Sep 2002 04:42:15 +0000 (04:42 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 3 Sep 2002 04:42:15 +0000 (04:42 +0000)
* Moved HTML-to-text conversion to the client side

citadel/ChangeLog
citadel/Makefile.in
citadel/citadel.c
citadel/citadel_decls.h
citadel/citadel_ipc.c
citadel/citadel_ipc.h
citadel/client_crypto.c
citadel/html.c
citadel/messages.c

index 832b4036d0ee0edf74c9264a029bc8bd1e94e165..a03f748c6d694b7e2943030839745443ece8ab23 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 591.108  2002/09/03 04:42:15  ajc
+ * Added MSG4 support to client-side IPC
+ * Moved HTML-to-text conversion to the client side
+
  Revision 591.107  2002/09/02 20:40:34  ajc
  * Automation work for setup
 
@@ -3959,4 +3963,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index fdfe60d44fb873f5ed55cf7ddab2b4e7300a1efc..e3bf0f17ebfb4112f8bb0cbd93ae16fb27ad752e 100644 (file)
@@ -110,11 +110,11 @@ serv_modules: $(SERV_MODULES)
 
 citadel$(EXEEXT): ipc_c_tcp.o citadel.o rooms.o routines.o \
        routines2.o messages.o screen.o citadel_ipc.o \
-       client_passwords.o md5.o client_crypto.o \
+       client_passwords.o md5.o client_crypto.o html.o \
        commands.o client_chat.o tools.o $(LIBOBJS)
        $(CC) ipc_c_tcp.o citadel.o rooms.o routines.o \
        routines2.o messages.o screen.o citadel_ipc.o \
-       commands.o client_chat.o tools.o \
+       commands.o client_chat.o tools.o html.o \
        client_passwords.o md5.o client_crypto.o \
        $(LIBOBJS) $(LDFLAGS) -o citadel $(LIBS)
 
index 3c767c2bc5827e56ad3829fc200a1efb65dc5996..a853289a5c18209d3c60e3aca9b1e466dc3a3222 100644 (file)
@@ -102,6 +102,7 @@ char curr_floor = 0;                /* number of current floor */
 char floorlist[128][SIZ];      /* names of floors */
 int termn8 = 0;                        /* Set to nonzero to cause a logoff */
 int secure;                    /* Set to nonzero when wire is encrypted */
+int can_do_msg4 = 0;           /* Set to nonzero if the server can handle MSG4 commands */
 
 extern char express_msgs;      /* express messages waiting! */
 extern int rc_ansi_color;      /* ansi color value from citadel.rc */
@@ -749,6 +750,11 @@ void get_serv_info(char *supplied_hostname)
                 (server_is_local ? "local" : CITADEL),
                 (supplied_hostname) ? supplied_hostname : "", buf);
                 /* (locate_host(buf), buf)); */
+
+       /* Tell the server what our preferred content formats are */
+       if ((CtdlIPCSpecifyPreferredFormats(buf, "text/html|text/plain") / 100 )== 2) {
+               can_do_msg4 = 1;
+       }
 }
 
 
@@ -763,7 +769,7 @@ void who_is_online(int longlist)
        char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
        char flags[SIZ];
        char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
-       char tbuf[SIZ], clientsoft[SIZ];
+       char clientsoft[SIZ];
        time_t timenow = 0;
        time_t idletime, idlehours, idlemins, idlesecs;
        int last_session = (-1);
index 005d6ac0eb701c455b6606fbaf3042cbf94a42bc..b66c8e1ff2a882ef30b2aa103742c37f845ad017 100644 (file)
@@ -29,3 +29,4 @@ void formout(char *name);
 void sighandler(int which_sig);
 void do_system_configuration(void);
 extern int secure;
+extern int can_do_msg4;
index 391649ff00f60d299c8c3d44bb088e65047f0ae5..85ad5b10f304a8e2933354e97edb05da583e7b95 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 #include "citadel.h"
 #include "citadel_ipc.h"
+#include "citadel_decls.h"
 #include "client_crypto.h"
 #include "tools.h"
 
@@ -393,10 +394,11 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime,
        if (!*mret) return -1;
        if (!msgnum) return -1;
 
-       sprintf(aaa, "MSG%c %ld|%d", as_mime ? '2' : '0', msgnum, headers);
+       strcpy(mret[0]->content_type, "");
+       sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
        ret = CtdlIPCGenericCommand(aaa, NULL, 0, &bbb, &bbbsize, cret);
        if (ret / 100 == 1) {
-               if (!as_mime) {
+               if (as_mime != 2) {
                        strcpy(mret[0]->mime_chosen, "1");      /* Default chosen-part is "1" */
                        while (strlen(bbb) > 4 && bbb[4] == '=') {
                                extract_token(aaa, bbb, 0, '\n');
@@ -481,6 +483,21 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime,
                        }
                        /* Eliminate "text\n" */
                        remove_token(bbb, 0, '\n');
+
+                       /* If doing a MIME thing, pull out the extra headers */
+                       if (as_mime == 4) {
+                               do {
+                                       if (!strncasecmp(bbb, "Content-type: ", 14)) {
+                                               extract_token(mret[0]->content_type, bbb, 0, '\n');
+                                               strcpy(mret[0]->content_type,
+                                                       &mret[0]->content_type[14]);
+                                               striplt(mret[0]->content_type);
+                                       }
+                                       remove_token(bbb, 0, '\n');
+                               } while ((bbb[0] != 0) && (bbb[0] != '\n'));
+                       }
+
+
                }
                if (strlen(bbb)) {
                        /* Strip trailing whitespace */
@@ -1860,6 +1877,18 @@ int CtdlIPCEndDownload(char *cret)
 }
 
 
+/* MSGP */
+int CtdlIPCSpecifyPreferredFormats(char *cret, char *formats) {
+       register int ret;
+       char cmd[SIZ];
+       
+       snprintf(cmd, sizeof cmd, "MSGP %s", formats);
+       ret = CtdlIPCGenericCommand(cmd, NULL, 0, NULL, NULL, cret);
+       return ret;
+}
+
+
+
 /* READ */
 int CtdlIPCReadDownload(void **buf, size_t bytes, char *cret)
 {
index f794bc90334747c8c4fe1d484df8f374c5563d34..565c6e541cc6d3f42843dd5e2ef9a0845baa67ec 100644 (file)
@@ -44,6 +44,7 @@ struct ctdlipcmessage {
        char nhdr;                      /* Suppress message header? */
        char anonymous;                 /* An anonymous message */
        char mime_chosen[SIZ];          /* Chosen MIME part to output */
+       char content_type[SIZ];         /* How would you like that? */
 };
 
 
@@ -149,6 +150,7 @@ int CtdlIPCRequestClientLogout(int session, char *cret);
 int CtdlIPCSetMessageSeen(long msgnum, int seen, char *cret);
 int CtdlIPCStartEncryption(char *cret);
 int CtdlIPCDirectoryLookup(const char *address, char *cret);
+int CtdlIPCSpecifyPreferredFormats(char *cret, char *formats);
 
 /* ************************************************************************** */
 /*             Stuff below this line is not for public consumption            */
index ec6ab2538a98173f204551e21f86e561fbc9030c..3da98af1d408df7b65eb8d3ecaf3b55b4be3dc62 100644 (file)
@@ -150,7 +150,7 @@ int starttls(void)
 {
 #ifdef HAVE_OPENSSL
        int a;
-       int r;                          /* IPC response code */
+       /* int r; */                            /* IPC response code */
        char buf[SIZ];
        SSL_METHOD *ssl_method;
        DH *dh;
@@ -276,6 +276,7 @@ int starttls(void)
                error_printf("Server can't start TLS: %s\n", buf);
                return 0;
        }
+
        /* New code
        r = CtdlIPCStartEncryption(buf);
        if (r / 100 != 2) {
index 2df7c78255356fb9dcda1c67d4c776d80e7be0e6..0a6686a17c58cfb1de86eb79b1eaece605ec5667 100644 (file)
@@ -98,6 +98,8 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
                        if (inbuf[i]==9) inbuf[i]=32;
                        if ((inbuf[i]<32) || (inbuf[i]>126))
                                strcpy(&inbuf[i], &inbuf[i+1]);
+                   }
+                   for (i=0; i<strlen(inbuf); ++i) {
                        while ((inbuf[i]==32)&&(inbuf[i+1]==32))
                                strcpy(&inbuf[i], &inbuf[i+1]);
                    }
@@ -244,7 +246,7 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
                            for (i = 0; i<strlen(outbuf); ++i) {
                                if ( (i<(screenwidth-2)) && (outbuf[i]=='\n')) {
                                        strncat(outptr, outbuf, i+1);
-                                       strcat(outptr, "\n");
+                                       /* strcat(outptr, "\n"); */
                                        if (do_citaformat)
                                                strcat(outptr, " ");
                                        strcpy(outbuf, &outbuf[i+1]);
@@ -279,7 +281,8 @@ char *html_to_ascii(char *inputmsg, int screenwidth, int do_citaformat) {
        } while (done_reading == 0);
 
        strcat(outptr, outbuf);
-       strcat(outptr, "\n");
+       striplt(outptr);
+       if (outptr[strlen(outptr)-1] != '\n') strcat(outptr, "\n");
 
        return outptr;
 
index fbbcdc6d413baa185a6b3396fc97967715ac39e1..cfd9aa41b07bc638dbc395517d85526611be6066 100644 (file)
 
 #include <stdarg.h>
 #include "citadel.h"
+#include "citadel_decls.h"
 #include "messages.h"
 #include "commands.h"
 #include "rooms.h"
 #include "tools.h"
+#include "html.h"
 #include "citadel_ipc.h"
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
@@ -363,6 +365,7 @@ int read_message(
        int nhdr = 0;
        struct ctdlipcmessage *message = NULL;
        int r;                          /* IPC response code */
+       char *converted_text = NULL;
 
        sigcaught = 0;
        sttybbs(1);
@@ -370,8 +373,9 @@ int read_message(
        strcpy(reply_to, NO_REPLY_TO);
        strcpy(reply_subject, "");
 
-       r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0), 0,
-                                   &message, buf);
+       r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0),
+                               (can_do_msg4 ? 4 : 0),
+                               &message, buf);
        if (r / 100 != 1) {
                err_printf("*** msg #%ld: %d %s\n", num, r, buf);
                ++lines_printed;
@@ -567,6 +571,22 @@ int read_message(
 
        /******* end of header output, start of message text output *******/
 
+       /*
+        * Convert HTML to plain text, formatting for the actual width
+        * of the client screen.
+        */
+       if (!strcasecmp(message->content_type, "text/html")) {
+               converted_text = html_to_ascii(message->text, screenwidth, 0);
+               if (converted_text != NULL) {
+                       free(message->text);
+                       message->text = converted_text;
+                       format_type = 1;
+               }
+       }
+
+       /*
+        * Here we go
+        */
        if (format_type == 0) {
                fr = fmout(screenwidth, NULL, message->text, dest,
                           ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);