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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "apr_general.h"
#include "apr_uri.h"
struct aup_test {
const char *uri;
apr_status_t rv;
const char *scheme;
const char *hostinfo;
const char *user;
const char *password;
const char *hostname;
const char *port_str;
const char *path;
const char *query;
const char *fragment;
apr_port_t port;
};
struct aup_test aup_tests[] =
{
{ "http://[/::1]/index.html", APR_EGENERAL },
{ "http://[", APR_EGENERAL },
{ "http://[?::1]/index.html", APR_EGENERAL },
{
"http://127.0.0.1:9999/asdf.html",
0, "http", "127.0.0.1:9999", NULL, NULL, "127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
},
{
"http://127.0.0.1:9999a/asdf.html",
APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
},
{
"http://[::127.0.0.1]:9999/asdf.html",
0, "http", "[::127.0.0.1]:9999", NULL, NULL, "::127.0.0.1", "9999", "/asdf.html", NULL, NULL, 9999
},
{
"http://[::127.0.0.1]:9999a/asdf.html",
APR_EGENERAL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0
},
{
"/error/include/top.html",
0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/top.html", NULL, NULL, 0
},
{
"/error/include/../contact.html.var",
0, NULL, NULL, NULL, NULL, NULL, NULL, "/error/include/../contact.html.var", NULL, NULL, 0
},
{
"/",
0, NULL, NULL, NULL, NULL, NULL, NULL, "/", NULL, NULL, 0
},
{
"/manual/",
0, NULL, NULL, NULL, NULL, NULL, NULL, "/manual/", NULL, NULL, 0
},
{
"/cocoon/developing/graphics/Using%20Databases-label_over.jpg",
0, NULL, NULL, NULL, NULL, NULL, NULL, "/cocoon/developing/graphics/Using%20Databases-label_over.jpg", NULL, NULL, 0
},
{
"http://sonyamt:garbage@127.0.0.1/filespace/",
0, "http", "sonyamt:garbage@127.0.0.1", "sonyamt", "garbage", "127.0.0.1", NULL, "/filespace/", NULL, NULL, 0
},
{
"http://sonyamt:garbage@[fe80::1]/filespace/",
0, "http", "sonyamt:garbage@[fe80::1]", "sonyamt", "garbage", "fe80::1", NULL, "/filespace/", NULL, NULL, 0
},
{
"http://sonyamt@[fe80::1]/filespace/?arg1=store",
0, "http", "sonyamt@[fe80::1]", "sonyamt", NULL, "fe80::1", NULL, "/filespace/", "arg1=store", NULL, 0
}
};
struct uph_test {
const char *hostinfo;
apr_status_t rv;
const char *hostname;
const char *port_str;
apr_port_t port;
};
struct uph_test uph_tests[] =
{
{
"www.ibm.com:443",
0, "www.ibm.com", "443", 443
},
{
"[fe80::1]:443",
0, "fe80::1", "443", 443
},
{
"127.0.0.1:443",
0, "127.0.0.1", "443", 443
},
{
"127.0.0.1",
APR_EGENERAL, NULL, NULL, 0
},
{
"[fe80:80",
APR_EGENERAL, NULL, NULL, 0
},
{
"fe80::80]:443",
APR_EGENERAL, NULL, NULL, 0
}
};
static void show_info(apr_status_t rv, apr_status_t expected, const apr_uri_t *info)
{
if (rv != expected) {
fprintf(stderr, " actual rv: %d expected rv: %d\n", rv, expected);
}
else {
fprintf(stderr,
" scheme: %s\n"
" hostinfo: %s\n"
" user: %s\n"
" password: %s\n"
" hostname: %s\n"
" port_str: %s\n"
" path: %s\n"
" query: %s\n"
" fragment: %s\n"
" hostent: %p\n"
" port: %u\n"
" is_initialized: %u\n"
" dns_looked_up: %u\n"
" dns_resolved: %u\n",
info->scheme, info->hostinfo, info->user, info->password,
info->hostname, info->port_str, info->path, info->query,
info->fragment, info->hostent, info->port, info->is_initialized,
info->dns_looked_up, info->dns_resolved);
}
}
static int same_str(const char *s1, const char *s2)
{
if (s1 == s2) { /* e.g., NULL and NULL */
return 1;
}
else if (!s1 || !s2) { /* only 1 is NULL */
return 0;
}
else {
return strcmp(s1, s2) == 0;
}
}
static int test_aup(apr_pool_t *p)
{
int i;
apr_status_t rv;
apr_uri_t info;
struct aup_test *t;
const char *failed;
int rc = 0;
for (i = 0; i < sizeof(aup_tests) / sizeof(aup_tests[0]); i++) {
memset(&info, 0, sizeof(info));
t = &aup_tests[i];
rv = apr_uri_parse(p, t->uri, &info);
failed = (rv != t->rv) ? "bad rc" : NULL;
if (!failed && t->rv == APR_SUCCESS) {
if (!same_str(info.scheme, t->scheme))
failed = "bad scheme";
if (!same_str(info.hostinfo, t->hostinfo))
failed = "bad hostinfo";
if (!same_str(info.user, t->user))
failed = "bad user";
if (!same_str(info.password, t->password))
failed = "bad password";
if (!same_str(info.hostname, t->hostname))
failed = "bad hostname";
if (!same_str(info.port_str, t->port_str))
failed = "bad port_str";
if (!same_str(info.path, t->path))
failed = "bad path";
if (!same_str(info.query, t->query))
failed = "bad query";
if (!same_str(info.fragment, t->fragment))
failed = "bad fragment";
if (info.port != t->port)
failed = "bad port";
}
if (failed) {
++rc;
fprintf(stderr, "failure for testcase %d/uri %s: %s\n", i,
t->uri, failed);
show_info(rv, t->rv, &info);
}
else if (t->rv == APR_SUCCESS) {
const char *s = apr_uri_unparse(p, &info,
APR_URI_UNP_REVEALPASSWORD);
if (strcmp(s, t->uri)) {
fprintf(stderr, "apr_uri_unparsed failed for testcase %d\n", i);
fprintf(stderr, " got %s, expected %s\n", s, t->uri);
}
}
}
return rc;
}
static int test_uph(apr_pool_t *p)
{
int i;
apr_status_t rv;
apr_uri_t info;
struct uph_test *t;
const char *failed;
int rc = 0;
for (i = 0; i < sizeof(uph_tests) / sizeof(uph_tests[0]); i++) {
memset(&info, 0, sizeof(info));
t = &uph_tests[i];
rv = apr_uri_parse_hostinfo(p, t->hostinfo, &info);
failed = (rv != t->rv) ? "bad rc" : NULL;
if (!failed && t->rv == APR_SUCCESS) {
if (!same_str(info.hostname, t->hostname))
failed = "bad hostname";
if (!same_str(info.port_str, t->port_str))
failed = "bad port_str";
if (info.port != t->port)
failed = "bad port";
}
if (failed) {
++rc;
fprintf(stderr, "failure for testcase %d/hostinfo %s: %s\n", i,
t->hostinfo, failed);
show_info(rv, t->rv, &info);
}
}
return rc;
}
int main(void)
{
apr_pool_t *pool;
int rc;
apr_initialize();
atexit(apr_terminate);
apr_pool_create(&pool, NULL);
rc = test_aup(pool);
if (!rc) {
rc = test_uph(pool);
}
return rc;
}
|