test_stack.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. #define PAYLOAD_LIST "<list name=\"newlist\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
  25. "<display-name>newlist</display-name>" \
  26. "</list>"
  27. #define PAYLOAD_ENTRY "<entry uri=\""XUI"\" xmlns=\"urn:ietf:params:xml:ns:resource-lists\">" \
  28. "<display-name>"XUI"</display-name>" \
  29. "</entry>"
  30. int test_stack_callback(const thttp_event_t *httpevent)
  31. {
  32. switch(httpevent->type) {
  33. case thttp_event_message: { /* New HTTP message */
  34. if(THTTP_MESSAGE_IS_RESPONSE(httpevent->message)) {
  35. const thttp_header_ETag_t* etag;
  36. TSK_DEBUG_INFO("=== %d ==> %s", THTTP_RESPONSE_CODE(httpevent->message), THTTP_MESSAGE_CONTENT(httpevent->message));
  37. // You can use
  38. if((etag = (const thttp_header_ETag_t*)thttp_message_get_header(httpevent->message, thttp_htype_ETag))) {
  39. TSK_DEBUG_INFO("Etag=%s", etag->value);
  40. }
  41. }
  42. else {
  43. }
  44. break;
  45. }
  46. case thttp_event_auth_failed: {
  47. TSK_DEBUG_INFO("=== auth failed.");
  48. break;
  49. }
  50. case thttp_event_closed: { /* HTTP connection closed (informational) */
  51. TSK_DEBUG_INFO("=== closed.");
  52. break;
  53. }
  54. default: {
  55. break;
  56. }
  57. }
  58. return 0;
  59. }
  60. void test_stack()
  61. {
  62. txcap_stack_handle_t* stack = tsk_null;
  63. int ret;
  64. stack = txcap_stack_create(test_stack_callback, XUI, PASSWORD, XCAP_ROOT,
  65. #if defined(ANDROID)
  66. TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_LOCAL_IP, "10.0.2.15"),
  67. #endif
  68. // stack-level options
  69. TXCAP_STACK_SET_OPTION(TXCAP_STACK_OPTION_TIMEOUT, "6000"),
  70. // stack-level headers
  71. TXCAP_STACK_SET_HEADER("Connection", "Keep-Alive"),
  72. TXCAP_STACK_SET_HEADER("User-Agent", "XDM-client/OMA1.1"),
  73. TXCAP_STACK_SET_HEADER("X-3GPP-Intended-Identity", XUI),
  74. TXCAP_STACK_SET_NULL());
  75. if((ret = txcap_stack_start(stack))) {
  76. goto bail;
  77. }
  78. /* add user auids */
  79. txcap_stack_set(stack,
  80. // add new AUIDs
  81. TXCAP_STACK_SET_AUID("xcap-caps2", "application/xcap-caps2+xml", "urn:ietf:params:xml:ns:xcap-caps2", "index2", tsk_true),
  82. TXCAP_STACK_SET_AUID("resource-lists2", "application/resource-lists+xml2", "urn:ietf:params:xml:ns:resource-lists2", "index2", tsk_false),
  83. TXCAP_STACK_SET_NULL()); /* mandatory */
  84. //== get xcap-caps document
  85. ret = txcap_action_fetch_document(stack,
  86. // action-level options
  87. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  88. // action-level headers
  89. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  90. // selector
  91. TXCAP_ACTION_SET_SELECTOR("xcap-caps",
  92. TXCAP_SELECTOR_NODE_SET_NULL()),
  93. // ends parameters
  94. TXCAP_ACTION_SET_NULL()
  95. );
  96. getchar();
  97. /*
  98. //== get resource-lists document
  99. ret = txcap_action_fetch_document(stack,
  100. // action-level options
  101. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  102. //action-level headers
  103. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  104. // selector
  105. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  106. TXCAP_SELECTOR_NODE_SET_NULL()),
  107. // ends parameters
  108. TXCAP_ACTION_SET_NULL()
  109. );
  110. getchar();
  111. //== get 'rcs' list
  112. ret = txcap_action_fetch_element(stack,
  113. // action-level options
  114. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  115. // action-level headers
  116. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  117. // selector
  118. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  119. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  120. TXCAP_SELECTOR_NODE_SET_NULL()),
  121. // ends parameters
  122. TXCAP_ACTION_SET_NULL()
  123. );
  124. getchar();
  125. //== Retrieve the 2nd list
  126. ret = txcap_action_fetch_element(stack,
  127. // action-level options
  128. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  129. // headers
  130. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  131. // action-level selector
  132. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  133. TXCAP_SELECTOR_NODE_SET_POS("list", 2),
  134. TXCAP_SELECTOR_NODE_SET_NULL()),
  135. // ends parameters
  136. TXCAP_ACTION_SET_NULL()
  137. );
  138. getchar();
  139. //== Retrieve the 4th list (wildcard)
  140. ret = txcap_action_fetch_element(stack,
  141. // action-level options
  142. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  143. // headers
  144. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  145. // action-level selector
  146. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  147. TXCAP_SELECTOR_NODE_SET_POS("*", 4),
  148. TXCAP_SELECTOR_NODE_SET_NULL()),
  149. // ends parameters
  150. TXCAP_ACTION_SET_NULL()
  151. );
  152. getchar();
  153. //== Retrieve the entry with: uri=XUI and list='rcs'
  154. ret = txcap_action_fetch_element(stack,
  155. // action-level options
  156. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  157. // headers
  158. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  159. // action-level selector
  160. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  161. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  162. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  163. TXCAP_SELECTOR_NODE_SET_NULL()),
  164. // ends parameters
  165. TXCAP_ACTION_SET_NULL()
  166. );
  167. getchar();
  168. //== Retrieve XUI's display-name ==> 404
  169. ret = txcap_action_fetch_attribute(stack,
  170. // action-level options
  171. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  172. // headers
  173. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  174. // action-level selector
  175. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  176. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  177. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  178. TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
  179. TXCAP_SELECTOR_NODE_SET_NULL()),
  180. // ends parameters
  181. TXCAP_ACTION_SET_NULL()
  182. );
  183. getchar();
  184. //== Retrieve the display-name of the fisrt entry from the 'rcs' list ==> 404
  185. ret = txcap_action_fetch_attribute(stack,
  186. // action-level options
  187. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  188. // headers
  189. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  190. // action-level selector
  191. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  192. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  193. TXCAP_SELECTOR_NODE_SET_POS("entry", 1),
  194. TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
  195. TXCAP_SELECTOR_NODE_SET_NULL()),
  196. // ends parameters
  197. TXCAP_ACTION_SET_NULL()
  198. );
  199. getchar();
  200. //== Retrieve the entry with: uri='XUI' from position 1 from 'rcs' list
  201. ret = txcap_action_fetch_element(stack,
  202. // action-level options
  203. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  204. // headers
  205. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  206. // action-level selector
  207. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  208. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  209. TXCAP_SELECTOR_NODE_SET_POS_ATTRIBUTE("entry", 1, "uri", XUI),
  210. TXCAP_SELECTOR_NODE_SET_NULL()),
  211. // ends parameters
  212. TXCAP_ACTION_SET_NULL()
  213. );
  214. getchar();
  215. //== Add newlist
  216. ret = txcap_action_create_element(stack,
  217. // selector
  218. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  219. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
  220. TXCAP_SELECTOR_NODE_SET_NULL()),
  221. // payload
  222. TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_LIST, strlen(PAYLOAD_LIST)),
  223. // ends parameters
  224. TXCAP_ACTION_SET_NULL()
  225. );
  226. getchar();
  227. //== Add entry
  228. ret = txcap_action_create_element(stack,
  229. // selector
  230. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  231. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
  232. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  233. TXCAP_SELECTOR_NODE_SET_NULL()),
  234. // payload
  235. TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_ENTRY, strlen(PAYLOAD_ENTRY)),
  236. // ends parameters
  237. TXCAP_ACTION_SET_NULL()
  238. );
  239. getchar();
  240. //== Add entry using dummy URI
  241. ret = txcap_action_create_element(stack,
  242. // dummy uri
  243. TXCAP_ACTION_SET_REQUEST_URI("http://doubango.org/services/dummy/"XUI),
  244. // payload
  245. TXCAP_ACTION_SET_PAYLOAD(PAYLOAD_ENTRY, strlen(PAYLOAD_ENTRY)),
  246. // ends parameters
  247. TXCAP_ACTION_SET_NULL()
  248. );
  249. getchar();
  250. //== Delete entry
  251. ret = txcap_action_delete_element(stack,
  252. // selector
  253. TXCAP_ACTION_SET_SELECTOR("resource-lists",
  254. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "newlist"),
  255. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  256. TXCAP_SELECTOR_NODE_SET_NULL()),
  257. // ends parameters
  258. TXCAP_ACTION_SET_NULL()
  259. );
  260. getchar();
  261. ret = txcap_action_fetch_document(stack,
  262. // action-level options
  263. TXCAP_ACTION_SET_OPTION(TXCAP_ACTION_OPTION_TIMEOUT, "6000"),
  264. //action-level headers
  265. TXCAP_ACTION_SET_HEADER("Pragma", "No-Cache"),
  266. // selector
  267. TXCAP_ACTION_SET_SELECTOR("org.openmobilealliance.pres-content",
  268. TXCAP_SELECTOR_NODE_SET_NULL()),
  269. // ends parameters
  270. TXCAP_ACTION_SET_NULL()
  271. );
  272. */
  273. bail:
  274. getchar();
  275. TSK_OBJECT_SAFE_FREE(stack);
  276. }
  277. #endif /* _TEST_STACK_H */