Checks that the path exists, and that it has the appropriate
permissions, where permissions contains some combination of r, w and x. If not, and if non_fatal is perlishly false,
it dies, using the value of option to produce a semi-intelligable error message. If non_fatal is perlishly true it returns the error or an empty string.
=cut
subcheck_path {
my$option= shift;
my$path= shift;
my$permissions= shift;
my$non_fatal= 0;
$non_fatal= 1 if$_[0];
my$error= "";
if(not(-e $path)) {
$error= "No file corresponding to path for '$option'";
} elsif($permissions=~/r/ and (not -r $path)) {
$error= "File '$path' for '$option' option is not readable";
} elsif($permissions=~/w/ and (not -w $path)) {
$error= "File '$path' for '$option' option is not writable";
} elsif($permissions=~/x/ and (not -x $path)) {
$error= "File '$path' for '$option' option is not executable";
Returns errors on typechecking value against record. Name is provided for error messages. Path is from config file.
=cut
subtype_check {
my$path= shift;
my$name= shift;
my$value= shift;
my$record= shift;
$value=~s/^\s*(.*?)\s*$/$1/s;
my@errors= ();
my$list_name= '';
$list_name= "Item $_[0] of"ifdefined$_[0];
my$datatype= $record->[2];
if($datatypeeq 'integer') {
push@errors,sprintf("$list_name Entry called %s should be an integer",$name) unless$value=~/^\d+$/;
push@errors,sprintf("$list_name Entry called %s is less than minimum permitted value of $record->[3]",$name) if($value=~/^\d+$/ and (defined$record->[3]) and ($record->[3] > $value));
push@errors,sprintf("$list_name Entry called %s exceeds permitted value of $record->[4]",$name) if($value=~/^\d+$/ and (defined$record->[4]) and ($record->[4] < $value));
} elsif($datatypeeq 'float') {
push@errors,sprintf("$list_name Entry called %s should be a number",$name) unless$value=~/^-?\d+(\.\d+)$/;
push@errors,sprintf("$list_name Entry called %s is less than minimum permitted value of $record->[3]",$name) if($value=~/^-?\d+(\.\d+)$/ and (defined$record->[3]) and ($record->[3] > $value));
push@errors,sprintf("$list_name Entry called %s exceeds permitted value of $record->[4]",$name) if($value=~/^-?\d+(\.\d+)$/ and (defined$record->[4]) and ($record->[4] < $value));
} elsif($datatypeeq 'ip') {
push@errors,sprintf("$list_name Entry called %s should be an ip address",$name) unless$value=~/^\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?$/;
} elsif($datatypeeq 'cidr') {
push@errors,sprintf("$list_name Entry called %s should be a CIDR ip range",$name) unless$value=~m!^\d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d?/\d\d?$!;
# } elsif ($datatype eq 'xml_leaf') {
# push @errors,sprintf("$list_name Entry called %s should be an xml filename",$name) unless $value=~/^[A-Za-z0-9_-]+\.xml$/;
# } elsif ($datatype eq 'xsl_leaf') {
# push @errors,sprintf("$list_name Entry called %s should be an xsl filename",$name) unless $value=~/^[A-Za-z0-9_-]+\.xsl$/;
} elsif($datatypeeq 'yes_no') {
push@errors,sprintf("$list_name Entry called %s should be 'yes' or 'no'",$name) unless$value=~/^(yes)|(no)$/;
} elsif($datatypeeq 'word') {
push@errors,sprintf("$list_name Entry called %s should be a word (ie no whitespace)",$name) unless$value=~/^\S+$/;
} elsif($datatypeeq 'function_name') {
push@errors,sprintf("$list_name Entry called %s should be an xpath function name",$name) unless$value=~/^[^\s:]+(:\S+)?$/;
} elsif($datatypeeq 'path') {
push@errors,sprintf("$list_name Entry called %s should be a path",$name) unless$value=~/^\S+$/;
} elsif($datatypeeq 'email') {
push@errors,sprintf("$list_name Entry called %s should be an email address",$name) unless$value=~/^[^\s@]+\@[^\s@]+$/;
} elsif(($datatypeeq 'abs_file') or ($datatypeeq 'abs_dir')) {
$value= "$path/$value"if($pathand $value!~/^\//);
push@errors,sprintf("$list_name Entry called %s should be absolute (ie it should start with /)",$name) unless$value=~/^\//;
push@errors,sprintf("No file or directory corresponds to $list_name entry called %s ('%s')",$name,$value) unless-e $value;
if(-e $value) {
push@errors,sprintf("$list_name Entry called %s should be a file, not a directory",$name) if((-d $value) and ($datatypeeq 'abs_file'));
push@errors,sprintf("$list_name Entry called %s should be a directory, not a file",$name) if((-f $value) and ($datatypeeq 'abs_dir'));
push@errors,sprintf("$list_name Entry called %s must be readable",$name) if($record->[3]=~/r/ and not -r $value);
push@errors,sprintf("$list_name Entry called %s must be writable",$name) if($record->[3]=~/w/ and not -w $value);
push@errors,sprintf("$list_name Entry called %s must be executable",$name) if($record->[3]=~/x/ and not -x $value);
push@errors,check_file_content($name,$value,$record->[4]) if((-f $value) and $record->[4]);
}
} elsif($datatypeeq 'abs_create'){
$value= "$path/$value"if($pathand $value!~/^\//);
$value=~m!^(.*/)?([^/]+$)!;
my$dir= $1;
push@errors,sprintf("$list_name Entry called %s should be absolute (ie it should start with /)",$name) unless$value=~/^\//;
push@errors,sprintf("$list_name No file or directory corresponds to entry called %s, and insufficient rights to create one",$name) if((not -e $value) and ((not $dir) or (-d $dir) and ((not -r $dir) or (not -w $dir) or (not -x $dir))));
push@errors,sprintf("$list_name Entry called %s must be readable",$name) if($record->[3]=~/r/ and -e $valueand not -r $value);
push@errors,sprintf("$list_name Entry called %s must be writable",$name) if($record->[3]=~/w/ and -e $valueand not -w $value);
push@errors,sprintf("$list_name Entry called %s must be executable",$name) if($record->[3]=~/x/ and -e $valueand not -x $value);
} elsif($datatypeeq 'debug_list') {
if($value!~/,/) {
push@errors,sprintf("$list_name Entry called %s cannot include '%s'",$name,$value) unless$value=~/^((none)|(all)|(timer-io)|(non-timer-io)|(io)|(show-wrappers)|(connections)|(doc-cache)|(doc-write)|(channels)|(stack)|(update))$/;
} else{
foreachmy$v(split/\s*,\s*/,$value) {
push@errors,sprintf("$list_name Entry called %s cannot include 'all' or 'none' in a comma-separated list",$name) if$v=~/^((none)|(all))$/;
push@errors,sprintf("$list_name Entry called %s cannot include '%s'",$name,$v) unless$v=~/^((none)|(all)|(timer-io)|(non-timer-io)|(io)|(show-wrappers)|(connections)|(doc-cache)|(channels)|(stack)|(update))$/;
}
}
} else{
croak sprintf("Unknown unit config datatype %s",$datatype);