Asterisk - The Open Source Telephony Project  GIT-master-1f78ee9
Data Structures | Functions | Variables
app_forkcdr.c File Reference

Fork CDR application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/cdr.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_message_router.h"

Go to the source code of this file.

Data Structures

struct  fork_cdr_message_payload
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void forkcdr_callback (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static int forkcdr_exec (struct ast_channel *chan, const char *data)
 
static int load_module (void)
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (forkcdr_message_type)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Fork The CDR into 2 separate entities" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "cdr", }
 
static char * app = "ForkCDR"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_app_option forkcdr_exec_options [128] = { [ 'a' ] = { .flag = AST_CDR_FLAG_SET_ANSWER }, [ 'e' ] = { .flag = AST_CDR_FLAG_FINALIZE }, [ 'r' ] = { .flag = AST_CDR_FLAG_RESET }, [ 'v' ] = { .flag = AST_CDR_FLAG_KEEP_VARS }, }
 

Detailed Description

Fork CDR application.

Author
Anthony Minessale anthm.nosp@m.ct@y.nosp@m.ahoo..nosp@m.com
Note
Development of this app Sponsored/Funded by TAAN Softworks Corp

Definition in file app_forkcdr.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 223 of file app_forkcdr.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 223 of file app_forkcdr.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 223 of file app_forkcdr.c.

◆ forkcdr_callback()

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

Definition at line 115 of file app_forkcdr.c.

References ast_cdr_fork(), ast_log, AST_LOG_WARNING, fork_cdr_message_payload::channel_name, fork_cdr_message_payload::flags, stasis_message_data(), and stasis_message_type().

Referenced by load_module().

116 {
117  struct fork_cdr_message_payload *payload;
118 
119  if (stasis_message_type(message) != forkcdr_message_type()) {
120  return;
121  }
122 
123  payload = stasis_message_data(message);
124  if (!payload) {
125  return;
126  }
127 
128  if (ast_cdr_fork(payload->channel_name, payload->flags)) {
129  ast_log(AST_LOG_WARNING, "Failed to fork CDR for channel %s\n",
130  payload->channel_name);
131  }
132 }
const char * channel_name
Definition: app_forkcdr.c:110
int ast_cdr_fork(const char *channel_name, struct ast_flags *options)
Fork a CDR.
Definition: cdr.c:3637
#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.
#define ast_log
Definition: astobj2.c:42
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct ast_flags * flags
Definition: app_forkcdr.c:112

◆ forkcdr_exec()

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

Definition at line 134 of file app_forkcdr.c.

References ao2_alloc, ao2_cleanup, args, AST_APP_ARG, ast_app_parse_options(), ast_cdr_message_router(), ast_channel_name(), AST_DECLARE_APP_ARGS, ast_log, AST_LOG_WARNING, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, fork_cdr_message_payload::flags, forkcdr_exec_options, NULL, options, parse(), RAII_VAR, router, stasis_message_create(), and stasis_message_router_publish_sync().

Referenced by load_module().

135 {
137  RAII_VAR(struct fork_cdr_message_payload *, payload, NULL, ao2_cleanup);
139 
140  char *parse;
141  struct ast_flags flags = { 0, };
144  );
145 
146  parse = ast_strdupa(data);
147 
148  AST_STANDARD_APP_ARGS(args, parse);
149 
150  if (!ast_strlen_zero(args.options)) {
152  }
153 
154  if (!forkcdr_message_type()) {
155  ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message type\n",
156  ast_channel_name(chan));
157  return -1;
158  }
159 
160  payload = ao2_alloc(sizeof(*payload), NULL);
161  if (!payload) {
162  return -1;
163  }
164 
165  if (!router) {
166  ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
167  ast_channel_name(chan));
168  return -1;
169  }
170 
171  payload->channel_name = ast_channel_name(chan);
172  payload->flags = &flags;
173  message = stasis_message_create(forkcdr_message_type(), payload);
174  if (!message) {
175  ast_log(AST_LOG_WARNING, "Failed to fork CDR for channel %s: unable to create message\n",
176  ast_channel_name(chan));
177  return -1;
178  }
180 
181  return 0;
182 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
unsigned int flags
Definition: utils.h:200
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.
#define AST_LOG_WARNING
Definition: logger.h:279
const char * args
#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:851
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct stasis_message_router * router
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:2829
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define ast_strlen_zero(a)
Definition: muted.c:73
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
static const struct ast_app_option forkcdr_exec_options[128]
Definition: app_forkcdr.c:103
Structure used to handle boolean flags.
Definition: utils.h:199
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
const char * ast_channel_name(const struct ast_channel *chan)
static struct test_options options
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ load_module()

static int load_module ( void  )
static

Definition at line 196 of file app_forkcdr.c.

References ao2_cleanup, app, ast_cdr_message_router(), AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_register_application_xml, ASTERISK_GPL_KEY, forkcdr_callback(), forkcdr_exec(), NULL, RAII_VAR, router, stasis_message_router_add(), STASIS_MESSAGE_TYPE_INIT, and unload_module().

197 {
199  int res = 0;
200 
201  if (!router) {
203  }
204 
205  res |= STASIS_MESSAGE_TYPE_INIT(forkcdr_message_type);
207  res |= stasis_message_router_add(router, forkcdr_message_type(),
209 
210  if (res) {
211  unload_module();
212 
214  }
216 }
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 char * app
Definition: app_forkcdr.c:96
#define NULL
Definition: resample.c:96
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:851
static struct stasis_message_router * router
static int unload_module(void)
Definition: app_forkcdr.c:184
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static void forkcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: app_forkcdr.c:115
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
static int forkcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_forkcdr.c:134

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL()

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( forkcdr_message_type  )

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 184 of file app_forkcdr.c.

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

Referenced by load_module().

185 {
187 
188  if (router) {
189  stasis_message_router_remove(router, forkcdr_message_type());
190  }
191  STASIS_MESSAGE_TYPE_CLEANUP(forkcdr_message_type);
193  return 0;
194 }
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1523
static char * app
Definition: app_forkcdr.c:96
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:851
static struct stasis_message_router * router
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_DEFAULT , .description = "Fork The CDR into 2 separate entities" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "cdr", }
static

Definition at line 223 of file app_forkcdr.c.

◆ app

char* app = "ForkCDR"
static

Definition at line 96 of file app_forkcdr.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 223 of file app_forkcdr.c.

◆ forkcdr_exec_options

const struct ast_app_option forkcdr_exec_options[128] = { [ 'a' ] = { .flag = AST_CDR_FLAG_SET_ANSWER }, [ 'e' ] = { .flag = AST_CDR_FLAG_FINALIZE }, [ 'r' ] = { .flag = AST_CDR_FLAG_RESET }, [ 'v' ] = { .flag = AST_CDR_FLAG_KEEP_VARS }, }
static

Definition at line 103 of file app_forkcdr.c.

Referenced by forkcdr_exec().