Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | a771a51 | 2007-02-19 01:13:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 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 | #ifndef __PJSUA_INTERNAL_H__ |
| 20 | #define __PJSUA_INTERNAL_H__ |
| 21 | |
| 22 | /** |
| 23 | * This is the private header used by pjsua library implementation. |
| 24 | * Applications should not include this file. |
| 25 | */ |
| 26 | |
| 27 | PJ_BEGIN_DECL |
| 28 | |
| 29 | /** |
| 30 | * Structure to be attached to invite dialog. |
| 31 | * Given a dialog "dlg", application can retrieve this structure |
| 32 | * by accessing dlg->mod_data[pjsua.mod.id]. |
| 33 | */ |
| 34 | typedef struct pjsua_call |
| 35 | { |
| 36 | unsigned index; /**< Index in pjsua array. */ |
| 37 | pjsip_inv_session *inv; /**< The invite session. */ |
| 38 | void *user_data; /**< User/application data. */ |
| 39 | pjsip_status_code last_code; /**< Last status code seen. */ |
| 40 | pj_str_t last_text; /**< Last status text seen. */ |
| 41 | pj_time_val start_time;/**< First INVITE sent/received. */ |
| 42 | pj_time_val res_time; /**< First response sent/received. */ |
| 43 | pj_time_val conn_time; /**< Connected/confirmed time. */ |
| 44 | pj_time_val dis_time; /**< Disconnect time. */ |
| 45 | pjsua_acc_id acc_id; /**< Account index being used. */ |
| 46 | pjsua_call_media_status media_st;/**< Media state. */ |
| 47 | pjmedia_dir media_dir; /**< Media direction. */ |
| 48 | pjmedia_session *session; /**< The media session. */ |
| 49 | int conf_slot; /**< Slot # in conference bridge. */ |
| 50 | pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this |
| 51 | call was triggered by xfer. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 52 | pjmedia_transport *med_tp; /**< Media transport. */ |
| 53 | pj_timer_entry refresh_tm;/**< Timer to send re-INVITE. */ |
| 54 | pj_timer_entry hangup_tm; /**< Timer to hangup call. */ |
| 55 | |
| 56 | char last_text_buf_[128]; /**< Buffer for last_text. */ |
| 57 | |
| 58 | } pjsua_call; |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Server presence subscription list head. |
| 63 | */ |
| 64 | typedef struct pjsua_srv_pres |
| 65 | { |
| 66 | PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres); |
| 67 | pjsip_evsub *sub; |
| 68 | char *remote; |
| 69 | } pjsua_srv_pres; |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | * Account |
| 74 | */ |
| 75 | typedef struct pjsua_acc |
| 76 | { |
| 77 | pjsua_acc_config cfg; /**< Account configuration. */ |
| 78 | pj_bool_t valid; /**< Is this account valid? */ |
| 79 | |
| 80 | int index; /**< Index in accounts array. */ |
Benny Prijono | c570f2d | 2006-07-18 00:33:02 +0000 | [diff] [blame] | 81 | pj_str_t display; /**< Display name, if any. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 82 | pj_str_t user_part; /**< User part of local URI. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 83 | |
Benny Prijono | b4a17c9 | 2006-07-10 14:40:21 +0000 | [diff] [blame] | 84 | pj_str_t srv_domain; /**< Host part of reg server. */ |
| 85 | int srv_port; /**< Port number of reg server. */ |
| 86 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 87 | pjsip_regc *regc; /**< Client registration session. */ |
| 88 | pj_timer_entry reg_timer; /**< Registration timer. */ |
| 89 | pj_status_t reg_last_err; /**< Last registration error. */ |
| 90 | int reg_last_code; /**< Last status last register. */ |
| 91 | |
| 92 | pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/ |
| 93 | |
| 94 | unsigned cred_cnt; /**< Number of credentials. */ |
| 95 | pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */ |
| 96 | |
| 97 | pj_bool_t online_status; /**< Our online status. */ |
| 98 | pjsua_srv_pres pres_srv_list; /**< Server subscription list. */ |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 99 | pjsip_publishc *publish_sess; /**< Client publication session. */ |
| 100 | pj_bool_t publish_state; /**< Last published online status */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 101 | |
| 102 | } pjsua_acc; |
| 103 | |
| 104 | |
| 105 | /** |
| 106 | *Transport. |
| 107 | */ |
Benny Prijono | 62c5c5b | 2007-01-13 23:22:40 +0000 | [diff] [blame] | 108 | typedef struct pjsua_transport_data |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 109 | { |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 110 | int index; |
| 111 | pjsip_transport_type_e type; |
| 112 | pjsip_host_port local_name; |
| 113 | |
| 114 | union { |
| 115 | pjsip_transport *tp; |
| 116 | pjsip_tpfactory *factory; |
| 117 | void *ptr; |
| 118 | } data; |
| 119 | |
Benny Prijono | 62c5c5b | 2007-01-13 23:22:40 +0000 | [diff] [blame] | 120 | } pjsua_transport_data; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 121 | |
| 122 | |
| 123 | /** |
| 124 | * Buddy data. |
| 125 | */ |
| 126 | typedef struct pjsua_buddy |
| 127 | { |
| 128 | unsigned index; /**< Buddy index. */ |
| 129 | pj_str_t uri; /**< Buddy URI. */ |
| 130 | pj_str_t contact; /**< Contact learned from subscrp. */ |
| 131 | pj_str_t name; /**< Buddy name. */ |
| 132 | pj_str_t display; /**< Buddy display name. */ |
| 133 | pj_str_t host; /**< Buddy host. */ |
| 134 | unsigned port; /**< Buddy port. */ |
| 135 | pj_bool_t monitor; /**< Should we monitor? */ |
| 136 | pjsip_evsub *sub; /**< Buddy presence subscription */ |
| 137 | pjsip_pres_status status; /**< Buddy presence status. */ |
| 138 | |
| 139 | } pjsua_buddy; |
| 140 | |
| 141 | |
| 142 | /** |
| 143 | * File player/recorder data. |
| 144 | */ |
| 145 | typedef struct pjsua_file_data |
| 146 | { |
Benny Prijono | a66c331 | 2007-01-21 23:12:40 +0000 | [diff] [blame] | 147 | pj_bool_t type; /* 0=player, 1=playlist */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 148 | pjmedia_port *port; |
| 149 | unsigned slot; |
| 150 | } pjsua_file_data; |
| 151 | |
| 152 | |
| 153 | /** |
| 154 | * Additional parameters for conference bridge. |
| 155 | */ |
| 156 | typedef struct pjsua_conf_setting |
| 157 | { |
| 158 | unsigned channel_count; |
| 159 | unsigned samples_per_frame; |
| 160 | unsigned bits_per_sample; |
| 161 | } pjsua_conf_setting; |
| 162 | |
| 163 | |
| 164 | /** |
| 165 | * Global pjsua application data. |
| 166 | */ |
| 167 | struct pjsua_data |
| 168 | { |
| 169 | |
| 170 | /* Control: */ |
| 171 | pj_caching_pool cp; /**< Global pool factory. */ |
| 172 | pj_pool_t *pool; /**< pjsua's private pool. */ |
| 173 | pj_mutex_t *mutex; /**< Mutex protection for this data */ |
| 174 | |
| 175 | /* Logging: */ |
| 176 | pjsua_logging_config log_cfg; /**< Current logging config. */ |
| 177 | pj_oshandle_t log_file; /**<Output log file handle */ |
| 178 | |
| 179 | /* SIP: */ |
| 180 | pjsip_endpoint *endpt; /**< Global endpoint. */ |
| 181 | pjsip_module mod; /**< pjsua's PJSIP module. */ |
Benny Prijono | 62c5c5b | 2007-01-13 23:22:40 +0000 | [diff] [blame] | 182 | pjsua_transport_data tpdata[8]; /**< Array of transports. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 183 | |
| 184 | /* Threading: */ |
| 185 | pj_bool_t thread_quit_flag; /**< Thread quit flag. */ |
| 186 | pj_thread_t *thread[4]; /**< Array of threads. */ |
| 187 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 188 | /* STUN and resolver */ |
| 189 | pj_stun_config stun_cfg; /**< Global STUN settings. */ |
| 190 | pj_sockaddr stun_srv; /**< Resolved STUN server address */ |
| 191 | pj_status_t stun_status; /**< STUN server status. */ |
| 192 | pj_dns_resolver *resolver; /**< DNS resolver. */ |
| 193 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 194 | /* Account: */ |
| 195 | unsigned acc_cnt; /**< Number of accounts. */ |
| 196 | pjsua_acc_id default_acc; /**< Default account ID */ |
| 197 | pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */ |
Benny Prijono | 093d302 | 2006-09-24 00:07:11 +0000 | [diff] [blame] | 198 | pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 199 | |
| 200 | /* Calls: */ |
| 201 | pjsua_config ua_cfg; /**< UA config. */ |
| 202 | unsigned call_cnt; /**< Call counter. */ |
| 203 | pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */ |
| 204 | |
| 205 | /* Buddy; */ |
| 206 | unsigned buddy_cnt; /**< Buddy count. */ |
| 207 | pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */ |
| 208 | |
Benny Prijono | 7a5f510 | 2007-05-29 00:33:09 +0000 | [diff] [blame] | 209 | /* Presence: */ |
| 210 | pj_timer_entry pres_timer;/**< Presence refresh timer. */ |
| 211 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 212 | /* Media: */ |
| 213 | pjsua_media_config media_cfg; /**< Media config. */ |
| 214 | pjmedia_endpt *med_endpt; /**< Media endpoint. */ |
| 215 | pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */ |
| 216 | pjmedia_conf *mconf; /**< Conference bridge. */ |
| 217 | int cap_dev; /**< Capture device ID. */ |
| 218 | int play_dev; /**< Playback device ID. */ |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 219 | pj_bool_t no_snd; /**< No sound (app will manage it) */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 220 | pjmedia_snd_port *snd_port; /**< Sound port. */ |
| 221 | pjmedia_master_port *null_snd; /**< Master port for null sound. */ |
| 222 | pjmedia_port *null_port; /**< Null port. */ |
| 223 | |
| 224 | |
| 225 | /* File players: */ |
| 226 | unsigned player_cnt;/**< Number of file players. */ |
Benny Prijono | cba59d9 | 2007-02-16 09:22:56 +0000 | [diff] [blame] | 227 | pjsua_file_data player[PJSUA_MAX_PLAYERS];/**< Array of players.*/ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 228 | |
| 229 | /* File recorders: */ |
| 230 | unsigned rec_cnt; /**< Number of file recorders. */ |
Benny Prijono | cba59d9 | 2007-02-16 09:22:56 +0000 | [diff] [blame] | 231 | pjsua_file_data recorder[PJSUA_MAX_RECORDERS];/**< Array of recs.*/ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | |
| 235 | extern struct pjsua_data pjsua_var; |
| 236 | |
| 237 | |
| 238 | /** |
| 239 | * IM callback data. |
| 240 | */ |
| 241 | typedef struct pjsua_im_data |
| 242 | { |
| 243 | pjsua_acc_id acc_id; |
| 244 | pjsua_call_id call_id; |
| 245 | pj_str_t to; |
| 246 | pj_str_t body; |
| 247 | void *user_data; |
| 248 | } pjsua_im_data; |
| 249 | |
| 250 | |
| 251 | /** |
| 252 | * Duplicate IM data. |
| 253 | */ |
| 254 | PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool, |
| 255 | const pjsua_im_data *src) |
| 256 | { |
| 257 | pjsua_im_data *dst; |
| 258 | |
Benny Prijono | 07113c9 | 2006-11-21 08:38:00 +0000 | [diff] [blame] | 259 | dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst)); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 260 | dst->acc_id = src->acc_id; |
| 261 | dst->call_id = src->call_id; |
| 262 | pj_strdup_with_null(pool, &dst->to, &src->to); |
| 263 | dst->user_data = src->user_data; |
| 264 | pj_strdup_with_null(pool, &dst->body, &src->body); |
| 265 | |
| 266 | return dst; |
| 267 | } |
| 268 | |
| 269 | |
Benny Prijono | 148c9dd | 2006-09-19 13:37:53 +0000 | [diff] [blame] | 270 | #if 1 |
| 271 | #define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex) |
| 272 | #define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex) |
| 273 | #define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex) |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 274 | #else |
| 275 | #define PJSUA_LOCK() |
Benny Prijono | 148c9dd | 2006-09-19 13:37:53 +0000 | [diff] [blame] | 276 | #define PJSUA_TRY_LOCK() PJ_SUCCESS |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 277 | #define PJSUA_UNLOCK() |
| 278 | #endif |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 279 | |
| 280 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 281 | /** |
| 282 | * Resolve STUN server. |
| 283 | */ |
| 284 | pj_status_t pjsua_resolve_stun_server(pj_bool_t wait); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * Handle incoming invite request. |
| 288 | */ |
| 289 | pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata); |
| 290 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 291 | /* |
| 292 | * Media channel. |
| 293 | */ |
| 294 | pj_status_t pjsua_media_channel_init(pjsua_call_id call_id, |
| 295 | pjsip_role_e role); |
| 296 | pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, |
| 297 | pj_pool_t *pool, |
| 298 | pjmedia_sdp_session **p_sdp); |
| 299 | pj_status_t pjsua_media_channel_update(pjsua_call_id call_id, |
Benny Prijono | dbce2cf | 2007-03-28 16:24:00 +0000 | [diff] [blame] | 300 | const pjmedia_sdp_session *local_sdp, |
| 301 | const pjmedia_sdp_session *remote_sdp); |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 302 | pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id); |
| 303 | |
| 304 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 305 | /** |
| 306 | * Init presence. |
| 307 | */ |
| 308 | pj_status_t pjsua_pres_init(); |
| 309 | |
| 310 | /* |
| 311 | * Start presence subsystem. |
| 312 | */ |
| 313 | pj_status_t pjsua_pres_start(void); |
| 314 | |
| 315 | /** |
| 316 | * Refresh presence subscriptions |
| 317 | */ |
| 318 | void pjsua_pres_refresh(void); |
| 319 | |
| 320 | /* |
| 321 | * Shutdown presence. |
| 322 | */ |
| 323 | void pjsua_pres_shutdown(void); |
| 324 | |
| 325 | /** |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 326 | * Init presence for aoocunt. |
| 327 | */ |
| 328 | pj_status_t pjsua_pres_init_acc(int acc_id); |
| 329 | |
| 330 | /** |
Benny Prijono | 8b6834f | 2007-02-24 13:29:22 +0000 | [diff] [blame] | 331 | * Send PUBLISH |
| 332 | */ |
| 333 | pj_status_t pjsua_pres_init_publish_acc(int acc_id); |
| 334 | |
| 335 | /** |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 336 | * Terminate server subscription for the account |
| 337 | */ |
| 338 | void pjsua_pres_delete_acc(int acc_id); |
| 339 | |
| 340 | /** |
| 341 | * Init IM module handler to handle incoming MESSAGE outside dialog. |
| 342 | */ |
| 343 | pj_status_t pjsua_im_init(void); |
| 344 | |
| 345 | /** |
| 346 | * Init call subsystem. |
| 347 | */ |
| 348 | pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg); |
| 349 | |
| 350 | /** |
| 351 | * Start call subsystem. |
| 352 | */ |
| 353 | pj_status_t pjsua_call_subsys_start(void); |
| 354 | |
| 355 | /** |
| 356 | * Init media subsystems. |
| 357 | */ |
| 358 | pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg); |
| 359 | |
| 360 | /** |
| 361 | * Start pjsua media subsystem. |
| 362 | */ |
| 363 | pj_status_t pjsua_media_subsys_start(void); |
| 364 | |
| 365 | /** |
| 366 | * Destroy pjsua media subsystem. |
| 367 | */ |
| 368 | pj_status_t pjsua_media_subsys_destroy(void); |
| 369 | |
| 370 | /** |
| 371 | * Private: check if we can accept the message. |
| 372 | * If not, then p_accept header will be filled with a valid |
| 373 | * Accept header. |
| 374 | */ |
| 375 | pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata, |
| 376 | pjsip_accept_hdr **p_accept_hdr); |
| 377 | |
| 378 | /** |
| 379 | * Private: process pager message. |
| 380 | * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing(). |
| 381 | */ |
| 382 | void pjsua_im_process_pager(int call_id, const pj_str_t *from, |
| 383 | const pj_str_t *to, pjsip_rx_data *rdata); |
| 384 | |
| 385 | |
| 386 | /** |
| 387 | * Create Accept header for MESSAGE. |
| 388 | */ |
| 389 | pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool); |
| 390 | |
| 391 | /* |
| 392 | * Add additional headers etc in msg_data specified by application |
| 393 | * when sending requests. |
| 394 | */ |
| 395 | void pjsua_process_msg_data(pjsip_tx_data *tdata, |
| 396 | const pjsua_msg_data *msg_data); |
| 397 | |
| 398 | |
| 399 | /* |
| 400 | * Add route_set to outgoing requests |
| 401 | */ |
| 402 | void pjsua_set_msg_route_set( pjsip_tx_data *tdata, |
| 403 | const pjsip_route_hdr *route_set ); |
| 404 | |
| 405 | |
| 406 | /* |
| 407 | * Simple version of MIME type parsing (it doesn't support parameters) |
| 408 | */ |
| 409 | void pjsua_parse_media_type( pj_pool_t *pool, |
| 410 | const pj_str_t *mime, |
| 411 | pjsip_media_type *media_type); |
| 412 | |
| 413 | |
Benny Prijono | 62c5c5b | 2007-01-13 23:22:40 +0000 | [diff] [blame] | 414 | /* |
| 415 | * Internal function to init transport selector from transport id. |
| 416 | */ |
| 417 | void pjsua_init_tpselector(pjsua_transport_id tp_id, |
| 418 | pjsip_tpselector *sel); |
| 419 | |
| 420 | |
| 421 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 422 | PJ_END_DECL |
| 423 | |
| 424 | #endif /* __PJSUA_INTERNAL_H__ */ |
| 425 | |