Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Functions | Variables
func_periodic_hook.c File Reference

Periodic dialplan hooks. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/audiohook.h"
#include "asterisk/test.h"
#include "asterisk/beep.h"
Include dependency graph for func_periodic_hook.c:

Go to the source code of this file.

Data Structures

struct  hook_state
 
struct  hook_thread_arg
 

Macros

#define AST_API_MODULE
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
int AST_OPTIONAL_API_NAME() ast_beep_start (struct ast_channel *chan, unsigned int interval, char *beep_id, size_t len)
 
int AST_OPTIONAL_API_NAME() ast_beep_stop (struct ast_channel *chan, const char *beep_id)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int do_hook (struct ast_channel *chan, struct hook_state *state)
 
static int hook_callback (struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
 
static void hook_datastore_destroy_callback (void *data)
 
static void * hook_launch_thread (void *data)
 
static int hook_off (struct ast_channel *chan, const char *hook_id)
 
static int hook_on (struct ast_channel *chan, const char *data, unsigned int hook_id)
 
static int hook_re_enable (struct ast_channel *chan, const char *uid)
 
static int hook_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static struct hook_statehook_state_alloc (const char *context, const char *exten, unsigned int interval, unsigned int hook_id)
 
static struct hook_thread_arghook_thread_arg_alloc (struct ast_channel *chan, struct hook_state *state)
 
static void hook_thread_arg_destroy (struct hook_thread_arg *arg)
 
static int hook_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static int init_hook (struct ast_channel *chan, const char *context, const char *exten, unsigned int interval, unsigned int hook_id)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "Periodic dialplan hooks." , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "app_chanspy,func_cut,func_groupcount,func_uri", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const char beep_exten [] = "beep"
 
static const char context_name [] = "__func_periodic_hook_context__"
 
static const char exten_name [] = "hook"
 
static const char full_exten_name [] = "hook@__func_periodic_hook_context__"
 
static unsigned int global_hook_id
 Last used hook ID. More...
 
static const struct ast_datastore_info hook_datastore
 
static struct ast_custom_function hook_function
 

Detailed Description

Periodic dialplan hooks.

Author
Russell Bryant russe.nosp@m.ll@r.nosp@m.ussel.nosp@m.lbry.nosp@m.ant.n.nosp@m.et

Definition in file func_periodic_hook.c.

Macro Definition Documentation

◆ AST_API_MODULE

#define AST_API_MODULE

Definition at line 44 of file func_periodic_hook.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 528 of file func_periodic_hook.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 528 of file func_periodic_hook.c.

◆ ast_beep_start()

int AST_OPTIONAL_API_NAME() ast_beep_start ( struct ast_channel chan,
unsigned int  interval,
char *  beep_id,
size_t  len 
)

Definition at line 502 of file func_periodic_hook.c.

504{
506
507 snprintf(args, sizeof(args), "%s,%s,%u",
508 context_name, beep_exten, interval);
509
510 if (hook_read(chan, NULL, args, beep_id, len)) {
511 ast_log(LOG_WARNING, "Failed to enable periodic beep.\n");
512 return -1;
513 }
514
515 return 0;
516}
#define ast_log
Definition: astobj2.c:42
#define AST_MAX_CONTEXT
Definition: channel.h:135
#define AST_MAX_EXTENSION
Definition: channel.h:134
static int hook_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static const char context_name[]
static const char beep_exten[]
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define LOG_WARNING
#define NULL
Definition: resample.c:96
const char * args

References args, ast_log, AST_MAX_CONTEXT, AST_MAX_EXTENSION, beep_exten, context_name, hook_read(), len(), LOG_WARNING, and NULL.

Referenced by mixmonitor_exec().

◆ ast_beep_stop()

int AST_OPTIONAL_API_NAME() ast_beep_stop ( struct ast_channel chan,
const char *  beep_id 
)

Definition at line 518 of file func_periodic_hook.c.

519{
520 return hook_write(chan, NULL, (char *) beep_id, "off");
521}
static int hook_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)

References hook_write(), and NULL.

Referenced by stop_mixmonitor_full().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 528 of file func_periodic_hook.c.

◆ do_hook()

static int do_hook ( struct ast_channel chan,
struct hook_state state 
)
static

Definition at line 226 of file func_periodic_hook.c.

