$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
|| (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);
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));
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) {
}
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]);
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;
);
/* Convert it to base64 so it looks cool */
- encode_base64(buf, sourcebuf);
+ CtdlEncodeBase64(buf, sourcebuf, strlen(sourcebuf));
}
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;
}
}
else {
- encode_base64(buf, "Username:");
+ CtdlEncodeBase64(buf, "Username:", 9);
cprintf("334 %s\r\n", buf);
SMTP->command_state = smtp_user;
}
/*
- * 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;
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) {
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);