parse_uri: break apart the uri * Side Effects: * - sets r->args to rest after '?' (or NULL if no '?') * - sets r->uri to request uri (without r->args part) * - sets r->hostname (if not set already) from request (scheme://host:port) */
| 578 | * - sets r->hostname (if not set already) from request (scheme://host:port) |
| 579 | */ |
| 580 | AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri) |
| 581 | { |
| 582 | int status = HTTP_OK; |
| 583 | |
| 584 | r->unparsed_uri = apr_pstrdup(r->pool, uri); |
| 585 | |
| 586 | /* http://issues.apache.org/bugzilla/show_bug.cgi?id=31875 |
| 587 | * http://issues.apache.org/bugzilla/show_bug.cgi?id=28450 |
| 588 | * |
| 589 | * This is not in fact a URI, it's a path. That matters in the |
| 590 | * case of a leading double-slash. We need to resolve the issue |
| 591 | * by normalizing that out before treating it as a URI. |
| 592 | */ |
| 593 | while ((uri[0] == '/') && (uri[1] == '/')) { |
| 594 | ++uri ; |
| 595 | } |
| 596 | if (r->method_number == M_CONNECT) { |
| 597 | status = apr_uri_parse_hostinfo(r->pool, uri, &r->parsed_uri); |
| 598 | } |
| 599 | else { |
| 600 | status = apr_uri_parse(r->pool, uri, &r->parsed_uri); |
| 601 | } |
| 602 | |
| 603 | if (status == APR_SUCCESS) { |
| 604 | /* if it has a scheme we may need to do absoluteURI vhost stuff */ |
| 605 | if (r->parsed_uri.scheme |
| 606 | && !ap_cstr_casecmp(r->parsed_uri.scheme, ap_http_scheme(r))) { |
| 607 | r->hostname = r->parsed_uri.hostname; |
| 608 | } |
| 609 | else if (r->method_number == M_CONNECT) { |
| 610 | r->hostname = r->parsed_uri.hostname; |
| 611 | } |
| 612 | |
| 613 | r->args = r->parsed_uri.query; |
| 614 | if (r->parsed_uri.path) { |
| 615 | r->uri = r->parsed_uri.path; |
| 616 | } |
| 617 | else if (r->method_number == M_OPTIONS) { |
| 618 | r->uri = apr_pstrdup(r->pool, "*"); |
| 619 | } |
| 620 | else { |
| 621 | r->uri = apr_pstrdup(r->pool, "/"); |
| 622 | } |
| 623 | |
| 624 | #if defined(OS2) || defined(WIN32) |
| 625 | /* Handle path translations for OS/2 and plug security hole. |
| 626 | * This will prevent "http://www.wherever.com/..\..\/" from |
| 627 | * returning a directory for the root drive. |
| 628 | */ |
| 629 | { |
| 630 | char *x; |
| 631 | |
| 632 | for (x = r->uri; (x = strchr(x, '\\')) != NULL; ) |
| 633 | *x = '/'; |
| 634 | } |
| 635 | #endif /* OS2 || WIN32 */ |
| 636 | } |
| 637 | else { |
no test coverage detected