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)
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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static struct ast_module_infoast_module_info = &__mod_info
static const char nocdr_app [] = "NoCDR"
static const char resetcdr_app [] = "ResetCDR"
static 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 <martinp@digium.com>

Definition in file app_cdr.c.


Enumeration Type Documentation

Enumerator:
OPT_DISABLE_DISPATCH 
OPT_KEEP_VARS 
OPT_ENABLE 

Definition at line 106 of file app_cdr.c.

00106                        {
00107    OPT_DISABLE_DISPATCH = (1 << 0),
00108    OPT_KEEP_VARS = (1 << 1),
00109    OPT_ENABLE = (1 << 2),
00110 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 269 of file app_cdr.c.

static void __unreg_module ( void   )  [static]

Definition at line 269 of file app_cdr.c.

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

Definition at line 133 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().

00134 {
00135    struct app_cdr_message_payload *payload;
00136 
00137    if (stasis_message_type(message) != appcdr_message_type()) {
00138       return;
00139    }
00140 
00141    payload = stasis_message_data(message);
00142    if (!payload) {
00143       return;
00144    }
00145 
00146    if (payload->disable) {
00147       if (ast_cdr_set_property(payload->channel_name, AST_CDR_FLAG_DISABLE_ALL)) {
00148          ast_log(AST_LOG_WARNING, "Failed to disable CDRs on channel %s\n",
00149             payload->channel_name);
00150       }
00151    }
00152 
00153    if (payload->reenable) {
00154       if (ast_cdr_clear_property(payload->channel_name, AST_CDR_FLAG_DISABLE_ALL)) {
00155          ast_log(AST_LOG_WARNING, "Failed to enable CDRs on channel %s\n",
00156             payload->channel_name);
00157       }
00158    }
00159 
00160    if (payload->reset) {
00161       if (ast_cdr_reset(payload->channel_name, payload->keep_variables)) {
00162          ast_log(AST_LOG_WARNING, "Failed to reset CDRs on channel %s\n",
00163             payload->channel_name);
00164       }
00165    }
00166 }

static int load_module ( void   )  [static]

Definition at line 248 of file app_cdr.c.

References ao2_cleanup, appcdr_callback(), ast_cdr_message_router(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, nocdr_exec(), NULL, RAII_VAR, resetcdr_exec(), router, stasis_message_router_add(), and STASIS_MESSAGE_TYPE_INIT.

00249 {
00250    RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
00251    int res = 0;
00252 
00253    if (!router) {
00254       return AST_MODULE_LOAD_FAILURE;
00255    }
00256 
00257    res |= STASIS_MESSAGE_TYPE_INIT(appcdr_message_type);
00258    res |= ast_register_application_xml(nocdr_app, nocdr_exec);
00259    res |= ast_register_application_xml(resetcdr_app, resetcdr_exec);
00260    res |= stasis_message_router_add(router, appcdr_message_type(),
00261                                     appcdr_callback, NULL);
00262 
00263    if (res) {
00264       return AST_MODULE_LOAD_FAILURE;
00265    }
00266    return AST_MODULE_LOAD_SUCCESS;
00267 }

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

Definition at line 220 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().

00221 {
00222    RAII_VAR(struct app_cdr_message_payload *, payload,
00223       ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
00224 
00225    if (!payload) {
00226       return -1;
00227    }
00228 
00229    payload->channel_name = ast_channel_name(chan);
00230    payload->disable = 1;
00231 
00232    return publish_app_cdr_message(chan, payload);
00233 }

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

Definition at line 168 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().

00169 {
00170    RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
00171    RAII_VAR(struct stasis_message_router *, router, ast_cdr_message_router(), ao2_cleanup);
00172 
00173    if (!router) {
00174       ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n",
00175          ast_channel_name(chan));
00176       return -1;
00177    }
00178 
00179    message = stasis_message_create(appcdr_message_type(), payload);
00180    if (!message) {
00181       ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n",
00182          payload->channel_name);
00183       return -1;
00184    }
00185    stasis_message_router_publish_sync(router, message);
00186 
00187    return 0;
00188 }

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

Definition at line 190 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().

00191 {
00192    RAII_VAR(struct app_cdr_message_payload *, payload,
00193       ao2_alloc(sizeof(*payload), NULL), ao2_cleanup);
00194    char *args;
00195    struct ast_flags flags = { 0 };
00196 
00197    if (!payload) {
00198       return -1;
00199    }
00200 
00201    if (!ast_strlen_zero(data)) {
00202       args = ast_strdupa(data);
00203       ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
00204    }
00205 
00206    payload->channel_name = ast_channel_name(chan);
00207    payload->reset = 1;
00208 
00209    if (ast_test_flag(&flags, AST_CDR_FLAG_DISABLE_ALL)) {
00210       payload->reenable = 1;
00211    }
00212 
00213    if (ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) {
00214       payload->keep_variables = 1;
00215    }
00216 
00217    return publish_app_cdr_message(chan, payload);
00218 }

STASIS_MESSAGE_TYPE_DEFN_LOCAL ( appcdr_message_type   ) 

static int unload_module ( void   )  [static]


Variable Documentation

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

Definition at line 269 of file app_cdr.c.

const char nocdr_app[] = "NoCDR" [static]

Definition at line 103 of file app_cdr.c.

const char resetcdr_app[] = "ResetCDR" [static]

Definition at line 104 of file app_cdr.c.

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

Referenced by resetcdr_exec().


Generated on Thu Apr 16 06:28:20 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6