blob: 42344ec841f71d6b668d79ab8ac06506802295d4 [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#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
27PJ_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 */
34typedef 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 */
65typedef 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 */
76typedef 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 Prijonoc570f2d2006-07-18 00:33:02 +000082 pj_str_t display; /**< Display name, if any. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +000083 pj_str_t user_part; /**< User part of local URI. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +000084
Benny Prijonob4a17c92006-07-10 14:40:21 +000085 pj_str_t srv_domain; /**< Host part of reg server. */
86 int srv_port; /**< Port number of reg server. */
87
Benny Prijonoeebe9af2006-06-13 22:57:13 +000088 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. */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000100 pjsip_publishc *publish_sess; /**< Client publication session. */
101 pj_bool_t publish_state; /**< Last published online status */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000102
103} pjsua_acc;
104
105
106/**
107 *Transport.
108 */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000109typedef struct pjsua_transport_data
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000110{
Benny Prijonoe93e2872006-06-28 16:46:49 +0000111 int index;
112 pjsip_transport_type_e type;
113 pjsip_host_port local_name;
114
115 union {
116 pjsip_transport *tp;
117 pjsip_tpfactory *factory;
118 void *ptr;
119 } data;
120
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000121} pjsua_transport_data;
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000122
123
124/**
125 * Buddy data.
126 */
127typedef struct pjsua_buddy
128{
129 unsigned index; /**< Buddy index. */
130 pj_str_t uri; /**< Buddy URI. */
131 pj_str_t contact; /**< Contact learned from subscrp. */
132 pj_str_t name; /**< Buddy name. */
133 pj_str_t display; /**< Buddy display name. */
134 pj_str_t host; /**< Buddy host. */
135 unsigned port; /**< Buddy port. */
136 pj_bool_t monitor; /**< Should we monitor? */
137 pjsip_evsub *sub; /**< Buddy presence subscription */
138 pjsip_pres_status status; /**< Buddy presence status. */
139
140} pjsua_buddy;
141
142
143/**
144 * File player/recorder data.
145 */
146typedef struct pjsua_file_data
147{
Benny Prijonoa66c3312007-01-21 23:12:40 +0000148 pj_bool_t type; /* 0=player, 1=playlist */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000149 pjmedia_port *port;
150 unsigned slot;
151} pjsua_file_data;
152
153
154/**
155 * Additional parameters for conference bridge.
156 */
157typedef struct pjsua_conf_setting
158{
159 unsigned channel_count;
160 unsigned samples_per_frame;
161 unsigned bits_per_sample;
162} pjsua_conf_setting;
163
164
165/**
166 * Global pjsua application data.
167 */
168struct pjsua_data
169{
170
171 /* Control: */
172 pj_caching_pool cp; /**< Global pool factory. */
173 pj_pool_t *pool; /**< pjsua's private pool. */
174 pj_mutex_t *mutex; /**< Mutex protection for this data */
175
176 /* Logging: */
177 pjsua_logging_config log_cfg; /**< Current logging config. */
178 pj_oshandle_t log_file; /**<Output log file handle */
179
180 /* SIP: */
181 pjsip_endpoint *endpt; /**< Global endpoint. */
182 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000183 pjsua_transport_data tpdata[8]; /**< Array of transports. */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000184
185 /* Threading: */
186 pj_bool_t thread_quit_flag; /**< Thread quit flag. */
187 pj_thread_t *thread[4]; /**< Array of threads. */
188
189 /* Account: */
190 unsigned acc_cnt; /**< Number of accounts. */
191 pjsua_acc_id default_acc; /**< Default account ID */
192 pjsua_acc acc[PJSUA_MAX_ACC]; /**< Account array. */
Benny Prijono093d3022006-09-24 00:07:11 +0000193 pjsua_acc_id acc_ids[PJSUA_MAX_ACC]; /**< Acc sorted by prio*/
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000194
195 /* Calls: */
196 pjsua_config ua_cfg; /**< UA config. */
197 unsigned call_cnt; /**< Call counter. */
198 pjsua_call calls[PJSUA_MAX_CALLS];/**< Calls array. */
199
200 /* Buddy; */
201 unsigned buddy_cnt; /**< Buddy count. */
202 pjsua_buddy buddy[PJSUA_MAX_BUDDIES]; /**< Buddy array. */
203
204 /* Media: */
205 pjsua_media_config media_cfg; /**< Media config. */
206 pjmedia_endpt *med_endpt; /**< Media endpoint. */
207 pjsua_conf_setting mconf_cfg; /**< Additionan conf. bridge. param */
208 pjmedia_conf *mconf; /**< Conference bridge. */
209 int cap_dev; /**< Capture device ID. */
210 int play_dev; /**< Playback device ID. */
Benny Prijonoe909eac2006-07-27 22:04:56 +0000211 pj_bool_t no_snd; /**< No sound (app will manage it) */
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000212 pjmedia_snd_port *snd_port; /**< Sound port. */
213 pjmedia_master_port *null_snd; /**< Master port for null sound. */
214 pjmedia_port *null_port; /**< Null port. */
215
216
217 /* File players: */
218 unsigned player_cnt;/**< Number of file players. */
219 pjsua_file_data player[32];/**< Array of players. */
220
221 /* File recorders: */
222 unsigned rec_cnt; /**< Number of file recorders. */
223 pjsua_file_data recorder[32];/**< Array of file recorders. */
224};
225
226
227extern struct pjsua_data pjsua_var;
228
229
230/**
231 * IM callback data.
232 */
233typedef struct pjsua_im_data
234{
235 pjsua_acc_id acc_id;
236 pjsua_call_id call_id;
237 pj_str_t to;
238 pj_str_t body;
239 void *user_data;
240} pjsua_im_data;
241
242
243/**
244 * Duplicate IM data.
245 */
246PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
247 const pjsua_im_data *src)
248{
249 pjsua_im_data *dst;
250
Benny Prijono07113c92006-11-21 08:38:00 +0000251 dst = (pjsua_im_data*) pj_pool_alloc(pool, sizeof(*dst));
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000252 dst->acc_id = src->acc_id;
253 dst->call_id = src->call_id;
254 pj_strdup_with_null(pool, &dst->to, &src->to);
255 dst->user_data = src->user_data;
256 pj_strdup_with_null(pool, &dst->body, &src->body);
257
258 return dst;
259}
260
261
Benny Prijono148c9dd2006-09-19 13:37:53 +0000262#if 1
263#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
264#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
265#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000266#else
267#define PJSUA_LOCK()
Benny Prijono148c9dd2006-09-19 13:37:53 +0000268#define PJSUA_TRY_LOCK() PJ_SUCCESS
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000269#define PJSUA_UNLOCK()
270#endif
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000271
272
273
274/**
275 * Handle incoming invite request.
276 */
277pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
278
279/**
280 * Init presence.
281 */
282pj_status_t pjsua_pres_init();
283
284/*
285 * Start presence subsystem.
286 */
287pj_status_t pjsua_pres_start(void);
288
289/**
290 * Refresh presence subscriptions
291 */
292void pjsua_pres_refresh(void);
293
294/*
295 * Shutdown presence.
296 */
297void pjsua_pres_shutdown(void);
298
299/**
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000300 * Init presence for aoocunt.
301 */
302pj_status_t pjsua_pres_init_acc(int acc_id);
303
304/**
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000305 * Terminate server subscription for the account
306 */
307void pjsua_pres_delete_acc(int acc_id);
308
309/**
310 * Init IM module handler to handle incoming MESSAGE outside dialog.
311 */
312pj_status_t pjsua_im_init(void);
313
314/**
315 * Init call subsystem.
316 */
317pj_status_t pjsua_call_subsys_init(const pjsua_config *cfg);
318
319/**
320 * Start call subsystem.
321 */
322pj_status_t pjsua_call_subsys_start(void);
323
324/**
325 * Init media subsystems.
326 */
327pj_status_t pjsua_media_subsys_init(const pjsua_media_config *cfg);
328
329/**
330 * Start pjsua media subsystem.
331 */
332pj_status_t pjsua_media_subsys_start(void);
333
334/**
335 * Destroy pjsua media subsystem.
336 */
337pj_status_t pjsua_media_subsys_destroy(void);
338
339/**
340 * Private: check if we can accept the message.
341 * If not, then p_accept header will be filled with a valid
342 * Accept header.
343 */
344pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
345 pjsip_accept_hdr **p_accept_hdr);
346
347/**
348 * Private: process pager message.
349 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
350 */
351void pjsua_im_process_pager(int call_id, const pj_str_t *from,
352 const pj_str_t *to, pjsip_rx_data *rdata);
353
354
355/**
356 * Create Accept header for MESSAGE.
357 */
358pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
359
360/*
361 * Add additional headers etc in msg_data specified by application
362 * when sending requests.
363 */
364void pjsua_process_msg_data(pjsip_tx_data *tdata,
365 const pjsua_msg_data *msg_data);
366
367
368/*
369 * Add route_set to outgoing requests
370 */
371void pjsua_set_msg_route_set( pjsip_tx_data *tdata,
372 const pjsip_route_hdr *route_set );
373
374
375/*
376 * Simple version of MIME type parsing (it doesn't support parameters)
377 */
378void pjsua_parse_media_type( pj_pool_t *pool,
379 const pj_str_t *mime,
380 pjsip_media_type *media_type);
381
382
Benny Prijono62c5c5b2007-01-13 23:22:40 +0000383/*
384 * Internal function to init transport selector from transport id.
385 */
386void pjsua_init_tpselector(pjsua_transport_id tp_id,
387 pjsip_tpselector *sel);
388
389
390
Benny Prijonoeebe9af2006-06-13 22:57:13 +0000391PJ_END_DECL
392
393#endif /* __PJSUA_INTERNAL_H__ */
394