227{
228 pthread_t t;
229 struct hook_thread_arg *arg;
230 int res;
231
232 if (!(arg = hook_thread_arg_alloc(chan, state))) {
233 return -1;
234 }
235
236 /*
237 * We don't want to block normal frame processing *at all* while we kick
238 * this off, so do it in a new thread.
239 */
241 if (res != 0) {
243 }
244
245 return res;
246}
static void * hook_launch_thread(void *data)
static void hook_thread_arg_destroy(struct hook_thread_arg *arg)
static struct hook_thread_arg * hook_thread_arg_alloc(struct ast_channel *chan, struct hook_state *state)
#define ast_pthread_create_detached_background(a, b, c, d)
Definition: utils.h:597

References ast_pthread_create_detached_background, hook_launch_thread(), hook_thread_arg_alloc(), hook_thread_arg_destroy(), and NULL.

Referenced by hook_callback().

◆ hook_callback()

static int hook_callback ( struct ast_audiohook audiohook,
struct ast_channel chan,
struct ast_frame frame,
enum ast_audiohook_direction  direction 
)
static

Definition at line 248 of file func_periodic_hook.c.

250{
251 struct hook_state *state = (struct hook_state *) audiohook; /* trust me. */
252 struct timeval now;
253 int res = 0;
254
255 if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE || state->disabled) {
256 return 0;
257 }
258
259 now = ast_tvnow();
260 if (ast_tvdiff_ms(now, state->last_hook) > state->interval * 1000) {
261 if ((res = do_hook(chan, state))) {
262 const char *name;
263 ast_channel_lock(chan);
265 ast_channel_unlock(chan);
266 ast_log(LOG_WARNING, "Failed to run hook on '%s'\n", name);
267 }
268 state->last_hook = now;
269 }
270
271 return res;
272}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
@ AST_AUDIOHOOK_STATUS_DONE
Definition: audiohook.h:45
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2968
#define ast_channel_unlock(chan)
Definition: channel.h:2969
static const char name[]
Definition: format_mp3.c:68
static int do_hook(struct ast_channel *chan, struct hook_state *state)
enum ast_audiohook_status status
Definition: audiohook.h:108
struct ast_audiohook audiohook
audiohook used as a callback into this module
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References AST_AUDIOHOOK_STATUS_DONE, ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_log, ast_strdupa, ast_tvdiff_ms(), ast_tvnow(), hook_state::audiohook, do_hook(), LOG_WARNING, name, and ast_audiohook::status.

Referenced by hook_state_alloc().

◆ hook_datastore_destroy_callback()

static void hook_datastore_destroy_callback ( void *  data)
static

Definition at line 129 of file func_periodic_hook.c.

130{
131 struct hook_state *state = data;
132
133 ast_audiohook_lock(&state->audiohook);
134 ast_audiohook_detach(&state->audiohook);
135 ast_audiohook_unlock(&state->audiohook);
136 ast_audiohook_destroy(&state->audiohook);
137
138 ast_free(state->context);
139 ast_free(state->exten);
141}
#define ast_free(a)
Definition: astmm.h:180
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition: audiohook.h:313
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Definition: audiohook.c:578
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
Definition: audiohook.c:124
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition: audiohook.h:318

References ast_audiohook_destroy(), ast_audiohook_detach(), ast_audiohook_lock, ast_audiohook_unlock, and ast_free.

◆ hook_launch_thread()

static void * hook_launch_thread ( void *  data)
static

Definition at line 169 of file func_periodic_hook.c.

170{
171 struct hook_thread_arg *arg = data;
172 struct ast_variable hook_id = {
173 .name = "HOOK_ID",
174 .value = arg->hook_id,
175 };
176 struct ast_variable chan_name_var = {
177 .name = "HOOK_CHANNEL",
178 .value = arg->chan_name,
179 .next = &hook_id,
180 };
181
183 arg->context, arg->exten, 1, NULL, AST_OUTGOING_NO_WAIT,
184 NULL, NULL, &chan_name_var, NULL, NULL, 1, NULL);
185
187
188 return NULL;
189}
static const char full_exten_name[]
@ AST_OUTGOING_NO_WAIT
Definition: pbx.h:1140
int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media, const struct ast_assigned_ids *assignedids)
Synchronously or asynchronously make an outbound call and send it to a particular extension.
Definition: pbx.c:7916
Structure for variables, used for configurations and for channel variables.

References AST_OUTGOING_NO_WAIT, ast_pbx_outgoing_exten(), hook_thread_arg::chan_name, hook_thread_arg::context, hook_thread_arg::exten, full_exten_name, hook_thread_arg::hook_id, hook_thread_arg_destroy(), ast_variable::name, and NULL.

Referenced by do_hook().

◆ hook_off()

static int hook_off ( struct ast_channel chan,
const char *  hook_id 
)
static

Definition at line 353 of file func_periodic_hook.c.

