blob: 8a213233459957f7c394899f3fac8ca22fdac94a [file] [log] [blame]
Benny Prijonoeebe9af2006-06-13 22:57:13 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijonoeebe9af2006-06-13 22:57:13 +00005 *
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.
10 *
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.
15 *
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
19 */
20#ifndef __PJSUA_INTERNAL_H__
21#define __PJSUA_INTERNAL_H__
22
23/**
24 * This is the private header used by pjsua library implementation.
25 * Applications should not include this file.
26 */
27
28PJ_BEGIN_DECL
29
30/**
Benny Prijono224b4e22008-06-19 14:10:28 +000031 * Media transport state.
32 */
33typedef enum pjsua_med_tp_st
34{
35 /** Not initialized */
36 PJSUA_MED_TP_IDLE,
37
38 /** Initialized (media_create() has been called) */
39 PJSUA_MED_TP_INIT,
40
41 /** Running (media_start() has been called) */
42 PJSUA_MED_TP_RUNNING
43
44} pjsua_med_tp_st;
45
Benny Prijono0bc99a92011-03-17 04:34:43 +000046/** Forward decl of pjsua call */
47typedef struct pjsua_call pjsua_call;
48
49/**
50 * Call's media stream.
51 */
52typedef struct pjsua_call_media
53{
54 pjsua_call *call; /**< Parent call. */
55 pjmedia_type type; /**< Media type. */
56 unsigned idx; /**< This media index in parent call. */
57 pjsua_call_media_status state; /**< Media state. */
58 pjmedia_dir dir; /**< Media direction. */
59
60 /** The stream */
Benny Prijono9b61ff52011-03-18 09:55:48 +000061 struct {
Benny Prijono0bc99a92011-03-17 04:34:43 +000062 /** Audio stream */
63 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000064 pjmedia_stream *stream; /**< The audio stream. */
Benny Prijono0bc99a92011-03-17 04:34:43 +000065 int conf_slot; /**< Slot # in conference bridge. */
66 } a;
67
68 /** Video stream */
69 struct {
Nanang Izzuddinbf26db12011-03-18 07:54:50 +000070 pjmedia_vid_stream *stream; /**< The video stream. */
71 pjmedia_vid_port *capturer; /**< Video capturer. */
72 pjmedia_vid_port *renderer; /**< Video renderer. */
73 pjmedia_converter *conv_enc; /**< Converter for encoding dir.*/
74 pjmedia_converter *conv_dec; /**< Converter for decoding dir.*/
Benny Prijono0bc99a92011-03-17 04:34:43 +000075 } v;
76
77 } strm;
78
79 pj_uint32_t ssrc; /**< RTP SSRC */
80 pj_uint32_t rtp_tx_ts; /**< Initial RTP timestamp for sender. */
81 pj_uint16_t rtp_tx_seq;/**< Initial RTP sequence for sender. */
82 pj_uint8_t rtp_tx_seq_ts_set;
83 /**< Bitmask flags if initial RTP sequence
84 and/or timestamp for sender are set.
85 bit 0/LSB : sequence flag
86 bit 1 : timestamp flag */
87
88 pjmedia_transport *tp; /**< Current media transport (can be 0) */
89 pj_status_t tp_ready; /**< Media transport status. */
90 pjmedia_transport *tp_orig; /**< Original media transport */
91 pj_bool_t tp_auto_del; /**< May delete media transport */
92 pjsua_med_tp_st tp_st; /**< Media transport state */
93 pj_sockaddr rtp_addr; /**< Current RTP source address
94 (used to update ICE default
95 address) */
96 pjmedia_srtp_use rem_srtp_use; /**< Remote's SRTP usage policy. */
97} pjsua_call_media;
98
99/**
100 * Maximum number of SDP "m=" lines to be supported.
101 */
102#define PJSUA_MAX_CALL_MEDIA PJMEDIA_MAX_SDP_MEDIA
103
Benny Prijono224b4e22008-06-19 14:10:28 +0000104/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000105 * Structure to be attached to invite dialog.
106 * Given a dialog "dlg", application can retrieve this structure
107 * by accessing dlg->mod_data[pjsua.mod.id].
108 */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000109struct pjsua_call
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000110{
111 unsigned index; /**< Index in pjsua array. */
112 pjsip_inv_session *inv; /**< The invite session. */
113 void *user_data; /**< User/application data. */
114 pjsip_status_code last_code; /**< Last status code seen. */
115 pj_str_t last_text; /**< Last status text seen. */
116 pj_time_val start_time;/**< First INVITE sent/received. */
117 pj_time_val res_time; /**< First response sent/received. */
118 pj_time_val conn_time; /**< Connected/confirmed time. */
119 pj_time_val dis_time; /**< Disconnect time. */
120 pjsua_acc_id acc_id; /**< Account index being used. */
Benny Prijonodb844a42008-02-02 17:07:18 +0000121 int secure_level;/**< Signaling security level. */
Benny Prijonodd63b992010-10-01 02:03:42 +0000122 pjsua_call_hold_type call_hold_type; /**< How to do call hold. */
Nanang Izzuddin99d69522008-08-04 15:01:38 +0000123 pj_bool_t local_hold;/**< Flag for call-hold by local. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000124
125 unsigned med_cnt; /**< Number of media in SDP. */
126 pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */
Nanang Izzuddinbf26db12011-03-18 07:54:50 +0000127 int audio_idx; /**< First active audio media. */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000128
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000129 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
130 call was triggered by xfer. */
Benny Prijono91a6a172007-10-31 08:59:29 +0000131 pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000132
133 char last_text_buf_[128]; /**< Buffer for last_text. */
134
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000135 struct {
136 pj_timer_entry reinv_timer;/**< Reinvite retry timer. */
Benny Prijono1e601552010-10-20 05:31:08 +0000137 pj_uint32_t sdp_ver; /**< SDP version of the bad answer */
138 int retry_cnt; /**< Retry count. */
Nanang Izzuddinec919002010-11-25 09:27:06 +0000139 pj_bool_t pending; /**< Pending until CONFIRMED state */
Nanang Izzuddin93bacd02010-06-15 09:56:39 +0000140 } lock_codec; /**< Data for codec locking when answer
141 contains multiple codecs. */
142
Benny Prijono0bc99a92011-03-17 04:34:43 +0000143};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000144
145
146/**
147 * Server presence subscription list head.
148 */
Benny Prijono63fba012008-07-17 14:19:10 +0000149struct pjsua_srv_pres
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000150{
151 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
Benny Prijono63fba012008-07-17 14:19:10 +0000152 pjsip_evsub *sub; /**< The evsub. */
153 char *remote; /**< Remote URI. */
154 int acc_id; /**< Account ID. */
155 pjsip_dialog *dlg; /**< Dialog. */
156 int expires; /**< "expires" value in the request. */
157};
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000158
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000159/**
160 * Account
161 */
162typedef struct pjsua_acc
163{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000164 pj_pool_t *pool; /**< Pool for this account. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000165 pjsua_acc_config cfg; /**< Account configuration. */
166 pj_bool_t valid; /**< Is this account valid? */
167
168 int index; /**< Index in accounts array. */
Benny Prijonoc570f2d2006-07-18 00:33:02 +0000169 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000170 pj_str_t user_part; /**< User part of local URI. */
Nanang Izzuddin5af37ff2009-08-05 18:41:23 +0000171 pj_str_t contact; /**< Our Contact header. */
Benny Prijonob54719f2010-11-16 03:07:46 +0000172 pj_str_t reg_contact; /**< Contact header for REGISTER.
173 It may be different than acc
174 contact if outbound is used */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000175
Benny Prijonob4a17c92006-07-10 14:40:21 +0000176 pj_str_t srv_domain; /**< Host part of reg server. */
177 int srv_port; /**< Port number of reg server. */
178
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000179 pjsip_regc *regc; /**< Client registration session. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000180 pj_status_t reg_last_err; /**< Last registration error. */
181 int reg_last_code; /**< Last status last register. */
182
Nanang Izzuddin36dd5b62010-03-30 11:13:59 +0000183 struct {
184 pj_bool_t active; /**< Flag of reregister status. */
185 pj_timer_entry timer; /**< Timer for reregistration. */
186 void *reg_tp; /**< Transport for registration. */
187 unsigned attempt_cnt; /**< Attempt counter. */
188 } auto_rereg; /**< Reregister/reconnect data. */
189
Benny Prijonobddef2c2007-10-31 13:28:08 +0000190 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */
191 pjsip_transport *ka_transport; /**< Transport for keep-alive. */
192 pj_sockaddr ka_target; /**< Destination address for K-A */
193 unsigned ka_target_len; /**< Length of ka_target. */
194
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000195 pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/
Nanang Izzuddinc3ea16a2010-04-20 14:36:38 +0000196 pj_uint32_t global_route_crc; /** CRC of global route setting. */
197 pj_uint32_t local_route_crc; /** CRC of account route setting.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000198
Benny Prijonob54719f2010-11-16 03:07:46 +0000199 unsigned rfc5626_status;/**< SIP outbound status:
200 0: not used
201 1: requested
202 2: acknowledged by servers */
203 pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */
204 pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */
205
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000206 unsigned cred_cnt; /**< Number of credentials. */
207 pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */
208
209 pj_bool_t online_status; /**< Our online status. */
Benny Prijono4461c7d2007-08-25 13:36:15 +0000210 pjrpid_element rpid; /**< RPID element information. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000211 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000212 pjsip_publishc *publish_sess; /**< Client publication session. */
213 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000214
Benny Prijono4dd961b2009-10-26 11:21:37 +0000215 pjsip_evsub *mwi_sub; /**< MWI client subscription */
216 pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000217} pjsua_acc;
218
219
220/**
221 *Transport.
222 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000223typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000224{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000225 int index;
226 pjsip_transport_type_e type;
227 pjsip_host_port local_name;
228
229 union {
230 pjsip_transport *tp;
231 pjsip_tpfactory *factory;
232 void *ptr;
233 } data;
234
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000235} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000236
237
Benny Prijono63fba012008-07-17 14:19:10 +0000238/** Maximum length of subscription termination reason. */
239#define PJSUA_BUDDY_SUB_TERM_REASON_LEN 32
240
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000241/**
242 * Buddy data.
243 */
244typedef struct pjsua_buddy
245{
Benny Prijonoc91ed8d2008-07-13 12:24:55 +0000246 pj_pool_t *pool; /**< Pool for this buddy. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000247 unsigned index; /**< Buddy index. */
Benny Prijono705e7842008-07-21 18:12:51 +0000248 void *user_data; /**< Application data. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000249 pj_str_t uri; /**< Buddy URI. */
250 pj_str_t contact; /**< Contact learned from subscrp. */
251 pj_str_t name; /**< Buddy name. */
252 pj_str_t display; /**< Buddy display name. */
253 pj_str_t host; /**< Buddy host. */
254 unsigned port; /**< Buddy port. */
255 pj_bool_t monitor; /**< Should we monitor? */
Benny Prijonof9c40c32007-06-28 07:20:26 +0000256 pjsip_dialog *dlg; /**< The underlying dialog. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000257 pjsip_evsub *sub; /**< Buddy presence subscription */
Benny Prijono73bb7232009-10-20 13:56:26 +0000258 unsigned term_code; /**< Subscription termination code */
Benny Prijono63fba012008-07-17 14:19:10 +0000259 pj_str_t term_reason;/**< Subscription termination reason */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000260 pjsip_pres_status status; /**< Buddy presence status. */
Benny Prijono73bb7232009-10-20 13:56:26 +0000261 pj_timer_entry timer; /**< Resubscription timer */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000262} pjsua_buddy;
263
264
265/**
266 * File player/recorder data.
267 */
268typedef struct pjsua_file_data
269{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000270 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000271 pjmedia_port *port;
Benny Prijonod5696da2007-07-17 16:25:45 +0000272 pj_pool_t *pool;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000273 unsigned slot;
274} pjsua_file_data;
275
276
277/**
278 * Additional parameters for conference bridge.
279 */
280typedef struct pjsua_conf_setting
281{
282 unsigned channel_count;
283 unsigned samples_per_frame;
284 unsigned bits_per_sample;
285} pjsua_conf_setting;
286
Benny Prijonobb995fd2009-08-12 11:03:23 +0000287typedef struct pjsua_stun_resolve
288{
289 PJ_DECL_LIST_MEMBER(struct pjsua_stun_resolve);
290
291 pj_pool_t *pool; /**< Pool */
292 unsigned count; /**< # of entries */
293 pj_str_t *srv; /**< Array of entries */
294 unsigned idx; /**< Current index */
295 void *token; /**< App token */
296 pj_stun_resolve_cb cb; /**< App callback */
297 pj_bool_t blocking; /**< Blocking? */
298 pj_status_t status; /**< Session status */
299 pj_sockaddr addr; /**< Result */
300 pj_stun_sock *stun_sock; /**< Testing STUN sock */
301} pjsua_stun_resolve;
302
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000303
304/**
305 * Global pjsua application data.
306 */
307struct pjsua_data
308{
309
310 /* Control: */
311 pj_caching_pool cp; /**< Global pool factory. */
312 pj_pool_t *pool; /**< pjsua's private pool. */
313 pj_mutex_t *mutex; /**< Mutex protection for this data */
Benny Prijono0bc99a92011-03-17 04:34:43 +0000314 pjsua_state state; /**< Library state. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000315
316 /* Logging: */
317 pjsua_logging_config log_cfg; /**< Current logging config. */
318 pj_oshandle_t log_file; /**<Output log file handle */
319
320 /* SIP: */
321 pjsip_endpoint *endpt; /**< Global endpoint. */
322 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000323 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijono21407322010-03-10 13:33:25 +0000324 pjsip_tp_state_callback old_tp_cb; /**< Old transport callback. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000325
326 /* Threading: */
327 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
328 pj_thread_t *thread[4]; /**< Array of threads. */
329
Benny Prijonoc97608e2007-03-23 16:34:20 +0000330 /* STUN and resolver */
331 pj_stun_config stun_cfg; /**< Global STUN settings. */
332 pj_sockaddr stun_srv; /**< Resolved STUN server address */
333 pj_status_t stun_status; /**< STUN server status. */
Benny Prijonobb995fd2009-08-12 11:03:23 +0000334 pjsua_stun_resolve stun_res; /**< List of pending STUN resolution*/
Benny Prijonoc97608e2007-03-23 16:34:20 +0000335 pj_dns_resolver *resolver; /**< DNS resolver. */
336
Benny Prijono6ba8c542007-10-16 01:34:14 +0000337 /* Detected NAT type */
338 pj_stun_nat_type nat_type; /**< NAT type. */
339 pj_status_t nat_status; /**< Detection status. */
340 pj_bool_t nat_in_progress; /**< Detection in progress */
341
Benny Prijono29c8ca32010-06-22 06:02:13 +0000342 /* List of outbound proxies: */
343 pjsip_route_hdr outbound_proxy;
344
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000345 /* Account: */
346 unsigned acc_cnt; /**< Number of accounts. */
347 pjsua_acc_id default_acc; /**< Default account ID */
348 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000349 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000350
351 /* Calls: */
352 pjsua_config ua_cfg; /**< UA config. */
353 unsigned call_cnt; /**< Call counter. */
354 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
Benny Prijono5773cd62008-01-19 13:01:42 +0000355 pjsua_call_id next_call_id; /**< Next call id to use*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000356
357 /* Buddy; */
358 unsigned buddy_cnt; /**< Buddy count. */
359 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
360
Benny Prijono7a5f5102007-05-29 00:33:09 +0000361 /* Presence: */
362 pj_timer_entry pres_timer;/**< Presence refresh timer. */
363
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000364 /* Media: */
365 pjsua_media_config media_cfg; /**< Media config. */
366 pjmedia_endpt *med_endpt; /**< Media endpoint. */
367 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
368 pjmedia_conf *mconf; /**< Conference bridge. */
Benny Prijonof798e502009-03-09 13:08:16 +0000369 pj_bool_t is_mswitch;/**< Are we using audio switchboard
370 (a.k.a APS-Direct) */
371
372 /* Sound device */
373 pjmedia_aud_dev_index cap_dev; /**< Capture device ID. */
374 pjmedia_aud_dev_index play_dev; /**< Playback device ID. */
375 pj_uint32_t aud_svmask;/**< Which settings to save */
376 pjmedia_aud_param aud_param; /**< User settings to sound dev */
377 pj_bool_t aud_open_cnt;/**< How many # device is opened */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000378 pj_bool_t no_snd; /**< No sound (app will manage it) */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000379 pj_pool_t *snd_pool; /**< Sound's private pool. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000380 pjmedia_snd_port *snd_port; /**< Sound port. */
Nanang Izzuddin68559c32008-06-13 17:01:46 +0000381 pj_timer_entry snd_idle_timer;/**< Sound device idle timer. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000382 pjmedia_master_port *null_snd; /**< Master port for null sound. */
383 pjmedia_port *null_port; /**< Null port. */
384
385
Nanang Izzuddin50fae732011-03-22 09:49:23 +0000386 /* Video device */
387 pjmedia_vid_dev_index vcap_dev; /**< Capture device ID. */
388 pjmedia_vid_dev_index vrdr_dev; /**< Playback device ID. */
389
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000390 /* File players: */
391 unsigned player_cnt;/**< Number of file players. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000392 pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000393
394 /* File recorders: */
395 unsigned rec_cnt; /**< Number of file recorders. */
Benny Prijonocba59d92007-02-16 09:22:56 +0000396 pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000397};
398
399
400extern struct pjsua_data pjsua_var;
401
Benny Prijono44e88ea2007-10-30 15:42:35 +0000402/**
403 * Get the instance of pjsua
404 */
405PJ_DECL(struct pjsua_data*) pjsua_get_var(void);
406
407
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000408
409/**
410 * IM callback data.
411 */
412typedef struct pjsua_im_data
413{
414 pjsua_acc_id acc_id;
415 pjsua_call_id call_id;
416 pj_str_t to;
417 pj_str_t body;
418 void *user_data;
419} pjsua_im_data;
420
421
422/**
423 * Duplicate IM data.
424 */
425PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
426 const pjsua_im_data *src)
427{
428 pjsua_im_data *dst;
429
Benny Prijono07113c92006-11-21 08:38:00 +0000430 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000431 dst->acc_id = src->acc_id;
432 dst->call_id = src->call_id;
433 pj_strdup_with_null(pool, &dst->to, &src->to);
434 dst->user_data = src->user_data;
435 pj_strdup_with_null(pool, &dst->body, &src->body);
436
437 return dst;
438}
439
440
Benny Prijono148c9dd2006-09-19 13:37:53 +0000441#if 1
442#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
443#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
444#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000445#else
446#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000447#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000448#define PJSUA_UNLOCK()
449#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000450
Benny Prijono0bc99a92011-03-17 04:34:43 +0000451/* Core */
452void pjsua_set_state(pjsua_state new_state);
453
Benny Prijonobb995fd2009-08-12 11:03:23 +0000454/******
455 * STUN resolution
456 */
457/* Resolve the STUN server */
458pj_status_t resolve_stun_server(pj_bool_t wait);
459
Benny Prijono91d06b62008-09-20 12:16:56 +0000460/**
461 * Normalize route URI (check for ";lr" and append one if it doesn't
462 * exist and pjsua_config.force_lr is set.
463 */
464pj_status_t normalize_route_uri(pj_pool_t *pool, pj_str_t *uri);
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000465
Benny Prijonoc97608e2007-03-23 16:34:20 +0000466/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000467 * Handle incoming invite request.
468 */
469pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
470
Benny Prijonoc97608e2007-03-23 16:34:20 +0000471/*
472 * Media channel.
473 */
474pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
Benny Prijonod8179652008-01-23 20:39:07 +0000475 pjsip_role_e role,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000476 int security_level,
Benny Prijono224b4e22008-06-19 14:10:28 +0000477 pj_pool_t *tmp_pool,
478 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000479 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000480pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,
481 pj_pool_t *pool,
Benny Prijonod8179652008-01-23 20:39:07 +0000482 const pjmedia_sdp_session *rem_sdp,
Benny Prijono25b2ea12008-01-24 19:20:54 +0000483 pjmedia_sdp_session **p_sdp,
484 int *sip_err_code);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000485pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
Benny Prijono224b4e22008-06-19 14:10:28 +0000486 const pjmedia_sdp_session *local_sdp,
Benny Prijonodbce2cf2007-03-28 16:24:00 +0000487 const pjmedia_sdp_session *remote_sdp);
Benny Prijonoc97608e2007-03-23 16:34:20 +0000488pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
489
490
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000491/**
492 * Init presence.
493 */
494pj_status_t pjsua_pres_init();
495
496/*
497 * Start presence subsystem.
498 */
499pj_status_t pjsua_pres_start(void);
500
501/**
502 * Refresh presence subscriptions
503 */
504void pjsua_pres_refresh(void);
505
506/*
Benny Prijono4461c7d2007-08-25 13:36:15 +0000507 * Update server subscription (e.g. when our online status has changed)
508 */
509void pjsua_pres_update_acc(int acc_id, pj_bool_t force);
510
511/*
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000512 * Shutdown presence.
513 */
514void pjsua_pres_shutdown(void);
515
516/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000517 * Init presence for aoocunt.
518 */
519pj_status_t pjsua_pres_init_acc(int acc_id);
520
521/**
Benny Prijono8b6834f2007-02-24 13:29:22 +0000522 * Send PUBLISH
523 */
524pj_status_t pjsua_pres_init_publish_acc(int acc_id);
525
526/**
Benny Prijono166d5022010-02-10 14:24:48 +0000527 * Send un-PUBLISH
528 */
529void pjsua_pres_unpublish(pjsua_acc *acc);
530
531/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000532 * Terminate server subscription for the account
533 */
534void pjsua_pres_delete_acc(int acc_id);
535
536/**
537 * Init IM module handler to handle incoming MESSAGE outside dialog.
538 */
539pj_status_t pjsua_im_init(void);
540
541/**
Benny Prijono4dd961b2009-10-26 11:21:37 +0000542 * Start MWI subscription
543 */
544void pjsua_start_mwi(pjsua_acc *acc);
545
546/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000547 * Init call subsystem.
548 */
549pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
550
551/**
552 * Start call subsystem.
553 */
554pj_status_t pjsua_call_subsys_start(void);
555
556/**
557 * Init media subsystems.
558 */
559pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
560
561/**
562 * Start pjsua media subsystem.
563 */
564pj_status_t pjsua_media_subsys_start(void);
565
566/**
567 * Destroy pjsua media subsystem.
568 */
569pj_status_t pjsua_media_subsys_destroy(void);
570
571/**
572 * Private: check if we can accept the message.
573 * If not, then p_accept header will be filled with a valid
574 * Accept header.
575 */
576pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
577 pjsip_accept_hdr **p_accept_hdr);
578
579/**
580 * Private: process pager message.
581 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
582 */
583void pjsua_im_process_pager(int call_id, const pj_str_t *from,
584 const pj_str_t *to, pjsip_rx_data *rdata);
585
586
587/**
588 * Create Accept header for MESSAGE.
589 */
590pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
591
592/*
593 * Add additional headers etc in msg_data specified by application
594 * when sending requests.
595 */
596void pjsua_process_msg_data(pjsip_tx_data *tdata,
597 const pjsua_msg_data *msg_data);
598
599
600/*
601 * Add route_set to outgoing requests
602 */
603void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
604 const pjsip_route_hdr *route_set );
605
606
607/*
608 * Simple version of MIME type parsing (it doesn't support parameters)
609 */
610void pjsua_parse_media_type( pj_pool_t *pool,
611 const pj_str_t *mime,
612 pjsip_media_type *media_type);
613
614
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000615/*
616 * Internal function to init transport selector from transport id.
617 */
618void pjsua_init_tpselector(pjsua_transport_id tp_id,
619 pjsip_tpselector *sel);
620
Benny Prijono3c5e28b2008-09-24 10:10:15 +0000621pjsip_dialog* on_dlg_forked(pjsip_dialog *first_set, pjsip_rx_data *res);
Benny Prijono627cbb42007-09-25 20:48:49 +0000622pj_status_t acquire_call(const char *title,
623 pjsua_call_id call_id,
624 pjsua_call **p_call,
625 pjsip_dialog **p_dlg);
626const char *good_number(char *buf, pj_int32_t val);
627void print_call(const char *title,
628 int call_id,
629 char *buf, pj_size_t size);
630
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000631
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000632PJ_END_DECL
633
634#endif /* __PJSUA_INTERNAL_H__ */
635