33 const char *usr = (
const char *)u;
48 XrdOucString *msg = (XrdOucString *)u;
50 if (msg->length() > 0)
53 *msg = g->
Name(); *msg +=
": ";
56 *msg +=
", members(s): ";
78 XrdOucString *opt = (XrdOucString *)s;
80 if (!opt || opt->length() <= 0 || (*opt) ==
"getfirst")
84 if (opt->beginswith(
"getnextgrp:")) {
85 XrdOucString grp(
"||");
86 grp.insert(g->
Name(),1);
87 if (opt->find(grp) == STR_NPOS) {
101 : fName(n), fMembers(m)
124 XPDLOC(GMGR,
"Group::Print")
128 if (
fName !=
"default") {
145 if (!usr || !usr[0] || n == 0)
177 if (!usr || !usr[0]) {
193 XrdOucString u(usr); u +=
",";
196 if (iu == 0 ||
fMembers[iu-1] ==
',')
221 return (fGroups.Num() > 0 ? fGroups.Apply(
f,arg) : (
XrdProofGroup *)0);
267 if (grp && strlen(grp) > 0) {
269 return fGroups.Find(grp);
286 if (!usr || strlen(usr) <= 0)
292 if (grp && strlen(grp) > 0) {
293 g = fGroups.Find(grp);
294 if (g && (!strncmp(g->
Name(),
"default",7) || g->
HasMember(usr)))
301 g = fGroups.Apply(
CheckUser, (
void *)usr);
304 return ((!g) ? fGroups.Find(
"default") :
g);
318 return fGroups.Apply(
AuxFunc,&fIterator);
327 XPDLOC(GMGR,
"GroupMgr::Config")
329 if ((!fn || strlen(fn) <= 0)) {
330 if (fCfgFile.fName != fn) {
342 return fGroups.Num();
346 if (fCfgFile.fName != fn) {
354 if (stat(fCfgFile.fName.c_str(), &st) != 0)
356 TRACE(DBG,
"enter: time of last modification: " << st.st_mtime);
359 if (st.st_mtime <= fCfgFile.fMtime)
return fGroups.Num();
362 fCfgFile.fMtime = st.st_mtime;
375 if (ParseInfoFrom(fCfgFile.fName.c_str()) != 0) {
376 TRACE(XERR,
"problems parsing config file "<<fCfgFile.fName);
383 return fGroups.Num();
393 XPDLOC(GMGR,
"GroupMgr::ParseInfoFrom")
396 if (!fn || strlen(fn) <= 0) {
397 TRACE(XERR,
"file name undefined!");
403 if (!(fin = fopen(fn,
"r"))) {
404 TRACE(XERR,
"cannot open file: "<<fn<<
" (errno:"<<errno<<
")");
410 while (fgets(lin,
sizeof(lin),fin)) {
412 if (lin[strlen(lin)-1] ==
'\n') lin[strlen(lin)-1] =
'\0';
414 if (lin[0] ==
'#' || strlen(lin) <= 0)
continue;
416 bool gotkey = 0, gotgrp = 0;
417 XrdOucString gl(lin), tok, key,
group;
420 while ((from = gl.tokenize(tok, from,
',')) != -1) {
421 if (tok.length() > 0) {
425 }
else if (!gotgrp) {
433 if (!gotkey || !gotgrp) {
435 TRACE(DBG,
"incomplete line: " << lin);
439 if (key ==
"include") {
441 XrdOucString subfn = group;
445 if (ParseInfoFrom(subfn.c_str()) != 0) {
446 TRACE(XERR,
"problems parsing included file "<<subfn);
451 if (key ==
"priorityfile") {
453 fPriorityFile.fName = group;
455 fPriorityFile.fMtime = 0;
463 if (key ==
"group") {
466 fGroups.Add(group.c_str(), (g =
new XrdProofGroup(group.c_str())));
467 while ((from = gl.tokenize(tok, from,
',')) != -1) {
468 if (tok.length() > 0)
472 }
else if (key ==
"property") {
477 bool gotname = 0, gotnom = 0;
478 while ((from = gl.tokenize(tok, from,
',')) != -1) {
479 if (tok.length() > 0) {
483 }
else if (!gotnom) {
484 nom = atoi(tok.c_str());
490 if (!gotname || !gotnom) {
492 TRACE(DBG,
"incomplete property line: " << lin);
497 fGroups.Add(group.c_str(), (g =
new XrdProofGroup(group.c_str())));
498 if (name ==
"priority")
500 if (name ==
"fraction")
517 XPDLOC(GMGR,
"GroupMgr::ReadPriorities")
521 if (stat(fPriorityFile.fName.c_str(), &st) != 0)
523 TRACE(DBG,
"time of last modification: " << st.st_mtime);
526 if (st.st_mtime <= fPriorityFile.fMtime) {
527 TRACE(DBG,
"file unchanged since last reading - do nothing ");
532 fPriorityFile.fMtime = st.st_mtime;
536 if (!(fin = fopen(fPriorityFile.fName.c_str(),
"r"))) {
537 TRACE(XERR,
"cannot open file: "<<fPriorityFile.fName<<
" (errno:"<<errno<<
")");
546 while (fgets(lin,
sizeof(lin),fin)) {
548 if (lin[strlen(lin)-1] ==
'\n') lin[strlen(lin)-1] =
'\0';
550 if (lin[0] ==
'#' || strlen(lin) <= 0)
continue;
552 XrdOucString gl(lin),
group, value;
555 if ((from = gl.tokenize(group, 0,
'=')) == -1)
560 TRACE(XERR,
"found info for unknown group: "<<group<<
" - ignoring");
563 gl.tokenize(value, from,
'=');
564 if (value.length() <= 0) {
565 TRACE(XERR,
"value missing: read line is: '"<<gl<<
"'");
569 if (value.find(
'.') == STR_NPOS)
620 if (eff && eff->
glo) {
626 }
else if (eff->
opt == 1) {
631 }
else if (eff->
opt == 2) {
680 }
else if (glo.
totfrac > 100) {
const char * Name() const
static int AuxFunc(const char *, XrdProofGroup *g, void *s)
Generic function used for auxiliary purpose.
void AddMember(const char *usr)
XrdProofGroupMgr(const char *fn=0)
Constructor.
int ParseInfoFrom(const char *fn)
Parse config information from the open file 'fin'.
XrdProofGroup(const char *n, const char *m=0)
Constructor.
#define TRACE(Flag, Args)
int SetEffectiveFractions(bool optprio)
Go through the list of active groups (those having at least a non-idle member) and determine the effe...
void SetPriority(float p)
XrdOucHash< XrdProofGroupMember > fActives
XrdProofGroup * GetGroup(const char *grp)
Returns the instance of for group 'grp.
void Print()
Dump group content.
bool HasMember(const char *usr)
Check if 'usr' is member of this group.
int ReadPriorities()
Read update priorities from the file defined at configuration time.
static int ExportGroup(const char *, XrdProofGroup *g, void *u)
Add a string describing group 'g' to a global string.
const char * Members() const
#define XrdSysMutexHelper
void Count(const char *usr, int n=1)
Modify the active count.
XrdProofGroup * GetUserGroup(const char *usr, const char *grp=0)
Returns the instance of the first group to which this user belongs; if grp != 0, return the instance ...
int Active(const char *usr=0)
Return the number of active groups (usr = 0) or the number of active sessions for user 'usr'...
static int PrintGroup(const char *, XrdProofGroup *g, void *)
Print info describing group 'g' to stdout.
XrdProofGroup * Next()
Returns the instance of next group in the pseudo-iterator functionality.
~XrdProofGroup()
Destructor.
static char * Expand(char *p)
Expand path 'p' relative to: $HOME if begins with ~/ <user>'s $HOME if begins with ~<user>/ $PWD if d...
static constexpr double s
XrdOucString Export(const char *grp)
Return a string describing the group.
static int SetGroupFracEff(const char *, XrdProofGroup *g, void *s)
Check if user 'u' is memmebr of group 'grp'.
static int GetGroupsInfo(const char *, XrdProofGroup *g, void *s)
Fill the global group structure.
int Config(const char *fn)
(Re-)configure the group info using the file 'fn'.
void Print(const char *grp)
Return a string describing the group.
static int CheckUser(const char *, XrdProofGroup *g, void *u)
Check if user 'u' is memmebr of group 'grp'.
XrdProofGroup * Apply(int(*f)(const char *, XrdProofGroup *, void *), void *arg)
Apply function 'f' to the hash table of groups; 'arg' is passed to 'f' in the last argument...