37 #include "asterisk/stasis_channels.h"
44 static void publish_hangup_handler_message(
const char *action,
struct ast_channel *chan,
const char *handler)
50 "handler",
S_OR(handler,
""));
63 ast_channel_lock(chan);
64 handlers = ast_channel_hangup_handlers(chan);
66 ast_channel_unlock(chan);
77 handlers = ast_channel_hangup_handlers(chan);
83 publish_hangup_handler_message(
"run", chan, h_handler->
args);
84 ast_channel_unlock(chan);
89 ast_channel_lock(chan);
91 ast_channel_unlock(chan);
99 handlers = ast_channel_hangup_handlers(chan);
108 ast_channel_lock(chan);
111 handlers = ast_channel_hangup_handlers(chan);
116 ast_channel_unlock(chan);
124 ast_channel_lock(chan);
125 handlers = ast_channel_hangup_handlers(chan);
128 publish_hangup_handler_message(
"pop", chan, h_handler->
args);
130 ast_channel_unlock(chan);
142 const char *expanded_handler;
144 if (ast_strlen_zero(handler)) {
149 if (!expanded_handler) {
152 h_handler =
ast_malloc(
sizeof(*h_handler) + 1 + strlen(expanded_handler));
154 ast_free((
char *) expanded_handler);
157 strcpy(h_handler->
args, expanded_handler);
158 ast_free((
char *) expanded_handler);
160 ast_channel_lock(chan);
162 handlers = ast_channel_hangup_handlers(chan);
164 publish_hangup_handler_message(
"push", chan, h_handler->
args);
165 ast_channel_unlock(chan);
168 #define HANDLER_FORMAT "%-30s %s\n"
177 static void ast_pbx_hangup_handler_headers(
int fd)
179 ast_cli(fd, HANDLER_FORMAT,
"Channel",
"Handler");
190 static void ast_pbx_hangup_handler_show(
int fd,
struct ast_channel *chan)
196 ast_channel_lock(chan);
197 handlers = ast_channel_hangup_handlers(chan);
199 ast_cli(fd, HANDLER_FORMAT, first ? ast_channel_name(chan) :
"", h_handler->
args);
202 ast_channel_unlock(chan);
214 e->
command =
"core show hanguphandlers";
216 "Usage: core show hanguphandlers <channel>\n"
217 " Show hangup handlers of a specified channel.\n";
224 return CLI_SHOWUSAGE;
229 ast_cli(a->fd,
"Channel does not exist.\n");
233 ast_pbx_hangup_handler_headers(a->fd);
234 ast_pbx_hangup_handler_show(a->fd, chan);
251 e->
command =
"core show hanguphandlers all";
253 "Usage: core show hanguphandlers all\n"
254 " Show hangup handlers for all channels.\n";
261 return CLI_SHOWUSAGE;
269 ast_pbx_hangup_handler_headers(a->fd);
271 ast_pbx_hangup_handler_show(a->fd, chan);
283 static void unload_pbx_hangup_handler(
void)
int load_pbx_hangup_handler(void)
static char * handle_show_hangup_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
'show hanguphandlers ' CLI command implementation function...
Main Channel structure associated with a channel.
int ast_pbx_hangup_handler_pop(struct ast_channel *chan)
Pop the top of the channel hangup handler stack.
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
#define ast_channel_unref(c)
Decrease channel reference count.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
descriptor for a cli entry.
void ast_pbx_hangup_handler_destroy(struct ast_channel *chan)
Destroy the hangup handler container on a channel.
static char * handle_show_hangup_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
'show hanguphandlers all' CLI command implementation function...
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
int args
This gets set in ast_cli_register()
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Core PBX routines and definitions.
void ast_pbx_hangup_handler_push(struct ast_channel *chan, const char *handler)
Push the given hangup handler onto the channel hangup handler stack.
int ast_pbx_hangup_handler_run(struct ast_channel *chan)
Run all hangup handlers on the channel.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
struct stasis_message_type * ast_channel_hangup_handler_type(void)
Message type for hangup handler related actions.
Prototypes for public functions only of internal interest,.
void ast_pbx_hangup_handler_init(struct ast_channel *chan)
Init the hangup handler container on a channel.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Standard Command Line Interface.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
char * ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
Command completion for the list of active channels.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Abstract JSON element (object, array, string, int, ...).
void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message.
struct ast_channel_iterator * ast_channel_iterator_all_new(void)
Create a new channel iterator.
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...