Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_celgenuserevent.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2008, Digium, Inc
5 *
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
11 *
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
15 */
16
17/*! \file
18 *
19 * \brief Generate User-Defined CEL event
20 *
21 * \author Steve Murphy
22 *
23 * \ingroup applications
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "asterisk/module.h"
33#include "asterisk/app.h"
34#include "asterisk/channel.h"
35#include "asterisk/cel.h"
36
37/*** DOCUMENTATION
38 <application name="CELGenUserEvent" language="en_US">
39 <since>
40 <version>1.8.0</version>
41 </since>
42 <synopsis>
43 Generates a CEL User Defined Event.
44 </synopsis>
45 <syntax>
46 <parameter name="event-name" required="true">
47 <argument name="event-name" required="true">
48 </argument>
49 <argument name="extra" required="false">
50 <para>Extra text to be included with the event.</para>
51 </argument>
52 </parameter>
53 </syntax>
54 <description>
55 <para>A CEL event will be immediately generated by this channel, with the supplied name for a type.</para>
56 </description>
57 </application>
58 ***/
59
60static char *app = "CELGenUserEvent";
61
62static int celgenuserevent_exec(struct ast_channel *chan, const char *data)
63{
64 int res = 0;
65 char *parse;
66 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
69 AST_APP_ARG(extra);
70 );
71
72 if (ast_strlen_zero(data)) {
73 return 0;
74 }
75
76 parse = ast_strdupa(data);
78
79 blob = ast_json_pack("{s: s, s: {s: s}}",
80 "event", args.event,
81 "extra", "extra", S_OR(args.extra, ""));
82 if (!blob) {
83 return res;
84 }
86 return res;
87}
88
89static int unload_module(void)
90{
92 return 0;
93}
94
95static int load_module(void)
96{
98 if (res) {
100 } else {
102 }
103}
104
105AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Generate an User-Defined CEL event",
106 .support_level = AST_MODULE_SUPPORT_CORE,
107 .load = load_module,
108 .unload = unload_module,
109 .requires = "cel",
static char * app
static int celgenuserevent_exec(struct ast_channel *chan, const char *data)
static int load_module(void)
static int unload_module(void)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
Call Event Logging API.
void ast_cel_publish_event(struct ast_channel *chan, enum ast_cel_event_type event_type, struct ast_json *blob)
Publish a CEL event.
Definition: cel.c:1724
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
Definition: cel.h:69
General Asterisk PBX channel definitions.
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#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.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
@ 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
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
#define NULL
Definition: resample.c:96
#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
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Abstract JSON element (object, array, string, int, ...).
Definition: astman.c:222
const char * args
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941