28 SetUrl(std::string(url ? url :
""));
56 if (url.length()==0)
return false;
62 std::size_t pos = s.find(
"://");
64 if (pos != std::string::npos) {
65 fProtocol = s.substr(0, pos);
69 if (s.length() == 0)
return fValid;
73 if (pos != std::string::npos) {
74 SetOptions(s.substr(pos+1));
83 if (pos != std::string::npos) {
84 fHostName = s.substr(0, pos);
85 fFileName = s.substr(pos+1);
90 pos = fHostName.find(
":");
91 if (pos != std::string::npos) {
93 if (showerr)
EOUT(
"Invalid URL format:%s - wrong port number", fHostName.c_str());
106 ReplaceSpecialSymbols(fOptions);
114 while ((pos = opt.find(
"%27")) != std::string::npos) opt.replace(pos, 3,
"\'");
115 while ((pos = opt.find(
"%22")) != std::string::npos) opt.replace(pos, 3,
"\"");
116 while ((pos = opt.find(
"%20")) != std::string::npos) opt.replace(pos, 3,
" ");
117 while ((pos = opt.find(
"%3E")) != std::string::npos) opt.replace(pos, 3,
">");
118 while ((pos = opt.find(
"%3C")) != std::string::npos) opt.replace(pos, 3,
"<");
119 while ((pos = opt.find(
"%5B")) != std::string::npos) opt.replace(pos, 3,
"[");
120 while ((pos = opt.find(
"%5D")) != std::string::npos) opt.replace(pos, 3,
"]");
126 if (fFileName.length()==0)
return fHostName;
127 if (fHostName.length()==0)
return fFileName;
129 return dabc::format(
"%s/%s", fHostName.c_str(), fFileName.c_str());
134 if (fPort<=0)
return std::string();
142 if (port <= 0) port = dfltport;
144 return (port>0) ? fHostName +
dabc::format(
":%d", port) : fHostName;
149 if (nodeid<0)
return std::string();
151 return dabc::format(
"dabc://node%d/%s", nodeid, itemname.length() > 0 ? itemname.c_str() :
"");
157 if ((nodeid<0) || fullportname.empty())
return sbuf;
159 sbuf = ComposeItemName(nodeid, fullportname);
173 if (!url.
SetUrl(name,
false))
return false;
181 if (url.
GetProtocol().compare(
"dabc")!=0)
return false;
184 if (node.compare(0, 4,
"node")!=0)
return false;
188 if (!
str_to_int(node.c_str(), &nodeid))
return false;
189 if (nodeid<0)
return false;
198 GetOption(
"", number, &res);
205 if (value) value->clear();
207 if (fOptions.empty())
return false;
208 if ((optionnumber<0) && optname.empty())
return false;
213 while (p < fOptions.length()) {
220 bool q1(
false), q2(
false), special(
false);
222 size_t separ = p, posequal = std::string::npos;
223 for(;separ<fOptions.length();separ++) {
226 if (fOptions[separ] ==
'\\') { special = !special;
continue; }
227 else special =
false;
230 if (!q2 && (fOptions[separ]==
'\'') && !special) { q1 = !q1;
continue; }
231 if (!q1 && (fOptions[separ]==
'\"') && !special) { q2 = !q2;
continue; }
234 if (fOptions[separ] ==
'&')
break;
235 if ((fOptions[separ] ==
'=') && (posequal = std::string::npos)) posequal = separ;
242 if (optionnumber>=0) {
243 if (cnt==optionnumber) {
244 if (value) *value = fOptions.substr(p, separ-p);
249 if (separ-p >= optname.length()) {
250 bool find = fOptions.compare(p, optname.length(), optname)==0;
256 if (p==separ)
return true;
258 if (fOptions[p]==
'=') {
261 if ((p<separ) && value) {
262 *value = fOptions.substr(p, separ-p);
264 if ((value->length()>1) && ((value->at(0)==
'\'') || (value->at(0)==
'\"'))
265 && (value->at(0) == value->at(value->length()-1))) {
267 value->resize(value->length()-1);
285 if (GetOption(optname, -1, &res))
return res;
292 std::string res = GetOptionStr(optname);
294 if (res.empty())
return dflt;
297 if (
str_to_int(res.c_str(), &resi))
return resi;
304 std::string res = GetOptionStr(optname);
306 if (res.empty())
return dflt;
316 std::string res = GetOptionStr(optname);
318 if (res.empty())
return dflt;
Uniform Resource Locator interpreter.
std::string GetOptionsPart(int number=0) const
std::string GetOptionStr(const std::string &optname, const std::string &dflt="") const
bool SetUrl(const std::string &url, bool showerr=true)
std::string GetFullName() const
bool GetOptionBool(const std::string &optname, bool dflt=false) const
std::string GetFileName() const
int GetOptionInt(const std::string &optname, int dflt=0) const
std::string GetHostName() const
std::string GetProtocol() const
std::string GetPortStr() const
static void ReplaceSpecialSymbols(std::string &opt)
!
std::string GetHostNameWithPort(int dfltport=0) const
static bool DecomposeItemName(const std::string &url, int &nodeid, std::string &itemtname)
Method decompose from url nodeid and full item name, which includes all parents.
double GetOptionDouble(const std::string &optname, double dflt=0.) const
void SetOptions(const std::string &opt)
Method allows to set URL options directly to be able use all Get methods.
bool GetOption(const std::string &optname, int optionnumber=-1, std::string *value=nullptr) const
static std::string ComposeItemName(int nodeid, const std::string &itemname="")
!
static std::string ComposePortName(int nodeid, const std::string &fullportname, int portid=-1)
! Method creates url string with port address, which includes nodeid and full portname If optional pa...
bool str_to_double(const char *val, double *res)
Convert string to double value.
std::string format(const char *fmt,...)
const char * xmlTrueValue
const char * xmlFalseValue
bool str_to_int(const char *val, int *res)
Convert string to integer value.