blob: a24240639a8989005e38d791be22f937e514e950 [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 */
Benny Prijonoa91a0032006-02-26 21:23:45 +000050#ifndef PJSUA_MAX_BUDDIES
51# define PJSUA_MAX_BUDDIES 32
52#endif
53
Benny Prijonof3195072006-02-14 21:15:30 +000054
Benny Prijonof04ffdd2006-02-21 00:11:18 +000055/**
56 * Max simultaneous calls.
57 */
Benny Prijonoa91a0032006-02-26 21:23:45 +000058#ifndef PJSUA_MAX_CALLS
59# define PJSUA_MAX_CALLS 256
60#endif
61
62
63/**
64 * Aditional ports to be allocated in the conference ports for non-call
65 * streams.
66 */
67#define PJSUA_CONF_MORE_PORTS 2
68
69
70/**
71 * Maximum accounts.
72 */
73#ifndef PJSUA_MAX_ACC
74# define PJSUA_MAX_ACC 8
75#endif
76
77
78/**
79 * Maximum credentials.
80 */
81#ifndef PJSUA_MAX_CRED
82# define PJSUA_MAX_CRED PJSUA_MAX_ACC
83#endif
Benny Prijonof04ffdd2006-02-21 00:11:18 +000084
85
Benny Prijono632ce712006-02-09 14:01:40 +000086/**
Benny Prijonoa91a0032006-02-26 21:23:45 +000087 * Structure to be attached to invite dialog.
Benny Prijono632ce712006-02-09 14:01:40 +000088 * Given a dialog "dlg", application can retrieve this structure
89 * by accessing dlg->mod_data[pjsua.mod.id].
90 */
Benny Prijonoa91a0032006-02-26 21:23:45 +000091struct pjsua_call
Benny Prijono632ce712006-02-09 14:01:40 +000092{
Benny Prijonoa91a0032006-02-26 21:23:45 +000093 unsigned index; /**< Index in pjsua array. */
Benny Prijonof04ffdd2006-02-21 00:11:18 +000094 pjsip_inv_session *inv; /**< The invite session. */
Benny Prijonoa91a0032006-02-26 21:23:45 +000095 int acc_index; /**< Account index being used. */
Benny Prijonof04ffdd2006-02-21 00:11:18 +000096 pjmedia_session *session; /**< The media session. */
97 unsigned conf_slot; /**< Slot # in conference bridge. */
Benny Prijono26ff9062006-02-21 23:47:00 +000098 pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this
99 call was triggered by xfer. */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000100 pjmedia_sock_info skinfo; /**< Preallocated media sockets. */
101
102 void *app_data; /**< Application data. */
Benny Prijono632ce712006-02-09 14:01:40 +0000103};
104
Benny Prijonoa91a0032006-02-26 21:23:45 +0000105typedef struct pjsua_call pjsua_call;
106
Benny Prijono632ce712006-02-09 14:01:40 +0000107
Benny Prijono834aee32006-02-19 01:38:06 +0000108/**
109 * Buddy data.
110 */
111struct pjsua_buddy
112{
113 pj_str_t uri; /**< Buddy URI */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000114 int acc_index; /**< Which account to use. */
Benny Prijono834aee32006-02-19 01:38:06 +0000115 pj_bool_t monitor; /**< Should we monitor? */
116 pjsip_evsub *sub; /**< Buddy presence subscription */
117 pjsip_pres_status status; /**< Buddy presence status. */
118};
119
120typedef struct pjsua_buddy pjsua_buddy;
121
122
123/**
124 * Server presence subscription list head.
125 */
126struct pjsua_srv_pres
127{
128 PJ_DECL_LIST_MEMBER(struct pjsua_srv_pres);
129 pjsip_evsub *sub;
130 char *remote;
131};
132
133typedef struct pjsua_srv_pres pjsua_srv_pres;
134
135
Benny Prijonoa91a0032006-02-26 21:23:45 +0000136/**
137 * Account
138 */
139struct pjsua_acc
140{
141 int index; /**< Index in accounts array. */
142 pj_str_t local_uri; /**< Uri in From: header. */
143 pj_str_t user_part; /**< User part of local URI. */
144 pj_str_t host_part; /**< Host part of local URI. */
145 pj_str_t contact_uri; /**< Uri in Contact: header. */
146
147 pj_str_t reg_uri; /**< Registrar URI. */
148 pjsip_regc *regc; /**< Client registration session. */
149 pj_int32_t reg_timeout; /**< Default timeout. */
150 pj_timer_entry reg_timer; /**< Registration timer. */
151 pj_status_t reg_last_err; /**< Last registration error. */
152 int reg_last_code; /**< Last status last register. */
153
154 pj_str_t proxy; /**< Proxy URL. */
155 pjsip_route_hdr route_set; /**< Route set. */
156
157 pj_bool_t online_status; /**< Our online status. */
158 pjsua_srv_pres pres_srv_list; /**< Server subscription list. */
159
160 void *app_data; /**< Application data. */
161};
162
163
164typedef struct pjsua_acc pjsua_acc;
165
Benny Prijono632ce712006-02-09 14:01:40 +0000166
Benny Prijono268ca612006-02-07 12:34:11 +0000167/* PJSUA application variables. */
Benny Prijono95196582006-02-09 00:13:40 +0000168struct pjsua
Benny Prijono268ca612006-02-07 12:34:11 +0000169{
170 /* Control: */
Benny Prijono95196582006-02-09 00:13:40 +0000171 pj_caching_pool cp; /**< Global pool factory. */
172 pjsip_endpoint *endpt; /**< Global endpoint. */
173 pj_pool_t *pool; /**< pjsua's private pool. */
174 pjsip_module mod; /**< pjsua's PJSIP module. */
Benny Prijono268ca612006-02-07 12:34:11 +0000175
176
Benny Prijono95196582006-02-09 00:13:40 +0000177 /* Media: */
Benny Prijonocbf37402006-03-01 19:29:10 +0000178 int start_rtp_port;/**< Start of RTP port to try. */
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000179 pjmedia_endpt *med_endpt; /**< Media endpoint. */
Benny Prijono08e0d062006-03-04 14:52:44 +0000180 unsigned clock_rate; /**< Internal clock rate. */
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000181 pjmedia_conf *mconf; /**< Media conference. */
182 pj_bool_t null_audio; /**< Null audio flag. */
Benny Prijono39879152006-02-23 02:09:10 +0000183 char *wav_file; /**< WAV file name to play. */
184 unsigned wav_slot; /**< WAV player slot in bridge */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000185 pj_bool_t auto_play; /**< Auto play file for calls? */
186 pj_bool_t auto_loop; /**< Auto loop RTP stream? */
187 pj_bool_t auto_conf; /**< Auto put to conference? */
Benny Prijono1c2bf462006-03-05 11:54:02 +0000188 int complexity; /**< Codec complexity. */
189 int quality; /**< Codec quality. */
190
Benny Prijonoa91a0032006-02-26 21:23:45 +0000191
Benny Prijonoeb30bf52006-03-04 20:43:52 +0000192 /* Codec arguments: */
193 int codec_cnt; /**< Number of --add-codec args. */
194 pj_str_t codec_arg[32]; /**< Array of --add-codec args. */
195 pj_status_t (*codec_deinit[32])(void); /**< Array of funcs. */
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000196
Benny Prijono64f851e2006-02-23 13:49:28 +0000197 /* User Agent behaviour: */
Benny Prijono64f851e2006-02-23 13:49:28 +0000198 int auto_answer; /**< Automatically answer in calls. */
199
Benny Prijonoa91a0032006-02-26 21:23:45 +0000200 /* Account: */
Benny Prijonoccb03fa2006-03-06 13:35:47 +0000201 pj_bool_t has_acc; /**< Any --id cmdline? */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000202 int acc_cnt; /**< Number of client registrations */
203 pjsua_acc acc[PJSUA_MAX_ACC]; /** Client regs array. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000204
205
206 /* Authentication credentials: */
207
Benny Prijonoa91a0032006-02-26 21:23:45 +0000208 int cred_count; /**< Number of credentials. */
209 pjsip_cred_info cred_info[10]; /**< Array of credentials. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000210
211
Benny Prijonof04ffdd2006-02-21 00:11:18 +0000212 /* Threading (optional): */
Benny Prijono268ca612006-02-07 12:34:11 +0000213 int thread_cnt; /**< Thread count. */
214 pj_thread_t *threads[8]; /**< Thread instances. */
215 pj_bool_t quit_flag; /**< To signal thread to quit. */
216
217 /* Transport (UDP): */
Benny Prijono268ca612006-02-07 12:34:11 +0000218 pj_uint16_t sip_port; /**< SIP signaling port. */
219 pj_sock_t sip_sock; /**< SIP UDP socket. */
220 pj_sockaddr_in sip_sock_name; /**< Public/STUN UDP socket addr. */
Benny Prijono268ca612006-02-07 12:34:11 +0000221
Benny Prijonoa91a0032006-02-26 21:23:45 +0000222 pj_str_t outbound_proxy;/**< Outbound proxy. */
Benny Prijono268ca612006-02-07 12:34:11 +0000223
224
225 /* STUN: */
Benny Prijono268ca612006-02-07 12:34:11 +0000226 pj_str_t stun_srv1;
227 int stun_port1;
228 pj_str_t stun_srv2;
229 int stun_port2;
230
231
Benny Prijonoa91a0032006-02-26 21:23:45 +0000232 /* Logging: */
Benny Prijono268ca612006-02-07 12:34:11 +0000233 int log_level; /**< Logging verbosity. */
234 int app_log_level; /**< stdout log verbosity. */
235 unsigned log_decor; /**< Log decoration. */
Benny Prijonoccf95622006-02-07 18:48:01 +0000236 char *log_filename; /**< Log filename. */
Benny Prijono268ca612006-02-07 12:34:11 +0000237
Benny Prijonof3195072006-02-14 21:15:30 +0000238
Benny Prijonoa91a0032006-02-26 21:23:45 +0000239 /* PJSUA Calls: */
240 int max_calls; /**< Max nb of calls. */
241 int call_cnt; /**< Number of calls. */
242 pjsua_call calls[PJSUA_MAX_CALLS]; /** Calls array. */
Benny Prijonof3195072006-02-14 21:15:30 +0000243
244
Benny Prijono834aee32006-02-19 01:38:06 +0000245 /* SIMPLE and buddy status: */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000246 int buddy_cnt;
247 pjsua_buddy buddies[PJSUA_MAX_BUDDIES];
Benny Prijono1a01ad32006-02-07 21:13:28 +0000248};
Benny Prijono268ca612006-02-07 12:34:11 +0000249
Benny Prijono95196582006-02-09 00:13:40 +0000250
251/** PJSUA instance. */
252extern struct pjsua pjsua;
253
254
Benny Prijono268ca612006-02-07 12:34:11 +0000255
256/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000257 * PJSUA API (defined in pjsua_core.c).
Benny Prijono268ca612006-02-07 12:34:11 +0000258 */
259
260/**
261 * Initialize pjsua settings with default parameters.
262 */
263void pjsua_default(void);
264
265
266/**
267 * Display error message for the specified error code.
268 */
Benny Prijonobcaed6c2006-02-19 15:37:19 +0000269void pjsua_perror(const char *sender, const char *title,
270 pj_status_t status);
Benny Prijono268ca612006-02-07 12:34:11 +0000271
272
273/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000274 * Initialize pjsua application. Application can call this before parsing
275 * application settings.
276 *
277 * This will initialize all libraries, create endpoint instance, and register
278 * pjsip modules. Transport will NOT be created however.
279 *
280 * Application may register module after calling this function.
Benny Prijono268ca612006-02-07 12:34:11 +0000281 */
282pj_status_t pjsua_init(void);
283
284
285/**
Benny Prijonoccf95622006-02-07 18:48:01 +0000286 * Start pjsua stack. Application calls this after pjsua settings has been
287 * configured.
288 *
289 * This will start the transport, worker threads (if any), and registration
290 * process, if registration is configured.
291 */
292pj_status_t pjsua_start(void);
293
294
295/**
Benny Prijono268ca612006-02-07 12:34:11 +0000296 * Destroy pjsua.
297 */
298pj_status_t pjsua_destroy(void);
299
300
Benny Prijonoa91a0032006-02-26 21:23:45 +0000301/**
302 * Find account for incoming request.
Benny Prijono84126ab2006-02-09 09:30:09 +0000303 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000304int pjsua_find_account_for_incoming(pjsip_rx_data *rdata);
305
306
307/**
308 * Find account for outgoing request.
309 */
310int pjsua_find_account_for_outgoing(const pj_str_t *url);
311
312
313/*****************************************************************************
314 * PJSUA Call API (defined in pjsua_call.c).
315 */
316
317/**
318 * Init pjsua call module.
319 */
320pj_status_t pjsua_call_init(void);
Benny Prijono84126ab2006-02-09 09:30:09 +0000321
Benny Prijono268ca612006-02-07 12:34:11 +0000322/**
323 * Make outgoing call.
324 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000325pj_status_t pjsua_make_call(int acc_index,
326 const char *cstr_dest_uri,
327 int *p_call_index);
Benny Prijono268ca612006-02-07 12:34:11 +0000328
329
Benny Prijono84126ab2006-02-09 09:30:09 +0000330/**
331 * Handle incoming invite request.
332 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000333pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
Benny Prijono84126ab2006-02-09 09:30:09 +0000334
335
336/**
Benny Prijonoa91a0032006-02-26 21:23:45 +0000337 * Answer call.
338 */
339void pjsua_call_answer(int call_index, int code);
340
341/**
Benny Prijono26ff9062006-02-21 23:47:00 +0000342 * Hangup call.
343 */
Benny Prijono1c2bf462006-03-05 11:54:02 +0000344void pjsua_call_hangup(int call_index);
Benny Prijono26ff9062006-02-21 23:47:00 +0000345
346
347/**
348 * Put call on-hold.
349 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000350void pjsua_call_set_hold(int call_index);
Benny Prijono26ff9062006-02-21 23:47:00 +0000351
352
353/**
354 * Send re-INVITE (to release hold).
355 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000356void pjsua_call_reinvite(int call_index);
Benny Prijono26ff9062006-02-21 23:47:00 +0000357
358
359/**
360 * Transfer call.
361 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000362void pjsua_call_xfer(int call_index, const char *dest);
Benny Prijono26ff9062006-02-21 23:47:00 +0000363
364
365/**
Benny Prijonob0808372006-03-02 21:18:58 +0000366 * Send instant messaging inside INVITE session.
367 */
368void pjsua_call_send_im(int call_index, const char *text);
369
370
371/**
372 * Send IM typing indication inside INVITE session.
373 */
374void pjsua_call_typing(int call_index, pj_bool_t is_typing);
375
376/**
Benny Prijono834aee32006-02-19 01:38:06 +0000377 * Terminate all calls.
378 */
Benny Prijono1a174142006-03-01 20:46:13 +0000379void pjsua_call_hangup_all(void);
Benny Prijono834aee32006-02-19 01:38:06 +0000380
381
Benny Prijono268ca612006-02-07 12:34:11 +0000382/*****************************************************************************
Benny Prijono84126ab2006-02-09 09:30:09 +0000383 * PJSUA Client Registration API (defined in pjsua_reg.c).
Benny Prijonoccf95622006-02-07 18:48:01 +0000384 */
385
386/**
387 * Initialize client registration session.
388 *
389 * @param app_callback Optional callback
390 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000391pj_status_t pjsua_regc_init(int acc_index);
Benny Prijonoccf95622006-02-07 18:48:01 +0000392
393/**
394 * Update registration or perform unregistration. If renew argument is zero,
395 * this will start unregistration process.
396 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000397void pjsua_regc_update(int acc_index, pj_bool_t renew);
Benny Prijonoccf95622006-02-07 18:48:01 +0000398
399
Benny Prijono834aee32006-02-19 01:38:06 +0000400
401
402/*****************************************************************************
403 * PJSUA Presence (pjsua_pres.c)
404 */
405
406/**
407 * Init presence.
408 */
409pj_status_t pjsua_pres_init();
410
411/**
412 * Refresh both presence client and server subscriptions.
413 */
Benny Prijonoa91a0032006-02-26 21:23:45 +0000414void pjsua_pres_refresh(int acc_index);
Benny Prijono834aee32006-02-19 01:38:06 +0000415
416/**
417 * Terminate all subscriptions
418 */
419void pjsua_pres_shutdown(void);
420
421/**
422 * Dump presence subscriptions.
423 */
Benny Prijono1a174142006-03-01 20:46:13 +0000424void pjsua_pres_dump(pj_bool_t detail);
Benny Prijono834aee32006-02-19 01:38:06 +0000425
426
Benny Prijonoccf95622006-02-07 18:48:01 +0000427/*****************************************************************************
Benny Prijonob0808372006-03-02 21:18:58 +0000428 * PJSUA Instant Messaging (pjsua_im.c)
429 */
430
431/**
432 * The MESSAGE method (defined in pjsua_im.c)
433 */
434extern const pjsip_method pjsip_message_method;
435
436
437/**
438 * Init IM module handler to handle incoming MESSAGE outside dialog.
439 */
440pj_status_t pjsua_im_init();
441
442
443/**
444 * Create Accept header for MESSAGE.
445 */
446pjsip_accept_hdr* pjsua_im_create_accept(pj_pool_t *pool);
447
448/**
449 * Send IM outside dialog.
450 */
451pj_status_t pjsua_im_send(int acc_index, const char *dst_uri,
452 const char *text);
453
454
455/**
456 * Send typing indication outside dialog.
457 */
458pj_status_t pjsua_im_typing(int acc_index, const char *dst_uri,
459 pj_bool_t is_typing);
460
461
462/**
463 * Private: check if we can accept the message.
464 * If not, then p_accept header will be filled with a valid
465 * Accept header.
466 */
467pj_bool_t pjsua_im_accept_pager(pjsip_rx_data *rdata,
Benny Prijonof9c668f2006-03-06 15:14:59 +0000468 pjsip_accept_hdr **p_accept_hdr);
Benny Prijonob0808372006-03-02 21:18:58 +0000469
470/**
471 * Private: process pager message.
472 * This may trigger pjsua_ui_on_pager() or pjsua_ui_on_typing().
473 */
474void pjsua_im_process_pager(int call_id, const pj_str_t *from,
475 const pj_str_t *to, pjsip_rx_data *rdata);
476
477
478/*****************************************************************************
Benny Prijono268ca612006-02-07 12:34:11 +0000479 * User Interface API.
Benny Prijono84126ab2006-02-09 09:30:09 +0000480 *
Benny Prijono268ca612006-02-07 12:34:11 +0000481 * The UI API specifies functions that will be called by pjsua upon
482 * occurence of various events.
483 */
484
485/**
486 * Notify UI when invite state has changed.
487 */
Benny Prijonob0808372006-03-02 21:18:58 +0000488void pjsua_ui_on_call_state(int call_index, pjsip_event *e);
Benny Prijono268ca612006-02-07 12:34:11 +0000489
Benny Prijonof3195072006-02-14 21:15:30 +0000490/**
491 * Notify UI when registration status has changed.
492 */
Benny Prijonob0808372006-03-02 21:18:58 +0000493void pjsua_ui_on_reg_state(int acc_index);
494
495/**
496 * Notify UI on incoming pager (i.e. MESSAGE request).
497 * Argument call_index will be -1 if MESSAGE request is not related to an
498 * existing call.
499 */
500void pjsua_ui_on_pager(int call_index, const pj_str_t *from,
501 const pj_str_t *to, const pj_str_t *txt);
502
503
504/**
505 * Notify UI about typing indication.
506 */
507void pjsua_ui_on_typing(int call_index, const pj_str_t *from,
508 const pj_str_t *to, pj_bool_t is_typing);
Benny Prijonof3195072006-02-14 21:15:30 +0000509
510
511/*****************************************************************************
512 * Utilities.
513 *
514 */
515
516/** String to describe invite session states */
517extern const char *pjsua_inv_state_names[];
518
519/**
520 * Parse arguments (pjsua_opt.c).
521 */
522pj_status_t pjsua_parse_args(int argc, char *argv[]);
523
524/**
525 * Load settings from a file.
526 */
527pj_status_t pjsua_load_settings(const char *filename);
528
529/**
Benny Prijonoa91a0032006-02-26 21:23:45 +0000530 * Dump settings.
531 */
532int pjsua_dump_settings(char *buf, pj_size_t max);
533
534/**
Benny Prijonof3195072006-02-14 21:15:30 +0000535 * Save settings to a file.
536 */
537pj_status_t pjsua_save_settings(const char *filename);
538
539
540/*
541 * Verify that valid SIP url is given.
542 * @return PJ_SUCCESS if valid.
543 */
544pj_status_t pjsua_verify_sip_url(const char *c_url);
545
546/*
547 * Dump application states.
548 */
Benny Prijono1a174142006-03-01 20:46:13 +0000549void pjsua_dump(pj_bool_t detail);
Benny Prijonof3195072006-02-14 21:15:30 +0000550
Benny Prijono268ca612006-02-07 12:34:11 +0000551
Benny Prijono1a01ad32006-02-07 21:13:28 +0000552PJ_END_DECL
553
Benny Prijonof3195072006-02-14 21:15:30 +0000554
Benny Prijono268ca612006-02-07 12:34:11 +0000555#endif /* __PJSUA_H__ */