| 249 | */ |
| 250 | |
| 251 | static void |
| 252 | xmlNanoHTTPScanURL(xmlNanoHTTPCtxtPtr ctxt, const char *URL) { |
| 253 | xmlURIPtr uri; |
| 254 | int len; |
| 255 | |
| 256 | /* |
| 257 | * Clear any existing data from the context |
| 258 | */ |
| 259 | if (ctxt->protocol != NULL) { |
| 260 | xmlFree(ctxt->protocol); |
| 261 | ctxt->protocol = NULL; |
| 262 | } |
| 263 | if (ctxt->hostname != NULL) { |
| 264 | xmlFree(ctxt->hostname); |
| 265 | ctxt->hostname = NULL; |
| 266 | } |
| 267 | if (ctxt->path != NULL) { |
| 268 | xmlFree(ctxt->path); |
| 269 | ctxt->path = NULL; |
| 270 | } |
| 271 | if (ctxt->query != NULL) { |
| 272 | xmlFree(ctxt->query); |
| 273 | ctxt->query = NULL; |
| 274 | } |
| 275 | if (URL == NULL) return; |
| 276 | |
| 277 | uri = xmlParseURIRaw(URL, 1); |
| 278 | if (uri == NULL) |
| 279 | return; |
| 280 | |
| 281 | if ((uri->scheme == NULL) || (uri->server == NULL)) { |
| 282 | xmlFreeURI(uri); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | ctxt->protocol = xmlMemStrdup(uri->scheme); |
| 287 | /* special case of IPv6 addresses, the [] need to be removed */ |
| 288 | if ((uri->server != NULL) && (*uri->server == '[')) { |
| 289 | len = strlen(uri->server); |
| 290 | if ((len > 2) && (uri->server[len - 1] == ']')) { |
| 291 | ctxt->hostname = (char *) xmlCharStrndup(uri->server + 1, len -2); |
| 292 | } else |
| 293 | ctxt->hostname = xmlMemStrdup(uri->server); |
| 294 | } else |
| 295 | ctxt->hostname = xmlMemStrdup(uri->server); |
| 296 | if (uri->path != NULL) |
| 297 | ctxt->path = xmlMemStrdup(uri->path); |
| 298 | else |
| 299 | ctxt->path = xmlMemStrdup("/"); |
| 300 | if (uri->query != NULL) |
| 301 | ctxt->query = xmlMemStrdup(uri->query); |
| 302 | if (uri->port != 0) |
| 303 | ctxt->port = uri->port; |
| 304 | |
| 305 | xmlFreeURI(uri); |
| 306 | } |
| 307 | |
| 308 | /** |
no test coverage detected