test_stack.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 Lesser 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_STACK_H_
  23. #define _TEST_STACK_H_
  24. int test_stack_callback(const thttp_event_t *httpevent)
  25. {
  26. thttp_session_id_t id = thttp_session_get_id(httpevent->session);
  27. switch(httpevent->type) {
  28. case thttp_event_message: { /* New HTTP message */
  29. TSK_DEBUG_INFO("sid=%llu", id);
  30. if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)) {
  31. const thttp_header_ETag_t* etag;
  32. TSK_DEBUG_INFO("=== %d ==> %s", THTTP_RESPONSE_CODE(httpevent->message), THTTP_MESSAGE_CONTENT(httpevent->message));
  33. // You can use
  34. if((etag = (const thttp_header_ETag_t*)thttp_message_get_header(httpevent->message, thttp_htype_ETag))) {
  35. TSK_DEBUG_INFO("Etag=%s", etag->value);
  36. }
  37. }
  38. else {
  39. if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)) {
  40. TSK_DEBUG_INFO("=== code ==> %u", THTTP_RESPONSE_CODE(httpevent->message));
  41. }
  42. }
  43. break;
  44. }
  45. case thttp_event_auth_failed: {
  46. TSK_DEBUG_INFO("auth failed sid=%llu", id);
  47. break;
  48. }
  49. case thttp_event_closed: { /* HTTP connection closed (informational) */
  50. TSK_DEBUG_INFO("closed sid=%llu", id);
  51. break;
  52. }
  53. case thttp_event_transport_error: { /* HTTP connection closed (informational) */
  54. TSK_DEBUG_INFO("Transport sid=%llu", id);
  55. break;
  56. }
  57. }
  58. return 0;
  59. }
  60. #define PAYLOAD "<entry uri=\"sip:samba@micromethod.com\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
  61. "<display-name>samba</display-name>" \
  62. "</entry>"
  63. void test_stack()
  64. {
  65. thttp_session_handle_t *session = tsk_null;
  66. int ret;
  67. thttp_stack_handle_t* stack = thttp_stack_create(test_stack_callback,
  68. THTTP_STACK_SET_TLS_ENABLED(tsk_true),
  69. //THTTP_STACK_SET_TLS_CERTS_VERIFY(tsk_false),
  70. //THTTP_STACK_SET_LOCAL_IP("0.0.0.0"),
  71. //THTTP_STACK_SET_LOCAL_PORT(8080),
  72. //THTTP_STACK_SET_PROXY("msp.f-secure.com", 443),
  73. THTTP_STACK_SET_NULL());
  74. if((ret = thttp_stack_start(stack))) {
  75. TSK_DEBUG_ERROR("Failed to start the HTTP/HTTPS stack.");
  76. goto bail;
  77. }
  78. // http://ipv6.google.com/
  79. //op = THTTP_OPERATION_CREATE(stack,
  80. // THTTP_OPERATION_SET_PARAM("method", "GET"),
  81. // THTTP_OPERATION_SET_PARAM("URL", "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index"),
  82. //
  83. // THTTP_OPERATION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  84. // THTTP_OPERATION_SET_HEADER("Pragma", "No-Cache"),
  85. // THTTP_OPERATION_SET_HEADER("Connection", "Keep-Alive"),
  86. // THTTP_OPERATION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
  87. // THTTP_OPERATION_SET_HEADER("X-3GPP-Intended-Identity", "sip:mercuro1@doubango.org"),
  88. //
  89. // THTTP_OPERATION_SET_NULL());
  90. //thttp_operation_perform(op);
  91. /* creates session */
  92. session = thttp_session_create(stack,
  93. // session-level options
  94. THTTP_SESSION_SET_OPTION(THTTP_SESSION_OPTION_TIMEOUT, "6000"),
  95. // session-level headers
  96. THTTP_SESSION_SET_HEADER("Pragma", "No-Cache"),
  97. THTTP_SESSION_SET_HEADER("Connection", "Keep-Alive"),
  98. // THTTP_SESSION_SET_HEADER("Connection", "close"),
  99. THTTP_SESSION_SET_HEADER("User-Agent", "doubango 1.0"),
  100. THTTP_SESSION_SET_NULL()); /* MUST always be present */
  101. //ret = thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
  102. // THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  103. //
  104. // tsk_null);
  105. //getchar();
  106. //thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
  107. // THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  108. //
  109. // tsk_null);
  110. //getchar();
  111. // HTTPS
  112. thttp_action_GET(session, "https://msp.f-secure.com/web-test/common/test.html",
  113. // action-level options
  114. THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
  115. // action-level headers
  116. THTTP_ACTION_SET_HEADER("User-Agent", "Doubango"),
  117. THTTP_ACTION_SET_HEADER("Connection", "Keep-Alive"),
  118. THTTP_ACTION_SET_NULL());
  119. getchar();
  120. // IPv6
  121. /*thttp_action_GET(session, "http://ipv6.google.com",
  122. // action-level options
  123. THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
  124. // action-level headers
  125. THTTP_ACTION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
  126. THTTP_ACTION_SET_HEADER("Connection", "Keep-Alive"),
  127. THTTP_ACTION_SET_NULL());
  128. getchar();*/
  129. /*ret = thttp_action_GET(session, "http://doubango.org",
  130. // action-level options
  131. THTTP_ACTION_SET_OPTION(THTTP_ACTION_OPTION_TIMEOUT, "2500"),
  132. THTTP_ACTION_SET_NULL());
  133. getchar();*/
  134. //thttp_action_GET(session, "http://www.google.com",
  135. //THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  136. // THTTP_ACTION_SET_NULL());
  137. //thttp_action_GET(session, "http://www.doubango.org",
  138. // THTTP_ACTION_SET_NULL());
  139. /* Gets resource-lists document */
  140. /*thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/index",
  141. THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  142. tsk_null);
  143. getchar();*/
  144. //TSK_OBJECT_SAFE_FREE(session);
  145. //getchar();
  146. /* Gets xcap-caps document */
  147. /*thttp_action_GET(session, "http://siptest.doubango.org:8080/services/xcap-caps/global/index",
  148. THTTP_ACTION_SET_HEADER("Content-Type", "application/xcap-caps+xml"),
  149. tsk_null);
  150. getchar();*/
  151. /*thttp_action_GET(session, "http://siptest.doubango.org:8080/services/resource-lists/users/sip:mercuro1@doubango.org/properties-resource-list.xml",
  152. THTTP_ACTION_SET_HEADER("Content-Type", "application/resource-lists+xml"),
  153. tsk_null);
  154. getchar();*/
  155. //thttp_operation_perform(op);
  156. /*
  157. op = THTTP_OPERATION_CREATE(stack,
  158. THTTP_OPERATION_SET_PARAM("method", "GET"),
  159. //THTTP_OPERATION_SET_PARAM("URL", "https://msp.f-secure.com/web-test/common/test.html"),
  160. THTTP_OPERATION_SET_PARAM("URL", "http://www.doubango.org"),
  161. THTTP_OPERATION_SET_HEADER("Pragma", "No-Cache"),
  162. THTTP_OPERATION_SET_HEADER("Connection", "Keep-Alive"),
  163. THTTP_OPERATION_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
  164. THTTP_OPERATION_SET_NULL());
  165. thttp_operation_perform(op);
  166. */
  167. /*thttp_operation_set(op,
  168. THTTP_OPERATION_SET_PARAM("method", "HEAD"),
  169. THTTP_OPERATION_SET_NULL());
  170. thttp_operation_perform(op);*/
  171. getchar();
  172. bail:
  173. TSK_OBJECT_SAFE_FREE(session);
  174. TSK_OBJECT_SAFE_FREE(stack);
  175. }
  176. #endif /* _TEST_STACK_H_ */