Asterisk - The Open Source Telephony Project GIT-master-66c01d8
Functions | Variables
app_userevent.c File Reference

UserEvent application – send manager event. More...

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/manager.h"
#include "asterisk/app.h"
#include "asterisk/json.h"
#include "asterisk/stasis_channels.h"
Include dependency graph for app_userevent.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 
static int userevent_exec (struct ast_channel *chan, const char *data)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Custom User Event Application" , .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, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app = "UserEvent"
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

UserEvent application – send manager event.

Definition in file app_userevent.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 138 of file app_userevent.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 138 of file app_userevent.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 138 of file app_userevent.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 133 of file app_userevent.c.

134{
136}
static int userevent_exec(struct ast_channel *chan, const char *data)
Definition: app_userevent.c:75
static char * app
Definition: app_userevent.c:73
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References app, ast_register_application_xml, and userevent_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 128 of file app_userevent.c.

129{
131}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, and ast_unregister_application().

◆ userevent_exec()

static int userevent_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 75 of file app_userevent.c.

76{
77 char *parse;
78 int x;
80 AST_APP_ARG(eventname);
81 AST_APP_ARG(extra)[100];
82 );
83 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
84
85 if (ast_strlen_zero(data)) {
86 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
87 return -1;
88 }
89
90 parse = ast_strdupa(data);
91
93
94 blob = ast_json_pack("{s: s}",
95 "eventname", args.eventname);
96 if (!blob) {
97 return -1;
98 }
99
100 for (x = 0; x < args.argc - 1; x++) {
101 char *key, *value = args.extra[x];
102 struct ast_json *json_value;
103
104 key = strsep(&value, ":");
105 if (!value) {
106 /* no ':' in string? */
107 continue;
108 }
109
111 json_value = ast_json_string_create(value);
112 if (!json_value) {
113 return -1;
114 }
115
116 /* ref stolen by ast_json_object_set */
117 if (ast_json_object_set(blob, key, json_value)) {
118 return -1;
119 }
120 }
121
122 ast_channel_lock(chan);
124 ast_channel_unlock(chan);
125 return 0;
126}
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
void ast_multi_object_blob_single_channel_publish(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Create and publish a stasis message blob on a channel with it's snapshot.
Definition: stasis.c:2037
struct stasis_message_type * ast_multi_user_event_type(void)
Message type for custom user defined events with multi object blobs.
#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 LOG_WARNING
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
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
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
Abstract JSON element (object, array, string, int, ...).
int value
Definition: syslog.c:37
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

References args, AST_APP_ARG, ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_unref(), ast_log, ast_multi_object_blob_single_channel_publish(), ast_multi_user_event_type(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strip(), ast_strlen_zero(), LOG_WARNING, NULL, RAII_VAR, strsep(), and value.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Custom User Event Application" , .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, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 138 of file app_userevent.c.

◆ app

char* app = "UserEvent"
static

Definition at line 73 of file app_userevent.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 138 of file app_userevent.c.