test_url.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_HTTPURL_H
  23. #define _TEST_HTTPURL_H
  24. #include "tinyhttp/parsers/thttp_parser_url.h"
  25. const char* urls[] = {
  26. //== HTTP:
  27. "http://www.doubango.org",
  28. "http://www.doubango.org/?p=1",
  29. "http://doubango.org:452/test",
  30. "http://doubango.org:45/test?p=452",
  31. //== HTTPS:
  32. "https://www.doubango.org",
  33. "https://www.doubango.org/?p=1",
  34. "https://doubango.org:452/test",
  35. "https://doubango.org:45/test?p=452",
  36. };
  37. #include "tsk_string.h"
  38. void test_url_tostring(const thttp_url_t *url)
  39. {
  40. char* ret = thttp_url_tostring(url);
  41. TSK_DEBUG_INFO("url_to_string=%s", ret);
  42. TSK_FREE(ret);
  43. }
  44. void test_url_parser()
  45. {
  46. int i;
  47. for(i=0; i<sizeof(urls)/sizeof(const char*); i++) {
  48. thttp_url_t *url = thttp_url_parse(urls[i], strlen(urls[i]));
  49. printf("\n== Parsing {{ %s }} ==\n\n", urls[i]);
  50. if(url) {
  51. printf("scheme: %s\n", url->scheme);
  52. printf("host: %s\n", url->host);
  53. printf("port: %u\n", url->port);
  54. printf("hpath: %s\n", url->hpath);
  55. printf("search: %s\n", url->search);
  56. printf("host-type: %s\n", url->host_type == thttp_host_ipv4 ? "IPv4" : (url->host_type == thttp_host_ipv6 ? "IPv6" : (url->host_type == thttp_host_hostname ? "HOSTNAME" : "UNKNOWN")) );
  57. printf("---PARAMS---\n");
  58. printf("Is-secure: %s\n", THTTP_URL_IS_SECURE(url) ? "YES" : "NO");
  59. test_url_tostring(url);
  60. }
  61. else {
  62. printf("INVALID HTTP URL.\n");
  63. }
  64. printf("\n\n");
  65. getchar();
  66. TSK_OBJECT_SAFE_FREE(url);
  67. }
  68. }
  69. void test_url()
  70. {
  71. test_url_parser();
  72. }
  73. #endif /* _TEST_HTTPURL_H */