From: Frédéric Marchal Date: Tue, 31 Jan 2012 19:49:47 +0000 (+0100) Subject: Don't fail if report_type doesn't request for topusers X-Git-Tag: v2.3.3-pre1~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=124ec0b0b20e17e994b6879358d85bbe1f7a5e6f;p=thirdparty%2Fsarg.git Don't fail if report_type doesn't request for topusers The topusers page is always generated and now serves as an index for the other report pages instead of promoting the topsites pages as the main page. --- diff --git a/topsites.c b/topsites.c index 9c05b21..6ca2cfe 100644 --- a/topsites.c +++ b/topsites.c @@ -76,10 +76,7 @@ void topsites(void) sprintf(general2,"%s/sarg-general2",outdirname); sprintf(general3,"%s/sarg-general3",outdirname); - if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) - sprintf(report,"%s/index.html",outdirname); - else - sprintf(report,"%s/topsites.html",outdirname); + sprintf(report,"%s/topsites.html",outdirname); if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) { debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general,general2); diff --git a/topuser.c b/topuser.c index 0f1f712..24b9b64 100644 --- a/topuser.c +++ b/topuser.c @@ -29,9 +29,31 @@ extern struct globalstatstruct globstat; +/*! +Save the total number of users. The number is written in sarg-users and set +in a global variable for further reference. + +\param totuser The total number of users. +*/ +static void set_total_users(int totuser) +{ + char tusr[1024]; + FILE *fp_ou; + + snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); + if((fp_ou=fopen(tusr,"w"))==NULL) { + debuga(_("(topuser) Cannot open file %s\n"),tusr); + exit(EXIT_FAILURE); + } + fprintf(fp_ou,"%d\n",totuser); + if (fclose(fp_ou)==EOF) + debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); + globstat.totuser=totuser; +} + void topuser(void) { - FILE *fp_in = NULL, *fp_ou = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; + FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL; long long int ttnbytes=0, ttnacc=0, tnacc=0; long long int tnbytes=0, ttnelap=0, tnelap=0; long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; @@ -44,7 +66,7 @@ void topuser(void) int posicao=0; char olduser[MAX_USER_LEN], csort[MAXLEN]; char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; - char user[MAX_USER_LEN], tusr[MAXLEN]; + char user[MAX_USER_LEN]; const char *sfield="-n -k 2,2"; const char *order; const char *sort_field; @@ -139,6 +161,8 @@ void topuser(void) } #endif + set_total_users(totuser); + if((TopuserSort & TOPUSER_SORT_USER) != 0) { sfield="-k 1,1"; sort_field=_("user"); @@ -193,10 +217,17 @@ void topuser(void) fputs("",fp_top3); fprintf(fp_top3,_("Period: %s"),period.html); fputs("\n",fp_top3); - fputs("",fp_top3); - fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order); - fputs("\n",fp_top3); - fprintf(fp_top3,"%s\n",_("Top users")); + if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) { + fputs("",fp_top3); + fprintf(fp_top3,_("Sort: %s, %s"),sort_field,sort_order); + fputs("\n",fp_top3); + fprintf(fp_top3,"%s\n",_("Top users")); + } else { + /* TRANSLATORS: This is the title of the main report page when no + * top users list are requested. + */ + fprintf(fp_top3,"%s\n",_("Table of content")); + } close_html_header(fp_top3); if (!indexonly) { @@ -445,15 +476,5 @@ void topuser(void) if (fclose(fp_top3)==EOF) debuga(_("Failed to close the top user list %s - %s\n"),top3,strerror(errno)); - snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname); - if((fp_ou=fopen(tusr,"w"))==NULL) { - debuga(_("(topuser) Cannot open file %s\n"),tusr); - exit(EXIT_FAILURE); - } - fprintf(fp_ou,"%d\n",totuser); - if (fclose(fp_ou)==EOF) - debuga(_("Failed to close file %s - %s\n"),tusr,strerror(errno)); - globstat.totuser=totuser; - return; }