354{
355 struct ast_datastore *datastore;
356 struct hook_state *state;
357
359 return -1;
360 }
361
362 ast_channel_lock(chan);
363
364 if (!(datastore = ast_channel_datastore_find(chan, &hook_datastore, hook_id))) {
365 ast_log(LOG_WARNING, "Hook with ID '%s' not found on channel '%s'\n", hook_id,
366 ast_channel_name(chan));
367 ast_channel_unlock(chan);
368 return -1;
369 }
370
371 state = datastore->data;
372 state->disabled = 1;
373
374 ast_channel_unlock(chan);
375
376 return 0;
377}
enum cc_state state
Definition: ccss.c:393
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2418
static const struct ast_datastore_info hook_datastore
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
unsigned int hook_id

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_log, ast_strlen_zero(), ast_datastore::data, hook_datastore, hook_state::hook_id, LOG_WARNING, and state.

Referenced by hook_write().

◆ hook_on()

static int hook_on ( struct ast_channel chan,
const char *  data,
unsigned int  hook_id 
)
static

Definition at line 322 of file func_periodic_hook.c.

323{
324 char *parse = ast_strdupa(S_OR(data, ""));
327 AST_APP_ARG(exten);
328 AST_APP_ARG(interval);
329 );
330 unsigned int interval;
331
333
334 if (ast_strlen_zero(args.interval) ||
335 sscanf(args.interval, "%30u", &interval) != 1 || interval == 0) {
336 ast_log(LOG_WARNING, "Invalid hook interval: '%s'\n", S_OR(args.interval, ""));
337 return -1;
338 }
339
340 if (ast_strlen_zero(args.context) || ast_strlen_zero(args.exten)) {
341 ast_log(LOG_WARNING, "A context and extension are required for PERIODIC_HOOK().\n");
342 return -1;
343 }
344
345 ast_debug(1, "hook to %s@%s enabled on %s with interval of %u seconds\n",
346 args.exten, args.context, ast_channel_name(chan), interval);
347 ast_test_suite_event_notify("PERIODIC_HOOK_ENABLED", "Exten: %s\r\nChannel: %s\r\nInterval: %u\r\n",
348 args.exten, ast_channel_name(chan), interval);
349
350 return init_hook(chan, args.context, args.exten, interval, hook_id);
351}
static int init_hook(struct ast_channel *chan, const char *context, const char *exten, unsigned int interval, unsigned int hook_id)
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define ast_debug(level,...)
Log a DEBUG message.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189

References args, AST_APP_ARG, ast_channel_name(), ast_debug, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_suite_event_notify, voicemailpwcheck::context, ast_datastore::data, init_hook(), LOG_WARNING, and S_OR.

Referenced by hook_read().

◆ hook_re_enable()

static int hook_re_enable ( struct ast_channel chan,
const char *  uid 
)
static

Definition at line 395 of file func_periodic_hook.c.

396{
397 struct ast_datastore *datastore;
398 struct hook_state *state;
399
400 if (ast_strlen_zero(uid)) {
401 return -1;
402 }
403
404 ast_channel_lock(chan);
405
406 if (!(datastore = ast_channel_datastore_find(chan, &hook_datastore, uid))) {
407 ast_log(LOG_WARNING, "Hook with ID '%s' not found on '%s'\n",
408 uid, ast_channel_name(chan));
409 ast_channel_unlock(chan);
410 return -1;
411 }
412
413 state = datastore->data;
414 state->disabled = 0;
415
416 ast_channel_unlock(chan);
417
418 return 0;
419}

References ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_log, ast_strlen_zero(), ast_datastore::data, hook_datastore, LOG_WARNING, and state.

Referenced by hook_write().

◆ hook_read()

static int hook_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 379 of file func_periodic_hook.c.

381{
382 unsigned int hook_id;
383
384 if (!chan) {
385 return -1;
386 }
387
388 hook_id = (unsigned int) ast_atomic_fetchadd_int((int *) &global_hook_id, 1);
389
390 snprintf(buf, len, "%u", hook_id);
391
392 return hook_on(chan, data, hook_id);
393}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static unsigned int global_hook_id
Last used hook ID.
static int hook_on(struct ast_channel *chan, const char *data, unsigned int hook_id)
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:757

References ast_atomic_fetchadd_int(), buf, global_hook_id, hook_state::hook_id, hook_on(), and len().

Referenced by ast_beep_start().

◆ hook_state_alloc()

static struct hook_state * hook_state_alloc ( const char *  context,
const char *  exten,
unsigned int  interval,
unsigned int  hook_id 
)
static

Definition at line 274 of file func_periodic_hook.c.

