* Parses network-location. * urlp on input the URL; on output the path, after the leading / * user NULL if no user/password permitted * password holder for password * host holder for host * port port number; only set if one is supplied. * * Returns an error string. */
| 339 | * Returns an error string. |
| 340 | */ |
| 341 | PROXY_DECLARE(char *) |
| 342 | ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp, |
| 343 | char **passwordp, char **hostp, apr_port_t *port) |
| 344 | { |
| 345 | char *addr, *scope_id, *strp, *host, *url = *urlp; |
| 346 | char *user = NULL, *password = NULL; |
| 347 | apr_port_t tmp_port; |
| 348 | apr_status_t rv; |
| 349 | |
| 350 | if (url[0] != '/' || url[1] != '/') { |
| 351 | return "Malformed URL"; |
| 352 | } |
| 353 | host = url + 2; |
| 354 | url = strchr(host, '/'); |
| 355 | if (url == NULL) { |
| 356 | url = ""; |
| 357 | } |
| 358 | else { |
| 359 | *(url++) = '\0'; /* skip separating '/' */ |
| 360 | } |
| 361 | |
| 362 | /* find _last_ '@' since it might occur in user/password part */ |
| 363 | strp = strrchr(host, '@'); |
| 364 | |
| 365 | if (strp != NULL) { |
| 366 | *strp = '\0'; |
| 367 | user = host; |
| 368 | host = strp + 1; |
| 369 | |
| 370 | /* find password */ |
| 371 | strp = strchr(user, ':'); |
| 372 | if (strp != NULL) { |
| 373 | *strp = '\0'; |
| 374 | password = ap_proxy_canonenc(p, strp + 1, strlen(strp + 1), enc_user, 1, 0); |
| 375 | if (password == NULL) { |
| 376 | return "Bad %-escape in URL (password)"; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | user = ap_proxy_canonenc(p, user, strlen(user), enc_user, 1, 0); |
| 381 | if (user == NULL) { |
| 382 | return "Bad %-escape in URL (username)"; |
| 383 | } |
| 384 | } |
| 385 | if (userp != NULL) { |
| 386 | *userp = user; |
| 387 | } |
| 388 | if (passwordp != NULL) { |
| 389 | *passwordp = password; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Parse the host string to separate host portion from optional port. |
| 394 | * Perform range checking on port. |
| 395 | */ |
| 396 | rv = apr_parse_addr_port(&addr, &scope_id, &tmp_port, host, p); |
| 397 | if (rv != APR_SUCCESS || addr == NULL || scope_id != NULL) { |
| 398 | return "Invalid host/port"; |
no test coverage detected