Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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"
Include dependency graph for app_forkcdr.c:

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 226 of file app_forkcdr.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 226 of file app_forkcdr.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

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

119{
120 struct fork_cdr_message_payload *payload;
121
122 if (stasis_message_type(message) != forkcdr_message_type()) {
123 return;
124 }
125
126 payload = stasis_message_data(message);
127 if (!payload) {
128 return;
129 }
130
131 if (ast_cdr_fork(payload->channel_name, payload->flags)) {
132 ast_log(AST_LOG_WARNING, "Failed to fork CDR for channel %s\n",
133 payload->channel_name);
134 }
135}
#define ast_log
Definition: astobj2.c:42
int ast_cdr_fork(const char *channel_name, struct ast_flags *options)
Fork a CDR.
Definition: cdr.c:3770
#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.
struct ast_flags * flags
Definition: app_forkcdr.c:115
const char * channel_name
Definition: app_forkcdr.c:113

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().

◆ forkcdr_exec()

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

Definition at line 137 of file app_forkcdr.c.

138{
142
143 char *parse;
144 struct ast_flags flags = { 0, };
147 );
148
149 parse = ast_strdupa(data);
150
152
153 if (!ast_strlen_zero(args.options)) {
155 }
156
157 if (!forkcdr_message_type()) {
158 ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message type\n",
159 ast_channel_name(chan));
160 return -1;
161 }
162
163 payload = ao2_alloc(sizeof(*payload), NULL);
164 if (!payload) {
165 return -1;
166 }
167
168 if (!router) {
169 ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
170 ast_channel_name(chan));
171 return -1;
172 }
173
174 payload->channel_name = ast_channel_name(chan);
175 payload->flags = &flags;
176 message = stasis_message_create(forkcdr_message_type(), payload);
177 if (!message) {
178 ast_log(AST_LOG_WARNING, "Failed to fork CDR for channel %s: unable to create message\n",
179 ast_channel_name(chan));
180 return -1;
181 }
183
184 return 0;
185}
static const struct ast_app_option forkcdr_exec_options[128]
Definition: app_forkcdr.c:106
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
struct stasis_message_router * ast_cdr_message_router(void)
Return the message router for the CDR engine.
Definition: cdr.c:4427
const char * ast_channel_name(const struct ast_channel *chan)
#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.
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:3066
static struct stasis_message_router * router
#define NULL
Definition: resample.c:96
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.
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
static struct test_options options
#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_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(), ast_flags::flags, forkcdr_exec_options, NULL, options, RAII_VAR, router, stasis_message_create(), and stasis_message_router_publish_sync().

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 199 of file app_forkcdr.c.

200{
202 int res = 0;
203
204 if (!router) {
206 }
207
208 res |= STASIS_MESSAGE_TYPE_INIT(forkcdr_message_type);
210 res |= stasis_message_router_add(router, forkcdr_message_type(),
212
213 if (res) {
215
217 }
219}
static char * app
Definition: app_forkcdr.c:99
static int forkcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_forkcdr.c:137
static void forkcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: app_forkcdr.c:118
static int unload_module(void)
Definition: app_forkcdr.c:187
@ 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:640
#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.

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

◆ STASIS_MESSAGE_TYPE_DEFN_LOCAL()

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( forkcdr_message_type  )

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 187 of file app_forkcdr.c.

188{
190
191 if (router) {
192 stasis_message_router_remove(router, forkcdr_message_type());
193 }
194 STASIS_MESSAGE_TYPE_CLEANUP(forkcdr_message_type);
196 return 0;
197}
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, app, ast_cdr_message_router(), ast_unregister_application(), RAII_VAR, 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_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 226 of file app_forkcdr.c.

◆ app

char* app = "ForkCDR"
static

Definition at line 99 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 226 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 106 of file app_forkcdr.c.

Referenced by forkcdr_exec().