blob: e731b4e4dcac8619c2f52351a271bff58b6c40ec [file] [log] [blame]
Benny Prijono268ca612006-02-07 12:34:11 +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_H__
20#define __PJSUA_H__
21
22/* Include all PJSIP core headers. */
23#include <pjsip.h>
24
25/* Include all PJMEDIA headers. */
26#include <pjmedia.h>
27
Benny Prijono1f9afba2006-02-10 15:57:32 +000028/* Include all PJMEDIA-CODEC headers. */
29#include <pjmedia-codec.h>
30
Benny Prijono268ca612006-02-07 12:34:11 +000031/* Include all PJSIP-UA headers */
32#include <pjsip_ua.h>
33
Benny Prijono834aee32006-02-19 01:38:06 +000034/* Include all PJSIP-SIMPLE headers */
35#include <pjsip_simple.h>
36
Benny Prijono268ca612006-02-07 12:34:11 +000037/* Include all PJLIB-UTIL headers. */
38#include <pjlib-util.h>
39
40/* Include all PJLIB headers. */
41#include <pjlib.h>
42
43
Benny Prijono1a01ad32006-02-07 21:13:28 +000044PJ_BEGIN_DECL
45
Benny Prijono632ce712006-02-09 14:01:40 +000046
Benny Prijonof3195072006-02-14 21:15:30 +000047/**
48 * Max buddies in buddy list.
49 */
50#define PJSUA_MAX_BUDDIES 32
51
Benny Prijonof04ffdd2006-02-21 00:11:18 +000052/**
53 * Max simultaneous calls.
54 */
55#define PJSUA_MAX_CALLS 8
56
57
Benny Prijono632ce712006-02-09 14:01:40 +000058/**
59 * Structure to be attached to all dialog.
60 * Given a dialog "dlg", application can retrieve this structure
61 * by accessing dlg->mod_data[pjsua.mod.id].
62 */
63struct pjsua_inv_data
64{
65 PJ_DECL_LIST_MEMBER(struct pjsua_inv_data);
66
Benny Prijonof04ffdd2006-02-21 00:11:18 +000067 pjsip_inv_session *inv; /**< The invite session. */
68 pjmedia_session *session; /**< The media session. */
69 unsigned conf_slot; /**< Slot # in conference bridge. */
70 unsigned call_slot; /**< RTP media index in med_sock_use[] */
Benny Prijono26ff9062006-02-21 23:47:00 +000071 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
72 call was triggered by xfer. */
Benny Prijono632ce712006-02-09 14:01:40 +000073};
74
75
Benny Prijono834aee32006-02-19 01:38:06 +000076/**
77 * Buddy data.
78 */
79struct pjsua_buddy
80{
81 pj_str_t uri; /**< Buddy URI */
82 pj_bool_t monitor; /**< Should we monitor? */
83 pjsip_evsub *sub; /**< Buddy presence subscription */
84 pjsip_pres_status status; /**< Buddy presence status. */
85};
86
87typedef struct pjsua_buddy pjsua_buddy;
88
89
90/**
91 * Server presence subscription list head.
92 */
93struct pjsua_srv_pres
94{
95 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
96 pjsip_evsub *sub;
97 char *remote;
98};
99
100typedef struct pjsua_srv_pres pjsua_srv_pres;
101
102
Benny Prijono632ce712006-02-09 14:01:40 +0000103
Benny Prijono268ca612006-02-07 12:34:11 +0000104/* PJSUA application variables. */
Benny Prijono95196582006-02-09 00:13:40 +0000105struct pjsua
Benny Prijono268ca612006-02-07 12:34:11 +0000106{
107 /* Control: */
108
Benny Prijono95196582006-02-09 00:13:40 +0000109 pj_caching_pool cp; /**< Global pool factory. */
110 pjsip_endpoint *endpt; /**< Global endpoint. */
111 pj_pool_t *pool; /**< pjsua's private pool. */
112 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono268ca612006-02-07 12:34:11 +0000113
114
Benny Prijono95196582006-02-09 00:13:40 +0000115 /* Media: */
116
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000117 pjmedia_endpt *med_endpt; /**< Media endpoint. */
118 pjmedia_conf *mconf; /**< Media conference. */
119 pj_bool_t null_audio; /**< Null audio flag. */
120
121
122 /* Since we support simultaneous calls, we need to have multiple
123 * RTP sockets.
124 */
125 pjmedia_sock_info med_sock_info[PJSUA_MAX_CALLS];
126 pj_bool_t med_sock_use[PJSUA_MAX_CALLS];
Benny Prijono95196582006-02-09 00:13:40 +0000127
Benny Prijono268ca612006-02-07 12:34:11 +0000128 /* User info: */
Benny Prijonoccf95622006-02-07 18:48:01 +0000129
Benny Prijono268ca612006-02-07 12:34:11 +0000130 pj_str_t local_uri; /**< Uri in From: header. */
131 pj_str_t contact_uri; /**< Uri in Contact: header. */
132
Benny Prijonoccf95622006-02-07 18:48:01 +0000133 /* Proxy URLs: */
134
135 pj_str_t proxy;
136 pj_str_t outbound_proxy;
Benny Prijono95196582006-02-09 00:13:40 +0000137 pjsip_route_hdr route_set;
138
Benny Prijonoccf95622006-02-07 18:48:01 +0000139
140 /* Registration: */
141
142 pj_str_t registrar_uri;
143 pjsip_regc *regc;
144 pj_int32_t reg_timeout;
145 pj_timer_entry regc_timer;
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000146 pj_status_t regc_last_err; /**< Last registration error. */
Benny Prijonof3195072006-02-14 21:15:30 +0000147 int regc_last_code;/**< Last status last register. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000148
149
150 /* Authentication credentials: */
151
Benny Prijonof3195072006-02-14 21:15:30 +0000152 unsigned cred_count;
Benny Prijonoccf95622006-02-07 18:48:01 +0000153 pjsip_cred_info cred_info[4];
154
155
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000156 /* Threading (optional): */
Benny Prijono268ca612006-02-07 12:34:11 +0000157
158 int thread_cnt; /**< Thread count. */
159 pj_thread_t *threads[8]; /**< Thread instances. */
160 pj_bool_t quit_flag; /**< To signal thread to quit. */
161
162 /* Transport (UDP): */
163
164 pj_uint16_t sip_port; /**< SIP signaling port. */
165 pj_sock_t sip_sock; /**< SIP UDP socket. */
166 pj_sockaddr_in sip_sock_name; /**< Public/STUN UDP socket addr. */
Benny Prijono268ca612006-02-07 12:34:11 +0000167
168
169
170 /* STUN: */
171
172 pj_str_t stun_srv1;
173 int stun_port1;
174 pj_str_t stun_srv2;
175 int stun_port2;
176
177
178 /* Misc: */
179
180 int log_level; /**< Logging verbosity. */
181 int app_log_level; /**< stdout log verbosity. */
182 unsigned log_decor; /**< Log decoration. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000183 char *log_filename; /**< Log filename. */
Benny Prijono268ca612006-02-07 12:34:11 +0000184
Benny Prijonof3195072006-02-14 21:15:30 +0000185
Benny Prijono632ce712006-02-09 14:01:40 +0000186 /* List of invite sessions: */
187
188 struct pjsua_inv_data inv_list;
Benny Prijonof3195072006-02-14 21:15:30 +0000189
190
Benny Prijono834aee32006-02-19 01:38:06 +0000191 /* SIMPLE and buddy status: */
192
193 pj_bool_t online_status; /**< Out online status. */
194 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijonof3195072006-02-14 21:15:30 +0000195
196 unsigned buddy_cnt;
Benny Prijono834aee32006-02-19 01:38:06 +0000197 pjsua_buddy buddies[PJSUA_MAX_BUDDIES];
Benny Prijono1a01ad32006-02-07 21:13:28 +0000198};
Benny Prijono268ca612006-02-07 12:34:11 +0000199
Benny Prijono95196582006-02-09 00:13:40 +0000200
201/** PJSUA instance. */
202extern struct pjsua pjsua;
203
204
Benny Prijono268ca612006-02-07 12:34:11 +0000205
206/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000207 * PJSUA API (defined in pjsua_core.c).
Benny Prijono268ca612006-02-07 12:34:11 +0000208 */
209
210/**
211 * Initialize pjsua settings with default parameters.
212 */
213void pjsua_default(void);
214
215
216/**
217 * Display error message for the specified error code.
218 */
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000219void pjsua_perror(const char *sender, const char *title,
220 pj_status_t status);
Benny Prijono268ca612006-02-07 12:34:11 +0000221
222
223/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000224 * Initialize pjsua application. Application can call this before parsing
225 * application settings.
226 *
227 * This will initialize all libraries, create endpoint instance, and register
228 * pjsip modules. Transport will NOT be created however.
229 *
230 * Application may register module after calling this function.
Benny Prijono268ca612006-02-07 12:34:11 +0000231 */
232pj_status_t pjsua_init(void);
233
234
235/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000236 * Start pjsua stack. Application calls this after pjsua settings has been
237 * configured.
238 *
239 * This will start the transport, worker threads (if any), and registration
240 * process, if registration is configured.
241 */
242pj_status_t pjsua_start(void);
243
244
245/**
Benny Prijono268ca612006-02-07 12:34:11 +0000246 * Destroy pjsua.
247 */
248pj_status_t pjsua_destroy(void);
249
250
Benny Prijono84126ab2006-02-09 09:30:09 +0000251/*****************************************************************************
252 * PJSUA Invite session API (defined in pjsua_inv.c).
253 */
254
Benny Prijono268ca612006-02-07 12:34:11 +0000255/**
256 * Make outgoing call.
257 */
258pj_status_t pjsua_invite(const char *cstr_dest_uri,
Benny Prijono26ff9062006-02-21 23:47:00 +0000259 struct pjsua_inv_data **p_inv_data);
Benny Prijono268ca612006-02-07 12:34:11 +0000260
261
Benny Prijono84126ab2006-02-09 09:30:09 +0000262/**
263 * Handle incoming invite request.
264 */
265pj_bool_t pjsua_inv_on_incoming(pjsip_rx_data *rdata);
266
267
268/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000269 * Hangup call.
270 */
271void pjsua_inv_hangup(struct pjsua_inv_data *inv_session, int code);
272
273
274/**
275 * Put call on-hold.
276 */
277void pjsua_inv_set_hold(struct pjsua_inv_data *inv_session);
278
279
280/**
281 * Send re-INVITE (to release hold).
282 */
283void pjsua_inv_reinvite(struct pjsua_inv_data *inv_session);
284
285
286/**
287 * Transfer call.
288 */
289void pjsua_inv_xfer_call(struct pjsua_inv_data *inv_session,
290 const char *dest);
291
292
293/**
Benny Prijono84126ab2006-02-09 09:30:09 +0000294 * Callback to be called by session when invite session's state has changed.
295 */
296void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
297
298
299/**
300 * Callback to be called by session when outgoing dialog has forked.
301 * This function will create a forked dialog.
302 */
303void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e);
304
305
306/**
307 * Callback to be called when SDP offer/answer negotiation has just completed
308 * in the session. This function will start/update media if negotiation
309 * has succeeded.
310 */
311void pjsua_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status);
312
Benny Prijono26ff9062006-02-21 23:47:00 +0000313/**
314 * Callback called when invite session received new offer.
315 */
316void pjsua_inv_on_rx_offer( pjsip_inv_session *inv,
317 const pjmedia_sdp_session *offer);
318
319/**
320 * Callback to receive transaction state inside invite session or dialog
321 * (e.g. REFER, MESSAGE).
322 */
323void pjsua_inv_on_tsx_state_changed(pjsip_inv_session *inv,
324 pjsip_transaction *tsx,
325 pjsip_event *e);
Benny Prijono84126ab2006-02-09 09:30:09 +0000326
Benny Prijono834aee32006-02-19 01:38:06 +0000327/**
328 * Terminate all calls.
329 */
330void pjsua_inv_shutdown(void);
331
332
Benny Prijono268ca612006-02-07 12:34:11 +0000333/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000334 * PJSUA Client Registration API (defined in pjsua_reg.c).
Benny Prijonoccf95622006-02-07 18:48:01 +0000335 */
336
337/**
338 * Initialize client registration session.
339 *
340 * @param app_callback Optional callback
341 */
342pj_status_t pjsua_regc_init(void);
343
344/**
345 * Update registration or perform unregistration. If renew argument is zero,
346 * this will start unregistration process.
347 */
348void pjsua_regc_update(pj_bool_t renew);
349
350
Benny Prijono834aee32006-02-19 01:38:06 +0000351
352
353/*****************************************************************************
354 * PJSUA Presence (pjsua_pres.c)
355 */
356
357/**
358 * Init presence.
359 */
360pj_status_t pjsua_pres_init();
361
362/**
363 * Refresh both presence client and server subscriptions.
364 */
365void pjsua_pres_refresh(void);
366
367/**
368 * Terminate all subscriptions
369 */
370void pjsua_pres_shutdown(void);
371
372/**
373 * Dump presence subscriptions.
374 */
375void pjsua_pres_dump(void);
376
377
Benny Prijonoccf95622006-02-07 18:48:01 +0000378/*****************************************************************************
Benny Prijono268ca612006-02-07 12:34:11 +0000379 * User Interface API.
Benny Prijono84126ab2006-02-09 09:30:09 +0000380 *
Benny Prijono268ca612006-02-07 12:34:11 +0000381 * The UI API specifies functions that will be called by pjsua upon
382 * occurence of various events.
383 */
384
385/**
386 * Notify UI when invite state has changed.
387 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000388void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
Benny Prijono268ca612006-02-07 12:34:11 +0000389
Benny Prijonof3195072006-02-14 21:15:30 +0000390/**
391 * Notify UI when registration status has changed.
392 */
393void pjsua_ui_regc_on_state_changed(int code);
394
395
396/*****************************************************************************
397 * Utilities.
398 *
399 */
400
401/** String to describe invite session states */
402extern const char *pjsua_inv_state_names[];
403
404/**
405 * Parse arguments (pjsua_opt.c).
406 */
407pj_status_t pjsua_parse_args(int argc, char *argv[]);
408
409/**
410 * Load settings from a file.
411 */
412pj_status_t pjsua_load_settings(const char *filename);
413
414/**
415 * Save settings to a file.
416 */
417pj_status_t pjsua_save_settings(const char *filename);
418
419
420/*
421 * Verify that valid SIP url is given.
422 * @return PJ_SUCCESS if valid.
423 */
424pj_status_t pjsua_verify_sip_url(const char *c_url);
425
426/*
427 * Dump application states.
428 */
429void pjsua_dump(void);
430
Benny Prijono268ca612006-02-07 12:34:11 +0000431
Benny Prijono1a01ad32006-02-07 21:13:28 +0000432PJ_END_DECL
433
Benny Prijonof3195072006-02-14 21:15:30 +0000434
Benny Prijono268ca612006-02-07 12:34:11 +0000435#endif /* __PJSUA_H__ */