Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1 | /* $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 | #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. */ |
| 52 | pjmedia_sock_info skinfo; /**< Preallocated media sockets. */ |
| 53 | pjmedia_transport *med_tp; /**< Media transport. */ |
| 54 | pj_timer_entry refresh_tm;/**< Timer to send re-INVITE. */ |
| 55 | pj_timer_entry hangup_tm; /**< Timer to hangup call. */ |
| 56 | |
| 57 | char last_text_buf_[128]; /**< Buffer for last_text. */ |
| 58 | |
| 59 | } pjsua_call; |
| 60 | |
| 61 | |
| 62 | /** |
| 63 | * Server presence subscription list head. |
| 64 | */ |
| 65 | typedef struct pjsua_srv_pres |
| 66 | { |
| 67 | PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres); |
| 68 | pjsip_evsub *sub; |
| 69 | char *remote; |
| 70 | } pjsua_srv_pres; |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * Account |
| 75 | */ |
| 76 | typedef struct pjsua_acc |
| 77 | { |
| 78 | pjsua_acc_config cfg; /**< Account configuration. */ |
| 79 | pj_bool_t valid; /**< Is this account valid? */ |
| 80 | |
| 81 | int index; /**< Index in accounts array. */ |
Benny Prijono | c570f2d | 2006-07-18 00:33:02 +0000 | [diff] [blame^] | 82 | pj_str_t display; /**< Display name, if any. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 83 | pj_str_t user_part; /**< User part of local URI. */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 84 | |
Benny Prijono | b4a17c9 | 2006-07-10 14:40:21 +0000 | [diff] [blame] | 85 | pj_str_t srv_domain; /**< Host part of reg server. */ |
| 86 | int srv_port; /**< Port number of reg server. */ |
| 87 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 88 | pjsip_regc *regc; /**< Client registration session. */ |
| 89 | pj_timer_entry reg_timer; /**< Registration timer. */ |
| 90 | pj_status_t reg_last_err; /**< Last registration error. */ |
| 91 | int reg_last_code; /**< Last status last register. */ |
| 92 | |
| 93 | pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/ |
| 94 | |
| 95 | unsigned cred_cnt; /**< Number of credentials. */ |
| 96 | pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */ |
| 97 | |
| 98 | pj_bool_t online_status; /**< Our online status. */ |
| 99 | pjsua_srv_pres pres_srv_list; /**< Server subscription list. */ |
| 100 | |
| 101 | } pjsua_acc; |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | *Transport. |
| 106 | */ |
| 107 | typedef struct transport_data |
| 108 | { |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 109 | int index; |
| 110 | pjsip_transport_type_e type; |
| 111 | pjsip_host_port local_name; |
| 112 | |
| 113 | union { |
| 114 | pjsip_transport *tp; |
| 115 | pjsip_tpfactory *factory; |
| 116 | void *ptr; |
| 117 | } data; |
| 118 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 119 | } transport_data; |
| 120 | |
| 121 | |
| 122 | /** |
| 123 | * Buddy data. |
| 124 | */ |
| 125 | typedef struct pjsua_buddy |
| 126 | { |
| 127 | unsigned index; /**< Buddy index. */ |
| 128 | pj_str_t uri; /**< Buddy URI. */ |
| 129 | pj_str_t contact; /**< Contact learned from subscrp. */ |
| 130 | pj_str_t name; /**< Buddy name. */ |
| 131 | pj_str_t display; /**< Buddy display name. */ |
| 132 | pj_str_t host; /**< Buddy host. */ |
| 133 | unsigned port; /**< Buddy port. */ |
| 134 | pj_bool_t monitor; /**< Should we monitor? */ |
| 135 | pjsip_evsub *sub; /**< Buddy presence subscription */ |
| 136 | pjsip_pres_status status; /**< Buddy presence status. */ |
| 137 | |
| 138 | } pjsua_buddy; |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * File player/recorder data. |
| 143 | */ |
| 144 | typedef struct pjsua_file_data |
| 145 | { |
| 146 | pjmedia_port *port; |
| 147 | unsigned slot; |
| 148 | } pjsua_file_data; |
| 149 | |
| 150 | |
| 151 | /** |
| 152 | * Additional parameters for conference bridge. |
| 153 | */ |
| 154 | typedef struct pjsua_conf_setting |
| 155 | { |
| 156 | unsigned channel_count; |
| 157 | unsigned samples_per_frame; |
| 158 | unsigned bits_per_sample; |
| 159 | } pjsua_conf_setting; |
| 160 | |
| 161 | |
| 162 | /** |
| 163 | * Global pjsua application data. |
| 164 | */ |
| 165 | struct pjsua_data |
| 166 | { |
| 167 | |
| 168 | /* Control: */ |
| 169 | pj_caching_pool cp; /**< Global pool factory. */ |
| 170 | pj_pool_t *pool; /**< pjsua's private pool. */ |
| 171 | pj_mutex_t *mutex; /**< Mutex protection for this data */ |
| 172 | |
| 173 | /* Logging: */ |
| 174 | pjsua_logging_config log_cfg; /**< Current logging config. */ |
| 175 | pj_oshandle_t log_file; /**<Output log file handle */ |
| 176 | |
| 177 | /* SIP: */ |
| 178 | pjsip_endpoint *endpt; /**< Global endpoint. */ |
| 179 | pjsip_module mod; /**< pjsua's PJSIP module. */ |
| 180 | transport_data tpdata[8]; /**< Array of transports. */ |
| 181 | |
| 182 | /* Threading: */ |
| 183 | pj_bool_t thread_quit_flag; /**< Thread quit flag. */ |
| 184 | pj_thread_t *thread[4]; /**< Array of threads. */ |
| 185 | |
| 186 | /* Account: */ |
| 187 | unsigned acc_cnt; /**< Number of accounts. */ |
| 188 | pjsua_acc_id default_acc; /**< Default account ID */ |
| 189 | pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */ |
| 190 | |
| 191 | /* Calls: */ |
| 192 | pjsua_config ua_cfg; /**< UA config. */ |
| 193 | unsigned call_cnt; /**< Call counter. */ |
| 194 | pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */ |
| 195 | |
| 196 | /* Buddy; */ |
| 197 | unsigned buddy_cnt; /**< Buddy count. */ |
| 198 | pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */ |
| 199 | |
| 200 | /* Media: */ |
| 201 | pjsua_media_config media_cfg; /**< Media config. */ |
| 202 | pjmedia_endpt *med_endpt; /**< Media endpoint. */ |
| 203 | pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */ |
| 204 | pjmedia_conf *mconf; /**< Conference bridge. */ |
| 205 | int cap_dev; /**< Capture device ID. */ |
| 206 | int play_dev; /**< Playback device ID. */ |
| 207 | pjmedia_snd_port *snd_port; /**< Sound port. */ |
| 208 | pjmedia_master_port *null_snd; /**< Master port for null sound. */ |
| 209 | pjmedia_port *null_port; /**< Null port. */ |
| 210 | |
| 211 | |
| 212 | /* File players: */ |
| 213 | unsigned player_cnt;/**< Number of file players. */ |
| 214 | pjsua_file_data player[32];/**< Array of players. */ |
| 215 | |
| 216 | /* File recorders: */ |
| 217 | unsigned rec_cnt; /**< Number of file recorders. */ |
| 218 | pjsua_file_data recorder[32];/**< Array of file recorders. */ |
| 219 | }; |
| 220 | |
| 221 | |
| 222 | extern struct pjsua_data pjsua_var; |
| 223 | |
| 224 | |
| 225 | /** |
| 226 | * IM callback data. |
| 227 | */ |
| 228 | typedef struct pjsua_im_data |
| 229 | { |
| 230 | pjsua_acc_id acc_id; |
| 231 | pjsua_call_id call_id; |
| 232 | pj_str_t to; |
| 233 | pj_str_t body; |
| 234 | void *user_data; |
| 235 | } pjsua_im_data; |
| 236 | |
| 237 | |
| 238 | /** |
| 239 | * Duplicate IM data. |
| 240 | */ |
| 241 | PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool, |
| 242 | const pjsua_im_data *src) |
| 243 | { |
| 244 | pjsua_im_data *dst; |
| 245 | |
| 246 | dst = pj_pool_alloc(pool, sizeof(*dst)); |
| 247 | dst->acc_id = src->acc_id; |
| 248 | dst->call_id = src->call_id; |
| 249 | pj_strdup_with_null(pool, &dst->to, &src->to); |
| 250 | dst->user_data = src->user_data; |
| 251 | pj_strdup_with_null(pool, &dst->body, &src->body); |
| 252 | |
| 253 | return dst; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | #define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex); |
| 258 | #define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex); |
| 259 | |
| 260 | |
| 261 | |
| 262 | /** |
| 263 | * Handle incoming invite request. |
| 264 | */ |
| 265 | pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata); |
| 266 | |
| 267 | /** |
| 268 | * Init presence. |
| 269 | */ |
| 270 | pj_status_t pjsua_pres_init(); |
| 271 | |
| 272 | /* |
| 273 | * Start presence subsystem. |
| 274 | */ |
| 275 | pj_status_t pjsua_pres_start(void); |
| 276 | |
| 277 | /** |
| 278 | * Refresh presence subscriptions |
| 279 | */ |
| 280 | void pjsua_pres_refresh(void); |
| 281 | |
| 282 | /* |
| 283 | * Shutdown presence. |
| 284 | */ |
| 285 | void pjsua_pres_shutdown(void); |
| 286 | |
| 287 | /** |
| 288 | * Terminate server subscription for the account |
| 289 | */ |
| 290 | void pjsua_pres_delete_acc(int acc_id); |
| 291 | |
| 292 | /** |
| 293 | * Init IM module handler to handle incoming MESSAGE outside dialog. |
| 294 | */ |
| 295 | pj_status_t pjsua_im_init(void); |
| 296 | |
| 297 | /** |
| 298 | * Init call subsystem. |
| 299 | */ |
| 300 | pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg); |
| 301 | |
| 302 | /** |
| 303 | * Start call subsystem. |
| 304 | */ |
| 305 | pj_status_t pjsua_call_subsys_start(void); |
| 306 | |
| 307 | /** |
| 308 | * Init media subsystems. |
| 309 | */ |
| 310 | pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg); |
| 311 | |
| 312 | /** |
| 313 | * Start pjsua media subsystem. |
| 314 | */ |
| 315 | pj_status_t pjsua_media_subsys_start(void); |
| 316 | |
| 317 | /** |
| 318 | * Destroy pjsua media subsystem. |
| 319 | */ |
| 320 | pj_status_t pjsua_media_subsys_destroy(void); |
| 321 | |
| 322 | /** |
| 323 | * Private: check if we can accept the message. |
| 324 | * If not, then p_accept header will be filled with a valid |
| 325 | * Accept header. |
| 326 | */ |
| 327 | pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata, |
| 328 | pjsip_accept_hdr **p_accept_hdr); |
| 329 | |
| 330 | /** |
| 331 | * Private: process pager message. |
| 332 | * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing(). |
| 333 | */ |
| 334 | void pjsua_im_process_pager(int call_id, const pj_str_t *from, |
| 335 | const pj_str_t *to, pjsip_rx_data *rdata); |
| 336 | |
| 337 | |
| 338 | /** |
| 339 | * Create Accept header for MESSAGE. |
| 340 | */ |
| 341 | pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool); |
| 342 | |
| 343 | /* |
| 344 | * Add additional headers etc in msg_data specified by application |
| 345 | * when sending requests. |
| 346 | */ |
| 347 | void pjsua_process_msg_data(pjsip_tx_data *tdata, |
| 348 | const pjsua_msg_data *msg_data); |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | * Add route_set to outgoing requests |
| 353 | */ |
| 354 | void pjsua_set_msg_route_set( pjsip_tx_data *tdata, |
| 355 | const pjsip_route_hdr *route_set ); |
| 356 | |
| 357 | |
| 358 | /* |
| 359 | * Simple version of MIME type parsing (it doesn't support parameters) |
| 360 | */ |
| 361 | void pjsua_parse_media_type( pj_pool_t *pool, |
| 362 | const pj_str_t *mime, |
| 363 | pjsip_media_type *media_type); |
| 364 | |
| 365 | |
| 366 | PJ_END_DECL |
| 367 | |
| 368 | #endif /* __PJSUA_INTERNAL_H__ */ |
| 369 | |