home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdarg.h>
- #include <time.h>
- #include <sys/socket.h>
- #include <exec/types.h>
-
- #include <proto/socket.h>
- #include <proto/exec.h>
-
- #include "ftp.h"
-
- char *SignOn="RAM:";
- char *Userfile="RAM:FTPUsers";
- char *curftwin="0023";
- char *ConfFile="AmiTCP:db/ftpd.conf";
- char *DefDirCommand=NULL;
- char *ArgDirCommand=NULL;
- char *LogFile=NULL;
- int LogLevel=0;
-
- char *strip(char *str)
- {
- char *p;
-
- p=str+strlen(str)-1;
- while(p>str) if(isspace(*p)) *(p--)='\0'; else break;
- while(*str && isspace(*str)) str++;
-
- return str;
- }
-
- char *mystrdup(char *str)
- {
- if(*str) return strdup(str);
- return NULL;
- }
-
- void ReadConfig(void)
- {
- FILE *f;
- char buf[512];
- char *p,*q;
-
- if(!(f=fopen(ConfFile,"r"))) return;
-
- while(!feof(f))
- {
- if(fgets(buf,sizeof(buf),f))
- {
- if(p=strchr(buf,'\r')) *p='\0';
- if(p=strchr(buf,'\n')) *p='\0';
- if(p=strchr(buf,'#')) *p='\0';
- if(p=strchr(buf,'='))
- {
- *(p++)='\0';
- p=strip(p);
- q=strip(buf);
- // q=var, p=value
-
- if(!stricmp(q,"FTPUsers")) Userfile=strdup(p);
- else if(!stricmp(q,"SignOn")) SignOn=strdup(p);
- else if(!stricmp(q,"CurfTWin")) curftwin=strdup(p);
- else if(!stricmp(q,"DevDir")) DefDirCommand=mystrdup(p);
- else if(!stricmp(q,"ArgDir")) ArgDirCommand=mystrdup(p);
- else if(!stricmp(q,"LogLevel")) LogLevel=atoi(p);
- else if(!stricmp(q,"LogFile")) LogFile=mystrdup(p);
- }
- }
- }
- fclose(f);
- }
-
- void AddLog(char *fmt,...)
- {
- va_list ap;
- time_t tt;
- char *t;
- FILE *f;
-
- if(!LogFile) return;
-
- if(f=fopen(LogFile,"a"))
- {
- tt=time(0);
- t=ctime(&tt);
- *strchr(t,'\n')='\0';
- fprintf(f,"%s (%08X): ",t,FindTask(NULL));
-
- va_start(ap,fmt);
- vfprintf(f,fmt,ap);
- va_end(ap);
-
- fprintf(f,"\n");
-
- fclose(f);
- }
- }
-