]> code.citadel.org Git - citadel.git/commitdiff
* CtdlWriteObject() encode in memory instead of on disk (not tested)
authorArt Cancro <ajc@citadel.org>
Wed, 16 Oct 2002 02:49:56 +0000 (02:49 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 16 Oct 2002 02:49:56 +0000 (02:49 +0000)
citadel/ChangeLog
citadel/client_passwords.c
citadel/msgbase.c
citadel/serv_imap.c
citadel/serv_listsub.c
citadel/serv_smtp.c
citadel/tools.c
citadel/tools.h

index e2c8e543fd339a802cc41c1a3b60c031363d434c..0e107aff3cbd26ec5591baba2a645adf14f53cd3 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 601.29  2002/10/16 02:49:55  ajc
+ * CtdlWriteObject() encode in memory instead of on disk (not tested)
+
  Revision 601.28  2002/10/15 17:41:20  ajc
  * Numerous warning fixes and cleanups for compile on Linux for IBM S/390
  * Name temp files with source code location of who created them
@@ -4080,3 +4083,4 @@ 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 d755f363b86067c56126a867ec27005b93de6054..23d2e84c11000319cdf809d816064aba9d2b10c9 100644 (file)
@@ -108,14 +108,14 @@ void set_stored_password(
                   || (strcasecmp(portbuf, port)) ) {
                        snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
                                hostbuf, portbuf, ubuf, pbuf);
-                       encode_base64(buf64, buf);
+                       CtdlEncodeBase64(buf64, buf, strlen(buf));
                        fprintf(fp, "%s\n", buf64);
                }
        }
        if (strlen(username) > 0) {
                snprintf(buf, sizeof buf, "%s|%s|%s|%s|",
                        host, port, username, password);
-               encode_base64(buf64, buf);
+               CtdlEncodeBase64(buf64, buf, strlen(buf));
                fprintf(fp, "%s\n", buf64);
        }
        fclose(oldfp);
