[asterisk-commits] oej: branch oej/bufo-manager-contexts-trunk r283014 - in /team/oej/bufo-manag...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 20 07:45:25 CDT 2010
Author: oej
Date: Fri Aug 20 07:45:22 2010
New Revision: 283014
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=283014
Log:
Initialize automatic merging in the bufo-manager-contexts-trunk branch...
Modified:
team/oej/bufo-manager-contexts-trunk/ (props changed)
team/oej/bufo-manager-contexts-trunk/main/manager.c
Propchange: team/oej/bufo-manager-contexts-trunk/
------------------------------------------------------------------------------
automerge = Note to myself: Always use fruit or frog names on branches.
Propchange: team/oej/bufo-manager-contexts-trunk/
------------------------------------------------------------------------------
automerge-email = oej at edvina.net
Modified: team/oej/bufo-manager-contexts-trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-contexts-trunk/main/manager.c?view=diff&rev=283014&r1=283013&r2=283014
==============================================================================
--- team/oej/bufo-manager-contexts-trunk/main/manager.c (original)
+++ team/oej/bufo-manager-contexts-trunk/main/manager.c Fri Aug 20 07:45:22 2010
@@ -142,6 +142,14 @@
{{ "module", "unload", NULL }},
{{ "restart", "gracefully", NULL }},
};
+
+/*! \brief Structure for simple linked list of available contexts for a manager
+ session */
+struct man_context {
+ char context[AST_MAX_CONTEXT];
+ struct man_context *next;
+};
+
/* In order to understand what the heck is going on with the
* mansession_session and mansession structs, we need to have a bit of a history
@@ -210,6 +218,7 @@
char inbuf[1024];
int inlen;
int send_events;
+ struct man_context *contexts;
int displaysystemname; /*!< Add system name to manager responses and events */
/* Queued events that we've not had the ability to send yet */
struct eventqent *eventq;
@@ -248,6 +257,12 @@
static struct manager_action *first_action;
AST_RWLOCK_DEFINE_STATIC(actionlock);
+
+/* Forward declarations */
+static struct man_context *append_context(struct man_context *con, const char *context);
+static int apply_context(struct man_context *con, const char *context);
+static void free_contexts(struct man_context *con);
+static struct man_context *build_context(const char *context);
/*! \brief Convert authority code to string with serveral options */
static char *authority_to_str(int authority, char *res, int reslen)
@@ -794,6 +809,9 @@
s->eventq = s->eventq->next;
unuse_eventqent(eqe);
}
+ if (s->contexts) {
+ free_contexts(s->contexts);
+ }
free(s);
}
@@ -1005,6 +1023,7 @@
const char *authtype = astman_get_header(m, "AuthType");
const char *key = astman_get_header(m, "Key");
const char *events = astman_get_header(m, "Events");
+ struct man_context *contexts = NULL;
cfg = ast_config_load("manager.conf");
if (!cfg)
@@ -1021,6 +1040,8 @@
for (v = ast_variable_browse(cfg, cat); v; v = v->next) {
if (!strcasecmp(v->name, "secret")) {
password = v->value;
+ } else if (!strcasecmp(v->name, "context")) {
+ contexts = append_context(contexts, v->value);
} else if (!strcasecmp(v->name, "displaysystemname")) {
if (ast_true(v->value)) {
if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
@@ -1088,6 +1109,7 @@
}
if (cat) {
ast_copy_string(s->session->username, cat, sizeof(s->session->username));
+ s->session->contexts = contexts;
s->session->readperm = get_perm(ast_variable_retrieve(cfg, cat, "read"));
s->session->writeperm = get_perm(ast_variable_retrieve(cfg, cat, "write"));
ast_config_destroy(cfg);
@@ -1725,6 +1747,12 @@
return 0;
}
}
+
+ /* Check if redirect is to allowed context */
+ if (s->session->contexts && ! apply_context(s->session->contexts, context) ) {
+ astman_send_error(s, m, "Illegal context");
+ return 0;
+ }
/* XXX watch out, possible deadlock!!! */
chan = ast_get_channel_by_name_locked(name);
if (!chan) {
@@ -1920,6 +1948,50 @@
ast_channel_unlock(chan);
free(in);
return NULL;
+}
+
+/* Search list of context. Stolen from chan_iax2 */
+static int apply_context(struct man_context *con, const char *context)
+{
+ while(con) {
+ if (!strcmp(con->context, context) || !strcmp(con->context, "*")) {
+ return 1;
+ }
+ con = con->next;
+ }
+ return 0;
+}
+
+static void free_contexts(struct man_context *con)
+{
+ struct man_context *conl;
+ while(con) {
+ conl = con;
+ con = con->next;
+ ast_free(conl);
+ }
+}
+
+static struct man_context *build_context(const char *context)
+{
+ struct man_context *con;
+
+ if ((con = ast_calloc(1, sizeof(*con)))) {
+ ast_copy_string(con->context, context, sizeof(con->context));
+ }
+
+ return con;
+}
+
+static struct man_context *append_context(struct man_context *con, const char *context)
+{
+ struct man_context *top;
+ if (!con) {
+ return build_context(context);
+ }
+ top = build_context(context);
+ top->next = con;
+ return top;
}
static char mandescr_originate[] =
@@ -1986,6 +2058,11 @@
astman_send_error(s, m, "Invalid channel");
return 0;
}
+ if (s->session->contexts && ! apply_context(s->session->contexts, context) ) {
+ astman_send_error(s, m, "Illegal context");
+ return 0;
+ }
+
*data++ = '\0';
ast_copy_string(tmp2, callerid, sizeof(tmp2));
ast_callerid_parse(tmp2, &n, &l);
@@ -2146,6 +2223,11 @@
}
if (ast_strlen_zero(context))
context = "default";
+ /* Check if redirect is to allowed context */
+ if (s->session->contexts && ! apply_context(s->session->contexts, context) ) {
+ astman_send_error(s, m, "Illegal context");
+ return 0;
+ }
status = ast_extension_state(NULL, context, exten);
ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
if (!ast_strlen_zero(id)) {
More information about the asterisk-commits
mailing list