~ubuntu-branches/ubuntu/wily/sflphone/wily-proposed

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.2.1/pjsip/src/pjsua2/siptypes.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: siptypes.cpp 4761 2014-02-24 09:02:44Z nanang $ */
 
2
/*
 
3
 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
 
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
#include <pjsua2/types.hpp>
 
20
#include <pjsua2/siptypes.hpp>
 
21
#include "util.hpp"
 
22
 
 
23
using namespace pj;
 
24
using namespace std;
 
25
 
 
26
#define THIS_FILE       "siptypes.cpp"
 
27
 
 
28
///////////////////////////////////////////////////////////////////////////////
 
29
namespace pj
 
30
{
 
31
void readIntVector( ContainerNode &node,
 
32
                    const string &array_name,
 
33
                    IntVector &v) throw(Error)
 
34
{
 
35
    ContainerNode array_node = node.readArray(array_name);
 
36
    v.resize(0);
 
37
    while (array_node.hasUnread()) {
 
38
        v.push_back((int)array_node.readNumber());
 
39
    }
 
40
}
 
41
 
 
42
void writeIntVector(ContainerNode &node,
 
43
                    const string &array_name,
 
44
                    const IntVector &v) throw(Error)
 
45
{
 
46
    ContainerNode array_node = node.writeNewArray(array_name);
 
47
    for (unsigned i=0; i<v.size(); ++i) {
 
48
        array_node.writeNumber("", (float)v[i]);
 
49
    }
 
50
}
 
51
 
 
52
void readQosParams( ContainerNode &node,
 
53
                    pj_qos_params &qos) throw(Error)
 
54
{
 
55
    ContainerNode this_node = node.readContainer("qosParams");
 
56
 
 
57
    NODE_READ_NUM_T( this_node, pj_uint8_t, qos.flags);
 
58
    NODE_READ_NUM_T( this_node, pj_uint8_t, qos.dscp_val);
 
59
    NODE_READ_NUM_T( this_node, pj_uint8_t, qos.so_prio);
 
60
    NODE_READ_NUM_T( this_node, pj_qos_wmm_prio, qos.wmm_prio);
 
61
}
 
62
 
 
63
void writeQosParams( ContainerNode &node,
 
64
                     const pj_qos_params &qos) throw(Error)
 
65
{
 
66
    ContainerNode this_node = node.writeNewContainer("qosParams");
 
67
 
 
68
    NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.flags);
 
69
    NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.dscp_val);
 
70
    NODE_WRITE_NUM_T( this_node, pj_uint8_t, qos.so_prio);
 
71
    NODE_WRITE_NUM_T( this_node, pj_qos_wmm_prio, qos.wmm_prio);
 
72
}
 
73
 
 
74
void readSipHeaders( const ContainerNode &node,
 
75
                     const string &array_name,
 
76
                     SipHeaderVector &headers) throw(Error)
 
77
{
 
78
    ContainerNode headers_node = node.readArray(array_name);
 
79
    headers.resize(0);
 
80
    while (headers_node.hasUnread()) {
 
81
        SipHeader hdr;
 
82
 
 
83
        ContainerNode header_node = headers_node.readContainer("header");
 
84
        hdr.hName = header_node.readString("hname");
 
85
        hdr.hValue = header_node.readString("hvalue");
 
86
        headers.push_back(hdr);
 
87
    }
 
88
}
 
89
 
 
90
void writeSipHeaders(ContainerNode &node,
 
91
                     const string &array_name,
 
92
                     const SipHeaderVector &headers) throw(Error)
 
93
{
 
94
    ContainerNode headers_node = node.writeNewArray(array_name);
 
95
    for (unsigned i=0; i<headers.size(); ++i) {
 
96
        ContainerNode header_node = headers_node.writeNewContainer("header");
 
97
        header_node.writeString("hname", headers[i].hName);
 
98
        header_node.writeString("hvalue", headers[i].hValue);
 
99
    }
 
100
}
 
101
 
 
102
} // namespace
 
103
///////////////////////////////////////////////////////////////////////////////
 
104
 
 
105
AuthCredInfo::AuthCredInfo()
 
106
: scheme("digest"), realm("*"), dataType(0)
 
107
{
 
108
}
 
109
 
 
110
AuthCredInfo::AuthCredInfo(const string &param_scheme,
 
111
                           const string &param_realm,
 
112
                           const string &param_user_name,
 
113
                           const int param_data_type,
 
114
                           const string param_data)
 
115
: scheme(param_scheme), realm(param_realm), username(param_user_name),
 
116
  dataType(param_data_type), data(param_data)
 
117
{
 
118
}
 
119
 
 
120
void AuthCredInfo::readObject(const ContainerNode &node) throw(Error)
 
121
{
 
122
    ContainerNode this_node = node.readContainer("AuthCredInfo");
 
123
 
 
124
    NODE_READ_STRING( this_node, scheme);
 
125
    NODE_READ_STRING( this_node, realm);
 
126
    NODE_READ_STRING( this_node, username);
 
127
    NODE_READ_INT   ( this_node, dataType);
 
128
    NODE_READ_STRING( this_node, data);
 
129
    NODE_READ_STRING( this_node, akaK);
 
130
    NODE_READ_STRING( this_node, akaOp);
 
131
    NODE_READ_STRING( this_node, akaAmf);
 
132
}
 
133
 
 
134
void AuthCredInfo::writeObject(ContainerNode &node) const throw(Error)
 
135
{
 
136
    ContainerNode this_node = node.writeNewContainer("AuthCredInfo");
 
137
 
 
138
    NODE_WRITE_STRING( this_node, scheme);
 
139
    NODE_WRITE_STRING( this_node, realm);
 
140
    NODE_WRITE_STRING( this_node, username);
 
141
    NODE_WRITE_INT   ( this_node, dataType);
 
142
    NODE_WRITE_STRING( this_node, data);
 
143
    NODE_WRITE_STRING( this_node, akaK);
 
144
    NODE_WRITE_STRING( this_node, akaOp);
 
145
    NODE_WRITE_STRING( this_node, akaAmf);
 
146
}
 
147
 
 
148
///////////////////////////////////////////////////////////////////////////////
 
149
 
 
150
TlsConfig::TlsConfig()
 
151
{
 
152
    pjsip_tls_setting ts;
 
153
    pjsip_tls_setting_default(&ts);
 
154
    this->fromPj(ts);
 
155
}
 
156
 
 
157
pjsip_tls_setting TlsConfig::toPj() const
 
158
{
 
159
    pjsip_tls_setting ts;
 
160
 
 
161
    ts.ca_list_file     = str2Pj(this->CaListFile);
 
162
    ts.cert_file        = str2Pj(this->certFile);
 
163
    ts.privkey_file     = str2Pj(this->privKeyFile);
 
164
    ts.password         = str2Pj(this->password);
 
165
    ts.method           = this->method;
 
166
    ts.ciphers_num      = (unsigned)this->ciphers.size();
 
167
    // The following will only work if sizeof(enum)==sizeof(int)
 
168
    pj_assert(sizeof(ts.ciphers[0]) == sizeof(int));
 
169
    ts.ciphers          = ts.ciphers_num? 
 
170
                            (pj_ssl_cipher*)&this->ciphers[0] : NULL;
 
171
    ts.verify_server    = this->verifyServer;
 
172
    ts.verify_client    = this->verifyClient;
 
173
    ts.require_client_cert = this->requireClientCert;
 
174
    ts.timeout.sec      = this->msecTimeout / 1000;
 
175
    ts.timeout.msec     = this->msecTimeout % 1000;
 
176
    ts.qos_type         = this->qosType;
 
177
    ts.qos_params       = this->qosParams;
 
178
    ts.qos_ignore_error = this->qosIgnoreError;
 
179
 
 
180
    return ts;
 
181
}
 
182
 
 
183
void TlsConfig::fromPj(const pjsip_tls_setting &prm)
 
184
{
 
185
    this->CaListFile    = pj2Str(prm.ca_list_file);
 
186
    this->certFile      = pj2Str(prm.cert_file);
 
187
    this->privKeyFile   = pj2Str(prm.privkey_file);
 
188
    this->password      = pj2Str(prm.password);
 
189
    this->method        = (pjsip_ssl_method)prm.method;
 
190
    // The following will only work if sizeof(enum)==sizeof(int)
 
191
    pj_assert(sizeof(prm.ciphers[0]) == sizeof(int));
 
192
    this->ciphers       = IntVector(prm.ciphers, prm.ciphers+prm.ciphers_num);
 
193
    this->verifyServer  = PJ2BOOL(prm.verify_server);
 
194
    this->verifyClient  = PJ2BOOL(prm.verify_client);
 
195
    this->requireClientCert = PJ2BOOL(prm.require_client_cert);
 
196
    this->msecTimeout   = PJ_TIME_VAL_MSEC(prm.timeout);
 
197
    this->qosType       = prm.qos_type;
 
198
    this->qosParams     = prm.qos_params;
 
199
    this->qosIgnoreError = PJ2BOOL(prm.qos_ignore_error);
 
200
}
 
201
 
 
202
void TlsConfig::readObject(const ContainerNode &node) throw(Error)
 
203
{
 
204
    ContainerNode this_node = node.readContainer("TlsConfig");
 
205
 
 
206
    NODE_READ_STRING  ( this_node, CaListFile);
 
207
    NODE_READ_STRING  ( this_node, certFile);
 
208
    NODE_READ_STRING  ( this_node, privKeyFile);
 
209
    NODE_READ_STRING  ( this_node, password);
 
210
    NODE_READ_NUM_T   ( this_node, pjsip_ssl_method, method);
 
211
    readIntVector     ( this_node, "ciphers", ciphers);
 
212
    NODE_READ_BOOL    ( this_node, verifyServer);
 
213
    NODE_READ_BOOL    ( this_node, verifyClient);
 
214
    NODE_READ_BOOL    ( this_node, requireClientCert);
 
215
    NODE_READ_UNSIGNED( this_node, msecTimeout);
 
216
    NODE_READ_NUM_T   ( this_node, pj_qos_type, qosType);
 
217
    readQosParams     ( this_node, qosParams);
 
218
    NODE_READ_BOOL    ( this_node, qosIgnoreError);
 
219
}
 
220
 
 
221
void TlsConfig::writeObject(ContainerNode &node) const throw(Error)
 
222
{
 
223
    ContainerNode this_node = node.writeNewContainer("TlsConfig");
 
224
 
 
225
    NODE_WRITE_STRING  ( this_node, CaListFile);
 
226
    NODE_WRITE_STRING  ( this_node, certFile);
 
227
    NODE_WRITE_STRING  ( this_node, privKeyFile);
 
228
    NODE_WRITE_STRING  ( this_node, password);
 
229
    NODE_WRITE_NUM_T   ( this_node, pjsip_ssl_method, method);
 
230
    writeIntVector     ( this_node, "ciphers", ciphers);
 
231
    NODE_WRITE_BOOL    ( this_node, verifyServer);
 
232
    NODE_WRITE_BOOL    ( this_node, verifyClient);
 
233
    NODE_WRITE_BOOL    ( this_node, requireClientCert);
 
234
    NODE_WRITE_UNSIGNED( this_node, msecTimeout);
 
235
    NODE_WRITE_NUM_T   ( this_node, pj_qos_type, qosType);
 
236
    writeQosParams     ( this_node, qosParams);
 
237
    NODE_WRITE_BOOL    ( this_node, qosIgnoreError);
 
238
}
 
239
 
 
240
///////////////////////////////////////////////////////////////////////////////
 
241
 
 
242
TransportConfig::TransportConfig()
 
243
{
 
244
    pjsua_transport_config tc;
 
245
    pjsua_transport_config_default(&tc);
 
246
    this->fromPj(tc);
 
247
}
 
248
 
 
249
void TransportConfig::fromPj(const pjsua_transport_config &prm)
 
250
{
 
251
    this->port          = prm.port;
 
252
    this->portRange     = prm.port_range;
 
253
    this->publicAddress = pj2Str(prm.public_addr);
 
254
    this->boundAddress  = pj2Str(prm.bound_addr);
 
255
    this->tlsConfig.fromPj(prm.tls_setting);
 
256
    this->qosType       = prm.qos_type;
 
257
    this->qosParams     = prm.qos_params;
 
258
}
 
259
 
 
260
pjsua_transport_config TransportConfig::toPj() const
 
261
{
 
262
    pjsua_transport_config tc;
 
263
 
 
264
    tc.port             = this->port;
 
265
    tc.port_range       = this->portRange;
 
266
    tc.public_addr      = str2Pj(this->publicAddress);
 
267
    tc.bound_addr       = str2Pj(this->boundAddress);
 
268
    tc.tls_setting      = this->tlsConfig.toPj();
 
269
    tc.qos_type         = this->qosType;
 
270
    tc.qos_params       = this->qosParams;
 
271
 
 
272
    return tc;
 
273
}
 
274
 
 
275
void TransportConfig::readObject(const ContainerNode &node) throw(Error)
 
276
{
 
277
    ContainerNode this_node = node.readContainer("TransportConfig");
 
278
 
 
279
    NODE_READ_UNSIGNED  ( this_node, port);
 
280
    NODE_READ_UNSIGNED  ( this_node, portRange);
 
281
    NODE_READ_STRING    ( this_node, publicAddress);
 
282
    NODE_READ_STRING    ( this_node, boundAddress);
 
283
    NODE_READ_NUM_T     ( this_node, pj_qos_type, qosType);
 
284
    readQosParams       ( this_node, qosParams);
 
285
    NODE_READ_OBJ       ( this_node, tlsConfig);
 
286
}
 
287
 
 
288
void TransportConfig::writeObject(ContainerNode &node) const throw(Error)
 
289
{
 
290
    ContainerNode this_node = node.writeNewContainer("TransportConfig");
 
291
 
 
292
    NODE_WRITE_UNSIGNED  ( this_node, port);
 
293
    NODE_WRITE_UNSIGNED  ( this_node, portRange);
 
294
    NODE_WRITE_STRING    ( this_node, publicAddress);
 
295
    NODE_WRITE_STRING    ( this_node, boundAddress);
 
296
    NODE_WRITE_NUM_T     ( this_node, pj_qos_type, qosType);
 
297
    writeQosParams       ( this_node, qosParams);
 
298
    NODE_WRITE_OBJ       ( this_node, tlsConfig);
 
299
}
 
300
 
 
301
///////////////////////////////////////////////////////////////////////////////
 
302
 
 
303
void TransportInfo::fromPj(const pjsua_transport_info &info)
 
304
{
 
305
    this->id = info.id;
 
306
    this->type = info.type;
 
307
    this->typeName = pj2Str(info.type_name);
 
308
    this->info = pj2Str(info.info);
 
309
    this->flags = info.flag;
 
310
 
 
311
    char straddr[PJ_INET6_ADDRSTRLEN+10];
 
312
    pj_sockaddr_print(&info.local_addr, straddr, sizeof(straddr), 3);
 
313
    this->localAddress = straddr;
 
314
 
 
315
    pj_ansi_snprintf(straddr, sizeof(straddr), "%.*s:%d",
 
316
                     (int)info.local_name.host.slen,
 
317
                     info.local_name.host.ptr,
 
318
                     info.local_name.port);
 
319
    this->localName = straddr;
 
320
    this->usageCount = info.usage_count;
 
321
}
 
322
 
 
323
///////////////////////////////////////////////////////////////////////////////
 
324
 
 
325
SipRxData::SipRxData()
 
326
: pjRxData(NULL)
 
327
{
 
328
}
 
329
 
 
330
void SipRxData::fromPj(pjsip_rx_data &rdata)
 
331
{
 
332
    char straddr[PJ_INET6_ADDRSTRLEN+10];
 
333
 
 
334
    info        = pjsip_rx_data_get_info(&rdata);
 
335
    wholeMsg    = string(rdata.msg_info.msg_buf, rdata.msg_info.len);
 
336
    pj_sockaddr_print(&rdata.pkt_info.src_addr, straddr, sizeof(straddr), 3);
 
337
    srcAddress  = straddr;
 
338
    pjRxData    = (void *)&rdata;
 
339
}
 
340
 
 
341
///////////////////////////////////////////////////////////////////////////////
 
342
 
 
343
void SipMediaType::fromPj(const pjsip_media_type &prm)
 
344
{
 
345
    type        = pj2Str(prm.type);
 
346
    subType     = pj2Str(prm.subtype);
 
347
}
 
348
 
 
349
pjsip_media_type SipMediaType::toPj() const
 
350
{
 
351
    pjsip_media_type pj_mt;
 
352
    pj_bzero(&pj_mt, sizeof(pj_mt));
 
353
    pj_mt.type      = str2Pj(type);
 
354
    pj_mt.subtype   = str2Pj(subType);
 
355
    return pj_mt;
 
356
}
 
357
 
 
358
///////////////////////////////////////////////////////////////////////////////
 
359
 
 
360
void SipHeader::fromPj(const pjsip_hdr *hdr) throw(Error)
 
361
{
 
362
    char buf[256];
 
363
 
 
364
    int len = pjsip_hdr_print_on((void*)hdr, buf, sizeof(buf)-1);
 
365
    if (len <= 0)
 
366
        PJSUA2_RAISE_ERROR(PJ_ETOOSMALL);
 
367
    buf[len] = '\0';
 
368
 
 
369
    char *pos = strchr(buf, ':');
 
370
    if (!pos)
 
371
        PJSUA2_RAISE_ERROR(PJSIP_EINVALIDHDR);
 
372
 
 
373
    // Trim white space after header name
 
374
    char *end_name = pos;
 
375
    while (end_name>buf && pj_isspace(*(end_name-1))) --end_name;
 
376
 
 
377
    // Trim whitespaces after colon
 
378
    char *start_val = pos+1;
 
379
    while (*start_val && pj_isspace(*start_val)) ++start_val;
 
380
 
 
381
    hName = string(buf, end_name);
 
382
    hValue = string(start_val);
 
383
}
 
384
 
 
385
pjsip_generic_string_hdr &SipHeader::toPj() const
 
386
{
 
387
    pj_str_t hname  = str2Pj(hName);
 
388
    pj_str_t hvalue = str2Pj(hValue);
 
389
 
 
390
    pjsip_generic_string_hdr_init2(&pjHdr, &hname, &hvalue);
 
391
    return pjHdr;
 
392
}
 
393
 
 
394
///////////////////////////////////////////////////////////////////////////////
 
395
 
 
396
void SipMultipartPart::fromPj(const pjsip_multipart_part &prm) throw(Error)
 
397
{
 
398
    headers.clear();
 
399
    pjsip_hdr* pj_hdr = prm.hdr.next;
 
400
    while (pj_hdr != &prm.hdr) {
 
401
        SipHeader sh;
 
402
        sh.fromPj(pj_hdr);
 
403
        headers.push_back(sh);
 
404
        pj_hdr = pj_hdr->next;
 
405
    }
 
406
 
 
407
    if (!prm.body)
 
408
        PJSUA2_RAISE_ERROR(PJ_EINVAL);
 
409
    
 
410
    contentType.fromPj(prm.body->content_type);
 
411
    body = string((char*)prm.body->data, prm.body->len);
 
412
}
 
413
 
 
414
pjsip_multipart_part& SipMultipartPart::toPj() const
 
415
{
 
416
    pj_list_init(&pjMpp.hdr);
 
417
    for (unsigned i = 0; i < headers.size(); i++) {
 
418
        pjsip_generic_string_hdr& pj_hdr = headers[i].toPj();
 
419
        pj_list_push_back(&pjMpp.hdr, &pj_hdr);
 
420
    }
 
421
 
 
422
    pj_bzero(&pjMsgBody, sizeof(pjMsgBody));
 
423
    pjMsgBody.content_type  = contentType.toPj();
 
424
    pjMsgBody.print_body    = &pjsip_print_text_body;
 
425
    pjMsgBody.clone_data    = &pjsip_clone_text_data;
 
426
    pjMsgBody.data          = (void*)body.c_str();
 
427
    pjMsgBody.len           = (unsigned)body.size();
 
428
    pjMpp.body = &pjMsgBody;
 
429
 
 
430
    return pjMpp;
 
431
}
 
432
 
 
433
///////////////////////////////////////////////////////////////////////////////
 
434
 
 
435
SipEvent::SipEvent()
 
436
: type(PJSIP_EVENT_UNKNOWN), pjEvent(NULL)
 
437
{
 
438
}
 
439
 
 
440
void SipEvent::fromPj(const pjsip_event &ev)
 
441
{
 
442
    type = ev.type;
 
443
    if (type == PJSIP_EVENT_TIMER) {
 
444
        body.timer.entry = ev.body.timer.entry;
 
445
    } else if (type == PJSIP_EVENT_TSX_STATE) {
 
446
        body.tsxState.prevState = (pjsip_tsx_state_e)
 
447
        ev.body.tsx_state.prev_state;
 
448
        body.tsxState.tsx.fromPj(*ev.body.tsx_state.tsx);
 
449
        if (body.tsxState.type == PJSIP_EVENT_TX_MSG) {
 
450
            if (ev.body.tsx_state.src.tdata)
 
451
                body.tsxState.src.tdata.fromPj(*ev.body.tsx_state.src.tdata);
 
452
        } else if (body.tsxState.type == PJSIP_EVENT_RX_MSG) {
 
453
            if (ev.body.tsx_state.src.rdata)
 
454
                body.tsxState.src.rdata.fromPj(*ev.body.tsx_state.src.rdata);
 
455
        } else if (body.tsxState.type == PJSIP_EVENT_TRANSPORT_ERROR) {
 
456
            body.tsxState.src.status = ev.body.tsx_state.src.status;
 
457
        } else if (body.tsxState.type == PJSIP_EVENT_TIMER) {
 
458
            body.tsxState.src.timer = ev.body.tsx_state.src.timer;
 
459
        } else if (body.tsxState.type == PJSIP_EVENT_USER) {
 
460
            body.tsxState.src.data = ev.body.tsx_state.src.data;
 
461
        }
 
462
    } else if (type == PJSIP_EVENT_TX_MSG) {
 
463
        if (ev.body.tx_msg.tdata)
 
464
            body.txMsg.tdata.fromPj(*ev.body.tx_msg.tdata);
 
465
    } else if (type == PJSIP_EVENT_RX_MSG) {
 
466
        if (ev.body.rx_msg.rdata)
 
467
            body.rxMsg.rdata.fromPj(*ev.body.rx_msg.rdata);
 
468
    } else if (type == PJSIP_EVENT_TRANSPORT_ERROR) {
 
469
        if (ev.body.tx_error.tdata)
 
470
            body.txError.tdata.fromPj(*ev.body.tx_error.tdata);
 
471
        if (ev.body.tx_error.tsx)
 
472
            body.txError.tsx.fromPj(*ev.body.tx_error.tsx);
 
473
    } else if (type == PJSIP_EVENT_USER) {
 
474
        body.user.user1 = ev.body.user.user1;
 
475
        body.user.user2 = ev.body.user.user2;
 
476
        body.user.user3 = ev.body.user.user3;
 
477
        body.user.user4 = ev.body.user.user4;
 
478
    }
 
479
    pjEvent = (void *)&ev;
 
480
}
 
481
 
 
482
SipTxData::SipTxData()
 
483
: pjTxData(NULL)
 
484
{
 
485
}
 
486
 
 
487
void SipTxData::fromPj(pjsip_tx_data &tdata)
 
488
{
 
489
    char straddr[PJ_INET6_ADDRSTRLEN+10];
 
490
    
 
491
    info        = pjsip_tx_data_get_info(&tdata);
 
492
    pjsip_tx_data_encode(&tdata);
 
493
    wholeMsg    = string(tdata.buf.start, tdata.buf.end - tdata.buf.start);
 
494
    if (pj_sockaddr_has_addr(&tdata.tp_info.dst_addr)) {
 
495
        pj_sockaddr_print(&tdata.tp_info.dst_addr, straddr, sizeof(straddr), 3);
 
496
        dstAddress  = straddr;
 
497
    } else {
 
498
        dstAddress = "";
 
499
    }
 
500
    pjTxData    = (void *)&tdata;
 
501
}
 
502
 
 
503
SipTransaction::SipTransaction()
 
504
: role(PJSIP_ROLE_UAC), statusCode(0), pjTransaction(NULL)
 
505
{
 
506
}
 
507
 
 
508
void SipTransaction::fromPj(pjsip_transaction &tsx)
 
509
{
 
510
    this->role          = tsx.role;
 
511
    this->method        = pj2Str(tsx.method.name);
 
512
    this->statusCode    = tsx.status_code;
 
513
    this->statusText    = pj2Str(tsx.status_text);
 
514
    if (tsx.last_tx)
 
515
        this->lastTx.fromPj(*tsx.last_tx);
 
516
    else
 
517
        this->lastTx.pjTxData = NULL;
 
518
    this->pjTransaction = (void *)&tsx;
 
519
}
 
520
 
 
521
bool SipTxOption::isEmpty() const
 
522
{
 
523
    return (targetUri == "" && headers.size() == 0 && contentType == "" &&
 
524
            msgBody == "" && multipartContentType.type == "" &&
 
525
            multipartContentType.subType == "" && multipartParts.size() == 0);
 
526
}
 
527
 
 
528
void SipTxOption::fromPj(const pjsua_msg_data &prm) throw(Error)
 
529
{
 
530
    targetUri = pj2Str(prm.target_uri);
 
531
 
 
532
    headers.clear();
 
533
    pjsip_hdr* pj_hdr = prm.hdr_list.next;
 
534
    while (pj_hdr != &prm.hdr_list) {
 
535
        SipHeader sh;
 
536
        sh.fromPj(pj_hdr);
 
537
        headers.push_back(sh);
 
538
        pj_hdr = pj_hdr->next;
 
539
    }
 
540
 
 
541
    contentType = pj2Str(prm.content_type);
 
542
    msgBody = pj2Str(prm.msg_body);
 
543
    multipartContentType.fromPj(prm.multipart_ctype);
 
544
 
 
545
    multipartParts.clear();
 
546
    pjsip_multipart_part* pj_mp = prm.multipart_parts.next;
 
547
    while (pj_mp != &prm.multipart_parts) {
 
548
        SipMultipartPart smp;
 
549
        smp.fromPj(*pj_mp);
 
550
        multipartParts.push_back(smp);
 
551
        pj_mp = pj_mp->next;
 
552
    }
 
553
}
 
554
 
 
555
void SipTxOption::toPj(pjsua_msg_data &msg_data) const
 
556
{
 
557
    unsigned i;
 
558
 
 
559
    pjsua_msg_data_init(&msg_data);
 
560
 
 
561
    msg_data.target_uri = str2Pj(targetUri);
 
562
 
 
563
    pj_list_init(&msg_data.hdr_list);
 
564
    for (i = 0; i < headers.size(); i++) {
 
565
        pjsip_generic_string_hdr& pj_hdr = headers[i].toPj();
 
566
        pj_list_push_back(&msg_data.hdr_list, &pj_hdr);
 
567
    }
 
568
 
 
569
    msg_data.content_type = str2Pj(contentType);
 
570
    msg_data.msg_body = str2Pj(msgBody);
 
571
    msg_data.multipart_ctype = multipartContentType.toPj();
 
572
 
 
573
    pj_list_init(&msg_data.multipart_parts);
 
574
    for (i = 0; i < multipartParts.size(); i++) {
 
575
        pjsip_multipart_part& pj_part = multipartParts[i].toPj();
 
576
        pj_list_push_back(&msg_data.multipart_parts, &pj_part);
 
577
    }
 
578
}
 
579
 
 
580
//////////////////////////////////////////////////////////////////////////////
 
581
 
 
582
SendInstantMessageParam::SendInstantMessageParam()
 
583
: contentType("text/plain"), content(""), userData(NULL)
 
584
{
 
585
}
 
586
 
 
587
SendTypingIndicationParam::SendTypingIndicationParam()
 
588
: isTyping(false)
 
589
{
 
590
}