blob: e87220867b3d4329df98a33a784589cfc4d4a261 [file] [log] [blame]
Riza Sulistyobc9c6772013-04-05 03:02:19 +00001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <pjsua-lib/pjsua.h>
21#include "pjsua_common.h"
22
23#define THIS_FILE "pjsua_config.c"
24
25#define MAX_APP_OPTIONS 128
26
27char *stdout_refresh_text = "STDOUT_REFRESH";
28
29/** This is for storing console runtime options **/
30static int cmd_argc;
31static char cmd_argv[MAX_APP_OPTIONS][MAX_APP_OPTIONS];
32
33/* Show usage */
34static void usage(void)
35{
36 puts ("Usage:");
37 puts (" pjsua [options] [SIP URL to call]");
38 puts ("");
39 puts ("General options:");
40 puts (" --config-file=file Read the config/arguments from file.");
41 puts (" --help Display this help screen");
42 puts (" --version Display version info");
43 puts ("");
44 puts ("Logging options:");
45 puts (" --log-file=fname Log to filename (default stderr)");
46 puts (" --log-level=N Set log max level to N (0(none) to 6(trace)) (default=5)");
47 puts (" --app-log-level=N Set log max level for stdout display (default=4)");
48 puts (" --log-append Append instead of overwrite existing log file.\n");
49 puts (" --color Use colorful logging (default yes on Win32)");
50 puts (" --no-color Disable colorful logging");
51 puts (" --light-bg Use dark colors for light background (default is dark bg)");
52 puts (" --no-stderr Disable stderr");
53
54 puts ("");
55 puts ("SIP Account options:");
56 puts (" --registrar=url Set the URL of registrar server");
57 puts (" --id=url Set the URL of local ID (used in From header)");
58 puts (" --realm=string Set realm");
59 puts (" --username=string Set authentication username");
60 puts (" --password=string Set authentication password");
61 puts (" --contact=url Optionally override the Contact information");
62 puts (" --contact-params=S Append the specified parameters S in Contact header");
63 puts (" --contact-uri-params=S Append the specified parameters S in Contact URI");
64 puts (" --proxy=url Optional URL of proxy server to visit");
65 puts (" May be specified multiple times");
66 printf(" --reg-timeout=SEC Optional registration interval (default %d)\n",
67 PJSUA_REG_INTERVAL);
68 printf(" --rereg-delay=SEC Optional auto retry registration interval (default %d)\n",
69 PJSUA_REG_RETRY_INTERVAL);
70 puts (" --reg-use-proxy=N Control the use of proxy settings in REGISTER.");
71 puts (" 0=no proxy, 1=outbound only, 2=acc only, 3=all (default)");
72 puts (" --publish Send presence PUBLISH for this account");
73 puts (" --mwi Subscribe to message summary/waiting indication");
74 puts (" --use-ims Enable 3GPP/IMS related settings on this account");
75#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
76 puts (" --use-srtp=N Use SRTP? 0:disabled, 1:optional, 2:mandatory,");
77 puts (" 3:optional by duplicating media offer (def:0)");
78 puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 2:sips (def:1)");
79#endif
80 puts (" --use-100rel Require reliable provisional response (100rel)");
81 puts (" --use-timer=N Use SIP session timers? (default=1)");
82 puts (" 0:inactive, 1:optional, 2:mandatory, 3:always");
83 printf(" --timer-se=N Session timers expiration period, in secs (def:%d)\n",
84 PJSIP_SESS_TIMER_DEF_SE);
85 puts (" --timer-min-se=N Session timers minimum expiration period, in secs (def:90)");
86 puts (" --outb-rid=string Set SIP outbound reg-id (default:1)");
87 puts (" --auto-update-nat=N Where N is 0 or 1 to enable/disable SIP traversal behind");
88 puts (" symmetric NAT (default 1)");
89 puts (" --disable-stun Disable STUN for this account");
90 puts (" --next-cred Add another credentials");
91 puts ("");
92 puts ("SIP Account Control:");
93 puts (" --next-account Add more account");
94 puts ("");
95 puts ("Transport Options:");
96#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6
97 puts (" --ipv6 Use IPv6 instead for SIP and media.");
98#endif
99 puts (" --set-qos Enable QoS tagging for SIP and media.");
100 puts (" --local-port=port Set TCP/UDP port. This implicitly enables both ");
101 puts (" TCP and UDP transports on the specified port, unless");
102 puts (" if TCP or UDP is disabled.");
103 puts (" --ip-addr=IP Use the specifed address as SIP and RTP addresses.");
104 puts (" (Hint: the IP may be the public IP of the NAT/router)");
105 puts (" --bound-addr=IP Bind transports to this IP interface");
106 puts (" --no-tcp Disable TCP transport.");
107 puts (" --no-udp Disable UDP transport.");
108 puts (" --nameserver=NS Add the specified nameserver to enable SRV resolution");
109 puts (" This option can be specified multiple times.");
110 puts (" --outbound=url Set the URL of global outbound proxy server");
111 puts (" May be specified multiple times");
112 puts (" --stun-srv=FORMAT Set STUN server host or domain. This option may be");
113 puts (" specified more than once. FORMAT is hostdom[:PORT]");
114
115#if defined(PJSIP_HAS_TLS_TRANSPORT) && (PJSIP_HAS_TLS_TRANSPORT != 0)
116 puts ("");
117 puts ("TLS Options:");
118 puts (" --use-tls Enable TLS transport (default=no)");
119 puts (" --tls-ca-file Specify TLS CA file (default=none)");
120 puts (" --tls-cert-file Specify TLS certificate file (default=none)");
121 puts (" --tls-privkey-file Specify TLS private key file (default=none)");
122 puts (" --tls-password Specify TLS password to private key file (default=none)");
123 puts (" --tls-verify-server Verify server's certificate (default=no)");
124 puts (" --tls-verify-client Verify client's certificate (default=no)");
125 puts (" --tls-neg-timeout Specify TLS negotiation timeout (default=no)");
126 puts (" --tls-srv-name Specify TLS server name for multihosting server");
127 puts (" --tls-cipher Specify prefered TLS cipher (optional).");
128 puts (" May be specified multiple times");
129#endif
130
131 puts ("");
132 puts ("Audio Options:");
133 puts (" --add-codec=name Manually add codec (default is to enable all)");
134 puts (" --dis-codec=name Disable codec (can be specified multiple times)");
135 puts (" --clock-rate=N Override conference bridge clock rate");
136 puts (" --snd-clock-rate=N Override sound device clock rate");
137 puts (" --stereo Audio device and conference bridge opened in stereo mode");
138 puts (" --null-audio Use NULL audio device");
139 puts (" --play-file=file Register WAV file in conference bridge.");
140 puts (" This can be specified multiple times.");
141 puts (" --play-tone=FORMAT Register tone to the conference bridge.");
142 puts (" FORMAT is 'F1,F2,ON,OFF', where F1,F2 are");
143 puts (" frequencies, and ON,OFF=on/off duration in msec.");
144 puts (" This can be specified multiple times.");
145 puts (" --auto-play Automatically play the file (to incoming calls only)");
146 puts (" --auto-loop Automatically loop incoming RTP to outgoing RTP");
147 puts (" --auto-conf Automatically put calls in conference with others");
148 puts (" --rec-file=file Open file recorder (extension can be .wav or .mp3");
149 puts (" --auto-rec Automatically record conversation");
150 puts (" --quality=N Specify media quality (0-10, default=6)");
151 puts (" --ptime=MSEC Override codec ptime to MSEC (default=specific)");
152 puts (" --no-vad Disable VAD/silence detector (default=vad enabled)");
153 puts (" --ec-tail=MSEC Set echo canceller tail length (default=256)");
154 puts (" --ec-opt=OPT Select echo canceller algorithm (0=default, ");
155 puts (" 1=speex, 2=suppressor)");
156 puts (" --ilbc-mode=MODE Set iLBC codec mode (20 or 30, default is 30)");
157 puts (" --capture-dev=id Audio capture device ID (default=-1)");
158 puts (" --playback-dev=id Audio playback device ID (default=-1)");
159 puts (" --capture-lat=N Audio capture latency, in ms (default=100)");
160 puts (" --playback-lat=N Audio playback latency, in ms (default=100)");
161 puts (" --snd-auto-close=N Auto close audio device when idle for N secs (default=1)");
162 puts (" Specify N=-1 to disable this feature.");
163 puts (" Specify N=0 for instant close when unused.");
164 puts (" --no-tones Disable audible tones");
165 puts (" --jb-max-size Specify jitter buffer maximum size, in frames (default=-1)");
166 puts (" --extra-audio Add one more audio stream");
167
168#if PJSUA_HAS_VIDEO
169 puts ("");
170 puts ("Video Options:");
171 puts (" --video Enable video");
172 puts (" --vcapture-dev=id Video capture device ID (default=-1)");
173 puts (" --vrender-dev=id Video render device ID (default=-2)");
174 puts (" --play-avi=FILE Load this AVI as virtual capture device");
175 puts (" --auto-play-avi Automatically play the AVI media to call");
176#endif
177
178 puts ("");
179 puts ("Media Transport Options:");
180 puts (" --use-ice Enable ICE (default:no)");
181 puts (" --ice-regular Use ICE regular nomination (default: aggressive)");
182 puts (" --ice-max-hosts=N Set maximum number of ICE host candidates");
183 puts (" --ice-no-rtcp Disable RTCP component in ICE (default: no)");
184 puts (" --rtp-port=N Base port to try for RTP (default=4000)");
185 puts (" --rx-drop-pct=PCT Drop PCT percent of RX RTP (for pkt lost sim, default: 0)");
186 puts (" --tx-drop-pct=PCT Drop PCT percent of TX RTP (for pkt lost sim, default: 0)");
187 puts (" --use-turn Enable TURN relay with ICE (default:no)");
188 puts (" --turn-srv Domain or host name of TURN server (\"NAME:PORT\" format)");
189 puts (" --turn-tcp Use TCP connection to TURN server (default no)");
190 puts (" --turn-user TURN username");
191 puts (" --turn-passwd TURN password");
192
193 puts ("");
194 puts ("Buddy List (can be more than one):");
195 puts (" --add-buddy url Add the specified URL to the buddy list.");
196 puts ("");
197 puts ("User Agent options:");
198 puts (" --auto-answer=code Automatically answer incoming calls with code (e.g. 200)");
199 puts (" --max-calls=N Maximum number of concurrent calls (default:4, max:255)");
200 puts (" --thread-cnt=N Number of worker threads (default:1)");
201 puts (" --duration=SEC Set maximum call duration (default:no limit)");
202 puts (" --norefersub Suppress event subscription when transfering calls");
203 puts (" --use-compact-form Minimize SIP message size");
204 puts (" --no-force-lr Allow strict-route to be used (i.e. do not force lr)");
205 puts (" --accept-redirect=N Specify how to handle call redirect (3xx) response.");
206 puts (" 0: reject, 1: follow automatically,");
207 puts (" 2: follow + replace To header (default), 3: ask");
208
209 puts ("");
210 puts ("CLI options:");
211 puts (" --use-cli Use CLI as user interface");
212 puts (" --cli-telnet-port=N CLI telnet port");
213 puts (" --no-cli-console Disable CLI console");
214 puts ("");
215
216 puts ("");
217 puts ("When URL is specified, pjsua will immediately initiate call to that URL");
218 puts ("");
219
220 fflush(stdout);
221}
222
223/*
224 * Read command arguments from config file.
225 */
226static int read_config_file(pj_pool_t *pool, const char *filename,
227 int *app_argc, char ***app_argv)
228{
229 int i;
230 FILE *fhnd;
231 char line[200];
232 int argc = 0;
233 char **argv;
234 enum { MAX_ARGS = 128 };
235
236 /* Allocate MAX_ARGS+1 (argv needs to be terminated with NULL argument) */
237 argv = pj_pool_calloc(pool, MAX_ARGS+1, sizeof(char*));
238 argv[argc++] = *app_argv[0];
239
240 /* Open config file. */
241 fhnd = fopen(filename, "rt");
242 if (!fhnd) {
243 PJ_LOG(1,(THIS_FILE, "Unable to open config file %s", filename));
244 fflush(stdout);
245 return -1;
246 }
247
248 /* Scan tokens in the file. */
249 while (argc < MAX_ARGS && !feof(fhnd)) {
250 char *token;
251 char *p;
252 const char *whitespace = " \t\r\n";
253 char cDelimiter;
254 int len, token_len;
255
256 pj_bzero(line, sizeof(line));
257 if (fgets(line, sizeof(line), fhnd) == NULL) break;
258
259 // Trim ending newlines
260 len = strlen(line);
261 if (line[len-1]=='\n')
262 line[--len] = '\0';
263 if (line[len-1]=='\r')
264 line[--len] = '\0';
265
266 if (len==0) continue;
267
268 for (p = line; *p != '\0' && argc < MAX_ARGS; p++) {
269 // first, scan whitespaces
270 while (*p != '\0' && strchr(whitespace, *p) != NULL) p++;
271
272 if (*p == '\0') // are we done yet?
273 break;
274
275 if (*p == '"' || *p == '\'') { // is token a quoted string
276 cDelimiter = *p++; // save quote delimiter
277 token = p;
278
279 while (*p != '\0' && *p != cDelimiter) p++;
280
281 if (*p == '\0') // found end of the line, but,
282 cDelimiter = '\0'; // didn't find a matching quote
283
284 } else { // token's not a quoted string
285 token = p;
286
287 while (*p != '\0' && strchr(whitespace, *p) == NULL) p++;
288
289 cDelimiter = *p;
290 }
291
292 *p = '\0';
293 token_len = p-token;
294
295 if (token_len > 0) {
296 if (*token == '#')
297 break; // ignore remainder of line
298
299 argv[argc] = pj_pool_alloc(pool, token_len + 1);
300 pj_memcpy(argv[argc], token, token_len + 1);
301 ++argc;
302 }
303
304 *p = cDelimiter;
305 }
306 }
307
308 /* Copy arguments from command line */
309 for (i=1; i<*app_argc && argc < MAX_ARGS; ++i)
310 argv[argc++] = (*app_argv)[i];
311
312 if (argc == MAX_ARGS && (i!=*app_argc || !feof(fhnd))) {
313 PJ_LOG(1,(THIS_FILE,
314 "Too many arguments specified in cmd line/config file"));
315 fflush(stdout);
316 fclose(fhnd);
317 return -1;
318 }
319
320 fclose(fhnd);
321
322 /* Assign the new command line back to the original command line. */
323 *app_argc = argc;
324 *app_argv = argv;
325 return 0;
326}
327
328/* Parse arguments. */
329static pj_status_t parse_args(int argc, char *argv[],
330 pjsua_app_config *cfg,
331 pj_str_t *uri_to_call)
332{
333 int c;
334 int option_index;
335 enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL,
336 OPT_LOG_APPEND, OPT_COLOR, OPT_NO_COLOR, OPT_LIGHT_BG, OPT_NO_STDERR,
337 OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE,
338 OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY,
339 OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT,
340 OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, OPT_CONTACT_URI_PARAMS,
341 OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD,
342 OPT_REG_RETRY_INTERVAL, OPT_REG_USE_PROXY,
343 OPT_MWI, OPT_NAMESERVER, OPT_STUN_SRV, OPT_OUTB_RID,
344 OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE,
345 OPT_AUTO_ANSWER, OPT_AUTO_PLAY, OPT_AUTO_PLAY_HANGUP, OPT_AUTO_LOOP,
346 OPT_AUTO_CONF, OPT_CLOCK_RATE, OPT_SND_CLOCK_RATE, OPT_STEREO,
347 OPT_USE_ICE, OPT_ICE_REGULAR, OPT_USE_SRTP, OPT_SRTP_SECURE,
348 OPT_USE_TURN, OPT_ICE_MAX_HOSTS, OPT_ICE_NO_RTCP, OPT_TURN_SRV,
349 OPT_TURN_TCP, OPT_TURN_USER, OPT_TURN_PASSWD,
350 OPT_PLAY_FILE, OPT_PLAY_TONE, OPT_RTP_PORT, OPT_ADD_CODEC,
351 OPT_ILBC_MODE, OPT_REC_FILE, OPT_AUTO_REC,
352 OPT_COMPLEXITY, OPT_QUALITY, OPT_PTIME, OPT_NO_VAD,
353 OPT_RX_DROP_PCT, OPT_TX_DROP_PCT, OPT_EC_TAIL, OPT_EC_OPT,
354 OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS,
355 OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, OPT_THREAD_CNT,
356 OPT_NOREFERSUB, OPT_ACCEPT_REDIRECT,
357 OPT_USE_TLS, OPT_TLS_CA_FILE, OPT_TLS_CERT_FILE, OPT_TLS_PRIV_FILE,
358 OPT_TLS_PASSWORD, OPT_TLS_VERIFY_SERVER, OPT_TLS_VERIFY_CLIENT,
359 OPT_TLS_NEG_TIMEOUT, OPT_TLS_CIPHER,
360 OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV,
361 OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, OPT_NO_TONES, OPT_JB_MAX_SIZE,
362 OPT_STDOUT_REFRESH, OPT_STDOUT_REFRESH_TEXT, OPT_IPV6, OPT_QOS,
363#ifdef _IONBF
364 OPT_STDOUT_NO_BUF,
365#endif
366 OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC,
367 OPT_DISABLE_STUN, OPT_NO_FORCE_LR,
368 OPT_TIMER, OPT_TIMER_SE, OPT_TIMER_MIN_SE,
369 OPT_VIDEO, OPT_EXTRA_AUDIO,
370 OPT_VCAPTURE_DEV, OPT_VRENDER_DEV, OPT_PLAY_AVI, OPT_AUTO_PLAY_AVI,
371 OPT_USE_CLI, OPT_CLI_TELNET_PORT, OPT_DISABLE_CLI_CONSOLE
372 };
373 struct pj_getopt_option long_options[] = {
374 { "config-file",1, 0, OPT_CONFIG_FILE},
375 { "log-file", 1, 0, OPT_LOG_FILE},
376 { "log-level", 1, 0, OPT_LOG_LEVEL},
377 { "app-log-level",1,0,OPT_APP_LOG_LEVEL},
378 { "log-append", 0, 0, OPT_LOG_APPEND},
379 { "color", 0, 0, OPT_COLOR},
380 { "no-color", 0, 0, OPT_NO_COLOR},
381 { "light-bg", 0, 0, OPT_LIGHT_BG},
382 { "no-stderr", 0, 0, OPT_NO_STDERR},
383 { "help", 0, 0, OPT_HELP},
384 { "version", 0, 0, OPT_VERSION},
385 { "clock-rate", 1, 0, OPT_CLOCK_RATE},
386 { "snd-clock-rate", 1, 0, OPT_SND_CLOCK_RATE},
387 { "stereo", 0, 0, OPT_STEREO},
388 { "null-audio", 0, 0, OPT_NULL_AUDIO},
389 { "local-port", 1, 0, OPT_LOCAL_PORT},
390 { "ip-addr", 1, 0, OPT_IP_ADDR},
391 { "bound-addr", 1, 0, OPT_BOUND_ADDR},
392 { "no-tcp", 0, 0, OPT_NO_TCP},
393 { "no-udp", 0, 0, OPT_NO_UDP},
394 { "norefersub", 0, 0, OPT_NOREFERSUB},
395 { "proxy", 1, 0, OPT_PROXY},
396 { "outbound", 1, 0, OPT_OUTBOUND_PROXY},
397 { "registrar", 1, 0, OPT_REGISTRAR},
398 { "reg-timeout",1, 0, OPT_REG_TIMEOUT},
399 { "publish", 0, 0, OPT_PUBLISH},
400 { "mwi", 0, 0, OPT_MWI},
401 { "use-100rel", 0, 0, OPT_100REL},
402 { "use-ims", 0, 0, OPT_USE_IMS},
403 { "id", 1, 0, OPT_ID},
404 { "contact", 1, 0, OPT_CONTACT},
405 { "contact-params",1,0, OPT_CONTACT_PARAMS},
406 { "contact-uri-params",1,0, OPT_CONTACT_URI_PARAMS},
407 { "auto-update-nat", 1, 0, OPT_AUTO_UPDATE_NAT},
408 { "disable-stun",0,0, OPT_DISABLE_STUN},
409 { "use-compact-form", 0, 0, OPT_USE_COMPACT_FORM},
410 { "accept-redirect", 1, 0, OPT_ACCEPT_REDIRECT},
411 { "no-force-lr",0, 0, OPT_NO_FORCE_LR},
412 { "realm", 1, 0, OPT_REALM},
413 { "username", 1, 0, OPT_USERNAME},
414 { "password", 1, 0, OPT_PASSWORD},
415 { "rereg-delay",1, 0, OPT_REG_RETRY_INTERVAL},
416 { "reg-use-proxy", 1, 0, OPT_REG_USE_PROXY},
417 { "nameserver", 1, 0, OPT_NAMESERVER},
418 { "stun-srv", 1, 0, OPT_STUN_SRV},
419 { "add-buddy", 1, 0, OPT_ADD_BUDDY},
420 { "offer-x-ms-msg",0,0,OPT_OFFER_X_MS_MSG},
421 { "no-presence", 0, 0, OPT_NO_PRESENCE},
422 { "auto-answer",1, 0, OPT_AUTO_ANSWER},
423 { "auto-play", 0, 0, OPT_AUTO_PLAY},
424 { "auto-play-hangup",0, 0, OPT_AUTO_PLAY_HANGUP},
425 { "auto-rec", 0, 0, OPT_AUTO_REC},
426 { "auto-loop", 0, 0, OPT_AUTO_LOOP},
427 { "auto-conf", 0, 0, OPT_AUTO_CONF},
428 { "play-file", 1, 0, OPT_PLAY_FILE},
429 { "play-tone", 1, 0, OPT_PLAY_TONE},
430 { "rec-file", 1, 0, OPT_REC_FILE},
431 { "rtp-port", 1, 0, OPT_RTP_PORT},
432
433 { "use-ice", 0, 0, OPT_USE_ICE},
434 { "ice-regular",0, 0, OPT_ICE_REGULAR},
435 { "use-turn", 0, 0, OPT_USE_TURN},
436 { "ice-max-hosts",1, 0, OPT_ICE_MAX_HOSTS},
437 { "ice-no-rtcp",0, 0, OPT_ICE_NO_RTCP},
438 { "turn-srv", 1, 0, OPT_TURN_SRV},
439 { "turn-tcp", 0, 0, OPT_TURN_TCP},
440 { "turn-user", 1, 0, OPT_TURN_USER},
441 { "turn-passwd",1, 0, OPT_TURN_PASSWD},
442
443#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
444 { "use-srtp", 1, 0, OPT_USE_SRTP},
445 { "srtp-secure",1, 0, OPT_SRTP_SECURE},
446#endif
447 { "add-codec", 1, 0, OPT_ADD_CODEC},
448 { "dis-codec", 1, 0, OPT_DIS_CODEC},
449 { "complexity", 1, 0, OPT_COMPLEXITY},
450 { "quality", 1, 0, OPT_QUALITY},
451 { "ptime", 1, 0, OPT_PTIME},
452 { "no-vad", 0, 0, OPT_NO_VAD},
453 { "ec-tail", 1, 0, OPT_EC_TAIL},
454 { "ec-opt", 1, 0, OPT_EC_OPT},
455 { "ilbc-mode", 1, 0, OPT_ILBC_MODE},
456 { "rx-drop-pct",1, 0, OPT_RX_DROP_PCT},
457 { "tx-drop-pct",1, 0, OPT_TX_DROP_PCT},
458 { "next-account",0,0, OPT_NEXT_ACCOUNT},
459 { "next-cred", 0, 0, OPT_NEXT_CRED},
460 { "max-calls", 1, 0, OPT_MAX_CALLS},
461 { "duration", 1, 0, OPT_DURATION},
462 { "thread-cnt", 1, 0, OPT_THREAD_CNT},
463#if defined(PJSIP_HAS_TLS_TRANSPORT) && (PJSIP_HAS_TLS_TRANSPORT != 0)
464 { "use-tls", 0, 0, OPT_USE_TLS},
465 { "tls-ca-file",1, 0, OPT_TLS_CA_FILE},
466 { "tls-cert-file",1,0, OPT_TLS_CERT_FILE},
467 { "tls-privkey-file",1,0, OPT_TLS_PRIV_FILE},
468 { "tls-password",1,0, OPT_TLS_PASSWORD},
469 { "tls-verify-server", 0, 0, OPT_TLS_VERIFY_SERVER},
470 { "tls-verify-client", 0, 0, OPT_TLS_VERIFY_CLIENT},
471 { "tls-neg-timeout", 1, 0, OPT_TLS_NEG_TIMEOUT},
472 { "tls-cipher", 1, 0, OPT_TLS_CIPHER},
473#endif
474 { "capture-dev", 1, 0, OPT_CAPTURE_DEV},
475 { "playback-dev", 1, 0, OPT_PLAYBACK_DEV},
476 { "capture-lat", 1, 0, OPT_CAPTURE_LAT},
477 { "playback-lat", 1, 0, OPT_PLAYBACK_LAT},
478 { "stdout-refresh", 1, 0, OPT_STDOUT_REFRESH},
479 { "stdout-refresh-text", 1, 0, OPT_STDOUT_REFRESH_TEXT},
480#ifdef _IONBF
481 { "stdout-no-buf", 0, 0, OPT_STDOUT_NO_BUF },
482#endif
483 { "snd-auto-close", 1, 0, OPT_SND_AUTO_CLOSE},
484 { "no-tones", 0, 0, OPT_NO_TONES},
485 { "jb-max-size", 1, 0, OPT_JB_MAX_SIZE},
486#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6
487 { "ipv6", 0, 0, OPT_IPV6},
488#endif
489 { "set-qos", 0, 0, OPT_QOS},
490 { "use-timer", 1, 0, OPT_TIMER},
491 { "timer-se", 1, 0, OPT_TIMER_SE},
492 { "timer-min-se", 1, 0, OPT_TIMER_MIN_SE},
493 { "outb-rid", 1, 0, OPT_OUTB_RID},
494 { "video", 0, 0, OPT_VIDEO},
495 { "extra-audio",0, 0, OPT_EXTRA_AUDIO},
496 { "vcapture-dev", 1, 0, OPT_VCAPTURE_DEV},
497 { "vrender-dev", 1, 0, OPT_VRENDER_DEV},
498 { "play-avi", 1, 0, OPT_PLAY_AVI},
499 { "auto-play-avi", 0, 0, OPT_AUTO_PLAY_AVI},
500 { "use-cli", 0, 0, OPT_USE_CLI},
501 { "cli-telnet-port", 1, 0, OPT_CLI_TELNET_PORT},
502 { "no-cli-console", 0, 0, OPT_DISABLE_CLI_CONSOLE},
503 { NULL, 0, 0, 0}
504 };
505 pj_status_t status;
506 pjsua_acc_config *cur_acc;
507 char *config_file = NULL;
508 unsigned i;
509
510 /* Run pj_getopt once to see if user specifies config file to read. */
511 pj_optind = 0;
512 while ((c=pj_getopt_long(argc, argv, "", long_options,
513 &option_index)) != -1)
514 {
515 switch (c) {
516 case OPT_CONFIG_FILE:
517 config_file = pj_optarg;
518 break;
519 }
520 if (config_file)
521 break;
522 }
523
524 if (config_file) {
525 status = read_config_file(cfg->pool, config_file, &argc, &argv);
526 if (status != 0)
527 return status;
528 }
529
530 cfg->acc_cnt = 0;
531 cur_acc = &cfg->acc_cfg[0];
532
533
534 /* Reinitialize and re-run pj_getopt again, possibly with new arguments
535 * read from config file.
536 */
537 pj_optind = 0;
538 while((c=pj_getopt_long(argc,argv, "", long_options,&option_index))!=-1) {
539 pj_str_t tmp;
540 long lval;
541
542 switch (c) {
543
544 case OPT_CONFIG_FILE:
545 /* Ignore as this has been processed before */
546 break;
547
548 case OPT_LOG_FILE:
549 cfg->log_cfg.log_filename = pj_str(pj_optarg);
550 break;
551
552 case OPT_LOG_LEVEL:
553 c = pj_strtoul(pj_cstr(&tmp, pj_optarg));
554 if (c < 0 || c > 6) {
555 PJ_LOG(1,(THIS_FILE,
556 "Error: expecting integer value 0-6 "
557 "for --log-level"));
558 return PJ_EINVAL;
559 }
560 cfg->log_cfg.level = c;
561 pj_log_set_level( c );
562 break;
563
564 case OPT_APP_LOG_LEVEL:
565 cfg->log_cfg.console_level = pj_strtoul(pj_cstr(&tmp, pj_optarg));
566 if (cfg->log_cfg.console_level < 0 || cfg->log_cfg.console_level > 6) {
567 PJ_LOG(1,(THIS_FILE,
568 "Error: expecting integer value 0-6 "
569 "for --app-log-level"));
570 return PJ_EINVAL;
571 }
572 break;
573
574 case OPT_LOG_APPEND:
575 cfg->log_cfg.log_file_flags |= PJ_O_APPEND;
576 break;
577
578 case OPT_COLOR:
579 cfg->log_cfg.decor |= PJ_LOG_HAS_COLOR;
580 break;
581
582 case OPT_NO_COLOR:
583 cfg->log_cfg.decor &= ~PJ_LOG_HAS_COLOR;
584 break;
585
586 case OPT_LIGHT_BG:
587 pj_log_set_color(1, PJ_TERM_COLOR_R);
588 pj_log_set_color(2, PJ_TERM_COLOR_R | PJ_TERM_COLOR_G);
589 pj_log_set_color(3, PJ_TERM_COLOR_B | PJ_TERM_COLOR_G);
590 pj_log_set_color(4, 0);
591 pj_log_set_color(5, 0);
592 pj_log_set_color(77, 0);
593 break;
594
595 case OPT_NO_STDERR:
596 freopen("/dev/null", "w", stderr);
597 break;
598
599 case OPT_HELP:
600 usage();
601 return PJ_EINVAL;
602
603 case OPT_VERSION: /* version */
604 pj_dump_config();
605 return PJ_EINVAL;
606
607 case OPT_NULL_AUDIO:
608 cfg->null_audio = PJ_TRUE;
609 break;
610
611 case OPT_CLOCK_RATE:
612 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg));
613 if (lval < 8000 || lval > 192000) {
614 PJ_LOG(1,(THIS_FILE, "Error: expecting value between "
615 "8000-192000 for conference clock rate"));
616 return PJ_EINVAL;
617 }
618 cfg->media_cfg.clock_rate = lval;
619 break;
620
621 case OPT_SND_CLOCK_RATE:
622 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg));
623 if (lval < 8000 || lval > 192000) {
624 PJ_LOG(1,(THIS_FILE, "Error: expecting value between "
625 "8000-192000 for sound device clock rate"));
626 return PJ_EINVAL;
627 }
628 cfg->media_cfg.snd_clock_rate = lval;
629 break;
630
631 case OPT_STEREO:
632 cfg->media_cfg.channel_count = 2;
633 break;
634
635 case OPT_LOCAL_PORT: /* local-port */
636 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg));
637 if (lval < 0 || lval > 65535) {
638 PJ_LOG(1,(THIS_FILE,
639 "Error: expecting integer value for "
640 "--local-port"));
641 return PJ_EINVAL;
642 }
643 cfg->udp_cfg.port = (pj_uint16_t)lval;
644 break;
645
646 case OPT_IP_ADDR: /* ip-addr */
647 cfg->udp_cfg.public_addr = pj_str(pj_optarg);
648 cfg->rtp_cfg.public_addr = pj_str(pj_optarg);
649 break;
650
651 case OPT_BOUND_ADDR: /* bound-addr */
652 cfg->udp_cfg.bound_addr = pj_str(pj_optarg);
653 cfg->rtp_cfg.bound_addr = pj_str(pj_optarg);
654 break;
655
656 case OPT_NO_UDP: /* no-udp */
657 if (cfg->no_tcp && !cfg->use_tls) {
658 PJ_LOG(1,(THIS_FILE,"Error: cannot disable both TCP and UDP"));
659 return PJ_EINVAL;
660 }
661
662 cfg->no_udp = PJ_TRUE;
663 break;
664
665 case OPT_NOREFERSUB: /* norefersub */
666 cfg->no_refersub = PJ_TRUE;
667 break;
668
669 case OPT_NO_TCP: /* no-tcp */
670 if (cfg->no_udp && !cfg->use_tls) {
671 PJ_LOG(1,(THIS_FILE,"Error: cannot disable both TCP and UDP"));
672 return PJ_EINVAL;
673 }
674
675 cfg->no_tcp = PJ_TRUE;
676 break;
677
678 case OPT_PROXY: /* proxy */
679 if (pjsua_verify_sip_url(pj_optarg) != 0) {
680 PJ_LOG(1,(THIS_FILE,
681 "Error: invalid SIP URL '%s' "
682 "in proxy argument", pj_optarg));
683 return PJ_EINVAL;
684 }
685 cur_acc->proxy[cur_acc->proxy_cnt++] = pj_str(pj_optarg);
686 break;
687
688 case OPT_OUTBOUND_PROXY: /* outbound proxy */
689 if (pjsua_verify_sip_url(pj_optarg) != 0) {
690 PJ_LOG(1,(THIS_FILE,
691 "Error: invalid SIP URL '%s' "
692 "in outbound proxy argument", pj_optarg));
693 return PJ_EINVAL;
694 }
695 cfg->cfg.outbound_proxy[cfg->cfg.outbound_proxy_cnt++] = pj_str(pj_optarg);
696 break;
697
698 case OPT_REGISTRAR: /* registrar */
699 if (pjsua_verify_sip_url(pj_optarg) != 0) {
700 PJ_LOG(1,(THIS_FILE,
701 "Error: invalid SIP URL '%s' in "
702 "registrar argument", pj_optarg));
703 return PJ_EINVAL;
704 }
705 cur_acc->reg_uri = pj_str(pj_optarg);
706 break;
707
708 case OPT_REG_TIMEOUT: /* reg-timeout */
709 cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,pj_optarg));
710 if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) {
711 PJ_LOG(1,(THIS_FILE,
712 "Error: invalid value for --reg-timeout "
713 "(expecting 1-3600)"));
714 return PJ_EINVAL;
715 }
716 break;
717
718 case OPT_PUBLISH: /* publish */
719 cur_acc->publish_enabled = PJ_TRUE;
720 break;
721
722 case OPT_MWI: /* mwi */
723 cur_acc->mwi_enabled = PJ_TRUE;
724 break;
725
726 case OPT_100REL: /** 100rel */
727 cur_acc->require_100rel = PJSUA_100REL_MANDATORY;
728 cfg->cfg.require_100rel = PJSUA_100REL_MANDATORY;
729 break;
730
731 case OPT_TIMER: /** session timer */
732 lval = pj_strtoul(pj_cstr(&tmp, pj_optarg));
733 if (lval < 0 || lval > 3) {
734 PJ_LOG(1,(THIS_FILE,
735 "Error: expecting integer value 0-3 for --use-timer"));
736 return PJ_EINVAL;
737 }
738 cur_acc->use_timer = lval;
739 cfg->cfg.use_timer = lval;
740 break;
741
742 case OPT_TIMER_SE: /** session timer session expiration */
743 cur_acc->timer_setting.sess_expires = pj_strtoul(pj_cstr(&tmp, pj_optarg));
744 if (cur_acc->timer_setting.sess_expires < 90) {
745 PJ_LOG(1,(THIS_FILE,
746 "Error: invalid value for --timer-se "
747 "(expecting higher than 90)"));
748 return PJ_EINVAL;
749 }
750 cfg->cfg.timer_setting.sess_expires = cur_acc->timer_setting.sess_expires;
751 break;
752
753 case OPT_TIMER_MIN_SE: /** session timer minimum session expiration */
754 cur_acc->timer_setting.min_se = pj_strtoul(pj_cstr(&tmp, pj_optarg));
755 if (cur_acc->timer_setting.min_se < 90) {
756 PJ_LOG(1,(THIS_FILE,
757 "Error: invalid value for --timer-min-se "
758 "(expecting higher than 90)"));
759 return PJ_EINVAL;
760 }
761 cfg->cfg.timer_setting.min_se = cur_acc->timer_setting.min_se;
762 break;
763
764 case OPT_OUTB_RID: /* Outbound reg-id */
765 cur_acc->rfc5626_reg_id = pj_str(pj_optarg);
766 break;
767
768 case OPT_USE_IMS: /* Activate IMS settings */
769 cur_acc->auth_pref.initial_auth = PJ_TRUE;
770 break;
771
772 case OPT_ID: /* id */
773 if (pjsua_verify_url(pj_optarg) != 0) {
774 PJ_LOG(1,(THIS_FILE,
775 "Error: invalid SIP URL '%s' "
776 "in local id argument", pj_optarg));
777 return PJ_EINVAL;
778 }
779 cur_acc->id = pj_str(pj_optarg);
780 break;
781
782 case OPT_CONTACT: /* contact */
783 if (pjsua_verify_sip_url(pj_optarg) != 0) {
784 PJ_LOG(1,(THIS_FILE,
785 "Error: invalid SIP URL '%s' "
786 "in contact argument", pj_optarg));
787 return PJ_EINVAL;
788 }
789 cur_acc->force_contact = pj_str(pj_optarg);
790 break;
791
792 case OPT_CONTACT_PARAMS:
793 cur_acc->contact_params = pj_str(pj_optarg);
794 break;
795
796 case OPT_CONTACT_URI_PARAMS:
797 cur_acc->contact_uri_params = pj_str(pj_optarg);
798 break;
799
800 case OPT_AUTO_UPDATE_NAT: /* OPT_AUTO_UPDATE_NAT */
801 cur_acc->allow_contact_rewrite = pj_strtoul(pj_cstr(&tmp, pj_optarg));
802 break;
803
804 case OPT_DISABLE_STUN:
805 cur_acc->sip_stun_use = PJSUA_STUN_USE_DISABLED;
806 cur_acc->media_stun_use = PJSUA_STUN_USE_DISABLED;
807 break;
808
809 case OPT_USE_COMPACT_FORM:
810 /* enable compact form - from Ticket #342 */
811 {
812 extern pj_bool_t pjsip_use_compact_form;
813 extern pj_bool_t pjsip_include_allow_hdr_in_dlg;
814 extern pj_bool_t pjmedia_add_rtpmap_for_static_pt;
815
816 pjsip_use_compact_form = PJ_TRUE;
817 /* do not transmit Allow header */
818 pjsip_include_allow_hdr_in_dlg = PJ_FALSE;
819 /* Do not include rtpmap for static payload types (<96) */
820 pjmedia_add_rtpmap_for_static_pt = PJ_FALSE;
821 }
822 break;
823
824 case OPT_ACCEPT_REDIRECT:
825 cfg->redir_op = my_atoi(pj_optarg);
826 if (cfg->redir_op<0 || cfg->redir_op>PJSIP_REDIRECT_STOP) {
827 PJ_LOG(1,(THIS_FILE,
828 "Error: accept-redirect value '%s' ", pj_optarg));
829 return PJ_EINVAL;
830 }
831 break;
832
833 case OPT_NO_FORCE_LR:
834 cfg->cfg.force_lr = PJ_FALSE;
835 break;
836
837 case OPT_NEXT_ACCOUNT: /* Add more account. */
838 cfg->acc_cnt++;
839 cur_acc = &cfg->acc_cfg[cfg->acc_cnt];
840 break;
841
842 case OPT_USERNAME: /* Default authentication user */
843 cur_acc->cred_info[cur_acc->cred_count].username = pj_str(pj_optarg);
844 cur_acc->cred_info[cur_acc->cred_count].scheme = pj_str("Digest");
845 break;
846
847 case OPT_REALM: /* Default authentication realm. */
848 cur_acc->cred_info[cur_acc->cred_count].realm = pj_str(pj_optarg);
849 break;
850
851 case OPT_PASSWORD: /* authentication password */
852 cur_acc->cred_info[cur_acc->cred_count].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
853 cur_acc->cred_info[cur_acc->cred_count].data = pj_str(pj_optarg);
854#if PJSIP_HAS_DIGEST_AKA_AUTH
855 cur_acc->cred_info[cur_acc->cred_count].data_type |= PJSIP_CRED_DATA_EXT_AKA;
856 cur_acc->cred_info[cur_acc->cred_count].ext.aka.k = pj_str(pj_optarg);
857 cur_acc->cred_info[cur_acc->cred_count].ext.aka.cb = &pjsip_auth_create_aka_response;
858#endif
859 break;
860
861 case OPT_REG_RETRY_INTERVAL:
862 cur_acc->reg_retry_interval = pj_strtoul(pj_cstr(&tmp, pj_optarg));
863 break;
864
865 case OPT_REG_USE_PROXY:
866 cur_acc->reg_use_proxy = (unsigned)pj_strtoul(pj_cstr(&tmp, pj_optarg));
867 if (cur_acc->reg_use_proxy > 3) {
868 PJ_LOG(1,(THIS_FILE, "Error: invalid --reg-use-proxy value '%s'",
869 pj_optarg));
870 return PJ_EINVAL;
871 }
872 break;
873
874 case OPT_NEXT_CRED: /* next credential */
875 cur_acc->cred_count++;
876 break;
877
878 case OPT_NAMESERVER: /* nameserver */
879 cfg->cfg.nameserver[cfg->cfg.nameserver_count++] = pj_str(pj_optarg);
880 if (cfg->cfg.nameserver_count > PJ_ARRAY_SIZE(cfg->cfg.nameserver)) {
881 PJ_LOG(1,(THIS_FILE, "Error: too many nameservers"));
882 return PJ_ETOOMANY;
883 }
884 break;
885
886 case OPT_STUN_SRV: /* STUN server */
887 cfg->cfg.stun_host = pj_str(pj_optarg);
888 if (cfg->cfg.stun_srv_cnt==PJ_ARRAY_SIZE(cfg->cfg.stun_srv)) {
889 PJ_LOG(1,(THIS_FILE, "Error: too many STUN servers"));
890 return PJ_ETOOMANY;
891 }
892 cfg->cfg.stun_srv[cfg->cfg.stun_srv_cnt++] = pj_str(pj_optarg);
893 break;
894
895 case OPT_ADD_BUDDY: /* Add to buddy list. */
896 if (pjsua_verify_url(pj_optarg) != 0) {
897 PJ_LOG(1,(THIS_FILE,
898 "Error: invalid URL '%s' in "
899 "--add-buddy option", pj_optarg));
900 return -1;
901 }
902 if (cfg->buddy_cnt == PJ_ARRAY_SIZE(cfg->buddy_cfg)) {
903 PJ_LOG(1,(THIS_FILE,
904 "Error: too many buddies in buddy list."));
905 return -1;
906 }
907 cfg->buddy_cfg[cfg->buddy_cnt].uri = pj_str(pj_optarg);
908 cfg->buddy_cnt++;
909 break;
910
911 case OPT_AUTO_PLAY:
912 cfg->auto_play = 1;
913 break;
914
915 case OPT_AUTO_PLAY_HANGUP:
916 cfg->auto_play_hangup = 1;
917 break;
918
919 case OPT_AUTO_REC:
920 cfg->auto_rec = 1;
921 break;
922
923 case OPT_AUTO_LOOP:
924 cfg->auto_loop = 1;
925 break;
926
927 case OPT_AUTO_CONF:
928 cfg->auto_conf = 1;
929 break;
930
931 case OPT_PLAY_FILE:
932 cfg->wav_files[cfg->wav_count++] = pj_str(pj_optarg);
933 break;
934
935 case OPT_PLAY_TONE:
936 {
937 int f1, f2, on, off;
938 int n;
939
940 n = sscanf(pj_optarg, "%d,%d,%d,%d", &f1, &f2, &on, &off);
941 if (n != 4) {
942 puts("Expecting f1,f2,on,off in --play-tone");
943 return -1;
944 }
945
946 cfg->tones[cfg->tone_count].freq1 = (short)f1;
947 cfg->tones[cfg->tone_count].freq2 = (short)f2;
948 cfg->tones[cfg->tone_count].on_msec = (short)on;
949 cfg->tones[cfg->tone_count].off_msec = (short)off;
950 ++cfg->tone_count;
951 }
952 break;
953
954 case OPT_REC_FILE:
955 cfg->rec_file = pj_str(pj_optarg);
956 break;
957
958 case OPT_USE_ICE:
959 cfg->media_cfg.enable_ice =
960 cur_acc->ice_cfg.enable_ice = PJ_TRUE;
961 break;
962
963 case OPT_ICE_REGULAR:
964 cfg->media_cfg.ice_opt.aggressive =
965 cur_acc->ice_cfg.ice_opt.aggressive = PJ_FALSE;
966 break;
967
968 case OPT_USE_TURN:
969 cfg->media_cfg.enable_turn =
970 cur_acc->turn_cfg.enable_turn = PJ_TRUE;
971 break;
972
973 case OPT_ICE_MAX_HOSTS:
974 cfg->media_cfg.ice_max_host_cands =
975 cur_acc->ice_cfg.ice_max_host_cands = my_atoi(pj_optarg);
976 break;
977
978 case OPT_ICE_NO_RTCP:
979 cfg->media_cfg.ice_no_rtcp =
980 cur_acc->ice_cfg.ice_no_rtcp = PJ_TRUE;
981 break;
982
983 case OPT_TURN_SRV:
984 cfg->media_cfg.turn_server =
985 cur_acc->turn_cfg.turn_server = pj_str(pj_optarg);
986 break;
987
988 case OPT_TURN_TCP:
989 cfg->media_cfg.turn_conn_type =
990 cur_acc->turn_cfg.turn_conn_type = PJ_TURN_TP_TCP;
991 break;
992
993 case OPT_TURN_USER:
994 cfg->media_cfg.turn_auth_cred.type =
995 cur_acc->turn_cfg.turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC;
996 cfg->media_cfg.turn_auth_cred.data.static_cred.realm =
997 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.realm = pj_str("*");
998 cfg->media_cfg.turn_auth_cred.data.static_cred.username =
999 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.username = pj_str(pj_optarg);
1000 break;
1001
1002 case OPT_TURN_PASSWD:
1003 cfg->media_cfg.turn_auth_cred.data.static_cred.data_type =
1004 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN;
1005 cfg->media_cfg.turn_auth_cred.data.static_cred.data =
1006 cur_acc->turn_cfg.turn_auth_cred.data.static_cred.data = pj_str(pj_optarg);
1007 break;
1008
1009#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
1010 case OPT_USE_SRTP:
1011 app_config.cfg.use_srtp = my_atoi(pj_optarg);
1012 if (!pj_isdigit(*pj_optarg) || app_config.cfg.use_srtp > 3) {
1013 PJ_LOG(1,(THIS_FILE, "Invalid value for --use-srtp option"));
1014 return -1;
1015 }
1016 if ((int)app_config.cfg.use_srtp == 3) {
1017 /* SRTP optional mode with duplicated media offer */
1018 app_config.cfg.use_srtp = PJMEDIA_SRTP_OPTIONAL;
1019 app_config.cfg.srtp_optional_dup_offer = PJ_TRUE;
1020 cur_acc->srtp_optional_dup_offer = PJ_TRUE;
1021 }
1022 cur_acc->use_srtp = app_config.cfg.use_srtp;
1023 break;
1024 case OPT_SRTP_SECURE:
1025 app_config.cfg.srtp_secure_signaling = my_atoi(pj_optarg);
1026 if (!pj_isdigit(*pj_optarg) ||
1027 app_config.cfg.srtp_secure_signaling > 2)
1028 {
1029 PJ_LOG(1,(THIS_FILE, "Invalid value for --srtp-secure option"));
1030 return -1;
1031 }
1032 cur_acc->srtp_secure_signaling = app_config.cfg.srtp_secure_signaling;
1033 break;
1034#endif
1035
1036 case OPT_RTP_PORT:
1037 cfg->rtp_cfg.port = my_atoi(pj_optarg);
1038 if (cfg->rtp_cfg.port == 0) {
1039 enum { START_PORT=4000 };
1040 unsigned range;
1041
1042 range = (65535-START_PORT-PJSUA_MAX_CALLS*2);
1043 cfg->rtp_cfg.port = START_PORT +
1044 ((pj_rand() % range) & 0xFFFE);
1045 }
1046
1047 if (cfg->rtp_cfg.port < 1 || cfg->rtp_cfg.port > 65535) {
1048 PJ_LOG(1,(THIS_FILE,
1049 "Error: rtp-port argument value "
1050 "(expecting 1-65535"));
1051 return -1;
1052 }
1053 break;
1054
1055 case OPT_DIS_CODEC:
1056 cfg->codec_dis[cfg->codec_dis_cnt++] = pj_str(pj_optarg);
1057 break;
1058
1059 case OPT_ADD_CODEC:
1060 cfg->codec_arg[cfg->codec_cnt++] = pj_str(pj_optarg);
1061 break;
1062
1063 /* These options were no longer valid after new pjsua */
1064 /*
1065 case OPT_COMPLEXITY:
1066 cfg->complexity = my_atoi(pj_optarg);
1067 if (cfg->complexity < 0 || cfg->complexity > 10) {
1068 PJ_LOG(1,(THIS_FILE,
1069 "Error: invalid --complexity (expecting 0-10"));
1070 return -1;
1071 }
1072 break;
1073 */
1074
1075 case OPT_DURATION:
1076 cfg->duration = my_atoi(pj_optarg);
1077 break;
1078
1079 case OPT_THREAD_CNT:
1080 cfg->cfg.thread_cnt = my_atoi(pj_optarg);
1081 if (cfg->cfg.thread_cnt > 128) {
1082 PJ_LOG(1,(THIS_FILE,
1083 "Error: invalid --thread-cnt option"));
1084 return -1;
1085 }
1086 break;
1087
1088 case OPT_PTIME:
1089 cfg->media_cfg.ptime = my_atoi(pj_optarg);
1090 if (cfg->media_cfg.ptime < 10 || cfg->media_cfg.ptime > 1000) {
1091 PJ_LOG(1,(THIS_FILE,
1092 "Error: invalid --ptime option"));
1093 return -1;
1094 }
1095 break;
1096
1097 case OPT_NO_VAD:
1098 cfg->media_cfg.no_vad = PJ_TRUE;
1099 break;
1100
1101 case OPT_EC_TAIL:
1102 cfg->media_cfg.ec_tail_len = my_atoi(pj_optarg);
1103 if (cfg->media_cfg.ec_tail_len > 1000) {
1104 PJ_LOG(1,(THIS_FILE, "I think the ec-tail length setting "
1105 "is too big"));
1106 return -1;
1107 }
1108 break;
1109
1110 case OPT_EC_OPT:
1111 cfg->media_cfg.ec_options = my_atoi(pj_optarg);
1112 break;
1113
1114 case OPT_QUALITY:
1115 cfg->media_cfg.quality = my_atoi(pj_optarg);
1116 if (cfg->media_cfg.quality < 0 || cfg->media_cfg.quality > 10) {
1117 PJ_LOG(1,(THIS_FILE,
1118 "Error: invalid --quality (expecting 0-10"));
1119 return -1;
1120 }
1121 break;
1122
1123 case OPT_ILBC_MODE:
1124 cfg->media_cfg.ilbc_mode = my_atoi(pj_optarg);
1125 if (cfg->media_cfg.ilbc_mode!=20 && cfg->media_cfg.ilbc_mode!=30) {
1126 PJ_LOG(1,(THIS_FILE,
1127 "Error: invalid --ilbc-mode (expecting 20 or 30"));
1128 return -1;
1129 }
1130 break;
1131
1132 case OPT_RX_DROP_PCT:
1133 cfg->media_cfg.rx_drop_pct = my_atoi(pj_optarg);
1134 if (cfg->media_cfg.rx_drop_pct > 100) {
1135 PJ_LOG(1,(THIS_FILE,
1136 "Error: invalid --rx-drop-pct (expecting <= 100"));
1137 return -1;
1138 }
1139 break;
1140
1141 case OPT_TX_DROP_PCT:
1142 cfg->media_cfg.tx_drop_pct = my_atoi(pj_optarg);
1143 if (cfg->media_cfg.tx_drop_pct > 100) {
1144 PJ_LOG(1,(THIS_FILE,
1145 "Error: invalid --tx-drop-pct (expecting <= 100"));
1146 return -1;
1147 }
1148 break;
1149
1150 case OPT_AUTO_ANSWER:
1151 cfg->auto_answer = my_atoi(pj_optarg);
1152 if (cfg->auto_answer < 100 || cfg->auto_answer > 699) {
1153 PJ_LOG(1,(THIS_FILE,
1154 "Error: invalid code in --auto-answer "
1155 "(expecting 100-699"));
1156 return -1;
1157 }
1158 break;
1159
1160 case OPT_MAX_CALLS:
1161 cfg->cfg.max_calls = my_atoi(pj_optarg);
1162 if (cfg->cfg.max_calls < 1 || cfg->cfg.max_calls > PJSUA_MAX_CALLS) {
1163 PJ_LOG(1,(THIS_FILE,"Error: maximum call setting exceeds "
1164 "compile time limit (PJSUA_MAX_CALLS=%d)",
1165 PJSUA_MAX_CALLS));
1166 return -1;
1167 }
1168 break;
1169
1170#if defined(PJSIP_HAS_TLS_TRANSPORT) && (PJSIP_HAS_TLS_TRANSPORT != 0)
1171 case OPT_USE_TLS:
1172 cfg->use_tls = PJ_TRUE;
1173 break;
1174
1175 case OPT_TLS_CA_FILE:
1176 cfg->udp_cfg.tls_setting.ca_list_file = pj_str(pj_optarg);
1177 break;
1178
1179 case OPT_TLS_CERT_FILE:
1180 cfg->udp_cfg.tls_setting.cert_file = pj_str(pj_optarg);
1181 break;
1182
1183 case OPT_TLS_PRIV_FILE:
1184 cfg->udp_cfg.tls_setting.privkey_file = pj_str(pj_optarg);
1185 break;
1186
1187 case OPT_TLS_PASSWORD:
1188 cfg->udp_cfg.tls_setting.password = pj_str(pj_optarg);
1189 break;
1190
1191 case OPT_TLS_VERIFY_SERVER:
1192 cfg->udp_cfg.tls_setting.verify_server = PJ_TRUE;
1193 break;
1194
1195 case OPT_TLS_VERIFY_CLIENT:
1196 cfg->udp_cfg.tls_setting.verify_client = PJ_TRUE;
1197 cfg->udp_cfg.tls_setting.require_client_cert = PJ_TRUE;
1198 break;
1199
1200 case OPT_TLS_NEG_TIMEOUT:
1201 cfg->udp_cfg.tls_setting.timeout.sec = atoi(pj_optarg);
1202 break;
1203
1204 case OPT_TLS_CIPHER:
1205 {
1206 pj_ssl_cipher cipher;
1207
1208 if (pj_ansi_strnicmp(pj_optarg, "0x", 2) == 0) {
1209 pj_str_t cipher_st = pj_str(pj_optarg + 2);
1210 cipher = pj_strtoul2(&cipher_st, NULL, 16);
1211 } else {
1212 cipher = atoi(pj_optarg);
1213 }
1214
1215 if (pj_ssl_cipher_is_supported(cipher)) {
1216 static pj_ssl_cipher tls_ciphers[128];
1217
1218 tls_ciphers[cfg->udp_cfg.tls_setting.ciphers_num++] = cipher;
1219 cfg->udp_cfg.tls_setting.ciphers = tls_ciphers;
1220 } else {
1221 pj_ssl_cipher ciphers[128];
1222 unsigned j, ciphers_cnt;
1223
1224 ciphers_cnt = PJ_ARRAY_SIZE(ciphers);
1225 pj_ssl_cipher_get_availables(ciphers, &ciphers_cnt);
1226
1227 PJ_LOG(1,(THIS_FILE, "Cipher \"%s\" is not supported by "
1228 "TLS/SSL backend.", pj_optarg));
1229 printf("Available TLS/SSL ciphers (%d):\n", ciphers_cnt);
1230 for (j=0; j<ciphers_cnt; ++j)
1231 printf("- 0x%06X: %s\n", ciphers[j], pj_ssl_cipher_name(ciphers[j]));
1232 return -1;
1233 }
1234 }
1235 break;
1236#endif /* PJSIP_HAS_TLS_TRANSPORT */
1237
1238 case OPT_CAPTURE_DEV:
1239 cfg->capture_dev = atoi(pj_optarg);
1240 break;
1241
1242 case OPT_PLAYBACK_DEV:
1243 cfg->playback_dev = atoi(pj_optarg);
1244 break;
1245
1246 case OPT_STDOUT_REFRESH:
1247 stdout_refresh = atoi(pj_optarg);
1248 break;
1249
1250 case OPT_STDOUT_REFRESH_TEXT:
1251 stdout_refresh_text = pj_optarg;
1252 break;
1253
1254#ifdef _IONBF
1255 case OPT_STDOUT_NO_BUF:
1256 setvbuf(stdout, NULL, _IONBF, 0);
1257 break;
1258#endif
1259
1260 case OPT_CAPTURE_LAT:
1261 cfg->capture_lat = atoi(pj_optarg);
1262 break;
1263
1264 case OPT_PLAYBACK_LAT:
1265 cfg->playback_lat = atoi(pj_optarg);
1266 break;
1267
1268 case OPT_SND_AUTO_CLOSE:
1269 cfg->media_cfg.snd_auto_close_time = atoi(pj_optarg);
1270 break;
1271
1272 case OPT_NO_TONES:
1273 cfg->no_tones = PJ_TRUE;
1274 break;
1275
1276 case OPT_JB_MAX_SIZE:
1277 cfg->media_cfg.jb_max = atoi(pj_optarg);
1278 break;
1279
1280#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6
1281 case OPT_IPV6:
1282 cfg->ipv6 = PJ_TRUE;
1283 break;
1284#endif
1285 case OPT_QOS:
1286 cfg->enable_qos = PJ_TRUE;
1287 /* Set RTP traffic type to Voice */
1288 cfg->rtp_cfg.qos_type = PJ_QOS_TYPE_VOICE;
1289 /* Directly apply DSCP value to SIP traffic. Say lets
1290 * set it to CS3 (DSCP 011000). Note that this will not
1291 * work on all platforms.
1292 */
1293 cfg->udp_cfg.qos_params.flags = PJ_QOS_PARAM_HAS_DSCP;
1294 cfg->udp_cfg.qos_params.dscp_val = 0x18;
1295 break;
1296 case OPT_VIDEO:
1297 cfg->vid.vid_cnt = 1;
1298 cfg->vid.in_auto_show = PJ_TRUE;
1299 cfg->vid.out_auto_transmit = PJ_TRUE;
1300 break;
1301 case OPT_EXTRA_AUDIO:
1302 cfg->aud_cnt++;
1303 break;
1304
1305 case OPT_VCAPTURE_DEV:
1306 cfg->vid.vcapture_dev = atoi(pj_optarg);
1307 cur_acc->vid_cap_dev = cfg->vid.vcapture_dev;
1308 break;
1309
1310 case OPT_VRENDER_DEV:
1311 cfg->vid.vrender_dev = atoi(pj_optarg);
1312 cur_acc->vid_rend_dev = cfg->vid.vrender_dev;
1313 break;
1314
1315 case OPT_PLAY_AVI:
1316 if (app_config.avi_cnt >= MAX_AVI) {
1317 PJ_LOG(1,(THIS_FILE, "Too many AVIs"));
1318 return -1;
1319 }
1320 app_config.avi[app_config.avi_cnt++].path = pj_str(pj_optarg);
1321 break;
1322
1323 case OPT_AUTO_PLAY_AVI:
1324 app_config.avi_auto_play = PJ_TRUE;
1325 break;
1326
1327 case OPT_USE_CLI:
1328 cfg->use_cli = PJ_TRUE;
1329 break;
1330
1331 case OPT_CLI_TELNET_PORT:
1332 cfg->cli_telnet_port = atoi(pj_optarg);
1333 break;
1334
1335 case OPT_DISABLE_CLI_CONSOLE:
1336 cfg->disable_cli_console = PJ_TRUE;
1337 break;
1338
1339 default:
1340 PJ_LOG(1,(THIS_FILE,
1341 "Argument \"%s\" is not valid. Use --help to see help",
1342 argv[pj_optind-1]));
1343 return -1;
1344 }
1345 }
1346
1347 if (pj_optind != argc) {
1348 pj_str_t uri_arg;
1349
1350 if (pjsua_verify_url(argv[pj_optind]) != PJ_SUCCESS) {
1351 PJ_LOG(1,(THIS_FILE, "Invalid SIP URI %s", argv[pj_optind]));
1352 return -1;
1353 }
1354 uri_arg = pj_str(argv[pj_optind]);
1355 if (uri_to_call)
1356 *uri_to_call = uri_arg;
1357 pj_optind++;
1358
1359 /* Add URI to call to buddy list if it's not already there */
1360 for (i=0; i<cfg->buddy_cnt; ++i) {
1361 if (pj_stricmp(&cfg->buddy_cfg[i].uri, &uri_arg)==0)
1362 break;
1363 }
1364 if (i == cfg->buddy_cnt && cfg->buddy_cnt < PJSUA_MAX_BUDDIES) {
1365 cfg->buddy_cfg[cfg->buddy_cnt++].uri = uri_arg;
1366 }
1367
1368 } else {
1369 if (uri_to_call)
1370 uri_to_call->slen = 0;
1371 }
1372
1373 if (pj_optind != argc) {
1374 PJ_LOG(1,(THIS_FILE, "Error: unknown options %s", argv[pj_optind]));
1375 return PJ_EINVAL;
1376 }
1377
1378 if (cfg->acc_cfg[cfg->acc_cnt].id.slen)
1379 cfg->acc_cnt++;
1380
1381 for (i=0; i<cfg->acc_cnt; ++i) {
1382 pjsua_acc_config *acfg = &cfg->acc_cfg[i];
1383
1384 if (acfg->cred_info[acfg->cred_count].username.slen)
1385 {
1386 acfg->cred_count++;
1387 }
1388
1389 if (acfg->ice_cfg.enable_ice) {
1390 acfg->ice_cfg_use = PJSUA_ICE_CONFIG_USE_CUSTOM;
1391 }
1392 if (acfg->turn_cfg.enable_turn) {
1393 acfg->turn_cfg_use = PJSUA_TURN_CONFIG_USE_CUSTOM;
1394 }
1395
1396 /* When IMS mode is enabled for the account, verify that settings
1397 * are okay.
1398 */
1399 /* For now we check if IMS mode is activated by looking if
1400 * initial_auth is set.
1401 */
1402 if (acfg->auth_pref.initial_auth && acfg->cred_count) {
1403 /* Realm must point to the real domain */
1404 if (*acfg->cred_info[0].realm.ptr=='*') {
1405 PJ_LOG(1,(THIS_FILE,
1406 "Error: cannot use '*' as realm with IMS"));
1407 return PJ_EINVAL;
1408 }
1409
1410 /* Username for authentication must be in a@b format */
1411 if (strchr(acfg->cred_info[0].username.ptr, '@')==0) {
1412 PJ_LOG(1,(THIS_FILE,
1413 "Error: Username for authentication must "
1414 "be in user@domain format with IMS"));
1415 return PJ_EINVAL;
1416 }
1417 }
1418 }
1419 return PJ_SUCCESS;
1420}
1421
1422/* Set default config. */
1423static void default_config(pjsua_app_config *cfg)
1424{
1425 char tmp[80];
1426 unsigned i;
1427
1428 pjsua_config_default(&cfg->cfg);
1429 pj_ansi_sprintf(tmp, "PJSUA v%s %s", pj_get_version(),
1430 pj_get_sys_info()->info.ptr);
1431 pj_strdup2_with_null(app_config.pool, &cfg->cfg.user_agent, tmp);
1432
1433 pjsua_logging_config_default(&cfg->log_cfg);
1434 pjsua_media_config_default(&cfg->media_cfg);
1435 pjsua_transport_config_default(&cfg->udp_cfg);
1436 cfg->udp_cfg.port = 5060;
1437 pjsua_transport_config_default(&cfg->rtp_cfg);
1438 cfg->rtp_cfg.port = 4000;
1439 cfg->redir_op = PJSIP_REDIRECT_ACCEPT_REPLACE;
1440 cfg->duration = NO_LIMIT_DURATION;
1441 cfg->wav_id = PJSUA_INVALID_ID;
1442 cfg->rec_id = PJSUA_INVALID_ID;
1443 cfg->wav_port = PJSUA_INVALID_ID;
1444 cfg->rec_port = PJSUA_INVALID_ID;
1445 cfg->mic_level = cfg->speaker_level = 1.0;
1446 cfg->capture_dev = PJSUA_INVALID_ID;
1447 cfg->playback_dev = PJSUA_INVALID_ID;
1448 cfg->capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY;
1449 cfg->playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
1450 cfg->ringback_slot = PJSUA_INVALID_ID;
1451 cfg->ring_slot = PJSUA_INVALID_ID;
1452
1453 for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i)
1454 pjsua_acc_config_default(&cfg->acc_cfg[i]);
1455
1456 for (i=0; i<PJ_ARRAY_SIZE(cfg->buddy_cfg); ++i)
1457 pjsua_buddy_config_default(&cfg->buddy_cfg[i]);
1458
1459 cfg->vid.vcapture_dev = PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
1460 cfg->vid.vrender_dev = PJMEDIA_VID_DEFAULT_RENDER_DEV;
1461 cfg->aud_cnt = 1;
1462
1463 cfg->avi_def_idx = PJSUA_INVALID_ID;
1464
1465 cfg->use_cli = PJ_FALSE;
1466 cfg->disable_cli_console = PJ_FALSE;
1467 cfg->cli_telnet_port = -1;
1468}
1469
1470static pj_status_t parse_config(int argc, char *argv[],
1471 pjsua_app_config *app_config, pj_str_t *uri_arg)
1472{
1473 pj_status_t status;
1474
1475 /* Initialize default config */
1476 default_config(app_config);
1477
1478 /* Parse the arguments */
1479 status = parse_args(argc, argv, app_config, uri_arg);
1480 return status;
1481}
1482
1483PJ_DEF(void) add_startup_config(int argc, char *argv[])
1484{
1485 int i;
1486 cmd_argc = argc;
1487
1488 for (i=0;i<argc;++i)
1489 {
1490 pj_memcpy(&cmd_argv[i], argv[i], strlen(argv[i]));
1491 cmd_argv[i][strlen(argv[i])] = 0;
1492 }
1493}
1494
1495PJ_DEF(void) add_reload_config(unsigned idx, pj_str_t *option)
1496{
1497 /** First command always contain the app path**/
1498 pj_str_t cmd;
1499
1500 pj_assert(idx < MAX_APP_OPTIONS);
1501
1502 cmd = pj_str(&cmd_argv[idx][0]);
1503 pj_strncpy_with_null(&cmd, option, 128);
1504 cmd_argc = idx+1;
1505}
1506
1507PJ_DEF(pj_status_t) load_config(pjsua_app_config *app_config,
1508 pj_str_t *uri_arg,
1509 pj_bool_t app_running)
1510{
1511 int i;
1512 int argc = cmd_argc;
1513 char *argv[128];
1514 pj_status_t status;
1515 pj_bool_t use_cli = PJ_FALSE;
1516 pj_bool_t disable_cli_console = PJ_TRUE;
1517 int cli_telnet_port = 0;
1518
1519 /** CLI options are not changable **/
1520 if (app_running) {
1521 use_cli = app_config->use_cli;
1522 disable_cli_console = app_config->disable_cli_console;
1523 cli_telnet_port = app_config->cli_telnet_port;
1524 }
1525
1526 for (i=0;i<cmd_argc;++i)
1527 {
1528 argv[i] = &cmd_argv[i][0];
1529 }
1530
1531 status = parse_config(argc, argv, app_config, uri_arg);
1532 if (status != PJ_SUCCESS)
1533 return status;
1534
1535 if (app_running) {
1536 app_config->use_cli = use_cli;
1537 app_config->disable_cli_console = disable_cli_console;
1538 app_config->cli_telnet_port = cli_telnet_port;
1539 }
1540
1541 return status;
1542}
1543
1544/*
1545 * Save account settings
1546 */
1547static void write_account_settings(int acc_index, pj_str_t *result)
1548{
1549 unsigned i;
1550 char line[128];
1551 pjsua_acc_config *acc_cfg = &app_config.acc_cfg[acc_index];
1552
1553
1554 pj_ansi_sprintf(line, "\n#\n# Account %d:\n#\n", acc_index);
1555 pj_strcat2(result, line);
1556
1557
1558 /* Identity */
1559 if (acc_cfg->id.slen) {
1560 pj_ansi_sprintf(line, "--id %.*s\n",
1561 (int)acc_cfg->id.slen,
1562 acc_cfg->id.ptr);
1563 pj_strcat2(result, line);
1564 }
1565
1566 /* Registrar server */
1567 if (acc_cfg->reg_uri.slen) {
1568 pj_ansi_sprintf(line, "--registrar %.*s\n",
1569 (int)acc_cfg->reg_uri.slen,
1570 acc_cfg->reg_uri.ptr);
1571 pj_strcat2(result, line);
1572
1573 pj_ansi_sprintf(line, "--reg-timeout %u\n",
1574 acc_cfg->reg_timeout);
1575 pj_strcat2(result, line);
1576 }
1577
1578 /* Contact */
1579 if (acc_cfg->force_contact.slen) {
1580 pj_ansi_sprintf(line, "--contact %.*s\n",
1581 (int)acc_cfg->force_contact.slen,
1582 acc_cfg->force_contact.ptr);
1583 pj_strcat2(result, line);
1584 }
1585
1586 /* Contact header parameters */
1587 if (acc_cfg->contact_params.slen) {
1588 pj_ansi_sprintf(line, "--contact-params %.*s\n",
1589 (int)acc_cfg->contact_params.slen,
1590 acc_cfg->contact_params.ptr);
1591 pj_strcat2(result, line);
1592 }
1593
1594 /* Contact URI parameters */
1595 if (acc_cfg->contact_uri_params.slen) {
1596 pj_ansi_sprintf(line, "--contact-uri-params %.*s\n",
1597 (int)acc_cfg->contact_uri_params.slen,
1598 acc_cfg->contact_uri_params.ptr);
1599 pj_strcat2(result, line);
1600 }
1601
1602 /* */
1603 if (acc_cfg->allow_contact_rewrite!=1)
1604 {
1605 pj_ansi_sprintf(line, "--auto-update-nat %i\n",
1606 (int)acc_cfg->allow_contact_rewrite);
1607 pj_strcat2(result, line);
1608 }
1609
1610#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
1611 /* SRTP */
1612 if (acc_cfg->use_srtp) {
1613 int use_srtp = (int)acc_cfg->use_srtp;
1614 if (use_srtp == PJMEDIA_SRTP_OPTIONAL &&
1615 acc_cfg->srtp_optional_dup_offer)
1616 {
1617 use_srtp = 3;
1618 }
1619 pj_ansi_sprintf(line, "--use-srtp %i\n", use_srtp);
1620 pj_strcat2(result, line);
1621 }
1622 if (acc_cfg->srtp_secure_signaling !=
1623 PJSUA_DEFAULT_SRTP_SECURE_SIGNALING)
1624 {
1625 pj_ansi_sprintf(line, "--srtp-secure %d\n",
1626 acc_cfg->srtp_secure_signaling);
1627 pj_strcat2(result, line);
1628 }
1629#endif
1630
1631 /* Proxy */
1632 for (i=0; i<acc_cfg->proxy_cnt; ++i) {
1633 pj_ansi_sprintf(line, "--proxy %.*s\n",
1634 (int)acc_cfg->proxy[i].slen,
1635 acc_cfg->proxy[i].ptr);
1636 pj_strcat2(result, line);
1637 }
1638
1639 /* Credentials */
1640 for (i=0; i<acc_cfg->cred_count; ++i) {
1641 if (acc_cfg->cred_info[i].realm.slen) {
1642 pj_ansi_sprintf(line, "--realm %.*s\n",
1643 (int)acc_cfg->cred_info[i].realm.slen,
1644 acc_cfg->cred_info[i].realm.ptr);
1645 pj_strcat2(result, line);
1646 }
1647
1648 if (acc_cfg->cred_info[i].username.slen) {
1649 pj_ansi_sprintf(line, "--username %.*s\n",
1650 (int)acc_cfg->cred_info[i].username.slen,
1651 acc_cfg->cred_info[i].username.ptr);
1652 pj_strcat2(result, line);
1653 }
1654
1655 if (acc_cfg->cred_info[i].data.slen) {
1656 pj_ansi_sprintf(line, "--password %.*s\n",
1657 (int)acc_cfg->cred_info[i].data.slen,
1658 acc_cfg->cred_info[i].data.ptr);
1659 pj_strcat2(result, line);
1660 }
1661
1662 if (i != acc_cfg->cred_count - 1)
1663 pj_strcat2(result, "--next-cred\n");
1664 }
1665
1666 /* reg-use-proxy */
1667 if (acc_cfg->reg_use_proxy != 3) {
1668 pj_ansi_sprintf(line, "--reg-use-proxy %d\n",
1669 acc_cfg->reg_use_proxy);
1670 pj_strcat2(result, line);
1671 }
1672
1673 /* rereg-delay */
1674 if (acc_cfg->reg_retry_interval != PJSUA_REG_RETRY_INTERVAL) {
1675 pj_ansi_sprintf(line, "--rereg-delay %d\n",
1676 acc_cfg->reg_retry_interval);
1677 pj_strcat2(result, line);
1678 }
1679
1680 /* 100rel extension */
1681 if (acc_cfg->require_100rel) {
1682 pj_strcat2(result, "--use-100rel\n");
1683 }
1684
1685 /* Session Timer extension */
1686 if (acc_cfg->use_timer) {
1687 pj_ansi_sprintf(line, "--use-timer %d\n",
1688 acc_cfg->use_timer);
1689 pj_strcat2(result, line);
1690 }
1691 if (acc_cfg->timer_setting.min_se != 90) {
1692 pj_ansi_sprintf(line, "--timer-min-se %d\n",
1693 acc_cfg->timer_setting.min_se);
1694 pj_strcat2(result, line);
1695 }
1696 if (acc_cfg->timer_setting.sess_expires != PJSIP_SESS_TIMER_DEF_SE) {
1697 pj_ansi_sprintf(line, "--timer-se %d\n",
1698 acc_cfg->timer_setting.sess_expires);
1699 pj_strcat2(result, line);
1700 }
1701
1702 /* Publish */
1703 if (acc_cfg->publish_enabled)
1704 pj_strcat2(result, "--publish\n");
1705
1706 /* MWI */
1707 if (acc_cfg->mwi_enabled)
1708 pj_strcat2(result, "--mwi\n");
1709
1710 if (acc_cfg->sip_stun_use != PJSUA_STUN_USE_DEFAULT ||
1711 acc_cfg->media_stun_use != PJSUA_STUN_USE_DEFAULT)
1712 {
1713 pj_strcat2(result, "--disable-stun\n");
1714 }
1715
1716 /* Media Transport*/
1717 if (acc_cfg->ice_cfg.enable_ice)
1718 pj_strcat2(result, "--use-ice\n");
1719
1720 if (acc_cfg->ice_cfg.ice_opt.aggressive == PJ_FALSE)
1721 pj_strcat2(result, "--ice-regular\n");
1722
1723 if (acc_cfg->turn_cfg.enable_turn)
1724 pj_strcat2(result, "--use-turn\n");
1725
1726 if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) {
1727 pj_ansi_sprintf(line, "--ice_max_host_cands %d\n",
1728 acc_cfg->ice_cfg.ice_max_host_cands);
1729 pj_strcat2(result, line);
1730 }
1731
1732 if (acc_cfg->ice_cfg.ice_no_rtcp)
1733 pj_strcat2(result, "--ice-no-rtcp\n");
1734
1735 if (acc_cfg->turn_cfg.turn_server.slen) {
1736 pj_ansi_sprintf(line, "--turn-srv %.*s\n",
1737 (int)acc_cfg->turn_cfg.turn_server.slen,
1738 acc_cfg->turn_cfg.turn_server.ptr);
1739 pj_strcat2(result, line);
1740 }
1741
1742 if (acc_cfg->turn_cfg.turn_conn_type == PJ_TURN_TP_TCP)
1743 pj_strcat2(result, "--turn-tcp\n");
1744
1745 if (acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.slen) {
1746 pj_ansi_sprintf(line, "--turn-user %.*s\n",
1747 (int)acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.slen,
1748 acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.username.ptr);
1749 pj_strcat2(result, line);
1750 }
1751
1752 if (acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.slen) {
1753 pj_ansi_sprintf(line, "--turn-passwd %.*s\n",
1754 (int)acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.slen,
1755 acc_cfg->turn_cfg.turn_auth_cred.data.static_cred.data.ptr);
1756 pj_strcat2(result, line);
1757 }
1758}
1759
1760/*
1761 * Write settings.
1762 */
1763PJ_DEF(int) write_settings(pjsua_app_config *config, char *buf, pj_size_t max)
1764{
1765 unsigned acc_index;
1766 unsigned i;
1767 pj_str_t cfg;
1768 char line[128];
1769 extern pj_bool_t pjsip_use_compact_form;
1770
1771 PJ_UNUSED_ARG(max);
1772
1773 cfg.ptr = buf;
1774 cfg.slen = 0;
1775
1776 /* Logging. */
1777 pj_strcat2(&cfg, "#\n# Logging options:\n#\n");
1778 pj_ansi_sprintf(line, "--log-level %d\n",
1779 config->log_cfg.level);
1780 pj_strcat2(&cfg, line);
1781
1782 pj_ansi_sprintf(line, "--app-log-level %d\n",
1783 config->log_cfg.console_level);
1784 pj_strcat2(&cfg, line);
1785
1786 if (config->log_cfg.log_filename.slen) {
1787 pj_ansi_sprintf(line, "--log-file %.*s\n",
1788 (int)config->log_cfg.log_filename.slen,
1789 config->log_cfg.log_filename.ptr);
1790 pj_strcat2(&cfg, line);
1791 }
1792
1793 if (config->log_cfg.log_file_flags & PJ_O_APPEND) {
1794 pj_strcat2(&cfg, "--log-append\n");
1795 }
1796
1797 /* Save account settings. */
1798 for (acc_index=0; acc_index < config->acc_cnt; ++acc_index) {
1799
1800 write_account_settings(acc_index, &cfg);
1801
1802 if (acc_index < config->acc_cnt-1)
1803 pj_strcat2(&cfg, "--next-account\n");
1804 }
1805
1806 pj_strcat2(&cfg, "\n#\n# Network settings:\n#\n");
1807
1808 /* Nameservers */
1809 for (i=0; i<config->cfg.nameserver_count; ++i) {
1810 pj_ansi_sprintf(line, "--nameserver %.*s\n",
1811 (int)config->cfg.nameserver[i].slen,
1812 config->cfg.nameserver[i].ptr);
1813 pj_strcat2(&cfg, line);
1814 }
1815
1816 /* Outbound proxy */
1817 for (i=0; i<config->cfg.outbound_proxy_cnt; ++i) {
1818 pj_ansi_sprintf(line, "--outbound %.*s\n",
1819 (int)config->cfg.outbound_proxy[i].slen,
1820 config->cfg.outbound_proxy[i].ptr);
1821 pj_strcat2(&cfg, line);
1822 }
1823
1824 /* Transport options */
1825 if (config->ipv6) {
1826 pj_strcat2(&cfg, "--ipv6\n");
1827 }
1828 if (config->enable_qos) {
1829 pj_strcat2(&cfg, "--set-qos\n");
1830 }
1831
1832 /* UDP Transport. */
1833 pj_ansi_sprintf(line, "--local-port %d\n", config->udp_cfg.port);
1834 pj_strcat2(&cfg, line);
1835
1836 /* IP address, if any. */
1837 if (config->udp_cfg.public_addr.slen) {
1838 pj_ansi_sprintf(line, "--ip-addr %.*s\n",
1839 (int)config->udp_cfg.public_addr.slen,
1840 config->udp_cfg.public_addr.ptr);
1841 pj_strcat2(&cfg, line);
1842 }
1843
1844 /* Bound IP address, if any. */
1845 if (config->udp_cfg.bound_addr.slen) {
1846 pj_ansi_sprintf(line, "--bound-addr %.*s\n",
1847 (int)config->udp_cfg.bound_addr.slen,
1848 config->udp_cfg.bound_addr.ptr);
1849 pj_strcat2(&cfg, line);
1850 }
1851
1852 /* No TCP ? */
1853 if (config->no_tcp) {
1854 pj_strcat2(&cfg, "--no-tcp\n");
1855 }
1856
1857 /* No UDP ? */
1858 if (config->no_udp) {
1859 pj_strcat2(&cfg, "--no-udp\n");
1860 }
1861
1862 /* STUN */
1863 for (i=0; i<config->cfg.stun_srv_cnt; ++i) {
1864 pj_ansi_sprintf(line, "--stun-srv %.*s\n",
1865 (int)config->cfg.stun_srv[i].slen,
1866 config->cfg.stun_srv[i].ptr);
1867 pj_strcat2(&cfg, line);
1868 }
1869
1870#if defined(PJSIP_HAS_TLS_TRANSPORT) && (PJSIP_HAS_TLS_TRANSPORT != 0)
1871 /* TLS */
1872 if (config->use_tls)
1873 pj_strcat2(&cfg, "--use-tls\n");
1874 if (config->udp_cfg.tls_setting.ca_list_file.slen) {
1875 pj_ansi_sprintf(line, "--tls-ca-file %.*s\n",
1876 (int)config->udp_cfg.tls_setting.ca_list_file.slen,
1877 config->udp_cfg.tls_setting.ca_list_file.ptr);
1878 pj_strcat2(&cfg, line);
1879 }
1880 if (config->udp_cfg.tls_setting.cert_file.slen) {
1881 pj_ansi_sprintf(line, "--tls-cert-file %.*s\n",
1882 (int)config->udp_cfg.tls_setting.cert_file.slen,
1883 config->udp_cfg.tls_setting.cert_file.ptr);
1884 pj_strcat2(&cfg, line);
1885 }
1886 if (config->udp_cfg.tls_setting.privkey_file.slen) {
1887 pj_ansi_sprintf(line, "--tls-privkey-file %.*s\n",
1888 (int)config->udp_cfg.tls_setting.privkey_file.slen,
1889 config->udp_cfg.tls_setting.privkey_file.ptr);
1890 pj_strcat2(&cfg, line);
1891 }
1892
1893 if (config->udp_cfg.tls_setting.password.slen) {
1894 pj_ansi_sprintf(line, "--tls-password %.*s\n",
1895 (int)config->udp_cfg.tls_setting.password.slen,
1896 config->udp_cfg.tls_setting.password.ptr);
1897 pj_strcat2(&cfg, line);
1898 }
1899
1900 if (config->udp_cfg.tls_setting.verify_server)
1901 pj_strcat2(&cfg, "--tls-verify-server\n");
1902
1903 if (config->udp_cfg.tls_setting.verify_client)
1904 pj_strcat2(&cfg, "--tls-verify-client\n");
1905
1906 if (config->udp_cfg.tls_setting.timeout.sec) {
1907 pj_ansi_sprintf(line, "--tls-neg-timeout %d\n",
1908 (int)config->udp_cfg.tls_setting.timeout.sec);
1909 pj_strcat2(&cfg, line);
1910 }
1911
1912 for (i=0; i<config->udp_cfg.tls_setting.ciphers_num; ++i) {
1913 pj_ansi_sprintf(line, "--tls-cipher 0x%06X # %s\n",
1914 config->udp_cfg.tls_setting.ciphers[i],
1915 pj_ssl_cipher_name(config->udp_cfg.tls_setting.ciphers[i]));
1916 pj_strcat2(&cfg, line);
1917 }
1918#endif
1919
1920 pj_strcat2(&cfg, "\n#\n# Media settings:\n#\n");
1921
1922 /* Video & extra audio */
1923 for (i=0; i<config->vid.vid_cnt; ++i) {
1924 pj_strcat2(&cfg, "--video\n");
1925 }
1926 for (i=1; i<config->aud_cnt; ++i) {
1927 pj_strcat2(&cfg, "--extra-audio\n");
1928 }
1929
1930 /* SRTP */
1931#if PJMEDIA_HAS_SRTP
1932 if (app_config.cfg.use_srtp != PJSUA_DEFAULT_USE_SRTP) {
1933 int use_srtp = (int)app_config.cfg.use_srtp;
1934 if (use_srtp == PJMEDIA_SRTP_OPTIONAL &&
1935 app_config.cfg.srtp_optional_dup_offer)
1936 {
1937 use_srtp = 3;
1938 }
1939 pj_ansi_sprintf(line, "--use-srtp %d\n", use_srtp);
1940 pj_strcat2(&cfg, line);
1941 }
1942 if (app_config.cfg.srtp_secure_signaling !=
1943 PJSUA_DEFAULT_SRTP_SECURE_SIGNALING)
1944 {
1945 pj_ansi_sprintf(line, "--srtp-secure %d\n",
1946 app_config.cfg.srtp_secure_signaling);
1947 pj_strcat2(&cfg, line);
1948 }
1949#endif
1950
1951 /* Media */
1952 if (config->null_audio)
1953 pj_strcat2(&cfg, "--null-audio\n");
1954 if (config->auto_play)
1955 pj_strcat2(&cfg, "--auto-play\n");
1956 if (config->auto_loop)
1957 pj_strcat2(&cfg, "--auto-loop\n");
1958 if (config->auto_conf)
1959 pj_strcat2(&cfg, "--auto-conf\n");
1960 for (i=0; i<config->wav_count; ++i) {
1961 pj_ansi_sprintf(line, "--play-file %s\n",
1962 config->wav_files[i].ptr);
1963 pj_strcat2(&cfg, line);
1964 }
1965 for (i=0; i<config->tone_count; ++i) {
1966 pj_ansi_sprintf(line, "--play-tone %d,%d,%d,%d\n",
1967 config->tones[i].freq1, config->tones[i].freq2,
1968 config->tones[i].on_msec, config->tones[i].off_msec);
1969 pj_strcat2(&cfg, line);
1970 }
1971 if (config->rec_file.slen) {
1972 pj_ansi_sprintf(line, "--rec-file %s\n",
1973 config->rec_file.ptr);
1974 pj_strcat2(&cfg, line);
1975 }
1976 if (config->auto_rec)
1977 pj_strcat2(&cfg, "--auto-rec\n");
1978 if (config->capture_dev != PJSUA_INVALID_ID) {
1979 pj_ansi_sprintf(line, "--capture-dev %d\n", config->capture_dev);
1980 pj_strcat2(&cfg, line);
1981 }
1982 if (config->playback_dev != PJSUA_INVALID_ID) {
1983 pj_ansi_sprintf(line, "--playback-dev %d\n", config->playback_dev);
1984 pj_strcat2(&cfg, line);
1985 }
1986 if (config->media_cfg.snd_auto_close_time != -1) {
1987 pj_ansi_sprintf(line, "--snd-auto-close %d\n",
1988 config->media_cfg.snd_auto_close_time);
1989 pj_strcat2(&cfg, line);
1990 }
1991 if (config->no_tones) {
1992 pj_strcat2(&cfg, "--no-tones\n");
1993 }
1994 if (config->media_cfg.jb_max != -1) {
1995 pj_ansi_sprintf(line, "--jb-max-size %d\n",
1996 config->media_cfg.jb_max);
1997 pj_strcat2(&cfg, line);
1998 }
1999
2000 /* Sound device latency */
2001 if (config->capture_lat != PJMEDIA_SND_DEFAULT_REC_LATENCY) {
2002 pj_ansi_sprintf(line, "--capture-lat %d\n", config->capture_lat);
2003 pj_strcat2(&cfg, line);
2004 }
2005 if (config->playback_lat != PJMEDIA_SND_DEFAULT_PLAY_LATENCY) {
2006 pj_ansi_sprintf(line, "--playback-lat %d\n", config->playback_lat);
2007 pj_strcat2(&cfg, line);
2008 }
2009
2010 /* Media clock rate. */
2011 if (config->media_cfg.clock_rate != PJSUA_DEFAULT_CLOCK_RATE) {
2012 pj_ansi_sprintf(line, "--clock-rate %d\n",
2013 config->media_cfg.clock_rate);
2014 pj_strcat2(&cfg, line);
2015 } else {
2016 pj_ansi_sprintf(line, "#using default --clock-rate %d\n",
2017 config->media_cfg.clock_rate);
2018 pj_strcat2(&cfg, line);
2019 }
2020
2021 if (config->media_cfg.snd_clock_rate &&
2022 config->media_cfg.snd_clock_rate != config->media_cfg.clock_rate)
2023 {
2024 pj_ansi_sprintf(line, "--snd-clock-rate %d\n",
2025 config->media_cfg.snd_clock_rate);
2026 pj_strcat2(&cfg, line);
2027 }
2028
2029 /* Stereo mode. */
2030 if (config->media_cfg.channel_count == 2) {
2031 pj_ansi_sprintf(line, "--stereo\n");
2032 pj_strcat2(&cfg, line);
2033 }
2034
2035 /* quality */
2036 if (config->media_cfg.quality != PJSUA_DEFAULT_CODEC_QUALITY) {
2037 pj_ansi_sprintf(line, "--quality %d\n",
2038 config->media_cfg.quality);
2039 pj_strcat2(&cfg, line);
2040 } else {
2041 pj_ansi_sprintf(line, "#using default --quality %d\n",
2042 config->media_cfg.quality);
2043 pj_strcat2(&cfg, line);
2044 }
2045
2046 if (config->vid.vcapture_dev != PJMEDIA_VID_DEFAULT_CAPTURE_DEV) {
2047 pj_ansi_sprintf(line, "--vcapture-dev %d\n", config->vid.vcapture_dev);
2048 pj_strcat2(&cfg, line);
2049 }
2050 if (config->vid.vrender_dev != PJMEDIA_VID_DEFAULT_RENDER_DEV) {
2051 pj_ansi_sprintf(line, "--vrender-dev %d\n", config->vid.vrender_dev);
2052 pj_strcat2(&cfg, line);
2053 }
2054 for (i=0; i<config->avi_cnt; ++i) {
2055 pj_ansi_sprintf(line, "--play-avi %s\n", config->avi[i].path.ptr);
2056 pj_strcat2(&cfg, line);
2057 }
2058 if (config->avi_auto_play) {
2059 pj_ansi_sprintf(line, "--auto-play-avi\n");
2060 pj_strcat2(&cfg, line);
2061 }
2062
2063 /* ptime */
2064 if (config->media_cfg.ptime) {
2065 pj_ansi_sprintf(line, "--ptime %d\n",
2066 config->media_cfg.ptime);
2067 pj_strcat2(&cfg, line);
2068 }
2069
2070 /* no-vad */
2071 if (config->media_cfg.no_vad) {
2072 pj_strcat2(&cfg, "--no-vad\n");
2073 }
2074
2075 /* ec-tail */
2076 if (config->media_cfg.ec_tail_len != PJSUA_DEFAULT_EC_TAIL_LEN) {
2077 pj_ansi_sprintf(line, "--ec-tail %d\n",
2078 config->media_cfg.ec_tail_len);
2079 pj_strcat2(&cfg, line);
2080 } else {
2081 pj_ansi_sprintf(line, "#using default --ec-tail %d\n",
2082 config->media_cfg.ec_tail_len);
2083 pj_strcat2(&cfg, line);
2084 }
2085
2086 /* ec-opt */
2087 if (config->media_cfg.ec_options != 0) {
2088 pj_ansi_sprintf(line, "--ec-opt %d\n",
2089 config->media_cfg.ec_options);
2090 pj_strcat2(&cfg, line);
2091 }
2092
2093 /* ilbc-mode */
2094 if (config->media_cfg.ilbc_mode != PJSUA_DEFAULT_ILBC_MODE) {
2095 pj_ansi_sprintf(line, "--ilbc-mode %d\n",
2096 config->media_cfg.ilbc_mode);
2097 pj_strcat2(&cfg, line);
2098 } else {
2099 pj_ansi_sprintf(line, "#using default --ilbc-mode %d\n",
2100 config->media_cfg.ilbc_mode);
2101 pj_strcat2(&cfg, line);
2102 }
2103
2104 /* RTP drop */
2105 if (config->media_cfg.tx_drop_pct) {
2106 pj_ansi_sprintf(line, "--tx-drop-pct %d\n",
2107 config->media_cfg.tx_drop_pct);
2108 pj_strcat2(&cfg, line);
2109
2110 }
2111 if (config->media_cfg.rx_drop_pct) {
2112 pj_ansi_sprintf(line, "--rx-drop-pct %d\n",
2113 config->media_cfg.rx_drop_pct);
2114 pj_strcat2(&cfg, line);
2115
2116 }
2117
2118 /* Start RTP port. */
2119 pj_ansi_sprintf(line, "--rtp-port %d\n",
2120 config->rtp_cfg.port);
2121 pj_strcat2(&cfg, line);
2122
2123 /* Disable codec */
2124 for (i=0; i<config->codec_dis_cnt; ++i) {
2125 pj_ansi_sprintf(line, "--dis-codec %s\n",
2126 config->codec_dis[i].ptr);
2127 pj_strcat2(&cfg, line);
2128 }
2129 /* Add codec. */
2130 for (i=0; i<config->codec_cnt; ++i) {
2131 pj_ansi_sprintf(line, "--add-codec %s\n",
2132 config->codec_arg[i].ptr);
2133 pj_strcat2(&cfg, line);
2134 }
2135
2136 pj_strcat2(&cfg, "\n#\n# User agent:\n#\n");
2137
2138 /* Auto-answer. */
2139 if (config->auto_answer != 0) {
2140 pj_ansi_sprintf(line, "--auto-answer %d\n",
2141 config->auto_answer);
2142 pj_strcat2(&cfg, line);
2143 }
2144
2145 /* accept-redirect */
2146 if (config->redir_op != PJSIP_REDIRECT_ACCEPT_REPLACE) {
2147 pj_ansi_sprintf(line, "--accept-redirect %d\n",
2148 config->redir_op);
2149 pj_strcat2(&cfg, line);
2150 }
2151
2152 /* Max calls. */
2153 pj_ansi_sprintf(line, "--max-calls %d\n",
2154 config->cfg.max_calls);
2155 pj_strcat2(&cfg, line);
2156
2157 /* Uas-duration. */
2158 if (config->duration != NO_LIMIT_DURATION) {
2159 pj_ansi_sprintf(line, "--duration %d\n",
2160 config->duration);
2161 pj_strcat2(&cfg, line);
2162 }
2163
2164 /* norefersub ? */
2165 if (config->no_refersub) {
2166 pj_strcat2(&cfg, "--norefersub\n");
2167 }
2168
2169 if (pjsip_use_compact_form)
2170 {
2171 pj_strcat2(&cfg, "--use-compact-form\n");
2172 }
2173
2174 if (!config->cfg.force_lr) {
2175 pj_strcat2(&cfg, "--no-force-lr\n");
2176 }
2177
2178 pj_strcat2(&cfg, "\n#\n# Buddies:\n#\n");
2179
2180 /* Add buddies. */
2181 for (i=0; i<config->buddy_cnt; ++i) {
2182 pj_ansi_sprintf(line, "--add-buddy %.*s\n",
2183 (int)config->buddy_cfg[i].uri.slen,
2184 config->buddy_cfg[i].uri.ptr);
2185 pj_strcat2(&cfg, line);
2186 }
2187
2188 /* SIP extensions. */
2189 pj_strcat2(&cfg, "\n#\n# SIP extensions:\n#\n");
2190 /* 100rel extension */
2191 if (config->cfg.require_100rel) {
2192 pj_strcat2(&cfg, "--use-100rel\n");
2193 }
2194 /* Session Timer extension */
2195 if (config->cfg.use_timer) {
2196 pj_ansi_sprintf(line, "--use-timer %d\n",
2197 config->cfg.use_timer);
2198 pj_strcat2(&cfg, line);
2199 }
2200 if (config->cfg.timer_setting.min_se != 90) {
2201 pj_ansi_sprintf(line, "--timer-min-se %d\n",
2202 config->cfg.timer_setting.min_se);
2203 pj_strcat2(&cfg, line);
2204 }
2205 if (config->cfg.timer_setting.sess_expires != PJSIP_SESS_TIMER_DEF_SE) {
2206 pj_ansi_sprintf(line, "--timer-se %d\n",
2207 config->cfg.timer_setting.sess_expires);
2208 pj_strcat2(&cfg, line);
2209 }
2210
2211 *(cfg.ptr + cfg.slen) = '\0';
2212 return cfg.slen;
2213}