MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / SplitURI

Function SplitURI

cpp/src/platform/HttpClient.cpp:274–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272// http://example.com/index.html#pos
273
274bool SplitURI
275(
276const std::string& uri,
277std::string& protocol,
278std::string& host,
279std::string& file,
280int& port,
281bool& useSSL
282)
283{
284 const char *p = uri.c_str();
285 const char *sl = strstr(p, "//");
286 unsigned int offs = 0;
287 if(sl)
288 {
289 size_t colon = uri.find(':');
290 size_t firstslash = uri.find('/');
291 if(colon < firstslash)
292 protocol = uri.substr(0, colon);
293 if(strncmp(p, "http://", 7) == 0)
294 {
295 useSSL = false;
296 offs = 7;
297 }
298 else if(strncmp(p, "https://", 8) == 0)
299 {
300 useSSL = true;
301 offs = 8;
302 }
303 else
304 return false;
305
306 p = sl + 2;
307 }
308
309 sl = strchr(p, '/');
310 if(!sl)
311 {
312 host = p;
313 file = "/";
314 }
315 else
316 {
317 host = uri.substr(offs, sl - p);
318 file = sl;
319 }
320
321 port = -1;
322 size_t colon = host.find(':');
323 if(colon != std::string::npos)
324 {
325 port = atoi(host.c_str() + colon);
326 host.erase(port);
327 }
328
329 return true;
330}
331

Callers 2

DownloadMethod · 0.85
_RedirectMethod · 0.85

Calls 2

findMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected