Exemplo n.º 1
0
void DisplayReqContents(struct fileentry *fe)
{
   char fullfile[200],line[200];
   osFile os;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      printf("Failed to open file\n");
   }
   else
   {
      while(osFGets(os,line,200))
      {
         strip(line);

         if(line[0])
            printf(" %s\n",line);
      }

      osClose(os);
   }

   printf("\n");
}
Exemplo n.º 2
0
char *PrintReqNums(struct fileentry *fe)
{
   static char buf[50];
   char fullfile[200],line[200];
   osFile os;
   uint32_t reqs;

   reqs=0;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      sprintf(buf,"?/?");
      return(buf);
   }

   while(osFGets(os,line,200))
   {
      strip(line);

      if(line[0])
      {
         reqs++;
         TotalRequests++;
      }
   }

   sprintf(buf,"-/%u",reqs);
   
   return(buf);
}
Exemplo n.º 3
0
char *PrintFlowSize(struct fileentry *fe)
{
   static char buf[50];
   char fullfile[200],line[200];
   osFile os;
   struct osFileEntry *osfe;
   uint32_t files,bytes;

   files=0;
   bytes=0;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      sprintf(buf,"?/?");
      return(buf);
   }

   while(osFGets(os,line,200))
   {
      strip(line);

      if(line[0])
      {
         if(line[0] == '#' || line[0] == '^' || line[0] == '-')
            strcpy(line,&line[1]);
      
         if(stricmp(GetFilePart(line),line) == 0)
         {
            /* No path specified */

            MakeFullPath(fe->dir,line,fullfile,200);
            osfe=osGetFileEntry(fullfile);
         }
         else
         {
            osfe=osGetFileEntry(line);
         }

         if(osfe)
         {
            files++;
            bytes+=osfe->Size;

            TotalFiles++;
            TotalBytes+=osfe->Size;

            osFree(osfe);
         }
      }
   }

   osClose(os);

   sprintf(buf,"%s/%u",unit(bytes),files);
   
   return(buf);
}
Exemplo n.º 4
0
void DisplayFlowContents(struct fileentry *fe)
{
   char size[40],*todo;
   char fullfile[200],line[200];
   osFile os;
   struct osFileEntry *osfe;

   MakeFullPath(cfg_Dir,fe->file,fullfile,200);

   if(!(os=osOpen(fullfile,MODE_OLDFILE)))
   {
      printf("Failed to open file\n");
   }
   else
   {
      while(osFGets(os,line,200))
      {
         strip(line);

         if(line[0])
         {
            todo="";

            if(line[0] == '#' || line[0] == '^') todo="(To be truncated)";
            if(line[0] == '-')                   todo="(To be deleted)";

            if(line[0] == '#' || line[0] == '^' || line[0] == '-')
               strcpy(line,&line[1]);
      
            if(stricmp(GetFilePart(line),line) == 0)
            {
               /* No path specified */

               MakeFullPath(fe->dir,line,fullfile,200);
               osfe=osGetFileEntry(fullfile);
            }
            else
            {
               osfe=osGetFileEntry(line);
            }

            strcpy(size,"Not found");

            if(osfe)
            {
               sprintf(size, "%s", unit(osfe->Size));
               osFree(osfe);
            }

            printf(" %-39.39s %10s   %s\n",line,size,todo);
         }
      }

      osClose(os);
   }

   printf("\n");
}
// a simple test for OS layer
void osTest() {
    SqlVFS *os = osGetVFS("unix");
    SqlFile *file = osGetFileHandle(os);
    printf("%d\n", osOpen(os, "data", file, O_RDWR | O_CREAT));
    printf("%d\n", osWrite(file, "123", 3, 0));
    printf("%d\n", osWrite(file, "abcd", 4, 1));
    printf("%d\n", osTruncate(file, 2));

    char buf[20];
    int ret = osRead(file, buf, 20, 0);
    printf("%d\n", ret);
    buf[ret] = 0;
    printf("%s\n", buf);
}
Exemplo n.º 6
0
void CloseDupeDB(void)
{
   osFile newfh;
   uint32_t c;
   char duptemp[200];

   if(!dupechanged)
   {
      osClose(dupefh);
      return;
   }

   strcpy(duptemp,config.cfg_DupeFile);
   strcat(duptemp,".tmp");

   if(!(newfh=osOpen(duptemp,MODE_NEWFILE)))
   {
		uint32_t err=osError();
      LogWrite(1,SYSTEMERR,"Failed to open temporary dupe file %s for writing",duptemp);
      LogWrite(1,SYSTEMERR,"Error: %s",osErrorMsg(err));

      osFree(dupebuf);
      osClose(dupefh);

      return;
   }

   osWrite(newfh,DUPES_IDENTIFIER,4);

   for(c=dupeentrynum;c<dupeentrymax;c++)
      copydupe(c,dupefh,newfh);

   for(c=0;c<dupeentrynum;c++)
      copydupe(c,dupefh,newfh);

   osClose(dupefh);
   osClose(newfh);
   osFree(dupebuf);

   dupechanged=FALSE;

   osDelete(config.cfg_DupeFile);
   osRename(duptemp,config.cfg_DupeFile);

   return;
}
Exemplo n.º 7
0
int main(int argc, char **argv)
{
   osFile fh;
   uint32_t total,areas,totaldupes;
   time_t firsttime,t;
   uint32_t DayStatsWritten;
   char buf[200],date[30],date2[30];
   struct DiskAreaStats dastat;
   struct DiskNodeStats dnstat;
   struct StatsNode *sn;
   struct NodeStatsNode *nsn;
   struct jbList StatsList;
   struct jbList NodesList;
   uint32_t c,num,tot;
   uint16_t total8days[8];
   char sortmode;
   struct tm *tp;
   char *monthnames[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","???"};

   signal(SIGINT,breakfunc);
         
   if(!osInit())
      exit(OS_EXIT_ERROR);

   if(argc > 1 &&
	  (strcmp(argv[1],"?")==0      ||
		strcmp(argv[1],"-h")==0     ||
		strcmp(argv[1],"--help")==0 ||
		strcmp(argv[1],"help")==0 ||
		strcmp(argv[1],"/h")==0     ||
		strcmp(argv[1],"/?")==0 ))
   {
      printargs(args);
      osEnd();
      exit(OS_EXIT_OK);
   }

   if(!parseargs(args,argc,argv))
   {
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   sortmode='a';
   
   if(args[ARG_SORT].data)
      sortmode=tolower(((char *)args[ARG_SORT].data)[0]);
      
   if(!strchr("amtdlu",sortmode))
   {
      printf("Unknown sort mode %c\n",sortmode);
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   if(args[ARG_NOAREAS].data && args[ARG_NONODES].data)
   {
      printf("Nothing to do\n");
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   printf("CrashStats "VERSION" © "  COPYRIGHT " Johan Billing\n");

   if(!(fh=osOpen(args[ARG_FILE].data,MODE_OLDFILE)))
   {
		uint32_t err=osError();
      printf("Error opening %s\n",(char *)args[ARG_FILE].data);
		printf("Error: %s\n",osErrorMsg(err));		
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   osRead(fh,buf,4);
   buf[4]=0;

   if(strcmp(buf,STATS_IDENTIFIER)!=0)
   {
      printf("Unknown format of stats file\n");
      osClose(fh);
      osEnd();
      exit(OS_EXIT_ERROR);
   }

   osRead(fh,&DayStatsWritten,sizeof(uint32_t));

   total=0;
   totaldupes=0;
   firsttime=0;
   areas=0;

   for(c=0;c<8;c++)
   	total8days[c]=0;

   jbNewList(&StatsList);
   jbNewList(&NodesList);

   osRead(fh,&num,sizeof(uint32_t));
   c=0;

   if(!args[ARG_NOAREAS].data)
   {
      while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats))
      {
         if(!args[ARG_GROUP].data || CheckFlags(dastat.Group,args[ARG_GROUP].data))
         {
            if(!(sn=osAlloc(sizeof(struct StatsNode))))
            {
               printf("Out of memory\n");
               jbFreeList(&StatsList);
               osClose(fh);
               osEnd();
               exit(OS_EXIT_ERROR);
            }

            jbAddNode(&StatsList,(struct jbNode *)sn);

            strcpy(sn->Tagname,dastat.Tagname);
            sn->Dupes=dastat.Dupes;
            sn->Total=dastat.TotalTexts;
            sn->FirstTime=dastat.FirstTime;
            sn->LastTime=dastat.LastTime;
            memcpy(&sn->Last8Days[0],&dastat.Last8Days[0],8*sizeof(uint16_t));

            sn->Average=CalculateAverage(&dastat.Last8Days[0],dastat.TotalTexts,DayStatsWritten,sn->FirstTime / (24*60*60));
         }

         if(dastat.FirstTime!=0)
            if(firsttime==0 || firsttime > dastat.FirstTime)
               firsttime=dastat.FirstTime;

         c++;
      }
   }
   else
   {
      while(c<num && osRead(fh,&dastat,sizeof(struct DiskAreaStats))==sizeof(struct DiskAreaStats))
         c++;
   }

   osRead(fh,&num,sizeof(uint32_t));
   c=0;

   if(!args[ARG_NONODES].data)
   {
      while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats))
      {
         if(!(nsn=osAlloc(sizeof(struct NodeStatsNode))))
         {
            printf("Out of memory\n");
            jbFreeList(&NodesList);
            jbFreeList(&StatsList);
            osClose(fh);
            osEnd();
            exit(OS_EXIT_ERROR);
         }

         jbAddNode(&NodesList,(struct jbNode *)nsn);

         Copy4D(&nsn->Node,&dnstat.Node);

         nsn->GotNetmails=dnstat.GotNetmails;
         nsn->GotNetmailBytes=dnstat.GotNetmailBytes;
         nsn->SentNetmails=dnstat.SentNetmails;
         nsn->SentNetmailBytes=dnstat.SentNetmailBytes;
         nsn->GotEchomails=dnstat.GotEchomails;
         nsn->GotEchomailBytes=dnstat.GotEchomailBytes;
         nsn->SentEchomails=dnstat.SentEchomails;
         nsn->SentEchomailBytes=dnstat.SentEchomailBytes;
         nsn->Dupes=dnstat.Dupes;

         nsn->Days=DayStatsWritten-dnstat.FirstTime % (24*60*60);
         if(nsn->Days==0) nsn->Days=1;

         nsn->FirstTime=dnstat.FirstTime;

         if(dnstat.FirstTime!=0)
            if(firsttime==0 || firsttime > dnstat.FirstTime)
               firsttime=dnstat.FirstTime;

         c++;
      }
   }
   else
   {
      while(c<num && osRead(fh,&dnstat,sizeof(struct DiskNodeStats))==sizeof(struct DiskNodeStats))
         c++;
   }

   osClose(fh);

   t=(time_t)DayStatsWritten * 24*60*60;

   tp=localtime(&firsttime);
   sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
   
   tp=localtime(&t);
   sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);

   printf("\nStatistics from %s to %s\n",date,date2);
   
   if(!ctrlc && !args[ARG_NOAREAS].data)
   {
      Sort(&StatsList,'a');
      Sort(&StatsList,sortmode);
      printf("\n");

      if(args[ARG_LAST7].data)
      {
         printf("Area                             ");

         for(c=1;c<8;c++)
         {
            t=(DayStatsWritten-c)*24*60*60;
            tp=localtime(&t);
            printf("   %02d",tp->tm_mday);
         }

         printf("   Total\n============================================================================\n");

         if(!ctrlc)
         {
            for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next)
            {
               tot=0;

               for(c=1;c<8;c++)
                  tot+=sn->Last8Days[c];

               printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n",
                  sn->Tagname,
                  sn->Last8Days[1],
                  sn->Last8Days[2],
                  sn->Last8Days[3],
                  sn->Last8Days[4],
                  sn->Last8Days[5],
                  sn->Last8Days[6],
                  sn->Last8Days[7],
                  tot);

               for(c=1;c<8;c++)
                  total8days[c]+=sn->Last8Days[c];

               areas++;
            }

            if(!ctrlc)
            {
               tot=0;

               for(c=1;c<8;c++)
                  tot+=total8days[c];

               printf("=============================================================================\n");
               sprintf(buf,"Totally in all %u areas",areas);

               printf("%-33.33s %4d %4d %4d %4d %4d %4d %4d : %5d\n",
                  buf,
                  total8days[1],
                  total8days[2],
                  total8days[3],
                  total8days[4],
                  total8days[5],
                  total8days[6],
                  total8days[7],
                  tot);
            }
         }
      }
      else
      {
         printf("Area                           First     Last         Msgs  Msgs/day   Dupes\n");
         printf("============================================================================\n");

         if(!ctrlc)
         {
            for(sn=(struct StatsNode *)StatsList.First;sn && !ctrlc;sn=sn->Next)
            {
               if(sn->LastTime==0)
               {
                  strcpy(date2,"<Never>");
               }
               else
               {
                  tp=localtime(&sn->LastTime);
                  sprintf(date2,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
               }

               if(sn->FirstTime==0)
               {
                  strcpy(date,"<Never>");
               }
               else
               {
                  tp=localtime(&sn->FirstTime);
                  sprintf(date,"%02d-%s-%02d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
               }

               for(c=0;c<8;c++)
                  total8days[c]+=sn->Last8Days[c];

               total+=sn->Total;
               totaldupes+=sn->Dupes;
               areas++;

               printf("%-29.30s %-9.9s %-9.9s %7d   %7d %7d\n",sn->Tagname,date,date2,sn->Total,sn->Average,sn->Dupes);
            }
         }

         if(!ctrlc)
         {
            printf("============================================================================\n");
            sprintf(buf,"Totally in all %u areas",areas);
            printf("%-42s         %7d   %7d %7d\n",
               buf,
               total,
               CalculateAverage(&total8days[0],total,DayStatsWritten,firsttime / (24*60*60)),
               totaldupes);
         }
      }
   }

   if(!ctrlc && !args[ARG_NONODES].data)
   {
      SortNodes(&NodesList);

      printf("\n");
      printf("Nodes statistics\n");
      printf("================\n");

      for(nsn=(struct NodeStatsNode *)NodesList.First;nsn && !ctrlc;nsn=nsn->Next)
      {
         if(nsn->FirstTime==0)
         {
            strcpy(date,"<Never>");
         }
         else
         {
            tp=localtime(&nsn->FirstTime);
            sprintf(date,"%0d-%s-%0d",tp->tm_mday,monthnames[tp->tm_mon],tp->tm_year%100);
         }

         sprintf(buf,"%u:%u/%u.%u",nsn->Node.Zone,nsn->Node.Net,nsn->Node.Node,nsn->Node.Point);

			printf("%-30.40s Statistics since: %s\n\n",buf,date);
			printf("                                  Sent netmails: %u/%s\n",nsn->SentNetmails,unit(nsn->SentNetmailBytes));
			printf("                              Received netmails: %u/%s\n",nsn->GotNetmails,unit(nsn->GotNetmailBytes));
			printf("                                 Sent echomails: %u/%s\n",nsn->SentEchomails,unit(nsn->SentEchomailBytes));
			printf("                             Received echomails: %u/%s\n",nsn->GotEchomails,unit(nsn->GotEchomailBytes));
			printf("                                          Dupes: %u\n",nsn->Dupes);
         printf("\n");
      }
   }

   if(ctrlc)
   {
      printf("*** Break\n");
   }
   else
   {
      printf("\n");
   }

   jbFreeList(&StatsList);
   jbFreeList(&NodesList);

   osEnd();
   
   exit(OS_EXIT_OK);
}
Exemplo n.º 8
0
bool OpenDupeDB(void)
{
   char buf[300];
   uint32_t offset,crc32,*crc32p;
   uint16_t size,res;

   if(!(dupebuf=osAlloc(config.cfg_DupeSize*sizeof(struct dupeentry))))
   {
      LogWrite(1,SYSTEMERR,"Not enough memory for dupe-check buffer\n");
      return(FALSE);
   }

   dupeentrynum=0;
   dupeentrymax=0;

   dupechanged=FALSE;

   if(!(dupefh=osOpen(config.cfg_DupeFile,MODE_READWRITE)))
   {
		uint32_t err=osError();
      LogWrite(1,SYSTEMERR,"Failed to open dupe file %s in read/write mode",config.cfg_DupeFile);
      LogWrite(1,SYSTEMERR,"Error: %s",osErrorMsg(err));
      return(FALSE);
   }

   res=osRead(dupefh,buf,4);
   buf[4]=0;

   if(res == 0)
   {
      /* New file */

		LogWrite(3,TOSSINGINFO,"Creating new dupe file %s",config.cfg_DupeFile);

      strcpy(buf,DUPES_IDENTIFIER);
      osWrite(dupefh,buf,4);
   }
   else if(res != 4 || strcmp(buf,DUPES_IDENTIFIER)!=0)
   {
      LogWrite(1,SYSTEMERR,"Invalid format of dupe file %s, exiting...",config.cfg_DupeFile);
      osClose(dupefh);
      return(FALSE);
   }

   offset=4;

   while(osRead(dupefh,&size,sizeof(uint16_t))==sizeof(uint16_t))
   {
      if(size == 0 || size > 300) /* Unreasonably big */
      {
         LogWrite(1,SYSTEMERR,"Error in dupe file %s, exiting...",config.cfg_DupeFile);
         osClose(dupefh);
         return(FALSE);
      }

      if(osRead(dupefh,buf,(uint32_t)size) != size)
      {
         LogWrite(1,SYSTEMERR,"Error in dupe file %s, exiting...",config.cfg_DupeFile);
         osClose(dupefh);
         return(FALSE);
      }

      crc32p=(uint32_t *)buf;
      crc32=*crc32p;

      adddupeindex(offset,crc32);

      offset += size+2;
   }

   dupechanged=FALSE;

   return(TRUE);
}