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

📄 preserve.c

📁 c语言实现的web http报文分析
💻 C
📖 第 1 页 / 共 2 页
字号:
         sprintf(buffer,"%s\n%lu\n", sptr->string,sptr->count);         if (fputs(buffer,fp)==EOF) return 1;  /* error exit */         sptr=sptr->next;      }   }   if (fputs("# End Of Table - search strings\n",fp)==EOF) return 1;   /* username list */   if (fputs("# -usernames- \n",fp)==EOF) return 1;  /* error exit */   for (i=0;i<MAXHASH;i++)   {      iptr=im_htab[i];      while (iptr!=NULL)      {         sprintf(buffer,"%s\n%d %lu %lu %.0f %lu %lu\n",              iptr->string,              iptr->flag,              iptr->count,              iptr->files,              iptr->xfer,              iptr->visit,              iptr->tstamp);         if (fputs(buffer,fp)==EOF) return 1;  /* error exit */         iptr=iptr->next;      }   }   if (fputs("# End Of Table - usernames\n",fp)==EOF) return 1;   fclose(fp);          /* close data file...                            */   return 0;            /* successful, return with good return code      */}/*********************************************//* RESTORE_STATE - reload internal run data  *//*********************************************/int restore_state(){   FILE *fp;   int  i;   struct hnode t_hnode;         /* Temporary hash nodes */   struct unode t_unode;   struct rnode t_rnode;   struct anode t_anode;   struct snode t_snode;   struct inode t_inode;   char   buffer[BUFSIZE];   char   tmp_buf[BUFSIZE];   u_long ul_bogus=0;   fp=fopen(state_fname,"r");   if (fp==NULL)   {      /* Previous run data not found... */      if (verbose>1) printf("%s\n",msg_no_data);      return 0;   /* return with ok code */   }   /* Reading previous run data... */   if (verbose>1) printf("%s %s\n",msg_get_data,state_fname);   /* get easy stuff */   sprintf(tmp_buf,"# Webalizer V%s    ",version);   if ((fgets(buffer,BUFSIZE,fp)) != NULL)                 /* Header record */     {if (strncmp(buffer,tmp_buf,17)) return 99;} /* bad magic? */   else return 1;   /* error exit */   /* Get current timestamp */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      sscanf(buffer,"%d %d %d %d %d %d",       &cur_year, &cur_month, &cur_day,       &cur_hour, &cur_min, &cur_sec);   } else return 2;  /* error exit */   /* calculate current timestamp (seconds since epoch) */   cur_tstamp=((jdate(cur_day,cur_month,cur_year)-epoch)*86400)+                     (cur_hour*3600)+(cur_min*60)+cur_sec;   /* Get monthly totals */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      sscanf(buffer,"%lu %lu %lu %lu %lu %lu %lf %lu %lu %lu",       &t_hit, &t_file, &t_site, &t_url,       &t_ref, &t_agent, &t_xfer, &t_page, &t_visit, &t_user);   } else return 3;  /* error exit */        /* Get daily totals */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      sscanf(buffer,"%lu %lu %lu %d %d",       &dt_site, &ht_hit, &mh_hit, &f_day, &l_day);   } else return 4;  /* error exit */   /* get daily totals */   for (i=0;i<31;i++)   {      if ((fgets(buffer,BUFSIZE,fp)) != NULL)      {         sscanf(buffer,"%lu %lu %lf %lu %lu %lu",          &tm_hit[i],&tm_file[i],&tm_xfer[i],&tm_site[i],&tm_page[i],          &tm_visit[i]);      } else return 5;  /* error exit */   }   /* get hourly totals */   for (i=0;i<24;i++)   {      if ((fgets(buffer,BUFSIZE,fp)) != NULL)      {         sscanf(buffer,"%lu %lu %lf %lu",          &th_hit[i],&th_file[i],&th_xfer[i],&th_page[i]);      } else return 6;  /* error exit */   }   /* get response code totals */   for (i=0;i<TOTAL_RC;i++)   {      if ((fgets(buffer,BUFSIZE,fp)) != NULL)         sscanf(buffer,"%lu",&response[i].count);      else return 7;  /* error exit */   }   /* Kludge for V2.01-06 TOTAL_RC off by one bug */   if (!strncmp(buffer,"# -urls- ",9)) response[TOTAL_RC-1].count=0;   else   {      /* now do hash tables */      /* url table */      if ((fgets(buffer,BUFSIZE,fp)) != NULL)            /* Table header */      { if (strncmp(buffer,"# -urls- ",9)) return 10; }  /* (url)        */      else return 10;   /* error exit */   }   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXURLH);      tmp_buf[strlen(tmp_buf)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 10;  /* error exit */      if (!isdigit((int)buffer[0])) return 10;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu %lu %lf %lu %lu",         &t_unode.flag,&t_unode.count,         &t_unode.files, &t_unode.xfer,         &t_unode.entry, &t_unode.exit);      /* Good record, insert into hash table */      if (put_unode(tmp_buf,t_unode.flag,t_unode.count,         t_unode.xfer,&ul_bogus,t_unode.entry,t_unode.exit,um_htab))      {         if (verbose)         /* Error adding URL node, skipping ... */         fprintf(stderr,"%s %s\n", msg_nomem_u, t_unode.string);      }   }   /* monthly sites table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -sites- ",10)) return 8; }    /* (monthly)    */   else return 8;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      /* Check for end of table */      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXHOST);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 8;  /* error exit */      if (!isdigit((int)buffer[0])) return 8;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu %lu %lf %lu %lu",         &t_hnode.flag,&t_hnode.count,         &t_hnode.files, &t_hnode.xfer,         &t_hnode.visit, &t_hnode.tstamp);      /* get last url */      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 8;  /* error exit */      if (buffer[0]=='-') t_hnode.lasturl=blank_str;      else      {         buffer[strlen(buffer)-1]=0;         t_hnode.lasturl=find_url(buffer);      }      /* Good record, insert into hash table */      if (put_hnode(tmp_buf,t_hnode.flag,         t_hnode.count,t_hnode.files,t_hnode.xfer,&ul_bogus,         t_hnode.visit+1,t_hnode.tstamp,t_hnode.lasturl,sm_htab))      {         /* Error adding host node (monthly), skipping .... */         if (verbose) fprintf(stderr,"%s %s\n",msg_nomem_mh, t_hnode.string);      }   }   /* Daily sites table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -sites- ",10)) return 9; }    /* (daily)      */   else return 9;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      /* Check for end of table */      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXHOST);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 9;  /* error exit */      if (!isdigit((int)buffer[0])) return 9;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu %lu %lf %lu %lu",          &t_hnode.flag,&t_hnode.count,          &t_hnode.files, &t_hnode.xfer,          &t_hnode.visit, &t_hnode.tstamp);      /* get last url */      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 9;  /* error exit */      if (buffer[0]=='-') t_hnode.lasturl=blank_str;      else      {         buffer[strlen(buffer)-1]=0;         t_hnode.lasturl=find_url(buffer);      }      /* Good record, insert into hash table */      if (put_hnode(tmp_buf,t_hnode.flag,         t_hnode.count,t_hnode.files,t_hnode.xfer,&ul_bogus,         t_hnode.visit+1,t_hnode.tstamp,t_hnode.lasturl,sd_htab))      {         /* Error adding host node (daily), skipping .... */         if (verbose) fprintf(stderr,"%s %s\n",msg_nomem_dh, t_hnode.string);      }   }   /* Referrers table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -referrers- ",14)) return 11; } /* (referrers)*/   else return 11;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXREFH);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 11;  /* error exit */      if (!isdigit((int)buffer[0])) return 11;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu",&t_rnode.flag,&t_rnode.count);      /* insert node */      if (put_rnode(tmp_buf,t_rnode.flag,         t_rnode.count, &ul_bogus, rm_htab))      {         if (verbose) fprintf(stderr,"%s %s\n", msg_nomem_r, log_rec.refer);      }   }   /* Agents table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -agents- ",11)) return 12; } /* (agents)*/   else return 12;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXAGENT);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 12;  /* error exit */      if (!isdigit((int)buffer[0])) return 12;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu",&t_anode.flag,&t_anode.count);      /* insert node */      if (put_anode(tmp_buf,t_anode.flag,t_anode.count,         &ul_bogus,am_htab))      {         if (verbose) fprintf(stderr,"%s %s\n", msg_nomem_a, log_rec.agent);      }   }   /* Search Strings table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -search string",16)) return 13; }  /* (search)*/   else return 13;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXSRCH);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 13;  /* error exit */      if (!isdigit((int)buffer[0])) return 13;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%lu",&t_snode.count);      /* insert node */      if (put_snode(tmp_buf,t_snode.count,sr_htab))      {         if (verbose) fprintf(stderr,"%s %s\n", msg_nomem_sc, t_snode.string);      }   }   /* usernames table */   if ((fgets(buffer,BUFSIZE,fp)) != NULL)               /* Table header */   { if (strncmp(buffer,"# -usernames- ",10)) return 14; }   else return 14;   /* error exit */   while ((fgets(buffer,BUFSIZE,fp)) != NULL)   {      /* Check for end of table */      if (!strncmp(buffer,"# End Of Table ",15)) break;      strncpy(tmp_buf,buffer,MAXIDENT);      tmp_buf[strlen(buffer)-1]=0;      if ((fgets(buffer,BUFSIZE,fp)) == NULL) return 14;  /* error exit */      if (!isdigit((int)buffer[0])) return 14;  /* error exit */      /* load temporary node data */      sscanf(buffer,"%d %lu %lu %lf %lu %lu",         &t_inode.flag,&t_inode.count,         &t_inode.files, &t_inode.xfer,         &t_inode.visit, &t_inode.tstamp);      /* Good record, insert into hash table */      if (put_inode(tmp_buf,t_inode.flag,         t_inode.count,t_inode.files,t_inode.xfer,&ul_bogus,         t_inode.visit+1,t_inode.tstamp,im_htab))      {         if (verbose)         /* Error adding username node, skipping .... */         fprintf(stderr,"%s %s\n",msg_nomem_i, t_inode.string);      }   }   fclose(fp);   check_dup = 1;              /* enable duplicate checking */   return 0;                   /* return with ok code       */}

⌨️ 快捷键说明

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