| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # Apache::ConfigParser::Directive: A single Apache directive or start context. | 
| 2 |  |  |  |  |  |  | # | 
| 3 |  |  |  |  |  |  | # Copyright (C) 2001-2005 Blair Zajac.  All rights reserved. | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package Apache::ConfigParser::Directive; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | require 5.004_05; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 2 |  |  | 2 |  | 15987 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 68 |  | 
| 10 | 2 |  |  | 2 |  | 8 | use Exporter; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 65 |  | 
| 11 | 2 |  |  | 2 |  | 8 | use Carp; | 
|  | 2 |  |  |  |  | 10 |  | 
|  | 2 |  |  |  |  | 127 |  | 
| 12 | 2 |  |  | 2 |  | 9 | use File::Spec     0.82; | 
|  | 2 |  |  |  |  | 84 |  | 
|  | 2 |  |  |  |  | 52 |  | 
| 13 | 2 |  |  | 2 |  | 1421 | use Tree::DAG_Node 1.04; | 
|  | 2 |  |  |  |  | 42179 |  | 
|  | 2 |  |  |  |  | 79 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 22 | use vars qw(@EXPORT_OK @ISA $VERSION); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 186 |  | 
| 16 |  |  |  |  |  |  | @ISA     = qw(Tree::DAG_Node Exporter); | 
| 17 |  |  |  |  |  |  | $VERSION = '1.02'; | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Determine if the filenames are case sensitive. | 
| 20 | 2 |  |  | 2 |  | 9 | use constant CASE_SENSITIVE_PATH => (! File::Spec->case_tolerant); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 186 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # This is a utility subroutine to determine if the specified path is | 
| 23 |  |  |  |  |  |  | # the /dev/null equivalent on this operating system. | 
| 24 | 2 |  |  | 2 |  | 9 | use constant DEV_NULL    =>    File::Spec->devnull; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 151 |  | 
| 25 | 2 |  |  | 2 |  | 9 | use constant DEV_NULL_LC => lc(File::Spec->devnull); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 268 |  | 
| 26 |  |  |  |  |  |  | sub is_dev_null { | 
| 27 | 2484 |  |  | 2484 | 1 | 2188 | if (CASE_SENSITIVE_PATH) { | 
| 28 | 2484 |  |  |  |  | 6019 | return $_[0] eq DEV_NULL; | 
| 29 |  |  |  |  |  |  | } else { | 
| 30 |  |  |  |  |  |  | return lc($_[0]) eq DEV_NULL_LC; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  | push(@EXPORT_OK, qw(DEV_NULL DEV_NULL_LC is_dev_null)); | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | # This constant is used throughout the module. | 
| 36 |  |  |  |  |  |  | my $INCORRECT_NUMBER_OF_ARGS = "passed incorrect number of arguments.\n"; | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | # These are declared now but defined and documented below. | 
| 39 | 2 |  |  |  |  | 5414 | use vars         qw(%directive_value_takes_abs_path | 
| 40 |  |  |  |  |  |  | %directive_value_takes_rel_path | 
| 41 | 2 |  |  | 2 |  | 9 | %directive_value_path_element_pos); | 
|  | 2 |  |  |  |  | 2 |  | 
| 42 |  |  |  |  |  |  | push(@EXPORT_OK, qw(%directive_value_takes_abs_path | 
| 43 |  |  |  |  |  |  | %directive_value_takes_rel_path | 
| 44 |  |  |  |  |  |  | %directive_value_path_element_pos)); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =head1 NAME | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | Apache::ConfigParser::Directive - An Apache directive or start context | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | use Apache::ConfigParser::Directive; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # Create a new empty directive. | 
| 55 |  |  |  |  |  |  | my $d = Apache::ConfigParser::Directive->new; | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | # Make it a ServerRoot directive. | 
| 58 |  |  |  |  |  |  | # ServerRoot /etc/httpd | 
| 59 |  |  |  |  |  |  | $d->name('ServerRoot'); | 
| 60 |  |  |  |  |  |  | $d->value('/etc/httpd'); | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | # A more complicated directive.  Value automatically splits the | 
| 63 |  |  |  |  |  |  | # argument into separate elements.  It treats elements in "'s as a | 
| 64 |  |  |  |  |  |  | # single element. | 
| 65 |  |  |  |  |  |  | # LogFormat "%h %l %u %t \"%r\" %>s %b" common | 
| 66 |  |  |  |  |  |  | $d->name('LogFormat'); | 
| 67 |  |  |  |  |  |  | $d->value('"%h %l %u %t \"%r\" %>s %b" common'); | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # Get a string form of the name. | 
| 70 |  |  |  |  |  |  | # Prints 'logformat'. | 
| 71 |  |  |  |  |  |  | print $d->name, "\n"; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | # Get a string form of the value. | 
| 74 |  |  |  |  |  |  | # Prints '"%h %l %u %t \"%r\" %>s %b" common'. | 
| 75 |  |  |  |  |  |  | print $d->value, "\n"; | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | # Get the values separated into individual elements.  Whitespace | 
| 78 |  |  |  |  |  |  | # separated elements that are enclosed in "'s are treated as a | 
| 79 |  |  |  |  |  |  | # single element.  Protected quotes, \", are honored to not begin or | 
| 80 |  |  |  |  |  |  | # end a value element.  In this form protected "'s, \", are no | 
| 81 |  |  |  |  |  |  | # longer protected. | 
| 82 |  |  |  |  |  |  | my @value = $d->get_value_array; | 
| 83 |  |  |  |  |  |  | scalar @value == 2;		# There are two elements in this array. | 
| 84 |  |  |  |  |  |  | $value[0] eq '%h %l %u %t \"%r\" %>s %b'; | 
| 85 |  |  |  |  |  |  | $value[1] eq 'common'; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | # The array form can also be set.  Change style of LogFormat from a | 
| 88 |  |  |  |  |  |  | # common to a referer style log. | 
| 89 |  |  |  |  |  |  | $d->set_value_array('%{Referer}i -> %U', 'referer'); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | # This is equivalent. | 
| 92 |  |  |  |  |  |  | $d->value('"%{Referer}i -> %U" referer'); | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | # There are also an equivalent pair of values that are called | 
| 95 |  |  |  |  |  |  | # 'original' that can be accessed via orig_value, | 
| 96 |  |  |  |  |  |  | # get_orig_value_array and set_orig_value_array. | 
| 97 |  |  |  |  |  |  | $d->orig_value('"%{User-agent}i" agent'); | 
| 98 |  |  |  |  |  |  | $d->set_orig_value_array('%{User-agent}i', 'agent'); | 
| 99 |  |  |  |  |  |  | @value = $d->get_orig_value_array; | 
| 100 |  |  |  |  |  |  | scalar @value == 2;		# There are two elements in this array. | 
| 101 |  |  |  |  |  |  | $value[0] eq '%{User-agent}i'; | 
| 102 |  |  |  |  |  |  | $value[1] eq 'agent'; | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | # You can set undef values for the strings. | 
| 105 |  |  |  |  |  |  | $d->value(undef); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | The C module is a subclass of | 
| 110 |  |  |  |  |  |  | C, which provides methods to represents nodes in a | 
| 111 |  |  |  |  |  |  | tree.  Each node is a single Apache configuration directive or root | 
| 112 |  |  |  |  |  |  | node for a context, such as  or .  All of the | 
| 113 |  |  |  |  |  |  | methods in that module are available here.  This module adds some | 
| 114 |  |  |  |  |  |  | additional methods that make it easier to represent Apache directives | 
| 115 |  |  |  |  |  |  | and contexts. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | This module holds a directive or context: | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | name | 
| 120 |  |  |  |  |  |  | value in string form | 
| 121 |  |  |  |  |  |  | value in array form | 
| 122 |  |  |  |  |  |  | a separate value termed 'original' in string form | 
| 123 |  |  |  |  |  |  | a separate value termed 'original' in array form | 
| 124 |  |  |  |  |  |  | the filename where the directive was set | 
| 125 |  |  |  |  |  |  | the line number in the filename where the directive was set | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | The 'original' value is separate from the non-'original' value and the | 
| 128 |  |  |  |  |  |  | methods to operate on the two sets of values have distinct names.  The | 
| 129 |  |  |  |  |  |  | 'original' value can be used to store the original value of a | 
| 130 |  |  |  |  |  |  | directive while the non-'directive' value can be a modified form, such | 
| 131 |  |  |  |  |  |  | as changing the CustomLog filename to make it absolute.  The actual | 
| 132 |  |  |  |  |  |  | use of these two distinct values is up to the caller as this module | 
| 133 |  |  |  |  |  |  | does not link the two in any way. | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =head1 METHODS | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | The following methods are available: | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =over | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =cut | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =item $d = Apache::ConfigParser::Directive->new; | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | This creates a brand new C object. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | It is not recommended to pass any arguments to C to set the | 
| 148 |  |  |  |  |  |  | internal state and instead use the following methods. | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | There actually is no C method in the | 
| 151 |  |  |  |  |  |  | C module.  Instead, due to | 
| 152 |  |  |  |  |  |  | C being a subclass of | 
| 153 |  |  |  |  |  |  | C, C will be used. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | =cut | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | # The Apache::ConfigParser::Directive object still needs to be | 
| 158 |  |  |  |  |  |  | # initialized.  This is done here.  Tree::DAG_Node->new calls | 
| 159 |  |  |  |  |  |  | # Apache::ConfigParser::Directive->_init, which will call | 
| 160 |  |  |  |  |  |  | # Tree::DAG_Node->_init. | 
| 161 |  |  |  |  |  |  | sub _init { | 
| 162 | 1243 |  |  | 1243 |  | 15381 | my $self                  = shift; | 
| 163 | 1243 |  |  |  |  | 3357 | $self->SUPER::_init; | 
| 164 | 1243 |  |  |  |  | 27752 | $self->{name}             = ''; | 
| 165 | 1243 |  |  |  |  | 1817 | $self->{value}            = ''; | 
| 166 | 1243 |  |  |  |  | 1932 | $self->{value_array}      = []; | 
| 167 | 1243 |  |  |  |  | 1647 | $self->{orig_value}       = ''; | 
| 168 | 1243 |  |  |  |  | 2920 | $self->{orig_value_array} = []; | 
| 169 | 1243 |  |  |  |  | 1650 | $self->{filename}         = ''; | 
| 170 | 1243 |  |  |  |  | 2563 | $self->{line_number}      = -1; | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =item $d->name | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | =item $d->name($name) | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | In the first form get the directive or context's name.  In the second | 
| 178 |  |  |  |  |  |  | form set the new name of the directive or context to the lowercase | 
| 179 |  |  |  |  |  |  | version of I<$name> and return the original name. | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =cut | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | sub name { | 
| 184 | 5198 | 50 |  | 5198 | 1 | 22768 | unless (@_ < 3) { | 
| 185 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::name ", | 
| 186 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  |  | 
| 189 | 5198 |  |  |  |  | 4937 | my $self = shift; | 
| 190 | 5198 | 100 |  |  |  | 7601 | if (@_) { | 
| 191 | 1275 |  |  |  |  | 1553 | my $old       = $self->{name}; | 
| 192 | 1275 |  |  |  |  | 2084 | $self->{name} = lc($_[0]); | 
| 193 | 1275 |  |  |  |  | 2440 | return $old; | 
| 194 |  |  |  |  |  |  | } else { | 
| 195 | 3923 |  |  |  |  | 11026 | return $self->{name}; | 
| 196 |  |  |  |  |  |  | } | 
| 197 |  |  |  |  |  |  | } | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =item $d->value | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =item $d->value($value) | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | In the first form get the directive's value in string form.  In the | 
| 204 |  |  |  |  |  |  | second form, return the previous directive value in string form and | 
| 205 |  |  |  |  |  |  | set the new directive value to I<$value>.  I<$value> can be set to | 
| 206 |  |  |  |  |  |  | undef. | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | If the value is being set, then I<$value> is saved so another call to | 
| 209 |  |  |  |  |  |  | C will return I<$value>.  If I<$value> is defined, then | 
| 210 |  |  |  |  |  |  | I<$value> is also parsed into an array of elements that can be | 
| 211 |  |  |  |  |  |  | retrieved with the C or C methods. | 
| 212 |  |  |  |  |  |  | The parser separates elements by whitespace, unless whitespace | 
| 213 |  |  |  |  |  |  | separated elements are enclosed by "'s.  Protected quotes, \", are | 
| 214 |  |  |  |  |  |  | honored to not begin or end a value element. | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | =item $d->orig_value | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | =item $d->orig_value($value) | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | Identical behavior as C, except that this applies to a the | 
| 221 |  |  |  |  |  |  | 'original' value.  Use C or C to | 
| 222 |  |  |  |  |  |  | get the value elements. | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | =cut | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | # This function manages getting and setting the string value for | 
| 227 |  |  |  |  |  |  | # either the 'value' or 'orig_value' hash keys. | 
| 228 |  |  |  |  |  |  | sub _get_set_value_string { | 
| 229 | 2670 | 50 | 33 | 2670 |  | 9045 | unless (@_ > 1 and @_ < 4) { | 
| 230 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::_get_set_value_string ", | 
| 231 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 232 |  |  |  |  |  |  | } | 
| 233 |  |  |  |  |  |  |  | 
| 234 | 2670 |  |  |  |  | 2764 | my $self            = shift; | 
| 235 | 2670 |  |  |  |  | 2526 | my $string_var_name = pop; | 
| 236 | 2670 |  |  |  |  | 3206 | my $old_value       = $self->{$string_var_name}; | 
| 237 | 2670 | 100 |  |  |  | 4681 | unless (@_) { | 
| 238 | 8 |  |  |  |  | 28 | return $old_value; | 
| 239 |  |  |  |  |  |  | } | 
| 240 |  |  |  |  |  |  |  | 
| 241 | 2662 |  |  |  |  | 2655 | my $value           = shift; | 
| 242 | 2662 |  |  |  |  | 3985 | my $array_var_name  = "${string_var_name}_array"; | 
| 243 |  |  |  |  |  |  |  | 
| 244 | 2662 | 100 |  |  |  | 3878 | if (defined $value) { | 
| 245 |  |  |  |  |  |  | # Keep the value as a string and also create an array of values. | 
| 246 |  |  |  |  |  |  | # Keep content inside " as a single value and also protect \". | 
| 247 | 2653 |  |  |  |  | 2249 | my @values; | 
| 248 | 2653 | 100 |  |  |  | 4321 | if (length $value) { | 
| 249 | 2652 |  |  |  |  | 2438 | my $v =  $value; | 
| 250 | 2652 |  |  |  |  | 3874 | $v    =~ s/\\"/\200/g; | 
| 251 | 2652 |  | 100 |  |  | 9549 | while (defined $v and length $v) { | 
| 252 | 4963 | 100 |  |  |  | 8140 | if ($v =~ s/^"//) { | 
| 253 | 213 |  |  |  |  | 366 | my $quote_index = index($v, '"'); | 
| 254 | 213 | 50 |  |  |  | 331 | if ($quote_index < 0) { | 
| 255 | 0 |  |  |  |  | 0 | $v =~ s/\200/"/g; | 
| 256 | 0 |  |  |  |  | 0 | push(@values, $v); | 
| 257 | 0 |  |  |  |  | 0 | last; | 
| 258 |  |  |  |  |  |  | } else { | 
| 259 | 213 |  |  |  |  | 445 | my $v1 =  substr($v, 0, $quote_index, ''); | 
| 260 | 213 |  |  |  |  | 510 | $v     =~ s/^"\s*//; | 
| 261 | 213 |  |  |  |  | 324 | $v1    =~ s/\200/"/g; | 
| 262 | 213 |  |  |  |  | 1151 | push(@values, $v1); | 
| 263 |  |  |  |  |  |  | } | 
| 264 |  |  |  |  |  |  | } else { | 
| 265 | 4750 |  |  |  |  | 19249 | my ($v1, $v2) = $v =~ /^(\S+)(?:\s+(.*))?$/; | 
| 266 | 4750 |  |  |  |  | 5864 | $v            = $v2; | 
| 267 | 4750 |  |  |  |  | 4921 | $v1           =~ s/\200/"/g; | 
| 268 | 4750 |  |  |  |  | 16567 | push(@values, $v1); | 
| 269 |  |  |  |  |  |  | } | 
| 270 |  |  |  |  |  |  | } | 
| 271 |  |  |  |  |  |  | } | 
| 272 | 2653 |  |  |  |  | 3856 | $self->{$string_var_name} = $value; | 
| 273 | 2653 |  |  |  |  | 5163 | $self->{$array_var_name}  = \@values; | 
| 274 |  |  |  |  |  |  | } else { | 
| 275 | 9 |  |  |  |  | 15 | $self->{$string_var_name} = undef; | 
| 276 | 9 |  |  |  |  | 11 | $self->{$array_var_name}  = undef; | 
| 277 |  |  |  |  |  |  | } | 
| 278 |  |  |  |  |  |  |  | 
| 279 | 2662 |  |  |  |  | 7019 | $old_value; | 
| 280 |  |  |  |  |  |  | } | 
| 281 |  |  |  |  |  |  |  | 
| 282 |  |  |  |  |  |  | sub value { | 
| 283 | 1337 | 50 | 33 | 1337 | 1 | 6341 | unless (@_ and @_ < 3) { | 
| 284 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::value ", | 
| 285 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 286 |  |  |  |  |  |  | } | 
| 287 |  |  |  |  |  |  |  | 
| 288 | 1337 |  |  |  |  | 2381 | return _get_set_value_string(@_, 'value'); | 
| 289 |  |  |  |  |  |  | } | 
| 290 |  |  |  |  |  |  |  | 
| 291 |  |  |  |  |  |  | sub orig_value { | 
| 292 | 1333 | 50 | 33 | 1333 | 1 | 5837 | unless (@_ and @_ < 3) { | 
| 293 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::orig_value ", | 
| 294 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 295 |  |  |  |  |  |  | } | 
| 296 |  |  |  |  |  |  |  | 
| 297 | 1333 |  |  |  |  | 2190 | return _get_set_value_string(@_, 'orig_value'); | 
| 298 |  |  |  |  |  |  | } | 
| 299 |  |  |  |  |  |  |  | 
| 300 |  |  |  |  |  |  | =item $d->value_array_ref | 
| 301 |  |  |  |  |  |  |  | 
| 302 |  |  |  |  |  |  | =item $d->value_array_ref(\@array) | 
| 303 |  |  |  |  |  |  |  | 
| 304 |  |  |  |  |  |  | In the first form get a reference to the value array.  This can return | 
| 305 |  |  |  |  |  |  | an undefined value if an undefined value was passed to C or an | 
| 306 |  |  |  |  |  |  | undefined reference was passed to C.  In the second | 
| 307 |  |  |  |  |  |  | form C sets the value array and value string.  Both | 
| 308 |  |  |  |  |  |  | forms of C return the original array reference. | 
| 309 |  |  |  |  |  |  |  | 
| 310 |  |  |  |  |  |  | If you modify the value array reference after getting it and do not | 
| 311 |  |  |  |  |  |  | use C C to set the value, then the | 
| 312 |  |  |  |  |  |  | string returned from C will not be consistent with the array. | 
| 313 |  |  |  |  |  |  |  | 
| 314 |  |  |  |  |  |  | =item $d->orig_value_array_ref | 
| 315 |  |  |  |  |  |  |  | 
| 316 |  |  |  |  |  |  | =item $d->orig_value_array_ref(\@array) | 
| 317 |  |  |  |  |  |  |  | 
| 318 |  |  |  |  |  |  | Identical behavior as C, except that this applies to | 
| 319 |  |  |  |  |  |  | the 'original' value. | 
| 320 |  |  |  |  |  |  |  | 
| 321 |  |  |  |  |  |  | =cut | 
| 322 |  |  |  |  |  |  |  | 
| 323 |  |  |  |  |  |  | # This is a utility function that takes the hash key name to place the | 
| 324 |  |  |  |  |  |  | # value elements into, saves the array and creates a value string | 
| 325 |  |  |  |  |  |  | # suitable for placing into an Apache configuration file. | 
| 326 |  |  |  |  |  |  | sub _set_value_array { | 
| 327 | 1428 | 50 |  | 1428 |  | 3001 | unless (@_ > 1) { | 
| 328 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::_set_value_array ", | 
| 329 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 330 |  |  |  |  |  |  | } | 
| 331 |  |  |  |  |  |  |  | 
| 332 | 1428 |  |  |  |  | 1542 | my $self            = shift; | 
| 333 | 1428 |  |  |  |  | 1483 | my $string_var_name = pop; | 
| 334 | 1428 |  |  |  |  | 1947 | my $array_var_name  = "${string_var_name}_array"; | 
| 335 | 1428 |  |  |  |  | 2623 | my @values          = @_; | 
| 336 |  |  |  |  |  |  |  | 
| 337 | 1428 |  |  |  |  | 1603 | my $value = ''; | 
| 338 | 1428 |  |  |  |  | 1805 | foreach my $s (@values) { | 
| 339 | 2774 | 50 |  |  |  | 4564 | next unless length $s; | 
| 340 |  |  |  |  |  |  |  | 
| 341 | 2774 | 100 |  |  |  | 4105 | $value .= ' ' if length $value; | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  | # Make a copy of the string so that the regex doesn't modify the | 
| 344 |  |  |  |  |  |  | # contents of @values. | 
| 345 | 2774 |  |  |  |  | 2633 | my $substring  =  $s; | 
| 346 | 2774 |  |  |  |  | 4354 | $substring     =~ s/(["\\])/\\$1/g; | 
| 347 | 2774 | 100 |  |  |  | 4926 | if ($substring =~ /\s/) { | 
| 348 | 208 |  |  |  |  | 568 | $value .= "\"$substring\""; | 
| 349 |  |  |  |  |  |  | } else { | 
| 350 | 2566 |  |  |  |  | 4827 | $value .= $substring; | 
| 351 |  |  |  |  |  |  | } | 
| 352 |  |  |  |  |  |  | } | 
| 353 |  |  |  |  |  |  |  | 
| 354 | 1428 |  |  |  |  | 2481 | my $old_array_ref = $self->{$array_var_name}; | 
| 355 |  |  |  |  |  |  |  | 
| 356 | 1428 |  |  |  |  | 2102 | $self->{$string_var_name} = $value; | 
| 357 | 1428 |  |  |  |  | 1991 | $self->{$array_var_name}  = \@values; | 
| 358 |  |  |  |  |  |  |  | 
| 359 | 1428 | 100 |  |  |  | 5146 | $old_array_ref ? @$old_array_ref : (); | 
| 360 |  |  |  |  |  |  | } | 
| 361 |  |  |  |  |  |  |  | 
| 362 |  |  |  |  |  |  | sub value_array_ref { | 
| 363 | 6 | 50 | 33 | 6 | 1 | 1299 | unless (@_ and @_ < 3) { | 
| 364 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::value_array_ref ", | 
| 365 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 366 |  |  |  |  |  |  | } | 
| 367 |  |  |  |  |  |  |  | 
| 368 | 6 |  |  |  |  | 8 | my $self = shift; | 
| 369 |  |  |  |  |  |  |  | 
| 370 | 6 |  |  |  |  | 7 | my $old = $self->{value_array}; | 
| 371 |  |  |  |  |  |  |  | 
| 372 | 6 | 100 |  |  |  | 10 | if (@_) { | 
| 373 | 1 |  |  |  |  | 2 | my $ref = shift; | 
| 374 | 1 | 50 |  |  |  | 3 | if (defined $ref) { | 
| 375 | 0 |  |  |  |  | 0 | $self->_set_value_array(@$ref, 'value'); | 
| 376 |  |  |  |  |  |  | } else { | 
| 377 | 1 |  |  |  |  | 2 | $self->{value}       = undef; | 
| 378 | 1 |  |  |  |  | 2 | $self->{value_array} = undef; | 
| 379 |  |  |  |  |  |  | } | 
| 380 |  |  |  |  |  |  | } | 
| 381 |  |  |  |  |  |  |  | 
| 382 | 6 |  |  |  |  | 28 | $old; | 
| 383 |  |  |  |  |  |  | } | 
| 384 |  |  |  |  |  |  |  | 
| 385 |  |  |  |  |  |  | sub orig_value_array_ref { | 
| 386 | 3 | 50 | 33 | 3 | 1 | 1157 | unless (@_ and @_ < 3) { | 
| 387 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::orig_value_array_ref ", | 
| 388 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 389 |  |  |  |  |  |  | } | 
| 390 |  |  |  |  |  |  |  | 
| 391 | 3 |  |  |  |  | 5 | my $self = shift; | 
| 392 |  |  |  |  |  |  |  | 
| 393 | 3 |  |  |  |  | 5 | my $old = $self->{orig_value_array}; | 
| 394 |  |  |  |  |  |  |  | 
| 395 | 3 | 50 |  |  |  | 6 | if (@_) { | 
| 396 | 0 |  |  |  |  | 0 | my $ref = shift; | 
| 397 | 0 | 0 |  |  |  | 0 | if (defined $ref) { | 
| 398 | 0 |  |  |  |  | 0 | $self->_set_value_array(@$ref, 'orig_value'); | 
| 399 |  |  |  |  |  |  | } else { | 
| 400 | 0 |  |  |  |  | 0 | $self->{value}       = undef; | 
| 401 | 0 |  |  |  |  | 0 | $self->{value_array} = undef; | 
| 402 |  |  |  |  |  |  | } | 
| 403 |  |  |  |  |  |  | } | 
| 404 |  |  |  |  |  |  |  | 
| 405 | 3 |  |  |  |  | 12 | $old; | 
| 406 |  |  |  |  |  |  | } | 
| 407 |  |  |  |  |  |  |  | 
| 408 |  |  |  |  |  |  | =item $d->get_value_array | 
| 409 |  |  |  |  |  |  |  | 
| 410 |  |  |  |  |  |  | Get the value array elements.  If the value was set to an undefined | 
| 411 |  |  |  |  |  |  | value using C, then C will return an empty | 
| 412 |  |  |  |  |  |  | list in a list context, an undefined value in a scalar context, or | 
| 413 |  |  |  |  |  |  | nothing in a void context. | 
| 414 |  |  |  |  |  |  |  | 
| 415 |  |  |  |  |  |  | =item $d->get_orig_value_array | 
| 416 |  |  |  |  |  |  |  | 
| 417 |  |  |  |  |  |  | This has the same behavior of C except that it | 
| 418 |  |  |  |  |  |  | operates on the 'original' value. | 
| 419 |  |  |  |  |  |  |  | 
| 420 |  |  |  |  |  |  | =cut | 
| 421 |  |  |  |  |  |  |  | 
| 422 |  |  |  |  |  |  | sub get_value_array { | 
| 423 | 1054 | 50 |  | 1054 | 1 | 2104 | unless (@_ == 1) { | 
| 424 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::get_value_array ", | 
| 425 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 426 |  |  |  |  |  |  | } | 
| 427 |  |  |  |  |  |  |  | 
| 428 | 1054 |  |  |  |  | 1425 | my $ref = shift->{value_array}; | 
| 429 |  |  |  |  |  |  |  | 
| 430 | 1054 | 100 |  |  |  | 1950 | if ($ref) { | 
| 431 | 1052 |  |  |  |  | 3973 | return @$ref; | 
| 432 |  |  |  |  |  |  | } else { | 
| 433 | 2 |  |  |  |  | 8 | return; | 
| 434 |  |  |  |  |  |  | } | 
| 435 |  |  |  |  |  |  | } | 
| 436 |  |  |  |  |  |  |  | 
| 437 |  |  |  |  |  |  | sub get_orig_value_array { | 
| 438 | 4 | 50 |  | 4 | 1 | 334 | unless (@_ == 1) { | 
| 439 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::get_orig_value_array ", | 
| 440 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 441 |  |  |  |  |  |  | } | 
| 442 |  |  |  |  |  |  |  | 
| 443 | 4 |  |  |  |  | 7 | my $ref = shift->{orig_value_array}; | 
| 444 |  |  |  |  |  |  |  | 
| 445 | 4 | 50 |  |  |  | 5 | if ($ref) { | 
| 446 | 4 |  |  |  |  | 12 | return @$ref; | 
| 447 |  |  |  |  |  |  | } else { | 
| 448 | 0 |  |  |  |  | 0 | return; | 
| 449 |  |  |  |  |  |  | } | 
| 450 |  |  |  |  |  |  | } | 
| 451 |  |  |  |  |  |  |  | 
| 452 |  |  |  |  |  |  | =item $d->set_value_array(@values) | 
| 453 |  |  |  |  |  |  |  | 
| 454 |  |  |  |  |  |  | Set the value array elements.  If no elements are passed in, then the | 
| 455 |  |  |  |  |  |  | value will be defined but empty and a following call to | 
| 456 |  |  |  |  |  |  | C will return an empty array.  This returns the value | 
| 457 |  |  |  |  |  |  | of the array before this method was called. | 
| 458 |  |  |  |  |  |  |  | 
| 459 |  |  |  |  |  |  | After setting the value elements with this method, the string returned | 
| 460 |  |  |  |  |  |  | from calling C is a concatenation of each of the elements so | 
| 461 |  |  |  |  |  |  | that the output could be used for an Apache configuration file.  If | 
| 462 |  |  |  |  |  |  | any elements contain whitespace, then the "'s are placed around the | 
| 463 |  |  |  |  |  |  | element as the element is being concatenated into the value string and | 
| 464 |  |  |  |  |  |  | if any elements contain a " or a \, then a copy of the element is made | 
| 465 |  |  |  |  |  |  | and the character is protected, i.e. \" or \\, and then copied into | 
| 466 |  |  |  |  |  |  | the value string. | 
| 467 |  |  |  |  |  |  |  | 
| 468 |  |  |  |  |  |  | =item $d->set_orig_value_array(@values) | 
| 469 |  |  |  |  |  |  |  | 
| 470 |  |  |  |  |  |  | This has the same behavior as C except that it | 
| 471 |  |  |  |  |  |  | operates on the 'original' value. | 
| 472 |  |  |  |  |  |  |  | 
| 473 |  |  |  |  |  |  | =cut | 
| 474 |  |  |  |  |  |  |  | 
| 475 |  |  |  |  |  |  | sub set_value_array { | 
| 476 | 1362 |  |  | 1362 | 1 | 2385 | return _set_value_array(@_, 'value'); | 
| 477 |  |  |  |  |  |  | } | 
| 478 |  |  |  |  |  |  |  | 
| 479 |  |  |  |  |  |  | sub set_orig_value_array { | 
| 480 | 66 |  |  | 66 | 1 | 16206 | return _set_value_array(@_, 'orig_value'); | 
| 481 |  |  |  |  |  |  | } | 
| 482 |  |  |  |  |  |  |  | 
| 483 |  |  |  |  |  |  | =item Note on $d->value_is_path, $d->value_is_abs_path, | 
| 484 |  |  |  |  |  |  | $d->value_is_rel_path, $d->orig_value_is_path, | 
| 485 |  |  |  |  |  |  | $d->orig_value_is_abs_path and $d->orig_value_is_rel_path | 
| 486 |  |  |  |  |  |  |  | 
| 487 |  |  |  |  |  |  | These six methods are very similar.  They all check if the directive | 
| 488 |  |  |  |  |  |  | can take a file or directory path value argument in the appropriate | 
| 489 |  |  |  |  |  |  | index in the value array and then check the value.  For example, the | 
| 490 |  |  |  |  |  |  | C directive, i.e. | 
| 491 |  |  |  |  |  |  |  | 
| 492 |  |  |  |  |  |  | =over 4 | 
| 493 |  |  |  |  |  |  |  | 
| 494 |  |  |  |  |  |  | LoadModule cgi_module libexec/mod_cgi.so | 
| 495 |  |  |  |  |  |  |  | 
| 496 |  |  |  |  |  |  | =back | 
| 497 |  |  |  |  |  |  |  | 
| 498 |  |  |  |  |  |  | does not take a path element in its first (index 0) value array | 
| 499 |  |  |  |  |  |  | element. | 
| 500 |  |  |  |  |  |  |  | 
| 501 |  |  |  |  |  |  | If there is no argument supplied to the method call, then the | 
| 502 |  |  |  |  |  |  | directive checks the first element of the value array that can legally | 
| 503 |  |  |  |  |  |  | contain path.  For C, it would check element 1.  You could | 
| 504 |  |  |  |  |  |  | pass 0 to the method to check the first indexed value of | 
| 505 |  |  |  |  |  |  | C, but it would always return false, because index 0 does | 
| 506 |  |  |  |  |  |  | not contain a path. | 
| 507 |  |  |  |  |  |  |  | 
| 508 |  |  |  |  |  |  | These are the differences between the methods: | 
| 509 |  |  |  |  |  |  |  | 
| 510 |  |  |  |  |  |  | =over 4 | 
| 511 |  |  |  |  |  |  |  | 
| 512 |  |  |  |  |  |  | 1) The methods beginning with the string 'value_is' apply to the | 
| 513 |  |  |  |  |  |  | current value in the directive while the methods beginning with the | 
| 514 |  |  |  |  |  |  | string 'orig_value_is' apply to the original value of the directive. | 
| 515 |  |  |  |  |  |  |  | 
| 516 |  |  |  |  |  |  | 2) The methods '*value_is_path' test if the directive value is a path, | 
| 517 |  |  |  |  |  |  | either absolute or relative.  The methods '*value_is_abs_path' test if | 
| 518 |  |  |  |  |  |  | the path if an absolute path, and the methods '*value_is_rel_path' | 
| 519 |  |  |  |  |  |  | test if the path is not an absolute path. | 
| 520 |  |  |  |  |  |  |  | 
| 521 |  |  |  |  |  |  | =back | 
| 522 |  |  |  |  |  |  |  | 
| 523 |  |  |  |  |  |  | =item $d->value_is_path | 
| 524 |  |  |  |  |  |  |  | 
| 525 |  |  |  |  |  |  | =item $d->value_is_path($index_into_value_array) | 
| 526 |  |  |  |  |  |  |  | 
| 527 |  |  |  |  |  |  | Returns true if C<$d>'s directive can take a file or directory path in | 
| 528 |  |  |  |  |  |  | the specified value array element (indexed by $index_into_value_array | 
| 529 |  |  |  |  |  |  | or the first path element for the particular directive if | 
| 530 |  |  |  |  |  |  | $index_into_value_array is not provided) and if the value is either an | 
| 531 |  |  |  |  |  |  | absolute or relative file or directory path.  Both the directive name | 
| 532 |  |  |  |  |  |  | and the value is checked, because some directives such as ErrorLog, | 
| 533 |  |  |  |  |  |  | can take values that are not paths (i.e. a piped command or | 
| 534 |  |  |  |  |  |  | syslog:facility).  The /dev/null equivalent for the operating system | 
| 535 |  |  |  |  |  |  | is not treated as a path, since on some operating systems the | 
| 536 |  |  |  |  |  |  | /dev/null equivalent is not a file, such as nul on Windows. | 
| 537 |  |  |  |  |  |  |  | 
| 538 |  |  |  |  |  |  | The method actually does not check if its value is a path, rather it | 
| 539 |  |  |  |  |  |  | checks if the value does not match all of the other possible non-path | 
| 540 |  |  |  |  |  |  | values for the specific directive because different operating systems | 
| 541 |  |  |  |  |  |  | have different path formats, such as Unix, Windows and Macintosh. | 
| 542 |  |  |  |  |  |  |  | 
| 543 |  |  |  |  |  |  | =cut | 
| 544 |  |  |  |  |  |  |  | 
| 545 |  |  |  |  |  |  | # Define these constant subroutines as the different types of paths to | 
| 546 |  |  |  |  |  |  | # check for in _value_is_path_or_abs_path_or_rel_path. | 
| 547 |  |  |  |  |  |  | sub CHECK_TYPE_ABS        () { 'abs' } | 
| 548 |  |  |  |  |  |  | sub CHECK_TYPE_REL        () { 'rel' } | 
| 549 |  |  |  |  |  |  | sub CHECK_TYPE_ABS_OR_REL () { 'abs_or_rel' } | 
| 550 |  |  |  |  |  |  |  | 
| 551 |  |  |  |  |  |  | # This is a function that does the work for value_is_path, | 
| 552 |  |  |  |  |  |  | # orig_value_is_path, value_is_abs_path, orig_value_is_abs_path, | 
| 553 |  |  |  |  |  |  | # value_is_rel_path and orig_value_is_rel_path. | 
| 554 |  |  |  |  |  |  | sub _value_is_path_or_abs_path_or_rel_path { | 
| 555 | 1374 | 50 |  | 1374 |  | 2587 | unless (@_ == 4) { | 
| 556 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::", | 
| 557 |  |  |  |  |  |  | "_value_is_path_or_abs_path_or_rel_path ", | 
| 558 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 559 |  |  |  |  |  |  | } | 
| 560 |  |  |  |  |  |  |  | 
| 561 | 1374 |  |  |  |  | 2589 | my ($self, | 
| 562 |  |  |  |  |  |  | $check_type, | 
| 563 |  |  |  |  |  |  | $array_var_name, | 
| 564 |  |  |  |  |  |  | $value_path_index) = @_; | 
| 565 |  |  |  |  |  |  |  | 
| 566 | 1374 | 50 | 100 |  |  | 6054 | unless ($check_type eq CHECK_TYPE_ABS or | 
|  |  |  | 66 |  |  |  |  | 
| 567 |  |  |  |  |  |  | $check_type eq CHECK_TYPE_REL or | 
| 568 |  |  |  |  |  |  | $check_type eq CHECK_TYPE_ABS_OR_REL) { | 
| 569 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::", | 
| 570 |  |  |  |  |  |  | "_value_is_path_or_abs_path_or_rel_path ", | 
| 571 |  |  |  |  |  |  | "passed invalid check_type value '$check_type'.\n"; | 
| 572 |  |  |  |  |  |  | } | 
| 573 |  |  |  |  |  |  |  | 
| 574 | 1374 | 50 | 66 |  |  | 3561 | if (defined $value_path_index and $value_path_index !~ /^\d+$/) { | 
| 575 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::", | 
| 576 |  |  |  |  |  |  | "_value_is_path_or_abs_path_or_rel_path ", | 
| 577 |  |  |  |  |  |  | "passed invalid value_path_index value '$value_path_index'.\n"; | 
| 578 |  |  |  |  |  |  | } | 
| 579 |  |  |  |  |  |  |  | 
| 580 | 1374 |  |  |  |  | 1840 | my $array_ref = $self->{$array_var_name}; | 
| 581 |  |  |  |  |  |  |  | 
| 582 | 1374 | 50 |  |  |  | 2139 | unless ($array_ref) { | 
| 583 | 0 |  |  |  |  | 0 | return 0; | 
| 584 |  |  |  |  |  |  | } | 
| 585 |  |  |  |  |  |  |  | 
| 586 | 1374 |  |  |  |  | 2522 | my $directive_name = $self->name; | 
| 587 |  |  |  |  |  |  |  | 
| 588 | 1374 | 50 | 33 |  |  | 5183 | unless (defined $directive_name and length $directive_name) { | 
| 589 | 0 |  |  |  |  | 0 | return 0; | 
| 590 |  |  |  |  |  |  | } | 
| 591 |  |  |  |  |  |  |  | 
| 592 |  |  |  |  |  |  | # Check if there is an index into the value array that can take a | 
| 593 |  |  |  |  |  |  | # path. | 
| 594 | 1374 |  |  |  |  | 1950 | my $first_value_path_index = | 
| 595 |  |  |  |  |  |  | $directive_value_path_element_pos{$directive_name}; | 
| 596 | 1374 | 100 | 66 |  |  | 4370 | unless (defined $first_value_path_index and length $first_value_path_index) { | 
| 597 | 27 |  |  |  |  | 170 | return 0; | 
| 598 |  |  |  |  |  |  | } | 
| 599 |  |  |  |  |  |  |  | 
| 600 |  |  |  |  |  |  | # If the index into the value array was specified, then check if the | 
| 601 |  |  |  |  |  |  | # value in the index can take a path.  If the index was not | 
| 602 |  |  |  |  |  |  | # specified, then use the first value index that can contain a path. | 
| 603 | 1347 | 100 |  |  |  | 1971 | if (defined $value_path_index) { | 
| 604 | 265 | 100 |  |  |  | 504 | if (substr($first_value_path_index, 0, 1) eq '-') { | 
| 605 | 3 | 50 |  |  |  | 12 | return 0 if $value_path_index <  abs($first_value_path_index); | 
| 606 |  |  |  |  |  |  | } else { | 
| 607 | 262 | 50 |  |  |  | 727 | return 0 if $value_path_index != $first_value_path_index; | 
| 608 |  |  |  |  |  |  | } | 
| 609 |  |  |  |  |  |  | } else { | 
| 610 | 1082 |  |  |  |  | 1735 | $value_path_index = abs($first_value_path_index); | 
| 611 |  |  |  |  |  |  | } | 
| 612 | 1347 |  |  |  |  | 1589 | my $path = $array_ref->[$value_path_index]; | 
| 613 |  |  |  |  |  |  |  | 
| 614 | 1347 | 50 | 33 |  |  | 4199 | unless (defined $path and length $path) { | 
| 615 | 0 |  |  |  |  | 0 | return 0; | 
| 616 |  |  |  |  |  |  | } | 
| 617 |  |  |  |  |  |  |  | 
| 618 | 1347 | 100 |  |  |  | 2120 | if (is_dev_null($path)) { | 
| 619 | 93 |  |  |  |  | 513 | return 0; | 
| 620 |  |  |  |  |  |  | } | 
| 621 |  |  |  |  |  |  |  | 
| 622 |  |  |  |  |  |  | # Get the subroutine that will check if the directive value is a | 
| 623 |  |  |  |  |  |  | # path.  If there is no subroutine for the directive, then it | 
| 624 |  |  |  |  |  |  | # doesn't take a path. | 
| 625 | 1254 |  |  |  |  | 1432 | my $sub_ref; | 
| 626 | 1254 | 100 |  |  |  | 2686 | if ($check_type eq CHECK_TYPE_ABS) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 627 | 248 |  |  |  |  | 351 | $sub_ref = $directive_value_takes_abs_path{$directive_name}; | 
| 628 |  |  |  |  |  |  | } elsif ($check_type eq CHECK_TYPE_REL) { | 
| 629 | 478 |  |  |  |  | 709 | $sub_ref = $directive_value_takes_rel_path{$directive_name}; | 
| 630 |  |  |  |  |  |  | } elsif ($check_type eq CHECK_TYPE_ABS_OR_REL) { | 
| 631 | 528 |  |  |  |  | 742 | $sub_ref = $directive_value_takes_abs_path{$directive_name}; | 
| 632 | 528 | 50 |  |  |  | 886 | unless (defined $sub_ref) { | 
| 633 | 0 |  |  |  |  | 0 | $sub_ref = $directive_value_takes_rel_path{$directive_name}; | 
| 634 |  |  |  |  |  |  | } | 
| 635 |  |  |  |  |  |  | } else { | 
| 636 | 0 |  |  |  |  | 0 | confess "$0: internal error: check_type case '$check_type' not handled.\n"; | 
| 637 |  |  |  |  |  |  | } | 
| 638 |  |  |  |  |  |  |  | 
| 639 | 1254 | 100 |  |  |  | 1994 | unless ($sub_ref) { | 
| 640 | 117 |  |  |  |  | 765 | return 0; | 
| 641 |  |  |  |  |  |  | } | 
| 642 |  |  |  |  |  |  |  | 
| 643 | 1137 |  |  |  |  | 1835 | my $result = &$sub_ref($path); | 
| 644 | 1137 | 100 |  |  |  | 1653 | if ($result) { | 
| 645 | 1098 | 100 |  |  |  | 3902 | return 1 if $check_type eq CHECK_TYPE_ABS_OR_REL; | 
| 646 |  |  |  |  |  |  |  | 
| 647 | 587 | 100 |  |  |  | 1060 | if ($check_type eq CHECK_TYPE_ABS) { | 
|  |  | 50 |  |  |  |  |  | 
| 648 | 236 | 100 |  |  |  | 2700 | return File::Spec->file_name_is_absolute($path) ? 1 : 0; | 
| 649 |  |  |  |  |  |  | } elsif ($check_type eq CHECK_TYPE_REL) { | 
| 650 | 351 | 100 |  |  |  | 3678 | return File::Spec->file_name_is_absolute($path) ? 0 : 1; | 
| 651 |  |  |  |  |  |  | } else { | 
| 652 | 0 |  |  |  |  | 0 | confess "$0: internal error: check_type case ", | 
| 653 |  |  |  |  |  |  | "'$check_type' not handled.\n"; | 
| 654 |  |  |  |  |  |  | } | 
| 655 |  |  |  |  |  |  | } else { | 
| 656 | 39 |  |  |  |  | 264 | return 0; | 
| 657 |  |  |  |  |  |  | } | 
| 658 |  |  |  |  |  |  | } | 
| 659 |  |  |  |  |  |  |  | 
| 660 |  |  |  |  |  |  | sub value_is_path { | 
| 661 | 440 | 50 |  | 440 | 1 | 14252 | unless (@_ < 3) { | 
| 662 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::value_is_path ", | 
| 663 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 664 |  |  |  |  |  |  | } | 
| 665 |  |  |  |  |  |  |  | 
| 666 | 440 |  |  |  |  | 1384 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 667 |  |  |  |  |  |  | CHECK_TYPE_ABS_OR_REL, | 
| 668 |  |  |  |  |  |  | 'value_array', | 
| 669 |  |  |  |  |  |  | $_[1]); | 
| 670 |  |  |  |  |  |  | } | 
| 671 |  |  |  |  |  |  |  | 
| 672 |  |  |  |  |  |  | =item $d->orig_value_is_path | 
| 673 |  |  |  |  |  |  |  | 
| 674 |  |  |  |  |  |  | =item $d->orig_value_is_path($index_into_value_array) | 
| 675 |  |  |  |  |  |  |  | 
| 676 |  |  |  |  |  |  | This has the same behavior as C<< $d->value_is_path >> except the results | 
| 677 |  |  |  |  |  |  | are applicable to C<$d>'s 'original' value array. | 
| 678 |  |  |  |  |  |  |  | 
| 679 |  |  |  |  |  |  | =cut | 
| 680 |  |  |  |  |  |  |  | 
| 681 |  |  |  |  |  |  | sub orig_value_is_path { | 
| 682 | 128 | 50 |  | 128 | 1 | 432 | unless (@_ < 3) { | 
| 683 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::orig_value_is_path ", | 
| 684 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 685 |  |  |  |  |  |  | } | 
| 686 |  |  |  |  |  |  |  | 
| 687 | 128 |  |  |  |  | 531 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 688 |  |  |  |  |  |  | CHECK_TYPE_ABS_OR_REL, | 
| 689 |  |  |  |  |  |  | 'orig_value_array', | 
| 690 |  |  |  |  |  |  | $_[1]); | 
| 691 |  |  |  |  |  |  | } | 
| 692 |  |  |  |  |  |  |  | 
| 693 |  |  |  |  |  |  | =item $d->value_is_abs_path | 
| 694 |  |  |  |  |  |  |  | 
| 695 |  |  |  |  |  |  | =item $d->value_is_abs_path($index_into_value_array) | 
| 696 |  |  |  |  |  |  |  | 
| 697 |  |  |  |  |  |  | Returns true if C<$d>'s directive can take a file or directory path in | 
| 698 |  |  |  |  |  |  | the specified value array element (indexed by $index_into_value_array | 
| 699 |  |  |  |  |  |  | or the first path element for the particular directive if | 
| 700 |  |  |  |  |  |  | $index_into_value_array is not provided) and if the value is an | 
| 701 |  |  |  |  |  |  | absolute file or directory path.  Both the directive name and the | 
| 702 |  |  |  |  |  |  | value is checked, because some directives such as ErrorLog, can take | 
| 703 |  |  |  |  |  |  | values that are not paths (i.e. a piped command or syslog:facility). | 
| 704 |  |  |  |  |  |  | The /dev/null equivalent for the operating system is not treated as a | 
| 705 |  |  |  |  |  |  | path, since on some operating systems the /dev/null equivalent is not | 
| 706 |  |  |  |  |  |  | a file, such as nul on Windows. | 
| 707 |  |  |  |  |  |  |  | 
| 708 |  |  |  |  |  |  | The method actually does not check if its value is a path, rather it | 
| 709 |  |  |  |  |  |  | checks if the value does not match all of the other possible non-path | 
| 710 |  |  |  |  |  |  | values for the specific directive because different operating systems | 
| 711 |  |  |  |  |  |  | have different path formats, such as Unix, Windows and Macintosh. | 
| 712 |  |  |  |  |  |  |  | 
| 713 |  |  |  |  |  |  | =cut | 
| 714 |  |  |  |  |  |  |  | 
| 715 |  |  |  |  |  |  | sub value_is_abs_path { | 
| 716 | 160 | 50 |  | 160 | 1 | 524 | unless (@_ < 3) { | 
| 717 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::value_is_abs_path ", | 
| 718 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 719 |  |  |  |  |  |  | } | 
| 720 |  |  |  |  |  |  |  | 
| 721 | 160 |  |  |  |  | 525 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 722 |  |  |  |  |  |  | CHECK_TYPE_ABS, | 
| 723 |  |  |  |  |  |  | 'value_array', | 
| 724 |  |  |  |  |  |  | $_[1]); | 
| 725 |  |  |  |  |  |  | } | 
| 726 |  |  |  |  |  |  |  | 
| 727 |  |  |  |  |  |  | =item $d->orig_value_is_abs_path | 
| 728 |  |  |  |  |  |  |  | 
| 729 |  |  |  |  |  |  | =item $d->orig_value_is_abs_path($index_into_value_array) | 
| 730 |  |  |  |  |  |  |  | 
| 731 |  |  |  |  |  |  | This has the same behavior as C<< $d->value_is_abs_path >> except the | 
| 732 |  |  |  |  |  |  | results are applicable to C<$d>'s 'original' value array. | 
| 733 |  |  |  |  |  |  |  | 
| 734 |  |  |  |  |  |  | =cut | 
| 735 |  |  |  |  |  |  |  | 
| 736 |  |  |  |  |  |  | sub orig_value_is_abs_path { | 
| 737 | 128 | 50 |  | 128 | 1 | 466 | unless (@_ < 3) { | 
| 738 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::orig_value_is_abs_path ", | 
| 739 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 740 |  |  |  |  |  |  | } | 
| 741 |  |  |  |  |  |  |  | 
| 742 | 128 |  |  |  |  | 465 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 743 |  |  |  |  |  |  | CHECK_TYPE_ABS, | 
| 744 |  |  |  |  |  |  | 'orig_value_array', | 
| 745 |  |  |  |  |  |  | $_[1]); | 
| 746 |  |  |  |  |  |  | } | 
| 747 |  |  |  |  |  |  |  | 
| 748 |  |  |  |  |  |  | =item $d->value_is_rel_path | 
| 749 |  |  |  |  |  |  |  | 
| 750 |  |  |  |  |  |  | =item $d->value_is_rel_path($index_into_value_array) | 
| 751 |  |  |  |  |  |  |  | 
| 752 |  |  |  |  |  |  | Returns true if C<$d>'s directive can take a file or directory path in | 
| 753 |  |  |  |  |  |  | the specified value array element (indexed by $index_into_value_array | 
| 754 |  |  |  |  |  |  | or the first path element for the particular directive if | 
| 755 |  |  |  |  |  |  | $index_into_value_array is not provided) and if the value is a | 
| 756 |  |  |  |  |  |  | relative file or directory path.  Both the directive name and the | 
| 757 |  |  |  |  |  |  | value is checked, because some directives such as ErrorLog, can take | 
| 758 |  |  |  |  |  |  | values that are not paths (i.e. a piped command or syslog:facility). | 
| 759 |  |  |  |  |  |  | The /dev/null equivalent for the operating system is not treated as a | 
| 760 |  |  |  |  |  |  | path, since on some operating systems the /dev/null equivalent is not | 
| 761 |  |  |  |  |  |  | a file, such as nul on Windows. | 
| 762 |  |  |  |  |  |  |  | 
| 763 |  |  |  |  |  |  | The method actually does not check if its value is a path, rather it | 
| 764 |  |  |  |  |  |  | checks if the value does not match all of the other possible non-path | 
| 765 |  |  |  |  |  |  | values for the specific directive because different operating systems | 
| 766 |  |  |  |  |  |  | have different path formats, such as Unix, Windows and Macintosh. | 
| 767 |  |  |  |  |  |  |  | 
| 768 |  |  |  |  |  |  | =cut | 
| 769 |  |  |  |  |  |  |  | 
| 770 |  |  |  |  |  |  | sub value_is_rel_path { | 
| 771 | 390 | 50 |  | 390 | 1 | 934 | unless (@_ < 3) { | 
| 772 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::value_is_rel_path ", | 
| 773 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 774 |  |  |  |  |  |  | } | 
| 775 |  |  |  |  |  |  |  | 
| 776 | 390 |  |  |  |  | 1222 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 777 |  |  |  |  |  |  | CHECK_TYPE_REL, | 
| 778 |  |  |  |  |  |  | 'value_array', | 
| 779 |  |  |  |  |  |  | $_[1]); | 
| 780 |  |  |  |  |  |  | } | 
| 781 |  |  |  |  |  |  |  | 
| 782 |  |  |  |  |  |  | =item $d->orig_value_is_rel_path | 
| 783 |  |  |  |  |  |  |  | 
| 784 |  |  |  |  |  |  | =item $d->orig_value_is_rel_path($index_into_value_array) | 
| 785 |  |  |  |  |  |  |  | 
| 786 |  |  |  |  |  |  | This has the same behavior as C<< $d->value_is_rel_path >> except the | 
| 787 |  |  |  |  |  |  | results are applicable to C<$d>'s 'original' value array. | 
| 788 |  |  |  |  |  |  |  | 
| 789 |  |  |  |  |  |  | =cut | 
| 790 |  |  |  |  |  |  |  | 
| 791 |  |  |  |  |  |  | sub orig_value_is_rel_path { | 
| 792 | 128 | 50 |  | 128 | 1 | 392 | unless (@_ < 3) { | 
| 793 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::orig_value_is_rel_path ", | 
| 794 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 795 |  |  |  |  |  |  | } | 
| 796 |  |  |  |  |  |  |  | 
| 797 | 128 |  |  |  |  | 452 | _value_is_path_or_abs_path_or_rel_path($_[0], | 
| 798 |  |  |  |  |  |  | CHECK_TYPE_REL, | 
| 799 |  |  |  |  |  |  | 'orig_value_array', | 
| 800 |  |  |  |  |  |  | $_[1]); | 
| 801 |  |  |  |  |  |  | } | 
| 802 |  |  |  |  |  |  |  | 
| 803 |  |  |  |  |  |  | =item $d->filename | 
| 804 |  |  |  |  |  |  |  | 
| 805 |  |  |  |  |  |  | =item $d->filename($filename) | 
| 806 |  |  |  |  |  |  |  | 
| 807 |  |  |  |  |  |  | In the first form get the filename where this particular directive or | 
| 808 |  |  |  |  |  |  | context appears.  In the second form set the new filename of the | 
| 809 |  |  |  |  |  |  | directive or context and return the original filename. | 
| 810 |  |  |  |  |  |  |  | 
| 811 |  |  |  |  |  |  | =cut | 
| 812 |  |  |  |  |  |  |  | 
| 813 |  |  |  |  |  |  | sub filename { | 
| 814 | 1236 | 50 |  | 1236 | 1 | 3177 | unless (@_ < 3) { | 
| 815 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::filename ", | 
| 816 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 817 |  |  |  |  |  |  | } | 
| 818 |  |  |  |  |  |  |  | 
| 819 | 1236 |  |  |  |  | 1273 | my $self = shift; | 
| 820 | 1236 | 100 |  |  |  | 2059 | if (@_) { | 
| 821 | 1234 |  |  |  |  | 1604 | my $old           = $self->{filename}; | 
| 822 | 1234 |  |  |  |  | 1743 | $self->{filename} = $_[0]; | 
| 823 | 1234 |  |  |  |  | 2261 | return $old; | 
| 824 |  |  |  |  |  |  | } else { | 
| 825 | 2 |  |  |  |  | 8 | return $self->{filename}; | 
| 826 |  |  |  |  |  |  | } | 
| 827 |  |  |  |  |  |  | } | 
| 828 |  |  |  |  |  |  |  | 
| 829 |  |  |  |  |  |  | =item $d->line_number | 
| 830 |  |  |  |  |  |  |  | 
| 831 |  |  |  |  |  |  | =item $d->line_number($line_number) | 
| 832 |  |  |  |  |  |  |  | 
| 833 |  |  |  |  |  |  | In the first form get the line number where the directive or context | 
| 834 |  |  |  |  |  |  | appears in a filename.  In the second form set the new line number of | 
| 835 |  |  |  |  |  |  | the directive or context and return the original line number. | 
| 836 |  |  |  |  |  |  |  | 
| 837 |  |  |  |  |  |  | =cut | 
| 838 |  |  |  |  |  |  |  | 
| 839 |  |  |  |  |  |  | sub line_number { | 
| 840 | 1236 | 50 |  | 1236 | 1 | 2305 | unless (@_ < 3) { | 
| 841 | 0 |  |  |  |  | 0 | confess "$0: Apache::ConfigParser::Directive::line_number ", | 
| 842 |  |  |  |  |  |  | $INCORRECT_NUMBER_OF_ARGS; | 
| 843 |  |  |  |  |  |  | } | 
| 844 |  |  |  |  |  |  |  | 
| 845 | 1236 |  |  |  |  | 1234 | my $self = shift; | 
| 846 | 1236 | 100 |  |  |  | 1813 | if (@_) { | 
| 847 | 1234 |  |  |  |  | 1329 | my $old              = $self->{line_number}; | 
| 848 | 1234 |  |  |  |  | 1635 | $self->{line_number} = $_[0]; | 
| 849 | 1234 |  |  |  |  | 2031 | return $old; | 
| 850 |  |  |  |  |  |  | } else { | 
| 851 | 2 |  |  |  |  | 7 | return $self->{line_number}; | 
| 852 |  |  |  |  |  |  | } | 
| 853 |  |  |  |  |  |  | } | 
| 854 |  |  |  |  |  |  |  | 
| 855 |  |  |  |  |  |  | =back | 
| 856 |  |  |  |  |  |  |  | 
| 857 |  |  |  |  |  |  | =head1 EXPORTED VARIABLES | 
| 858 |  |  |  |  |  |  |  | 
| 859 |  |  |  |  |  |  | The following variables are exported via C<@EXPORT_OK>. | 
| 860 |  |  |  |  |  |  |  | 
| 861 |  |  |  |  |  |  | =over 4 | 
| 862 |  |  |  |  |  |  |  | 
| 863 |  |  |  |  |  |  | =item DEV_NULL | 
| 864 |  |  |  |  |  |  |  | 
| 865 |  |  |  |  |  |  | The string representation of the null device on this operating system. | 
| 866 |  |  |  |  |  |  |  | 
| 867 |  |  |  |  |  |  | =item DEV_NULL_LC | 
| 868 |  |  |  |  |  |  |  | 
| 869 |  |  |  |  |  |  | The lowercase version of DEV_NULL. | 
| 870 |  |  |  |  |  |  |  | 
| 871 |  |  |  |  |  |  | =item is_dev_null($path) | 
| 872 |  |  |  |  |  |  |  | 
| 873 |  |  |  |  |  |  | On a case sensitive system, compares $path to DEV_NULL and on a case | 
| 874 |  |  |  |  |  |  | insensitive system, compares lc($path) to DEV_NULL_LC. | 
| 875 |  |  |  |  |  |  |  | 
| 876 |  |  |  |  |  |  | =item %directive_value_takes_abs_path | 
| 877 |  |  |  |  |  |  |  | 
| 878 |  |  |  |  |  |  | This hash is keyed by the lowercase version of a directive name.  This | 
| 879 |  |  |  |  |  |  | hash is keyed by all directives that accept a file or directory path | 
| 880 |  |  |  |  |  |  | value as its first value array element. The hash value is a subroutine | 
| 881 |  |  |  |  |  |  | reference to pass the value array element containing the file, | 
| 882 |  |  |  |  |  |  | directory, pipe or syslog entry to.  If a hash entry exists for a | 
| 883 |  |  |  |  |  |  | particular entry, then the directive name can take either a relative | 
| 884 |  |  |  |  |  |  | or absolute path to either a file or directory.  The hash does not | 
| 885 |  |  |  |  |  |  | distinguish between directives that take only filenames, only | 
| 886 |  |  |  |  |  |  | directories or both, and it does not distinguish if the directive | 
| 887 |  |  |  |  |  |  | takes only absolute, only relative or both types of paths. | 
| 888 |  |  |  |  |  |  |  | 
| 889 |  |  |  |  |  |  | The hash value for the lowercase directive name is a subroutine | 
| 890 |  |  |  |  |  |  | reference.  The subroutine returns 1 if its only argument is a path | 
| 891 |  |  |  |  |  |  | and 0 otherwise.  The /dev/null equivalent (C<< File::Spec->devnull >>) | 
| 892 |  |  |  |  |  |  | for the operating system being used is not counted as a path, since on | 
| 893 |  |  |  |  |  |  | some operating systems the /dev/null equivalent is not a filename, | 
| 894 |  |  |  |  |  |  | such as nul on Windows. | 
| 895 |  |  |  |  |  |  |  | 
| 896 |  |  |  |  |  |  | The subroutine actually does not check if its argument is a path, | 
| 897 |  |  |  |  |  |  | rather it checks if the argument does not match one of the other | 
| 898 |  |  |  |  |  |  | possible non-path values for the specific directive because different | 
| 899 |  |  |  |  |  |  | operating systems have different path formats, such as Unix, Windows | 
| 900 |  |  |  |  |  |  | and Macintosh.  For example, ErrorLog can take a filename, such as | 
| 901 |  |  |  |  |  |  |  | 
| 902 |  |  |  |  |  |  | ErrorLog /var/log/httpd/error_log | 
| 903 |  |  |  |  |  |  |  | 
| 904 |  |  |  |  |  |  | or a piped command, such as | 
| 905 |  |  |  |  |  |  |  | 
| 906 |  |  |  |  |  |  | ErrorLog "| cronolog /var/log/httpd/%Y/%m/%d/error.log" | 
| 907 |  |  |  |  |  |  |  | 
| 908 |  |  |  |  |  |  | or a syslog entry of the two forms: | 
| 909 |  |  |  |  |  |  |  | 
| 910 |  |  |  |  |  |  | ErrorLog syslog | 
| 911 |  |  |  |  |  |  | ErrorLog syslog:local7 | 
| 912 |  |  |  |  |  |  |  | 
| 913 |  |  |  |  |  |  | The particular subroutine for ErrorLog checks if the value is not | 
| 914 |  |  |  |  |  |  | equal to C<< File::Spec->devnull >>, does not begin with a | or does not | 
| 915 |  |  |  |  |  |  | match syslog(:[a-zA-Z0-9]+)?. | 
| 916 |  |  |  |  |  |  |  | 
| 917 |  |  |  |  |  |  | These subroutines do not remove any "'s before checking on the type of | 
| 918 |  |  |  |  |  |  | value. | 
| 919 |  |  |  |  |  |  |  | 
| 920 |  |  |  |  |  |  | This hash is used by C and C. | 
| 921 |  |  |  |  |  |  |  | 
| 922 |  |  |  |  |  |  | This is a list of directives and any special values to check for as of | 
| 923 |  |  |  |  |  |  | Apache 1.3.20 with the addition of IncludeOptional from 2.4.x. | 
| 924 |  |  |  |  |  |  |  | 
| 925 |  |  |  |  |  |  | AccessConfig | 
| 926 |  |  |  |  |  |  | AgentLog          check for "| prog" | 
| 927 |  |  |  |  |  |  | AuthDBGroupFile | 
| 928 |  |  |  |  |  |  | AuthDBMGroupFile | 
| 929 |  |  |  |  |  |  | AuthDBMUserFile | 
| 930 |  |  |  |  |  |  | AuthDBUserFile | 
| 931 |  |  |  |  |  |  | AuthDigestFile | 
| 932 |  |  |  |  |  |  | AuthGroupFile | 
| 933 |  |  |  |  |  |  | AuthUserFile | 
| 934 |  |  |  |  |  |  | CacheRoot | 
| 935 |  |  |  |  |  |  | CookieLog | 
| 936 |  |  |  |  |  |  | CoreDumpDirectory | 
| 937 |  |  |  |  |  |  | CustomLog         check for "| prog" | 
| 938 |  |  |  |  |  |  | Directory | 
| 939 |  |  |  |  |  |  | DocumentRoot | 
| 940 |  |  |  |  |  |  | ErrorLog          check for "| prog", or syslog or syslog:facility | 
| 941 |  |  |  |  |  |  | Include | 
| 942 |  |  |  |  |  |  | IncludeOptional | 
| 943 |  |  |  |  |  |  | LoadFile | 
| 944 |  |  |  |  |  |  | LoadModule | 
| 945 |  |  |  |  |  |  | LockFile | 
| 946 |  |  |  |  |  |  | MimeMagicFile | 
| 947 |  |  |  |  |  |  | MMapFile | 
| 948 |  |  |  |  |  |  | PidFile | 
| 949 |  |  |  |  |  |  | RefererLog        check for "| prog" | 
| 950 |  |  |  |  |  |  | ResourceConfig | 
| 951 |  |  |  |  |  |  | RewriteLock | 
| 952 |  |  |  |  |  |  | ScoreBoardFile | 
| 953 |  |  |  |  |  |  | ScriptLog | 
| 954 |  |  |  |  |  |  | ServerRoot | 
| 955 |  |  |  |  |  |  | TransferLog       check for "| prog" | 
| 956 |  |  |  |  |  |  | TypesConfig | 
| 957 |  |  |  |  |  |  |  | 
| 958 |  |  |  |  |  |  | =item %directive_value_takes_rel_path | 
| 959 |  |  |  |  |  |  |  | 
| 960 |  |  |  |  |  |  | This hash is keyed by the lowercase version of a directive name.  This | 
| 961 |  |  |  |  |  |  | hash contains only those directive names that can accept both relative | 
| 962 |  |  |  |  |  |  | and absolute file or directory names.  The hash value is a subroutine | 
| 963 |  |  |  |  |  |  | reference to pass the value array element containing the file, | 
| 964 |  |  |  |  |  |  | directory, pipe or syslog entry to.  The hash does not distinguish | 
| 965 |  |  |  |  |  |  | between directives that take only filenames, only directories or both. | 
| 966 |  |  |  |  |  |  |  | 
| 967 |  |  |  |  |  |  | The hash value for the lowercase directive name is a subroutine | 
| 968 |  |  |  |  |  |  | reference.  The subroutine returns 1 if its only argument is a path | 
| 969 |  |  |  |  |  |  | and 0 otherwise.  The /dev/null equivalent (C<< File::Spec->devnull >>) | 
| 970 |  |  |  |  |  |  | for the operating system being used is not counted as a path, since on | 
| 971 |  |  |  |  |  |  | some operating systems the /dev/null equivalent is not a filename, | 
| 972 |  |  |  |  |  |  | such as nul on Windows. | 
| 973 |  |  |  |  |  |  |  | 
| 974 |  |  |  |  |  |  | The subroutine actually does not check if its argument is a path, | 
| 975 |  |  |  |  |  |  | rather it checks if the argument does not match one of the other | 
| 976 |  |  |  |  |  |  | possible non-path values for the specific directive because different | 
| 977 |  |  |  |  |  |  | operating systems have different path formats, such as Unix, Windows | 
| 978 |  |  |  |  |  |  | and Macintosh.  For example, ErrorLog can take a filename, such as | 
| 979 |  |  |  |  |  |  |  | 
| 980 |  |  |  |  |  |  | ErrorLog /var/log/httpd/error_log | 
| 981 |  |  |  |  |  |  |  | 
| 982 |  |  |  |  |  |  | or a piped command, such as | 
| 983 |  |  |  |  |  |  |  | 
| 984 |  |  |  |  |  |  | ErrorLog "| cronolog /var/log/httpd/%Y/%m/%d/error.log" | 
| 985 |  |  |  |  |  |  |  | 
| 986 |  |  |  |  |  |  | or a syslog entry of the two forms: | 
| 987 |  |  |  |  |  |  |  | 
| 988 |  |  |  |  |  |  | ErrorLog syslog | 
| 989 |  |  |  |  |  |  | ErrorLog syslog:local7 | 
| 990 |  |  |  |  |  |  |  | 
| 991 |  |  |  |  |  |  | The particular subroutine for ErrorLog checks if the value is not | 
| 992 |  |  |  |  |  |  | equal to C<< File::Spec->devnull >>, does not begin with a | or does not | 
| 993 |  |  |  |  |  |  | match syslog(:[a-zA-Z0-9]+)?. | 
| 994 |  |  |  |  |  |  |  | 
| 995 |  |  |  |  |  |  | These subroutines do not remove any "'s before checking on the type of | 
| 996 |  |  |  |  |  |  | value. | 
| 997 |  |  |  |  |  |  |  | 
| 998 |  |  |  |  |  |  | This hash is used by C and | 
| 999 |  |  |  |  |  |  | C. | 
| 1000 |  |  |  |  |  |  |  | 
| 1001 |  |  |  |  |  |  | This is a list of directives and any special values to check for as of | 
| 1002 |  |  |  |  |  |  | Apache 1.3.20 with the addition of IncludeOptional from 2.4.x. | 
| 1003 |  |  |  |  |  |  |  | 
| 1004 |  |  |  |  |  |  | AccessFileName is not a key in the hash because, while its value is | 
| 1005 |  |  |  |  |  |  | one or more relative paths, the ServerRoot is never prepended to it as | 
| 1006 |  |  |  |  |  |  | the AccessFileName values are looked up in every directory of the path | 
| 1007 |  |  |  |  |  |  | to the document being requested. | 
| 1008 |  |  |  |  |  |  |  | 
| 1009 |  |  |  |  |  |  | AccessConfig | 
| 1010 |  |  |  |  |  |  | AuthGroupFile | 
| 1011 |  |  |  |  |  |  | AuthUserFile | 
| 1012 |  |  |  |  |  |  | CookieLog | 
| 1013 |  |  |  |  |  |  | CustomLog         check for "| prog" | 
| 1014 |  |  |  |  |  |  | ErrorLog          check for "| prog", or syslog or syslog:facility | 
| 1015 |  |  |  |  |  |  | Include | 
| 1016 |  |  |  |  |  |  | IncludeOptional | 
| 1017 |  |  |  |  |  |  | LoadFile | 
| 1018 |  |  |  |  |  |  | LoadModule | 
| 1019 |  |  |  |  |  |  | LockFile | 
| 1020 |  |  |  |  |  |  | MimeMagicFile | 
| 1021 |  |  |  |  |  |  | PidFile | 
| 1022 |  |  |  |  |  |  | RefererLog        check for "| prog" | 
| 1023 |  |  |  |  |  |  | ResourceConfig | 
| 1024 |  |  |  |  |  |  | ScoreBoardFile | 
| 1025 |  |  |  |  |  |  | ScriptLog | 
| 1026 |  |  |  |  |  |  | TransferLog       check for "| prog" | 
| 1027 |  |  |  |  |  |  | TypesConfig | 
| 1028 |  |  |  |  |  |  |  | 
| 1029 |  |  |  |  |  |  | =item %directive_value_path_element_pos | 
| 1030 |  |  |  |  |  |  |  | 
| 1031 |  |  |  |  |  |  | This hash holds the indexes into the directive value array for the | 
| 1032 |  |  |  |  |  |  | value or values that can contain either absolute or relative file or | 
| 1033 |  |  |  |  |  |  | directory paths.  This hash is keyed by the lowercase version of a | 
| 1034 |  |  |  |  |  |  | directive name.  The hash value is a string representing an integer. | 
| 1035 |  |  |  |  |  |  | The string can take two forms: | 
| 1036 |  |  |  |  |  |  |  | 
| 1037 |  |  |  |  |  |  | /^\d+$/   The directive has only one value element indexed by \d+ | 
| 1038 |  |  |  |  |  |  | that takes a file or directory path. | 
| 1039 |  |  |  |  |  |  |  | 
| 1040 |  |  |  |  |  |  | /^-\d+$/  The directive takes any number of file or directory path | 
| 1041 |  |  |  |  |  |  | elements beginning with the abs(\d+) element. | 
| 1042 |  |  |  |  |  |  |  | 
| 1043 |  |  |  |  |  |  | For example: | 
| 1044 |  |  |  |  |  |  |  | 
| 1045 |  |  |  |  |  |  | # CustomLog logs/access_log common | 
| 1046 |  |  |  |  |  |  | $directive_value_path_element_pos{customlog}  eq '0'; | 
| 1047 |  |  |  |  |  |  |  | 
| 1048 |  |  |  |  |  |  | # LoadFile modules/mod_env.so libexec/mod_mime.so | 
| 1049 |  |  |  |  |  |  | $directive_value_path_element_pos{loadfile}   eq '-0'; | 
| 1050 |  |  |  |  |  |  |  | 
| 1051 |  |  |  |  |  |  | # LoadModule env_module modules/mod_env.so | 
| 1052 |  |  |  |  |  |  | $directive_value_path_element_pos{loadmodule} eq '1'; | 
| 1053 |  |  |  |  |  |  |  | 
| 1054 |  |  |  |  |  |  | # PidFile logs/httpd.pid | 
| 1055 |  |  |  |  |  |  | $directive_value_path_element_pos{pidfile}    eq '0'; | 
| 1056 |  |  |  |  |  |  |  | 
| 1057 |  |  |  |  |  |  | =back | 
| 1058 |  |  |  |  |  |  |  | 
| 1059 |  |  |  |  |  |  | =cut | 
| 1060 |  |  |  |  |  |  |  | 
| 1061 |  |  |  |  |  |  | sub directive_value_is_not_dev_null { | 
| 1062 | 890 |  |  | 890 | 0 | 1229 | !is_dev_null($_[0]); | 
| 1063 |  |  |  |  |  |  | } | 
| 1064 |  |  |  |  |  |  |  | 
| 1065 |  |  |  |  |  |  | sub directive_value_is_not_dev_null_and_pipe { | 
| 1066 | 161 | 50 |  | 161 | 0 | 258 | if (is_dev_null($_[0])) { | 
| 1067 | 0 |  |  |  |  | 0 | return 0; | 
| 1068 |  |  |  |  |  |  | } | 
| 1069 |  |  |  |  |  |  |  | 
| 1070 | 161 |  |  |  |  | 498 | return $_[0] !~ /^\s*\|/; | 
| 1071 |  |  |  |  |  |  | } | 
| 1072 |  |  |  |  |  |  |  | 
| 1073 |  |  |  |  |  |  | sub directive_value_is_not_dev_null_and_pipe_and_syslog { | 
| 1074 | 86 | 50 |  | 86 | 0 | 155 | if (is_dev_null($_[0])) { | 
| 1075 | 0 |  |  |  |  | 0 | return 0; | 
| 1076 |  |  |  |  |  |  | } | 
| 1077 |  |  |  |  |  |  |  | 
| 1078 | 86 |  |  |  |  | 376 | return $_[0] !~ /^\s*(?:(?:\|)|(?:syslog(?::[a-zA-Z0-9]+)?))/; | 
| 1079 |  |  |  |  |  |  | } | 
| 1080 |  |  |  |  |  |  |  | 
| 1081 |  |  |  |  |  |  | # This is a hash keyed by directive name and the value is an array | 
| 1082 |  |  |  |  |  |  | # reference.  The array element are | 
| 1083 |  |  |  |  |  |  | #   array    array | 
| 1084 |  |  |  |  |  |  | #   index    value | 
| 1085 |  |  |  |  |  |  | #       0    A string containing an integer that describes the element | 
| 1086 |  |  |  |  |  |  | #            position(s) that contains the file or directory path. | 
| 1087 |  |  |  |  |  |  | #            string =~ /^\d+/   a single element that contains a path | 
| 1088 |  |  |  |  |  |  | #            string =~ /^-\d+/  multiple elements, first is abs(\d+) | 
| 1089 |  |  |  |  |  |  | #       1    1 if the paths the directive accepts can be absolute and | 
| 1090 |  |  |  |  |  |  | #            relative, 0 if they can only be absolute | 
| 1091 |  |  |  |  |  |  | #       2    a subroutine reference to directive_value_is_not_dev_null, | 
| 1092 |  |  |  |  |  |  | #            directive_value_is_not_dev_null_and_pipe or | 
| 1093 |  |  |  |  |  |  | #            directive_value_is_not_dev_null_and_pipe_and_syslog. | 
| 1094 |  |  |  |  |  |  |  | 
| 1095 |  |  |  |  |  |  | my %directive_info = ( | 
| 1096 |  |  |  |  |  |  | AccessConfig      => ['0', | 
| 1097 |  |  |  |  |  |  | 1, | 
| 1098 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1099 |  |  |  |  |  |  | AuthDBGroupFile   => ['0', | 
| 1100 |  |  |  |  |  |  | 0, | 
| 1101 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1102 |  |  |  |  |  |  | AuthDBMGroupFile  => ['0', | 
| 1103 |  |  |  |  |  |  | 0, | 
| 1104 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1105 |  |  |  |  |  |  | AuthDBMUserFile   => ['0', | 
| 1106 |  |  |  |  |  |  | 0, | 
| 1107 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1108 |  |  |  |  |  |  | AuthDBUserFile    => ['0', | 
| 1109 |  |  |  |  |  |  | 0, | 
| 1110 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1111 |  |  |  |  |  |  | AuthDigestFile    => ['0', | 
| 1112 |  |  |  |  |  |  | 0, | 
| 1113 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1114 |  |  |  |  |  |  | AgentLog          => ['0', | 
| 1115 |  |  |  |  |  |  | 0, | 
| 1116 |  |  |  |  |  |  | \&directive_value_is_not_dev_null_and_pipe], | 
| 1117 |  |  |  |  |  |  | AuthGroupFile     => ['0', | 
| 1118 |  |  |  |  |  |  | 1, | 
| 1119 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1120 |  |  |  |  |  |  | AuthUserFile      => ['0', | 
| 1121 |  |  |  |  |  |  | 1, | 
| 1122 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1123 |  |  |  |  |  |  | CacheRoot         => ['0', | 
| 1124 |  |  |  |  |  |  | 0, | 
| 1125 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1126 |  |  |  |  |  |  | CookieLog         => ['0', | 
| 1127 |  |  |  |  |  |  | 1, | 
| 1128 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1129 |  |  |  |  |  |  | CoreDumpDirectory => ['0', | 
| 1130 |  |  |  |  |  |  | 0, | 
| 1131 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1132 |  |  |  |  |  |  | CustomLog         => ['0', | 
| 1133 |  |  |  |  |  |  | 1, | 
| 1134 |  |  |  |  |  |  | \&directive_value_is_not_dev_null_and_pipe], | 
| 1135 |  |  |  |  |  |  | Directory         => ['0', | 
| 1136 |  |  |  |  |  |  | 0, | 
| 1137 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1138 |  |  |  |  |  |  | DocumentRoot      => ['0', | 
| 1139 |  |  |  |  |  |  | 0, | 
| 1140 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1141 |  |  |  |  |  |  | ErrorLog          => ['0', | 
| 1142 |  |  |  |  |  |  | 1, | 
| 1143 |  |  |  |  |  |  | \&directive_value_is_not_dev_null_and_pipe_and_syslog], | 
| 1144 |  |  |  |  |  |  | Include           => ['0', | 
| 1145 |  |  |  |  |  |  | 1, | 
| 1146 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1147 |  |  |  |  |  |  | IncludeOptional   => ['0', | 
| 1148 |  |  |  |  |  |  | 1, | 
| 1149 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1150 |  |  |  |  |  |  | LoadFile          => ['-0', | 
| 1151 |  |  |  |  |  |  | 1, | 
| 1152 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1153 |  |  |  |  |  |  | LoadModule        => ['1', | 
| 1154 |  |  |  |  |  |  | 1, | 
| 1155 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1156 |  |  |  |  |  |  | LockFile          => ['0', | 
| 1157 |  |  |  |  |  |  | 1, | 
| 1158 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1159 |  |  |  |  |  |  | MMapFile          => ['0', | 
| 1160 |  |  |  |  |  |  | 0, | 
| 1161 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1162 |  |  |  |  |  |  | MimeMagicFile     => ['0', | 
| 1163 |  |  |  |  |  |  | 1, | 
| 1164 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1165 |  |  |  |  |  |  | PidFile           => ['0', | 
| 1166 |  |  |  |  |  |  | 1, | 
| 1167 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1168 |  |  |  |  |  |  | RefererLog        => ['0', | 
| 1169 |  |  |  |  |  |  | 1, | 
| 1170 |  |  |  |  |  |  | \&directive_value_is_not_dev_null_and_pipe], | 
| 1171 |  |  |  |  |  |  | ResourceConfig    => ['0', | 
| 1172 |  |  |  |  |  |  | 1, | 
| 1173 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1174 |  |  |  |  |  |  | RewriteLock       => ['0', | 
| 1175 |  |  |  |  |  |  | 0, | 
| 1176 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1177 |  |  |  |  |  |  | ScoreBoardFile    => ['0', | 
| 1178 |  |  |  |  |  |  | 1, | 
| 1179 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1180 |  |  |  |  |  |  | ScriptLog         => ['0', | 
| 1181 |  |  |  |  |  |  | 1, | 
| 1182 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1183 |  |  |  |  |  |  | ServerRoot        => ['0', | 
| 1184 |  |  |  |  |  |  | 0, | 
| 1185 |  |  |  |  |  |  | \&directive_value_is_not_dev_null], | 
| 1186 |  |  |  |  |  |  | TransferLog       => ['0', | 
| 1187 |  |  |  |  |  |  | 1, | 
| 1188 |  |  |  |  |  |  | \&directive_value_is_not_dev_null_and_pipe], | 
| 1189 |  |  |  |  |  |  | TypesConfig       => ['0', | 
| 1190 |  |  |  |  |  |  | 1, | 
| 1191 |  |  |  |  |  |  | \&directive_value_is_not_dev_null]); | 
| 1192 |  |  |  |  |  |  |  | 
| 1193 |  |  |  |  |  |  | # Set up the three exported hashes using the information in | 
| 1194 |  |  |  |  |  |  | # %directive_info.  Use lowercase directive names. | 
| 1195 |  |  |  |  |  |  | foreach my $key (keys %directive_info) { | 
| 1196 |  |  |  |  |  |  | my $ref                                    = $directive_info{$key}; | 
| 1197 |  |  |  |  |  |  | my $lc_key                                 = lc($key); | 
| 1198 |  |  |  |  |  |  | my ($index, $abs_and_rel, $sub_ref)        = @$ref; | 
| 1199 |  |  |  |  |  |  | if ($abs_and_rel) { | 
| 1200 |  |  |  |  |  |  | $directive_value_takes_rel_path{$lc_key} = $sub_ref; | 
| 1201 |  |  |  |  |  |  | } | 
| 1202 |  |  |  |  |  |  | $directive_value_takes_abs_path{$lc_key}   = $sub_ref; | 
| 1203 |  |  |  |  |  |  | $directive_value_path_element_pos{$lc_key} = $index; | 
| 1204 |  |  |  |  |  |  | } | 
| 1205 |  |  |  |  |  |  |  | 
| 1206 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 1207 |  |  |  |  |  |  |  | 
| 1208 |  |  |  |  |  |  | L and L. | 
| 1209 |  |  |  |  |  |  |  | 
| 1210 |  |  |  |  |  |  | =head1 AUTHOR | 
| 1211 |  |  |  |  |  |  |  | 
| 1212 |  |  |  |  |  |  | Blair Zajac . | 
| 1213 |  |  |  |  |  |  |  | 
| 1214 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 1215 |  |  |  |  |  |  |  | 
| 1216 |  |  |  |  |  |  | Copyright (C) 2001-2005 Blair Zajac.  All rights reserved.  This | 
| 1217 |  |  |  |  |  |  | program is free software; you can redistribute it and/or modify it | 
| 1218 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 1219 |  |  |  |  |  |  |  | 
| 1220 |  |  |  |  |  |  | =cut | 
| 1221 |  |  |  |  |  |  |  | 
| 1222 |  |  |  |  |  |  | 1; |