Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
pbx_hangup_handler.c File Reference

PBX Hangup Handler management routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/app.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/utils.h"

Go to the source code of this file.

Macros

#define HANDLER_FORMAT   "%-30s %s\n"
 

Functions

void ast_pbx_hangup_handler_destroy (struct ast_channel *chan)
 Destroy the hangup handler container on a channel. More...
 
static void ast_pbx_hangup_handler_headers (int fd)
 
void ast_pbx_hangup_handler_init (struct ast_channel *chan)
 Init the hangup handler container on a channel. More...
 
int ast_pbx_hangup_handler_pop (struct ast_channel *chan)
 Pop the top of the channel hangup handler stack. More...
 
void ast_pbx_hangup_handler_push (struct ast_channel *chan, const char *handler)
 Push the given hangup handler onto the channel hangup handler stack. More...
 
int ast_pbx_hangup_handler_run (struct ast_channel *chan)
 Run all hangup handlers on the channel. More...
 
static void ast_pbx_hangup_handler_show (int fd, struct ast_channel *chan)
 
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...
 
static char * handle_show_hangup_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 'show hanguphandlers <channel>' CLI command implementation function...
 
int load_pbx_hangup_handler (void)
 
static void publish_hangup_handler_message (const char *action, struct ast_channel *chan, const char *handler)
 
static void unload_pbx_hangup_handler (void)
 

Variables

static struct ast_cli_entry cli []
 

Detailed Description

PBX Hangup Handler management routines.

Author
Corey Farrell git@c.nosp@m.fwar.nosp@m.e.com

Definition in file pbx_hangup_handler.c.

Function Documentation

void ast_pbx_hangup_handler_destroy ( struct ast_channel chan)

Destroy the hangup handler container on a channel.

Since
11.0
Parameters
chanChannel to destroy the hangup handler container on.

Definition at line 103 of file pbx_hangup_handler.c.

References AST_LIST_REMOVE_HEAD.

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

104 {
105  struct ast_hangup_handler_list *handlers;
106  struct ast_hangup_handler *h_handler;
107 
108  ast_channel_lock(chan);
109 
110  /* Get rid of each of the hangup handlers on the channel */
111  handlers = ast_channel_hangup_handlers(chan);
112  while ((h_handler = AST_LIST_REMOVE_HEAD(handlers, node))) {
113  ast_free(h_handler);
114  }
115 
116  ast_channel_unlock(chan);
117 }
Definition: test_heap.c:38
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
void ast_pbx_hangup_handler_init ( struct ast_channel chan)

Init the hangup handler container on a channel.

Since
11.0
Parameters
chanChannel to init the hangup handler container on.

Definition at line 95 of file pbx_hangup_handler.c.

References AST_LIST_HEAD_INIT_NOLOCK.

Referenced by __ast_channel_alloc_ap().

96 {
97  struct ast_hangup_handler_list *handlers;
98 
99  handlers = ast_channel_hangup_handlers(chan);
100  AST_LIST_HEAD_INIT_NOLOCK(handlers);
101 }
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
int ast_pbx_hangup_handler_pop ( struct ast_channel chan)

Pop the top of the channel hangup handler stack.

Since
11.0
Parameters
chanChannel to push the hangup handler onto.
Return values
TRUEif a handler was popped off of the stack.

Definition at line 119 of file pbx_hangup_handler.c.

References ast_hangup_handler::args, and AST_LIST_REMOVE_HEAD.

120 {
121  struct ast_hangup_handler_list *handlers;
122  struct ast_hangup_handler *h_handler;
123 
124  ast_channel_lock(chan);
125  handlers = ast_channel_hangup_handlers(chan);
126  h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
127  if (h_handler) {
128  publish_hangup_handler_message("pop", chan, h_handler->args);
129  }
130  ast_channel_unlock(chan);
131  if (h_handler) {
132  ast_free(h_handler);
133  return 1;
134  }
135  return 0;
136 }
Definition: test_heap.c:38
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
void ast_pbx_hangup_handler_push ( struct ast_channel chan,
const char *  handler 
)

