Asterisk - The Open Source Telephony Project  18.5.0
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 nocdr_exec (struct ast_channel *chan, const char *data)
 
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 nocdr_app [] = "NoCDR"
 
static const char resetcdr_app [] = "ResetCDR"
 
static const struct ast_app_option resetcdr_opts [128] = { [ 'v' ] = { .flag = AST_CDR_FLAG_KEEP_VARS }, [ 'e' ] = { .flag = AST_CDR_FLAG_DISABLE_ALL }, }
 

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 104 of file app_cdr.c.

104  {
105  OPT_DISABLE_DISPATCH = (1 << 0),
106  OPT_KEEP_VARS = (1 << 1),
107  OPT_ENABLE = (1 << 2),
108 };

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 268 of file app_cdr.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 268 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 131 of file app_cdr.c.

References ast_cdr_clear_property(), AST_CDR_FLAG_DISABLE_ALL, ast_cdr_reset(), ast_cdr_set_property(), ast_log, AST_LOG_WARNING, app_cdr_message_payload::channel_name, app_cdr_message_payload::disable, app_cdr_message_payload::keep_variables, app_cdr_message_payload::reenable, app_cdr_message_payload::reset, stasis_message_data(), and stasis_message_type().

Referenced by load_module().

132 {
133  struct app_cdr_message_payload *payload;
134 
135  if (stasis_message_type(message) != appcdr_message_type()) {
136  return;
137  }
138 
139  payload = stasis_message_data(message);
140  if (!payload) {
141  return;
142  }
143 
144  if (payload->disable) {
146  ast_log(AST_LOG_WARNING, "Failed to disable CDRs on channel %s\n",
147  payload->channel_name);
148  }
149  }
150 
151  if (payload->reenable) {
153  ast_log(AST_LOG_WARNING, "Failed to enable CDRs on channel %s\n",
154  payload->channel_name);
155  }
156  }
157 
158  if (payload->reset) {
159  if (ast_cdr_reset(payload->channel_name, payload->keep_variables)) {
160  ast_log(AST_LOG_WARNING, "Failed to reset CDRs on channel %s\n",
161  payload->channel_name);
162  }
163  }
164 }
unsigned int reenable
Definition: app_cdr.c:124
#define AST_LOG_WARNING
Definition: logger.h:279
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
const char * channel_name
Definition: app_cdr.c:120
unsigned int keep_variables
Definition: app_cdr.c:128
#define ast_log
Definition: astobj2.c:42
unsigned int reset
Definition: app_cdr.c:126
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition: cdr.c:3598
int ast_cdr_set_property(const char *channel_name, enum ast_cdr_options option)
Set a property on a CDR for a channel.
Definition: cdr.c:3548
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
unsigned int disable
Definition: app_cdr.c:122
int ast_cdr_clear_property(const char *channel_name, enum ast_cdr_options option)
Clear a property on a CDR for a channel.
Definition: cdr.c:3575

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 268 of file app_cdr.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 246 of file app_cdr.c.

