1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
define SZ_QUERY 2048
# T_CGIPARSE -- Parse the CGI QUERY_STRING environment variable.
# The string is expected to be a set of task.param=value pairs.
# The task parameter values are set.
procedure t_cgiparse ()
char c, hex[2]
int i
long hexval
pointer sp, str, par, val
pointer ip, op
int envfind(), gctol()
begin
call smark (sp)
call salloc (str, SZ_QUERY, TY_CHAR)
call salloc (par, SZ_LINE, TY_CHAR)
call salloc (val, SZ_LINE, TY_CHAR)
# Get the query string. If there isn't one then do nothing.
if (envfind ("QUERY_STRING", Memc[str], SZ_QUERY) <= 0)
return
# Parse the query string into parameters and values.
# For each pair set the task parameter.
op = par
for (ip=str;; ip=ip+1) {
c = Memc[ip]
switch (c) {
case '&', EOS: # End of parameter=value
Memc[op] = EOS
call cgi_setpar (Memc[par], Memc[val])
if (c == EOS)
break
Memc[par] = EOS
Memc[val] = EOS
op = par
next
case '=': # Separator between parameters and value
Memc[op] = EOS
op = val
next
case '+': # Space character
c = ' '
case '%': # Special characters in hex
call strcpy (Memc[ip+1], hex, 2)
i = 1
if (gctol (hex, i, hexval, 16) > 0) {
c = hexval
ip = ip + 2
}
}
Memc[op] = c
op = op + 1
}
call sfree (sp)
end
# CGI_SETPAR -- Set parameter value.
# There is no error check for undefined tasks or parameters.
# Values of the wrong type are ignored.
procedure cgi_setpar (param, val)
char param[ARB] #I Task parameter
char val[ARB] #I Value string
bool bval, streq()
int ival, ip, ctoi(), ctod()
double dval
pointer sp, str, type
begin
call smark (sp)
call salloc (str, SZ_LINE, TY_CHAR)
call salloc (type, 10, TY_CHAR)
# Determine if parameter type.
call sprintf (Memc[str], SZ_LINE, "%s.p_type")
call pargstr (param)
call clgstr (Memc[str], Memc[type], 10)
# Set parameter in the approriate type.
ip = 1
switch (Memc[type]) {
case 'i':
if (ctoi (val, ip, ival) > 0)
call clputi (param, ival)
case 'r':
if (ctod (val, ip, dval) > 0)
call clputd (param, dval)
case 'b':
if (streq (val, "no") || streq (val, "yes")) {
bval = streq (val, "yes")
call clputb (param, bval)
}
default:
call clpstr (param, val)
}
call sfree (sp)
end
|