X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmsgbase.c;h=b00b8870bb716ac9aea7666027739f200e5bdad1;hb=6b742317d9bb76fd800ba1774305a8ae72551326;hp=e9855ea42b12afdb8f30e484217ef460a9c3645c;hpb=9d086d4051a4b6c5cafc3b06b231ec28f24c8b6d;p=citadel.git diff --git a/citadel/msgbase.c b/citadel/msgbase.c index e9855ea42..b00b8870b 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -116,6 +116,15 @@ char *msgkeys[] = { NULL /* Z */ }; +void CtdlMsgSetCM_Fields(struct CtdlMessage *Msg, const char which, const char *buf, long length) +{ + if (Msg->cm_fields[which] != NULL) + free (Msg->cm_fields[which]); + Msg->cm_fields[which] = malloc(length + 1); + memcpy(Msg->cm_fields[which], buf, length); + Msg->cm_fields[which][length] = '\0'; +} + /* * This function is self explanatory. * (What can I say, I'm in a weird mood today...) @@ -1138,7 +1147,7 @@ void mime_download(char *name, char *filename, char *partnum, char *disp, return; } - rv = fwrite(content, length, 1, CC->download_fp); + rv = fwrite(content, length, 1, CCC->download_fp); if (rv <= 0) { MSG_syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n", strerror(errno)); @@ -1204,6 +1213,7 @@ struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body) MSG_syslog(LOG_DEBUG, "CtdlFetchMessage(%ld, %d)\n", msgnum, with_body); dmsgtext = cdb_fetch(CDB_MSGMAIN, &msgnum, sizeof(long)); if (dmsgtext == NULL) { + MSG_syslog(LOG_ERR, "CtdlFetchMessage(%ld, %d) Failed!\n", msgnum, with_body); return NULL; } mptr = dmsgtext->ptr; @@ -1335,7 +1345,7 @@ struct CtdlMessage * CtdlDuplicateMessage(struct CtdlMessage *OrgMsg) if (NewMsg == NULL) return NULL; - memcpy(NewMsg, OrgMsg, sizeof(struct CtdlMessage *)); + memcpy(NewMsg, OrgMsg, sizeof(struct CtdlMessage)); memset(&NewMsg->cm_fields, 0, sizeof(char*) * 256); @@ -3542,7 +3552,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ */ void quickie_message(const char *from, const char *fromaddr, - char *to, + const char *to, char *room, const char *text, int format_type, @@ -3589,25 +3599,25 @@ void quickie_message(const char *from, void flood_protect_quickie_message(const char *from, const char *fromaddr, - char *to, + const char *to, char *room, const char *text, int format_type, const char *subject, int nCriterions, const char **CritStr, - long *CritStrLen) + long *CritStrLen, + long ccid, + long ioid, + time_t NOW) { int i; - struct UseTable ut; u_char rawdigest[MD5_DIGEST_LEN]; struct MD5Context md5context; StrBuf *guid; - struct cdbdata *cdbut; char timestamp[64]; long tslen; - time_t ts = time(NULL); - time_t tsday = ts / (8*60*60); /* just care for a day... */ + time_t tsday = NOW / (8*60*60); /* just care for a day... */ tslen = snprintf(timestamp, sizeof(timestamp), "%ld", tsday); MD5Init(&md5context); @@ -3625,27 +3635,22 @@ void flood_protect_quickie_message(const char *from, StrBufAppendBufPlain(guid, HKEY("_fldpt"), 0); if (StrLength(guid) > 40) StrBufCutAt(guid, 40, NULL); - /* Find out if we've already sent a similar message */ - memcpy(ut.ut_msgid, SKEY(guid)); - ut.ut_timestamp = ts; - cdbut = cdb_fetch(CDB_USETABLE, SKEY(guid)); - - if (cdbut != NULL) { + if (CheckIfAlreadySeen("FPAideMessage", + guid, + NOW, + tsday, + eUpdate, + ccid, + ioid)!= 0) + { + FreeStrBuf(&guid); /* yes, we did. flood protection kicks in. */ syslog(LOG_DEBUG, "not sending message again\n"); - cdb_free(cdbut); + return; } - - /* rewrite the record anyway, to update the timestamp */ - cdb_store(CDB_USETABLE, - SKEY(guid), - &ut, sizeof(struct UseTable) ); - FreeStrBuf(&guid); - - if (cdbut != NULL) return; /* no, this message isn't sent recently; go ahead. */ quickie_message(from, fromaddr, @@ -4799,12 +4804,12 @@ int CtdlDeleteMessages(char *room_name, /* which room */ regcomp(&re, content_type, 0); need_to_free_re = 1; } - MSG_syslog(LOG_DEBUG, "CtdlDeleteMessages(%s, %d msgs, %s)\n", + MSG_syslog(LOG_DEBUG, " CtdlDeleteMessages(%s, %d msgs, %s)\n", room_name, num_dmsgnums, content_type); /* get room record, obtaining a lock... */ if (CtdlGetRoomLock(&qrbuf, room_name) != 0) { - MSG_syslog(LOG_ERR, "CtdlDeleteMessages(): Room <%s> not found\n", + MSG_syslog(LOG_ERR, " CtdlDeleteMessages(): Room <%s> not found\n", room_name); if (need_to_free_re) regfree(&re); return (0); /* room not found */ @@ -4831,7 +4836,7 @@ int CtdlDeleteMessages(char *room_name, /* which room */ StrBuf *dbg = NewStrBuf(); for (i = 0; i < num_dmsgnums; i++) StrBufAppendPrintf(dbg, ", %ld", dmsgnums[i]); - MSG_syslog(LOG_DEBUG, "Deleting before: %s", ChrPtr(dbg)); + MSG_syslog(LOG_DEBUG, " Deleting before: %s", ChrPtr(dbg)); FreeStrBuf(&dbg); } */ @@ -4839,7 +4844,6 @@ int CtdlDeleteMessages(char *room_name, /* which room */ while ((i < num_msgs) && (have_more_del)) { delete_this = 0x00; - /* Set/clear a bit for each criterion */ /* 0 messages in the list or a null list means that we are @@ -4850,6 +4854,10 @@ int CtdlDeleteMessages(char *room_name, /* which room */ } else { while ((i < num_msgs) && (msglist[i] < dmsgnums[j])) i++; + + if (i >= num_msgs) + continue; + if (msglist[i] == dmsgnums[j]) { delete_this |= 0x01; } @@ -4878,7 +4886,7 @@ int CtdlDeleteMessages(char *room_name, /* which room */ StrBuf *dbg = NewStrBuf(); for (i = 0; i < num_deleted; i++) StrBufAppendPrintf(dbg, ", %ld", dellist[i]); - MSG_syslog(LOG_DEBUG, "Deleting: %s", ChrPtr(dbg)); + MSG_syslog(LOG_DEBUG, " Deleting: %s", ChrPtr(dbg)); FreeStrBuf(&dbg); } */ @@ -4910,7 +4918,7 @@ int CtdlDeleteMessages(char *room_name, /* which room */ /* Now free the memory we used, and go away. */ if (msglist != NULL) free(msglist); if (dellist != NULL) free(dellist); - MSG_syslog(LOG_DEBUG, "%d message(s) deleted.\n", num_deleted); + MSG_syslog(LOG_DEBUG, " %d message(s) deleted.\n", num_deleted); if (need_to_free_re) regfree(&re); return (num_deleted); }