Debian Codegraph @

Xpjproject/pjsip-apps/src/pjsua/pjsua_app_config.c

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