From 4cf84102a77010569414eeb57e64275e407db6a4 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 18 Jan 2005 17:58:38 +0000 Subject: [PATCH] * Trying to fix IMAP brokenness on Linux-x64. Committing changes even though there are a lot of annoying trace messages in this tree, because I did clean up a bunch of stuff here and there. --- citadel/ChangeLog | 6 ++ citadel/citadel.c | 4 +- citadel/imap_fetch.c | 136 +++++++++++++++++++++++++++++-------------- citadel/imap_misc.c | 12 ++-- citadel/imap_tools.c | 22 ------- citadel/msgbase.c | 80 +++++++++++++++---------- citadel/serv_imap.c | 12 ++-- citadel/serv_imap.h | 6 +- citadel/sysdep.c | 2 +- citadel/tools.c | 20 ++++--- citadel/tools.h | 14 ++--- 11 files changed, 186 insertions(+), 128 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 5da4aa15f..060128543 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,9 @@ $Log$ + Revision 629.6 2005/01/18 17:58:38 ajc + * Trying to fix IMAP brokenness on Linux-x64. Committing changes even + though there are a lot of annoying trace messages in this tree, because + I did clean up a bunch of stuff here and there. + Revision 629.5 2005/01/14 17:08:30 ajc * Applied a configure script fix sent in by David Given for more reliable detection of the installed libical version. @@ -6272,3 +6277,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citadel.c b/citadel/citadel.c index bd3fbf24a..336957be5 100644 --- a/citadel/citadel.c +++ b/citadel/citadel.c @@ -849,7 +849,7 @@ char *SortOnlineUsers(char *listing) { for (i=0; icached_fetch; } - else if ((IMAP->cached_fetch != NULL) && (IMAP->cached_msgnum != msgnum)) { + else if (IMAP->cached_fetch != NULL) { /* Some other message is cached -- free it */ fclose(IMAP->cached_fetch); IMAP->cached_fetch == NULL; IMAP->cached_msgnum = (-1); - tmp = NULL; } /* At this point, we now can fetch and convert the message iff it's not @@ -154,12 +153,16 @@ void imap_fetch_rfc822(long msgnum, char *whichfmt) { } /* - * Load the message into a temp file for translation - * and measurement - */ + * Load the message into a temp file for translation + * and measurement + */ + TRACE; CtdlRedirectOutput(tmp, -1); + TRACE; CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ALL, 0, 1); + TRACE; CtdlRedirectOutput(NULL, -1); + TRACE; IMAP->cached_fetch = tmp; IMAP->cached_msgnum = msgnum; @@ -183,6 +186,8 @@ void imap_fetch_rfc822(long msgnum, char *whichfmt) { fseek(tmp, 0L, SEEK_END); total_size = ftell(tmp); text_size = total_size - headers_size; + lprintf(CTDL_DEBUG, "RFC822: headers=%ld, text=%ld, total=%ld\n", + headers_size, text_size, total_size); if (!strcasecmp(whichfmt, "RFC822.SIZE")) { cprintf("RFC822.SIZE %ld", total_size); @@ -205,11 +210,11 @@ void imap_fetch_rfc822(long msgnum, char *whichfmt) { } cprintf("%s {%ld}\r\n", whichfmt, bytes_remaining); - blocksize = sizeof(buf); + blocksize = (long)sizeof(buf); while (bytes_remaining > 0L) { if (blocksize > bytes_remaining) blocksize = bytes_remaining; - fread(buf, blocksize, 1, tmp); - client_write(buf, blocksize); + fread(buf, (size_t)blocksize, 1, tmp); + client_write(buf, (int)blocksize); bytes_remaining = bytes_remaining - blocksize; } @@ -231,7 +236,7 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp, void *cbuserdata) { struct imap_fetch_part *imfp; - char mbuf2[1024]; + char mbuf2[SIZ]; imfp = (struct imap_fetch_part *)cbuserdata; @@ -272,7 +277,7 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp, * really need to make this suck less. */ void imap_output_envelope_from(struct CtdlMessage *msg) { - char user[1024], node[1024], name[1024]; + char user[SIZ], node[SIZ], name[SIZ]; /* For anonymous messages, it's so easy! */ if (!is_room_aide() && (msg->cm_anon_type == MES_ANONONLY)) { @@ -450,7 +455,7 @@ void imap_fetch_envelope(long msgnum, struct CtdlMessage *msg) { * then boil it down to just the fields we want. */ void imap_strip_headers(FILE *fp, char *section) { - char buf[1024]; + char buf[SIZ]; char *which_fields = NULL; int doing_headers = 0; int headers_not = 0; @@ -530,11 +535,10 @@ void imap_strip_headers(FILE *fp, char *section) { */ void imap_fetch_body(long msgnum, char *item, int is_peek) { struct CtdlMessage *msg = NULL; - char section[1024]; - char partial[1024]; + char section[SIZ]; + char partial[SIZ]; int is_partial = 0; - char buf[1024]; - int i; + char buf[SIZ]; FILE *tmp = NULL; long bytes_remaining = 0; long blocksize; @@ -542,14 +546,11 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) { struct imap_fetch_part imfp; /* extract section */ - strcpy(section, item); - for (i=0; i') partial[i] = 0; + safestrncpy(partial, item, sizeof partial); + if (strchr(partial, '<') != NULL) { + stripallbut(partial, '<', '>'); + is_partial = 1; } if (is_partial == 0) strcpy(partial, ""); if (strlen(partial) > 0) lprintf(CTDL_DEBUG, "Partial is %s\n", partial); @@ -585,25 +581,37 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) { return; } msg = CtdlFetchMessage(msgnum, 1); +TRACE; } /* Now figure out what the client wants, and get it */ +TRACE; if (IMAP->cached_body != NULL) { tmp = IMAP->cached_body; +TRACE; } else if ( (!strcmp(section, "1")) && (msg->cm_format_type != 4) ) { +TRACE; CtdlRedirectOutput(tmp, -1); CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, HEADERS_NONE, 0, 1); CtdlRedirectOutput(NULL, -1); +TRACE; } else if (!strcmp(section, "")) { +TRACE; CtdlRedirectOutput(tmp, -1); +TRACE; + lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n"); + lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") ); + lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, HEADERS_ALL, 0, 1); +TRACE; CtdlRedirectOutput(NULL, -1); +TRACE; } /* @@ -611,9 +619,15 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) { * fields, strip it down. */ else if (!strncasecmp(section, "HEADER", 6)) { +TRACE; CtdlRedirectOutput(tmp, -1); +TRACE; + lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n"); + lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") ); + lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, HEADERS_ONLY, 0, 1); +TRACE; CtdlRedirectOutput(NULL, -1); imap_strip_headers(tmp, section); } @@ -623,9 +637,14 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) { */ else if (!strncasecmp(section, "TEXT", 4)) { CtdlRedirectOutput(tmp, -1); + lprintf(CTDL_DEBUG, "calling CtdlOutputPreLoadedMsg()\n"); + lprintf(CTDL_DEBUG, "msg %s null\n", ((msg == NULL) ? "is" : "is not") ); + lprintf(CTDL_DEBUG, "msgnum is %ld\n", msgnum); CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, HEADERS_NONE, 0, 1); +TRACE; CtdlRedirectOutput(NULL, -1); +TRACE; } /* @@ -633,57 +652,83 @@ void imap_fetch_body(long msgnum, char *item, int is_peek) { * (Note value of 1 passed as 'dont_decode' so client gets it encoded) */ else { +TRACE; safestrncpy(imfp.desired_section, section, sizeof(imfp.desired_section)); +TRACE; imfp.output_fp = tmp; +TRACE; mime_parser(msg->cm_fields['M'], NULL, *imap_load_part, NULL, NULL, (void *)&imfp, 1); +TRACE; } +TRACE; fseek(tmp, 0L, SEEK_END); +TRACE; bytes_remaining = ftell(tmp); +TRACE; if (is_partial == 0) { +TRACE; rewind(tmp); cprintf("BODY[%s] {%ld}\r\n", section, bytes_remaining); +TRACE; } else { +TRACE; sscanf(partial, "%ld.%ld", &pstart, &pbytes); if ((bytes_remaining - pstart) < pbytes) { pbytes = bytes_remaining - pstart; } +TRACE; fseek(tmp, pstart, SEEK_SET); +TRACE; bytes_remaining = pbytes; +TRACE; cprintf("BODY[%s]<%ld> {%ld}\r\n", section, pstart, bytes_remaining); } +TRACE; - blocksize = sizeof(buf); + blocksize = (long)sizeof(buf); +TRACE; while (bytes_remaining > 0L) { +TRACE; if (blocksize > bytes_remaining) blocksize = bytes_remaining; +TRACE; fread(buf, blocksize, 1, tmp); - client_write(buf, blocksize); +TRACE; + client_write(buf, (int)blocksize); +TRACE; bytes_remaining = bytes_remaining - blocksize; +TRACE; } +TRACE; /* Don't close it ... cache it! */ /* fclose(tmp); */ +TRACE; IMAP->cached_body = tmp; IMAP->cached_bodymsgnum = msgnum; strcpy(IMAP->cached_bodypart, section); +TRACE; if (msg != NULL) { +TRACE; CtdlFreeMessage(msg); } /* Mark this message as "seen" *unless* this is a "peek" operation */ +TRACE; if (is_peek == 0) { CtdlSetSeen(msgnum, 1, ctdlsetseen_seen); } +TRACE; } /* @@ -839,7 +884,7 @@ void imap_fetch_bodystructure_part( void imap_fetch_bodystructure (long msgnum, char *item, struct CtdlMessage *msg) { FILE *tmp; - char buf[1024]; + char buf[SIZ]; long lines = 0L; long start_of_body = 0L; long body_bytes = 0L; @@ -896,6 +941,11 @@ void imap_do_fetch_msg(int seq, int i; struct CtdlMessage *msg = NULL; + lprintf(CTDL_DEBUG, "imap_do_fetch_msg(%d, %d)\n", seq, num_items); + for (i=0; i= 2) { extract_token(histr, setstr, 1, ':'); - if (!strcmp(histr, "*")) snprintf(histr, sizeof histr, "%d", INT_MAX); + if (!strcmp(histr, "*")) snprintf(histr, sizeof histr, "%ld", LONG_MAX); } else { strcpy(histr, lostr); } - lo = atoi(lostr); - hi = atoi(histr); + lo = atol(lostr); + hi = atol(histr); /* Loop through the array, flipping bits where appropriate */ for (i = 1; i <= IMAP->num_msgs; ++i) { @@ -1185,7 +1235,7 @@ void imap_pick_range(char *supplied_range, int is_uid) { * This function is called by the main command loop. */ void imap_fetch(int num_parms, char *parms[]) { - char items[SIZ]; /* was 1024 */ + char items[SIZ]; char *itemlist[SIZ]; int num_items; int i; @@ -1217,7 +1267,7 @@ void imap_fetch(int num_parms, char *parms[]) { * This function is called by the main command loop. */ void imap_uidfetch(int num_parms, char *parms[]) { - char items[SIZ]; /* was 1024 */ + char items[SIZ]; char *itemlist[SIZ]; int num_items; int i; diff --git a/citadel/imap_misc.c b/citadel/imap_misc.c index b4299c583..5bf63ff6b 100644 --- a/citadel/imap_misc.c +++ b/citadel/imap_misc.c @@ -210,9 +210,9 @@ void imap_print_instant_messages(void) { * This function is called by the main command loop. */ void imap_append(int num_parms, char *parms[]) { - size_t literal_length; - size_t bytes_transferred; - size_t stripped_length = 0; + long literal_length; + long bytes_transferred; + long stripped_length = 0; struct CtdlMessage *msg; int ret = 0; size_t blksize; @@ -234,7 +234,7 @@ void imap_append(int num_parms, char *parms[]) { return; } - literal_length = (size_t) atol(&parms[num_parms-1][1]); + literal_length = atol(&parms[num_parms-1][1]); if (literal_length < 1) { cprintf("%s BAD Message length must be at least 1.\r\n", parms[0]); @@ -250,7 +250,7 @@ void imap_append(int num_parms, char *parms[]) { IMAP->transmitted_length = literal_length; cprintf("+ Transmit message now.\r\n"); - lprintf(CTDL_DEBUG, "imap_append() expecting %d bytes\n", + lprintf(CTDL_DEBUG, "imap_append() expecting %ld bytes\n", literal_length); bytes_transferred = 0; @@ -267,7 +267,7 @@ void imap_append(int num_parms, char *parms[]) { else { bytes_transferred += blksize; /* keep going */ } - lprintf(CTDL_DEBUG, "Received %d of %d bytes (%d%%)\n", + lprintf(CTDL_DEBUG, "Received %ld of %ld bytes (%ld%%)\n", bytes_transferred, literal_length, ((bytes_transferred * 100) / literal_length) diff --git a/citadel/imap_tools.c b/citadel/imap_tools.c index 024f872e8..abb75b666 100644 --- a/citadel/imap_tools.c +++ b/citadel/imap_tools.c @@ -43,21 +43,6 @@ static void string_init(struct string* s, char* buf, int bufsize) s->size = strlen(buf); } -static int string_overflow(struct string* s) -{ - return (s->size == s->maxsize); -} - -static int string_length(struct string* s) -{ - return s->size; -} - -static char* string_ptr(struct string* s) -{ - return s->buffer; -} - static char* string_end(struct string* s) { return s->buffer + s->size; @@ -126,13 +111,6 @@ static void string_append_c(struct string* s, int c) string_append_sn(s, buf, len); } -/* Append another string structure. */ - -static void string_append(struct string* dest, struct string* src) -{ - string_append_sn(dest, src->buffer, src->size); -} - /* Reads a UTF8 character from a char*, advancing the pointer. */ int utf8_getc(char** ptr) diff --git a/citadel/msgbase.c b/citadel/msgbase.c index c6f0233cd..ec06acaca 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -833,7 +833,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body) if (field_length == 0) break; field_header = *mptr++; - ret->cm_fields[field_header] = malloc(field_length); + ret->cm_fields[field_header] = malloc(field_length + 1); strcpy(ret->cm_fields[field_header], mptr); while (*mptr++ != 0); /* advance to next field */ @@ -1070,14 +1070,12 @@ int CtdlOutputMsg(long msg_num, /* message number (local) to fetch */ int do_proto, /* do Citadel protocol responses? */ int crlf /* Use CRLF newlines instead of LF? */ ) { - struct CtdlMessage *TheMessage; - int retcode; + struct CtdlMessage *TheMessage = NULL; + int retcode = om_no_such_msg; lprintf(CTDL_DEBUG, "CtdlOutputMsg() msgnum=%ld, mode=%d\n", msg_num, mode); - TheMessage = NULL; - if ((!(CC->logged_in)) && (!(CC->internal_pgm))) { if (do_proto) cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN); @@ -1104,10 +1102,12 @@ int CtdlOutputMsg(long msg_num, /* message number (local) to fetch */ return(om_no_such_msg); } + TRACE; retcode = CtdlOutputPreLoadedMsg( TheMessage, msg_num, mode, headers_only, do_proto, crlf); + TRACE; CtdlFreeMessage(TheMessage); return(retcode); @@ -1118,7 +1118,8 @@ int CtdlOutputMsg(long msg_num, /* message number (local) to fetch */ * Get a message off disk. (returns om_* values found in msgbase.h) * */ -int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, +int CtdlOutputPreLoadedMsg( + struct CtdlMessage *TheMessage, long msg_num, int mode, /* how would you like that message? */ int headers_only, /* eschew the message body? */ @@ -1126,7 +1127,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, int crlf /* Use CRLF newlines instead of LF? */ ) { int i, k; - char buf[1024]; + char buf[SIZ]; cit_uint8_t ch; char allkeys[SIZ]; char display_name[SIZ]; @@ -1145,9 +1146,16 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, char datestamp[SIZ]; /* */ + lprintf(CTDL_DEBUG, "CtdlOutputPreLoadedMsg(TheMessage=%s, %ld, %d, %d, %d, %d\n", + ((TheMessage == NULL) ? "NULL" : "not null"), + msg_num, + mode, headers_only, do_proto, crlf); + + TRACE; snprintf(mid, sizeof mid, "%ld", msg_num); nl = (crlf ? "\r\n" : "\n"); + TRACE; if (!is_valid_message(TheMessage)) { lprintf(CTDL_ERR, "ERROR: invalid preloaded message for output\n"); @@ -1155,6 +1163,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, } /* Are we downloading a MIME component? */ + TRACE; if (mode == MT_DOWNLOAD) { if (TheMessage->cm_format_type != FMT_RFC822) { if (do_proto) @@ -1180,8 +1189,10 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, desired_section); } } + TRACE; return((CC->download_fp != NULL) ? om_ok : om_mime_error); } + TRACE; /* now for the user-mode message reading loops */ if (do_proto) cprintf("%d Message %ld:\n", LISTING_FOLLOWS, msg_num); @@ -1204,6 +1215,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, /* begin header processing loop for Citadel message format */ + TRACE; if ((mode == MT_CITADEL) || (mode == MT_MIME)) { strcpy(display_name, ""); @@ -1267,31 +1279,25 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, } /* begin header processing loop for RFC822 transfer format */ + TRACE; strcpy(suser, ""); strcpy(luser, ""); strcpy(fuser, ""); strcpy(snode, NODENAME); strcpy(lnode, HUMANNODE); + TRACE; if (mode == MT_RFC822) { - cprintf("X-UIDL: %ld%s", msg_num, nl); for (i = 0; i < 256; ++i) { + TRACE; if (TheMessage->cm_fields[i]) { mptr = TheMessage->cm_fields[i]; + TRACE; if (i == 'A') { - strcpy(luser, mptr); - strcpy(suser, mptr); - } -/**** - "Path:" removed for now because it confuses brain-dead Microsoft shitware - into thinking that mail messages are newsgroup messages instead. When we - add NNTP support back into Citadel we'll have to add code to only output - this field when appropriate. - else if (i == 'P') { - cprintf("Path: %s%s", mptr, nl); + safestrncpy(luser, mptr, sizeof luser); + safestrncpy(suser, mptr, sizeof suser); } - ****/ else if (i == 'U') { cprintf("Subject: %s%s", mptr, nl); subject_found = 1; @@ -1317,19 +1323,23 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, } } if (subject_found == 0) { + TRACE; cprintf("Subject: (no subject)%s", nl); } } + TRACE; for (i=0; i%s", nl); + TRACE; if (!is_room_aide() && (TheMessage->cm_anon_type == MES_ANONONLY)) { cprintf("From: x@x.org (----)%s", nl); @@ -1352,6 +1363,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, } cprintf("Organization: %s%s", lnode, nl); + TRACE; /* Blank line signifying RFC822 end-of-headers */ if (TheMessage->cm_format_type != FMT_RFC822) { @@ -1361,6 +1373,7 @@ int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, /* end header processing loop ... at this point, we're in the text */ START_TEXT: + TRACE; if (headers_only == HEADERS_FAST) goto DONE; mptr = TheMessage->cm_fields['M']; @@ -1427,11 +1440,13 @@ START_TEXT: if ( (mode == MT_CITADEL) || (mode == MT_MIME) ) { if (do_proto) cprintf("text\n"); } + TRACE; /* If the format type on disk is 1 (fixed-format), then we want * everything to be output completely literally ... regardless of * what message transfer format is in use. */ + TRACE; if (TheMessage->cm_format_type == FMT_FIXED) { if (mode == MT_MIME) { cprintf("Content-type: text/plain\n\n"); @@ -1459,6 +1474,7 @@ START_TEXT: * for new paragraphs is correct and the client will reformat the * message to the reader's screen width. */ + TRACE; if (TheMessage->cm_format_type == FMT_CITADEL) { if (mode == MT_MIME) { cprintf("Content-type: text/x-citadel-variformat\n\n"); @@ -1471,6 +1487,7 @@ START_TEXT: * this message is format 1 (fixed format), so the callback function * we use will display those parts as-is. */ + TRACE; if (TheMessage->cm_format_type == FMT_RFC822) { CtdlAllocUserData(SYM_MA_INFO, sizeof(struct ma_info)); memset(ma, 0, sizeof(struct ma_info)); @@ -1492,6 +1509,7 @@ START_TEXT: DONE: /* now we're done */ if (do_proto) cprintf("000\n"); + TRACE; return(om_ok); } @@ -1708,8 +1726,8 @@ int CtdlSaveMsgPointerInRoom(char *roomname, long msgid, int flags) { highest_msg = msglist[num_msgs - 1]; /* Write it back to disk. */ - cdb_store(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long), - msglist, num_msgs * sizeof(long)); + cdb_store(CDB_MSGLISTS, &CC->room.QRnumber, (int)sizeof(long), + msglist, (int)(num_msgs * sizeof(long))); /* Free up the memory we used. */ free(msglist); @@ -1779,7 +1797,7 @@ long send_message(struct CtdlMessage *msg) { } /* Write our little bundle of joy into the message base */ - if (cdb_store(CDB_MSGMAIN, &newmsgid, sizeof(long), + if (cdb_store(CDB_MSGMAIN, &newmsgid, (int)sizeof(long), smr.ser, smr.len) < 0) { lprintf(CTDL_ERR, "Can't store message\n"); retval = 0L; @@ -1787,7 +1805,7 @@ long send_message(struct CtdlMessage *msg) { if (is_bigmsg) { cdb_store(CDB_BIGMSGS, &newmsgid, - sizeof(long), + (int)sizeof(long), holdM, (strlen(holdM) + 1) ); @@ -2875,8 +2893,8 @@ int CtdlDeleteMessages(char *room_name, /* which room */ } num_msgs = sort_msglist(msglist, num_msgs); - cdb_store(CDB_MSGLISTS, &qrbuf.QRnumber, sizeof(long), - msglist, (num_msgs * sizeof(long))); + cdb_store(CDB_MSGLISTS, &qrbuf.QRnumber, (int)sizeof(long), + msglist, (int)(num_msgs * sizeof(long))); qrbuf.QRhighest = msglist[num_msgs - 1]; } @@ -3079,8 +3097,8 @@ void PutMetaData(struct MetaData *smibuf) smibuf->meta_msgnum, smibuf->meta_refcount); cdb_store(CDB_MSGMAIN, - &TheIndex, sizeof(long), - smibuf, sizeof(struct MetaData)); + &TheIndex, (int)sizeof(long), + smibuf, (int)sizeof(struct MetaData)); } @@ -3114,12 +3132,12 @@ void AdjRefCount(long msgnum, int incr) if (smi.meta_refcount == 0) { lprintf(CTDL_DEBUG, "Deleting message <%ld>\n", msgnum); delnum = msgnum; - cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long)); - cdb_delete(CDB_BIGMSGS, &delnum, sizeof(long)); + cdb_delete(CDB_MSGMAIN, &delnum, (int)sizeof(long)); + cdb_delete(CDB_BIGMSGS, &delnum, (int)sizeof(long)); /* We have to delete the metadata record too! */ delnum = (0L - msgnum); - cdb_delete(CDB_MSGMAIN, &delnum, sizeof(long)); + cdb_delete(CDB_MSGMAIN, &delnum, (int)sizeof(long)); } } diff --git a/citadel/serv_imap.c b/citadel/serv_imap.c index 3412eb638..65682eb36 100644 --- a/citadel/serv_imap.c +++ b/citadel/serv_imap.c @@ -217,7 +217,11 @@ void imap_rescan_msgids(void) cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long)); if (cdbfr != NULL) { msglist = malloc(cdbfr->len); - memcpy(msglist, cdbfr->ptr, cdbfr->len); + if (msglist == NULL) { + lprintf(CTDL_CRIT, "malloc() failed\n"); + abort(); + } + memcpy(msglist, cdbfr->ptr, (size_t)cdbfr->len); num_msgs = cdbfr->len / sizeof(long); cdb_free(cdbfr); } else { @@ -602,7 +606,7 @@ int imap_do_expunge(void) imap_rescan_msgids(); } - lprintf(9, "Expunged %d messages.\n", num_expunged); + lprintf(CTDL_DEBUG, "Expunged %d messages.\n", num_expunged); return (num_expunged); } @@ -1253,7 +1257,7 @@ void imap_command_loop(void) char *parms[SIZ]; int num_parms; - time(&CC->lastcmd); + CC->lastcmd = time(NULL); memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ flush_output(); if (client_gets(cmdbuf) < 1) { @@ -1266,7 +1270,6 @@ void imap_command_loop(void) while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); - /* strip off l/t whitespace and CRLF */ if (cmdbuf[strlen(cmdbuf) - 1] == '\n') cmdbuf[strlen(cmdbuf) - 1] = 0; @@ -1284,7 +1287,6 @@ void imap_command_loop(void) return; } - /* Ok, at this point we're in normal command mode. The first thing * we do is print any incoming pages (yeah! we really do!) */ diff --git a/citadel/serv_imap.h b/citadel/serv_imap.h index 904a657c3..85b4e7a1a 100644 --- a/citadel/serv_imap.h +++ b/citadel/serv_imap.h @@ -13,9 +13,9 @@ int imap_do_expunge(void); struct citimap { int authstate; char authseq[SIZ]; - int selected; /* set to 1 if in the SELECTED state */ - int readonly; /* mailbox is open read only */ - int num_msgs; /* Number of messages being mapped */ + int selected; /* set to 1 if in the SELECTED state */ + int readonly; /* mailbox is open read only */ + int num_msgs; /* Number of messages being mapped */ long *msgids; unsigned int *flags; char *transmitted_message; /* for APPEND command... */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index bdf4491df..2884761a9 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -109,7 +109,7 @@ int syslog_facility = (-1); void lprintf(enum LogLevel loglevel, const char *format, ...) { va_list arg_ptr; char buf[SIZ]; - + va_start(arg_ptr, format); vsnprintf(buf, sizeof(buf), format, arg_ptr); va_end(arg_ptr); diff --git a/citadel/tools.c b/citadel/tools.c index 0cfa3b3a2..0f59b34a1 100644 --- a/citadel/tools.c +++ b/citadel/tools.c @@ -91,8 +91,10 @@ int num_tokens(const char *source, char tok) { } -/* extract_token() - a smarter string tokenizer */ -void extract_token(char *dest, const char *source, unsigned long parmnum, char separator) +/* + * extract_token() - a string tokenizer + */ +void extract_token(char *dest, const char *source, int parmnum, char separator) { char *d; /* dest */ const char *s; /* source */ @@ -122,8 +124,10 @@ void extract_token(char *dest, const char *source, unsigned long parmnum, char s } -/* remove_token() - a tokenizer that kills, maims, and destroys fast */ -void remove_token(char *source, unsigned long parmnum, char separator) +/* + * remove_token() - a tokenizer that kills, maims, and destroys + */ +void remove_token(char *source, int parmnum, char separator) { char *d, *s; /* dest, source */ int count = 0; @@ -168,7 +172,7 @@ void remove_token(char *source, unsigned long parmnum, char separator) /* * extract_int() - extract an int parm w/o supplying a buffer */ -int extract_int(const char *source, unsigned long parmnum) +int extract_int(const char *source, int parmnum) { char buf[SIZ]; @@ -179,7 +183,7 @@ int extract_int(const char *source, unsigned long parmnum) /* * extract_long() - extract an long parm w/o supplying a buffer */ -long extract_long(const char *source, unsigned long parmnum) +long extract_long(const char *source, int parmnum) { char buf[SIZ]; @@ -191,7 +195,7 @@ long extract_long(const char *source, unsigned long parmnum) /* * extract_unsigned_long() - extract an unsigned long parm */ -unsigned long extract_unsigned_long(const char *source, unsigned long parmnum) +unsigned long extract_unsigned_long(const char *source, int parmnum) { char buf[SIZ]; @@ -533,7 +537,7 @@ void urlesc(char *outbuf, char *strbuf) strcpy(outbuf, ""); - for (a = 0; a < strlen(strbuf); ++a) { + for (a = 0; a < (int)strlen(strbuf); ++a) { c = 0; for (b = 0; b < strlen(ec); ++b) { if (strbuf[a] == ec[b]) diff --git a/citadel/tools.h b/citadel/tools.h index 479bc054c..7beb1bb94 100644 --- a/citadel/tools.h +++ b/citadel/tools.h @@ -1,15 +1,15 @@ /* $Id$ */ char *safestrncpy(char *dest, const char *src, size_t n); int num_tokens (const char *source, char tok); -void extract_token(char *dest, const char *source, unsigned long parmnum, char separator); -int extract_int (const char *source, unsigned long parmnum); -long extract_long (const char *source, unsigned long parmnum); -unsigned long extract_unsigned_long(const char *source, unsigned long parmnum); +void extract_token(char *dest, const char *source, int parmnum, char separator); +int extract_int (const char *source, int parmnum); +long extract_long (const char *source, int parmnum); +unsigned long extract_unsigned_long(const char *source, int parmnum); void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen); int CtdlDecodeBase64(char *dest, const char *source, size_t length); void striplt(char *); int haschar(const char *st, int ch); -void remove_token(char *source, unsigned long parmnum, char separator); +void remove_token(char *source, int parmnum, char separator); void fmt_date(char *buf, size_t n, time_t thetime, int seconds); int is_msg_in_mset(char *mset, long msgnum); char *memreadline(char *start, char *buf, int maxlen); @@ -21,8 +21,8 @@ int strncasecmp(char *, char *, int); #define strcasecmp(x,y) strncasecmp(x,y,INT_MAX); #endif -#define extract(dest,source,parmnum) extract_token(dest,source,parmnum,'|') -#define num_parms(source) num_tokens(source, '|') +#define extract(dest,source,parmnum) extract_token(dest,source,parmnum,(char)'|') +#define num_parms(source) num_tokens(source,(char)'|') void stripout(char *str, char leftboundary, char rightboundary); void stripallbut(char *str, char leftboundary, char rightboundary); -- 2.39.2