[asterisk-commits] oej: branch oej/bufo-manager-varfix-trunk r283010 - in /team/oej/bufo-manager...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Aug 20 07:39:21 CDT 2010
Author: oej
Date: Fri Aug 20 07:39:18 2010
New Revision: 283010
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=283010
Log:
- move ast_variable_copy to config.c where it belongs
- Fix bugs in memory allocation
Modified:
team/oej/bufo-manager-varfix-trunk/include/asterisk/config.h
team/oej/bufo-manager-varfix-trunk/main/config.c
team/oej/bufo-manager-varfix-trunk/main/manager.c
Modified: team/oej/bufo-manager-varfix-trunk/include/asterisk/config.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-varfix-trunk/include/asterisk/config.h?view=diff&rev=283010&r1=283009&r2=283010
==============================================================================
--- team/oej/bufo-manager-varfix-trunk/include/asterisk/config.h (original)
+++ team/oej/bufo-manager-varfix-trunk/include/asterisk/config.h Fri Aug 20 07:39:18 2010
@@ -195,6 +195,10 @@
int ast_variable_update(struct ast_category *category, const char *variable,
const char *value, const char *match, unsigned int object);
+/*! \brief copy variables, preserving order */
+struct ast_variable *ast_variable_copy(struct ast_variable *in);
+
+
int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, int withcomments);
Modified: team/oej/bufo-manager-varfix-trunk/main/config.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-varfix-trunk/main/config.c?view=diff&rev=283010&r1=283009&r2=283010
==============================================================================
--- team/oej/bufo-manager-varfix-trunk/main/config.c (original)
+++ team/oej/bufo-manager-varfix-trunk/main/config.c Fri Aug 20 07:39:18 2010
@@ -224,6 +224,27 @@
ast_destroy_comment(&vn->sameline);
free(vn);
}
+}
+
+/*! \brief copy variables, preserving order */
+struct ast_variable *ast_variable_copy(struct ast_variable *in)
+{
+ /* This really belongs in config.c, and will move there in non-releases */
+
+ struct ast_variable *out = NULL, *tmp, *v, *prev = NULL;
+
+ for (v = in ; v ; v = v->next) {
+ if ((tmp = ast_variable_new(v->name, v->value))) {
+ if (!out) {
+ out = tmp; /* The first record */
+ }
+ if (prev) {
+ prev->next = tmp;
+ }
+ prev = tmp;
+ }
+ }
+ return out;
}
struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category)
Modified: team/oej/bufo-manager-varfix-trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-varfix-trunk/main/manager.c?view=diff&rev=283010&r1=283009&r2=283010
==============================================================================
--- team/oej/bufo-manager-varfix-trunk/main/manager.c (original)
+++ team/oej/bufo-manager-varfix-trunk/main/manager.c Fri Aug 20 07:39:18 2010
@@ -1918,6 +1918,9 @@
/* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */
if (chan)
ast_channel_unlock(chan);
+ if (in->vars) {
+ ast_variables_destroy(in->vars);
+ }
free(in);
return NULL;
}
@@ -1952,7 +1955,7 @@
const char *async = astman_get_header(m, "Async");
const char *id = astman_get_header(m, "ActionID");
const char *codecs = astman_get_header(m, "Codecs");
- struct ast_variable *vars = astman_get_variables(m);
+ struct ast_variable *vars = NULL;
char *tech, *data;
char *l = NULL, *n = NULL;
int pi = 0;
@@ -2002,6 +2005,12 @@
format = 0;
ast_parse_allow_disallow(NULL, &format, codecs, 1);
}
+
+ /* read variables from manager command and allocate memory now
+ when we're ready to start acting.
+ */
+ vars = astman_get_variables(m);
+
if (ast_true(async)) {
struct fast_originate_helper *fast = ast_calloc(1, sizeof(*fast));
if (!fast) {
@@ -2017,7 +2026,7 @@
ast_copy_string(fast->cid_num, l, sizeof(fast->cid_num));
if (n)
ast_copy_string(fast->cid_name, n, sizeof(fast->cid_name));
- fast->vars = vars;
+ fast->vars = ast_variable_copy(vars);
ast_copy_string(fast->context, context, sizeof(fast->context));
ast_copy_string(fast->exten, exten, sizeof(fast->exten));
ast_copy_string(fast->account, account, sizeof(fast->account));
@@ -2027,6 +2036,9 @@
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (ast_pthread_create(&th, &attr, fast_originate, fast)) {
+ if (fast->vars) {
+ ast_variables_destroy(fast->vars);
+ }
ast_free(fast);
res = -1;
} else {
@@ -2041,6 +2053,9 @@
res = ast_pbx_outgoing_exten(tech, format, data, to, context, exten, pi, &reason, 1, l, n, vars, account, NULL);
else {
astman_send_error(s, m, "Originate with 'Exten' requires 'Context' and 'Priority'");
+ if (vars) {
+ ast_variables_destroy(vars);
+ }
return 0;
}
}
@@ -2048,6 +2063,9 @@
astman_send_ack(s, m, "Originate successfully queued");
else
astman_send_error(s, m, "Originate failed");
+ if (vars) {
+ ast_variables_destroy(vars);
+ }
return 0;
}
More information about the asterisk-commits
mailing list