MCPcopy Create free account
hub / github.com/apache/qpid-proton / parse_url

Function parse_url

cpp/src/url.cpp:92–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void parse_url(char *url, const char **scheme, const char **user, const char **pass, const char **host, const char **port, const char **path)
93{
94 if (!url) return;
95
96 char *slash = std::strchr(url, '/');
97
98 if (slash && slash>url) {
99 char *scheme_end = std::strstr(slash-1, "://");
100
101 if (scheme_end && scheme_end<slash) {
102 *scheme_end = '\0';
103 *scheme = url;
104 url = scheme_end + 3;
105 slash = std::strchr(url, '/');
106 }
107 } else if (0 == strncmp(url, "//", 2)) {
108 url += 2;
109 slash = std::strchr(url, '/');
110 }
111
112 if (slash) {
113 *slash = '\0';
114 *path = slash + 1;
115 }
116
117 char *at = std::strchr(url, '@');
118 if (at) {
119 *at = '\0';
120 char *up = url;
121 url = at + 1;
122 char *colon = std::strchr(up, ':');
123 if (colon) {
124 *colon = '\0';
125 char *p = colon + 1;
126 pni_urldecode(p, p);
127 *pass = p;
128 }
129 pni_urldecode(up, up);
130 *user = up;
131 }
132
133 *host = url;
134 char *open = (*url == '[') ? url : 0;
135 if (open) {
136 char *close = std::strchr(open, ']');
137 if (close) {
138 *host = open + 1;
139 *close = '\0';
140 url = close + 1;
141 }
142 }
143
144 char *colon = std::strchr(url, ':');
145 if (colon) {
146 *colon = '\0';
147 *port = colon + 1;
148 }
149}

Callers 1

implMethod · 0.85

Calls 1

pni_urldecodeFunction · 0.70

Tested by

no test coverage detected