Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Enumerations | Functions | Variables
app_cdr.c File Reference

Applications connected with CDR engine. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_message_router.h"
Include dependency graph for app_cdr.c:

Go to the source code of this file.

Data Structures

struct  app_cdr_message_payload
 

Enumerations

enum  reset_cdr_options { OPT_DISABLE_DISPATCH = (1 << 0) , OPT_KEEP_VARS = (1 << 1) , OPT_ENABLE = (1 << 2) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void appcdr_callback (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int publish_app_cdr_message (struct ast_channel *chan, struct app_cdr_message_payload *payload)
 
static int resetcdr_exec (struct ast_channel *chan, const char *data)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (appcdr_message_type)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Tell Asterisk to not maintain a CDR for the current call" , .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 const struct ast_module_infoast_module_info = &__mod_info
 
static const char resetcdr_app [] = "ResetCDR"
 
static const struct ast_app_option resetcdr_opts [128] = { [ 'v' ] = { .flag = AST_CDR_FLAG_KEEP_VARS }, }
 

Detailed Description

Applications connected with CDR engine.

Author
Martin Pycko marti.nosp@m.np@d.nosp@m.igium.nosp@m..com

Definition in file app_cdr.c.

Enumeration Type Documentation

◆ reset_cdr_options

Enumerator
OPT_DISABLE_DISPATCH 
OPT_KEEP_VARS 
OPT_ENABLE 

Definition at line 73 of file app_cdr.c.

73 {
74 OPT_DISABLE_DISPATCH = (1 << 0),
75 OPT_KEEP_VARS = (1 << 1),
76 OPT_ENABLE = (1 << 2),
77};
@ OPT_DISABLE_DISPATCH
Definition: app_cdr.c:74
@ OPT_KEEP_VARS
Definition: app_cdr.c:75
@ OPT_ENABLE
Definition: app_cdr.c:76

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 195 of file app_cdr.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 195 of file app_cdr.c.

◆ appcdr_callback()

static void appcdr_callback ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 95 of file app_cdr.c.

96{
97 struct app_cdr_message_payload *payload;
98
99 if (stasis_message_type(message) != appcdr_message_type()) {
100 return;
101 }
102
103 payload = stasis_message_data(message);
104 if (!payload) {
105 return;
106 }
107
108 if (payload->reset) {
109 if (ast_cdr_reset(payload->channel_name, payload->keep_variables)) {
110 ast_log(AST_LOG_WARNING, "Failed to reset CDRs on channel %s\n", payload->channel_name);
111 }
112 }
113}
#define ast_log
Definition: astobj2.c:42
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition: cdr.c:3660
#define AST_LOG_WARNING
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
unsigned int reset
Definition: app_cdr.c:90
const char * channel_name
Definition: app_cdr.c:88
unsigned int keep_variables
Definition: app_cdr.c:92

References ast_cdr_reset(), ast_log, AST_LOG_WARNING, app_cdr_message_payload::channel_name, app_cdr_message_payload::keep_variables, app_cdr_message_payload::reset, stasis_message_data(), and stasis_message_type().

Referenced by load_module().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 195 of file app_cdr.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 175 of file app_cdr.c.

176{
178 int res = 0;
179
180 if (!router) {
182 }
183
184 res |= STASIS_MESSAGE_TYPE_INIT(appcdr_message_type);
186 res |= stasis_message_router_add(router, appcdr_message_type(), appcdr_callback, NULL);
187
188 if (res) {
191 }
193}
static void appcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: app_cdr.c:95
static int resetcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_cdr.c:137
static int unload_module(void)
Definition: app_cdr.c:163
static const char resetcdr_app[]
Definition: app_cdr.c:71
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct stasis_message_router * ast_cdr_message_router(void)
Return the message router for the CDR engine.
Definition: cdr.c:4356
@ 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:626
static struct stasis_message_router * router
#define NULL
Definition: resample.c:96
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
#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 ao2_cleanup, appcdr_callback(), ast_cdr_message_router(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, NULL, RAII_VAR, resetcdr_app, resetcdr_exec(), router, stasis_message_router_add(), STASIS_MESSAGE_TYPE_INIT, and unload_module().

◆ publish_app_cdr_message()

static int publish_app_cdr_message ( struct ast_channel chan,
struct app_cdr_message_payload payload 
)
static

Definition at line 115 of file app_cdr.c.

116{
119
120 if (!router) {
121 ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
122 ast_channel_name(chan));
123 return -1;
124 }
125
126 message = stasis_message_create(appcdr_message_type(), payload);
127 if (!message) {
128 ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n",
129 payload->channel_name);
130 return -1;
131 }
133
134 return 0;
135}
const char * ast_channel_name(const struct ast_channel *chan)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_message_router_publish_sync(struct stasis_message_router *router, struct stasis_message *message)
Publish a message to a message router's subscription synchronously.

References ao2_cleanup, ast_cdr_message_router(), ast_channel_name(), ast_log, AST_LOG_WARNING, app_cdr_message_payload::channel_name, NULL, RAII_VAR, router, stasis_message_create(), and stasis_message_router_publish_sync().

Referenced by resetcdr_exec().

◆ resetcdr_exec()

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

Definition at line 137 of file app_cdr.c.

138{
139 RAII_VAR(struct app_cdr_message_payload *, payload,
140 ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
141 char *args;
142 struct ast_flags flags = { 0 };
143
144 if (!payload) {
145 return -1;
146 }
147
148 if (!ast_strlen_zero(data)) {
149 args = ast_strdupa(data);
151 }
152
153 payload->channel_name = ast_channel_name(chan);
154 payload->reset = 1;
155
157 payload->keep_variables = 1;
158 }
159
160 return publish_app_cdr_message(chan, payload);
161}
static const struct ast_app_option resetcdr_opts[128]
Definition: app_cdr.c:81
static int publish_app_cdr_message(struct ast_channel *chan, struct app_cdr_message_payload *payload)
Definition: app_cdr.c:115
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
@ AST_CDR_FLAG_KEEP_VARS
Definition: cdr.h:243
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3056
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200
const char * args
#define ast_test_flag(p, flag)
Definition: utils.h:63

References ao2_alloc, ao2_cleanup, args, ast_app_parse_options(), AST_CDR_FLAG_KEEP_VARS, ast_channel_name(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_flags::flags, NULL, publish_app_cdr_message(), RAII_VAR, and resetcdr_opts.

Referenced by load_module().

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL()

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( appcdr_message_type  )

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 163 of file app_cdr.c.

164{
166
167 if (router) {
168 stasis_message_router_remove(router, appcdr_message_type());
169 }
170 STASIS_MESSAGE_TYPE_CLEANUP(appcdr_message_type);
172 return 0;
173}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515
void stasis_message_router_remove(struct stasis_message_router *router, struct stasis_message_type *message_type)
Remove a route from a message router.

References ao2_cleanup, ast_cdr_message_router(), ast_unregister_application(), RAII_VAR, resetcdr_app, router, stasis_message_router_remove(), and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Tell Asterisk to not maintain a CDR for the current call" , .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 195 of file app_cdr.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 195 of file app_cdr.c.

◆ resetcdr_app

const char resetcdr_app[] = "ResetCDR"
static

Definition at line 71 of file app_cdr.c.

Referenced by load_module(), and unload_module().

◆ resetcdr_opts

const struct ast_app_option resetcdr_opts[128] = { [ 'v' ] = { .flag = AST_CDR_FLAG_KEEP_VARS }, }
static

Definition at line 81 of file app_cdr.c.

Referenced by resetcdr_exec().