Asterisk - The Open Source Telephony Project GIT-master-66c01d8
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 531 of file func_periodic_hook.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 531 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 505 of file func_periodic_hook.c.

507{
509
510 snprintf(args, sizeof(args), "%s,%s,%u",
511 context_name, beep_exten, interval);
512
513 if (hook_read(chan, NULL, args, beep_id, len)) {
514 ast_log(LOG_WARNING, "Failed to enable periodic beep.\n");
515 return -1;
516 }
517
518 return 0;
519}
#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 521 of file func_periodic_hook.c.

522{
523 return hook_write(chan, NULL, (char *) beep_id, "off");
524}
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 531 of file func_periodic_hook.c.

◆ do_hook()

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

Definition at line 229 of file func_periodic_hook.c.

230{
231 pthread_t t;
232 struct hook_thread_arg *arg;
233 int res;
234
235 if (!(arg = hook_thread_arg_alloc(chan, state))) {
236 return -1;
237 }
238
239 /*
240 * We don't want to block normal frame processing *at all* while we kick
241 * this off, so do it in a new thread.
242 */
244 if (res != 0) {
246 }
247
248 return res;
249}
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 251 of file func_periodic_hook.c.

253{
254 struct hook_state *state = (struct hook_state *) audiohook; /* trust me. */
255 struct timeval now;
256 int res = 0;
257
258 if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE || state->disabled) {
259 return 0;
260 }
261
262 now = ast_tvnow();
263 if (ast_tvdiff_ms(now, state->last_hook) > state->interval * 1000) {
264 if ((res = do_hook(chan, state))) {
265 const char *name;
266 ast_channel_lock(chan);
268 ast_channel_unlock(chan);
269 ast_log(LOG_WARNING, "Failed to run hook on '%s'\n", name);
270 }
271 state->last_hook = now;
272 }
273
274 return res;
275}
#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:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
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 132 of file func_periodic_hook.c.

133{
134 struct hook_state *state = data;
135
136 ast_audiohook_lock(&state->audiohook);
137 ast_audiohook_detach(&state->audiohook);
138 ast_audiohook_unlock(&state->audiohook);
139 ast_audiohook_destroy(&state->audiohook);
140
141 ast_free(state->context);
142 ast_free(state->exten);
144}
#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 172 of file func_periodic_hook.c.

173{
174 struct hook_thread_arg *arg = data;
175 struct ast_variable hook_id = {
176 .name = "HOOK_ID",
177 .value = arg->hook_id,
178 };
179 struct ast_variable chan_name_var = {
180 .name = "HOOK_CHANNEL",
181 .value = arg->chan_name,
182 .next = &hook_id,
183 };
184
186 arg->context, arg->exten, 1, NULL, AST_OUTGOING_NO_WAIT,
187 NULL, NULL, &chan_name_var, NULL, NULL, 1, NULL);
188
190
191 return NULL;
192}
static const char full_exten_name[]
@ AST_OUTGOING_NO_WAIT
Definition: pbx.h:1141
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:7931
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 356 of file func_periodic_hook.c.

357{
358 struct ast_datastore *datastore;
359 struct hook_state *state;
360
362 return -1;
363 }
364
365 ast_channel_lock(chan);
366
367 if (!(datastore = ast_channel_datastore_find(chan, &hook_datastore, hook_id))) {
368 ast_log(LOG_WARNING, "Hook with ID '%s' not found on channel '%s'\n", hook_id,
369 ast_channel_name(chan));
370 ast_channel_unlock(chan);
371 return -1;
372 }
373
374 state = datastore->data;
375 state->disabled = 1;
376
377 ast_channel_unlock(chan);
378
379 return 0;
380}
enum cc_state state
Definition: ccss.c:399
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:2428
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 325 of file func_periodic_hook.c.

326{
327 char *parse = ast_strdupa(S_OR(data, ""));
330 AST_APP_ARG(exten);
331 AST_APP_ARG(interval);
332 );
333 unsigned int interval;
334
336
337 if (ast_strlen_zero(args.interval) ||
338 sscanf(args.interval, "%30u", &interval) != 1 || interval == 0) {
339 ast_log(LOG_WARNING, "Invalid hook interval: '%s'\n", S_OR(args.interval, ""));
340 return -1;
341 }
342
343 if (ast_strlen_zero(args.context) || ast_strlen_zero(args.exten)) {
344 ast_log(LOG_WARNING, "A context and extension are required for PERIODIC_HOOK().\n");
345 return -1;
346 }
347
348 ast_debug(1, "hook to %s@%s enabled on %s with interval of %u seconds\n",
349 args.exten, args.context, ast_channel_name(chan), interval);
350 ast_test_suite_event_notify("PERIODIC_HOOK_ENABLED", "Exten: %s\r\nChannel: %s\r\nInterval: %u\r\n",
351 args.exten, ast_channel_name(chan), interval);
352
353 return init_hook(chan, args.context, args.exten, interval, hook_id);
354}
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 398 of file func_periodic_hook.c.

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

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 382 of file func_periodic_hook.c.

