test_nua.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * This file is part of the Sofia-SIP package
  3. *
  4. * Copyright (C) 2005 Nokia Corporation.
  5. *
  6. * Contact: Pekka Pessi <pekka.pessi@nokia.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. /**@@internal
  25. * @file test_nua.h
  26. * @brief High-level tester framework for Sofia SIP User Agent Engine
  27. *
  28. * @author Pekka Pessi <Pekka.Pessi@nokia.com>
  29. * @author Martti Mela <Martti Mela@nokia.com>
  30. *
  31. * @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
  32. */
  33. #ifndef TEST_NUA_H
  34. #define TEST_NUA_H
  35. struct context;
  36. #define NUA_MAGIC_T struct context
  37. struct call;
  38. #define NUA_HMAGIC_T struct call
  39. #include "sofia-sip/nua.h"
  40. #include "sofia-sip/sip_status.h"
  41. #include <sofia-sip/sdp.h>
  42. #include <sofia-sip/sip_header.h>
  43. #include <sofia-sip/su_log.h>
  44. #include <sofia-sip/su_tagarg.h>
  45. #include <sofia-sip/su_tag_io.h>
  46. #include <sofia-sip/su_string.h>
  47. #include <sofia-sip/nua_tag.h>
  48. #if __APPLE_CC__
  49. #include <sofia-sip/su_osx_runloop.h>
  50. #endif
  51. #include "test_proxy.h"
  52. #include "test_nat.h"
  53. #include <sofia-sip/auth_module.h>
  54. #include <stddef.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <assert.h>
  58. #include <unistd.h>
  59. extern char const name[];
  60. extern int print_headings;
  61. extern int tstflags;
  62. #define TSTFLAGS tstflags
  63. #include <sofia-sip/tstdef.h>
  64. #define TEST_E(a, b) TEST_S(nua_event_name(a), nua_event_name(b))
  65. #define NONE ((void*)-1)
  66. struct endpoint;
  67. typedef
  68. int condition_function(nua_event_t event,
  69. int status, char const *phrase,
  70. nua_t *nua, struct context *ctx,
  71. struct endpoint *ep,
  72. nua_handle_t *nh, struct call *call,
  73. sip_t const *sip,
  74. tagi_t tags[]);
  75. typedef
  76. void printer_function(nua_event_t event,
  77. char const *operation,
  78. int status, char const *phrase,
  79. nua_t *nua, struct context *ctx,
  80. struct endpoint *ep,
  81. nua_handle_t *nh, struct call *call,
  82. sip_t const *sip,
  83. tagi_t tags[]);
  84. struct proxy_transaction;
  85. struct registration_entry;
  86. enum { event_is_extra, event_is_normal, event_is_special };
  87. struct eventlist
  88. {
  89. nua_event_t kind;
  90. struct event *head, **tail;
  91. };
  92. struct event
  93. {
  94. struct event *next, **prev;
  95. struct call *call;
  96. nua_saved_event_t saved_event[1];
  97. nua_event_data_t const *data;
  98. };
  99. struct context
  100. {
  101. su_home_t home[1];
  102. su_root_t *root;
  103. int threading, proxy_tests, expensive, quit_on_single_failure, osx_runloop;
  104. int print_tags;
  105. url_t *external_proxy;
  106. int proxy_logging;
  107. struct endpoint {
  108. char name[4];
  109. struct context *ctx; /* Backpointer */
  110. int logging;
  111. int print_tags;
  112. int running;
  113. struct domain *domain;
  114. condition_function *next_condition;
  115. nua_event_t next_event, last_event;
  116. nua_t *nua;
  117. sip_contact_t *contact;
  118. sip_from_t *to;
  119. sip_allow_t *allow;
  120. char const *appl_method;
  121. sip_supported_t *supported;
  122. printer_function *printer;
  123. char const *instance;
  124. /* Per-call stuff */
  125. struct call {
  126. struct call *next;
  127. nua_handle_t *nh;
  128. char const *sdp;
  129. struct eventlist *events;
  130. } call[1], reg[1];
  131. int (*is_special)(nua_event_t e);
  132. /* Normal events are saved here */
  133. struct eventlist events[1];
  134. /* Special events are saved here */
  135. struct eventlist specials[1];
  136. /* State flags for complex scenarios */
  137. struct {
  138. unsigned n;
  139. unsigned bit0:1, bit1:1, bit2:1, bit3:1;
  140. unsigned bit4:1, bit5:1, bit6:1, bit7:1;
  141. unsigned :0;
  142. } flags;
  143. /* Accross-run state information */
  144. struct {
  145. unsigned n;
  146. } state;
  147. } a, b, c;
  148. struct proxy *p;
  149. sip_route_t const *lr;
  150. struct nat *nat;
  151. };
  152. #define RETURN_ON_SINGLE_FAILURE(retval) \
  153. do { \
  154. fflush(stdout); \
  155. if (retval && ctx->quit_on_single_failure) { return retval; } \
  156. } while(0)
  157. int save_event_in_list(struct context *,
  158. nua_event_t nevent,
  159. struct endpoint *,
  160. struct call *);
  161. void free_events_in_list(struct context *,
  162. struct eventlist *);
  163. void free_event_in_list(struct context *ctx,
  164. struct eventlist *list,
  165. struct event *e);
  166. struct event *event_by_type(struct event *e, nua_event_t);
  167. size_t count_events(struct event const *e);
  168. #define CONDITION_PARAMS \
  169. nua_event_t event, \
  170. int status, char const *phrase, \
  171. nua_t *nua, struct context *ctx, \
  172. struct endpoint *ep, \
  173. nua_handle_t *nh, struct call *call, \
  174. sip_t const *sip, \
  175. tagi_t tags[]
  176. int save_events(CONDITION_PARAMS);
  177. int until_final_response(CONDITION_PARAMS);
  178. int save_until_final_response(CONDITION_PARAMS);
  179. int save_until_received(CONDITION_PARAMS);
  180. int save_until_special(CONDITION_PARAMS);
  181. int until_terminated(CONDITION_PARAMS);
  182. int until_ready(CONDITION_PARAMS);
  183. int accept_call(CONDITION_PARAMS);
  184. int cancel_when_ringing(CONDITION_PARAMS);
  185. int accept_notify(CONDITION_PARAMS);
  186. void a_callback(nua_event_t event,
  187. int status, char const *phrase,
  188. nua_t *nua, struct context *ctx,
  189. nua_handle_t *nh, struct call *call,
  190. sip_t const *sip,
  191. tagi_t tags[]);
  192. void b_callback(nua_event_t event,
  193. int status, char const *phrase,
  194. nua_t *nua, struct context *ctx,
  195. nua_handle_t *nh, struct call *call,
  196. sip_t const *sip,
  197. tagi_t tags[]);
  198. void c_callback(nua_event_t event,
  199. int status, char const *phrase,
  200. nua_t *nua, struct context *ctx,
  201. nua_handle_t *nh, struct call *call,
  202. sip_t const *sip,
  203. tagi_t tags[]);
  204. void run_abc_until(struct context *ctx,
  205. nua_event_t a_event, condition_function *a_condition,
  206. nua_event_t b_event, condition_function *b_condition,
  207. nua_event_t c_event, condition_function *c_condition);
  208. void run_ab_until(struct context *ctx,
  209. nua_event_t a_event, condition_function *a_condition,
  210. nua_event_t b_event, condition_function *b_condition);
  211. void run_bc_until(struct context *ctx,
  212. nua_event_t b_event, condition_function *b_condition,
  213. nua_event_t c_event, condition_function *c_condition);
  214. int run_a_until(struct context *, nua_event_t, condition_function *);
  215. int run_b_until(struct context *, nua_event_t, condition_function *);
  216. int run_c_until(struct context *, nua_event_t, condition_function *);
  217. typedef int operation_f(struct endpoint *ep, struct call *call,
  218. nua_handle_t *nh, tag_type_t tag, tag_value_t value,
  219. ...);
  220. operation_f INVITE, ACK, BYE, CANCEL, AUTHENTICATE, UPDATE, INFO, PRACK,
  221. REFER, MESSAGE, METHOD, OPTIONS, PUBLISH, UNPUBLISH, REGISTER, UNREGISTER,
  222. SUBSCRIBE, UNSUBSCRIBE, NOTIFY, NOTIFIER, TERMINATE, AUTHORIZE;
  223. int RESPOND(struct endpoint *ep,
  224. struct call *call,
  225. nua_handle_t *nh,
  226. int status, char const *phrase,
  227. tag_type_t tag, tag_value_t value,
  228. ...);
  229. int DESTROY(struct endpoint *ep,
  230. struct call *call,
  231. nua_handle_t *nh);
  232. struct call *check_handle(struct endpoint *ep,
  233. struct call *call,
  234. nua_handle_t *nh,
  235. int status, char const *phrase);
  236. int is_special(nua_event_t e);
  237. int callstate(tagi_t const *tags);
  238. int is_offer_sent(tagi_t const *tags);
  239. int is_answer_sent(tagi_t const *tags);
  240. int is_offer_recv(tagi_t const *tags);
  241. int is_answer_recv(tagi_t const *tags);
  242. int is_offer_answer_done(tagi_t const *tags);
  243. int audio_activity(tagi_t const *tags);
  244. int video_activity(tagi_t const *tags);
  245. void print_event(nua_event_t event,
  246. char const *operation,
  247. int status, char const *phrase,
  248. nua_t *nua, struct context *ctx,
  249. struct endpoint *ep,
  250. nua_handle_t *nh, struct call *call,
  251. sip_t const *sip,
  252. tagi_t tags[]);
  253. su_inline
  254. void eventlist_init(struct eventlist *list)
  255. {
  256. list->tail = &list->head;
  257. }
  258. su_inline
  259. void call_init(struct call *call)
  260. {
  261. }
  262. void endpoint_init(struct context *ctx, struct endpoint *e, char id);
  263. int test_nua_init(struct context *ctx,
  264. int start_proxy,
  265. url_t const *o_proxy,
  266. int start_nat,
  267. tag_type_t tag, tag_value_t value, ...);
  268. int test_deinit(struct context *ctx);
  269. int test_nua_api_errors(struct context *ctx);
  270. int test_nua_destroy(struct context *ctx);
  271. int test_stack_errors(struct context *ctx);
  272. int test_tag_filter(void);
  273. int test_nua_params(struct context *ctx);
  274. int test_register(struct context *ctx);
  275. int test_connectivity(struct context *ctx);
  276. int test_nat_timeout(struct context *ctx);
  277. int test_unregister(struct context *ctx);
  278. int test_basic_call(struct context *ctx);
  279. int test_offer_answer(struct context *ctx);
  280. int test_rejects(struct context *ctx);
  281. int test_mime_negotiation(struct context *ctx);
  282. int test_call_timeouts(struct context *ctx);
  283. int test_reject_401_aka(struct context *ctx);
  284. int test_call_cancel(struct context *ctx);
  285. int test_call_destroy(struct context *ctx);
  286. int test_early_bye(struct context *ctx);
  287. int test_call_hold(struct context *ctx);
  288. int test_reinvites(struct context *ctx);
  289. int test_session_timer(struct context *ctx);
  290. int test_refer(struct context *ctx);
  291. int test_100rel(struct context *ctx);
  292. int test_simple(struct context *ctx);
  293. int test_events(struct context *ctx);
  294. int test_extension(struct context *ctx);
  295. #endif