74 {
75
76
80 return StatusCode::FAILURE;
81 }
82
84 FILE* p_inp=fopen(
file.c_str(),
"r");
85 if (p_inp==nullptr) {
87 return StatusCode::FAILURE;
88 }
89
90 const unsigned int bufsize=999;
91 char p_buf[bufsize];
92 while (!feof(p_inp)) {
93 char* p_line=fgets(p_buf,bufsize,p_inp);
94 if (p_line!=NULL && p_line[0]!='#') {
95 std::string
buf=std::string(p_line);
96 std::string::size_type iofs1=0;
97
98 bool sequal=false;
99 std::vector<std::string> domains;
100 std::vector<std::string> servers;
101 while (iofs1<
buf.size()) {
102 std::string::size_type iofs2=
buf.find(
' ',iofs1);
103
104 if (iofs2==std::string::npos) iofs2=
buf.size()-1;
105 std::string token=
buf.substr(iofs1,iofs2-iofs1);
106
107 if (token!="" && token!=" ") {
108 if (token=="=") {
109 sequal=true;
110 } else if (!sequal) {
111
112 domains.push_back(std::move(token));
113 } else {
114
115 if (!
m_nofailover || servers.size()==0 || token==
"atlas_dd")
116 servers.push_back(std::move(token));
117 }
118 }
119 iofs1=iofs2+1;
120 }
121
122
123 bool useit=false;
124 unsigned int bestlen=0;
125 for (const std::string& d : domains) {
126 std::string::size_type len=
d.size();
127 std::string::size_type hlen=
m_hostname.size();
128 if (hlen>=len && d==
m_hostname.substr(hlen-len,len)) {
129 if (len>bestlen) {
130 useit=true;
131 bestlen=len;
132 }
133 }
134
135
137 ATH_MSG_INFO (
"No specific match for domain found - use default fallback");
138 useit=true;
139 bestlen=0;
140 }
141 }
142 if (useit) {
143
144
145 for (
unsigned int i=0;
i<servers.size();++
i) {
147
149
150
151 if (servers[i]==
"ATLF")
priority-=2000;
154 " (priority " << priority << ")");
155 }
156 }
157 }
158 }
159 }
160 fclose(p_inp);
162 " servers found for host " <<
m_hostname <<
" [";
165 }
167 return StatusCode::SUCCESS;
168}
std::pair< std::string, int > ServerPair
std::vector< ServerPair > m_servermap
Gaudi::Property< std::string > m_configfile
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)