384{
385 unsigned int hook_id;
386
387 if (!chan) {
388 return -1;
389 }
390
391 hook_id = (unsigned int) ast_atomic_fetchadd_int((int *) &global_hook_id, 1);
392
393 snprintf(buf, len, "%u", hook_id);
394
395 return hook_on(chan, data, hook_id);
396}
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:761

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 277 of file func_periodic_hook.c.

279{
280 struct hook_state *state;
281
282 if (!(state = ast_calloc(1, sizeof(*state)))) {
283 return NULL;
284 }
285
286 state->context = ast_strdup(context);
287 state->exten = ast_strdup(exten);
288 state->interval = interval;
289 state->hook_id = hook_id;
290
293 state->audiohook.manipulate_callback = hook_callback;
294
295 return state;
296}
#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 194 of file func_periodic_hook.c.

196{
197 struct hook_thread_arg *arg;
198
199 if (!(arg = ast_calloc(1, sizeof(*arg)))) {
200 return NULL;
201 }
202
203 ast_channel_lock(chan);
205 ast_channel_unlock(chan);
206 if (!arg->chan_name) {
208 return NULL;
209 }
210
211 if (ast_asprintf(&arg->hook_id, "%u", state->hook_id) == -1) {
213 return NULL;
214 }
215
216 if (!(arg->context = ast_strdup(state->context))) {
218 return NULL;
219 }
220
221 if (!(arg->exten = ast_strdup(state->exten))) {
223 return NULL;
224 }
225
226 return arg;
227}
#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 424 of file func_periodic_hook.c.

426{
427 int res;
428
429 if (!chan) {
430 return -1;
431 }
432
433 if (ast_false(value)) {
434 res = hook_off(chan, data);
435 } else if (ast_true(value)) {
436 res = hook_re_enable(chan, data);
437 } else {
438 ast_log(LOG_WARNING, "Invalid value for PERIODIC_HOOK function: '%s'\n", value);
439 res = -1;
440 }
441
442 return res;
443}
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 298 of file func_periodic_hook.c.

300{
301 struct hook_state *state;
302 struct ast_datastore *datastore;
303 char uid[32];
304
305 snprintf(uid, sizeof(uid), "%u", hook_id);
306
307 if (!(datastore = ast_datastore_alloc(&hook_datastore, uid))) {
308 return -1;
309 }
310
311 if (!(state = hook_state_alloc(context, exten, interval, hook_id))) {
312 ast_datastore_free(datastore);
313 return -1;
314 }
315 datastore->data = state;
316
317 ast_channel_lock(chan);
318 ast_channel_datastore_add(chan, datastore);
319 ast_audiohook_attach(chan, &state->audiohook);
320 ast_channel_unlock(chan);
321
322 return 0;
323}
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:2414
#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 459 of file func_periodic_hook.c.

460{
461 int res;
462
464 ast_log(LOG_ERROR, "Failed to create %s dialplan context.\n", context_name);
466 }
467
468 /*
469 * Based on a handy recipe from the Asterisk Cookbook.
470 */
471 res = ast_add_extension(context_name, 1, exten_name, 1, "", "",
472 "Set", "EncodedChannel=${HOOK_CHANNEL}",
474 res |= ast_add_extension(context_name, 1, exten_name, 2, "", "",
475 "Set", "GROUP_NAME=${EncodedChannel}${HOOK_ID}",
477 res |= ast_add_extension(context_name, 1, exten_name, 3, "", "",
478 "Set", "GROUP(periodic-hook)=${GROUP_NAME}",
480 res |= ast_add_extension(context_name, 1, exten_name, 4, "", "", "ExecIf",
481 "$[${GROUP_COUNT(${GROUP_NAME}@periodic-hook)} > 1]?Hangup()",
483 res |= ast_add_extension(context_name, 1, exten_name, 5, "", "",
484 "Set", "ChannelToSpy=${URIDECODE(${EncodedChannel})}",
486 res |= ast_add_extension(context_name, 1, exten_name, 6, "", "",
487 "ChanSpy", "${ChannelToSpy},qEB", NULL, AST_MODULE);
488
489 res |= ast_add_extension(context_name, 1, beep_exten, 1, "", "",
490 "Answer", "", NULL, AST_MODULE);
491 res |= ast_add_extension(context_name, 1, beep_exten, 2, "", "",
492 "Playback", "beep", NULL, AST_MODULE);
493 res |= ast_add_extension(context_name, 1, beep_exten, 3, "", "",
494 "Hangup", "", NULL, AST_MODULE);
495
497
498 if (res) {
501 }
503}
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:6943
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:6164
#define ast_custom_function_register_escalating(acf, escalation)
Register a custom function which requires escalated privileges.
Definition: pbx.h:1568
@ AST_CFE_BOTH
Definition: pbx.h:1553

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 451 of file func_periodic_hook.c.

452{
454
456 return 0;
457}
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:8236
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 531 of file func_periodic_hook.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 531 of file func_periodic_hook.c.

◆ beep_exten

const char beep_exten[] = "beep"
static

Definition at line 100 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 98 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 108 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 146 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 445 of file func_periodic_hook.c.

Referenced by load_module(), and unload_module().