#include "bbs.h"
extern struct myst my_struct;

/* Check_Our_List.c */

/* our list of files that are not allowed to be sent up     */
/* also have to add this to the function that uploads files */
/* without entering the file name */

/* str = ptr to filename of file to upload */

static int Check_Our_List(char *fname, char *str)
{
 FILE *fp;
 char buff[255];
 register char *s, *p, *tmpstr;

 if(!(fp = fopen(fname,"r")))     /* can't find our file */
     return(SUCCESS);

 while(fgets(&buff[0],250,fp)!=0) {
     buff[strlen(buff)-1] = '\0';   /* remove newline */
     s = &buff[0];

     /* skip beginning spaces */
     while(*s == ' ')        s++;
     p = s;

     while(*p && *p!= '*')
        p++;
     if(*p == '*')  { /* found a wild card, everything after this can not be sent up */
          p++;                        /* move past aster */
          tmpstr = str+strlen(str)-1;   /* goto last char in string */
          tmpstr -= strlen(p) -1;       /* backup p chars - 1 */
          if(stricmp(tmpstr,p) == 0) {
              fclose(fp);
              sprintf(buff,"%s (.ext) files are not allowed\r\n",p);
              AEPutStr(buff);
              return(FAILURE);     /* found text in list */
          }

     }

     if(strnicmp(s,str,strlen(str)) == 0) {
           fclose(fp);
           return(FAILURE);     /* found text in list */
     }

 }
 if(fp) fclose(fp);
 return(SUCCESS);                 /* didn't find text in list */
}

extern char  Conference_Location[100];
//extern char *NotAllowedFiles;
extern BOOL LcFileXfr;
int Check_For_File(char *Fn)
{
 char path[255],final[255];
 FILE *ft;
 int x;

 if(strstr(Fn,"%") || strstr(Fn,"#") || strstr(Fn,"?") || strstr(Fn," ") ||
    strstr(Fn,"/") || strstr(Fn,"(") || strstr(Fn,")"))
     return(FAILURE);
 
 /* here we can add our own file list of files to check */
 if(Sopt->FilesNot[0]!=NULL) {
     x = Check_Our_List(Sopt->FilesNot,Fn);   /* a list of files not to allow up */
     if(x == FAILURE)
          return(FAILURE);

 }
  if(!LcFileXfr)
  {
 strcpy(path,Conference_Location);
 strcat(path,"LcFiles/");
 sprintf(final,"%s%s",path,Fn);
 if(ft=fopen(final,"r"))
 {
   fclose(ft); return(FAILURE);
 }
 }
//---------------- lcfiles checking finished
      x=1;
      sprintf(path,"DLPATH.%d",x++);  
	 while(GetFromConf(CN-1,path,path)) {
		    	strcpy(final,path);
			    strcat(final,Fn);
 			ft = fopen(final,"r");
	    		if(ft!=NULL) {  /* Found the file so return fail */
	    			if(ft) fclose(ft);
		    		return(FAILURE);
				}
            sprintf(path,"DLPATH.%d",x++);
		} 
 /*=== 11w add */
      x=1;
      sprintf(path,"ULPATH.%d",x++);
      while(GetFromConf(CN-1,path,path))
      {
			    strcpy(final,path);
			    strcat(final,Fn);
			    ft = fopen(final,"r");
			    if(ft!=NULL) {
				    if(ft) fclose(ft);
				    return(FAILURE);
			    }
sprintf(path,"ULPATH.%d",x++);
		    }
           
/*-- 11w end addition */
 return(SUCCESS);
}
