1
/* $Id: txdata_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
26
#define THIS_FILE "txdata_test.c"
29
#define HFIND(msg,h,H) ((pjsip_##h##_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_##H, NULL))
31
#if defined(PJ_DEBUG) && PJ_DEBUG!=0
39
* This tests various core message creation functions.
41
static int core_txdata_test(void)
44
pj_str_t target, from, to, contact, body;
45
pjsip_rx_data dummy_rdata;
46
pjsip_tx_data *invite, *invite2, *cancel, *response, *ack;
48
PJ_LOG(3,(THIS_FILE, " core transmit data test"));
50
/* Create INVITE request. */
51
target = pj_str("tel:+1");
52
from = pj_str("tel:+0");
53
to = pj_str("tel:+1");
54
contact = pj_str("Bob <sip:+0@example.com;user=phone>");
55
body = pj_str("Hello world!");
57
status = pjsip_endpt_create_request( endpt, &pjsip_invite_method, &target,
58
&from, &to, &contact, NULL, 10, &body,
60
if (status != PJ_SUCCESS) {
61
app_perror(" error: unable to create request", status);
65
/* Buffer must be invalid. */
66
if (pjsip_tx_data_is_valid(invite) != 0) {
67
PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid"));
70
/* Reference counter must be set to 1. */
71
if (pj_atomic_get(invite->ref_cnt) != 1) {
72
PJ_LOG(3,(THIS_FILE, " error: invalid reference counter"));
75
/* Check message type. */
76
if (invite->msg->type != PJSIP_REQUEST_MSG)
79
if (invite->msg->line.req.method.id != PJSIP_INVITE_METHOD)
82
/* Check that mandatory headers are present. */
83
if (HFIND(invite->msg, from, FROM) == 0)
85
if (HFIND(invite->msg, to, TO) == 0)
87
if (HFIND(invite->msg, contact, CONTACT) == 0)
89
if (HFIND(invite->msg, cid, CALL_ID) == 0)
91
if (HFIND(invite->msg, cseq, CSEQ) == 0)
94
pjsip_via_hdr *via = HFIND(invite->msg, via, VIA);
97
/* Branch param must be empty. */
98
if (via->branch_param.slen != 0)
101
if (invite->msg->body == NULL)
104
/* Create another INVITE request from first request. */
105
status = pjsip_endpt_create_request_from_hdr( endpt, &pjsip_invite_method,
106
invite->msg->line.req.uri,
107
HFIND(invite->msg,from,FROM),
108
HFIND(invite->msg,to,TO),
109
HFIND(invite->msg,contact,CONTACT),
110
HFIND(invite->msg,cid,CALL_ID),
111
10, &body, &invite2);
112
if (status != PJ_SUCCESS) {
113
app_perror(" error: create second request failed", status);
117
/* Buffer must be invalid. */
118
if (pjsip_tx_data_is_valid(invite2) != 0) {
119
PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid"));
122
/* Reference counter must be set to 1. */
123
if (pj_atomic_get(invite2->ref_cnt) != 1) {
124
PJ_LOG(3,(THIS_FILE, " error: invalid reference counter"));
127
/* Check message type. */
128
if (invite2->msg->type != PJSIP_REQUEST_MSG)
131
if (invite2->msg->line.req.method.id != PJSIP_INVITE_METHOD)
134
/* Check that mandatory headers are again present. */
135
if (HFIND(invite2->msg, from, FROM) == 0)
137
if (HFIND(invite2->msg, to, TO) == 0)
139
if (HFIND(invite2->msg, contact, CONTACT) == 0)
141
if (HFIND(invite2->msg, cid, CALL_ID) == 0)
143
if (HFIND(invite2->msg, cseq, CSEQ) == 0)
145
if (HFIND(invite2->msg, via, VIA) == 0)
148
if (HFIND(invite2->msg, ctype, CONTENT_TYPE) == 0)
150
if (HFIND(invite2->msg, clen, CONTENT_LENGTH) == 0)
153
if (invite2->msg->body == NULL)
156
/* Done checking invite2. We can delete this. */
157
if (pjsip_tx_data_dec_ref(invite2) != PJSIP_EBUFDESTROYED) {
158
PJ_LOG(3,(THIS_FILE, " error: request buffer not destroyed!"));
162
/* Initialize dummy rdata (to simulate receiving a request)
163
* We should never do this in real application, as there are many
164
* many more fields need to be initialized!!
166
dummy_rdata.msg_info.cid = HFIND(invite->msg, cid, CALL_ID);
167
dummy_rdata.msg_info.clen = NULL;
168
dummy_rdata.msg_info.cseq = HFIND(invite->msg, cseq, CSEQ);
169
dummy_rdata.msg_info.ctype = NULL;
170
dummy_rdata.msg_info.from = HFIND(invite->msg, from, FROM);
171
dummy_rdata.msg_info.max_fwd = NULL;
172
dummy_rdata.msg_info.msg = invite->msg;
173
dummy_rdata.msg_info.record_route = NULL;
174
dummy_rdata.msg_info.require = NULL;
175
dummy_rdata.msg_info.route = NULL;
176
dummy_rdata.msg_info.to = HFIND(invite->msg, to, TO);
177
dummy_rdata.msg_info.via = HFIND(invite->msg, via, VIA);
179
/* Create a response message for the request. */
180
status = pjsip_endpt_create_response( endpt, &dummy_rdata, 301, NULL,
182
if (status != PJ_SUCCESS) {
183
app_perror(" error: unable to create response", status);
187
/* Buffer must be invalid. */
188
if (pjsip_tx_data_is_valid(response) != 0) {
189
PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid"));
192
/* Check reference counter. */
193
if (pj_atomic_get(response->ref_cnt) != 1) {
194
PJ_LOG(3,(THIS_FILE, " error: invalid ref count in response"));
197
/* Check message type. */
198
if (response->msg->type != PJSIP_RESPONSE_MSG)
200
/* Check correct status is set. */
201
if (response->msg->line.status.code != 301)
204
/* Check that mandatory headers are again present. */
205
if (HFIND(response->msg, from, FROM) == 0)
207
if (HFIND(response->msg, to, TO) == 0)
210
if (HFIND(response->msg, contact, CONTACT) == 0)
213
if (HFIND(response->msg, cid, CALL_ID) == 0)
215
if (HFIND(response->msg, cseq, CSEQ) == 0)
217
if (HFIND(response->msg, via, VIA) == 0)
220
/* This response message will be used later when creating ACK */
222
/* Create CANCEL request for the original request. */
223
status = pjsip_endpt_create_cancel( endpt, invite, &cancel);
224
if (status != PJ_SUCCESS) {
225
app_perror(" error: unable to create CANCEL request", status);
229
/* Buffer must be invalid. */
230
if (pjsip_tx_data_is_valid(cancel) != 0) {
231
PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid"));
234
/* Check reference counter. */
235
if (pj_atomic_get(cancel->ref_cnt) != 1) {
236
PJ_LOG(3,(THIS_FILE, " error: invalid ref count in CANCEL request"));
239
/* Check message type. */
240
if (cancel->msg->type != PJSIP_REQUEST_MSG)
243
if (cancel->msg->line.req.method.id != PJSIP_CANCEL_METHOD)
246
/* Check that mandatory headers are again present. */
247
if (HFIND(cancel->msg, from, FROM) == 0)
249
if (HFIND(cancel->msg, to, TO) == 0)
252
if (HFIND(cancel->msg, contact, CONTACT) == 0)
255
if (HFIND(cancel->msg, cid, CALL_ID) == 0)
257
if (HFIND(cancel->msg, cseq, CSEQ) == 0)
259
if (HFIND(cancel->msg, via, VIA) == 0)
262
/* Done checking CANCEL request. */
263
if (pjsip_tx_data_dec_ref(cancel) != PJSIP_EBUFDESTROYED) {
264
PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!"));
268
/* Modify dummy_rdata to simulate receiving response. */
269
pj_bzero(&dummy_rdata, sizeof(dummy_rdata));
270
dummy_rdata.msg_info.msg = response->msg;
271
dummy_rdata.msg_info.to = HFIND(response->msg, to, TO);
273
/* Create ACK request */
274
status = pjsip_endpt_create_ack( endpt, invite, &dummy_rdata, &ack );
275
if (status != PJ_SUCCESS) {
276
PJ_LOG(3,(THIS_FILE, " error: unable to create ACK"));
279
/* Buffer must be invalid. */
280
if (pjsip_tx_data_is_valid(ack) != 0) {
281
PJ_LOG(3,(THIS_FILE, " error: buffer must be invalid"));
284
/* Check reference counter. */
285
if (pj_atomic_get(ack->ref_cnt) != 1) {
286
PJ_LOG(3,(THIS_FILE, " error: invalid ref count in ACK request"));
289
/* Check message type. */
290
if (ack->msg->type != PJSIP_REQUEST_MSG)
293
if (ack->msg->line.req.method.id != PJSIP_ACK_METHOD)
295
/* Check Request-URI is present. */
296
if (ack->msg->line.req.uri == NULL)
299
/* Check that mandatory headers are again present. */
300
if (HFIND(ack->msg, from, FROM) == 0)
302
if (HFIND(ack->msg, to, TO) == 0)
304
if (HFIND(ack->msg, cid, CALL_ID) == 0)
306
if (HFIND(ack->msg, cseq, CSEQ) == 0)
308
if (HFIND(ack->msg, via, VIA) == 0)
310
if (ack->msg->body != NULL)
313
/* Done checking invite message. */
314
if (pjsip_tx_data_dec_ref(invite) != PJSIP_EBUFDESTROYED) {
315
PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!"));
319
/* Done checking response message. */
320
if (pjsip_tx_data_dec_ref(response) != PJSIP_EBUFDESTROYED) {
321
PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!"));
325
/* Done checking ack message. */
326
if (pjsip_tx_data_dec_ref(ack) != PJSIP_EBUFDESTROYED) {
327
PJ_LOG(3,(THIS_FILE, " error: response buffer not destroyed!"));
338
* This test demonstrate the bug as reported in:
339
* http://bugzilla.pjproject.net/show_bug.cgi?id=49
342
static int gcc_test()
345
pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201"
346
"?X-Hdr-1=Header%201"
348
pjsip_tx_data *tdata;
349
pjsip_parser_err_report err_list;
354
PJ_LOG(3,(THIS_FILE, " header param in URI to create request"));
356
/* Create request with header param in target URI. */
357
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
358
&target, &target, &target, NULL, -1,
361
app_perror(" error: Unable to create request", status);
365
/* Print and parse the request.
366
* We'll check that header params are not present in
368
len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf));
370
PJ_LOG(3,(THIS_FILE, " error: printing message"));
371
pjsip_tx_data_dec_ref(tdata);
376
PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n"
378
"--end-msg--", len, msgbuf));
380
/* Now parse the message. */
381
pj_list_init(&err_list);
382
msg = pjsip_parse_msg( tdata->pool, msgbuf, len, &err_list);
384
pjsip_parser_err_report *e;
386
PJ_LOG(3,(THIS_FILE, " error: parsing message message"));
389
while (e != &err_list) {
390
PJ_LOG(3,(THIS_FILE, " %s in line %d col %d hname=%.*s",
391
pj_exception_id_name(e->except_code),
398
pjsip_tx_data_dec_ref(tdata);
402
pjsip_tx_data_dec_ref(tdata);
408
/* This tests the request creating functions against the following
410
* - header params in URI creates header in the request.
411
* - method and headers params are correctly shown or hidden in
412
* request URI, From, To, and Contact header.
414
static int txdata_test_uri_params(void)
417
pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201"
418
"?X-Hdr-1=Header%201"
421
pj_str_t pname = pj_str("x-param");
422
pj_str_t hname = pj_str("X-Hdr-1");
423
pj_str_t hemptyname = pj_str("X-Empty-Hdr");
424
pjsip_from_hdr *from_hdr;
425
pjsip_to_hdr *to_hdr;
426
pjsip_contact_hdr *contact_hdr;
427
pjsip_generic_string_hdr *hdr;
428
pjsip_tx_data *tdata;
432
pjsip_parser_err_report err_list;
437
PJ_LOG(3,(THIS_FILE, " header param in URI to create request"));
439
/* Due to #930, contact argument is now parsed as Contact header, so
440
* must enclose it with <> to make it be parsed as URI.
442
pj_ansi_snprintf(msgbuf, sizeof(msgbuf), "<%.*s>",
443
(int)target.slen, target.ptr);
444
contact.ptr = msgbuf;
445
contact.slen = strlen(msgbuf);
447
/* Create request with header param in target URI. */
448
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
449
&target, &target, &contact, NULL, -1,
452
app_perror(" error: Unable to create request", status);
456
/* Fill up the Via header to prevent syntax error on parsing */
457
via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
458
via->transport = pj_str("TCP");
459
via->sent_by.host = pj_str("127.0.0.1");
461
/* Print and parse the request.
462
* We'll check that header params are not present in
464
len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf));
466
PJ_LOG(3,(THIS_FILE, " error: printing message"));
467
pjsip_tx_data_dec_ref(tdata);
472
PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n"
474
"--end-msg--", len, msgbuf));
476
/* Now parse the message. */
477
pj_list_init(&err_list);
478
msg = pjsip_parse_msg( tdata->pool, msgbuf, len, &err_list);
480
pjsip_parser_err_report *e;
482
PJ_LOG(3,(THIS_FILE, " error: parsing message message"));
485
while (e != &err_list) {
486
PJ_LOG(3,(THIS_FILE, " %s in line %d col %d hname=%.*s",
487
pj_exception_id_name(e->except_code),
494
pjsip_tx_data_dec_ref(tdata);
498
/* Check the existence of port, other_param, and header param.
499
* Port is now allowed in To and From header.
501
/* Port in request URI. */
502
uri = (pjsip_sip_uri*) pjsip_uri_get_uri(msg->line.req.uri);
503
if (uri->port != 5061) {
504
PJ_LOG(3,(THIS_FILE, " error: port not present in request URI"));
505
pjsip_tx_data_dec_ref(tdata);
508
/* other_param in request_uri */
509
param = pjsip_param_find(&uri->other_param, &pname);
510
if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) {
511
PJ_LOG(3,(THIS_FILE, " error: x-param not present in request URI"));
512
pjsip_tx_data_dec_ref(tdata);
515
/* header param in request uri. */
516
if (!pj_list_empty(&uri->header_param)) {
517
PJ_LOG(3,(THIS_FILE, " error: hparam in request URI"));
518
pjsip_tx_data_dec_ref(tdata);
522
/* Port in From header. */
523
from_hdr = (pjsip_from_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_FROM, NULL);
524
uri = (pjsip_sip_uri*) pjsip_uri_get_uri(from_hdr->uri);
525
if (uri->port != 0) {
526
PJ_LOG(3,(THIS_FILE, " error: port most not exist in From header"));
527
pjsip_tx_data_dec_ref(tdata);
530
/* other_param in From header */
531
param = pjsip_param_find(&uri->other_param, &pname);
532
if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) {
533
PJ_LOG(3,(THIS_FILE, " error: x-param not present in From header"));
534
pjsip_tx_data_dec_ref(tdata);
537
/* header param in From header. */
538
if (!pj_list_empty(&uri->header_param)) {
539
PJ_LOG(3,(THIS_FILE, " error: hparam in From header"));
540
pjsip_tx_data_dec_ref(tdata);
545
/* Port in To header. */
546
to_hdr = (pjsip_to_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_TO, NULL);
547
uri = (pjsip_sip_uri*) pjsip_uri_get_uri(to_hdr->uri);
548
if (uri->port != 0) {
549
PJ_LOG(3,(THIS_FILE, " error: port most not exist in To header"));
550
pjsip_tx_data_dec_ref(tdata);
553
/* other_param in To header */
554
param = pjsip_param_find(&uri->other_param, &pname);
555
if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) {
556
PJ_LOG(3,(THIS_FILE, " error: x-param not present in To header"));
557
pjsip_tx_data_dec_ref(tdata);
560
/* header param in From header. */
561
if (!pj_list_empty(&uri->header_param)) {
562
PJ_LOG(3,(THIS_FILE, " error: hparam in To header"));
563
pjsip_tx_data_dec_ref(tdata);
569
/* Port in Contact header. */
570
contact_hdr = (pjsip_contact_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
571
uri = (pjsip_sip_uri*) pjsip_uri_get_uri(contact_hdr->uri);
572
if (uri->port != 5061) {
573
PJ_LOG(3,(THIS_FILE, " error: port not present in Contact header"));
574
pjsip_tx_data_dec_ref(tdata);
577
/* other_param in Contact header */
578
param = pjsip_param_find(&uri->other_param, &pname);
579
if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) {
580
PJ_LOG(3,(THIS_FILE, " error: x-param not present in Contact header"));
581
pjsip_tx_data_dec_ref(tdata);
584
/* header param in Contact header. */
585
if (pj_list_empty(&uri->header_param)) {
586
PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header"));
587
pjsip_tx_data_dec_ref(tdata);
590
/* Check for X-Hdr-1 */
591
param = pjsip_param_find(&uri->header_param, &hname);
592
if (param == NULL || pj_strcmp2(¶m->value, "Header 1")!=0) {
593
PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header"));
594
pjsip_tx_data_dec_ref(tdata);
597
/* Check for X-Empty-Hdr */
598
param = pjsip_param_find(&uri->header_param, &hemptyname);
599
if (param == NULL || pj_strcmp2(¶m->value, "")!=0) {
600
PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header"));
601
pjsip_tx_data_dec_ref(tdata);
606
/* Check that headers are present in the request. */
607
hdr = (pjsip_generic_string_hdr*)
608
pjsip_msg_find_hdr_by_name(msg, &hname, NULL);
609
if (hdr == NULL || pj_strcmp2(&hdr->hvalue, "Header 1")!=0) {
610
PJ_LOG(3,(THIS_FILE, " error: header X-Hdr-1 not created"));
611
pjsip_tx_data_dec_ref(tdata);
615
hdr = (pjsip_generic_string_hdr*)
616
pjsip_msg_find_hdr_by_name(msg, &hemptyname, NULL);
617
if (hdr == NULL || pj_strcmp2(¶m->value, "")!=0) {
618
PJ_LOG(3,(THIS_FILE, " error: header X-Empty-Hdr not created"));
619
pjsip_tx_data_dec_ref(tdata);
623
pjsip_tx_data_dec_ref(tdata);
629
* create request benchmark
631
static int create_request_bench(pj_timestamp *p_elapsed)
633
enum { COUNT = 100 };
635
pjsip_tx_data *tdata[COUNT];
636
pj_timestamp t1, t2, elapsed;
639
pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
640
pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
641
pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
642
pj_str_t str_contact = str_from;
646
for (i=0; i<LOOP; i+=COUNT) {
647
pj_bzero(tdata, sizeof(tdata));
649
pj_get_timestamp(&t1);
651
for (j=0; j<COUNT; ++j) {
652
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
653
&str_target, &str_from, &str_to,
654
&str_contact, NULL, -1, NULL,
656
if (status != PJ_SUCCESS) {
657
app_perror(" error: unable to create request", status);
662
pj_get_timestamp(&t2);
663
pj_sub_timestamp(&t2, &t1);
664
pj_add_timestamp(&elapsed, &t2);
666
for (j=0; j<COUNT; ++j)
667
pjsip_tx_data_dec_ref(tdata[j]);
670
p_elapsed->u64 = elapsed.u64;
674
for (i=0; i<COUNT; ++i) {
676
pjsip_tx_data_dec_ref(tdata[i]);
684
* create response benchmark
686
static int create_response_bench(pj_timestamp *p_elapsed)
688
enum { COUNT = 100 };
692
pjsip_tx_data *request;
693
pjsip_tx_data *tdata[COUNT];
694
pj_timestamp t1, t2, elapsed;
697
/* Create the request first. */
698
pj_str_t str_target = pj_str("sip:someuser@someprovider.com");
699
pj_str_t str_from = pj_str("\"Local User\" <sip:localuser@serviceprovider.com>");
700
pj_str_t str_to = pj_str("\"Remote User\" <sip:remoteuser@serviceprovider.com>");
701
pj_str_t str_contact = str_from;
703
status = pjsip_endpt_create_request(endpt, &pjsip_invite_method,
704
&str_target, &str_from, &str_to,
705
&str_contact, NULL, -1, NULL,
707
if (status != PJ_SUCCESS) {
708
app_perror(" error: unable to create request", status);
712
/* Create several Via headers */
713
via = pjsip_via_hdr_create(request->pool);
714
via->sent_by.host = pj_str("192.168.0.7");
715
via->sent_by.port = 5061;
716
via->transport = pj_str("udp");
717
via->rport_param = 0;
718
via->branch_param = pj_str("012345678901234567890123456789");
719
via->recvd_param = pj_str("192.168.0.7");
720
pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*) pjsip_hdr_clone(request->pool, via));
721
pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*) pjsip_hdr_clone(request->pool, via));
722
pjsip_msg_insert_first_hdr(request->msg, (pjsip_hdr*)via);
725
/* Create "dummy" rdata from the tdata */
726
pj_bzero(&rdata, sizeof(pjsip_rx_data));
727
rdata.tp_info.pool = request->pool;
728
rdata.msg_info.msg = request->msg;
729
rdata.msg_info.from = (pjsip_from_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
730
rdata.msg_info.to = (pjsip_to_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_TO, NULL);
731
rdata.msg_info.cseq = (pjsip_cseq_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_CSEQ, NULL);
732
rdata.msg_info.cid = (pjsip_cid_hdr*) pjsip_msg_find_hdr(request->msg, PJSIP_H_FROM, NULL);
733
rdata.msg_info.via = via;
736
* Now benchmark create_response
740
for (i=0; i<LOOP; i+=COUNT) {
741
pj_bzero(tdata, sizeof(tdata));
743
pj_get_timestamp(&t1);
745
for (j=0; j<COUNT; ++j) {
746
status = pjsip_endpt_create_response(endpt, &rdata, 200, NULL, &tdata[j]);
747
if (status != PJ_SUCCESS) {
748
app_perror(" error: unable to create request", status);
753
pj_get_timestamp(&t2);
754
pj_sub_timestamp(&t2, &t1);
755
pj_add_timestamp(&elapsed, &t2);
757
for (j=0; j<COUNT; ++j)
758
pjsip_tx_data_dec_ref(tdata[j]);
761
p_elapsed->u64 = elapsed.u64;
762
pjsip_tx_data_dec_ref(request);
766
for (i=0; i<COUNT; ++i) {
768
pjsip_tx_data_dec_ref(tdata[i]);
774
int txdata_test(void)
778
pj_timestamp usec[REPEAT], min, freq;
781
status = pj_get_timestamp_freq(&freq);
782
if (status != PJ_SUCCESS)
785
status = core_txdata_test();
795
status = txdata_test_uri_params();
801
* Benchmark create_request()
803
PJ_LOG(3,(THIS_FILE, " benchmarking request creation:"));
804
for (i=0; i<REPEAT; ++i) {
805
PJ_LOG(3,(THIS_FILE, " test %d of %d..",
807
status = create_request_bench(&usec[i]);
808
if (status != PJ_SUCCESS)
812
min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
813
for (i=0; i<REPEAT; ++i) {
814
if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
817
msgs = (unsigned)(freq.u64 * LOOP / min.u64);
819
PJ_LOG(3,(THIS_FILE, " Requests created at %d requests/sec", msgs));
821
report_ival("create-request-per-sec",
823
"Number of typical request messages that can be created "
824
"per second with <tt>pjsip_endpt_create_request()</tt>");
828
* Benchmark create_response()
830
PJ_LOG(3,(THIS_FILE, " benchmarking response creation:"));
831
for (i=0; i<REPEAT; ++i) {
832
PJ_LOG(3,(THIS_FILE, " test %d of %d..",
834
status = create_response_bench(&usec[i]);
835
if (status != PJ_SUCCESS)
839
min.u64 = PJ_UINT64(0xFFFFFFFFFFFFFFF);
840
for (i=0; i<REPEAT; ++i) {
841
if (usec[i].u64 < min.u64) min.u64 = usec[i].u64;
844
msgs = (unsigned)(freq.u64 * LOOP / min.u64);
846
PJ_LOG(3,(THIS_FILE, " Responses created at %d responses/sec", msgs));
848
report_ival("create-response-per-sec",
850
"Number of typical response messages that can be created "
851
"per second with <tt>pjsip_endpt_create_response()</tt>");