Mon Aug 31 12:30:15 2015

Asterisk developer's documentation


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"

Go to the source code of this file.

Enumerations

enum  {
  OPT_SETANS = (1 << 0), OPT_SETDISP = (1 << 1), OPT_RESETDEST = (1 << 2), OPT_ENDCDR = (1 << 3),
  OPT_NORESET = (1 << 4), OPT_KEEPVARS = (1 << 5), OPT_VARSET = (1 << 6), OPT_ANSLOCK = (1 << 7),
  OPT_DONTOUCH = (1 << 8)
}
enum  { OPT_ARG_VARSET = 0, OPT_ARG_ARRAY_SIZE }

Functions

 AST_APP_OPTIONS (forkcdr_exec_options,{AST_APP_OPTION('a', OPT_SETANS), AST_APP_OPTION('A', OPT_ANSLOCK), AST_APP_OPTION('d', OPT_SETDISP), AST_APP_OPTION('D', OPT_RESETDEST), AST_APP_OPTION('e', OPT_ENDCDR), AST_APP_OPTION('R', OPT_NORESET), AST_APP_OPTION_ARG('s', OPT_VARSET, OPT_ARG_VARSET), AST_APP_OPTION('T', OPT_DONTOUCH), AST_APP_OPTION('v', OPT_KEEPVARS),})
static void ast_cdr_fork (struct ast_channel *chan, struct ast_flags optflags, char *set)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Fork The CDR into 2 separate entities")
static int forkcdr_exec (struct ast_channel *chan, const char *data)
static int load_module (void)
static int unload_module (void)

Variables

static char * app = "ForkCDR"

Detailed Description

Fork CDR application.

Author:
Anthony Minessale anthmct@yahoo.com
Note:
Development of this app Sponsored/Funded by TAAN Softworks Corp

Definition in file app_forkcdr.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
OPT_SETANS 
OPT_SETDISP 
OPT_RESETDEST 
OPT_ENDCDR 
OPT_NORESET 
OPT_KEEPVARS 
OPT_VARSET 
OPT_ANSLOCK 
OPT_DONTOUCH 

Definition at line 150 of file app_forkcdr.c.

00150      {
00151    OPT_SETANS =            (1 << 0),
00152    OPT_SETDISP =           (1 << 1),
00153    OPT_RESETDEST =         (1 << 2),
00154    OPT_ENDCDR =            (1 << 3),
00155    OPT_NORESET =           (1 << 4),
00156    OPT_KEEPVARS =          (1 << 5),
00157    OPT_VARSET =            (1 << 6),
00158    OPT_ANSLOCK =           (1 << 7),
00159    OPT_DONTOUCH =          (1 << 8),
00160 };

anonymous enum
Enumerator:
OPT_ARG_VARSET 
OPT_ARG_ARRAY_SIZE 

Definition at line 162 of file app_forkcdr.c.

00162      {
00163    OPT_ARG_VARSET = 0,
00164    /* note: this entry _MUST_ be the last one in the enum */
00165    OPT_ARG_ARRAY_SIZE,
00166 };


Function Documentation

AST_APP_OPTIONS ( forkcdr_exec_options   ) 
static void ast_cdr_fork ( struct ast_channel chan,
struct ast_flags  optflags,
char *  set 
) [static]

Definition at line 180 of file app_forkcdr.c.

References ast_cdr::answer, ast_cdr_append(), ast_cdr_dup_unique(), ast_cdr_end(), AST_CDR_FLAG_ANSLOCKED, AST_CDR_FLAG_CHILD, AST_CDR_FLAG_DONT_TOUCH, AST_CDR_FLAG_KEEP_VARS, AST_CDR_FLAG_LOCKED, ast_cdr_free_vars(), ast_cdr_reset(), ast_cdr_setvar(), ast_set_flag, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tvzero(), ast_channel::cdr, ast_cdr::disposition, ast_cdr::dstchannel, ast_cdr::next, OPT_ANSLOCK, OPT_DONTOUCH, OPT_ENDCDR, OPT_NORESET, OPT_RESETDEST, OPT_SETANS, OPT_SETDISP, and ast_cdr::start.

Referenced by forkcdr_exec().

