| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
###################################################################### |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Copyright 1999 Web Juice, LLC. All Rights Reserved. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# CGI/ArgChecker.pm |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# An extensible CGI parameter validation module (allowing commonly used |
|
8
|
|
|
|
|
|
|
# checks on parameters to be called more concisely and consistently). |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# $Header: /usr/local/repository/advoco/CGI-ArgChecker/ArgChecker.pm,v 1.3 1999/08/12 00:07:22 dlowe Exp $ |
|
11
|
|
|
|
|
|
|
# $Log: ArgChecker.pm,v $ |
|
12
|
|
|
|
|
|
|
# Revision 1.3 1999/08/12 00:07:22 dlowe |
|
13
|
|
|
|
|
|
|
# Documentation update |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# Revision 1.2 1999/08/12 00:04:14 dlowe |
|
16
|
|
|
|
|
|
|
# Changed the argcheck() method to always return a hashref containing values, |
|
17
|
|
|
|
|
|
|
# even if some values failed in error checking. |
|
18
|
|
|
|
|
|
|
# |
|
19
|
|
|
|
|
|
|
# Revision 1.1.1.1 1999/07/09 01:24:54 dlowe |
|
20
|
|
|
|
|
|
|
# CGI::ArgChecker |
|
21
|
|
|
|
|
|
|
# |
|
22
|
|
|
|
|
|
|
# |
|
23
|
|
|
|
|
|
|
###################################################################### |
|
24
|
|
|
|
|
|
|
package CGI::ArgChecker; |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
614
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
27
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
68
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
818
|
use String::Checker; |
|
|
1
|
|
|
|
|
203169
|
|
|
|
1
|
|
|
|
|
499
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$VERSION = '0.02'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
###################################################################### |
|
34
|
|
|
|
|
|
|
## NAME: new |
|
35
|
|
|
|
|
|
|
## |
|
36
|
|
|
|
|
|
|
## DESCRIPTION: Constructor for CGI::ArgChecker |
|
37
|
|
|
|
|
|
|
## |
|
38
|
|
|
|
|
|
|
## USAGE: $checker = new CGI::ArgChecker; |
|
39
|
|
|
|
|
|
|
## |
|
40
|
|
|
|
|
|
|
## RETURN VALUES: undef if there's an error, otherwise a blessed hash ref. |
|
41
|
|
|
|
|
|
|
## |
|
42
|
|
|
|
|
|
|
## BUGS: Hopefully none. |
|
43
|
|
|
|
|
|
|
###################################################################### |
|
44
|
|
|
|
|
|
|
sub new |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
0
|
|
|
0
|
0
|
|
my($class) = shift; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
## We don't want this called as an instance method. |
|
49
|
0
|
0
|
|
|
|
|
if (ref($class)) |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
|
|
|
return(undef); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my($self) = { }; |
|
55
|
0
|
|
|
0
|
|
|
$self->{'errhandler'} = sub { }; |
|
|
0
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
bless($self, $class); |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $self; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
### end new ########################################################## |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
###################################################################### |
|
65
|
|
|
|
|
|
|
## NAME: register_check |
|
66
|
|
|
|
|
|
|
## |
|
67
|
|
|
|
|
|
|
## DESCRIPTION: Register a new parameter checking routine |
|
68
|
|
|
|
|
|
|
## |
|
69
|
|
|
|
|
|
|
## USAGE: $checker->register_check($name, \&sub); |
|
70
|
|
|
|
|
|
|
## |
|
71
|
|
|
|
|
|
|
## RETURN VALUES: None. |
|
72
|
|
|
|
|
|
|
## |
|
73
|
|
|
|
|
|
|
## BUGS: Hopefully none. |
|
74
|
|
|
|
|
|
|
###################################################################### |
|
75
|
|
|
|
|
|
|
sub register_check |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
|
78
|
0
|
0
|
|
|
|
|
if (! ref($self)) |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
|
|
|
|
|
return; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my($check) = shift; |
|
84
|
0
|
|
|
|
|
|
my($coderef) = shift; |
|
85
|
0
|
|
|
|
|
|
String::Checker::register_check($check, $coderef); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
### end register_check ############################################### |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
###################################################################### |
|
92
|
|
|
|
|
|
|
## NAME: error_handler |
|
93
|
|
|
|
|
|
|
## |
|
94
|
|
|
|
|
|
|
## DESCRIPTION: Register an error handling routine |
|
95
|
|
|
|
|
|
|
## |
|
96
|
|
|
|
|
|
|
## USAGE: $checker->error_handler(\&errhandler); |
|
97
|
|
|
|
|
|
|
## |
|
98
|
|
|
|
|
|
|
## RETURN VALUES: None. |
|
99
|
|
|
|
|
|
|
## |
|
100
|
|
|
|
|
|
|
## BUGS: Hopefully none. |
|
101
|
|
|
|
|
|
|
###################################################################### |
|
102
|
|
|
|
|
|
|
sub error_handler |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
|
105
|
0
|
0
|
|
|
|
|
if (! ref($self)) |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
|
|
|
return(undef); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$self->{'errhandler'} = shift; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
### end error_handler ################################################ |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
###################################################################### |
|
117
|
|
|
|
|
|
|
## NAME: argcheck |
|
118
|
|
|
|
|
|
|
## |
|
119
|
|
|
|
|
|
|
## DESCRIPTION: Check that all CGI parameters match the programmer's |
|
120
|
|
|
|
|
|
|
## expectations. |
|
121
|
|
|
|
|
|
|
## |
|
122
|
|
|
|
|
|
|
## USAGE: $href = $checker->argcheck($CGI_query_object, |
|
123
|
|
|
|
|
|
|
## 'param_name' => [ 'expectation', ... ], |
|
124
|
|
|
|
|
|
|
## ... ); |
|
125
|
|
|
|
|
|
|
## |
|
126
|
|
|
|
|
|
|
## RETURN VALUES: Returns a hash reference containing param_name => |
|
127
|
|
|
|
|
|
|
## param_value pairs. If there's an internal error, |
|
128
|
|
|
|
|
|
|
## returns undef. |
|
129
|
|
|
|
|
|
|
## |
|
130
|
|
|
|
|
|
|
## BUGS: Hopefully none. |
|
131
|
|
|
|
|
|
|
###################################################################### |
|
132
|
|
|
|
|
|
|
sub argcheck |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
0
|
|
|
0
|
0
|
|
my($self) = shift; |
|
135
|
0
|
0
|
|
|
|
|
if (! ref($self)) |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
0
|
|
|
|
|
|
return(undef); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my($query) = shift; |
|
141
|
0
|
|
|
|
|
|
my(%expectations) = @_; |
|
142
|
0
|
|
|
|
|
|
my($error_flag) = 0; |
|
143
|
0
|
|
|
|
|
|
my(%return); |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
foreach my $parameter (keys(%expectations)) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
0
|
|
|
|
|
|
my($value) = $query->param($parameter); |
|
148
|
0
|
|
|
|
|
|
my($ret) = String::Checker::checkstring($value, |
|
149
|
|
|
|
|
|
|
$expectations{$parameter}); |
|
150
|
0
|
0
|
|
|
|
|
if (! defined($ret)) |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
|
|
|
|
|
return(undef); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
0
|
|
|
|
|
|
foreach my $error_name (@{$ret}) |
|
|
0
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
{ |
|
156
|
0
|
|
|
|
|
|
$error_flag = 1; |
|
157
|
0
|
|
|
|
|
|
$self->{'errhandler'}->($parameter, $error_name); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$return{$parameter} = $value; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
0
|
0
|
|
|
|
|
if ($error_flag) |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
0
|
|
|
|
|
|
$return{'ERROR'} = 1; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
else |
|
167
|
|
|
|
|
|
|
{ |
|
168
|
0
|
|
|
|
|
|
$return{'ERROR'} = 0; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
0
|
|
|
|
|
|
return(\%return); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
### end argcheck ##################################################### |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
|
175
|
|
|
|
|
|
|
__END__ |