From 6b6aaa6987c0376a790648bcbecae3f231a09c6f Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Wed, 29 Dec 2004 10:13:08 +0000 Subject: [PATCH] Created smb_init_idx() which initializes the idx record in an smbmsg_t (to be used by smb_addmsg() and other higher level functions). --- src/smblib/smbhash.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/smblib/smblib.h | 2 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/smblib/smbhash.c b/src/smblib/smbhash.c index 449f87984c..b560707731 100644 --- a/src/smblib/smbhash.c +++ b/src/smblib/smbhash.c @@ -330,11 +330,14 @@ int SMBCALL smb_getmsghdr_by_hash(smb_t* smb, smbmsg_t* msg, unsigned source return(retval); } -ushort SMBCALL smb_subject_crc(const char *subj) +ushort SMBCALL smb_subject_crc(const char* subj) { char* str; ushort crc; + if(subj==NULL) + return(0xffff); + while(!strnicmp(subj,"RE:",3)) { subj+=3; while(*subj==' ') @@ -350,3 +353,41 @@ ushort SMBCALL smb_subject_crc(const char *subj) return(crc); } + +ushort SMBCALL smb_name_crc(const char* name) +{ + char* str; + ushort crc; + + if(name==NULL) + return(0xffff); + + if((str=strdup(name))==NULL) + return(0xffff); + + strlwr(str); + crc=crc16(str,0 /* auto-length */); + free(str); + + return(crc); +} + +int SMBCALL smb_init_idx(smb_t* smb, smbmsg_t* msg) +{ + msg->idx.subj=smb_subject_crc(msg->subj); + if(smb->status.attr&SMB_EMAIL) { + if(msg->to_ext) + msg->idx.to=atoi(msg->to_ext); + else + msg->idx.to=0; + if(msg->from_ext) + msg->idx.from=atoi(msg->from_ext); + else + msg->idx.from=0; + } else { + msg->idx.to=smb_name_crc(msg->to); + msg->idx.from=smb_name_crc(msg->from); + } + + return(SMB_SUCCESS); +} diff --git a/src/smblib/smblib.h b/src/smblib/smblib.h index 5fa63621b0..2df02993dc 100644 --- a/src/smblib/smblib.h +++ b/src/smblib/smblib.h @@ -181,7 +181,9 @@ SMBEXPORT hash_t* SMBCALL smb_hashstr(ulong msgnum, ulong time, unsigned source SMBEXPORT hash_t** SMBCALL smb_msghashes(smbmsg_t* msg, const uchar* text); SMBEXPORT int SMBCALL smb_addhashes(smb_t* smb, hash_t** hash_list, BOOL skip_marked); +SMBEXPORT ushort SMBCALL smb_name_crc(const char* name); SMBEXPORT ushort SMBCALL smb_subject_crc(const char *subj); +SMBEXPORT int SMBCALL smb_init_idx(smb_t* smb, smbmsg_t* msg); /* Fast look-up functions (using hashes) */ SMBEXPORT int SMBCALL smb_getmsgidx_by_hash(smb_t* smb, smbmsg_t* msg, unsigned source -- GitLab