00181 {
00182    struct ast_cdr *cdr;
00183    struct ast_cdr *newcdr;
00184    struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
00185 
00186    cdr = chan->cdr;
00187 
00188    while (cdr->next)
00189       cdr = cdr->next;
00190    
00191    if (!(newcdr = ast_cdr_dup_unique(cdr)))
00192       return;
00193    
00194    /*
00195     * End the original CDR if requested BEFORE appending the new CDR
00196     * otherwise we incorrectly end the new CDR also.
00197     */
00198    if (ast_test_flag(&optflags, OPT_ENDCDR)) {
00199       ast_cdr_end(cdr);
00200    }
00201 
00202    ast_cdr_append(cdr, newcdr);
00203 
00204    if (!ast_test_flag(&optflags, OPT_NORESET))
00205       ast_cdr_reset(newcdr, &flags);
00206       
00207    if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
00208       ast_cdr_free_vars(cdr, 0);
00209    
00210    if (!ast_strlen_zero(set)) {
00211       char *varname = ast_strdupa(set), *varval;
00212       varval = strchr(varname,'=');
00213       if (varval) {
00214          *varval = 0;
00215          varval++;
00216          ast_cdr_setvar(cdr, varname, varval, 0);
00217       }
00218    }
00219    
00220    if (ast_test_flag(&optflags, OPT_SETANS) && !ast_tvzero(cdr->answer))
00221       newcdr->answer = newcdr->start;
00222 
00223    if (ast_test_flag(&optflags, OPT_SETDISP))
00224       newcdr->disposition = cdr->disposition;
00225    
00226    if (ast_test_flag(&optflags, OPT_RESETDEST))
00227       newcdr->dstchannel[0] = 0;
00228    
00229    if (ast_test_flag(&optflags, OPT_ANSLOCK))
00230       ast_set_flag(cdr, AST_CDR_FLAG_ANSLOCKED);
00231    
00232    if (ast_test_flag(&optflags, OPT_DONTOUCH))
00233       ast_set_flag(cdr, AST_CDR_FLAG_DONT_TOUCH);
00234       
00235    ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
00236 }

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Fork The CDR into 2 separate entities"   
)
static int forkcdr_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 238 of file app_forkcdr.c.

References AST_APP_ARG, ast_app_parse_options(), AST_CDR_FLAG_KEEP_VARS, ast_cdr_fork(), AST_DECLARE_APP_ARGS, ast_log(), ast_set2_flag, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_channel::cdr, LOG_WARNING, ast_cdr::next, OPT_ARG_ARRAY_SIZE, OPT_ARG_VARSET, and OPT_KEEPVARS.

Referenced by load_module().

00239 {
00240    int res = 0;
00241    char *argcopy = NULL;
00242    struct ast_cdr *cdr;
00243    struct ast_flags flags = {0};
00244    char *opts[OPT_ARG_ARRAY_SIZE];
00245    AST_DECLARE_APP_ARGS(arglist,
00246       AST_APP_ARG(options);
00247    );
00248 
00249    if (!(cdr = chan->cdr)) {
00250       ast_log(LOG_WARNING, "Channel does not have a CDR\n");
00251       return 0;
00252    }
00253 
00254    argcopy = ast_strdupa(data);
00255 
00256    AST_STANDARD_APP_ARGS(arglist, argcopy);
00257 
00258    opts[OPT_ARG_VARSET] = 0;
00259 
00260    if (!ast_strlen_zero(arglist.options))
00261       ast_app_parse_options(forkcdr_exec_options, &flags, opts, arglist.options);
00262 
00263    if (!ast_strlen_zero(data)) {
00264       int keepvars = ast_test_flag(&flags, OPT_KEEPVARS) ? 1 : 0;
00265       while (cdr->next) {
00266          cdr = cdr->next;
00267       }
00268       ast_set2_flag(cdr, keepvars, AST_CDR_FLAG_KEEP_VARS);
00269    }
00270    
00271    ast_cdr_fork(chan, flags, opts[OPT_ARG_VARSET]);
00272 
00273    return res;
00274 }

static int load_module ( void   )  [static]

Definition at line 281 of file app_forkcdr.c.

References ast_register_application_xml, and forkcdr_exec().

00282 {
00283    return ast_register_application_xml(app, forkcdr_exec);
00284 }

static int unload_module ( void   )  [static]

Definition at line 276 of file app_forkcdr.c.

References ast_unregister_application().

00277 {
00278    return ast_unregister_application(app);
00279 }


Variable Documentation

char* app = "ForkCDR" [static]

Definition at line 148 of file app_forkcdr.c.


Generated on 31 Aug 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1