aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-17 03:10:38 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2004-11-17 03:10:38 +0000
commit4eee9c03a206ae469dc08b81e387285f6d5dd483 (patch)
tree5f09de0c63c3e5dfb630ede8e072960d03174ade /channels
parent9a7206444089965a64c71bb130a51e74f2850655 (diff)
Merge Tony's uservars (bug #2882)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4267 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-xchannels/chan_iax2.c41
-rwxr-xr-xchannels/chan_sip.c46
2 files changed, 84 insertions, 3 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 747e7328e..1b49dcce3 100755
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -15,6 +15,7 @@
#include <asterisk/frame.h>
#include <asterisk/channel.h>
#include <asterisk/channel_pvt.h>
+#include <asterisk/config_pvt.h>
#include <asterisk/logger.h>
#include <asterisk/module.h>
#include <asterisk/pbx.h>
@@ -207,6 +208,7 @@ struct iax2_user {
struct iax2_user *next;
int notransfer;
int usejitterbuf;
+ struct ast_variable *vars;
};
struct iax2_peer {
@@ -479,6 +481,7 @@ struct chan_iax2_pvt {
struct iax2_dpcache *dpentries;
int notransfer; /* do we want native bridging */
int usejitterbuf; /* use jitter buffer on this channel? */
+ struct ast_variable *vars;
};
static struct ast_iax2_queue {
@@ -1417,8 +1420,13 @@ retry:
if (pvt->reg) {
pvt->reg->callno = 0;
}
- if (!owner)
+ if (!owner) {
+ if (pvt->vars) {
+ ast_destroy_realtime(pvt->vars);
+ pvt->vars = NULL;
+ }
free(pvt);
+ }
}
if (owner) {
ast_mutex_unlock(&owner->lock);
@@ -2672,6 +2680,8 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
{
struct ast_channel *tmp;
struct chan_iax2_pvt *i;
+ struct ast_variable *v = NULL;
+
/* Don't hold call lock */
ast_mutex_unlock(&iaxsl[callno]);
tmp = ast_channel_alloc(1);
@@ -2737,6 +2747,9 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
tmp = NULL;
}
}
+ for (v = i->vars ; v ; v = v->next)
+ pbx_builtin_setvar_helper(tmp,v->name,v->value);
+
}
return tmp;
}
@@ -3574,6 +3587,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
int bestscore = 0;
int gotcapability=0;
char iabuf[INET_ADDRSTRLEN];
+ struct ast_variable *v = NULL, *tmpvar = NULL;
if (!iaxs[callno])
return res;
@@ -3676,7 +3690,14 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
}
if (user) {
/* We found our match (use the first) */
-
+ /* copy vars */
+ for (v = user->vars ; v ; v = v->next) {
+ if((tmpvar = ast_new_variable(v->name, v->value))) {
+ tmpvar->next = iaxs[callno]->vars;
+ iaxs[callno]->vars = tmpvar;
+ }
+ }
+
/* Store the requested username if not specified */
if (ast_strlen_zero(iaxs[callno]->username))
strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
@@ -6573,6 +6594,8 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, in
struct iax2_context *oldcon = NULL;
int format;
int found;
+ char *varname = NULL, *varval = NULL;
+ struct ast_variable *tmpvar = NULL;
prev = NULL;
ast_mutex_lock(&userl.lock);
@@ -6626,6 +6649,16 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, in
} else if (!strcasecmp(v->name, "permit") ||
!strcasecmp(v->name, "deny")) {
user->ha = ast_append_ha(v->name, v->value, user->ha);
+ } else if (!strcasecmp(v->name, "setvar")) {
+ varname = ast_strdupa(v->value);
+ if (varname && (varval = strchr(varname,'='))) {
+ *varval = '\0';
+ varval++;
+ if((tmpvar = ast_new_variable(varname, varval))) {
+ tmpvar->next = user->vars;
+ user->vars = tmpvar;
+ }
+ }
} else if (!strcasecmp(v->name, "allow")) {
format = ast_getformatbyname(v->value);
if (format < 1)
@@ -6741,6 +6774,10 @@ static void destroy_user(struct iax2_user *user)
{
ast_free_ha(user->ha);
free_context(user->contexts);
+ if(user->vars) {
+ ast_destroy_realtime(user->vars);
+ user->vars = NULL;
+ }
free(user);
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 3481f84ea..276d3ba60 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -18,6 +18,7 @@
#include <asterisk/lock.h>
#include <asterisk/channel.h>
#include <asterisk/channel_pvt.h>
+#include <asterisk/config_pvt.h>
#include <asterisk/config.h>
#include <asterisk/logger.h>
#include <asterisk/module.h>
@@ -352,6 +353,7 @@ static struct sip_pvt {
struct ast_rtp *vrtp; /* Video RTP session */
struct sip_pkt *packets; /* Packets scheduled for re-transmission */
struct sip_history *history; /* History of this SIP dialog */
+ struct ast_variable *vars;
struct sip_pvt *next; /* Next call in chain */
} *iflist = NULL;
@@ -405,6 +407,7 @@ struct sip_user {
int progressinband;
struct ast_ha *ha; /* ACL setting */
int temponly; /* Flag for temporary users (realtime) */
+ struct ast_variable *vars;
struct sip_user *next;
};
@@ -1151,6 +1154,10 @@ static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin)
static void destroy_user(struct sip_user *user)
{
ast_free_ha(user->ha);
+ if(user->vars) {
+ ast_destroy_realtime(user->vars);
+ user->vars = NULL;
+ }
free(user);
}
@@ -1557,6 +1564,10 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner)
free(cp);
}
ast_mutex_destroy(&p->lock);
+ if(p->vars) {
+ ast_destroy_realtime(p->vars);
+ p->vars = NULL;
+ }
free(p);
}
}
@@ -1957,8 +1968,9 @@ static int sip_indicate(struct ast_channel *ast, int condition)
static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
{
struct ast_channel *tmp;
+ struct ast_variable *v = NULL;
int fmt;
-
+
ast_mutex_unlock(&i->lock);
/* Don't hold a sip pvt lock while we allocate a channel */
tmp = ast_channel_alloc(1);
@@ -2062,6 +2074,8 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title)
tmp = NULL;
}
}
+ for (v = i->vars ; v ; v = v->next)
+ pbx_builtin_setvar_helper(tmp,v->name,v->value);
} else
ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
return tmp;
@@ -2294,6 +2308,10 @@ static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useg
if (!p->rtp) {
ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
ast_mutex_destroy(&p->lock);
+ if(p->vars) {
+ ast_destroy_realtime(p->vars);
+ p->vars = NULL;
+ }
free(p);
return NULL;
}
@@ -5257,6 +5275,7 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd
char *t;
char calleridname[50];
int debug=sip_debug_test_addr(sin);
+ struct ast_variable *tmpvar = NULL, *v = NULL;
/* Terminate URI */
t = uri;
@@ -5304,6 +5323,13 @@ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd
user = find_user(of);
/* Find user based on user name in the from header */
if (user && ast_apply_ha(user->ha, sin)) {
+ /* copy vars */
+ for (v = user->vars ; v ; v = v->next) {
+ if((tmpvar = ast_new_variable(v->name, v->value))) {
+ tmpvar->next = p->vars;
+ p->vars = tmpvar;
+ }
+ }
p->nat = user->nat;
#ifdef OSP_SUPPORT
p->ospauth = user->ospauth;
@@ -8126,6 +8152,9 @@ static struct sip_user *build_user(const char *name, struct ast_variable *v)
struct sip_user *user;
int format;
struct ast_ha *oldha = NULL;
+ char *varname = NULL, *varval = NULL;
+ struct ast_variable *tmpvar = NULL;
+
user = (struct sip_user *)malloc(sizeof(struct sip_user));
if (user) {
memset(user, 0, sizeof(struct sip_user));
@@ -8150,6 +8179,17 @@ static struct sip_user *build_user(const char *name, struct ast_variable *v)
while(v) {
if (!strcasecmp(v->name, "context")) {
strncpy(user->context, v->value, sizeof(user->context) - 1);
+ } else if (!strcasecmp(v->name, "setvar")) {
+ varname = ast_strdupa(v->value);
+ if (varname && (varval = strchr(varname,'='))) {
+ *varval = '\0';
+ varval++;
+ if((tmpvar = ast_new_variable(varname, varval))) {
+ tmpvar->next = user->vars;
+ user->vars = tmpvar;
+ }
+
+ }
} else if (!strcasecmp(v->name, "permit") ||
!strcasecmp(v->name, "deny")) {
user->ha = ast_append_ha(v->name, v->value, user->ha);
@@ -9203,6 +9243,10 @@ int unload_module()
p = p->next;
/* Free associated memory */
ast_mutex_destroy(&pl->lock);
+ if(pl->vars) {
+ ast_destroy_realtime(pl->vars);
+ pl->vars = NULL;
+ }
free(pl);
}
iflist = NULL;