index f8391787761db6e3afbdee69ed215bf87bdc6e76..afa4d455435832b874ad2b35d6552484eca09ede 100644 (file)
@@ -2974,43 +2974,71 @@ void CtdlWriteObject(char *req_room,            /* Room to stuff it in */
        struct CtdlMessage *msg;
        size_t len;
 
+       char *raw_message = NULL;
+       char *encoded_message = NULL;
+       off_t raw_length = 0;
+
        if (is_mailbox != NULL)
                MailboxName(roomname, sizeof roomname, is_mailbox, req_room);
        else
                safestrncpy(roomname, req_room, sizeof(roomname));
        lprintf(9, "CtdlWriteObject() to <%s> (flags=%d)\n", roomname, flags);
 
-       strcpy(filename, tmpnam(NULL));
-       fp = fopen(filename, "w");
-       if (fp == NULL)
-               return;
 
-       tempfp = fopen(tempfilename, "r");
-       if (tempfp == NULL) {
-               fclose(fp);
-               unlink(filename);
+       fp = fopen(tempfilename, "rb");
+       if (fp == NULL) {
+               lprintf(5, "Cannot open %s: %s\n",
+                       tempfilename, strerror(errno));
                return;
        }
+       fseek(fp, 0L, SEEK_END);
+       raw_length = ftell(fp);
+       rewind(fp);
+       lprintf(9, "Raw length is %ld\n", (long)raw_length);
 
-       fprintf(fp, "Content-type: %s\n", content_type);
-       lprintf(9, "Content-type: %s\n", content_type);
+       raw_message = mallok((size_t)raw_length);
+       fread(raw_message, (size_t)raw_length, 1, fp);
+       fclose(fp);
 
-       if (is_binary == 0) {
-               fprintf(fp, "Content-transfer-encoding: 7bit\n\n");
-               while (ch = getc(tempfp), ch > 0)
-                       putc(ch, fp);
-               fclose(tempfp);
-               putc(0, fp);
-               fclose(fp);
-       } else {
-               fprintf(fp, "Content-transfer-encoding: base64\n\n");
-               fclose(tempfp);
-               fclose(fp);
-               snprintf(cmdbuf, sizeof cmdbuf, "./base64 -e <%s >>%s",
-                       tempfilename, filename);
-               system(cmdbuf);
+       if (is_binary) {
+               encoded_message = mallok((size_t)
+                       (((raw_length * 134) / 100) + 4096 ) );
+       }
+       else {
+               encoded_message = mallok((size_t)(raw_length + 4096));
+       }
+
+       sprintf(encoded_message, "Content-type: %s\n", content_type);
+
+       if (is_binary) {
+               sprintf(&encoded_message[strlen(encoded_message)],
+                       "Content-transfer-encoding: base64\n\n"
+               );
+       }
+       else {
+               sprintf(&encoded_message[strlen(encoded_message)],
+                       "Content-transfer-encoding: 7bit\n\n"
+               );
        }
 
+       if (is_binary) {
+               CtdlEncodeBase64(
+                       &encoded_message[strlen(encoded_message)],
+                       raw_message,
+                       (int)raw_length
+               );
+       }
+       else {
+               raw_message[raw_length] = 0;
+               memcpy(
+                       &encoded_message[strlen(encoded_message)],
+                       raw_message,
+                       (int)(raw_length+1)
+               );
+       }
+
+       phree(raw_message);
+
        lprintf(9, "Allocating\n");
        msg = mallok(sizeof(struct CtdlMessage));
        memset(msg, 0, sizeof(struct CtdlMessage));
@@ -3023,15 +3051,7 @@ void CtdlWriteObject(char *req_room,             /* Room to stuff it in */
        msg->cm_fields['H'] = strdoop(config.c_humannode);
        msg->cm_flags = flags;
        
-       lprintf(9, "Loading\n");
-       fp = fopen(filename, "rb");
-       fseek(fp, 0L, SEEK_END);
-       len = ftell(fp);
-       rewind(fp);
-       msg->cm_fields['M'] = mallok(len);
-       fread(msg->cm_fields['M'], len, 1, fp);
-       fclose(fp);
-       unlink(filename);
+       msg->cm_fields['M'] = encoded_message;
 
        /* Create the requested room if we have to. */
        if (getroom(&qrbuf, roomname) != 0) {
index 5d9e119ef34228e3193696590fbc2242727dc41a..3e21b8cadde0e787629e676527dc456775682e2d 100644 (file)
@@ -299,7 +299,7 @@ void imap_authenticate(int num_parms, char *parms[]) {
        }
 
        if (!strcasecmp(parms[2], "LOGIN")) {
-               encode_base64(buf, "Username:");
+               CtdlEncodeBase64(buf, "Username:", 9);
                cprintf("+ %s\r\n", buf);
                IMAP->authstate = imap_as_expecting_username;
                strcpy(IMAP->authseq, parms[0]);
@@ -317,7 +317,7 @@ void imap_auth_login_user(char *cmd) {
 
        CtdlDecodeBase64(buf, cmd, SIZ);
        CtdlLoginExistingUser(buf);
-       encode_base64(buf, "Password:");
+       CtdlEncodeBase64(buf, "Password:", 9);
        cprintf("+ %s\r\n", buf);
        IMAP->authstate = imap_as_expecting_password;
        return;
index 7fdee6b0b133865253063d15c7ae2c7cc0ca8812..31265508845feb775c49fd2128c2d27fb28d7977 100644 (file)
@@ -73,7 +73,7 @@ void listsub_generate_token(char *buf) {
        );
 
        /* Convert it to base64 so it looks cool */     
-       encode_base64(buf, sourcebuf);
+       CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf));
 }
 
 
index 383e05194dde4f4504989bf9d7988224ab4dc938..3d9dc248cdefb755ab862f53f0a5bb180dcbe078 100644 (file)
@@ -167,7 +167,7 @@ void smtp_get_user(char *argbuf) {
        CtdlDecodeBase64(username, argbuf, SIZ);
        lprintf(9, "Trying <%s>\n", username);
        if (CtdlLoginExistingUser(username) == login_ok) {
-               encode_base64(buf, "Password:");
+               CtdlEncodeBase64(buf, "Password:", 9);
                cprintf("334 %s\r\n", buf);
                SMTP->command_state = smtp_password;
        }
@@ -215,7 +215,7 @@ void smtp_auth(char *argbuf) {
        }
 
        else {
-               encode_base64(buf, "Username:");
+               CtdlEncodeBase64(buf, "Username:", 9);
                cprintf("334 %s\r\n", buf);
                SMTP->command_state = smtp_user;
        }
index 049987bd4ea4f901b1aee0561059b68fbac2c1e9..64e790c881a76aca24d709149367efbdc83a13d3 100644 (file)
@@ -254,14 +254,13 @@ long extract_long(char *source, long int parmnum)
 
 
 /*
- * CtdlDecodeBase64() and encode_base64() are adaptations of code by
+ * CtdlDecodeBase64() and CtdlEncodeBase64() are adaptations of code by
  * John Walker, found in full in the file "base64.c" included with this
- * distribution.  The difference between those functions and these is that
- * these are intended to encode/decode small string buffers, and those are
- * intended to encode/decode entire MIME parts.
+ * distribution.  We are moving in the direction of eventually discarding
+ * the separate executables, and using the ones in our code exclusively.
  */
 
-void encode_base64(char *dest, char *source)
+void CtdlEncodeBase64(char *dest, char *source, int sourcelen)
 {
     int i, hiteof = FALSE;
     int spos = 0;
@@ -285,11 +284,11 @@ void encode_base64(char *dest, char *source)
 
        igroup[0] = igroup[1] = igroup[2] = 0;
        for (n = 0; n < 3; n++) {
-           c = source[spos++];
-           if (c == 0) {
+           if (spos >= sourcelen) {
                hiteof = TRUE;
                break;
            }
+           c = source[spos++];
            igroup[n] = (byte) c;
        }
        if (n > 0) {
index 9dda38cae65d18e9f931fa7f64ed67ea2aff9c0e..7e199a191f6d8650b7ee88b7ccb860b87cd6acbc 100644 (file)
@@ -4,7 +4,7 @@ int num_tokens (char *source, char tok);
 void extract_token(char *dest, char *source, int parmnum, char separator);
 int extract_int (char *source, int parmnum);
 long int extract_long (char *source, long int parmnum);
-void encode_base64(char *dest, char *source);
+void CtdlEncodeBase64(char *dest, char *source, int sourcelen);
 int CtdlDecodeBase64(char *dest, char *source, size_t length);
 void striplt(char *);
 int haschar(const char *st, int ch);