Commits (2)
  • Rob Swindell's avatar
    4415d99b
  • Rob Swindell's avatar
    Modernize finduser() a bit · 2106e629
    Rob Swindell authored
    Skip any prepended white-space in the passed name to find.
    Use better variable names (and length) for the character strings.
    Use matchusername() instead of strcmp(); matchusername() follows the liberal user-id/alias/name matching algorithm.
    Use strcasestr() instead of strstr(), so no copy/modification (upper-casing) of passed name is now required.
    When 'Q'uitting the search, set the SS_ABORT flag.
    2106e629
...@@ -31,26 +31,26 @@ ...@@ -31,26 +31,26 @@
/* Returns the number of the matched user or 0 if unsuccessful */ /* Returns the number of the matched user or 0 if unsuccessful */
/* Called from functions main_sec, useredit and readmailw */ /* Called from functions main_sec, useredit and readmailw */
/****************************************************************************/ /****************************************************************************/
uint sbbs_t::finduser(const char* instr, bool silent_failure) uint sbbs_t::finduser(const char* name, bool silent_failure)
{ {
int file,i; int file,i;
char str[128],str2[256],str3[256],ynq[25],c,pass=1; char buf[256],ynq[25],c,pass=1;
char path[MAX_PATH + 1];
long l,length; long l,length;
FILE *stream; FILE *stream;
i=atoi(instr); SKIP_WHITESPACE(name);
i=atoi(name);
if(i>0) { if(i>0) {
username(&cfg, i,str2); username(&cfg, i, buf);
if(str2[0] && strcmp(str2,"DELETED USER")) if(buf[0] && strcmp(buf,"DELETED USER"))
return(i); return(i);
} }
SAFECOPY(str,instr); SAFEPRINTF(path,"%suser/name.dat",cfg.data_dir);
strupr(str); if(flength(path)<1L)
SAFEPRINTF(str3,"%suser/name.dat",cfg.data_dir);
if(flength(str3)<1L)
return(0); return(0);
if((stream=fnopen(&file,str3,O_RDONLY))==NULL) { if((stream=fnopen(&file,path,O_RDONLY))==NULL) {
errormsg(WHERE,ERR_OPEN,str3,O_RDONLY); errormsg(WHERE,ERR_OPEN,path,O_RDONLY);
return(0); return(0);
} }
SAFEPRINTF(ynq,"%.3s",text[YNQP]); SAFEPRINTF(ynq,"%.3s",text[YNQP]);
...@@ -59,20 +59,18 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure) ...@@ -59,20 +59,18 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure)
fseek(stream,0L,SEEK_SET); /* seek to beginning for each pass */ fseek(stream,0L,SEEK_SET); /* seek to beginning for each pass */
for(l=0;l<length;l+=LEN_ALIAS+2) { for(l=0;l<length;l+=LEN_ALIAS+2) {
if(!online) break; if(!online) break;
fread(str2,LEN_ALIAS+2,1,stream); fread(buf,LEN_ALIAS+2,1,stream);
for(c=0;c<LEN_ALIAS;c++) for(c=0;c<LEN_ALIAS;c++)
if(str2[c]==ETX) break; if(buf[c]==ETX) break;
str2[c]=0; buf[c]=0;
if(!c) /* deleted user */ if(!c) /* deleted user */
continue; continue;
SAFECOPY(str3,str2); if(pass==1 && matchusername(&cfg, name, buf)) {
strupr(str2);
if(pass==1 && !strcmp(str,str2)) {
fclose(stream); fclose(stream);
return((l/(LEN_ALIAS+2))+1); return((l/(LEN_ALIAS+2))+1);
} }
if(pass==2 && strstr(str2,str)) { if(pass==2 && strcasestr(buf, name)) {
bprintf(text[DoYouMeanThisUserQ],str3 bprintf(text[DoYouMeanThisUserQ], buf
,(uint)(l/(LEN_ALIAS+2))+1); ,(uint)(l/(LEN_ALIAS+2))+1);
c=(char)getkeys(ynq,0); c=(char)getkeys(ynq,0);
if(sys_status&SS_ABORT) { if(sys_status&SS_ABORT) {
...@@ -85,6 +83,7 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure) ...@@ -85,6 +83,7 @@ uint sbbs_t::finduser(const char* instr, bool silent_failure)
} }
if(c==text[YNQP][2]) { if(c==text[YNQP][2]) {
fclose(stream); fclose(stream);
sys_status |= SS_ABORT;
return(0); return(0);
} }
} }
......
...@@ -120,7 +120,7 @@ void sbbs_t::showfileinfo(file_t* f, bool show_extdesc) ...@@ -120,7 +120,7 @@ void sbbs_t::showfileinfo(file_t* f, bool show_extdesc)
char* sbbs_t::getfilespec(char *str) char* sbbs_t::getfilespec(char *str)
{ {
bputs(text[FileSpecStarDotStar]); bputs(text[FileSpecStarDotStar]);
if(!getstr(str, MAX_FILENAME_LEN, K_NONE)) if(!getstr(str, MAX_FILENAME_LEN, K_TRIM))
strcpy(str, ALLFILES); strcpy(str, ALLFILES);
if(msgabort(true)) if(msgabort(true))
return NULL; return NULL;
...@@ -271,7 +271,7 @@ bool sbbs_t::editfilename(file_t* f) ...@@ -271,7 +271,7 @@ bool sbbs_t::editfilename(file_t* f)
bputs(text[EditFilename]); bputs(text[EditFilename]);
SAFECOPY(str, f->name); SAFECOPY(str, f->name);
if(!getstr(str, sizeof(str) - 1, K_EDIT|K_AUTODEL)) if(!getstr(str, sizeof(str) - 1, K_EDIT|K_AUTODEL|K_TRIM))
return false; return false;
if(msgabort(true)) if(msgabort(true))
return false; return false;
...@@ -336,7 +336,7 @@ bool sbbs_t::editfileinfo(file_t* f) ...@@ -336,7 +336,7 @@ bool sbbs_t::editfileinfo(file_t* f)
char uploader[LEN_ALIAS + 1]; char uploader[LEN_ALIAS + 1];
SAFECOPY(uploader, f->from); SAFECOPY(uploader, f->from);
bputs(text[EditUploader]); bputs(text[EditUploader]);
getstr(uploader, sizeof(uploader), K_EDIT|K_AUTODEL); getstr(uploader, sizeof(uploader), K_EDIT|K_AUTODEL|K_TRIM);
if(msgabort(true)) if(msgabort(true))
return false; return false;
if(*uploader != '\0' || *f->from != '\0') if(*uploader != '\0' || *f->from != '\0')
......