276{
277 struct hook_state *state;
278
279 if (!(state = ast_calloc(1, sizeof(*state)))) {
280 return NULL;
281 }
282
283 state->context = ast_strdup(context);
284 state->exten = ast_strdup(exten);
285 state->interval = interval;
286 state->hook_id = hook_id;
287
290 state->audiohook.manipulate_callback = hook_callback;
291
292 return state;
293}
#define AST_MODULE
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
@ AST_AUDIOHOOK_MANIPULATE_ALL_RATES
Definition: audiohook.h:75
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
Initialize an audiohook structure.
Definition: audiohook.c:100
@ AST_AUDIOHOOK_TYPE_MANIPULATE
Definition: audiohook.h:38
static int hook_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
unsigned int interval

References ast_audiohook_init(), AST_AUDIOHOOK_MANIPULATE_ALL_RATES, AST_AUDIOHOOK_TYPE_MANIPULATE, ast_calloc, AST_MODULE, ast_strdup, voicemailpwcheck::context, hook_state::exten, hook_callback(), hook_state::hook_id, hook_state::interval, NULL, and state.

Referenced by init_hook().

◆ hook_thread_arg_alloc()

static struct hook_thread_arg * hook_thread_arg_alloc ( struct ast_channel chan,
struct hook_state state 
)
static

Definition at line 191 of file func_periodic_hook.c.

193{
194 struct hook_thread_arg *arg;
195
196 if (!(arg = ast_calloc(1, sizeof(*arg)))) {
197 return NULL;
198 }
199
200 ast_channel_lock(chan);
202 ast_channel_unlock(chan);
203 if (!arg->chan_name) {
205 return NULL;
206 }
207
208 if (ast_asprintf(&arg->hook_id, "%u", state->hook_id) == -1) {
210 return NULL;
211 }
212
213 if (!(arg->context = ast_strdup(state->context))) {
215 return NULL;
216 }
217
218 if (!(arg->exten = ast_strdup(state->exten))) {
220 return NULL;
221 }
222
223 return arg;
224}
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267

References ast_asprintf, ast_calloc, ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_strdup, hook_thread_arg::chan_name, hook_thread_arg::context, hook_thread_arg::exten, hook_thread_arg::hook_id, hook_thread_arg_destroy(), and NULL.

Referenced by do_hook().

◆ hook_thread_arg_destroy()

static void hook_thread_arg_destroy ( struct hook_thread_arg arg)
static

◆ hook_write()

static int hook_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 421 of file func_periodic_hook.c.

423{
424 int res;
425
426 if (!chan) {
427 return -1;
428 }
429
430 if (ast_false(value)) {
431 res = hook_off(chan, data);
432 } else if (ast_true(value)) {
433 res = hook_re_enable(chan, data);
434 } else {
435 ast_log(LOG_WARNING, "Invalid value for PERIODIC_HOOK function: '%s'\n", value);
436 res = -1;
437 }
438
439 return res;
440}
static int hook_re_enable(struct ast_channel *chan, const char *uid)
static int hook_off(struct ast_channel *chan, const char *hook_id)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
int attribute_pure ast_false(const char *val)
Make sure something is false. Determine if a string containing a boolean value is "false"....
Definition: utils.c:2216
int value
Definition: syslog.c:37

References ast_false(), ast_log, ast_true(), hook_off(), hook_re_enable(), LOG_WARNING, and value.

Referenced by ast_beep_stop().

◆ init_hook()

static int init_hook ( struct ast_channel chan,
const char *  context,
const char *  exten,
unsigned int  interval,
unsigned int  hook_id 
)
static

Definition at line 295 of file func_periodic_hook.c.

297{
298 struct hook_state *state;
299 struct ast_datastore *datastore;
300 char uid[32];
301
302 snprintf(uid, sizeof(uid), "%u", hook_id);
303
304 if (!(datastore = ast_datastore_alloc(&hook_datastore, uid))) {
305 return -1;
306 }
307
308 if (!(state = hook_state_alloc(context, exten, interval, hook_id))) {
309 ast_datastore_free(datastore);
310 return -1;
311 }
312 datastore->data = state;
313
314 ast_channel_lock(chan);
315 ast_channel_datastore_add(chan, datastore);
316 ast_audiohook_attach(chan, &state->audiohook);
317 ast_channel_unlock(chan);
318
319 return 0;
320}
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition: audiohook.c:512
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2404
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static struct hook_state * hook_state_alloc(const char *context, const char *exten, unsigned int interval, unsigned int hook_id)
const char * uid
Definition: datastore.h:65

