22 #include "uriparser.h" 31 URIParser::URIParser(
const std::string& location)
33 size_t len = location.length();
34 m_buffer =
new char[len + 1];
35 strncpy(m_buffer, location.c_str(), len);
37 URIScan(m_buffer, &m_parts);
40 URIParser::~URIParser()
42 SAFE_DELETE_ARRAY(m_buffer);
45 void URIParser::URIScan(
char *uri, URI_t *parts)
48 char *after_scheme = uri;
49 memset(parts,
'\0',
sizeof(URI_t));
52 if ((p = strchr(uri,
'#')) != NULL)
55 parts->fragment = ++p;
57 if ((p = strchr(uri,
' ')) != NULL)
60 for (p = after_scheme; *p; p++)
62 if (*p ==
'/' || *p ==
'#' || *p ==
'?')
69 if (toupper(after_scheme[0]) ==
'U' 70 && toupper(after_scheme[1]) ==
'R' 71 && toupper(after_scheme[2]) ==
'L')
78 parts->scheme = after_scheme;
95 if ((p = strchr(parts->host,
'/')) != NULL)
100 parts->absolute = p + 1;
103 if ((p = strchr(parts->host,
'@')) != NULL)
107 parts->user = parts->host;
110 if ((p = strchr(parts->user,
':')) != NULL)
118 if ((p = strchr(parts->host,
']')) != NULL)
124 parts->port = (unsigned) atoi(p + 2);
129 if ((p = strchr(parts->host,
':')) != NULL)
134 parts->port = (unsigned) atoi(p + 1);
141 parts->absolute = p + 1;
147 parts->relative = (*after_scheme) ? after_scheme : NULL;