2 webalizer - a web server log analysis program
4 Copyright (C) 1997-2011 Bradford L. Barrett
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version, and provided that the above
10 copyright and permission notice is included with all distributed
11 copies of this or derived software.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 /*********************************************/
25 /* STANDARD INCLUDES */
26 /*********************************************/
32 #include <unistd.h> /* normal stuff */
36 #include <sys/utsname.h>
38 /* ensure sys/types */
40 #include <sys/types.h>
43 /* need socket header? */
44 #ifdef HAVE_SYS_SOCKET_H
45 #include <sys/socket.h>
48 /* some systems need this */
53 #include "webalizer.h" /* main header */
59 struct hist_rec hist
[HISTSIZE
]; /* history structure array */
61 /*********************************************/
62 /* GET_HISTORY - load in history file */
63 /*********************************************/
73 /* try to open history file */
74 hist_fp
=fopen(hist_fname
,"r");
78 if (verbose
>1) printf("%s %s\n",msg_get_hist
,hist_fname
);
79 while ( fgets(buffer
,BUFSIZE
,hist_fp
) != NULL
)
81 if (buffer
[0]=='#') { continue; } /* skip comments */
83 /* get record month/year */
84 sscanf(buffer
,"%d %d",&in_m
,&in_y
);
86 /* check if valid numbers */
87 if ( (in_m
<1 || in_m
>12 || in_y
<1970) )
89 if (verbose
) fprintf(stderr
,"%s (mth=%d)\n",msg_bad_hist
,in_m
);
93 /* populate if first time through */
94 if (hist
[HISTSIZE
-1].year
==0) populate_history(in_m
, in_y
);
96 for (i
=HISTSIZE
-1;i
>=0;i
--)
98 if (in_m
==hist
[i
].month
&& in_y
==hist
[i
].year
) break;
101 if ( (in_m
>hist
[i
].month
&&in_y
==hist
[i
].year
) ||
102 (in_y
>hist
[i
].year
) )
106 n
=(mth_idx(in_m
,in_y
)-mth_idx(hist
[i
].month
,hist
[i
].year
));
110 mth
= hist
[i
].month
+1;
111 if (mth
>12) { mth
=1; yr
++; }
112 memcpy(&hist
[0], &hist
[1], sizeof(hist
[0])*i
);
113 memset(&hist
[i
], 0, sizeof(struct hist_rec
));
114 hist
[i
].year
=yr
; hist
[i
].month
=mth
; n
--;
123 /* month# year# requests files sites xfer firstday lastday */
124 numfields
= sscanf(buffer
,"%d %d %llu %llu %llu %lf %d %d %llu %llu",
139 else if (verbose
>1) printf("%s\n",msg_no_hist
);
142 /*********************************************/
143 /* PUT_HISTORY - write out history file */
144 /*********************************************/
150 char new_fname
[MAXKVAL
+4];
151 char old_fname
[MAXKVAL
+4];
152 struct stat hist_stat
;
156 /* generate 'new' filename */
157 sprintf(new_fname
, "%s.new", hist_fname
);
160 if ( !(lstat(new_fname
, &hist_stat
)) )
162 /* check if the file a symlink */
163 if ( S_ISLNK(hist_stat
.st_mode
) )
166 fprintf(stderr
,"%s %s (symlink)\n",msg_no_open
,new_fname
);
171 /* Generate our timestamp */
173 strftime(timestamp
,sizeof(timestamp
),"%d/%b/%Y %H:%M:%S",localtime(&now
));
175 /* Open file for writing */
176 hist_fp
= fopen(new_fname
,"w");
179 if (verbose
>1) printf("%s\n",msg_put_hist
);
182 fprintf(hist_fp
,"# Webalizer V%s-%s History Data - %s (%d month)\n",
183 version
, editlvl
, timestamp
, HISTSIZE
);
185 for (i
=HISTSIZE
-1;i
>=0;i
--)
187 fprintf(hist_fp
,"%d %d %llu %llu %llu %.0f %d %d %llu %llu\n",
199 /* Done, close file */
202 /* if time-warp error detected, save old */
205 sprintf(old_fname
, "%s.sav", hist_fname
);
206 if ((rename(hist_fname
,old_fname
)==-1)&&(errno
!=ENOENT
)&&verbose
)
207 fprintf(stderr
,"Failed renaming %s to %s: %s\n",
208 hist_fname
,old_fname
,strerror(errno
));
211 /* now rename the 'new' file to real name */
212 if ((rename(new_fname
,hist_fname
) == -1) && verbose
)
213 fprintf(stderr
,"Failed renaming %s to %s\n",new_fname
,hist_fname
);
217 fprintf(stderr
,"%s %s\n",msg_hist_err
,new_fname
);
220 /*********************************************/
221 /* POPULATE_HISTORY - populate with dates */
222 /*********************************************/
224 void populate_history(int month
, int year
)
230 if (hist
[HISTSIZE
-1].year
==0)
232 for (i
=HISTSIZE
-1;i
>=0;i
--)
234 hist
[i
].year
=yr
; hist
[i
].month
=mth
--;
235 if (mth
==0) { yr
--; mth
=12; }
240 /*********************************************/
241 /* UPDATE_HISTORY - update with cur totals */
242 /*********************************************/
244 void update_history()
249 /* populate if first time through */
250 if (hist
[HISTSIZE
-1].year
==0) populate_history(cur_month
,cur_year
);
252 /* we need to figure out where to put in history */
253 for (i
=HISTSIZE
-1;i
>=0;i
--)
255 if (cur_month
==hist
[i
].month
&& cur_year
==hist
[i
].year
) break;
258 if ((cur_month
>hist
[i
].month
&&cur_year
==hist
[i
].year
) ||
259 (cur_year
>hist
[i
].year
))
263 n
=(mth_idx(cur_month
,cur_year
) -
264 mth_idx(hist
[i
].month
,hist
[i
].year
));
269 fprintf(stderr
,"Warning! %d month gap detected! " \
270 "(%d/%d to %d/%d)\n", n
, hist
[i
].month
,
271 hist
[i
].year
, cur_month
, cur_year
);
272 if (n
>11) hist_gap
=1; /* year or more? */
278 mth
= hist
[i
].month
+1;
279 if (mth
>12) { mth
=1; yr
++; }
280 memcpy(&hist
[0],&hist
[1],sizeof(hist
[0])*i
);
281 memset(&hist
[i
], 0, sizeof(struct hist_rec
));
282 hist
[i
].year
=yr
; hist
[i
].month
=mth
; n
--;
291 hist
[i
].month
= cur_month
;
292 hist
[i
].year
= cur_year
;
294 hist
[i
].files
= t_file
;
295 hist
[i
].page
= t_page
;
296 hist
[i
].visit
= t_visit
;
297 hist
[i
].site
= t_site
;
298 hist
[i
].xfer
= t_xfer
/1024;
299 hist
[i
].fday
= f_day
;
300 hist
[i
].lday
= l_day
;
304 /*********************************************/
305 /* SAVE_STATE - save internal data structs */
306 /*********************************************/
319 struct stat state_stat
;
321 char buffer
[BUFSIZE
];
322 char new_fname
[MAXKVAL
+4];
324 /* generate 'new' filename */
325 sprintf(new_fname
, "%s.new", state_fname
);
328 if ( !(lstat(new_fname
, &state_stat
)) )
330 /* check if the file a symlink */
331 if ( S_ISLNK(state_stat
.st_mode
) )
334 fprintf(stderr
,"%s %s (symlink)\n",msg_no_open
,new_fname
);
339 /* Open file for writing */
340 fp
=fopen(new_fname
,"w");
341 if (fp
==NULL
) return 1;
343 /* Saving current run data... */
346 sprintf(buffer
,"%02d/%02d/%04d %02d:%02d:%02d",
347 cur_month
,cur_day
,cur_year
,cur_hour
,cur_min
,cur_sec
);
348 printf("%s [%s]\n",msg_put_data
,buffer
);
351 /* first, save the easy stuff */
353 snprintf(buffer
,sizeof(buffer
),
354 "# Webalizer V%s-%s Incremental Data - %02d/%02d/%04d %02d:%02d:%02d\n",
355 version
,editlvl
,cur_month
,cur_day
,cur_year
,cur_hour
,cur_min
,cur_sec
);
356 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
358 /* Current date/time */
359 sprintf(buffer
,"%d %d %d %d %d %d\n",
360 cur_year
, cur_month
, cur_day
, cur_hour
, cur_min
, cur_sec
);
361 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
363 /* Monthly totals for sites, urls, etc... */
364 sprintf(buffer
,"%llu %llu %llu %llu %llu %llu %.0f %llu %llu %llu\n",
365 t_hit
, t_file
, t_site
, t_url
,
366 t_ref
, t_agent
, t_xfer
, t_page
, t_visit
, t_user
);
367 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
369 /* Daily totals for sites, urls, etc... */
370 sprintf(buffer
,"%llu %llu %llu %d %d\n",
371 dt_site
, ht_hit
, mh_hit
, f_day
, l_day
);
372 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
374 /* Monthly (by day) total array */
377 sprintf(buffer
,"%llu %llu %.0f %llu %llu %llu\n",
378 tm_hit
[i
],tm_file
[i
],tm_xfer
[i
],tm_site
[i
],tm_page
[i
],tm_visit
[i
]);
379 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
382 /* Daily (by hour) total array */
385 sprintf(buffer
,"%llu %llu %.0f %llu\n",
386 th_hit
[i
],th_file
[i
],th_xfer
[i
],th_page
[i
]);
387 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
391 for (i
=0;i
<TOTAL_RC
;i
++)
393 sprintf(buffer
,"%llu\n",response
[i
].count
);
394 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
397 /* now we need to save our linked lists */
399 if (fputs("# -urls- \n",fp
)==EOF
) return 1; /* error exit */
400 for (i
=0;i
<MAXHASH
;i
++)
405 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu %llu %.0f %llu %llu\n",
406 uptr
->string
, uptr
->flag
, uptr
->count
, uptr
->files
,
407 uptr
->xfer
, uptr
->entry
, uptr
->exit
);
408 if (fputs(buffer
,fp
)==EOF
) return 1;
412 if (fputs("# End Of Table - urls\n",fp
)==EOF
) return 1; /* error exit */
414 /* daily hostname list */
415 if (fputs("# -sites- (monthly)\n",fp
)==EOF
) return 1; /* error exit */
417 for (i
=0;i
<MAXHASH
;i
++)
422 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu %llu %.0f %llu %llu\n%s\n",
423 hptr
->string
, hptr
->flag
, hptr
->count
, hptr
->files
,
424 hptr
->xfer
, hptr
->visit
, hptr
->tstamp
,
425 (hptr
->lasturl
==blank_str
)?"-":hptr
->lasturl
);
426 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
430 if (fputs("# End Of Table - sites (monthly)\n",fp
)==EOF
) return 1;
432 /* hourly hostname list */
433 if (fputs("# -sites- (daily)\n",fp
)==EOF
) return 1; /* error exit */
434 for (i
=0;i
<MAXHASH
;i
++)
439 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu %llu %.0f %llu %llu\n%s\n",
440 hptr
->string
, hptr
->flag
, hptr
->count
, hptr
->files
,
441 hptr
->xfer
, hptr
->visit
, hptr
->tstamp
,
442 (hptr
->lasturl
==blank_str
)?"-":hptr
->lasturl
);
443 if (fputs(buffer
,fp
)==EOF
) return 1;
447 if (fputs("# End Of Table - sites (daily)\n",fp
)==EOF
) return 1;
450 if (fputs("# -referrers- \n",fp
)==EOF
) return 1; /* error exit */
453 for (i
=0;i
<MAXHASH
;i
++)
458 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu\n",
459 rptr
->string
, rptr
->flag
, rptr
->count
);
460 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
465 if (fputs("# End Of Table - referrers\n",fp
)==EOF
) return 1;
467 /* User agent list */
468 if (fputs("# -agents- \n",fp
)==EOF
) return 1; /* error exit */
471 for (i
=0;i
<MAXHASH
;i
++)
476 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu\n",
477 aptr
->string
, aptr
->flag
, aptr
->count
);
478 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
483 if (fputs("# End Of Table - agents\n",fp
)==EOF
) return 1;
485 /* Search String list */
486 if (fputs("# -search strings- \n",fp
)==EOF
) return 1; /* error exit */
487 for (i
=0;i
<MAXHASH
;i
++)
492 snprintf(buffer
,sizeof(buffer
),"%s\n%llu\n",
493 sptr
->string
,sptr
->count
);
494 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
498 if (fputs("# End Of Table - search strings\n",fp
)==EOF
) return 1;
501 if (fputs("# -usernames- \n",fp
)==EOF
) return 1; /* error exit */
503 for (i
=0;i
<MAXHASH
;i
++)
508 snprintf(buffer
,sizeof(buffer
),"%s\n%d %llu %llu %.0f %llu %llu\n",
509 iptr
->string
, iptr
->flag
, iptr
->count
, iptr
->files
,
510 iptr
->xfer
, iptr
->visit
, iptr
->tstamp
);
511 if (fputs(buffer
,fp
)==EOF
) return 1; /* error exit */
515 if (fputs("# End Of Table - usernames\n",fp
)==EOF
) return 1;
517 /* Done, close file */
520 /* now rename the 'new' file to real name */
521 if ((rename(new_fname
,state_fname
) == -1) && verbose
)
523 fprintf(stderr
,"Failed renaming %s to %s\n",new_fname
,state_fname
);
524 return 1; /* Failed, return with error code */
526 return 0; /* successful, return with good return code */
529 /*********************************************/
530 /* RESTORE_STATE - reload internal run data */
531 /*********************************************/
537 struct hnode t_hnode
; /* Temporary hash nodes */
538 struct unode t_unode
;
539 struct rnode t_rnode
;
540 struct anode t_anode
;
541 struct snode t_snode
;
542 struct inode t_inode
;
544 char buffer
[BUFSIZE
];
545 char tmp_buf
[BUFSIZE
];
547 u_int64_t ul_bogus
=0;
549 /* if ignoring, just return */
550 if (ignore_state
) return 0;
552 /* try to open state file */
553 fp
=fopen(state_fname
,"r");
556 /* Previous run data not found... */
557 if (verbose
>1) printf("%s\n",msg_no_data
);
558 return 0; /* return with ok code */
561 /* Reading previous run data... */
562 if (verbose
>1) printf("%s %s\n",msg_get_data
,state_fname
);
565 sprintf(tmp_buf
,"# Webalizer V%s ",version
);
566 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Header record */
568 if (strncmp(buffer
,tmp_buf
,16))
570 /* Kludge to allow 2.01 files also */
571 sprintf(tmp_buf
,"# Webalizer V2.01-1");
572 if (strncmp(buffer
,tmp_buf
,19)) return 99; /* bad magic? */
575 else return 1; /* error exit */
577 /* Get current timestamp */
578 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
580 sscanf(buffer
,"%d %d %d %d %d %d",
581 &cur_year
, &cur_month
, &cur_day
,
582 &cur_hour
, &cur_min
, &cur_sec
);
583 } else return 2; /* error exit */
585 /* calculate current timestamp (seconds since epoch) */
586 cur_tstamp
=((jdate(cur_day
,cur_month
,cur_year
)-epoch
)*86400)+
587 (cur_hour
*3600)+(cur_min
*60)+cur_sec
;
589 /* Get monthly totals */
590 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
592 sscanf(buffer
,"%llu %llu %llu %llu %llu %llu %lf %llu %llu %llu",
593 &t_hit
, &t_file
, &t_site
, &t_url
,
594 &t_ref
, &t_agent
, &t_xfer
, &t_page
, &t_visit
, &t_user
);
595 } else return 3; /* error exit */
597 /* Get daily totals */
598 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
600 sscanf(buffer
,"%llu %llu %llu %d %d",
601 &dt_site
, &ht_hit
, &mh_hit
, &f_day
, &l_day
);
602 } else return 4; /* error exit */
604 /* get daily totals */
607 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
609 sscanf(buffer
,"%llu %llu %lf %llu %llu %llu",
610 &tm_hit
[i
],&tm_file
[i
],&tm_xfer
[i
],&tm_site
[i
],&tm_page
[i
],
612 } else return 5; /* error exit */
615 /* get hourly totals */
618 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
620 sscanf(buffer
,"%llu %llu %lf %llu",
621 &th_hit
[i
],&th_file
[i
],&th_xfer
[i
],&th_page
[i
]);
622 } else return 6; /* error exit */
625 /* get response code totals */
626 for (i
=0;i
<TOTAL_RC
;i
++)
628 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
629 sscanf(buffer
,"%llu",&response
[i
].count
);
630 else return 7; /* error exit */
633 /* Kludge for V2.01-06 TOTAL_RC off by one bug */
634 if (!strncmp(buffer
,"# -urls- ",9)) response
[TOTAL_RC
-1].count
=0;
637 /* now do hash tables */
640 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
641 { if (strncmp(buffer
,"# -urls- ",9)) return 10; } /* (url) */
642 else return 10; /* error exit */
645 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
647 if (!strncmp(buffer
,"# End Of Table ",15)) break;
648 strncpy(tmp_buf
,buffer
,MAXURLH
);
649 tmp_buf
[strlen(tmp_buf
)-1]=0;
651 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 10; /* error exit */
652 if (!isdigit((unsigned char)buffer
[0])) return 10; /* error exit */
654 /* load temporary node data */
655 sscanf(buffer
,"%d %llu %llu %lf %llu %llu",
656 &t_unode
.flag
,&t_unode
.count
,
657 &t_unode
.files
, &t_unode
.xfer
,
658 &t_unode
.entry
, &t_unode
.exit
);
660 /* Good record, insert into hash table */
661 if (put_unode(tmp_buf
,t_unode
.flag
,t_unode
.count
,
662 t_unode
.xfer
,&ul_bogus
,t_unode
.entry
,t_unode
.exit
,um_htab
))
665 /* Error adding URL node, skipping ... */
666 fprintf(stderr
,"%s %s\n", msg_nomem_u
, t_unode
.string
);
670 /* monthly sites table */
671 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
672 { if (strncmp(buffer
,"# -sites- ",10)) return 8; } /* (monthly) */
673 else return 8; /* error exit */
675 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
677 /* Check for end of table */
678 if (!strncmp(buffer
,"# End Of Table ",15)) break;
679 strncpy(tmp_buf
,buffer
,MAXHOST
);
680 tmp_buf
[strlen(buffer
)-1]=0;
682 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 8; /* error exit */
683 if (!isdigit((unsigned char)buffer
[0])) return 8; /* error exit */
685 /* load temporary node data */
686 sscanf(buffer
,"%d %llu %llu %lf %llu %llu",
687 &t_hnode
.flag
,&t_hnode
.count
,
688 &t_hnode
.files
, &t_hnode
.xfer
,
689 &t_hnode
.visit
, &t_hnode
.tstamp
);
692 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 8; /* error exit */
693 if (buffer
[0]=='-') t_hnode
.lasturl
=blank_str
;
696 buffer
[strlen(buffer
)-1]=0;
697 t_hnode
.lasturl
=find_url(buffer
);
700 /* Good record, insert into hash table */
701 if (put_hnode(tmp_buf
,t_hnode
.flag
,
702 t_hnode
.count
,t_hnode
.files
,t_hnode
.xfer
,&ul_bogus
,
703 t_hnode
.visit
+1,t_hnode
.tstamp
,t_hnode
.lasturl
,sm_htab
))
705 /* Error adding host node (monthly), skipping .... */
706 if (verbose
) fprintf(stderr
,"%s %s\n",msg_nomem_mh
, t_hnode
.string
);
710 /* Daily sites table */
711 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
712 { if (strncmp(buffer
,"# -sites- ",10)) return 9; } /* (daily) */
713 else return 9; /* error exit */
715 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
717 /* Check for end of table */
718 if (!strncmp(buffer
,"# End Of Table ",15)) break;
719 strncpy(tmp_buf
,buffer
,MAXHOST
);
720 tmp_buf
[strlen(buffer
)-1]=0;
722 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 9; /* error exit */
723 if (!isdigit((unsigned char)buffer
[0])) return 9; /* error exit */
725 /* load temporary node data */
726 sscanf(buffer
,"%d %llu %llu %lf %llu %llu",
727 &t_hnode
.flag
,&t_hnode
.count
,
728 &t_hnode
.files
, &t_hnode
.xfer
,
729 &t_hnode
.visit
, &t_hnode
.tstamp
);
732 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 9; /* error exit */
733 if (buffer
[0]=='-') t_hnode
.lasturl
=blank_str
;
736 buffer
[strlen(buffer
)-1]=0;
737 t_hnode
.lasturl
=find_url(buffer
);
740 /* Good record, insert into hash table */
741 if (put_hnode(tmp_buf
,t_hnode
.flag
,
742 t_hnode
.count
,t_hnode
.files
,t_hnode
.xfer
,&ul_bogus
,
743 t_hnode
.visit
+1,t_hnode
.tstamp
,t_hnode
.lasturl
,sd_htab
))
745 /* Error adding host node (daily), skipping .... */
746 if (verbose
) fprintf(stderr
,"%s %s\n",msg_nomem_dh
, t_hnode
.string
);
750 /* Referrers table */
751 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
752 { if (strncmp(buffer
,"# -referrers- ",14)) return 11; } /* (referrers)*/
753 else return 11; /* error exit */
755 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
757 if (!strncmp(buffer
,"# End Of Table ",15)) break;
758 strncpy(tmp_buf
,buffer
,MAXREFH
);
759 tmp_buf
[strlen(buffer
)-1]=0;
761 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 11; /* error exit */
762 if (!isdigit((unsigned char)buffer
[0])) return 11; /* error exit */
764 /* load temporary node data */
765 sscanf(buffer
,"%d %llu",&t_rnode
.flag
,&t_rnode
.count
);
768 if (put_rnode(tmp_buf
,t_rnode
.flag
,
769 t_rnode
.count
, &ul_bogus
, rm_htab
))
771 if (verbose
) fprintf(stderr
,"%s %s\n", msg_nomem_r
, log_rec
.refer
);
776 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
777 { if (strncmp(buffer
,"# -agents- ",11)) return 12; } /* (agents)*/
778 else return 12; /* error exit */
780 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
782 if (!strncmp(buffer
,"# End Of Table ",15)) break;
783 strncpy(tmp_buf
,buffer
,MAXAGENT
);
784 tmp_buf
[strlen(buffer
)-1]=0;
786 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 12; /* error exit */
787 if (!isdigit((unsigned char)buffer
[0])) return 12; /* error exit */
789 /* load temporary node data */
790 sscanf(buffer
,"%d %llu",&t_anode
.flag
,&t_anode
.count
);
793 if (put_anode(tmp_buf
,t_anode
.flag
,t_anode
.count
,
796 if (verbose
) fprintf(stderr
,"%s %s\n", msg_nomem_a
, log_rec
.agent
);
800 /* Search Strings table */
801 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
802 { if (strncmp(buffer
,"# -search string",16)) return 13; } /* (search)*/
803 else return 13; /* error exit */
805 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
807 if (!strncmp(buffer
,"# End Of Table ",15)) break;
808 strncpy(tmp_buf
,buffer
,MAXSRCH
);
809 tmp_buf
[strlen(buffer
)-1]=0;
811 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 13; /* error exit */
812 if (!isdigit((unsigned char)buffer
[0])) return 13; /* error exit */
814 /* load temporary node data */
815 sscanf(buffer
,"%llu",&t_snode
.count
);
818 if (put_snode(tmp_buf
,t_snode
.count
,sr_htab
))
820 if (verbose
) fprintf(stderr
,"%s %s\n", msg_nomem_sc
, t_snode
.string
);
824 /* usernames table */
825 if ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
) /* Table header */
826 { if (strncmp(buffer
,"# -usernames- ",10)) return 14; }
827 else return 14; /* error exit */
829 while ((fgets(buffer
,BUFSIZE
,fp
)) != NULL
)
831 /* Check for end of table */
832 if (!strncmp(buffer
,"# End Of Table ",15)) break;
833 strncpy(tmp_buf
,buffer
,MAXIDENT
);
834 tmp_buf
[strlen(buffer
)-1]=0;
836 if ((fgets(buffer
,BUFSIZE
,fp
)) == NULL
) return 14; /* error exit */
837 if (!isdigit((unsigned char)buffer
[0])) return 14; /* error exit */
839 /* load temporary node data */
840 sscanf(buffer
,"%d %llu %llu %lf %llu %llu",
841 &t_inode
.flag
,&t_inode
.count
,
842 &t_inode
.files
, &t_inode
.xfer
,
843 &t_inode
.visit
, &t_inode
.tstamp
);
845 /* Good record, insert into hash table */
846 if (put_inode(tmp_buf
,t_inode
.flag
,
847 t_inode
.count
,t_inode
.files
,t_inode
.xfer
,&ul_bogus
,
848 t_inode
.visit
+1,t_inode
.tstamp
,im_htab
))
851 /* Error adding username node, skipping .... */
852 fprintf(stderr
,"%s %s\n",msg_nomem_i
, t_inode
.string
);
857 check_dup
= 1; /* enable duplicate checking */
858 return 0; /* return with ok code */