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

Created smb_getmsgidx_by_time(), derived from sbbs_t::getmsgnum().

parent 83cd7103
No related branches found
No related tags found
No related merge requests found
......@@ -627,7 +627,7 @@ typedef struct { /* Message */
} smbmsg_t;
typedef struct { /* Message base */
typedef struct { /* Message base */
char file[128]; /* Path and base filename (no extension) */
FILE* sdt_fp; /* File pointer for data (.sdt) file */
......@@ -638,7 +638,7 @@ typedef struct { /* Message base */
FILE* hash_fp; /* File pointer for hash (.hash) file */
uint32_t retry_time; /* Maximum number of seconds to retry opens/locks */
uint32_t retry_delay; /* Time-slice yield (milliseconds) while retrying */
smbstatus_t status; /* Status header record */
smbstatus_t status; /* Status header record */
BOOL locked; /* SMB header is locked */
char last_error[MAX_PATH*2]; /* Last error message */
......
......@@ -648,6 +648,63 @@ int SMBCALL smb_getlastidx(smb_t* smb, idxrec_t *idx)
return(SMB_SUCCESS);
}
/****************************************************************************/
/* Finds index of last message imported at or after specified time */
/****************************************************************************/
int SMBCALL smb_getmsgidx_by_time(smb_t* smb, idxrec_t* idx, time_t t)
{
int i;
ulong l,total,bot,top;
if(idx == NULL)
return SMB_FAILURE;
memset(idx, 0, sizeof(idxrec_t));
if(t <= 0)
return SMB_FAILURE;
total = filelength(fileno(smb->sid_fp))/sizeof(idxrec_t);
if(!total) /* Empty base */
return SMB_ERR_NOT_FOUND;
if((i=smb_locksmbhdr(smb)) != SMB_SUCCESS)
return i;
if((i=smb_getlastidx(smb,idx)) != SMB_SUCCESS) {
smb_unlocksmbhdr(smb);
return i;
}
if((time_t)idx->time > t) {
bot=0;
top=total;
l=total/2; /* Start at middle index */
clearerr(smb->sid_fp);
while(1) {
fseek(smb->sid_fp,l*sizeof(idxrec_t),SEEK_SET);
if(!fread(idx,sizeof(idxrec_t),1,smb->sid_fp))
break;
if(bot==top-1)
break;
if((time_t)idx->time > t) {
top=l;
l=bot+((top-bot)/2);
continue;
}
if((time_t)idx->time < t) {
bot=l;
l=top-((top-bot)/2);
continue;
}
break;
}
}
smb_unlocksmbhdr(smb);
return SMB_SUCCESS;
}
/****************************************************************************/
/* Figures out the total length of the header record for 'msg' */
/* Returns length */
......
......@@ -190,6 +190,7 @@ SMBEXPORT int SMBCALL smb_addhashes(smb_t* smb, hash_t** hash_list, BOOL skip_m
SMBEXPORT uint16_t SMBCALL smb_name_crc(const char* name);
SMBEXPORT uint16_t SMBCALL smb_subject_crc(const char *subj);
SMBEXPORT void SMBCALL smb_freehashes(hash_t**);
SMBEXPORT int SMBCALL smb_getmsgidx_by_time(smb_t*, idxrec_t*, time_t);
/* Fast look-up functions (using hashes) */
SMBEXPORT int SMBCALL smb_getmsgidx_by_hash(smb_t* smb, smbmsg_t* msg, unsigned source
......
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