summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2016-12-26 20:26:20 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2016-12-26 20:26:20 +0100
commit53712434c0f7b6d34523540ad766aa27c2cc9501 (patch)
treee40f9b195764aa9ec406d00a9d5729e66959028f /src
parentdb040d4ea167f23139d571662e79a4478700025e (diff)
mnat: make it re-entrant
Diffstat (limited to 'src')
-rw-r--r--src/account.c2
-rw-r--r--src/baresip.c9
-rw-r--r--src/core.h2
-rw-r--r--src/mnat.c19
4 files changed, 22 insertions, 10 deletions
diff --git a/src/account.c b/src/account.c
index f870e2f..3ecf7d8 100644
--- a/src/account.c
+++ b/src/account.c
@@ -387,7 +387,7 @@ int account_alloc(struct account **accp, const char *sipaddr)
if (err)
goto out;
- acc->mnat = mnat_find(acc->mnatid);
+ acc->mnat = mnat_find(baresip_mnatl(), acc->mnatid);
if (!acc->mnat) {
warning("account: medianat not found: `%s'\n",
acc->mnatid);
diff --git a/src/baresip.c b/src/baresip.c
index 6c68944..cc4009a 100644
--- a/src/baresip.c
+++ b/src/baresip.c
@@ -17,6 +17,7 @@ static struct baresip {
struct contacts contacts;
struct commands commands;
struct player *player;
+ struct list mnatl;
} baresip;
@@ -29,6 +30,8 @@ int baresip_init(struct config *cfg, bool prefer_ipv6)
baresip.net = mem_deref(baresip.net);
+ list_init(&baresip.mnatl);
+
/* Initialise Network */
err = net_alloc(&baresip.net, &cfg->net,
prefer_ipv6 ? AF_INET6 : AF_INET);
@@ -85,3 +88,9 @@ struct player *baresip_player(void)
{
return baresip.player;
}
+
+
+struct list *baresip_mnatl(void)
+{
+ return &baresip.mnatl;
+}
diff --git a/src/core.h b/src/core.h
index ac1efd8..5466eca 100644
--- a/src/core.h
+++ b/src/core.h
@@ -217,7 +217,7 @@ struct mnat {
mnat_update_h *updateh;
};
-const struct mnat *mnat_find(const char *id);
+const struct mnat *mnat_find(const struct list *mnatl, const char *id);
/*
diff --git a/src/mnat.c b/src/mnat.c
index 416e93b..4349589 100644
--- a/src/mnat.c
+++ b/src/mnat.c
@@ -9,9 +9,6 @@
#include "core.h"
-static struct list mnatl = LIST_INIT;
-
-
static void destructor(void *arg)
{
struct mnat *mnat = arg;
@@ -24,6 +21,7 @@ static void destructor(void *arg)
* Register a Media NAT traversal module
*
* @param mnatp Pointer to allocated Media NAT traversal module
+ * @param mnatl List of Media-NAT modules
* @param id Media NAT Identifier
* @param ftag SIP Feature tag (optional)
* @param sessh Session allocation handler
@@ -32,7 +30,8 @@ static void destructor(void *arg)
*
* @return 0 if success, otherwise errorcode
*/
-int mnat_register(struct mnat **mnatp, const char *id, const char *ftag,
+int mnat_register(struct mnat **mnatp, struct list *mnatl,
+ const char *id, const char *ftag,
mnat_sess_h *sessh, mnat_media_h *mediah,
mnat_update_h *updateh)
{
@@ -45,7 +44,7 @@ int mnat_register(struct mnat **mnatp, const char *id, const char *ftag,
if (!mnat)
return ENOMEM;
- list_append(&mnatl, &mnat->le, mnat);
+ list_append(mnatl, &mnat->le, mnat);
mnat->id = id;
mnat->ftag = ftag;
@@ -64,16 +63,20 @@ int mnat_register(struct mnat **mnatp, const char *id, const char *ftag,
/**
* Find a Media NAT module by name
*
- * @param id Name of the Media NAT module to find
+ * @param mnatl List of Media-NAT modules
+ * @param id Name of the Media NAT module to find
*
* @return Matching Media NAT module if found, otherwise NULL
*/
-const struct mnat *mnat_find(const char *id)
+const struct mnat *mnat_find(const struct list *mnatl, const char *id)
{
struct mnat *mnat;
struct le *le;
- for (le=mnatl.head; le; le=le->next) {
+ if (!mnatl)
+ return NULL;
+
+ for (le=mnatl->head; le; le=le->next) {
mnat = le->data;