rp_call_filters

one of the documented procedures in this installation of the ACS
Usage:
rp_call_filters   conn   kind
What it does:
Invokes filters in the rp_filters arrays. $kind must be one of preauth, postauth, and trace.
Defined in: /web/philip/packages/acs-core/request-processor-procs.tcl

Source code:


    # Loop through all filters in order of priority (they're stored in sorted order
    # in the NSV).
    foreach filter_info [nsv_get rp_filters "[ns_conn method],$kind" ] {
	set path [lindex $filter_info 3]
	if { [string match $path [ad_conn url]] } {
	    # We found a match with the path - apply the filter, catching any
	    # errors that might occur.

	    set errno [catch {
		set proc [lindex $filter_info 4]
		set args [lindex $filter_info 5]
		set debug [lindex $filter_info 6]
		set critical [lindex $filter_info 7]

		# Use [info args $proc] to obtain a list of the names of all
		# arguments to the procedure $proc. Place the number of arguments
		# into $proc_argcount.
		set proc_args [info args $proc]
		set proc_argcount [llength $proc_args]

		# Perform some magic to figure out how to invoke the procedure
		# (differs based on the number of elements).
		if { [string equal [lindex $proc_args [expr { [llength $proc_args] - 2 }]] "args"] } {
		    # The second-to-last argument name can be "args", in which case
		    # all the arguments are supposed to be wrapped in a list and placed
		    # there. So wrap the arguments in a list.
		    set args [list $args]
		}
		set actual_argcount [llength $args]

		if { [string equal $debug "t"] } {
		    ns_log "Notice" "Executing filter $proc for [ns_conn method] [ad_conn url]..."
		}

		if { $actual_argcount >= 3 || $proc_argcount - $actual_argcount == 2 } {
		    # Procedure has conn and kind.
		    set result [eval $proc [concat [list $conn] $args [list $kind]]]
		} elseif { $proc_argcount - $actual_argcount == 1 } {
		    # Procedure has kind.
		    set result [eval $proc [concat $args [list $kind]]]
		} else {
		    # Procedure has neither conn nor kind.
		    set result [eval $proc $args]
		}
		
		if { [string equal $debug "t"] } {
		    ns_log "Notice" "Done executing filter $proc."
		}

		if { [string equal $result "filter_break"] } {
		    # Halt invocations of filters.
		    set return "filter_break"
		} elseif { [string equal $result "filter_return"] } {
		    # We're outta here!
		    set return "filter_return"
		} elseif { ![string equal $result "filter_ok"] } {
		    ns_log "Filter" "Invalid result \"$result\" from filter $proc: should be filter_ok, filter_break, or filter_return"
		    if { [string equal $critical "t"] } {
			error "Critical filter $proc failed."
		    }
		}
	    } errmsg]
            if { $errno } {
		# Uh-oh - an error occurred. Dump a stack trace to the log.
		# Eventually we'll be really nice and write a server error
		# message containing the stack trace (a la ClientDebug) if
		# the user is an administrator.

		global errorInfo
		ns_log "Error" "Filter $proc returned error: $errorInfo"
		if { $critical == "t" } {
		    error "Critical filter $proc failed."
		}
	    }
	}
	if { [info exists return] } {
	    # If the return variable was set, we want to return that value
	    # (e.g., filter_break or filter_return).
	    return $return
	}
    }

    # No problems!
    return "filter_ok"


philg@mit.edu