Push the given hangup handler onto the channel hangup handler stack.

Since
11.0
Parameters
chanChannel to push the hangup handler onto.
handlerGosub application parameter string.

Definition at line 138 of file pbx_hangup_handler.c.

References ast_hangup_handler::args, ast_app_expand_sub_args(), AST_LIST_INSERT_HEAD, and ast_malloc.

139 {
140  struct ast_hangup_handler_list *handlers;
141  struct ast_hangup_handler *h_handler;
142  const char *expanded_handler;
143 
144  if (ast_strlen_zero(handler)) {
145  return;
146  }
147 
148  expanded_handler = ast_app_expand_sub_args(chan, handler);
149  if (!expanded_handler) {
150  return;
151  }
152  h_handler = ast_malloc(sizeof(*h_handler) + 1 + strlen(expanded_handler));
153  if (!h_handler) {
154  ast_free((char *) expanded_handler);
155  return;
156  }
157  strcpy(h_handler->args, expanded_handler);/* Safe */
158  ast_free((char *) expanded_handler);
159 
160  ast_channel_lock(chan);
161 
162  handlers = ast_channel_hangup_handlers(chan);
163  AST_LIST_INSERT_HEAD(handlers, h_handler, node);
164  publish_hangup_handler_message("push", chan, h_handler->args);
165  ast_channel_unlock(chan);
166 }
Definition: test_heap.c:38
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:278
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
int ast_pbx_hangup_handler_run ( struct ast_channel chan)

Run all hangup handlers on the channel.

Since
11.0
Parameters
chanChannel to run the hangup handlers on.
Note
Absolutely NO channel locks should be held before calling this function.
Return values
Zeroif no hangup handlers run.
non-zeroif hangup handlers were run.

Definition at line 58 of file pbx_hangup_handler.c.

References ast_hangup_handler::args, ast_app_exec_sub(), AST_LIST_EMPTY, AST_LIST_REMOVE_HEAD, AST_SOFTHANGUP_HANGUP_EXEC, and ast_softhangup_nolock().

Referenced by __ast_pbx_run(), and ast_hangup().

59 {
60  struct ast_hangup_handler_list *handlers;
61  struct ast_hangup_handler *h_handler;
62 
63  ast_channel_lock(chan);
64  handlers = ast_channel_hangup_handlers(chan);
65  if (AST_LIST_EMPTY(handlers)) {
66  ast_channel_unlock(chan);
67  return 0;
68  }
69 
70  /*
71  * Make sure that the channel is marked as hungup since we are
72  * going to run the hangup handlers on it.
73  */
75 
76  for (;;) {
77  handlers = ast_channel_hangup_handlers(chan);
78  h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
79  if (!h_handler) {
80  break;
81  }
82 
83  publish_hangup_handler_message("run", chan, h_handler->args);
84  ast_channel_unlock(chan);
85 
86  ast_app_exec_sub(NULL, chan, h_handler->args, 1);
87  ast_free(h_handler);
88 
89  ast_channel_lock(chan);
90  }
91  ast_channel_unlock(chan);
92  return 1;
93 }
Definition: test_heap.c:38
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833
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.
Definition: main/app.c:297
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2458
int load_pbx_hangup_handler ( void  )

Provided by pbx_hangup_handler.c

Definition at line 288 of file pbx_hangup_handler.c.

References ast_cli_register_multiple, and ast_register_cleanup().

289 {
290  ast_cli_register_multiple(cli, ARRAY_LEN(cli));
291  ast_register_cleanup(unload_pbx_hangup_handler);
292 
293  return 0;
294 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19

Variable Documentation

struct ast_cli_entry cli[]
static
Initial value:
= {
{ .handler = handle_show_hangup_all , .summary = "Show hangup handlers of all channels" ,},
{ .handler = handle_show_hangup_channel , .summary = "Show hangup handlers of a specified channel" ,},
}
static char * handle_show_hangup_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
'show hanguphandlers ' CLI command implementation function...
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...

Definition at line 278 of file pbx_hangup_handler.c.