Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_userevent.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, 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 UserEvent application -- send manager event
20  *
21  * \ingroup applications
22  */
23 
24 /*** MODULEINFO
25  <support_level>core</support_level>
26  ***/
27 
28 #include "asterisk.h"
29 
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
31 
32 #include "asterisk/pbx.h"
33 #include "asterisk/module.h"
34 #include "asterisk/manager.h"
35 #include "asterisk/app.h"
36 
37 /*** DOCUMENTATION
38  <application name="UserEvent" language="en_US">
39  <synopsis>
40  Send an arbitrary event to the manager interface.
41  </synopsis>
42  <syntax>
43  <parameter name="eventname" required="true" />
44  <parameter name="body" />
45  </syntax>
46  <description>
47  <para>Sends an arbitrary event to the manager interface, with an optional
48  <replaceable>body</replaceable> representing additional arguments. The
49  <replaceable>body</replaceable> may be specified as
50  a <literal>,</literal> delimited list of headers. Each additional
51  argument will be placed on a new line in the event. The format of the
52  event will be:</para>
53  <para> Event: UserEvent</para>
54  <para> UserEvent: &lt;specified event name&gt;</para>
55  <para> [body]</para>
56  <para>If no <replaceable>body</replaceable> is specified, only Event and UserEvent headers will be present.</para>
57  </description>
58  </application>
59  ***/
60 
61 static char *app = "UserEvent";
62 
63 static int userevent_exec(struct ast_channel *chan, const char *data)
64 {
65  char *parse;
66  int x;
68  AST_APP_ARG(eventname);
69  AST_APP_ARG(extra)[100];
70  );
71  struct ast_str *body = ast_str_create(16);
72 
73  if (ast_strlen_zero(data)) {
74  ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
75  ast_free(body);
76  return -1;
77  }
78 
79  if (!body) {
80  ast_log(LOG_WARNING, "Unable to allocate buffer\n");
81  return -1;
82  }
83 
84  parse = ast_strdupa(data);
85 
87 
88  for (x = 0; x < args.argc - 1; x++) {
89  ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
90  }
91 
92  manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, ast_str_buffer(body));
93  ast_free(body);
94 
95  return 0;
96 }
97 
98 static int unload_module(void)
99 {
100  return ast_unregister_application(app);
101 }
102 
103 static int load_module(void)
104 {
106 }
107 
108 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom User Event Application");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
static int load_module(void)
Asterisk main include file. File version handling, generic pbx functions.
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:900
static int unload_module(void)
Definition: app_userevent.c:98
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
static char * app
Definition: app_userevent.c:61
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static struct @350 args
#define EVENT_FLAG_USER
Definition: manager.h:77
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static int userevent_exec(struct ast_channel *chan, const char *data)
Definition: app_userevent.c:63
#define ast_free(a)
Definition: astmm.h:97
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
Asterisk module definitions.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180