Skip to content
Snippets Groups Projects
Commit ac29fdb6 authored by rswindell's avatar rswindell
Browse files

smb_findhash() now ignores pre-marked hashes and accepts a bool parameter

(mark) to indicate whether to mark all found hashes (or stop on first found).
parent c93e2295
No related branches found
No related tags found
No related merge requests found
......@@ -334,7 +334,7 @@ int main(int argc, char **argv)
/* Look-up the message hashes */
hashes=smb_msghashes(&smb,&msg,body);
if((i=smb_findhash(&smb,hashes,NULL))!=SMB_SUCCESS) {
if((i=smb_findhash(&smb,hashes,NULL,FALSE /* mark */))!=SMB_SUCCESS) {
fprintf(stderr,"%sFailed to find hash\n",beep);
msgerr=1;
if(extinfo)
......@@ -366,7 +366,6 @@ int main(int argc, char **argv)
,msg.hdr.number,smb.status.last_msg);
hdrnumerr++;
}
if(smb_getmsgidx(&smb,&msg)) {
fprintf(stderr,"%sNot found in index\n",beep);
msgerr=1;
......@@ -392,7 +391,6 @@ int main(int argc, char **argv)
"index import date/time\n");
timeerr++;
}
if(msg.hdr.number==0) {
fprintf(stderr,"%sZero message number\n",beep);
msgerr=1;
......
......@@ -460,9 +460,7 @@ typedef struct _PACK { /* Index record */
#define SMB_HASH_MD5 (1<<2) /* MD5 digest is valid */
#define SMB_HASH_MASK (SMB_HASH_CRC16|SMB_HASH_CRC32|SMB_HASH_MD5)
#define SMB_HASH_MARK (1<<3) /* Used by smb_findhash() */
#define SMB_HASH_MARKED (1<<4) /* Used by smb_findhash() */
#define SMB_HASH_MARK_MASK (SMB_HASH_MARK|SMB_HASH_MARKED)
#define SMB_HASH_STRIP_WSP (1<<6) /* Strip white-space chars first */
#define SMB_HASH_LOWERCASE (1<<7) /* Convert A-Z to a-z first */
......
......@@ -2363,7 +2363,7 @@ int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newmsgnum)
/**************************/
/* If return value is SMB_ERROR_NOT_FOUND, hash file is left open */
int SMBCALL smb_findhash(smb_t* smb, hash_t** compare, hash_t* found_hash)
int SMBCALL smb_findhash(smb_t* smb, hash_t** compare, hash_t* found_hash, BOOL mark)
{
int retval;
BOOL found=FALSE;
......@@ -2384,13 +2384,15 @@ int SMBCALL smb_findhash(smb_t* smb, hash_t** compare, hash_t* found_hash)
if(smb_fread(smb,&hash,sizeof(hash),smb->hash_fp)!=sizeof(hash))
break;
if(hash.number==0 || hash.flags==0)
if(hash.flags==0)
continue; /* invalid hash record (!?) */
for(c=0;compare[c]!=NULL;c++) {
if(compare[c]->source!=hash.source)
if(compare[c]->source!=hash.source)
continue; /* wrong source */
if(compare[c]->flags&SMB_HASH_MARKED)
continue; /* already marked */
if((compare[c]->flags&SMB_HASH_PROC_MASK)!=(hash.flags&SMB_HASH_PROC_MASK))
continue; /* wrong pre-process flags */
if((compare[c]->flags&hash.flags&SMB_HASH_MASK)==0)
......@@ -2417,7 +2419,7 @@ int SMBCALL smb_findhash(smb_t* smb, hash_t** compare, hash_t* found_hash)
if(found_hash!=NULL)
memcpy(found_hash,&hash,sizeof(hash));
if(!(compare[c]->flags&SMB_HASH_MARK))
if(!mark)
break;
compare[c]->flags|=SMB_HASH_MARKED;
......@@ -2525,7 +2527,6 @@ hash_t* SMBCALL smb_hashstr(ulong msgnum, ulong t, unsigned source, unsigned fla
return(hash);
}
/* Allocatese and calculates all hashes for a single message */
/* Returns NULL on failure */
hash_t** SMBCALL smb_msghashes(smb_t* smb, smbmsg_t* msg, uchar* text)
......@@ -2567,12 +2568,7 @@ int SMBCALL smb_hashmsg(smb_t* smb, smbmsg_t* msg, uchar* text, BOOL update)
hashes=smb_msghashes(smb,msg,text);
if(update) {
for(n=0;hashes[n]!=NULL;n++)
hashes[n]->flags|=SMB_HASH_MARK;
}
if(smb_findhash(smb, hashes, NULL)==SMB_SUCCESS && !update)
if(smb_findhash(smb, hashes, NULL, update)==SMB_SUCCESS && !update)
retval=SMB_DUPE_MSG;
else
retval=smb_addhashes(smb,hashes);
......
......@@ -162,7 +162,7 @@ SMBEXPORT int SMBCALL smb_tzutc(short timezone);
SMBEXPORT int SMBCALL smb_updatethread(smb_t* smb, smbmsg_t* remsg, ulong newmsgnum);
/* hash-related functions */
SMBEXPORT int SMBCALL smb_findhash(smb_t* smb, hash_t** compare_list, hash_t* found);
SMBEXPORT int SMBCALL smb_findhash(smb_t* smb, hash_t** compare_list, hash_t* found, BOOL mark);
SMBEXPORT int SMBCALL smb_hashmsg(smb_t* smb, smbmsg_t* msg, uchar* text, BOOL update);
SMBEXPORT hash_t* SMBCALL smb_hash(ulong msgnum, ulong time, unsigned source, unsigned flags, uchar* data, size_t length);
SMBEXPORT hash_t* SMBCALL smb_hashstr(ulong msgnum, ulong time, unsigned source, unsigned flags, uchar* str);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment