1
/* $Id: tsx_basic_test.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#define THIS_FILE "tsx_basic_test.c"
27
static char TARGET_URI[PJSIP_MAX_URL_SIZE];
28
static char FROM_URI[PJSIP_MAX_URL_SIZE];
31
/* Test transaction layer. */
32
static int tsx_layer_test(void)
34
pj_str_t target, from, tsx_key;
36
pjsip_transaction *tsx, *found;
39
PJ_LOG(3,(THIS_FILE, " transaction layer test"));
41
target = pj_str(TARGET_URI);
42
from = pj_str(FROM_URI);
44
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
45
&from, &target, NULL, NULL, -1, NULL,
47
if (status != PJ_SUCCESS) {
48
app_perror(" error: unable to create request", status);
52
status = pjsip_tsx_create_uac(NULL, tdata, &tsx);
53
if (status != PJ_SUCCESS) {
54
app_perror(" error: unable to create transaction", status);
58
pj_strdup(tdata->pool, &tsx_key, &tsx->transaction_key);
60
found = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_FALSE);
65
pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
68
if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) {
75
/* Double terminate test. */
76
static int double_terminate(void)
78
pj_str_t target, from, tsx_key;
80
pjsip_transaction *tsx;
83
PJ_LOG(3,(THIS_FILE, " double terminate test"));
85
target = pj_str(TARGET_URI);
86
from = pj_str(FROM_URI);
89
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
90
&from, &target, NULL, NULL, -1, NULL,
92
if (status != PJ_SUCCESS) {
93
app_perror(" error: unable to create request", status);
97
/* Create transaction. */
98
status = pjsip_tsx_create_uac(NULL, tdata, &tsx);
99
if (status != PJ_SUCCESS) {
100
app_perror(" error: unable to create transaction", status);
104
/* Save transaction key for later. */
105
pj_strdup_with_null(tdata->pool, &tsx_key, &tsx->transaction_key);
107
/* Add reference to transmit buffer (tsx_send_msg() will dec txdata). */
108
pjsip_tx_data_add_ref(tdata);
110
/* Send message to start timeout timer. */
111
status = pjsip_tsx_send_msg(tsx, NULL);
113
/* Terminate transaction. */
114
status = pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
115
if (status != PJ_SUCCESS) {
116
app_perror(" error: unable to terminate transaction", status);
120
tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE);
122
/* Terminate transaction again. */
123
pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
124
if (status != PJ_SUCCESS) {
125
app_perror(" error: unable to terminate transaction", status);
128
pj_mutex_unlock(tsx->mutex);
132
if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) {
139
int tsx_basic_test(struct tsx_test_param *param)
143
pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s",
144
param->port, param->tp_type);
145
pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s",
146
param->port, param->tp_type);
148
status = tsx_layer_test();
152
status = double_terminate();