MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Url

Method Url

lib/remote/url.cpp:13–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace icinga;
12
13Url::Url(const String& base_url)
14{
15 String url = base_url;
16
17 if (url.GetLength() == 0)
18 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Empty URL."));
19
20 size_t pHelper = String::NPos;
21 if (url[0] != '/')
22 pHelper = url.Find(":");
23
24 if (pHelper != String::NPos) {
25 if (!ParseScheme(url.SubStr(0, pHelper)))
26 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Scheme."));
27 url = url.SubStr(pHelper + 1);
28 }
29
30 if (*url.Begin() != '/')
31 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: '/' expected after scheme."));
32
33 if (url.GetLength() == 1) {
34 return;
35 }
36
37 if (*(url.Begin() + 1) == '/') {
38 pHelper = url.Find("/", 2);
39
40 if (pHelper == String::NPos)
41 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: Missing '/' after authority."));
42
43 if (!ParseAuthority(url.SubStr(0, pHelper)))
44 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Authority"));
45
46 url = url.SubStr(pHelper);
47 }
48
49 if (*url.Begin() == '/') {
50 pHelper = url.FindFirstOf("#?");
51 if (!ParsePath(url.SubStr(1, pHelper - 1)))
52 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Path"));
53
54 if (pHelper != String::NPos)
55 url = url.SubStr(pHelper);
56 } else
57 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: Missing path."));
58
59 if (*url.Begin() == '?') {
60 pHelper = url.Find("#");
61 if (!ParseQuery(url.SubStr(1, pHelper - 1)))
62 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Query"));
63
64 if (pHelper != String::NPos)
65 url = url.SubStr(pHelper);
66 }
67
68 if (*url.Begin() == '#') {
69 if (!ParseFragment(url.SubStr(1)))
70 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Fragment"));

Callers 15

HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleRequestMethod · 0.45
HandleGetMethod · 0.45

Calls 5

FindMethod · 0.80
SubStrMethod · 0.80
FindFirstOfMethod · 0.80
GetLengthMethod · 0.45
BeginMethod · 0.45

Tested by

no test coverage detected