Debian Codegraph @

Xpjproject/pjsip/src/test/inv_offer_answer_test.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "test.h"
21 #include <pjsip_ua.h>
22 #include <pjsip.h>
23 #include <pjlib.h>
24
25 #define THIS_FILE "inv_offer_answer_test.c"
26 #define TRACE_(x) //PJ_LOG(3,x)
27
28 static char contact_buf[80];
29 static pj_str_t contact_uri;
30
31 static struct oa_sdp_t
32 {
33 const char *offer;
34 const char *answer;
35 unsigned pt_result;
36 } oa_sdp[] =
37 {
38 {
39 /* Offer: */
40 "v=0\r\n"
41 "o=alice 1 1 IN IP4 host.anywhere.com\r\n"
42 "s= \r\n"
43 "c=IN IP4 host.anywhere.com\r\n"
44 "t=0 0\r\n"
45 "m=audio 49170 RTP/AVP 0\r\n"
46 "a=rtpmap:0 PCMU/8000\r\n",
47
48 /* Answer: */
49 "v=0\r\n"
50 "o=bob 1 1 IN IP4 host.example.com\r\n"
51 "s= \r\n"
52 "c=IN IP4 host.example.com\r\n"
53 "t=0 0\r\n"
54 "m=audio 49920 RTP/AVP 0\r\n"
55 "a=rtpmap:0 PCMU/8000\r\n"
56 "m=video 0 RTP/AVP 31\r\n",
57
58 0
59 },
60
61 {
62 /* Offer: */
63 "v=0\r\n"
64 "o=alice 2 2 IN IP4 host.anywhere.com\r\n"
65 "s= \r\n"
66 "c=IN IP4 host.anywhere.com\r\n"
67 "t=0 0\r\n"
68 "m=audio 49170 RTP/AVP 8\r\n"
69 "a=rtpmap:0 PCMA/8000\r\n",
70
71 /* Answer: */
72 "v=0\r\n"
73 "o=bob 2 2 IN IP4 host.example.com\r\n"
74 "s= \r\n"
75 "c=IN IP4 host.example.com\r\n"
76 "t=0 0\r\n"
77 "m=audio 49920 RTP/AVP 8\r\n"
78 "a=rtpmap:0 PCMA/8000\r\n",
79
80 8
81 },
82
83 {
84 /* Offer: */
85 "v=0\r\n"
86 "o=alice 3 3 IN IP4 host.anywhere.com\r\n"
87 "s= \r\n"
88 "c=IN IP4 host.anywhere.com\r\n"
89 "t=0 0\r\n"
90 "m=audio 49170 RTP/AVP 3\r\n",
91
92 /* Answer: */
93 "v=0\r\n"
94 "o=bob 3 3 IN IP4 host.example.com\r\n"
95 "s= \r\n"
96 "c=IN IP4 host.example.com\r\n"
97 "t=0 0\r\n"
98 "m=audio 49920 RTP/AVP 3\r\n",
99
100 3
101 },
102
103 {
104 /* Offer: */
105 "v=0\r\n"
106 "o=alice 4 4 IN IP4 host.anywhere.com\r\n"
107 "s= \r\n"
108 "c=IN IP4 host.anywhere.com\r\n"
109 "t=0 0\r\n"
110 "m=audio 49170 RTP/AVP 4\r\n",
111
112 /* Answer: */
113 "v=0\r\n"
114 "o=bob 4 4 IN IP4 host.example.com\r\n"
115 "s= \r\n"
116 "c=IN IP4 host.example.com\r\n"
117 "t=0 0\r\n"
118 "m=audio 49920 RTP/AVP 4\r\n",
119
120 4
121 }
122 };
123
124
125
126 typedef enum oa_t
127 {
128 OFFERER_NONE,
129 OFFERER_UAC,
130 OFFERER_UAS
131 } oa_t;
132
133 typedef struct inv_test_param_t
134 {
135 char *title;
136 unsigned inv_option;
137 pj_bool_t need_established;
138 unsigned count;
139 oa_t oa[4];
140 pj_bool_t multipart_body;
141 } inv_test_param_t;
142
143 typedef struct inv_test_t
144 {
145 inv_test_param_t param;
146 pjsip_inv_session *uac;
147 pjsip_inv_session *uas;
148
149 pj_bool_t complete;
150 pj_bool_t uas_complete,
151 uac_complete;
152
153 unsigned oa_index;
154 unsigned uac_update_cnt,
155 uas_update_cnt;
156 } inv_test_t;
157
158
159 /**************** GLOBALS ******************/
160 static inv_test_t inv_test;
161 static unsigned job_cnt;
162
163 typedef enum job_type
164 {
165 SEND_OFFER,
166 ESTABLISH_CALL
167 } job_type;
168
169 typedef struct job_t
170 {
171 job_type type;
172 pjsip_role_e who;
173 } job_t;
174
175 static job_t jobs[128];
176
177
178 /**************** UTILS ******************/
179 static pjmedia_sdp_session *create_sdp(pj_pool_t *pool, const char *body)
180 {
181 pjmedia_sdp_session *sdp;
182 pj_str_t dup;
183 pj_status_t status;
184
185 pj_strdup2_with_null(pool, &dup, body);
186 status = pjmedia_sdp_parse(pool, dup.ptr, dup.slen, &sdp);
187 pj_assert(status == PJ_SUCCESS);
188 PJ_UNUSED_ARG(status);
189
190 return sdp;
191 }
192
193 /**************** INVITE SESSION CALLBACKS ******************/
194 static void on_rx_offer(pjsip_inv_session *inv,
195 const pjmedia_sdp_session *offer)
196 {
197 pjmedia_sdp_session *sdp;
198
199 PJ_UNUSED_ARG(offer);
200
201 sdp = create_sdp(inv->dlg->pool, oa_sdp[inv_test.oa_index].answer);
202 pjsip_inv_set_sdp_answer(inv, sdp);
203
204 if (inv_test.oa_index == inv_test.param.count-1 &&
205 inv_test.param.need_established)
206 {
207 jobs[job_cnt].type = ESTABLISH_CALL;
208 jobs[job_cnt].who = PJSIP_ROLE_UAS;
209 job_cnt++;
210 }
211 }
212
213
214 static void on_create_offer(pjsip_inv_session *inv,
215 pjmedia_sdp_session **p_offer)
216 {
217 PJ_UNUSED_ARG(inv);
218 PJ_UNUSED_ARG(p_offer);
219
220 pj_assert(!"Should not happen");
221 }
222
223 static void on_media_update(pjsip_inv_session *inv_ses,
224 pj_status_t status)
225 {
226 PJ_UNUSED_ARG(status);
227
228 if (inv_ses == inv_test.uas) {
229 inv_test.uas_update_cnt++;
230 pj_assert(inv_test.uas_update_cnt - inv_test.uac_update_cnt <= 1);
231 TRACE_((THIS_FILE, " Callee media is established"));
232 } else if (inv_ses == inv_test.uac) {
233 inv_test.uac_update_cnt++;
234 pj_assert(inv_test.uac_update_cnt - inv_test.uas_update_cnt <= 1);
235 TRACE_((THIS_FILE, " Caller media is established"));
236
237 } else {
238 pj_assert(!"Unknown session!");
239 }
240
241 if (inv_test.uac_update_cnt == inv_test.uas_update_cnt) {
242 inv_test.oa_index++;
243
244 if (inv_test.oa_index < inv_test.param.count) {
245 switch (inv_test.param.oa[inv_test.oa_index]) {
246 case OFFERER_UAC:
247 jobs[job_cnt].type = SEND_OFFER;
248 jobs[job_cnt].who = PJSIP_ROLE_UAC;
249 job_cnt++;
250 break;
251 case OFFERER_UAS:
252 jobs[job_cnt].type = SEND_OFFER;
253 jobs[job_cnt].who = PJSIP_ROLE_UAS;
254 job_cnt++;
255 break;
256 default:
257 pj_assert(!"Invalid oa");
258 }
259 }
260
261 /* Special handling for standard offer/answer */
262 if (inv_test.param.count == 1 &&
263 inv_test.param.oa[0] == OFFERER_UAC &&
264 inv_test.param.need_established)
265 {
266 jobs[job_cnt].type = ESTABLISH_CALL;
267 jobs[job_cnt].who = PJSIP_ROLE_UAS;
268 job_cnt++;
269 TRACE_((THIS_FILE, " C+++"));
270 }
271
272 pj_assert(job_cnt <= PJ_ARRAY_SIZE(jobs));
273 }
274 }
275
276 static void on_state_changed(pjsip_inv_session *inv, pjsip_event *e)
277 {
278 const char *who = NULL;
279
280 PJ_UNUSED_ARG(e);
281 PJ_UNUSED_ARG(who);
282
283 if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
284 TRACE_((THIS_FILE, " %s call disconnected",
285 (inv==inv_test.uas ? "Callee" : "Caller")));
286 return;
287 }
288
289 if (inv->state != PJSIP_INV_STATE_CONFIRMED)
290 return;
291
292 if (inv == inv_test.uas) {
293 inv_test.uas_complete = PJ_TRUE;
294 who = "Callee";
295 } else if (inv == inv_test.uac) {
296 inv_test.uac_complete = PJ_TRUE;
297 who = "Caller";
298 } else
299 pj_assert(!"No session");
300
301 TRACE_((THIS_FILE, " %s call is confirmed", who));
302
303 if (inv_test.uac_complete && inv_test.uas_complete)
304 inv_test.complete = PJ_TRUE;
305 }
306
307
308 /**************** MODULE TO RECEIVE INITIAL INVITE ******************/
309
310 static pj_bool_t on_rx_request(pjsip_rx_data *rdata)
311 {
312 if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG &&
313 rdata->msg_info.msg->line.req.method.id == PJSIP_INVITE_METHOD)
314 {
315 pjsip_dialog *dlg;
316 pjmedia_sdp_session *sdp = NULL;
317 pj_str_t uri;
318 pjsip_tx_data *tdata;
319
320 if (!is_user_equal(rdata->msg_info.from, "inv_offer_answer_test"))
321 return PJ_FALSE;
322
323 /*
324 * Create UAS
325 */
326 uri = contact_uri;
327 PJ_TEST_SUCCESS(pjsip_dlg_create_uas_and_inc_lock(pjsip_ua_instance(), rdata,
328 &uri, &dlg),
329 NULL, { pj_assert(0); return PJ_FALSE; });
330
331 if (inv_test.param.oa[0] == OFFERER_UAC)
332 sdp = create_sdp(rdata->tp_info.pool, oa_sdp[0].answer);
333 else if (inv_test.param.oa[0] == OFFERER_UAS)
334 sdp = create_sdp(rdata->tp_info.pool, oa_sdp[0].offer);
335 else
336 pj_assert(!"Invalid offerer type");
337
338 PJ_TEST_SUCCESS(pjsip_inv_create_uas(dlg, rdata, sdp,
339 inv_test.param.inv_option,
340 &inv_test.uas),
341 NULL, { pj_assert(0); return PJ_FALSE; });
342 pjsip_dlg_dec_lock(dlg);
343
344 TRACE_((THIS_FILE, " Sending 183 with SDP"));
345
346 /*
347 * Answer with 183
348 */
349 PJ_TEST_SUCCESS(pjsip_inv_initial_answer(inv_test.uas, rdata, 183,
350 NULL, NULL, &tdata),
351 NULL, { pj_assert(0); return PJ_FALSE; });
352
353 /* Use multipart body, if configured */
354 if (sdp && inv_test.param.multipart_body) {
355 PJ_TEST_SUCCESS(pjsip_create_multipart_sdp_body(
356 tdata->pool,
357 pjmedia_sdp_session_clone(tdata->pool, sdp),
358 &tdata->msg->body),
359 NULL, { pj_assert(0); return PJ_FALSE; });
360 }
361
362 PJ_TEST_SUCCESS(pjsip_inv_send_msg(inv_test.uas, tdata),
363 NULL, { pj_assert(0); return PJ_FALSE; });
364
365 return PJ_TRUE;
366 }
367
368 return PJ_FALSE;
369 }
370
371 static pjsip_module mod_inv_oa_test =
372 {
373 NULL, NULL, /* prev, next. */
374 { "mod-inv-oa-test", 15 }, /* Name. */
375 -1, /* Id */
376 PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
377 NULL, /* load() */
378 NULL, /* start() */
379 NULL, /* stop() */
380 NULL, /* unload() */
381 &on_rx_request, /* on_rx_request() */
382 NULL, /* on_rx_response() */
383 NULL, /* on_tx_request. */
384 NULL, /* on_tx_response() */
385 NULL, /* on_tsx_state() */
386 };
387
388
389 /**************** THE TEST ******************/
390 static void run_job(job_t *j)
391 {
392 pjsip_inv_session *inv;
393 pjsip_tx_data *tdata;
394 pjmedia_sdp_session *sdp;
395 pj_status_t status;
396
397 if (j->who == PJSIP_ROLE_UAC)
398 inv = inv_test.uac;
399 else
400 inv = inv_test.uas;
401
402 switch (j->type) {
403 case SEND_OFFER:
404 sdp = create_sdp(inv->dlg->pool, oa_sdp[inv_test.oa_index].offer);
405
406 TRACE_((THIS_FILE, " Sending UPDATE with offer"));
407 status = pjsip_inv_update(inv, NULL, sdp, &tdata);
408 pj_assert(status == PJ_SUCCESS);
409
410 status = pjsip_inv_send_msg(inv, tdata);
411 pj_assert(status == PJ_SUCCESS);
412 break;
413 case ESTABLISH_CALL:
414 TRACE_((THIS_FILE, " Sending 200/OK"));
415 status = pjsip_inv_answer(inv, 200, NULL, NULL, &tdata);
416 pj_assert(status == PJ_SUCCESS);
417
418 status = pjsip_inv_send_msg(inv, tdata);
419 pj_assert(status == PJ_SUCCESS);
420 break;
421 }
422 PJ_UNUSED_ARG(status);
423 }
424
425
426 static int perform_test(inv_test_param_t *param)
427 {
428 pj_str_t uri;
429 pjsip_dialog *dlg;
430 pjmedia_sdp_session *sdp;
431 pjsip_tx_data *tdata;
432 pj_status_t status;
433
434 PJ_LOG(3,(THIS_FILE, " %s", param->title));
435
436 pj_bzero(&inv_test, sizeof(inv_test));
437 pj_memcpy(&inv_test.param, param, sizeof(*param));
438 job_cnt = 0;
439
440 uri = contact_uri;
441
442 /*
443 * Create UAC
444 */
445 status = pjsip_dlg_create_uac(pjsip_ua_instance(),
446 &uri, &uri, &uri, &uri, &dlg);
447 PJ_ASSERT_RETURN(status==PJ_SUCCESS, -10);
448
449 if (inv_test.param.oa[0] == OFFERER_UAC)
450 sdp = create_sdp(dlg->pool, oa_sdp[0].offer);
451 else
452 sdp = NULL;
453
454 status = pjsip_inv_create_uac(dlg, sdp, inv_test.param.inv_option, &inv_test.uac);
455 //inv_test.uac->create_multipart = param->multipart_body;
456 PJ_ASSERT_RETURN(status==PJ_SUCCESS, -20);
457
458 TRACE_((THIS_FILE, " Sending INVITE %s offer", (sdp ? "with" : "without")));
459
460 /*
461 * Make call!
462 */
463 status = pjsip_inv_invite(inv_test.uac, &tdata);
464 PJ_ASSERT_RETURN(status==PJ_SUCCESS, -30);
465
466 /* Use multipart body, if configured */
467 if (sdp && param->multipart_body) {
468 status = pjsip_create_multipart_sdp_body(
469 tdata->pool,
470 pjmedia_sdp_session_clone(tdata->pool, sdp),
471 &tdata->msg->body);
472 }
473 PJ_ASSERT_RETURN(status==PJ_SUCCESS, -40);
474
475 PJ_TEST_SUCCESS(pjsip_inv_send_msg(inv_test.uac, tdata),
476 NULL, PJ_ASSERT_RETURN(0, -50));
477
478 /*
479 * Wait until test completes
480 */
481 while (!inv_test.complete) {
482 pj_time_val delay = {0, 20};
483
484 pjsip_endpt_handle_events(endpt, &delay);
485
486 while (job_cnt) {
487 job_t j;
488
489 j = jobs[0];
490 pj_array_erase(jobs, sizeof(jobs[0]), job_cnt, 0);
491 --job_cnt;
492
493 run_job(&j);
494 }
495 }
496
497 flush_events(100);
498
499 /*
500 * Hangup
501 */
502 TRACE_((THIS_FILE, " Disconnecting call"));
503 status = pjsip_inv_end_session(inv_test.uas, PJSIP_SC_DECLINE, 0, &tdata);
504 pj_assert(status == PJ_SUCCESS);
505
506 if (tdata) {
507 PJ_TEST_SUCCESS(pjsip_inv_send_msg(inv_test.uas, tdata),
508 NULL, pj_assert(0));
509 }
510
511 flush_events(500);
512
513 return 0;
514 }
515
516
517 static pj_bool_t log_on_rx_msg(pjsip_rx_data *rdata)
518 {
519 pjsip_msg *msg = rdata->msg_info.msg;
520 char info[80];
521
522 if (!is_user_equal(rdata->msg_info.from, "inv_offer_answer_test"))
523 return PJ_FALSE;
524
525 if (msg->type == PJSIP_REQUEST_MSG)
526 pj_ansi_snprintf(info, sizeof(info), "%.*s",
527 (int)msg->line.req.method.name.slen,
528 msg->line.req.method.name.ptr);
529 else
530 pj_ansi_snprintf(info, sizeof(info), "%d/%.*s",
531 msg->line.status.code,
532 (int)rdata->msg_info.cseq->method.name.slen,
533 rdata->msg_info.cseq->method.name.ptr);
534
535 TRACE_((THIS_FILE, " Received %s %s sdp", info,
536 (msg->body ? "with" : "without")));
537
538 return PJ_FALSE;
539 }
540
541
542 /* Message logger module. */
543 static pjsip_module mod_msg_logger =
544 {
545 NULL, NULL, /* prev and next */
546 { "mod-msg-loggee", 14}, /* Name. */
547 -1, /* Id */
548 PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */
549 NULL, /* load() */
550 NULL, /* start() */
551 NULL, /* stop() */
552 NULL, /* unload() */
553 &log_on_rx_msg, /* on_rx_request() */
554 &log_on_rx_msg, /* on_rx_response() */
555 NULL, /* on_tx_request() */
556 NULL, /* on_tx_response() */
557 NULL, /* on_tsx_state() */
558 };
559
560 static inv_test_param_t test_params[] =
561 {
562 /* Normal scenario:
563
564 UAC UAS
565 INVITE (offer) -->
566 200/INVITE (answer) <--
567 ACK -->
568 */
569 #if 1
570 {
571 "Standard INVITE with offer",
572 0,
573 PJ_TRUE,
574 1,
575 { OFFERER_UAC },
576 PJ_FALSE
577 },
578
579 {
580 "Standard INVITE with offer, with 100rel",
581 PJSIP_INV_REQUIRE_100REL,
582 PJ_TRUE,
583 1,
584 { OFFERER_UAC },
585 PJ_FALSE
586 },
587 {
588 "Standard INVITE with offer, with Multipart",
589 0,
590 PJ_TRUE,
591 1,
592 { OFFERER_UAC },
593 PJ_TRUE
594 },
595
596 {
597 "Standard INVITE with offer, with 100rel, with Multipart",
598 PJSIP_INV_REQUIRE_100REL,
599 PJ_TRUE,
600 1,
601 { OFFERER_UAC },
602 PJ_TRUE
603 },
604 #endif
605
606 /* Delayed offer:
607 UAC UAS
608 INVITE (no SDP) -->
609 200/INVITE (offer) <--
610 ACK (answer) -->
611 */
612 #if 1
613 {
614 "INVITE with no offer",
615 0,
616 PJ_TRUE,
617 1,
618 { OFFERER_UAS },
619 PJ_FALSE
620 },
621
622 {
623 "INVITE with no offer, with 100rel",
624 PJSIP_INV_REQUIRE_100REL,
625 PJ_TRUE,
626 1,
627 { OFFERER_UAS },
628 PJ_FALSE
629 },
630 {
631 "INVITE with no offer, with Multipart",
632 0,
633 PJ_TRUE,
634 1,
635 { OFFERER_UAS },
636 PJ_TRUE
637 },
638
639 {
640 "INVITE with no offer, with 100rel, with Multipart",
641 PJSIP_INV_REQUIRE_100REL,
642 PJ_TRUE,
643 1,
644 { OFFERER_UAS },
645 PJ_TRUE
646 },
647 #endif
648
649 /* Subsequent UAC offer with UPDATE:
650
651 UAC UAS
652 INVITE (offer) -->
653 180/rel (answer) <--
654 UPDATE (offer) --> inv_update() on_rx_offer()
655 set_sdp_answer()
656 200/UPDATE (answer) <--
657 200/INVITE <--
658 ACK -->
659 */
660 #if 1
661 #if !PJSIP_INV_UPDATE_EARLY_CHECK_RELIABLE
662 {
663 "INVITE and UPDATE by UAC",
664 0,
665 PJ_TRUE,
666 2,
667 { OFFERER_UAC, OFFERER_UAC },
668 PJ_FALSE
669 },
670 #endif
671 {
672 "INVITE and UPDATE by UAC, with Multipart, with 100rel",
673 PJSIP_INV_REQUIRE_100REL,
674 PJ_TRUE,
675 2,
676 { OFFERER_UAC, OFFERER_UAC },
677 PJ_TRUE
678 },
679 {
680 "INVITE and UPDATE by UAC, with 100rel",
681 PJSIP_INV_REQUIRE_100REL,
682 PJ_TRUE,
683 2,
684 { OFFERER_UAC, OFFERER_UAC },
685 PJ_FALSE
686 },
687 #endif
688
689 /* Subsequent UAS offer with UPDATE:
690
691 INVITE (offer -->
692 180/rel (answer) <--
693 UPDATE (offer) <-- inv_update()
694 on_rx_offer()
695 set_sdp_answer()
696 200/UPDATE (answer) -->
697 UPDATE (offer) --> on_rx_offer()
698 set_sdp_answer()
699 200/UPDATE (answer) <--
700 200/INVITE <--
701 ACK -->
702
703 */
704
705 {
706 "INVITE and many UPDATE by UAC and UAS, with 100rel",
707 PJSIP_INV_REQUIRE_100REL,
708 PJ_TRUE,
709 4,
710 { OFFERER_UAC, OFFERER_UAS, OFFERER_UAC, OFFERER_UAS }
711 },
712 {
713 "INVITE and many UPDATE by UAC and UAS, with Multipart, with 100rel",
714 PJSIP_INV_REQUIRE_100REL,
715 PJ_TRUE,
716 4,
717 { OFFERER_UAC, OFFERER_UAS, OFFERER_UAC, OFFERER_UAS },
718 PJ_TRUE
719 },
720
721 };
722
723
724 static pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res)
725 {
726 PJ_UNUSED_ARG(first_set);
727 PJ_UNUSED_ARG(res);
728
729 return NULL;
730 }
731
732
733 static void on_new_session(pjsip_inv_session *inv, pjsip_event *e)
734 {
735 PJ_UNUSED_ARG(inv);
736 PJ_UNUSED_ARG(e);
737 }
738
739
740 int inv_offer_answer_test(void)
741 {
742 unsigned i;
743 int rc = 0;
744
745 /* Init UA layer */
746 if (pjsip_ua_instance()->id == -1) {
747 pjsip_ua_init_param ua_param;
748 pj_bzero(&ua_param, sizeof(ua_param));
749 ua_param.on_dlg_forked = &on_dlg_forked;
750 pjsip_ua_init_module(endpt, &ua_param);
751 }
752
753 /* Init inv-usage */
754 if (pjsip_inv_usage_instance()->id == -1) {
755 pjsip_inv_callback inv_cb;
756 pj_bzero(&inv_cb, sizeof(inv_cb));
757 inv_cb.on_media_update = &on_media_update;
758 inv_cb.on_rx_offer = &on_rx_offer;
759 inv_cb.on_create_offer = &on_create_offer;
760 inv_cb.on_state_changed = &on_state_changed;
761 inv_cb.on_new_session = &on_new_session;
762 pjsip_inv_usage_init(endpt, &inv_cb);
763 }
764
765 /* 100rel module */
766 pjsip_100rel_init_module(endpt);
767
768 /* Our module */
769 pjsip_endpt_register_module(endpt, &mod_inv_oa_test);
770 pjsip_endpt_register_module(endpt, &mod_msg_logger);
771
772 /* Create SIP UDP transport on ephemeral port */
773 {
774 pj_sockaddr_in addr;
775 pjsip_transport *tp;
776
777 pj_sockaddr_in_init(&addr, NULL, 0);
778 PJ_TEST_SUCCESS(pjsip_udp_transport_start(endpt, &addr, NULL, 1, &tp),
779 NULL, return -5);
780
781 /* Build contact URI from the assigned port */
782 pj_ansi_snprintf(contact_buf, sizeof(contact_buf),
783 "sip:[email protected]:%d",
784 tp->local_name.port);
785 contact_uri = pj_str(contact_buf);
786 }
787
788 /* Do tests */
789 for (i=0; i<PJ_ARRAY_SIZE(test_params); ++i) {
790 rc = perform_test(&test_params[i]);
791 if (rc != 0)
792 goto on_return;
793 }
794
795
796 on_return:
797 return rc;
798 }
799