Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 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.

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}
#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:3716
#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:112
const char * channel_name
Definition: app_forkcdr.c:110

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

135{
139
140 char *parse;
141 struct ast_flags flags = { 0, };
144 );
145
146 parse = ast_strdupa(data);
147
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}
static const struct ast_app_option forkcdr_exec_options[128]
Definition: app_forkcdr.c:103
#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:4373
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 196 of file app_forkcdr.c.

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) {
212
214 }
216}
static char * app
Definition: app_forkcdr.c:96
static int forkcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_forkcdr.c:134
static void forkcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
Definition: app_forkcdr.c:115
static int unload_module(void)
Definition: app_forkcdr.c:184
@ 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 184 of file app_forkcdr.c.

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