Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 135 of file app_userevent.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 135 of file app_userevent.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 135 of file app_userevent.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 130 of file app_userevent.c.

131{
133}
static int userevent_exec(struct ast_channel *chan, const char *data)
Definition: app_userevent.c:72
static char * app
Definition: app_userevent.c:70
#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 125 of file app_userevent.c.

126{
128}
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 72 of file app_userevent.c.

73{
74 char *parse;
75 int x;
77 AST_APP_ARG(eventname);
78 AST_APP_ARG(extra)[100];
79 );
80 RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
81
82 if (ast_strlen_zero(data)) {
83 ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
84 return -1;
85 }
86
87 parse = ast_strdupa(data);
88
90
91 blob = ast_json_pack("{s: s}",
92 "eventname", args.eventname);
93 if (!blob) {
94 return -1;
95 }
96
97 for (x = 0; x < args.argc - 1; x++) {
98 char *key, *value = args.extra[x];
99 struct ast_json *json_value;
100
101 key = strsep(&value, ":");
102 if (!value) {
103 /* no ':' in string? */
104 continue;
105 }
106
108 json_value = ast_json_string_create(value);
109 if (!json_value) {
110 return -1;
111 }
112
113 /* ref stolen by ast_json_object_set */
114 if (ast_json_object_set(blob, key, json_value)) {
115 return -1;
116 }
117 }
118
119 ast_channel_lock(chan);
121 ast_channel_unlock(chan);
122 return 0;
123}
#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:2968
#define ast_channel_unlock(chan)
Definition: channel.h:2969
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:2011
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.
char * strsep(char **str, const char *delims)
#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 135 of file app_userevent.c.

◆ app

char* app = "UserEvent"
static

Definition at line 70 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 135 of file app_userevent.c.