]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - userinfo.c
Indent the configure script for more readability.
[thirdparty/sarg.git] / userinfo.c
index c535ceed4ec02cf4af68e615800c546702242722..1a48778f212f50ba93a65fca0cfedb4b2252aadc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2013
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -79,7 +79,7 @@ struct userinfostruct *userinfo_create(const char *userid,const char *ip)
        if (!UserStrings) {
                UserStrings=StringBuffer_Create();
                if (!UserStrings) {
-                       debuga(_("Not enough memory to store the user's strings\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the user's strings\n"));
                        exit(EXIT_FAILURE);
                }
        }
@@ -93,7 +93,7 @@ struct userinfostruct *userinfo_create(const char *userid,const char *ip)
        if (!group) {
                group=malloc(sizeof(*group));
                if (!group) {
-                       debuga(_("Not enough memory to store user \"%s\"\n"),userid);
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store user \"%s\"\n"),userid);
                        exit(EXIT_FAILURE);
                }
                memset(group,0,sizeof(*group));
@@ -106,15 +106,22 @@ struct userinfostruct *userinfo_create(const char *userid,const char *ip)
 
        user->id=StringBuffer_Store(UserStrings,userid);
        if (!user->id) {
-               debuga(_("Not enough memory to store user ID \"%s\"\n"),userid);
+               debuga(__FILE__,__LINE__,_("Not enough memory to store user ID \"%s\"\n"),userid);
                exit(EXIT_FAILURE);
        }
        user->label=user->id; //assign a label to avoid a NULL pointer in case none is provided
        if (ip) {
-               user->id_is_ip=0;
+               /*
+                * IP address is not the same as the user's ID. A separate buffer
+                * must be allocated.
+                */
+               user->id_is_ip=false;
                user->ip=StringBuffer_Store(UserStrings,ip);
        } else {
-               user->id_is_ip=1;
+               /*
+                * User's IP address share the same buffer as the user's ID.
+                */
+               user->id_is_ip=true;
                user->ip=user->id;
        }
 
@@ -155,7 +162,7 @@ struct userinfostruct *userinfo_create(const char *userid,const char *ip)
        user->filename=StringBuffer_Store(UserStrings,filename);
        if (!user->filename)
        {
-               debuga(_("Not enough memory to store the file name for user \"%s\"\n"),user->id);
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the file name for user \"%s\"\n"),user->id);
                exit(EXIT_FAILURE);
        }
 
@@ -185,7 +192,7 @@ void userinfo_label(struct userinfostruct *uinfo,const char *label)
        if (!UserStrings) return;
        uinfo->label=StringBuffer_Store(UserStrings,label);
        if (!uinfo->label) {
-               debuga(_("Not enough memory to store label \"%s\" of user \"%s\"\n"),label,uinfo->id);
+               debuga(__FILE__,__LINE__,_("Not enough memory to store label \"%s\" of user \"%s\"\n"),label,uinfo->id);
                exit(EXIT_FAILURE);
        }
 }
@@ -304,41 +311,44 @@ Read the file containing the user names to alias in the report.
 */
 void read_useralias(const char *Filename)
 {
-       FILE *fi;
+       FileObject *fi;
        longline line;
        char *buf;
 
-       if (debug) debuga(_("Reading user alias file \"%s\"\n"),Filename);
+       if (debug) debuga(__FILE__,__LINE__,_("Reading user alias file \"%s\"\n"),Filename);
 
        UserAliases=Alias_Create();
        if (!UserAliases) {
-               debuga(_("Cannot store user's aliases\n"));
+               debuga(__FILE__,__LINE__,_("Cannot store user's aliases\n"));
                exit(EXIT_FAILURE);
        }
 
-       fi=fopen(Filename,"rt");
+       fi=FileObject_Open(Filename);
        if (!fi) {
-               debuga(_("Cannot read user name alias file \"%s\" - %s\n"),Filename,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot read user name alias file \"%s\": %s\n"),Filename,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the user name aliases\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),Filename);
                exit(EXIT_FAILURE);
        }
 
        while ((buf=longline_read(fi,line)) != NULL) {
                if (Alias_Store(UserAliases,buf)<0) {
-                       debuga(_("While reading \"%s\"\n"),Filename);
+                       debuga(__FILE__,__LINE__,_("While reading \"%s\"\n"),Filename);
                        exit(EXIT_FAILURE);
                }
        }
 
        longline_destroy(&line);
-       fclose(fi);
+       if (FileObject_Close(fi)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),Filename,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
+       }
 
        if (debug) {
-               debuga(_("List of user names to alias:\n"));
+               debuga(__FILE__,__LINE__,_("List of user names to alias:\n"));
                Alias_PrintList(UserAliases);
        }
 }