[asterisk-commits] mmichelson: branch mmichelson/features_config r390710 - in /team/mmichelson/f...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 6 15:19:01 CDT 2013
Author: mmichelson
Date: Thu Jun 6 15:19:00 2013
New Revision: 390710
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390710
Log:
Get the jump on automerge so I can get a new review posted.
Modified:
team/mmichelson/features_config/ (props changed)
team/mmichelson/features_config/CHANGES
team/mmichelson/features_config/include/asterisk/stasis_message_router.h
team/mmichelson/features_config/main/stasis_message_router.c
team/mmichelson/features_config/res/res_agi.c
Propchange: team/mmichelson/features_config/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jun 6 15:19:00 2013
@@ -1,1 +1,1 @@
-/trunk:1-390683
+/trunk:1-390707
Modified: team/mmichelson/features_config/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/CHANGES?view=diff&rev=390710&r1=390709&r2=390710
==============================================================================
--- team/mmichelson/features_config/CHANGES (original)
+++ team/mmichelson/features_config/CHANGES Thu Jun 6 15:19:00 2013
@@ -105,6 +105,13 @@
* The AMI 'Hold' event has been moved out of individual channel drivers, into
core, and is now two events: Hold and Unhold. The status field has been
removed.
+
+AGI (Asterisk Gateway Interface)
+------------------
+ * The manager event AGIExec has been split into AGIExecStart and AGIExecEnd.
+
+ * The manager event AsyncAGI has been split into AsyncAGIStart, AsyncAGIExec,
+ and AsyncAGIEnd.
Channel Drivers
------------------
Modified: team/mmichelson/features_config/include/asterisk/stasis_message_router.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/include/asterisk/stasis_message_router.h?view=diff&rev=390710&r1=390709&r2=390710
==============================================================================
--- team/mmichelson/features_config/include/asterisk/stasis_message_router.h (original)
+++ team/mmichelson/features_config/include/asterisk/stasis_message_router.h Thu Jun 6 15:19:00 2013
@@ -47,9 +47,12 @@
/*!
* \brief Create a new message router object.
+ *
* \param topic Topic to subscribe route to.
+ *
* \return New \ref stasis_message_router.
* \return \c NULL on error.
+ *
* \since 12
*/
struct stasis_message_router *stasis_message_router_create(
@@ -59,6 +62,7 @@
* \brief Unsubscribe the router from the upstream topic.
*
* \param router Router to unsubscribe.
+ *
* \since 12
*/
void stasis_message_router_unsubscribe(struct stasis_message_router *router);
@@ -71,6 +75,7 @@
* vs. stasis_message_router_unsubscribe().
*
* \param router Router to unsubscribe.
+ *
* \since 12
*/
void stasis_message_router_unsubscribe_and_join(
@@ -80,6 +85,7 @@
* \brief Returns whether \a router has received its final message.
*
* \param router Router.
+ *
* \return True (non-zero) if stasis_subscription_final_message() has been
* received.
* \return False (zero) if waiting for the end.
@@ -88,10 +94,15 @@
/*!
* \brief Add a route to a message router.
+ *
* \param router Router to add the route to.
* \param message_type Type of message to route.
* \param callback Callback to forard messages of \a message_type to.
* \param data Data pointer to pass to \a callback.
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
* \since 12
*/
int stasis_message_router_add(struct stasis_message_router *router,
@@ -100,10 +111,26 @@
void *data);
/*!
+ * \brief Remove a route from a message router.
+ *
+ * \param router Router to remove the route from.
+ * \param message_type Type of message to route.
+ *
+ * \since 12
+ */
+void stasis_message_router_remove(struct stasis_message_router *router,
+ struct stasis_message_type *message_type);
+
+/*!
* \brief Sets the default route of a router.
+ *
* \param router Router to set the default route of.
* \param callback Callback to forard messages which otherwise have no home.
* \param data Data pointer to pass to \a callback.
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
* \since 12
*/
int stasis_message_router_set_default(struct stasis_message_router *router,
Modified: team/mmichelson/features_config/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/main/stasis_message_router.c?view=diff&rev=390710&r1=390709&r2=390710
==============================================================================
--- team/mmichelson/features_config/main/stasis_message_router.c (original)
+++ team/mmichelson/features_config/main/stasis_message_router.c Thu Jun 6 15:19:00 2013
@@ -33,8 +33,6 @@
#include "asterisk/astobj2.h"
#include "asterisk/stasis_message_router.h"
-
-#define INITIAL_ROUTES_MAX 8
/*! \internal */
struct stasis_message_route {
@@ -54,36 +52,51 @@
route->message_type = NULL;
}
+static int route_hash(const void *obj, const int flags)
+{
+ const struct stasis_message_route *route = obj;
+ const struct stasis_message_type *message_type = (flags & OBJ_KEY) ? obj : route->message_type;
+
+ return ast_str_hash(stasis_message_type_name(message_type));
+}
+
+static int route_cmp(void *obj, void *arg, int flags)
+{
+ const struct stasis_message_route *left = obj;
+ const struct stasis_message_route *right = arg;
+ const struct stasis_message_type *message_type = (flags & OBJ_KEY) ? arg : right->message_type;
+
+ return (left->message_type == message_type) ? CMP_MATCH | CMP_STOP : 0;
+}
+
/*! \internal */
struct stasis_message_router {
/*! Subscription to the upstream topic */
struct stasis_subscription *subscription;
- /*! Variable length array of the routes */
- struct stasis_message_route **routes;
+ /*! Subscribed routes */
+ struct ao2_container *routes;
/*! Route of last resort */
struct stasis_message_route *default_route;
- /*! Allocated length of the routes array */
- size_t num_routes_max;
- /*! Current size of the routes array */
- size_t num_routes_current;
};
static void router_dtor(void *obj)
{
struct stasis_message_router *router = obj;
- size_t i;
ast_assert(!stasis_subscription_is_subscribed(router->subscription));
ast_assert(stasis_subscription_is_done(router->subscription));
router->subscription = NULL;
- for (i = 0; i < router->num_routes_current; ++i) {
- ao2_cleanup(router->routes[i]);
- router->routes[i] = NULL;
- }
- ast_free(router->routes);
+
+ ao2_cleanup(router->routes);
router->routes = NULL;
+
ao2_cleanup(router->default_route);
router->default_route = NULL;
+}
+
+static struct stasis_message_route *find_route(struct stasis_message_router *router, struct stasis_message_type *message_type)
+{
+ return ao2_find(router->routes, message_type, OBJ_KEY);
}
static void router_dispatch(void *data,
@@ -95,28 +108,14 @@
RAII_VAR(struct stasis_message_router *, router_needs_cleanup, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message_route *, route, NULL, ao2_cleanup);
struct stasis_message_type *type = stasis_message_type(message);
- size_t i;
{
SCOPED_AO2LOCK(lock, router);
- /* We don't expect many message types, so a simple loop should
- * be adequate, even if the complexity is O(n). Sorting the list
- * would be an easy way to bring that down to O(log(n)). Using a
- * hashtable/ao2_container could be even better. Just be sure to
- * profile before you optimize!
- */
- route = router->default_route;
- for (i = 0; i < router->num_routes_current; ++i) {
- if (router->routes[i]->message_type == type) {
- route = router->routes[i];
- break;
+ if (!(route = find_route(router, type))) {
+ if ((route = router->default_route)) {
+ ao2_ref(route, +1);
}
- }
-
- /* Ref the route before leaving the scoped lock */
- if (route) {
- ao2_ref(route, +1);
}
}
@@ -141,10 +140,7 @@
return NULL;
}
- router->num_routes_max = INITIAL_ROUTES_MAX;
- router->routes = ast_calloc(router->num_routes_max,
- sizeof(*router->routes));
- if (!router->routes) {
+ if (!(router->routes = ao2_container_alloc(7, route_hash, route_cmp))) {
return NULL;
}
@@ -212,31 +208,14 @@
static int add_route(struct stasis_message_router *router,
struct stasis_message_route *route)
{
- struct stasis_message_route **routes;
- size_t i;
SCOPED_AO2LOCK(lock, router);
-
- /* Check for route conflicts */
- for (i = 0; i < router->num_routes_current; ++i) {
- if (router->routes[i]->message_type == route->message_type) {
- return -1;
- }
- }
-
- /* Increase list size, if needed */
- if (router->num_routes_current + 1 > router->num_routes_max) {
- routes = realloc(router->routes,
- 2 * router->num_routes_max * sizeof(*routes));
- if (!routes) {
- return -1;
- }
- router->routes = routes;
- router->num_routes_max *= 2;
- }
-
-
- ao2_ref(route, +1);
- router->routes[router->num_routes_current++] = route;
+ RAII_VAR(struct stasis_message_route *, existing_route, NULL, ao2_cleanup);
+
+ if ((existing_route = find_route(router, route->message_type))) {
+ return -1;
+ }
+
+ ao2_link(router->routes, route);
return 0;
}
@@ -255,6 +234,14 @@
return add_route(router, route);
}
+void stasis_message_router_remove(struct stasis_message_router *router,
+ struct stasis_message_type *message_type)
+{
+ SCOPED_AO2LOCK(lock, router);
+
+ ao2_find(router->routes, message_type, OBJ_UNLINK | OBJ_NODATA | OBJ_KEY);
+}
+
int stasis_message_router_set_default(struct stasis_message_router *router,
stasis_subscription_cb callback,
void *data)
Modified: team/mmichelson/features_config/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/res/res_agi.c?view=diff&rev=390710&r1=390709&r2=390710
==============================================================================
--- team/mmichelson/features_config/res/res_agi.c (original)
+++ team/mmichelson/features_config/res/res_agi.c Thu Jun 6 15:19:00 2013
@@ -66,6 +66,8 @@
#include "asterisk/srv.h"
#include "asterisk/test.h"
#include "asterisk/netsock2.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_message_router.h"
#define AST_API_MODULE
#include "asterisk/agi.h"
@@ -928,6 +930,68 @@
<para>Add an AGI command to the execute queue of the channel in Async AGI.</para>
</description>
</manager>
+ <managerEvent language="en_US" name="AsyncAGIStart">
+ <managerEventInstance class="EVENT_FLAG_AGI">
+ <synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Env">
+ <para>URL encoded string read from the AsyncAGI server.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="AsyncAGIEnd">
+ <managerEventInstance class="EVENT_FLAG_AGI">
+ <synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="AsyncAGIExec">
+ <managerEventInstance class="EVENT_FLAG_AGI">
+ <synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="CommandID" required="false">
+ <para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
+ </parameter>
+ <parameter name="Result">
+ <para>URL encoded result string from the executed AGI command.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="AGIExecStart">
+ <managerEventInstance class="EVENT_FLAG_AGI">
+ <synopsis>Raised when a received AGI command starts processing.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Command">
+ <para>The AGI command as received from the external source.</para>
+ </parameter>
+ <parameter name="CommandId">
+ <para>Random identification number assigned to the execution of this command.</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="AGIExecEnd">
+ <managerEventInstance class="EVENT_FLAG_AGI">
+ <synopsis>Raised when a received AGI command completes processing.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter)" />
+ <parameter name="ResultCode">
+ <para>The numeric result code from AGI</para>
+ </parameter
+ <parameter name="Result">
+ <para>The text result reason from AGI</para>
+ </parameter
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
***/
#define MAX_ARGS 128
@@ -962,6 +1026,44 @@
AGI_RESULT_NOTFOUND,
AGI_RESULT_HANGUP,
};
+
+struct stasis_message_type *agi_exec_start_type(void);
+struct stasis_message_type *agi_exec_end_type(void);
+struct stasis_message_type *agi_async_start_type(void);
+struct stasis_message_type *agi_async_exec_type(void);
+struct stasis_message_type *agi_async_end_type(void);
+
+STASIS_MESSAGE_TYPE_DEFN(agi_exec_start_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_exec_end_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_start_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_exec_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_end_type);
+
+static void agi_channel_manager_event(void *data,
+ struct stasis_subscription *sub, struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ const char *type = data;
+ struct ast_channel_blob *obj = stasis_message_data(message);
+ RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+ RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
+
+ channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+ if (!channel_event_string) {
+ return;
+ }
+
+ event_string = ast_manager_str_from_json_object(obj->blob, NULL);
+ if (!event_string) {
+ return;
+ }
+
+ manager_event(EVENT_FLAG_AGI, type,
+ "%s"
+ "%s",
+ ast_str_buffer(channel_event_string),
+ ast_str_buffer(event_string));
+}
static agi_command *find_command(const char * const cmds[], int exact);
@@ -1300,6 +1402,7 @@
char ami_buffer[AMI_BUF_SIZE];
enum agi_result returnstatus = AGI_RESULT_SUCCESS;
AGI async_agi;
+ RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
if (efd) {
ast_log(LOG_WARNING, "Async AGI does not support Enhanced AGI yet\n");
@@ -1349,32 +1452,9 @@
care of AGI commands on this channel can decide which AGI commands
to execute based on the setup info */
ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
- <syntax>
- <parameter name="SubEvent">
- <para>A sub event type, specifying the channel AsyncAGI processing status.</para>
- <enumlist>
- <enum name="Start"/>
- <enum name="Exec"/>
- <enum name="End"/>
- </enumlist>
- </parameter>
- <parameter name="Env">
- <para>URL encoded string read from the AsyncAGI server.</para>
- </parameter>
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGI, "AsyncAGI",
- "SubEvent: Start\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Env: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- ami_buffer);
+ startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
+ ast_channel_publish_blob(chan, agi_async_start_type(), startblob);
+
hungup = ast_check_hangup(chan);
for (;;) {
/*
@@ -1382,6 +1462,7 @@
* the manager or the cli threads.
*/
while (!hungup) {
+ RAII_VAR(struct ast_json *, execblob, NULL, ast_json_unref);
res = get_agi_cmd(chan, &cmd);
if (res) {
@@ -1413,40 +1494,13 @@
*/
agi_buffer[res] = '\0';
ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
- if (ast_strlen_zero(cmd->cmd_id)) {
- manager_event(EVENT_FLAG_AGI, "AsyncAGI",
- "SubEvent: Exec\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Result: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- ami_buffer);
- } else {
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
- <syntax>
- <parameter name="CommandID" required="false">
- <para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
- </parameter>
- <parameter name="Result">
- <para>URL encoded result string from the executed AGI command.</para>
- </parameter>
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGI, "AsyncAGI",
- "SubEvent: Exec\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "CommandID: %s\r\n"
- "Result: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- cmd->cmd_id,
- ami_buffer);
+
+ execblob = ast_json_pack("{s: s}", "Result", ami_buffer);
+ if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
+ ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
}
+ ast_channel_publish_blob(chan, agi_async_exec_type(), execblob);
+
free_agi_cmd(cmd);
/*
@@ -1505,17 +1559,7 @@
ast_speech_destroy(async_agi.speech);
}
/* notify manager users this channel cannot be controlled anymore by Async AGI */
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGI, "AsyncAGI",
- "SubEvent: End\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan));
+ ast_channel_publish_blob(chan, agi_async_end_type(), NULL);
async_agi_abort:
/* close the pipe */
@@ -3546,47 +3590,34 @@
return 0;
}
+static void publish_async_exec_end(struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
+{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ blob = ast_json_pack("{s: i, s: s, s: i, s: s}",
+ "CommandId", command_id,
+ "Command", command,
+ "ResultCode", result_code,
+ "Result", result);
+ ast_channel_publish_blob(chan, agi_exec_end_type(), blob);
+}
+
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
{
const char *argv[MAX_ARGS];
int argc = MAX_ARGS;
int res;
agi_command *c;
+ char *ami_cmd = ast_strdupa(buf);
const char *ami_res;
- char *ami_cmd = ast_strdupa(buf);
int command_id = ast_random();
- int resultcode;
-
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a received AGI command starts processing.</synopsis>
- <syntax>
- <parameter name="SubEvent">
- <para>A sub event type, specifying whether the AGI command has begun or ended.</para>
- <enumlist>
- <enum name="Start"/>
- <enum name="End"/>
- </enumlist>
- </parameter>
- <parameter name="CommandId">
- <para>Random identification number assigned to the execution of this command.</para>
- </parameter>
- <parameter name="Command">
- <para>The AGI command as received from the external source.</para>
- </parameter>
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGI, "AGIExec",
- "SubEvent: Start\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "CommandId: %d\r\n"
- "Command: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- command_id,
- ami_cmd);
+ int resultcode = 0;
+ RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
+
+ startblob = ast_json_pack("{s: i, s: s}",
+ "CommandId", command_id,
+ "Command", ami_cmd);
+ ast_channel_publish_blob(chan, agi_exec_start_type(), startblob);
+
parse_args(buf, &argc, argv);
c = find_command(argv, 0);
if (c && (!dead || (dead && c->dead))) {
@@ -3606,42 +3637,9 @@
case RESULT_SHOWUSAGE:
ami_res = "Usage";
resultcode = 520;
- break;
- case RESULT_FAILURE:
- ami_res = "Failure";
- resultcode = -1;
- break;
- case ASYNC_AGI_BREAK:
- case RESULT_SUCCESS:
- ami_res = "Success";
- resultcode = 200;
- break;
- default:
- ami_res = "Unknown Result";
- resultcode = 200;
- break;
- }
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a received AGI command completes processing.</synopsis>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_AGI, "AGIExec",
- "SubEvent: End\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "CommandId: %d\r\n"
- "Command: %s\r\n"
- "ResultCode: %d\r\n"
- "Result: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- command_id,
- ami_cmd,
- resultcode,
- ami_res);
- switch (res) {
- case RESULT_SHOWUSAGE:
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
if (ast_strlen_zero(c->usage)) {
ast_agi_send(agi->fd, chan, "520 Invalid command syntax. Proper usage not available.\n");
} else {
@@ -3649,44 +3647,54 @@
ast_agi_send(agi->fd, chan, "%s", c->usage);
ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
}
+
break;
- case ASYNC_AGI_BREAK:
- return AGI_RESULT_SUCCESS_ASYNC;
case RESULT_FAILURE:
+ ami_res = "Failure";
+ resultcode = -1;
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
/* The RESULT_FAILURE code is usually because the channel hungup. */
return AGI_RESULT_FAILURE;
+ case ASYNC_AGI_BREAK:
+ ami_res = "Success";
+ resultcode = 200;
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+ return AGI_RESULT_SUCCESS_ASYNC;
+ case RESULT_SUCCESS:
+ ami_res = "Success";
+ resultcode = 200;
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+ break;
default:
+ ami_res = "Unknown Result";
+ resultcode = 200;
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
break;
}
} else if (c) {
- ast_agi_send(agi->fd, chan, "511 Command Not Permitted on a dead channel\n");
- manager_event(EVENT_FLAG_AGI, "AGIExec",
- "SubEvent: End\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "CommandId: %d\r\n"
- "Command: %s\r\n"
- "ResultCode: 511\r\n"
- "Result: Command not permitted on a dead channel\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- command_id,
- ami_cmd);
+ ami_res = "Command Not Permitted on a dead channel";
+ resultcode = 511;
+
+ ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
} else {
- ast_agi_send(agi->fd, chan, "510 Invalid or unknown command\n");
- manager_event(EVENT_FLAG_AGI, "AGIExec",
- "SubEvent: End\r\n"
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "CommandId: %d\r\n"
- "Command: %s\r\n"
- "ResultCode: 510\r\n"
- "Result: Invalid or unknown command\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- command_id,
- ami_cmd);
- }
+ ami_res = "Invalid or unknown command";
+ resultcode = 510;
+
+ ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+ publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+ }
+
return AGI_RESULT_SUCCESS;
}
static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
@@ -4228,6 +4236,23 @@
static int unload_module(void)
{
+ struct stasis_message_router *message_router;
+
+ message_router = ast_manager_get_message_router();
+ if (message_router) {
+ stasis_message_router_remove(message_router, agi_exec_start_type());
+ stasis_message_router_remove(message_router, agi_exec_end_type());
+ stasis_message_router_remove(message_router, agi_async_start_type());
+ stasis_message_router_remove(message_router, agi_async_exec_type());
+ stasis_message_router_remove(message_router, agi_async_end_type());
+ }
+
+ STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_start_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_end_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(agi_async_start_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(agi_async_exec_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(agi_async_end_type);
+
ast_cli_unregister_multiple(cli_agi, ARRAY_LEN(cli_agi));
/* we can safely ignore the result of ast_agi_unregister_multiple() here, since it cannot fail, as
we know that these commands were registered by this module and are still registered
@@ -4242,6 +4267,44 @@
static int load_module(void)
{
+ struct stasis_message_router *message_router;
+
+ message_router = ast_manager_get_message_router();
+ if (!message_router) {
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ STASIS_MESSAGE_TYPE_INIT(agi_exec_start_type);
+ STASIS_MESSAGE_TYPE_INIT(agi_exec_end_type);
+ STASIS_MESSAGE_TYPE_INIT(agi_async_start_type);
+ STASIS_MESSAGE_TYPE_INIT(agi_async_exec_type);
+ STASIS_MESSAGE_TYPE_INIT(agi_async_end_type);
+
+ stasis_message_router_add(message_router,
+ agi_exec_start_type(),
+ agi_channel_manager_event,
+ "AGIExecStart");
+
+ stasis_message_router_add(message_router,
+ agi_exec_end_type(),
+ agi_channel_manager_event,
+ "AGIExecEnd");
+
+ stasis_message_router_add(message_router,
+ agi_async_start_type(),
+ agi_channel_manager_event,
+ "AsyncAGIStart");
+
+ stasis_message_router_add(message_router,
+ agi_async_exec_type(),
+ agi_channel_manager_event,
+ "AsyncAGIExec");
+
+ stasis_message_router_add(message_router,
+ agi_async_end_type(),
+ agi_channel_manager_event,
+ "AsyncAGIEnd");
+
ast_cli_register_multiple(cli_agi, ARRAY_LEN(cli_agi));
/* we can safely ignore the result of ast_agi_register_multiple() here, since it cannot fail, as
no other commands have been registered yet
More information about the asterisk-commits
mailing list