⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preserve.c

📁 c语言实现的web http报文分析
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    webalizer - a web server log analysis program    Copyright (C) 1997-2001  Bradford L. Barrett (brad@mrunix.net)    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version, and provided that the above    copyright and permission notice is included with all distributed    copies of this or derived software.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA    This software uses the gd graphics library, which is copyright by    Quest Protein Database Center, Cold Spring Harbor Labs.  Please    see the documentation supplied with the library for additional    information and license terms, or visit www.boutell.com/gd/ for the    most recent version of the library and supporting documentation.*//*********************************************//* STANDARD INCLUDES                         *//*********************************************/#include <time.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>                           /* normal stuff             */#include <ctype.h>#include <sys/utsname.h>#include <sys/times.h>/* ensure getopt */#ifdef HAVE_GETOPT_H#include <getopt.h>#endif/* ensure sys/types */#ifndef _SYS_TYPES_H#include <sys/types.h>#endif/* some systems need this */#ifdef HAVE_MATH_H#include <math.h>#endif/* SunOS 4.x Fix */#ifndef CLK_TCK#define CLK_TCK _SC_CLK_TCK#endif#include "webalizer.h"                        /* main header              */#include "lang.h"#include "hashtab.h"#include "parser.h"#include "preserve.h"/* local variables */int     hist_month[12], hist_year[12];        /* arrays for monthly total */u_long  hist_hit[12];                         /* calculations: used to    */u_long  hist_files[12];                       /* produce index.html       */u_long  hist_site[12];                        /* these are read and saved */double  hist_xfer[12];                        /* in the history file      */u_long  hist_page[12];u_long  hist_visit[12];int     hist_fday[12], hist_lday[12];         /* first/last day arrays    *//*********************************************//* GET_HISTORY - load in history file        *//*********************************************/void get_history(){   int i,numfields;   FILE *hist_fp;   char buffer[BUFSIZE];   /* first initalize internal array */   for (i=0;i<12;i++)   {      hist_month[i]=hist_year[i]=hist_fday[i]=hist_lday[i]=0;      hist_hit[i]=hist_files[i]=hist_site[i]=hist_page[i]=hist_visit[i]=0;      hist_xfer[i]=0.0;   }   hist_fp=fopen(hist_fname,"r");   if (hist_fp)   {      if (verbose>1) printf("%s %s\n",msg_get_hist,hist_fname);      while ((fgets(buffer,BUFSIZE,hist_fp)) != NULL)      {         i = atoi(buffer) -1;         if (i>11)         {            if (verbose)               fprintf(stderr,"%s (mth=%d)\n",msg_bad_hist,i+1);            continue;         }         /* month# year# requests files sites xfer firstday lastday */         numfields = sscanf(buffer,"%d %d %lu %lu %lu %lf %d %d %lu %lu",                       &hist_month[i],                       &hist_year[i],                       &hist_hit[i],                       &hist_files[i],                       &hist_site[i],                       &hist_xfer[i],                       &hist_fday[i],                       &hist_lday[i],                       &hist_page[i],                       &hist_visit[i]);         if (numfields==8)     /* kludge for reading 1.20.xx history files */         {            hist_page[i] = 0;            hist_visit[i] = 0;         }      }      fclose(hist_fp);   }   else if (verbose>1) printf("%s\n",msg_no_hist);}/*********************************************//* PUT_HISTORY - write out history file      *//*********************************************/void put_history(){   int i;   FILE *hist_fp;   hist_fp = fopen(hist_fname,"w");   if (hist_fp)   {      if (verbose>1) printf("%s\n",msg_put_hist);      for (i=0;i<12;i++)      {         if ((hist_month[i] != 0) && (hist_hit[i] != 0))         {            fprintf(hist_fp,"%d %d %lu %lu %lu %.0f %d %d %lu %lu\n",                            hist_month[i],                            hist_year[i],                            hist_hit[i],                            hist_files[i],                            hist_site[i],                            hist_xfer[i],                            hist_fday[i],                            hist_lday[i],                            hist_page[i],                            hist_visit[i]);         }      }      fclose(hist_fp);   }   else      if (verbose)      fprintf(stderr,"%s %s\n",msg_hist_err,hist_fname);}/*********************************************//* SAVE_STATE - save internal data structs   *//*********************************************/int save_state(){   HNODEPTR hptr;   UNODEPTR uptr;   RNODEPTR rptr;   ANODEPTR aptr;   SNODEPTR sptr;   INODEPTR iptr;   FILE *fp;   int  i;   char buffer[BUFSIZE];   /* Open data file for write */   fp=fopen(state_fname,"w");   if (fp==NULL) return 1;   /* Saving current run data... */   if (verbose>1)   {      sprintf(buffer,"%02d/%02d/%04d %02d:%02d:%02d",       cur_month,cur_day,cur_year,cur_hour,cur_min,cur_sec);      printf("%s [%s]\n",msg_put_data,buffer);   }   /* first, save the easy stuff */   /* Header record */   sprintf(buffer,     "# Webalizer V%s-%s Incremental Data - %02d/%02d/%04d %02d:%02d:%02d\n",      version,editlvl,cur_month,cur_day,cur_year,cur_hour,cur_min,cur_sec);   if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   /* Current date/time          */   sprintf(buffer,"%d %d %d %d %d %d\n",        cur_year, cur_month, cur_day, cur_hour, cur_min, cur_sec);   if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   /* Monthly totals for sites, urls, etc... */   sprintf(buffer,"%lu %lu %lu %lu %lu %lu %.0f %lu %lu %lu\n",        t_hit, t_file, t_site, t_url,        t_ref, t_agent, t_xfer, t_page, t_visit, t_user);   if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   /* Daily totals for sites, urls, etc... */   sprintf(buffer,"%lu %lu %lu %d %d\n",        dt_site, ht_hit, mh_hit, f_day, l_day);   if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   /* Monthly (by day) total array */   for (i=0;i<31;i++)   {      sprintf(buffer,"%lu %lu %.0f %lu %lu %lu\n",        tm_hit[i],tm_file[i],tm_xfer[i],tm_site[i],tm_page[i],tm_visit[i]);      if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   }   /* Daily (by hour) total array */   for (i=0;i<24;i++)   {      sprintf(buffer,"%lu %lu %.0f %lu\n",        th_hit[i],th_file[i],th_xfer[i],th_page[i]);      if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   }   /* Response codes */   for (i=0;i<TOTAL_RC;i++)   {      sprintf(buffer,"%lu\n",response[i].count);      if (fputs(buffer,fp)==EOF) return 1;  /* error exit */   }   /* now we need to save our linked lists */   /* URL list */   if (fputs("# -urls- \n",fp)==EOF) return 1;  /* error exit */   for (i=0;i<MAXHASH;i++)   {      uptr=um_htab[i];      while (uptr!=NULL)      {         sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n", uptr->string,              uptr->flag, uptr->count, uptr->files, uptr->xfer,              uptr->entry, uptr->exit);         if (fputs(buffer,fp)==EOF) return 1;         uptr=uptr->next;      }   }   if (fputs("# End Of Table - urls\n",fp)==EOF) return 1;  /* error exit */   /* daily hostname list */   if (fputs("# -sites- (monthly)\n",fp)==EOF) return 1;  /* error exit */   for (i=0;i<MAXHASH;i++)   {      hptr=sm_htab[i];      while (hptr!=NULL)      {         sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n",              hptr->string,              hptr->flag,              hptr->count,              hptr->files,              hptr->xfer,              hptr->visit,              hptr->tstamp,              (hptr->lasturl==blank_str)?"-":hptr->lasturl);         if (fputs(buffer,fp)==EOF) return 1;  /* error exit */         hptr=hptr->next;      }   }   if (fputs("# End Of Table - sites (monthly)\n",fp)==EOF) return 1;   /* hourly hostname list */   if (fputs("# -sites- (daily)\n",fp)==EOF) return 1;  /* error exit */   for (i=0;i<MAXHASH;i++)   {      hptr=sd_htab[i];      while (hptr!=NULL)      {         sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n%s\n",              hptr->string,              hptr->flag,              hptr->count,              hptr->files,              hptr->xfer,              hptr->visit,              hptr->tstamp,              (hptr->lasturl==blank_str)?"-":hptr->lasturl);         if (fputs(buffer,fp)==EOF) return 1;         hptr=hptr->next;      }   }   if (fputs("# End Of Table - sites (daily)\n",fp)==EOF) return 1;   /* Referrer list */   if (fputs("# -referrers- \n",fp)==EOF) return 1;  /* error exit */   if (t_ref != 0)   {      for (i=0;i<MAXHASH;i++)      {         rptr=rm_htab[i];         while (rptr!=NULL)         {            sprintf(buffer,"%s\n%d %lu\n", rptr->string,                 rptr->flag, rptr->count);            if (fputs(buffer,fp)==EOF) return 1;  /* error exit */            rptr=rptr->next;         }      }   }   if (fputs("# End Of Table - referrers\n",fp)==EOF) return 1;   /* User agent list */   if (fputs("# -agents- \n",fp)==EOF) return 1;  /* error exit */   if (t_agent != 0)   {      for (i=0;i<MAXHASH;i++)      {         aptr=am_htab[i];         while (aptr!=NULL)         {            sprintf(buffer,"%s\n%d %lu\n", aptr->string,                 aptr->flag, aptr->count);            if (fputs(buffer,fp)==EOF) return 1;  /* error exit */            aptr=aptr->next;         }      }   }   if (fputs("# End Of Table - agents\n",fp)==EOF) return 1;   /* Search String list */   if (fputs("# -search strings- \n",fp)==EOF) return 1;  /* error exit */   for (i=0;i<MAXHASH;i++)   {      sptr=sr_htab[i];      while (sptr!=NULL)      {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -