blob: 3afde35475fd65639ecd7fdc8166fee1d4e366c9 [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 Prijono632ce712006-02-09 14:01:40 +000071};
72
73
Benny Prijono834aee32006-02-19 01:38:06 +000074/**
75 * Buddy data.
76 */
77struct pjsua_buddy
78{
79 pj_str_t uri; /**< Buddy URI */
80 pj_bool_t monitor; /**< Should we monitor? */
81 pjsip_evsub *sub; /**< Buddy presence subscription */
82 pjsip_pres_status status; /**< Buddy presence status. */
83};
84
85typedef struct pjsua_buddy pjsua_buddy;
86
87
88/**
89 * Server presence subscription list head.
90 */
91struct pjsua_srv_pres
92{
93 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
94 pjsip_evsub *sub;
95 char *remote;
96};
97
98typedef struct pjsua_srv_pres pjsua_srv_pres;
99
100
Benny Prijono632ce712006-02-09 14:01:40 +0000101
Benny Prijono268ca612006-02-07 12:34:11 +0000102/* PJSUA application variables. */
Benny Prijono95196582006-02-09 00:13:40 +0000103struct pjsua
Benny Prijono268ca612006-02-07 12:34:11 +0000104{
105 /* Control: */
106
Benny Prijono95196582006-02-09 00:13:40 +0000107 pj_caching_pool cp; /**< Global pool factory. */
108 pjsip_endpoint *endpt; /**< Global endpoint. */
109 pj_pool_t *pool; /**< pjsua's private pool. */
110 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono268ca612006-02-07 12:34:11 +0000111
112
Benny Prijono95196582006-02-09 00:13:40 +0000113 /* Media: */
114
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000115 pjmedia_endpt *med_endpt; /**< Media endpoint. */
116 pjmedia_conf *mconf; /**< Media conference. */
117 pj_bool_t null_audio; /**< Null audio flag. */
118
119
120 /* Since we support simultaneous calls, we need to have multiple
121 * RTP sockets.
122 */
123 pjmedia_sock_info med_sock_info[PJSUA_MAX_CALLS];
124 pj_bool_t med_sock_use[PJSUA_MAX_CALLS];
Benny Prijono95196582006-02-09 00:13:40 +0000125
Benny Prijono268ca612006-02-07 12:34:11 +0000126 /* User info: */
Benny Prijonoccf95622006-02-07 18:48:01 +0000127
Benny Prijono268ca612006-02-07 12:34:11 +0000128 pj_str_t local_uri; /**< Uri in From: header. */
129 pj_str_t contact_uri; /**< Uri in Contact: header. */
130
Benny Prijonoccf95622006-02-07 18:48:01 +0000131 /* Proxy URLs: */
132
133 pj_str_t proxy;
134 pj_str_t outbound_proxy;
Benny Prijono95196582006-02-09 00:13:40 +0000135 pjsip_route_hdr route_set;
136
Benny Prijonoccf95622006-02-07 18:48:01 +0000137
138 /* Registration: */
139
140 pj_str_t registrar_uri;
141 pjsip_regc *regc;
142 pj_int32_t reg_timeout;
143 pj_timer_entry regc_timer;
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000144 pj_status_t regc_last_err; /**< Last registration error. */
Benny Prijonof3195072006-02-14 21:15:30 +0000145 int regc_last_code;/**< Last status last register. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000146
147
148 /* Authentication credentials: */
149
Benny Prijonof3195072006-02-14 21:15:30 +0000150 unsigned cred_count;
Benny Prijonoccf95622006-02-07 18:48:01 +0000151 pjsip_cred_info cred_info[4];
152
153
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000154 /* Threading (optional): */
Benny Prijono268ca612006-02-07 12:34:11 +0000155
156 int thread_cnt; /**< Thread count. */
157 pj_thread_t *threads[8]; /**< Thread instances. */
158 pj_bool_t quit_flag; /**< To signal thread to quit. */
159
160 /* Transport (UDP): */
161
162 pj_uint16_t sip_port; /**< SIP signaling port. */
163 pj_sock_t sip_sock; /**< SIP UDP socket. */
164 pj_sockaddr_in sip_sock_name; /**< Public/STUN UDP socket addr. */
Benny Prijono268ca612006-02-07 12:34:11 +0000165
166
167
168 /* STUN: */
169
170 pj_str_t stun_srv1;
171 int stun_port1;
172 pj_str_t stun_srv2;
173 int stun_port2;
174
175
176 /* Misc: */
177
178 int log_level; /**< Logging verbosity. */
179 int app_log_level; /**< stdout log verbosity. */
180 unsigned log_decor; /**< Log decoration. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000181 char *log_filename; /**< Log filename. */
Benny Prijono268ca612006-02-07 12:34:11 +0000182
Benny Prijonof3195072006-02-14 21:15:30 +0000183
Benny Prijono632ce712006-02-09 14:01:40 +0000184 /* List of invite sessions: */
185
186 struct pjsua_inv_data inv_list;
Benny Prijonof3195072006-02-14 21:15:30 +0000187
188
Benny Prijono834aee32006-02-19 01:38:06 +0000189 /* SIMPLE and buddy status: */
190
191 pj_bool_t online_status; /**< Out online status. */
192 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
Benny Prijonof3195072006-02-14 21:15:30 +0000193
194 unsigned buddy_cnt;
Benny Prijono834aee32006-02-19 01:38:06 +0000195 pjsua_buddy buddies[PJSUA_MAX_BUDDIES];
Benny Prijono1a01ad32006-02-07 21:13:28 +0000196};
Benny Prijono268ca612006-02-07 12:34:11 +0000197
Benny Prijono95196582006-02-09 00:13:40 +0000198
199/** PJSUA instance. */
200extern struct pjsua pjsua;
201
202
Benny Prijono268ca612006-02-07 12:34:11 +0000203
204/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000205 * PJSUA API (defined in pjsua_core.c).
Benny Prijono268ca612006-02-07 12:34:11 +0000206 */
207
208/**
209 * Initialize pjsua settings with default parameters.
210 */
211void pjsua_default(void);
212
213
214/**
215 * Display error message for the specified error code.
216 */
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000217void pjsua_perror(const char *sender, const char *title,
218 pj_status_t status);
Benny Prijono268ca612006-02-07 12:34:11 +0000219
220
221/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000222 * Initialize pjsua application. Application can call this before parsing
223 * application settings.
224 *
225 * This will initialize all libraries, create endpoint instance, and register
226 * pjsip modules. Transport will NOT be created however.
227 *
228 * Application may register module after calling this function.
Benny Prijono268ca612006-02-07 12:34:11 +0000229 */
230pj_status_t pjsua_init(void);
231
232
233/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000234 * Start pjsua stack. Application calls this after pjsua settings has been
235 * configured.
236 *
237 * This will start the transport, worker threads (if any), and registration
238 * process, if registration is configured.
239 */
240pj_status_t pjsua_start(void);
241
242
243/**
Benny Prijono268ca612006-02-07 12:34:11 +0000244 * Destroy pjsua.
245 */
246pj_status_t pjsua_destroy(void);
247
248
Benny Prijono84126ab2006-02-09 09:30:09 +0000249/*****************************************************************************
250 * PJSUA Invite session API (defined in pjsua_inv.c).
251 */
252
Benny Prijono268ca612006-02-07 12:34:11 +0000253/**
254 * Make outgoing call.
255 */
256pj_status_t pjsua_invite(const char *cstr_dest_uri,
257 pjsip_inv_session **p_inv);
258
259
Benny Prijono84126ab2006-02-09 09:30:09 +0000260/**
261 * Handle incoming invite request.
262 */
263pj_bool_t pjsua_inv_on_incoming(pjsip_rx_data *rdata);
264
265
266/**
267 * Callback to be called by session when invite session's state has changed.
268 */
269void pjsua_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
270
271
272/**
273 * Callback to be called by session when outgoing dialog has forked.
274 * This function will create a forked dialog.
275 */
276void pjsua_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e);
277
278
279/**
280 * Callback to be called when SDP offer/answer negotiation has just completed
281 * in the session. This function will start/update media if negotiation
282 * has succeeded.
283 */
284void pjsua_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status);
285
286
Benny Prijono834aee32006-02-19 01:38:06 +0000287/**
288 * Terminate all calls.
289 */
290void pjsua_inv_shutdown(void);
291
292
Benny Prijono268ca612006-02-07 12:34:11 +0000293/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000294 * PJSUA Client Registration API (defined in pjsua_reg.c).
Benny Prijonoccf95622006-02-07 18:48:01 +0000295 */
296
297/**
298 * Initialize client registration session.
299 *
300 * @param app_callback Optional callback
301 */
302pj_status_t pjsua_regc_init(void);
303
304/**
305 * Update registration or perform unregistration. If renew argument is zero,
306 * this will start unregistration process.
307 */
308void pjsua_regc_update(pj_bool_t renew);
309
310
Benny Prijono834aee32006-02-19 01:38:06 +0000311
312
313/*****************************************************************************
314 * PJSUA Presence (pjsua_pres.c)
315 */
316
317/**
318 * Init presence.
319 */
320pj_status_t pjsua_pres_init();
321
322/**
323 * Refresh both presence client and server subscriptions.
324 */
325void pjsua_pres_refresh(void);
326
327/**
328 * Terminate all subscriptions
329 */
330void pjsua_pres_shutdown(void);
331
332/**
333 * Dump presence subscriptions.
334 */
335void pjsua_pres_dump(void);
336
337
Benny Prijonoccf95622006-02-07 18:48:01 +0000338/*****************************************************************************
Benny Prijono268ca612006-02-07 12:34:11 +0000339 * User Interface API.
Benny Prijono84126ab2006-02-09 09:30:09 +0000340 *
Benny Prijono268ca612006-02-07 12:34:11 +0000341 * The UI API specifies functions that will be called by pjsua upon
342 * occurence of various events.
343 */
344
345/**
346 * Notify UI when invite state has changed.
347 */
Benny Prijonoccf95622006-02-07 18:48:01 +0000348void pjsua_ui_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e);
Benny Prijono268ca612006-02-07 12:34:11 +0000349
Benny Prijonof3195072006-02-14 21:15:30 +0000350/**
351 * Notify UI when registration status has changed.
352 */
353void pjsua_ui_regc_on_state_changed(int code);
354
355
356/*****************************************************************************
357 * Utilities.
358 *
359 */
360
361/** String to describe invite session states */
362extern const char *pjsua_inv_state_names[];
363
364/**
365 * Parse arguments (pjsua_opt.c).
366 */
367pj_status_t pjsua_parse_args(int argc, char *argv[]);
368
369/**
370 * Load settings from a file.
371 */
372pj_status_t pjsua_load_settings(const char *filename);
373
374/**
375 * Save settings to a file.
376 */
377pj_status_t pjsua_save_settings(const char *filename);
378
379
380/*
381 * Verify that valid SIP url is given.
382 * @return PJ_SUCCESS if valid.
383 */
384pj_status_t pjsua_verify_sip_url(const char *c_url);
385
386/*
387 * Dump application states.
388 */
389void pjsua_dump(void);
390
Benny Prijono268ca612006-02-07 12:34:11 +0000391
Benny Prijono1a01ad32006-02-07 21:13:28 +0000392PJ_END_DECL
393
Benny Prijonof3195072006-02-14 21:15:30 +0000394
Benny Prijono268ca612006-02-07 12:34:11 +0000395#endif /* __PJSUA_H__ */