- Timestamp:
- Sep 27, 2010 8:35:08 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c
r3262 r3321 238 238 239 239 240 pj_status_t parse_url(const char *url )240 pj_status_t parse_url(const char *url, pj_http_url *hurl) 241 241 { 242 242 pj_str_t surl; 243 pj_http_url hurl;244 243 pj_status_t status; 245 244 246 245 pj_cstr(&surl, url); 247 status = pj_http_req_parse_url(&surl, &hurl);246 status = pj_http_req_parse_url(&surl, hurl); 248 247 #ifdef VERBOSE 249 248 if (!status) { 250 249 printf("URL: %s\nProtocol: %.*s\nHost: %.*s\nPort: %d\nPath: %.*s\n\n", 251 url, STR_PREC(hurl .protocol), STR_PREC(hurl.host),252 hurl .port, STR_PREC(hurl.path));250 url, STR_PREC(hurl->protocol), STR_PREC(hurl->host), 251 hurl->port, STR_PREC(hurl->path)); 253 252 } else { 254 253 } … … 257 256 } 258 257 259 int parse_url_test() 260 { 261 /* Simple URL without '/' in the end */ 262 if (parse_url("http://www.google.com.sg") != PJ_SUCCESS) 263 return -11; 264 /* Simple URL with port number but without '/' in the end */ 265 if (parse_url("http://www.example.com:8080") != PJ_SUCCESS) 266 return -13; 267 /* URL with path */ 268 if (parse_url("http://127.0.0.1:280/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6") 269 != PJ_SUCCESS) 270 return -15; 271 /* URL with port and path */ 272 if (parse_url("http://teluu.com:81/about-us/") != PJ_SUCCESS) 273 return -17; 274 /* unsupported protocol */ 275 if (parse_url("ftp://www.teluu.com") != PJ_ENOTSUP) 276 return -19; 277 /* invalid format */ 278 if (parse_url("http:/teluu.com/about-us/") != PJLIB_UTIL_EHTTPINURL) 279 return -21; 280 /* invalid port number */ 281 if (parse_url("http://teluu.com:xyz/") != PJLIB_UTIL_EHTTPINPORT) 282 return -23; 258 static int parse_url_test() 259 { 260 struct test_data 261 { 262 char *url; 263 pj_status_t result; 264 const char *username; 265 const char *passwd; 266 const char *host; 267 int port; 268 const char *path; 269 } test_data[] = 270 { 271 /* Simple URL without '/' in the end */ 272 {"http://www.pjsip.org", PJ_SUCCESS, "", "", "www.pjsip.org", 80, "/"}, 273 274 /* Simple URL with port number but without '/' in the end */ 275 {"http://pjsip.org:8080", PJ_SUCCESS, "", "", "pjsip.org", 8080, "/"}, 276 277 /* URL with path */ 278 {"http://127.0.0.1:280/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6", 279 PJ_SUCCESS, "", "", "127.0.0.1", 280, 280 "/Joomla/index.php?option=com_content&task=view&id=5&Itemid=6"}, 281 282 /* URL with port and path */ 283 {"http://pjsip.org:81/about-us/", PJ_SUCCESS, "", "", "pjsip.org", 81, "/about-us/"}, 284 285 /* unsupported protocol */ 286 {"ftp://www.pjsip.org", PJ_ENOTSUP, "", "", "", 80, ""}, 287 288 /* invalid format */ 289 {"http:/pjsip.org/about-us/", PJLIB_UTIL_EHTTPINURL, "", "", "", 80, ""}, 290 291 /* invalid port number */ 292 {"http://pjsip.org:xyz/", PJLIB_UTIL_EHTTPINPORT, "", "", "", 80, ""}, 293 294 /* with username and password */ 295 {"http://user:pass@pjsip.org", PJ_SUCCESS, "user", "pass", "pjsip.org", 80, "/"}, 296 297 /* password only*/ 298 {"http://:pass@pjsip.org", PJ_SUCCESS, "", "pass", "pjsip.org", 80, "/"}, 299 300 /* user only*/ 301 {"http://user:@pjsip.org", PJ_SUCCESS, "user", "", "pjsip.org", 80, "/"}, 302 303 /* empty username and passwd*/ 304 {"http://:@pjsip.org", PJ_SUCCESS, "", "", "pjsip.org", 80, "/"}, 305 306 /* Invalid URL */ 307 {"http://:", PJ_EINVAL, "", "", "", 0, ""}, 308 309 /* Invalid URL */ 310 {"http://@", PJ_EINVAL, "", "", "", 0, ""}, 311 312 /* Invalid URL */ 313 {"http", PJ_EINVAL, "", "", "", 0, ""}, 314 315 /* Invalid URL */ 316 {"http:/", PJ_EINVAL, "", "", "", 0, ""}, 317 318 /* Invalid URL */ 319 {"http://", PJ_EINVAL, "", "", "", 0, ""}, 320 321 /* Invalid URL */ 322 {"http:///", PJ_EINVAL, "", "", "", 0, ""}, 323 324 /* Invalid URL */ 325 {"http://@/", PJ_EINVAL, "", "", "", 0, ""}, 326 327 /* Invalid URL */ 328 {"http://:::", PJ_EINVAL, "", "", "", 0, ""}, 329 }; 330 unsigned i; 331 332 for (i=0; i<PJ_ARRAY_SIZE(test_data); ++i) { 333 struct test_data *ptd; 334 pj_http_url hurl; 335 pj_status_t status; 336 337 ptd = &test_data[i]; 338 339 PJ_LOG(3, (THIS_FILE, ".. %s", ptd->url)); 340 status = parse_url(ptd->url, &hurl); 341 342 if (status != ptd->result) { 343 PJ_LOG(3,(THIS_FILE, "%d", status)); 344 return -11; 345 } 346 if (status != PJ_SUCCESS) 347 continue; 348 if (pj_strcmp2(&hurl.username, ptd->username)) 349 return -12; 350 if (pj_strcmp2(&hurl.passwd, ptd->passwd)) 351 return -13; 352 if (pj_strcmp2(&hurl.host, ptd->host)) 353 return -14; 354 if (hurl.port != ptd->port) 355 return -15; 356 if (pj_strcmp2(&hurl.path, ptd->path)) 357 return -16; 358 } 283 359 284 360 return 0;
Note: See TracChangeset
for help on using the changeset viewer.