References ast_audiohook_attach(), ast_channel_datastore_add(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), voicemailpwcheck::context, ast_datastore::data, hook_datastore, hook_state_alloc(), state, and ast_datastore::uid.

Referenced by hook_on().

◆ load_module()

static int load_module ( void  )
static

Definition at line 456 of file func_periodic_hook.c.

457{
458 int res;
459
461 ast_log(LOG_ERROR, "Failed to create %s dialplan context.\n", context_name);
463 }
464
465 /*
466 * Based on a handy recipe from the Asterisk Cookbook.
467 */
468 res = ast_add_extension(context_name, 1, exten_name, 1, "", "",
469 "Set", "EncodedChannel=${HOOK_CHANNEL}",
471 res |= ast_add_extension(context_name, 1, exten_name, 2, "", "",
472 "Set", "GROUP_NAME=${EncodedChannel}${HOOK_ID}",
474 res |= ast_add_extension(context_name, 1, exten_name, 3, "", "",
475 "Set", "GROUP(periodic-hook)=${GROUP_NAME}",
477 res |= ast_add_extension(context_name, 1, exten_name, 4, "", "", "ExecIf",
478 "$[${GROUP_COUNT(${GROUP_NAME}@periodic-hook)} > 1]?Hangup()",
480 res |= ast_add_extension(context_name, 1, exten_name, 5, "", "",
481 "Set", "ChannelToSpy=${URIDECODE(${EncodedChannel})}",
483 res |= ast_add_extension(context_name, 1, exten_name, 6, "", "",
484 "ChanSpy", "${ChannelToSpy},qEB", NULL, AST_MODULE);
485
486 res |= ast_add_extension(context_name, 1, beep_exten, 1, "", "",
487 "Answer", "", NULL, AST_MODULE);
488 res |= ast_add_extension(context_name, 1, beep_exten, 2, "", "",
489 "Playback", "beep", NULL, AST_MODULE);
490 res |= ast_add_extension(context_name, 1, beep_exten, 3, "", "",
491 "Hangup", "", NULL, AST_MODULE);
492
494
495 if (res) {
498 }
500}
static const char exten_name[]
static struct ast_custom_function hook_function
static int unload_module(void)
#define LOG_ERROR
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition: pbx.c:6928
struct ast_context * ast_context_find_or_create(struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
Register a new context or find an existing one.
Definition: pbx.c:6149
#define ast_custom_function_register_escalating(acf, escalation)
Register a custom function which requires escalated privileges.
Definition: pbx.h:1567
@ AST_CFE_BOTH
Definition: pbx.h:1552

References ast_add_extension(), AST_CFE_BOTH, ast_context_find_or_create(), ast_custom_function_register_escalating, ast_log, AST_MODULE, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, beep_exten, context_name, exten_name, hook_function, LOG_ERROR, NULL, and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 448 of file func_periodic_hook.c.

449{
451
453 return 0;
454}
void ast_context_destroy(struct ast_context *con, const char *registrar)
Destroy a context (matches the specified context or ANY context if NULL)
Definition: pbx.c:8221
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_context_destroy(), ast_custom_function_unregister(), AST_MODULE, hook_function, and NULL.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "Periodic dialplan hooks." , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "app_chanspy,func_cut,func_groupcount,func_uri", }
static

Definition at line 528 of file func_periodic_hook.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 528 of file func_periodic_hook.c.

◆ beep_exten

const char beep_exten[] = "beep"
static

Definition at line 97 of file func_periodic_hook.c.

Referenced by ast_beep_start(), and load_module().

◆ context_name

const char context_name[] = "__func_periodic_hook_context__"
static

◆ exten_name

const char exten_name[] = "hook"
static

◆ full_exten_name

const char full_exten_name[] = "hook@__func_periodic_hook_context__"
static

Definition at line 95 of file func_periodic_hook.c.

Referenced by hook_launch_thread().

◆ global_hook_id

unsigned int global_hook_id
static

Last used hook ID.

This is incremented each time a hook is created to give each hook a unique ID.

Definition at line 105 of file func_periodic_hook.c.

Referenced by hook_read().

◆ hook_datastore

const struct ast_datastore_info hook_datastore
static
Initial value:
= {
.type = AST_MODULE,
}
static void hook_datastore_destroy_callback(void *data)

Definition at line 143 of file func_periodic_hook.c.

Referenced by hook_off(), hook_re_enable(), and init_hook().

◆ hook_function

struct ast_custom_function hook_function
static
Initial value:
= {
.name = "PERIODIC_HOOK",
.read = hook_read,
.write = hook_write,
}

Definition at line 442 of file func_periodic_hook.c.

Referenced by load_module(), and unload_module().