blob: 37f36ce71557e050bcd78545ae6569b9d4c9c53f [file] [log] [blame]
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org>
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 <pjsua-lib/pjsua.h>
20#include <pjsua-lib/pjsua_internal.h>
21
22
23#define THIS_FILE "pjsua_acc.c"
24
25
26/*
27 * Get number of current accounts.
28 */
29PJ_DEF(unsigned) pjsua_acc_get_count(void)
30{
31 return pjsua_var.acc_cnt;
32}
33
34
35/*
36 * Check if the specified account ID is valid.
37 */
38PJ_DEF(pj_bool_t) pjsua_acc_is_valid(pjsua_acc_id acc_id)
39{
40 return acc_id>=0 && acc_id<PJ_ARRAY_SIZE(pjsua_var.acc) &&
41 pjsua_var.acc[acc_id].valid;
42}
43
44
45/*
Benny Prijono21b9ad92006-08-15 13:11:22 +000046 * Set default account
47 */
48PJ_DEF(pj_status_t) pjsua_acc_set_default(pjsua_acc_id acc_id)
49{
50 pjsua_var.default_acc = acc_id;
51 return PJ_SUCCESS;
52}
53
54
55/*
56 * Get default account.
57 */
58PJ_DEF(pjsua_acc_id) pjsua_acc_get_default(void)
59{
60 return pjsua_var.default_acc;
61}
62
63
64/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +000065 * Copy account configuration.
66 */
67static void copy_acc_config(pj_pool_t *pool,
68 pjsua_acc_config *dst,
69 const pjsua_acc_config *src)
70{
71 unsigned i;
72
73 pj_memcpy(dst, src, sizeof(pjsua_acc_config));
74
75 pj_strdup_with_null(pool, &dst->id, &src->id);
76 pj_strdup_with_null(pool, &dst->reg_uri, &src->reg_uri);
Benny Prijonob4a17c92006-07-10 14:40:21 +000077 pj_strdup_with_null(pool, &dst->force_contact, &src->force_contact);
Benny Prijonoeebe9af2006-06-13 22:57:13 +000078
79 dst->proxy_cnt = src->proxy_cnt;
80 for (i=0; i<src->proxy_cnt; ++i)
81 pj_strdup_with_null(pool, &dst->proxy[i], &src->proxy[i]);
82
83 dst->reg_timeout = src->reg_timeout;
84 dst->cred_count = src->cred_count;
85
86 for (i=0; i<src->cred_count; ++i) {
87 pjsip_cred_dup(pool, &dst->cred_info[i], &src->cred_info[i]);
88 }
89}
90
91
92/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +000093 * Initialize a new account (after configuration is set).
94 */
95static pj_status_t initialize_acc(unsigned acc_id)
96{
97 pjsua_acc_config *acc_cfg = &pjsua_var.acc[acc_id].cfg;
98 pjsua_acc *acc = &pjsua_var.acc[acc_id];
Benny Prijonoc570f2d2006-07-18 00:33:02 +000099 pjsip_name_addr *name_addr;
Benny Prijonob4a17c92006-07-10 14:40:21 +0000100 pjsip_sip_uri *sip_uri, *sip_reg_uri;
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000101 pj_status_t status;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000102 unsigned i;
103
104 /* Need to parse local_uri to get the elements: */
105
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000106 name_addr = (pjsip_name_addr*)
107 pjsip_parse_uri(pjsua_var.pool, acc_cfg->id.ptr,
108 acc_cfg->id.slen,
109 PJSIP_PARSE_URI_AS_NAMEADDR);
110 if (name_addr == NULL) {
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000111 pjsua_perror(THIS_FILE, "Invalid local URI",
112 PJSIP_EINVALIDURI);
113 return PJSIP_EINVALIDURI;
114 }
115
116 /* Local URI MUST be a SIP or SIPS: */
117
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000118 if (!PJSIP_URI_SCHEME_IS_SIP(name_addr) &&
119 !PJSIP_URI_SCHEME_IS_SIPS(name_addr))
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000120 {
121 pjsua_perror(THIS_FILE, "Invalid local URI",
122 PJSIP_EINVALIDSCHEME);
123 return PJSIP_EINVALIDSCHEME;
124 }
125
126
127 /* Get the SIP URI object: */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000128 sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(name_addr);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000129
Benny Prijonob4a17c92006-07-10 14:40:21 +0000130
131 /* Parse registrar URI, if any */
132 if (acc_cfg->reg_uri.slen) {
133 pjsip_uri *reg_uri;
134
135 reg_uri = pjsip_parse_uri(pjsua_var.pool, acc_cfg->reg_uri.ptr,
136 acc_cfg->reg_uri.slen, 0);
137 if (reg_uri == NULL) {
138 pjsua_perror(THIS_FILE, "Invalid registrar URI",
139 PJSIP_EINVALIDURI);
140 return PJSIP_EINVALIDURI;
141 }
142
143 /* Registrar URI MUST be a SIP or SIPS: */
144 if (!PJSIP_URI_SCHEME_IS_SIP(reg_uri) &&
145 !PJSIP_URI_SCHEME_IS_SIPS(reg_uri))
146 {
147 pjsua_perror(THIS_FILE, "Invalid registar URI",
148 PJSIP_EINVALIDSCHEME);
149 return PJSIP_EINVALIDSCHEME;
150 }
151
152 sip_reg_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(reg_uri);
153
154 } else {
155 sip_reg_uri = NULL;
156 }
157
158
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000159 /* Save the user and domain part. These will be used when finding an
160 * account for incoming requests.
161 */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000162 acc->display = name_addr->display;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000163 acc->user_part = sip_uri->user;
Benny Prijonob4a17c92006-07-10 14:40:21 +0000164 acc->srv_domain = sip_uri->host;
165 acc->srv_port = 0;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000166
Benny Prijonob4a17c92006-07-10 14:40:21 +0000167 if (sip_reg_uri) {
168 acc->srv_port = sip_reg_uri->port;
169 }
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000170
171 /* Create Contact header if not present. */
Benny Prijonob4a17c92006-07-10 14:40:21 +0000172 //if (acc_cfg->contact.slen == 0) {
173 // acc_cfg->contact = acc_cfg->id;
174 //}
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000175
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000176 /* Build account route-set from outbound proxies and route set from
177 * account configuration.
178 */
179 pj_list_init(&acc->route_set);
180
181 for (i=0; i<pjsua_var.ua_cfg.outbound_proxy_cnt; ++i) {
182 pj_str_t hname = { "Route", 5};
183 pjsip_route_hdr *r;
184 pj_str_t tmp;
185
186 pj_strdup_with_null(pjsua_var.pool, &tmp,
187 &pjsua_var.ua_cfg.outbound_proxy[i]);
188 r = pjsip_parse_hdr(pjsua_var.pool, &hname, tmp.ptr, tmp.slen, NULL);
189 if (r == NULL) {
190 pjsua_perror(THIS_FILE, "Invalid outbound proxy URI",
191 PJSIP_EINVALIDURI);
192 return PJSIP_EINVALIDURI;
193 }
194 pj_list_push_back(&acc->route_set, r);
195 }
196
197 for (i=0; i<acc_cfg->proxy_cnt; ++i) {
198 pj_str_t hname = { "Route", 5};
199 pjsip_route_hdr *r;
200 pj_str_t tmp;
201
202 pj_strdup_with_null(pjsua_var.pool, &tmp, &acc_cfg->proxy[i]);
203 r = pjsip_parse_hdr(pjsua_var.pool, &hname, tmp.ptr, tmp.slen, NULL);
204 if (r == NULL) {
205 pjsua_perror(THIS_FILE, "Invalid URI in account route set",
206 PJ_EINVAL);
207 return PJ_EINVAL;
208 }
209 pj_list_push_back(&acc->route_set, r);
210 }
211
212
213 /* Concatenate credentials from account config and global config */
214 acc->cred_cnt = 0;
215 for (i=0; i<acc_cfg->cred_count; ++i) {
216 acc->cred[acc->cred_cnt++] = acc_cfg->cred_info[i];
217 }
218 for (i=0; i<pjsua_var.ua_cfg.cred_count &&
219 acc->cred_cnt < PJ_ARRAY_SIZE(acc->cred); ++i)
220 {
221 acc->cred[acc->cred_cnt++] = pjsua_var.ua_cfg.cred_info[i];
222 }
223
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000224 status = pjsua_pres_init_acc(acc_id);
225 if (status != PJ_SUCCESS)
226 return status;
227
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000228 /* Mark account as valid */
229 pjsua_var.acc[acc_id].valid = PJ_TRUE;
230
Benny Prijono093d3022006-09-24 00:07:11 +0000231 /* Insert account ID into account ID array, sorted by priority */
232 for (i=0; i<pjsua_var.acc_cnt; ++i) {
233 if ( pjsua_var.acc[pjsua_var.acc_ids[i]].cfg.priority <
234 pjsua_var.acc[acc_id].cfg.priority)
235 {
236 break;
237 }
238 }
239 pj_array_insert(pjsua_var.acc_ids, sizeof(pjsua_var.acc_ids[0]),
240 pjsua_var.acc_cnt, i, &acc_id);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000241
242 return PJ_SUCCESS;
243}
244
245
246/*
247 * Add a new account to pjsua.
248 */
249PJ_DEF(pj_status_t) pjsua_acc_add( const pjsua_acc_config *cfg,
250 pj_bool_t is_default,
251 pjsua_acc_id *p_acc_id)
252{
253 unsigned id;
254 pj_status_t status;
255
256 PJ_ASSERT_RETURN(pjsua_var.acc_cnt < PJ_ARRAY_SIZE(pjsua_var.acc),
257 PJ_ETOOMANY);
258
259 /* Must have a transport */
Benny Prijonoe93e2872006-06-28 16:46:49 +0000260 PJ_ASSERT_RETURN(pjsua_var.tpdata[0].data.ptr != NULL, PJ_EINVALIDOP);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000261
262 PJSUA_LOCK();
263
264 /* Find empty account id. */
265 for (id=0; id < PJ_ARRAY_SIZE(pjsua_var.acc); ++id) {
266 if (pjsua_var.acc[id].valid == PJ_FALSE)
267 break;
268 }
269
270 /* Expect to find a slot */
271 PJ_ASSERT_ON_FAIL( id < PJ_ARRAY_SIZE(pjsua_var.acc),
272 {PJSUA_UNLOCK(); return PJ_EBUG;});
273
274 /* Copy config */
275 copy_acc_config(pjsua_var.pool, &pjsua_var.acc[id].cfg, cfg);
276
277 /* Normalize registration timeout */
278 if (pjsua_var.acc[id].cfg.reg_uri.slen &&
279 pjsua_var.acc[id].cfg.reg_timeout == 0)
280 {
281 pjsua_var.acc[id].cfg.reg_timeout = PJSUA_REG_INTERVAL;
282 }
283
284 status = initialize_acc(id);
285 if (status != PJ_SUCCESS) {
286 pjsua_perror(THIS_FILE, "Error adding account", status);
287 PJSUA_UNLOCK();
288 return status;
289 }
290
291 if (is_default)
292 pjsua_var.default_acc = id;
293
294 if (p_acc_id)
295 *p_acc_id = id;
296
297 pjsua_var.acc_cnt++;
298
299 PJSUA_UNLOCK();
300
301 PJ_LOG(4,(THIS_FILE, "Account %.*s added with id %d",
302 (int)cfg->id.slen, cfg->id.ptr, id));
303
304 /* If accounts has registration enabled, start registration */
305 if (pjsua_var.acc[id].cfg.reg_uri.slen)
306 pjsua_acc_set_registration(id, PJ_TRUE);
307
308
309 return PJ_SUCCESS;
310}
311
312
313/*
314 * Add local account
315 */
316PJ_DEF(pj_status_t) pjsua_acc_add_local( pjsua_transport_id tid,
317 pj_bool_t is_default,
318 pjsua_acc_id *p_acc_id)
319{
320 pjsua_acc_config cfg;
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000321 pjsua_transport_data *t = &pjsua_var.tpdata[tid];
Benny Prijonoe85bc412006-07-29 20:29:24 +0000322 char uri[PJSIP_MAX_URL_SIZE];
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000323
Benny Prijonoe93e2872006-06-28 16:46:49 +0000324 /* ID must be valid */
325 PJ_ASSERT_RETURN(tid>=0 && tid<PJ_ARRAY_SIZE(pjsua_var.tpdata), PJ_EINVAL);
326
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000327 /* Transport must be valid */
Benny Prijonoe93e2872006-06-28 16:46:49 +0000328 PJ_ASSERT_RETURN(t->data.ptr != NULL, PJ_EINVAL);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000329
330 pjsua_acc_config_default(&cfg);
331
Benny Prijono093d3022006-09-24 00:07:11 +0000332 /* Lower the priority of local account */
333 --cfg.priority;
334
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000335 /* Build URI for the account */
Benny Prijonoe85bc412006-07-29 20:29:24 +0000336 pj_ansi_snprintf(uri, PJSIP_MAX_URL_SIZE,
337 "<sip:%.*s:%d;transport=%s>",
338 (int)t->local_name.host.slen,
339 t->local_name.host.ptr,
340 t->local_name.port,
341 pjsip_transport_get_type_name(t->type));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000342
343 cfg.id = pj_str(uri);
344
345 return pjsua_acc_add(&cfg, is_default, p_acc_id);
346}
347
348
349/*
350 * Delete account.
351 */
352PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id)
353{
Benny Prijono093d3022006-09-24 00:07:11 +0000354 unsigned i;
355
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000356 PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
357 PJ_EINVAL);
358 PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
359
360 PJSUA_LOCK();
361
362 /* Delete registration */
363 if (pjsua_var.acc[acc_id].regc != NULL)
364 pjsua_acc_set_registration(acc_id, PJ_FALSE);
365
366 /* Delete server presence subscription */
367 pjsua_pres_delete_acc(acc_id);
368
369 /* Invalidate */
370 pjsua_var.acc[acc_id].valid = PJ_FALSE;
371
Benny Prijono093d3022006-09-24 00:07:11 +0000372 /* Remove from array */
373 for (i=0; i<pjsua_var.acc_cnt; ++i) {
374 if (pjsua_var.acc_ids[i] == acc_id)
375 break;
376 }
377 if (i != pjsua_var.acc_cnt) {
378 pj_array_erase(pjsua_var.acc_ids, sizeof(pjsua_var.acc_ids[0]),
379 pjsua_var.acc_cnt, i);
380 --pjsua_var.acc_cnt;
381 }
382
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000383 /* Leave the calls intact, as I don't think calls need to
384 * access account once it's created
385 */
386
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000387
388 PJSUA_UNLOCK();
389
390 PJ_LOG(4,(THIS_FILE, "Account id %d deleted", acc_id));
391
392 return PJ_SUCCESS;
393}
394
395
396/*
397 * Modify account information.
398 */
399PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id,
400 const pjsua_acc_config *cfg)
401{
402 PJ_TODO(pjsua_acc_modify);
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000403 PJ_UNUSED_ARG(acc_id);
404 PJ_UNUSED_ARG(cfg);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000405 return PJ_EINVALIDOP;
406}
407
408
409/*
410 * Modify account's presence status to be advertised to remote/presence
411 * subscribers.
412 */
413PJ_DEF(pj_status_t) pjsua_acc_set_online_status( pjsua_acc_id acc_id,
414 pj_bool_t is_online)
415{
416 PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
417 PJ_EINVAL);
418 PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
419
420 pjsua_var.acc[acc_id].online_status = is_online;
421 pjsua_pres_refresh();
422 return PJ_SUCCESS;
423}
424
425
426/*
427 * This callback is called by pjsip_regc when outgoing register
428 * request has completed.
429 */
430static void regc_cb(struct pjsip_regc_cbparam *param)
431{
432
433 pjsua_acc *acc = param->token;
434
435 PJSUA_LOCK();
436
437 /*
438 * Print registration status.
439 */
440 if (param->status!=PJ_SUCCESS) {
441 pjsua_perror(THIS_FILE, "SIP registration error",
442 param->status);
443 pjsip_regc_destroy(acc->regc);
444 acc->regc = NULL;
445
446 } else if (param->code < 0 || param->code >= 300) {
447 PJ_LOG(2, (THIS_FILE, "SIP registration failed, status=%d (%.*s)",
448 param->code,
449 (int)param->reason.slen, param->reason.ptr));
450 pjsip_regc_destroy(acc->regc);
451 acc->regc = NULL;
452
453 } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) {
454
455 if (param->expiration < 1) {
456 pjsip_regc_destroy(acc->regc);
457 acc->regc = NULL;
458 PJ_LOG(3,(THIS_FILE, "%s: unregistration success",
459 pjsua_var.acc[acc->index].cfg.id.ptr));
460 } else {
461 PJ_LOG(3, (THIS_FILE,
462 "%s: registration success, status=%d (%.*s), "
463 "will re-register in %d seconds",
464 pjsua_var.acc[acc->index].cfg.id.ptr,
465 param->code,
466 (int)param->reason.slen, param->reason.ptr,
467 param->expiration));
468 }
469
470 } else {
471 PJ_LOG(4, (THIS_FILE, "SIP registration updated status=%d", param->code));
472 }
473
474 acc->reg_last_err = param->status;
475 acc->reg_last_code = param->code;
476
477 if (pjsua_var.ua_cfg.cb.on_reg_state)
478 (*pjsua_var.ua_cfg.cb.on_reg_state)(acc->index);
479
480 PJSUA_UNLOCK();
481}
482
483
484/*
485 * Initialize client registration.
486 */
487static pj_status_t pjsua_regc_init(int acc_id)
488{
489 pjsua_acc *acc;
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000490 pj_str_t contact;
Benny Prijonodfb7d482006-10-18 20:35:14 +0000491 char contact_buf[1024];
Benny Prijonoe1a8bad2006-10-13 17:45:38 +0000492 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000493 pj_status_t status;
494
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000495 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000496 acc = &pjsua_var.acc[acc_id];
497
498 if (acc->cfg.reg_uri.slen == 0) {
499 PJ_LOG(3,(THIS_FILE, "Registrar URI is not specified"));
500 return PJ_SUCCESS;
501 }
502
Benny Prijonoe1a8bad2006-10-13 17:45:38 +0000503 /* Destroy existing session, if any */
504 if (acc->regc) {
505 pjsip_regc_destroy(acc->regc);
506 acc->regc = NULL;
507 }
508
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000509 /* initialize SIP registration if registrar is configured */
510
511 status = pjsip_regc_create( pjsua_var.endpt,
512 acc, &regc_cb, &acc->regc);
513
514 if (status != PJ_SUCCESS) {
515 pjsua_perror(THIS_FILE, "Unable to create client registration",
516 status);
517 return status;
518 }
519
Benny Prijonoe1a8bad2006-10-13 17:45:38 +0000520 pool = pj_pool_create_on_buf(NULL, contact_buf, sizeof(contact_buf));
521 status = pjsua_acc_create_uac_contact( pool, &contact,
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000522 acc_id, &acc->cfg.reg_uri);
523 if (status != PJ_SUCCESS) {
524 pjsua_perror(THIS_FILE, "Unable to generate suitable Contact header"
525 " for registration",
526 status);
527 return status;
528 }
529
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000530 status = pjsip_regc_init( acc->regc,
531 &acc->cfg.reg_uri,
532 &acc->cfg.id,
533 &acc->cfg.id,
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000534 1, &contact,
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000535 acc->cfg.reg_timeout);
536 if (status != PJ_SUCCESS) {
537 pjsua_perror(THIS_FILE,
538 "Client registration initialization error",
539 status);
540 return status;
541 }
542
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000543 /* If account is locked to specific transport, then set transport to
544 * the client registration.
545 */
546 if (pjsua_var.acc[acc_id].cfg.transport_id != PJSUA_INVALID_ID) {
547 pjsip_tpselector tp_sel;
548
549 pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel);
550 pjsip_regc_set_transport(acc->regc, &tp_sel);
551 }
552
553
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000554 /* Set credentials
555 */
556 if (acc->cred_cnt) {
557 pjsip_regc_set_credentials( acc->regc, acc->cred_cnt, acc->cred);
558 }
559
560 /* Set route-set
561 */
562 if (!pj_list_empty(&acc->route_set)) {
563 pjsip_regc_set_route_set( acc->regc, &acc->route_set );
564 }
565
Benny Prijono8fc6de02006-11-11 21:25:55 +0000566 /* Add other request headers. */
567 if (pjsua_var.ua_cfg.user_agent.slen) {
568 pjsip_hdr hdr_list;
569 const pj_str_t STR_USER_AGENT = { "User-Agent", 10 };
570 pjsip_generic_string_hdr *h;
571
572 pool = pj_pool_create_on_buf(NULL, contact_buf, sizeof(contact_buf));
573 pj_list_init(&hdr_list);
574
575 h = pjsip_generic_string_hdr_create(pool, &STR_USER_AGENT,
576 &pjsua_var.ua_cfg.user_agent);
577 pj_list_push_back(&hdr_list, (pjsip_hdr*)h);
578
579 pjsip_regc_add_headers(acc->regc, &hdr_list);
580 }
581
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000582 return PJ_SUCCESS;
583}
584
585
586/*
587 * Update registration or perform unregistration.
588 */
589PJ_DEF(pj_status_t) pjsua_acc_set_registration( pjsua_acc_id acc_id,
590 pj_bool_t renew)
591{
592 pj_status_t status = 0;
593 pjsip_tx_data *tdata = 0;
594
595 PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
596 PJ_EINVAL);
597 PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
598
599 PJSUA_LOCK();
600
601 if (renew) {
602 if (pjsua_var.acc[acc_id].regc == NULL) {
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000603 status = pjsua_regc_init(acc_id);
604 if (status != PJ_SUCCESS) {
605 pjsua_perror(THIS_FILE, "Unable to create registration",
606 status);
607 goto on_return;
608 }
609 }
610 if (!pjsua_var.acc[acc_id].regc) {
611 status = PJ_EINVALIDOP;
612 goto on_return;
613 }
614
615 status = pjsip_regc_register(pjsua_var.acc[acc_id].regc, 1,
616 &tdata);
617
618 } else {
619 if (pjsua_var.acc[acc_id].regc == NULL) {
620 PJ_LOG(3,(THIS_FILE, "Currently not registered"));
621 status = PJ_EINVALIDOP;
622 goto on_return;
623 }
624 status = pjsip_regc_unregister(pjsua_var.acc[acc_id].regc, &tdata);
625 }
626
Benny Prijono56315612006-07-18 14:39:40 +0000627 if (status == PJ_SUCCESS) {
Benny Prijono8fc6de02006-11-11 21:25:55 +0000628 //pjsua_process_msg_data(tdata, NULL);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000629 status = pjsip_regc_send( pjsua_var.acc[acc_id].regc, tdata );
Benny Prijono56315612006-07-18 14:39:40 +0000630 }
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000631
632 if (status != PJ_SUCCESS) {
633 pjsua_perror(THIS_FILE, "Unable to create/send REGISTER",
634 status);
635 } else {
636 PJ_LOG(3,(THIS_FILE, "%s sent",
637 (renew? "Registration" : "Unregistration")));
638 }
639
640on_return:
641 PJSUA_UNLOCK();
642 return status;
643}
644
645
646/*
647 * Get account information.
648 */
649PJ_DEF(pj_status_t) pjsua_acc_get_info( pjsua_acc_id acc_id,
650 pjsua_acc_info *info)
651{
652 pjsua_acc *acc = &pjsua_var.acc[acc_id];
653 pjsua_acc_config *acc_cfg = &pjsua_var.acc[acc_id].cfg;
654
655 PJ_ASSERT_RETURN(info != NULL, PJ_EINVAL);
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000656 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000657
Benny Prijonoac623b32006-07-03 15:19:31 +0000658 pj_bzero(info, sizeof(pjsua_acc_info));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000659
660 PJ_ASSERT_RETURN(acc_id>=0 && acc_id<(int)PJ_ARRAY_SIZE(pjsua_var.acc),
661 PJ_EINVAL);
662 PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
663
664 PJSUA_LOCK();
665
666 if (pjsua_var.acc[acc_id].valid == PJ_FALSE) {
667 PJSUA_UNLOCK();
668 return PJ_EINVALIDOP;
669 }
670
671 info->id = acc_id;
672 info->is_default = (pjsua_var.default_acc == acc_id);
673 info->acc_uri = acc_cfg->id;
674 info->has_registration = (acc->cfg.reg_uri.slen > 0);
675 info->online_status = acc->online_status;
676
677 if (acc->reg_last_err) {
678 info->status = acc->reg_last_err;
679 pj_strerror(acc->reg_last_err, info->buf_, sizeof(info->buf_));
680 info->status_text = pj_str(info->buf_);
681 } else if (acc->reg_last_code) {
Benny Prijono6f979412006-06-15 12:25:46 +0000682 if (info->has_registration) {
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000683 info->status = acc->reg_last_code;
684 info->status_text = *pjsip_get_status_text(acc->reg_last_code);
685 } else {
686 info->status = 0;
687 info->status_text = pj_str("not registered");
688 }
689 } else if (acc->cfg.reg_uri.slen) {
690 info->status = 100;
691 info->status_text = pj_str("In Progress");
692 } else {
693 info->status = 0;
694 info->status_text = pj_str("does not register");
695 }
696
697 if (acc->regc) {
698 pjsip_regc_info regc_info;
699 pjsip_regc_get_info(acc->regc, &regc_info);
700 info->expires = regc_info.next_reg;
701 } else {
702 info->expires = -1;
703 }
704
705 PJSUA_UNLOCK();
706
707 return PJ_SUCCESS;
708
709}
710
711
712/*
713 * Enum accounts all account ids.
714 */
715PJ_DEF(pj_status_t) pjsua_enum_accs(pjsua_acc_id ids[],
716 unsigned *count )
717{
718 unsigned i, c;
719
720 PJ_ASSERT_RETURN(ids && *count, PJ_EINVAL);
721
722 PJSUA_LOCK();
723
724 for (i=0, c=0; c<*count && i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) {
725 if (!pjsua_var.acc[i].valid)
726 continue;
727 ids[c] = i;
728 ++c;
729 }
730
731 *count = c;
732
733 PJSUA_UNLOCK();
734
735 return PJ_SUCCESS;
736}
737
738
739/*
740 * Enum accounts info.
741 */
742PJ_DEF(pj_status_t) pjsua_acc_enum_info( pjsua_acc_info info[],
743 unsigned *count )
744{
745 unsigned i, c;
746
747 PJ_ASSERT_RETURN(info && *count, PJ_EINVAL);
748
749 PJSUA_LOCK();
750
751 for (i=0, c=0; c<*count && i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) {
752 if (!pjsua_var.acc[i].valid)
753 continue;
754
755 pjsua_acc_get_info(i, &info[c]);
756 ++c;
757 }
758
759 *count = c;
760
761 PJSUA_UNLOCK();
762
763 return PJ_SUCCESS;
764}
765
766
767/*
768 * This is an internal function to find the most appropriate account to
769 * used to reach to the specified URL.
770 */
771PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_outgoing(const pj_str_t *url)
772{
773 pj_str_t tmp;
774 pjsip_uri *uri;
775 pjsip_sip_uri *sip_uri;
Benny Prijono093d3022006-09-24 00:07:11 +0000776 unsigned i;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000777
778 PJSUA_LOCK();
779
780 PJ_TODO(dont_use_pjsua_pool);
781
782 pj_strdup_with_null(pjsua_var.pool, &tmp, url);
783
784 uri = pjsip_parse_uri(pjsua_var.pool, tmp.ptr, tmp.slen, 0);
785 if (!uri) {
Benny Prijono093d3022006-09-24 00:07:11 +0000786 PJSUA_UNLOCK();
787 return pjsua_var.default_acc;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000788 }
789
790 if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
791 !PJSIP_URI_SCHEME_IS_SIPS(uri))
792 {
793 /* Return the first account with proxy */
Benny Prijono093d3022006-09-24 00:07:11 +0000794 for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) {
795 if (!pjsua_var.acc[i].valid)
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000796 continue;
Benny Prijono093d3022006-09-24 00:07:11 +0000797 if (!pj_list_empty(&pjsua_var.acc[i].route_set))
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000798 break;
799 }
800
Benny Prijono093d3022006-09-24 00:07:11 +0000801 if (i != PJ_ARRAY_SIZE(pjsua_var.acc)) {
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000802 /* Found rather matching account */
Benny Prijono093d3022006-09-24 00:07:11 +0000803 PJSUA_UNLOCK();
804 return 0;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000805 }
806
807 /* Not found, use default account */
Benny Prijono093d3022006-09-24 00:07:11 +0000808 PJSUA_UNLOCK();
809 return pjsua_var.default_acc;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000810 }
811
812 sip_uri = pjsip_uri_get_uri(uri);
813
Benny Prijonob4a17c92006-07-10 14:40:21 +0000814 /* Find matching domain AND port */
Benny Prijono093d3022006-09-24 00:07:11 +0000815 for (i=0; i<pjsua_var.acc_cnt; ++i) {
816 unsigned acc_id = pjsua_var.acc_ids[i];
817 if (pj_stricmp(&pjsua_var.acc[acc_id].srv_domain, &sip_uri->host)==0 &&
818 pjsua_var.acc[acc_id].srv_port == sip_uri->port)
819 {
820 PJSUA_UNLOCK();
821 return acc_id;
Benny Prijono21b9ad92006-08-15 13:11:22 +0000822 }
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000823 }
824
Benny Prijonob4a17c92006-07-10 14:40:21 +0000825 /* If no match, try to match the domain part only */
Benny Prijono093d3022006-09-24 00:07:11 +0000826 for (i=0; i<pjsua_var.acc_cnt; ++i) {
827 unsigned acc_id = pjsua_var.acc_ids[i];
828 if (pj_stricmp(&pjsua_var.acc[acc_id].srv_domain, &sip_uri->host)==0)
829 {
830 PJSUA_UNLOCK();
831 return acc_id;
Benny Prijonob4a17c92006-07-10 14:40:21 +0000832 }
833 }
834
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000835
Benny Prijono093d3022006-09-24 00:07:11 +0000836 /* Still no match, just use default account */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000837 PJSUA_UNLOCK();
Benny Prijono093d3022006-09-24 00:07:11 +0000838 return pjsua_var.default_acc;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000839}
840
841
842/*
843 * This is an internal function to find the most appropriate account to be
844 * used to handle incoming calls.
845 */
846PJ_DEF(pjsua_acc_id) pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)
847{
848 pjsip_uri *uri;
849 pjsip_sip_uri *sip_uri;
Benny Prijono093d3022006-09-24 00:07:11 +0000850 unsigned i;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000851
852 uri = rdata->msg_info.to->uri;
853
854 /* Just return default account if To URI is not SIP: */
855 if (!PJSIP_URI_SCHEME_IS_SIP(uri) &&
856 !PJSIP_URI_SCHEME_IS_SIPS(uri))
857 {
858 return pjsua_var.default_acc;
859 }
860
861
862 PJSUA_LOCK();
863
864 sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri);
865
866 /* Find account which has matching username and domain. */
Benny Prijono093d3022006-09-24 00:07:11 +0000867 for (i=0; i < pjsua_var.acc_cnt; ++i) {
868 unsigned acc_id = pjsua_var.acc_ids[i];
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000869 pjsua_acc *acc = &pjsua_var.acc[acc_id];
870
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000871 if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0 &&
Benny Prijonob4a17c92006-07-10 14:40:21 +0000872 pj_stricmp(&acc->srv_domain, &sip_uri->host)==0)
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000873 {
874 /* Match ! */
875 PJSUA_UNLOCK();
876 return acc_id;
877 }
878 }
879
Benny Prijono093d3022006-09-24 00:07:11 +0000880 /* No matching account, try match domain part only. */
881 for (i=0; i < pjsua_var.acc_cnt; ++i) {
882 unsigned acc_id = pjsua_var.acc_ids[i];
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000883 pjsua_acc *acc = &pjsua_var.acc[acc_id];
884
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000885 if (acc->valid && pj_stricmp(&acc->srv_domain, &sip_uri->host)==0) {
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000886 /* Match ! */
887 PJSUA_UNLOCK();
888 return acc_id;
889 }
890 }
891
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000892 /* No matching account, try match user part (and transport type) only. */
Benny Prijono093d3022006-09-24 00:07:11 +0000893 for (i=0; i < pjsua_var.acc_cnt; ++i) {
894 unsigned acc_id = pjsua_var.acc_ids[i];
895 pjsua_acc *acc = &pjsua_var.acc[acc_id];
896
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000897 if (acc->valid && pj_stricmp(&acc->user_part, &sip_uri->user)==0) {
898
899 if (acc->cfg.transport_id != PJSUA_INVALID_ID) {
900 pjsip_transport_type_e type;
901 type = pjsip_transport_get_type_from_name(&sip_uri->transport_param);
902 if (type == PJSIP_TRANSPORT_UNSPECIFIED)
903 type = PJSIP_TRANSPORT_UDP;
904
905 if (pjsua_var.tpdata[acc->cfg.transport_id].type != type)
906 continue;
907 }
908
Benny Prijono093d3022006-09-24 00:07:11 +0000909 /* Match ! */
910 PJSUA_UNLOCK();
911 return acc_id;
912 }
913 }
914
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000915 /* Still no match, use default account */
916 PJSUA_UNLOCK();
917 return pjsua_var.default_acc;
918}
919
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000920
921PJ_DEF(pj_status_t) pjsua_acc_create_uac_contact( pj_pool_t *pool,
922 pj_str_t *contact,
923 pjsua_acc_id acc_id,
924 const pj_str_t *suri)
925{
926 pjsua_acc *acc;
927 pjsip_sip_uri *sip_uri;
928 pj_status_t status;
929 pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED;
930 pj_str_t local_addr;
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000931 pjsip_tpselector tp_sel;
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000932 unsigned flag;
933 int secure;
934 int local_port;
935
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000936 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL);
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000937 acc = &pjsua_var.acc[acc_id];
938
939 /* If route-set is configured for the account, then URI is the
940 * first entry of the route-set.
941 */
942 if (!pj_list_empty(&acc->route_set)) {
943 sip_uri = (pjsip_sip_uri*) acc->route_set.next->name_addr.uri;
944 } else {
945 pj_str_t tmp;
946 pjsip_uri *uri;
947
948 pj_strdup_with_null(pool, &tmp, suri);
949
950 uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
951 if (uri == NULL)
952 return PJSIP_EINVALIDURI;
953
954 /* For non-SIP scheme, route set should be configured */
955 if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))
956 return PJSIP_EINVALIDREQURI;
957
958 sip_uri = (pjsip_sip_uri*)uri;
959 }
960
961 /* Get transport type of the URI */
962 if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri))
963 tp_type = PJSIP_TRANSPORT_TLS;
964 else if (sip_uri->transport_param.slen == 0) {
965 tp_type = PJSIP_TRANSPORT_UDP;
966 } else
967 tp_type = pjsip_transport_get_type_from_name(&sip_uri->transport_param);
968
969 if (tp_type == PJSIP_TRANSPORT_UNSPECIFIED)
970 return PJSIP_EUNSUPTRANSPORT;
971
972 flag = pjsip_transport_get_flag_from_type(tp_type);
973 secure = (flag & PJSIP_TRANSPORT_SECURE) != 0;
974
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000975 /* Init transport selector. */
976 pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel);
977
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000978 /* Get local address suitable to send request from */
979 status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt),
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000980 pool, tp_type, &tp_sel,
981 &local_addr, &local_port);
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000982 if (status != PJ_SUCCESS)
983 return status;
984
985 /* Create the contact header */
986 contact->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
987 contact->slen = pj_ansi_snprintf(contact->ptr, PJSIP_MAX_URL_SIZE,
988 "%.*s%s<%s:%.*s%s%.*s:%d;transport=%s>",
989 (int)acc->display.slen,
990 acc->display.ptr,
991 (acc->display.slen?" " : ""),
992 (secure ? "sips" : "sip"),
993 (int)acc->user_part.slen,
994 acc->user_part.ptr,
995 (acc->user_part.slen?"@":""),
996 (int)local_addr.slen,
997 local_addr.ptr,
998 local_port,
999 pjsip_transport_get_type_name(tp_type));
1000
1001 return PJ_SUCCESS;
1002}
1003
1004
1005
1006PJ_DEF(pj_status_t) pjsua_acc_create_uas_contact( pj_pool_t *pool,
1007 pj_str_t *contact,
1008 pjsua_acc_id acc_id,
1009 pjsip_rx_data *rdata )
1010{
1011 /*
1012 * Section 12.1.1, paragraph about using SIPS URI in Contact.
1013 * If the request that initiated the dialog contained a SIPS URI
1014 * in the Request-URI or in the top Record-Route header field value,
1015 * if there was any, or the Contact header field if there was no
1016 * Record-Route header field, the Contact header field in the response
1017 * MUST be a SIPS URI.
1018 */
1019 pjsua_acc *acc;
1020 pjsip_sip_uri *sip_uri;
1021 pj_status_t status;
1022 pjsip_transport_type_e tp_type = PJSIP_TRANSPORT_UNSPECIFIED;
1023 pj_str_t local_addr;
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001024 pjsip_tpselector tp_sel;
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001025 unsigned flag;
1026 int secure;
1027 int local_port;
1028
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001029 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL);
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001030 acc = &pjsua_var.acc[acc_id];
1031
1032 /* If Record-Route is present, then URI is the top Record-Route. */
1033 if (rdata->msg_info.record_route) {
1034 sip_uri = (pjsip_sip_uri*) rdata->msg_info.record_route->name_addr.uri;
1035 } else {
1036 pjsip_contact_hdr *h_contact;
1037 pjsip_uri *uri = NULL;
1038
1039 /* Otherwise URI is Contact URI */
1040 h_contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT,
1041 NULL);
1042 if (h_contact)
1043 uri = pjsip_uri_get_uri(h_contact->uri);
1044
1045
1046 /* Or if Contact URI is not present, take the remote URI from
1047 * the From URI.
1048 */
1049 if (uri == NULL)
1050 uri = pjsip_uri_get_uri(rdata->msg_info.from->uri);
1051
1052
1053 /* Can only do sip/sips scheme at present. */
1054 if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))
1055 return PJSIP_EINVALIDREQURI;
1056
1057 sip_uri = (pjsip_sip_uri*)uri;
1058 }
1059
1060 /* Get transport type of the URI */
1061 if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri))
1062 tp_type = PJSIP_TRANSPORT_TLS;
1063 else if (sip_uri->transport_param.slen == 0) {
1064 tp_type = PJSIP_TRANSPORT_UDP;
1065 } else
1066 tp_type = pjsip_transport_get_type_from_name(&sip_uri->transport_param);
1067
1068 if (tp_type == PJSIP_TRANSPORT_UNSPECIFIED)
1069 return PJSIP_EUNSUPTRANSPORT;
1070
1071 flag = pjsip_transport_get_flag_from_type(tp_type);
1072 secure = (flag & PJSIP_TRANSPORT_SECURE) != 0;
1073
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001074 /* Init transport selector. */
1075 pjsua_init_tpselector(pjsua_var.acc[acc_id].cfg.transport_id, &tp_sel);
1076
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001077 /* Get local address suitable to send request from */
1078 status = pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(pjsua_var.endpt),
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001079 pool, tp_type, &tp_sel,
1080 &local_addr, &local_port);
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001081 if (status != PJ_SUCCESS)
1082 return status;
1083
1084 /* Create the contact header */
1085 contact->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
1086 contact->slen = pj_ansi_snprintf(contact->ptr, PJSIP_MAX_URL_SIZE,
1087 "%.*s%s<%s:%.*s%s%.*s:%d;transport=%s>",
1088 (int)acc->display.slen,
1089 acc->display.ptr,
1090 (acc->display.slen?" " : ""),
1091 (secure ? "sips" : "sip"),
1092 (int)acc->user_part.slen,
1093 acc->user_part.ptr,
1094 (acc->user_part.slen?"@":""),
1095 (int)local_addr.slen,
1096 local_addr.ptr,
1097 local_port,
1098 pjsip_transport_get_type_name(tp_type));
1099
1100 return PJ_SUCCESS;
1101}
1102
1103
Benny Prijono62c5c5b2007-01-13 23:22:40 +00001104PJ_DEF(pj_status_t) pjsua_acc_set_transport( pjsua_acc_id acc_id,
1105 pjsua_transport_id tp_id)
1106{
1107 pjsua_acc *acc;
1108
1109 PJ_ASSERT_RETURN(pjsua_acc_is_valid(acc_id), PJ_EINVAL);
1110 acc = &pjsua_var.acc[acc_id];
1111
1112 PJ_ASSERT_RETURN(tp_id >= 0 && tp_id < PJ_ARRAY_SIZE(pjsua_var.tpdata),
1113 PJ_EINVAL);
1114
1115 acc->cfg.transport_id = tp_id;
1116
1117 return PJ_SUCCESS;
1118}
Benny Prijonoc570f2d2006-07-18 00:33:02 +00001119