Thu Oct 8 21:57:31 2009

Asterisk developer's documentation


app_forkcdr.c File Reference

Fork CDR application. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/cdr.h"
#include "asterisk/app.h"
#include "asterisk/module.h"

Include dependency graph for app_forkcdr.c:

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)
}
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('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('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, void *data)
static int load_module (void)
static int unload_module (void)

Variables

static char * app = "ForkCDR"
static char * descrip
static char * synopsis


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 

Definition at line 71 of file app_forkcdr.c.

00071      {
00072    OPT_SETANS =            (1 << 0),
00073    OPT_SETDISP =           (1 << 1),
00074    OPT_RESETDEST =         (1 << 2),
00075    OPT_ENDCDR =            (1 << 3),
00076    OPT_NORESET =           (1 << 4),
00077    OPT_KEEPVARS =          (1 << 5),
00078    OPT_VARSET =            (1 << 6),
00079 };

anonymous enum

Enumerator:
OPT_ARG_VARSET 
OPT_ARG_ARRAY_SIZE 

Definition at line 81 of file app_forkcdr.c.

00081      {
00082    OPT_ARG_VARSET = 0,
00083    /* note: this entry _MUST_ be the last one in the enum */
00084    OPT_ARG_ARRAY_SIZE,
00085 };


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

References ast_cdr::answer, ast_cdr_append(), ast_cdr_dup(), ast_cdr_end(), AST_CDR_FLAG_CHILD, 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_channel::cdr, ast_cdr::disposition, ast_cdr::dstchannel, ast_cdr::next, OPT_ENDCDR, OPT_NORESET, OPT_RESETDEST, OPT_SETANS, OPT_SETDISP, and ast_cdr::start.

Referenced by forkcdr_exec().

00098 {
00099    struct ast_cdr *cdr;
00100    struct ast_cdr *newcdr;
00101    struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
00102 
00103    cdr = chan->cdr;
00104 
00105    while (cdr->next)
00106       cdr = cdr->next;
00107    
00108    if (!(newcdr = ast_cdr_dup(cdr)))
00109       return;
00110    
00111    ast_cdr_append(cdr, newcdr);
00112 
00113    if (!ast_test_flag(&optflags, OPT_NORESET))
00114       ast_cdr_reset(newcdr, &flags);
00115       
00116    if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
00117       ast_cdr_free_vars(cdr, 0);
00118    
00119    if (!ast_strlen_zero(set)) {
00120       char *varname = ast_strdupa(set), *varval;
00121       varval = strchr(varname,'=');
00122       if (varval) {
00123          *varval = 0;
00124          varval++;
00125          ast_cdr_setvar(cdr, varname, varval, 0);
00126       }
00127    }
00128    
00129    if (ast_test_flag(&optflags, OPT_SETANS) && !ast_tvzero(cdr->answer))
00130       newcdr->answer = newcdr->start;
00131 
00132    if (ast_test_flag(&optflags, OPT_SETDISP))
00133       newcdr->disposition = cdr->disposition;
00134    
00135    if (ast_test_flag(&optflags, OPT_RESETDEST))
00136       newcdr->dstchannel[0] = 0;
00137    
00138    if (ast_test_flag(&optflags, OPT_ENDCDR))
00139       ast_cdr_end(cdr);
00140 
00141    ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
00142 }

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Fork The CDR into 2 separate entities"   
)

static int forkcdr_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 144 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_module_user_add, ast_module_user_remove, ast_set2_flag, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_channel::cdr, LOG_WARNING, OPT_ARG_ARRAY_SIZE, OPT_ARG_VARSET, and OPT_KEEPVARS.

Referenced by load_module().

00145 {
00146    int res = 0;
00147    struct ast_module_user *u;
00148    char *argcopy = NULL;
00149    struct ast_flags flags = {0};
00150    char *opts[OPT_ARG_ARRAY_SIZE];
00151    AST_DECLARE_APP_ARGS(arglist,
00152       AST_APP_ARG(options);
00153    );
00154 
00155    if (!chan->cdr) {
00156       ast_log(LOG_WARNING, "Channel does not have a CDR\n");
00157       return 0;
00158    }
00159 
00160    u = ast_module_user_add(chan);
00161 
00162    argcopy = ast_strdupa(data);
00163 
00164    AST_STANDARD_APP_ARGS(arglist, argcopy);
00165 
00166    if (!ast_strlen_zero(arglist.options)) {
00167       ast_app_parse_options(forkcdr_exec_options, &flags, opts, arglist.options);
00168    } else
00169       opts[OPT_ARG_VARSET] = 0;
00170    
00171    if (!ast_strlen_zero(data))
00172       ast_set2_flag(chan->cdr, ast_test_flag(&flags, OPT_KEEPVARS), AST_CDR_FLAG_KEEP_VARS);
00173    
00174    ast_cdr_fork(chan, flags, opts[OPT_ARG_VARSET]);
00175 
00176    ast_module_user_remove(u);
00177    return res;
00178 }

static int load_module ( void   )  [static]

Definition at line 191 of file app_forkcdr.c.

References ast_register_application(), and forkcdr_exec().

00192 {
00193    return ast_register_application(app, forkcdr_exec, synopsis, descrip);
00194 }

static int unload_module ( void   )  [static]

Definition at line 180 of file app_forkcdr.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00181 {
00182    int res;
00183 
00184    res = ast_unregister_application(app);
00185 
00186    ast_module_user_hangup_all();
00187 
00188    return res; 
00189 }


Variable Documentation

char* app = "ForkCDR" [static]

Definition at line 46 of file app_forkcdr.c.

char* descrip [static]

Definition at line 49 of file app_forkcdr.c.

char* synopsis [static]

Initial value:

 
"Forks the Call Data Record"

Definition at line 47 of file app_forkcdr.c.


Generated on Thu Oct 8 21:57:31 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.8