]>
git.ipfire.org Git - thirdparty/sarg.git/blob - userinfo.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 //! The number of users to group in one unit.
31 #define USERS_PER_GROUP 50
33 /*! \brief Group the users in one allocation unit.
34 Structure to store a group of users and reduce the number of memory
37 struct usergroupstruct
39 //! The next group of users.
40 struct usergroupstruct
*next
;
42 struct userinfostruct list
[USERS_PER_GROUP
];
43 //! The number of users stored in the list.
47 //! The first group of users.
48 static struct usergroupstruct
*first_user_group
=NULL
;
50 struct userinfostruct
*userinfo_create(const char *userid
)
52 struct usergroupstruct
*group
, *last
;
53 struct userinfostruct
*user
;
61 for (group
=first_user_group
; group
; group
=group
->next
) {
62 if (group
->nusers
<USERS_PER_GROUP
) break;
67 group
=malloc(sizeof(*group
));
69 debuga(_("Not enough memory to store the user\n"));
72 memset(group
,0,sizeof(*group
));
76 first_user_group
=group
;
78 user
=group
->list
+group
->nusers
++;
80 strncpy(user
->id
,userid
,MAX_USER_LEN
-1);
81 user
->id
[MAX_USER_LEN
-1]='\0';
84 for(i
=0 ; userid
[i
] && i
<MAX_USER_FNAME_LEN
-1 ; i
++) {
85 if(userid
[i
]=='?' || userid
[i
]=='.' || userid
[i
]==':' || userid
[i
]=='/' || userid
[i
]=='\\' || userid
[i
]=='\'' ||
86 userid
[i
]=='$' || userid
[i
]=='@' || userid
[i
]=='\"' || userid
[i
]=='*') {
88 user
->filename
[i
]='_';
92 user
->filename
[i
]=userid
[i
];
96 user
->filename
[i
]='\0';
100 for (group
=first_user_group
; group
; group
=group
->next
) {
101 lastuser
=(group
->next
) ? group
->nusers
: group
->nusers
-1;
102 for (i
=0 ; i
<lastuser
; i
++) {
103 if (strcasecmp(user
->filename
,group
->list
[i
].filename
)==0) {
104 clen
=sprintf(cstr
,"-%04X",count
++);
105 if (flen
+clen
<MAX_USER_FNAME_LEN
)
106 strcpy(user
->filename
+flen
,cstr
);
108 strcpy(user
->filename
+MAX_USER_FNAME_LEN
-clen
,cstr
);
116 void userinfo_free(void)
118 struct usergroupstruct
*group
, *next
;
120 for (group
=first_user_group
; group
; group
=next
) {
124 first_user_group
=NULL
;
127 struct userinfostruct
*userinfo_find_from_file(const char *filename
)
129 struct usergroupstruct
*group
;
132 for (group
=first_user_group
; group
; group
=group
->next
) {
133 for (i
=0 ; i
<group
->nusers
; i
++)
134 if (strcmp(filename
,group
->list
[i
].filename
)==0)
135 return(group
->list
+i
);
140 struct userinfostruct
*userinfo_find_from_id(const char *id
)
142 struct usergroupstruct
*group
;
145 for (group
=first_user_group
; group
; group
=group
->next
) {
146 for (i
=0 ; i
<group
->nusers
; i
++)
147 if (strcmp(id
,group
->list
[i
].id
)==0)
148 return(group
->list
+i
);