]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topsites.c
Clarify an entry of the report's menu
[thirdparty/sarg.git] / topsites.c
index 9e424aeeadea98322c20542122408ed4f0e1d12d..842ccb63a10aeac80282467313a802c78121f24d 100644 (file)
@@ -39,10 +39,8 @@ void topsites(void)
    char general[MAXLEN];
    char general2[MAXLEN];
    char general3[MAXLEN];
-   char per[MAXLEN];
    char sites[MAXLEN];
    char report[MAXLEN];
-   char period[100];
    const char *sortf;
    const char *sortt;
    long long int nacc;
@@ -57,7 +55,7 @@ void topsites(void)
    int url_len;
    int ourl_size=0;
    struct getwordstruct gwarea;
-   struct longlinestruct line;
+   longline line;
    struct generalitemstruct item;
 
    if(Privacy)
@@ -67,24 +65,12 @@ void topsites(void)
    sprintf(sites,"%s/sarg-sites",outdirname);
    sprintf(general2,"%s/sarg-general2",outdirname);
    sprintf(general3,"%s/sarg-general3",outdirname);
-   sprintf(per,"%s/sarg-period",outdirname);
 
    if ((ReportType & REPORT_TYPE_TOPUSERS) == 0)
       sprintf(report,"%s/index.html",outdirname);
    else
       sprintf(report,"%s/topsites.html",outdirname);
 
-   if ((fp_in = fopen(per, "r")) == 0) {
-      debuga(_("(topsites) Cannot open file %s\n"),per);
-      exit(EXIT_FAILURE);
-   }
-
-   if (!fgets(period,sizeof(period),fp_in)) {
-      debuga(_("(topsites) read error in %s\n"),per);
-      exit(EXIT_FAILURE);
-   }
-   fclose(fp_in);
-
    sprintf(csort,"sort -k 4,4 -o \"%s\" \"%s\"",general2,general);
    cstatus=system(csort);
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
@@ -104,12 +90,12 @@ void topsites(void)
      exit(EXIT_FAILURE);
    }
 
-   if (longline_prepare(&line)<0) {
+   if ((line=longline_create())==NULL) {
       debuga(_("Not enough memory to read file %s\n"),general2);
       exit(EXIT_FAILURE);
    }
 
-   while((buf=longline_read(fp_in,&line))!=NULL) {
+   while((buf=longline_read(fp_in,line))!=NULL) {
       ger_read(buf,&item,general2);
       if(item.total) continue;
 
@@ -150,7 +136,7 @@ void topsites(void)
    }
    fclose(fp_in);
    unlink(general2);
-   longline_free(&line);
+   longline_destroy(&line);
 
    if (ourl) {
       fprintf(fp_ou,"%lld\t%lld\t%lld\t%s\n",tnacc,tnbytes,tntime,ourl);
@@ -198,7 +184,7 @@ void topsites(void)
 
    write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Top sites"));
    fputs("<tr><td class=\"header_c\">",fp_ou);
-   fprintf(fp_ou,_("Period: %s"),period);
+   fprintf(fp_ou,_("Period: %s"),period.html);
    fputs("</td></tr>\n",fp_ou);
    fputs("<tr><th class=\"header_c\">",fp_ou);
    fprintf(fp_ou,_("Top %d sites"),TopSitesNum);
@@ -206,18 +192,17 @@ void topsites(void)
    close_html_header(fp_ou);
 
    fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
-   fputs("<tr><td></td></tr>\n",fp_ou);
    fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("NUM"),_("ACCESSED SITE"),_("CONNECT"),_("BYTES"),_("TIME"));
 
    regs=0;
    ntopsites = 0;
 
-   if (longline_prepare(&line)<0) {
+   if ((line=longline_create())==NULL) {
       debuga(_("Not enough memory to read file %s\n"),sites);
       exit(EXIT_FAILURE);
    }
 
-   while(regs<TopSitesNum && (buf=longline_read(fp_in,&line))!=NULL) {
+   while(regs<TopSitesNum && (buf=longline_read(fp_in,line))!=NULL) {
       getword_start(&gwarea,buf);
       if (getword_atoll(&nacc,&gwarea,'\t')<0) {
          debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
@@ -256,11 +241,13 @@ void topsites(void)
       fprintf(fp_ou,"</a></td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",wwork1,wwork2,wwork3);
    }
    fclose(fp_in);
-   longline_free(&line);
+   longline_destroy(&line);
 
    fputs("</table></div>\n",fp_ou);
-   write_html_trailer(fp_ou);
-   fclose(fp_ou);
+   if (write_html_trailer(fp_ou)<0)
+      debuga(_("Write error in file %s\n"),report);
+   if (fclose(fp_ou)==EOF)
+      debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
 
    return;