48 static regEntry *first;
52 std::vector<std::string> hVec;
56 static void Add(regEntry *rP) {rP->next = first; first = rP;}
59 regEntry *Find(
const char *hName)
60 {regEntry *rP = first;
61 while(rP && (hName != rP->hName)) rP = rP->next;
62 if (rP && rP->parent)
return rP->parent;
67 {
if (want) myLock.ReadLock();
71 void Update(
const char **hlist,
int hlnum,
bool rot)
73 hVec.assign(hlist, hlist+hlnum);
78 regEntry(
const char *hname, regEntry *pP)
79 : next(0),
parent(pP), hName(hname), refs(0),
82 regEntry(
const char *hname,
const char *hlist[],
int hlnum,
bool rot)
83 : next(0),
parent(0), hName(hname), refs(0), rotate(rot)
84 {hVec.assign(hlist, hlist+hlnum);}
93 regEntry *regEntry::first = 0;
111 std::vector<XrdNetAddr> &aVec,
int *ordn,
120 if (!(reP = regEntry::Find(hSpec.c_str())))
122 return "pseudo host not registered";
127 if (reP->rotate) refs = reP->refs++;
139 if (aVec.size() == 0)
return "registry entry unresolvable";
148 const char *hList[],
int hLNum,
149 std::string *eText,
bool rotate)
155 if (!hName || *hName !=
pfx || !hList || hLNum <= 0)
156 {
if (eText) *eText =
"invalid calling arguments";
163 for (
int i = 0; i < hLNum; i++)
if (!Resolve(hList[i], eText))
return false;
168 if ((reP = regEntry::Find(hName))) reP->Update(hList, hLNum, rotate);
169 else regEntry::Add(
new regEntry(hName, hList, hLNum, rotate));
180 std::string *eText,
bool rotate)
182 char *comma, *hosts = strdup(hList);
183 std::vector<const char*> hVec;
187 if (!hName || *hName !=
pfx || !hList)
188 {
if (eText) *eText =
"invalid calling arguments";
194 if (*hList ==
pfx)
return SetAlias(hName, hList, eText);
199 hVec.push_back(hosts);
201 while((comma = index(comma,
',')))
203 hVec.push_back(comma);
208 for (
int i = 0; i < (int)hVec.size(); i++)
209 {
if (!index(hVec[i],
':'))
211 {*eText =
"port missing for '";
212 *eText += hVec[i]; *eText +=
"'";
221 bool aOK =
Register(hName, hVec.data(), (
int)hVec.size(), eText, rotate);
233 bool XrdNetRegistry::Resolve(
const char *hSpec, std::string *eText)
244 if (
emsg && strncmp(
emsg,
"Dynamic ", 8))
246 {*eText =
"unable to resolve '"; *eText += hSpec;
247 *eText +=
"'; "; *eText +=
emsg;
262 bool XrdNetRegistry::SetAlias(
const char *hAlias,
const char *hName,
266 const char *eWhy = 0;
271 if (regEntry::Find(hAlias)) eWhy =
"source already exists";
272 else if (!(reP = regEntry::Find(hName))) eWhy =
"target does not exist";
276 {*eText =
"alias "; *eText += hAlias; *eText +=
" not created; ";
284 regEntry::Add(
new regEntry(hAlias,reP));
int emsg(int rc, char *msg)
const char * Set(const char *hSpec, int pNum=PortInSpec)
static bool Register(const char *hName, const char *hList[], int hLNum, std::string *eText=0, bool rotate=false)
static const char * GetAddrs(const std::string &hSpec, std::vector< XrdNetAddr > &aVec, int *ordn=0, XrdNetUtils::AddrOpts opts=XrdNetUtils::allIPMap, int pNum=XrdNetUtils::PortInSpec)
static const char pfx
Registry names must start with this character.
static const char * GetAddrs(const char *hSpec, XrdNetAddr *aListP[], int &aListN, AddrOpts opts=allIPMap, int pNum=PortInSpec)