home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / comm / tcp / ftpdaemon / source / amiga.c next >
C/C++ Source or Header  |  1993-12-26  |  2KB  |  101 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdarg.h>
  6. #include <time.h>
  7. #include <sys/socket.h>
  8. #include <exec/types.h>
  9.  
  10. #include <proto/socket.h>
  11. #include <proto/exec.h>
  12.  
  13. #include "ftp.h"
  14.  
  15. char *SignOn="RAM:";
  16. char *Userfile="RAM:FTPUsers";
  17. char *curftwin="0023";
  18. char *ConfFile="AmiTCP:db/ftpd.conf";
  19. char *DefDirCommand=NULL;
  20. char *ArgDirCommand=NULL;
  21. char *LogFile=NULL;
  22. int LogLevel=0;
  23.  
  24. char *strip(char *str)
  25. {
  26.     char *p;
  27.     
  28.     p=str+strlen(str)-1;
  29.     while(p>str) if(isspace(*p)) *(p--)='\0'; else break;
  30.     while(*str && isspace(*str)) str++;
  31.     
  32.     return str;
  33. }
  34.  
  35. char *mystrdup(char *str)
  36. {
  37.     if(*str) return strdup(str);
  38.     return NULL;
  39. }
  40.  
  41. void ReadConfig(void)
  42. {
  43.     FILE *f;
  44.     char buf[512];
  45.     char *p,*q;
  46.     
  47.     if(!(f=fopen(ConfFile,"r"))) return;
  48.     
  49.     while(!feof(f))
  50.     {
  51.         if(fgets(buf,sizeof(buf),f))
  52.         {
  53.             if(p=strchr(buf,'\r')) *p='\0';
  54.             if(p=strchr(buf,'\n')) *p='\0';
  55.             if(p=strchr(buf,'#')) *p='\0';
  56.             if(p=strchr(buf,'='))
  57.             {
  58.                 *(p++)='\0';
  59.                 p=strip(p);
  60.                 q=strip(buf);
  61.                 // q=var, p=value
  62.                 
  63.                      if(!stricmp(q,"FTPUsers"))    Userfile=strdup(p);
  64.                 else if(!stricmp(q,"SignOn"))        SignOn=strdup(p);
  65.                 else if(!stricmp(q,"CurfTWin"))    curftwin=strdup(p);
  66.                 else if(!stricmp(q,"DevDir"))        DefDirCommand=mystrdup(p);
  67.                 else if(!stricmp(q,"ArgDir"))        ArgDirCommand=mystrdup(p);
  68.                 else if(!stricmp(q,"LogLevel"))    LogLevel=atoi(p);
  69.                 else if(!stricmp(q,"LogFile"))    LogFile=mystrdup(p);
  70.             }
  71.         }
  72.     }
  73.     fclose(f);
  74. }
  75.  
  76. void AddLog(char *fmt,...)
  77. {
  78.     va_list ap;
  79.     time_t tt;
  80.     char *t;
  81.     FILE *f;
  82.     
  83.     if(!LogFile) return;
  84.     
  85.     if(f=fopen(LogFile,"a"))
  86.     {
  87.         tt=time(0);
  88.         t=ctime(&tt);
  89.         *strchr(t,'\n')='\0';
  90.         fprintf(f,"%s (%08X): ",t,FindTask(NULL));
  91.         
  92.         va_start(ap,fmt);
  93.         vfprintf(f,fmt,ap);
  94.         va_end(ap);
  95.         
  96.         fprintf(f,"\n");
  97.         
  98.         fclose(f);
  99.     }
  100. }
  101.