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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
-
|
|
!
-
-
|
-
|
!
!
-
|
|
!
-
|
-
|
!
|
!
-
|
|
|
!
| #ifndef __CGI_MODULE__
#define __CGI_MODULE__
#include "mod_getenv.as"
#include "form_decode.as"
#module "cgi"
#uselib "user32.dll"
#func tolower_ "CharLowerBuffA" var, int
#define def_env_val(%1,%2) env(%1) = "" : getenv env(%1), %2
#enum QUERY_TYPE_GET = 0
#enum QUERY_TYPE_POST
#enum global PATH_INFO = 0
#enum global PATH_TRANSLATED
#enum global QUERY_STRING
#enum global REDIRECT_URL
#enum global REMOTE_ADDR
#enum global REMOTE_PORT
#enum global REQUEST_METHOD
#enum global REQUEST_URI
#enum global SCRIPT_FILENAME
#enum global SCRIPT_NAME
#enum global SERVER_ADDR
#enum global SERVER_ADMIN
#enum global SERVER_NAME
#enum global SERVER_PORT
#enum global SERVER_PROTOCOL
#enum global SERVER_SIGNATURE
#enum global SERVER_SOFTWARE
#enum global DOCUMENT_ROOT
#enum global GATEWAY_INTERFACE
#defcfunc tolower@cgi str s, local tmp
tmp = s
tolower_@cgi tmp, strlen(tmp)
return tmp
#deffunc split_get_or_post@cgi var data, int type, local n, local s, local p
n = 0
repeat strlen(data)
getstr s, data, cnt, '&', 512*1024
p = strsize
memexpand name(type,n), strsize + 1 : getstr name(type,n), s, 0, '=', 512*1024
memexpand value(type,n),strsize + 1 : getstr value(type,n),s, strsize, '=', 512*1024
n++
continue cnt + p
loop
return
#deffunc init_mod_cgi local s
sdim name, 64,2,1
sdim value,64,2,1
sdim env, 260, 1
def_env_val PATH_INFO, "PATH_INFO"
def_env_val PATH_TRANSLATED, "PATH_TRANSLATED"
def_env_val QUERY_STRING, "QUERY_STRING"
def_env_val REDIRECT_URL, "REDIRECT_URL"
def_env_val REMOTE_ADDR, "REMOTE_ADDR"
def_env_val REMOTE_PORT, "REMOTE_PORT"
def_env_val REQUEST_METHOD, "REQUEST_METHOD"
def_env_val REQUEST_URI, "REQUEST_URI"
def_env_val SCRIPT_FILENAME, "SCRIPT_FILENAME"
def_env_val SCRIPT_NAME, "SCRIPT_NAME"
def_env_val SERVER_ADDR, "SERVER_ADDR"
def_env_val SERVER_ADMIN, "SERVER_ADMIN"
def_env_val SERVER_NAME, "SERVER_NAME"
def_env_val SERVER_PORT, "SERVER_PORT"
def_env_val SERVER_PROTOCOL, "SERVER_PROTOCOL"
def_env_val SERVER_SIGNATURE, "SERVER_SIGNATURE"
def_env_val SERVER_SOFTWARE, "SERVER_SOFTWARE"
def_env_val DOCUMENT_ROOT, "DOCUMENT_ROOT"
def_env_val GATEWAY_INTERFACE, "GATEWAY_INTERFACE"
split_get_or_post@cgi ENV(QUERY_STRING), QUERY_TYPE_GET
input s, 64*1024
split_get_or_post@cgi s, QUERY_TYPE_POST
header_put = 0
header = ""
return
#defcfunc cgi_get_query_string@cgi int type, str _name, int decode, local s
idx = -1
repeat length2( name )
if _name = name(type, cnt) {
idx = cnt
break
}
loop
s = ""
if 0 <= idx {
if decode {
form_decode s, value(type, idx), 2
} else {
s = value(type, idx)
}
}
return s
#define global ctype cgi_get_param(%1,%2=0) cgi_get_query_string@cgi(QUERY_TYPE_GET@cgi, %1, %2)
#define global ctype cgi_post_param(%1,%2=0) cgi_get_query_string@cgi(QUERY_TYPE_POST@cgi, %1, %2)
#defcfunc cgi_dirname str path, local s
s = path
len = strlen(path)
repeat len
c = peek(s, len - cnt - 1)
if '\\' == c || '/' == c {
s = strmid(s, 0, len - cnt - 1)
break
}
loop
return s
#define global ctype cgi_basename(%1,%2="") cgi_basename_@cgi(%1, %2)
#defcfunc cgi_basename_@cgi str path, str ext, local s
s = path
len = strlen(path)
repeat len
c = peek(s, len - cnt - 1)
if '\\' == c || '/' == c {
s = strmid(s, len - cnt, len)
if tolower( strmid(s, -1, strlen(ext)) ) == tolower( ext ) {
s = strmid(s, 0, strlen(s) - strlen(ext))
}
break
}
loop
return s
#deffunc cgi_header str data
if header_put : return
header += data + "\n"
return
#undef mes
#deffunc mes str s
if 0 == header_put {
if "" = header : header = "Content-type: text/html\n"
mes@hsp header + "\n"
header_put = 1
}
mes@hsp s
return
#global
init_mod_cgi
#endif
|