References ao2_cleanup, appcdr_callback(), ast_cdr_message_router(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, nocdr_app, nocdr_exec(), NULL, RAII_VAR, resetcdr_app, resetcdr_exec(), router, stasis_message_router_add(), STASIS_MESSAGE_TYPE_INIT, and unload_module().

247 {
249  int res = 0;
250 
251  if (!router) {
253  }
254 
255  res |= STASIS_MESSAGE_TYPE_INIT(appcdr_message_type);
258  res |= stasis_message_router_add(router, appcdr_message_type(),
260 
261  if (res) {
262  unload_module();
264  }
266 }
static int resetcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_cdr.c:188
static struct stasis_message_router * router
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 STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1501
static void appcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: app_cdr.c:131
#define NULL
Definition: resample.c:96
static int unload_module(void)
Definition: app_cdr.c:233
struct stasis_message_router * ast_cdr_message_router(void)
Return the message router for the CDR engine.
Definition: cdr.c:4291
#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:911
static const char nocdr_app[]
Definition: app_cdr.c:101
static const char resetcdr_app[]
Definition: app_cdr.c:102
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int nocdr_exec(struct ast_channel *chan, const char *data)
Definition: app_cdr.c:218
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ nocdr_exec()

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

Definition at line 218 of file app_cdr.c.

References ao2_alloc, ao2_cleanup, ast_channel_name(), NULL, publish_app_cdr_message(), and RAII_VAR.

Referenced by load_module().

219 {
220  RAII_VAR(struct app_cdr_message_payload *, payload,
221  ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
222 
223  if (!payload) {
224  return -1;
225  }
226 
227  payload->channel_name = ast_channel_name(chan);
228  payload->disable = 1;
229 
230  return publish_app_cdr_message(chan, payload);
231 }
#define NULL
Definition: resample.c:96
#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:911
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static int publish_app_cdr_message(struct ast_channel *chan, struct app_cdr_message_payload *payload)
Definition: app_cdr.c:166
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const char * ast_channel_name(const struct ast_channel *chan)

◆ publish_app_cdr_message()

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

Definition at line 166 of file app_cdr.c.

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 nocdr_exec(), and resetcdr_exec().

167 {
170 
171  if (!router) {
172  ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
173  ast_channel_name(chan));
174  return -1;
175  }
176 
177  message = stasis_message_create(appcdr_message_type(), payload);
178  if (!message) {
179  ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n",
180  payload->channel_name);
181  return -1;
182  }
184 
185  return 0;
186 }
static struct stasis_message_router * router
void stasis_message_router_publish_sync(struct stasis_message_router *router, struct stasis_message *message)
Publish a message to a message router&#39;s subscription synchronously.
#define AST_LOG_WARNING
Definition: logger.h:279
const char * channel_name
Definition: app_cdr.c:120
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
struct stasis_message_router * ast_cdr_message_router(void)
Return the message router for the CDR engine.
Definition: cdr.c:4291
#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:911
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const char * ast_channel_name(const struct ast_channel *chan)

◆ resetcdr_exec()

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

Definition at line 188 of file app_cdr.c.

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

Referenced by load_module().

189 {
190  RAII_VAR(struct app_cdr_message_payload *, payload,
191  ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
192  char *args;
193  struct ast_flags flags = { 0 };
194 
195  if (!payload) {
196  return -1;
197  }
198 
199  if (!ast_strlen_zero(data)) {
200  args = ast_strdupa(data);
201  ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
202  }
203 
204  payload->channel_name = ast_channel_name(chan);
205  payload->reset = 1;
206 
208  payload->reenable = 1;
209  }
210 
211  if (ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) {
212  payload->keep_variables = 1;
213  }
214 
215  return publish_app_cdr_message(chan, payload);
216 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
unsigned int flags
Definition: utils.h:200
const char * args
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#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:911
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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:2906
static const struct ast_app_option resetcdr_opts[128]
Definition: app_cdr.c:113
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
Structure used to handle boolean flags.
Definition: utils.h:199
static int publish_app_cdr_message(struct ast_channel *chan, struct app_cdr_message_payload *payload)
Definition: app_cdr.c:166
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const char * ast_channel_name(const struct ast_channel *chan)

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL()

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( appcdr_message_type  )

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 233 of file app_cdr.c.

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

Referenced by load_module().

234 {
236 
237  if (router) {
238  stasis_message_router_remove(router, appcdr_message_type());
239  }
240  STASIS_MESSAGE_TYPE_CLEANUP(appcdr_message_type);
243  return 0;
244 }
static struct stasis_message_router * router
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1523
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
struct stasis_message_router * ast_cdr_message_router(void)
Return the message router for the CDR engine.
Definition: cdr.c:4291
#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:911
static const char nocdr_app[]
Definition: app_cdr.c:101
static const char resetcdr_app[]
Definition: app_cdr.c:102
void stasis_message_router_remove(struct stasis_message_router *router, struct stasis_message_type *message_type)
Remove a route from a message router.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 268 of file app_cdr.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 268 of file app_cdr.c.

◆ nocdr_app

const char nocdr_app[] = "NoCDR"
static

Definition at line 101 of file app_cdr.c.

Referenced by load_module(), and unload_module().

◆ resetcdr_app

const char resetcdr_app[] = "ResetCDR"
static

Definition at line 102 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 }, [ 'e' ] = { .flag = AST_CDR_FLAG_DISABLE_ALL }, }
static

Definition at line 113 of file app_cdr.c.

Referenced by resetcdr_exec().