diff --git a/channel.c b/channel.c index dc4dd8fb88314dd8289cb812bd8bb194db6448d6..98590d0b8f26f5b4f8fe62f340057b7d5d3cf4b7 100644 --- a/channel.c +++ b/channel.c @@ -2434,6 +2434,8 @@ struct ast_channel *__ast_request_and_dial(const char *type, int format, void *d ast_set_callerid(chan, oh->cid_num, oh->cid_name, oh->cid_num); if (oh->parent_channel) ast_channel_inherit_variables(oh->parent_channel, chan); + if (oh->account) + ast_cdr_setaccount(chan, oh->account); } ast_set_callerid(chan, cid_num, cid_name, cid_num); diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 94d776e4632fb30fd6acf25d46070eb3bfc00779..5457247740ce3e13f9fbbdbfdf01172a9bf683b9 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -481,6 +481,7 @@ struct chanmon; oh.priority = priority; \ oh.cid_num = cid_num; \ oh.cid_name = cid_name; \ + oh.account = account; \ oh.vars = vars; \ oh.parent_channel = NULL; \ } @@ -491,6 +492,7 @@ struct outgoing_helper { int priority; const char *cid_num; const char *cid_name; + const char *account; struct ast_variable *vars; struct ast_channel *parent_channel; }; diff --git a/include/asterisk/manager.h b/include/asterisk/manager.h index 5d62b300b5efd477834ec98ba7db420c807e186f..523ccfaae67d794018bd58328b18312d94c1dfbc 100644 --- a/include/asterisk/manager.h +++ b/include/asterisk/manager.h @@ -56,8 +56,8 @@ #define EVENT_FLAG_USER (1 << 6) /* Ability to read/set user info */ /* Export manager structures */ -#define MAX_HEADERS 80 -#define MAX_LEN 256 +#define AST_MAX_MANHEADERS 80 +#define AST_MAX_MANHEADER_LEN 256 struct eventqent { struct eventqent *next; @@ -88,7 +88,7 @@ struct mansession { /*! Authorization for writing */ int writeperm; /*! Buffer */ - char inbuf[MAX_LEN]; + char inbuf[AST_MAX_MANHEADER_LEN]; int inlen; int send_events; /* Queued events that we've not had the ability to send yet */ @@ -101,7 +101,7 @@ struct mansession { struct message { int hdrcount; - char headers[MAX_HEADERS][MAX_LEN]; + char headers[AST_MAX_MANHEADERS][AST_MAX_MANHEADER_LEN]; }; struct manager_action { diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 19d9284114d37e5e5415ac14248cd4e1a3da2e8e..e8d6507bbc2ff876563fac642cf8e7b0727e3169 100644 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -563,11 +563,11 @@ int ast_async_goto_by_name(const char *chan, const char *context, const char *ex /* Synchronously or asynchronously make an outbound call and send it to a particular extension */ -int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **locked_channel); +int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel); /* Synchronously or asynchronously make an outbound call and send it to a particular application with given extension */ -int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **locked_channel); +int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel); /* Functions for returning values from structures */ const char *ast_get_context_name(struct ast_context *con); diff --git a/manager.c b/manager.c index 91537c1185c8d9314aecd41438114cefddfb12ab..c8e4144f5473c8b001caa459e2022ba1e06aeff3 100644 --- a/manager.c +++ b/manager.c @@ -66,16 +66,17 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/utils.h" struct fast_originate_helper { - char tech[256]; - char data[256]; + char tech[AST_MAX_MANHEADER_LEN]; + char data[AST_MAX_MANHEADER_LEN]; int timeout; - char app[256]; - char appdata[256]; - char cid_name[256]; - char cid_num[256]; - char context[256]; - char exten[256]; - char idtext[256]; + char app[AST_MAX_APP]; + char appdata[AST_MAX_MANHEADER_LEN]; + char cid_name[AST_MAX_MANHEADER_LEN]; + char cid_num[AST_MAX_MANHEADER_LEN]; + char context[AST_MAX_CONTEXT]; + char exten[AST_MAX_EXTENSION]; + char idtext[AST_MAX_MANHEADER_LEN]; + char account[AST_MAX_ACCOUNT_CODE]; int priority; struct ast_variable *vars; }; @@ -949,12 +950,12 @@ static void *fast_originate(void *data) res = ast_pbx_outgoing_app(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->app, in->appdata, &reason, 1, !ast_strlen_zero(in->cid_num) ? in->cid_num : NULL, !ast_strlen_zero(in->cid_name) ? in->cid_name : NULL, - in->vars, &chan); + in->vars, in->account, &chan); } else { res = ast_pbx_outgoing_exten(in->tech, AST_FORMAT_SLINEAR, in->data, in->timeout, in->context, in->exten, in->priority, &reason, 1, !ast_strlen_zero(in->cid_num) ? in->cid_num : NULL, !ast_strlen_zero(in->cid_name) ? in->cid_name : NULL, - in->vars, &chan); + in->vars, in->account, &chan); } /* Tell the manager what happened with the channel */ @@ -1056,12 +1057,6 @@ static int action_originate(struct mansession *s, struct message *m) if (ast_strlen_zero(l)) l = NULL; } - if (account) { - struct ast_variable *newvar; - newvar = ast_variable_new("CDR(accountcode|r)", account); - newvar->next = vars; - vars = newvar; - } if (ast_true(async)) { struct fast_originate_helper *fast = malloc(sizeof(struct fast_originate_helper)); if (!fast) { @@ -1081,6 +1076,7 @@ static int action_originate(struct mansession *s, struct message *m) fast->vars = 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)); fast->timeout = to; fast->priority = pi; pthread_attr_init(&attr); @@ -1092,10 +1088,10 @@ static int action_originate(struct mansession *s, struct message *m) } } } else if (!ast_strlen_zero(app)) { - res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, NULL); + res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, account, NULL); } else { if (exten && context && pi) - res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, data, to, context, exten, pi, &reason, 1, l, n, vars, NULL); + res = ast_pbx_outgoing_exten(tech, AST_FORMAT_SLINEAR, 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'"); return 0; @@ -1414,7 +1410,7 @@ static void *session_do(void *data) if (process_message(s, &m)) break; memset(&m, 0, sizeof(m)); - } else if (m.hdrcount < MAX_HEADERS - 1) + } else if (m.hdrcount < AST_MAX_MANHEADERS - 1) m.hdrcount++; } else if (res < 0) break; diff --git a/pbx.c b/pbx.c index b25079b96963a30050b8f2a23b83876da6ec5332..e921811a9215fcc91cb7ee2023514aedabdc91f9 100644 --- a/pbx.c +++ b/pbx.c @@ -4649,7 +4649,7 @@ int ast_pbx_outgoing_cdr_failed(void) return 0; /* success */ } -int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **channel) +int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel) { struct ast_channel *chan; struct async_stat *as; @@ -4666,7 +4666,7 @@ int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout ast_mutex_lock(&chan->lock); } if (chan) { - if(chan->cdr) { /* check if the channel already has a cdr record, if not give it one */ + if (chan->cdr) { /* check if the channel already has a cdr record, if not give it one */ ast_log(LOG_WARNING, "%s already has a call record??\n", chan->name); } else { chan->cdr = ast_cdr_alloc(); /* allocate a cdr for the channel */ @@ -4743,6 +4743,8 @@ int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout ast_copy_string(chan->exten, "failed", sizeof(chan->exten)); chan->priority = 1; ast_set_variables(chan, vars); + if (account) + ast_cdr_setaccount(chan, account); ast_pbx_run(chan); } else ast_log(LOG_WARNING, "Can't allocate the channel structure, skipping execution of extension 'failed'\n"); @@ -4772,6 +4774,8 @@ int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout as->priority = priority; as->timeout = timeout; ast_set_variables(chan, vars); + if (account) + ast_cdr_setaccount(chan, account); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&as->p, &attr, async_wait, as)) { @@ -4813,7 +4817,7 @@ static void *ast_pbx_run_app(void *data) return NULL; } -int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, struct ast_channel **locked_channel) +int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel) { struct ast_channel *chan; struct async_stat *as; @@ -4821,9 +4825,10 @@ int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, int res = -1, cdr_res = -1; struct outgoing_helper oh; pthread_attr_t attr; - + memset(&oh, 0, sizeof(oh)); - oh.vars = vars; + oh.vars = vars; + oh.account = account; if (locked_channel) *locked_channel = NULL; @@ -4850,6 +4855,8 @@ int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, ast_cdr_start(chan->cdr); } ast_set_variables(chan, vars); + if (account) + ast_cdr_setaccount(chan, account); if (chan->_state == AST_STATE_UP) { res = 0; if (option_verbose > 3) @@ -4929,6 +4936,8 @@ int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout, ast_copy_string(as->appdata, appdata, sizeof(as->appdata)); as->timeout = timeout; ast_set_variables(chan, vars); + if (account) + ast_cdr_setaccount(chan, account); /* Start a new thread, and get something handling this channel. */ pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c index 2fa6f5f523b28c0fa4165e8d167bc2219cb5f828..a03085ed6c206b5d4d6f7b8e0ddc813eb0c96fb6 100644 --- a/pbx/pbx_spool.c +++ b/pbx/pbx_spool.c @@ -86,6 +86,9 @@ struct outgoing { char cid_num[256]; char cid_name[256]; + /* account code */ + char account[AST_MAX_ACCOUNT_CODE]; + /* Variables and Functions */ struct ast_variable *vars; @@ -211,11 +214,7 @@ static int apply_outgoing(struct outgoing *o, char *fn, FILE *f) } else ast_log(LOG_WARNING, "Malformed \"%s\" argument. Should be \"%s: variable=value\"\n", buf, buf); } else if (!strcasecmp(buf, "account")) { - var = ast_variable_new("CDR(accountcode|r)", c); - if (var) { - var->next = o->vars; - o->vars = var; - } + ast_copy_string(o->account, c, sizeof(o->account)); } else { ast_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, fn); } @@ -259,11 +258,11 @@ static void *attempt_thread(void *data) if (!ast_strlen_zero(o->app)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries); - res = ast_pbx_outgoing_app(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, NULL); + res = ast_pbx_outgoing_app(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL); } else { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries); - res = ast_pbx_outgoing_exten(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, NULL); + res = ast_pbx_outgoing_exten(o->tech, AST_FORMAT_SLINEAR, o->dest, o->waittime * 1000, o->context, o->exten, o->priority, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL); } if (res) { ast_log(LOG_NOTICE, "Call failed to go through, reason %d\n", reason); diff --git a/res/res_clioriginate.c b/res/res_clioriginate.c index 386f120a7be7d56e28d78f01b32c884ee3dd0a9f..36319f65fcba33e2f1015eaad878cfc5e26f8330 100644 --- a/res/res_clioriginate.c +++ b/res/res_clioriginate.c @@ -88,7 +88,7 @@ static int orig_app(const char *chan, const char *app, const char *appdata) return RESULT_SHOWUSAGE; } - ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL); + ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 1, NULL, NULL, NULL, NULL, NULL); return RESULT_SUCCESS; } @@ -122,7 +122,7 @@ static int orig_exten(const char *chan, const char *data) if (ast_strlen_zero(context)) context = "default"; - ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL); + ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 1, NULL, NULL, NULL, NULL, NULL); return RESULT_SUCCESS; }