util::split_location (public)

 util::split_location location protoVar hostnameVar portVar

Defined in packages/acs-tcl/tcl/utilities-procs.tcl

Split the provided location into "proto", "hostname" and "port". The results are returned on success to the provided output variables. The function supports IP-literal notation according to RFC 3986 section 3.2.2.

Parameters:
location (required)
protoVar (required)
hostnameVar (required)
portVar (required)
Returns:
boolean value indicating success
Author:
Gustaf Neumann
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_util__split_and_join_location util__split_and_join_location (test acs-tcl) util::split_location util::split_location test_util__split_and_join_location->util::split_location util::ns_set_pretty_print util::ns_set_pretty_print (private) util::split_location->util::ns_set_pretty_print security::get_insecure_location security::get_insecure_location (private) security::get_insecure_location->util::split_location security::get_register_subsite security::get_register_subsite (public) security::get_register_subsite->util::split_location security::get_secure_location security::get_secure_location (public) security::get_secure_location->util::split_location security::validated_host_header security::validated_host_header (public) security::validated_host_header->util::split_location util_current_location util_current_location (public) util_current_location->util::split_location

Testcases:
util__split_and_join_location
Source code:
    upvar $protoVar proto $hostnameVar hostname $portVar port

    try {
        set urlInfo [ns_parseurl $location]
    } on error {errorMsg} {
        #
        # Here we cannot use "ad_log warning", since it calls
        # "split_location" leading potentially in some error cases to
        # a recursive loop (call path "ad_log warning",
        # "util::request_info -with_headers...",
        # "util_current_location", "security::validated_host_header"
        # "util::split_location"). Therefore, we are using here the a
        # simplified version just printing the header fields.
        #
        set msg "cannot parse URL '$location': $errorMsg"
        if {[ns_conn isconnected]} {
            append msg  \n [ns_conn request]  \n [util::ns_set_pretty_print [ns_conn headers]]
        }
        ns_log warning $msg
        set success 0
    } on ok {result} {
        if {[dict exists $urlInfo proto] && [dict exists $urlInfo host]} {
            set proto [dict get $urlInfo proto]
            set hostname [dict get $urlInfo host]
            if {[dict exists $urlInfo port]} {
                set port [dict get $urlInfo port]
            } else {
                set port [dict get {http 80 https 443} $proto]
            }
            set success 1
        } else {
            ns_log warning "util::split_location <$location> fails"  "no host and port information in <$urlInfo>"
            set success 0
        }
    }
    return $success
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/utilities-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: