MCPcopy Create free account
hub / github.com/apache/httpd / escape_absolute_uri

Function escape_absolute_uri

modules/mappers/mod_rewrite.c:767–831  ·  view source on GitHub ↗

* escape absolute uri, which may or may not be path oriented. * So let's handle them differently. */

Source from the content-addressed store, hash-verified

765 * So let's handle them differently.
766 */
767static char *escape_absolute_uri(apr_pool_t *p, char *uri, unsigned scheme)
768{
769 char *cp;
770
771 /* be safe.
772 * NULL should indicate elsewhere, that something's wrong
773 */
774 if (!scheme || strlen(uri) < scheme) {
775 return NULL;
776 }
777
778 cp = uri + scheme;
779
780 /* scheme with authority part? */
781 if (cp[-1] == '/') {
782 /* skip host part */
783 while (*cp && *cp != '/') {
784 ++cp;
785 }
786
787 /* nothing after the hostpart. ready! */
788 if (!*cp || !*++cp) {
789 return apr_pstrdup(p, uri);
790 }
791
792 /* remember the hostname stuff */
793 scheme = cp - uri;
794
795 /* special thing for ldap.
796 * The parts are separated by question marks. From RFC 2255:
797 * ldapurl = scheme "://" [hostport] ["/"
798 * [dn ["?" [attributes] ["?" [scope]
799 * ["?" [filter] ["?" extensions]]]]]]
800 */
801 if (!ap_cstr_casecmpn(uri, "ldap", 4)) {
802 char *token[5];
803 int c = 0;
804
805 token[0] = cp = apr_pstrdup(p, cp);
806 while (*cp && c < 4) {
807 if (*cp == '?') {
808 token[++c] = cp + 1;
809 *cp = '\0';
810 }
811 ++cp;
812 }
813
814 return apr_pstrcat(p, apr_pstrndup(p, uri, scheme),
815 ap_escape_uri(p, token[0]),
816 (c >= 1) ? "?" : NULL,
817 (c >= 1) ? ap_escape_uri(p, token[1]) : NULL,
818 (c >= 2) ? "?" : NULL,
819 (c >= 2) ? ap_escape_uri(p, token[2]) : NULL,
820 (c >= 3) ? "?" : NULL,
821 (c >= 3) ? ap_escape_uri(p, token[3]) : NULL,
822 (c >= 4) ? "?" : NULL,
823 (c >= 4) ? ap_escape_uri(p, token[4]) : NULL,
824 NULL);

Callers 2

hook_uri2fileFunction · 0.85
hook_fixupFunction · 0.85

Calls 1

ap_cstr_casecmpnFunction · 0.85

Tested by

no test coverage detected