summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2015-11-30 11:01:18 +0100
committerAlfred E. Heggestad <aeh@db.org>2015-11-30 11:01:18 +0100
commitb3009aeb15d7eb450657e741493af9409dcf968c (patch)
tree84879ec45b15ec2523ab82f8baa1ee3d5906afb1 /src
parentd94d4acbc9c5c5cb77700a873a0208540ea8e8e8 (diff)
add command-line option -u to add extra UA params
- also move module pre-loading to after all arguments are parsed - the extra UA parameters will be appended to the end of the UA accounts string. Example $ baresip -umedianat=turn
Diffstat (limited to 'src')
-rw-r--r--src/main.c46
-rw-r--r--src/ua.c22
2 files changed, 61 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index b9a9309..a7aee59 100644
--- a/src/main.c
+++ b/src/main.c
@@ -45,10 +45,11 @@ static void usage(void)
"\t-d Daemon\n"
"\t-e <commands> Exec commands\n"
"\t-f <path> Config path\n"
- "\t-m <module> Pre-load module\n"
+ "\t-m <module> Pre-load modules (repeat)\n"
"\t-p <path> Audio files\n"
"\t-h -? Help\n"
"\t-t Test and exit\n"
+ "\t-u <parameters> Extra UA parameters\n"
"\t-v Verbose debug\n"
);
}
@@ -57,7 +58,10 @@ static void usage(void)
int main(int argc, char *argv[])
{
bool prefer_ipv6 = false, run_daemon = false, test = false;
+ const char *ua_eprm = NULL;
const char *exec = NULL;
+ const char *modv[16];
+ size_t modc = 0;
int err;
(void)re_fprintf(stderr, "baresip v%s"
@@ -73,7 +77,7 @@ int main(int argc, char *argv[])
#ifdef HAVE_GETOPT
for (;;) {
- const int c = getopt(argc, argv, "6de:f:p:hvtm:");
+ const int c = getopt(argc, argv, "6de:f:p:hu:vtm:");
if (0 > c)
break;
@@ -103,12 +107,13 @@ int main(int argc, char *argv[])
break;
case 'm':
- err = module_preload(optarg);
- if (err) {
- re_fprintf(stderr,
- "could not pre-load module"
- " '%s' (%m)\n", optarg, err);
+ if (modc >= ARRAY_SIZE(modv)) {
+ warning("max %zu modules\n",
+ ARRAY_SIZE(modv));
+ err = EINVAL;
+ goto out;
}
+ modv[modc++] = optarg;
break;
case 'p':
@@ -119,6 +124,10 @@ int main(int argc, char *argv[])
test = true;
break;
+ case 'u':
+ ua_eprm = optarg;
+ break;
+
case 'v':
log_enable_debug(true);
break;
@@ -132,6 +141,23 @@ int main(int argc, char *argv[])
(void)argv;
#endif
+ /* NOTE: must be done after all arguments are processed */
+ if (modc) {
+ size_t i;
+
+ info("pre-loading modules: %zu\n", modc);
+
+ for (i=0; i<modc; i++) {
+
+ err = module_preload(modv[i]);
+ if (err) {
+ re_fprintf(stderr,
+ "could not pre-load module"
+ " '%s' (%m)\n", modv[i], err);
+ }
+ }
+ }
+
err = conf_configure();
if (err) {
warning("main: configure failed: %m\n", err);
@@ -144,6 +170,12 @@ int main(int argc, char *argv[])
if (err)
goto out;
+ if (ua_eprm) {
+ err = uag_set_extra_params(ua_eprm);
+ if (err)
+ goto out;
+ }
+
if (test)
goto out;
diff --git a/src/ua.c b/src/ua.c
index cd49c62..685bb87 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -58,6 +58,7 @@ static struct {
bool use_tls; /**< Use TLS transport */
bool prefer_ipv6; /**< Force IPv6 transport */
sip_msg_h *subh;
+ char *eprm; /**< Extra UA parameters */
#ifdef USE_TLS
struct tls *tls; /**< TLS Context */
#endif
@@ -75,6 +76,7 @@ static struct {
true,
false,
NULL,
+ NULL,
#ifdef USE_TLS
NULL,
#endif
@@ -586,6 +588,7 @@ static void add_extension(struct ua *ua, const char *extension)
int ua_alloc(struct ua **uap, const char *aor)
{
struct ua *ua;
+ char *buf = NULL;
int err;
if (!aor)
@@ -606,6 +609,12 @@ int ua_alloc(struct ua **uap, const char *aor)
#endif
/* Decode SIP address */
+ if (uag.eprm) {
+ err = re_sdprintf(&buf, "%s;%s", aor, uag.eprm);
+ if (err)
+ goto out;
+ aor = buf;
+ }
err = account_alloc(&ua->acc, aor);
if (err)
@@ -677,6 +686,7 @@ int ua_alloc(struct ua **uap, const char *aor)
uag_current_set(ua);
out:
+ mem_deref(buf);
if (err)
mem_deref(ua);
else if (uap) {
@@ -1411,6 +1421,7 @@ void ua_close(void)
uag.sock = mem_deref(uag.sock);
uag.lsnr = mem_deref(uag.lsnr);
uag.sip = mem_deref(uag.sip);
+ uag.eprm = mem_deref(uag.eprm);
#ifdef USE_TLS
uag.tls = mem_deref(uag.tls);
@@ -1931,3 +1942,14 @@ void ua_set_media_af(struct ua *ua, int af_media)
ua->af_media = af_media;
}
+
+
+int uag_set_extra_params(char *eprm)
+{
+ uag.eprm = mem_deref(uag.eprm);
+
+ if (eprm)
+ return str_dup(&uag.eprm, eprm);
+
+ return 0;
+}