Wed Oct 28 15:48:04 2009

Asterisk developer's documentation


app_forkcdr.c File Reference

Fork CDR application. More...

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

Include dependency graph for app_forkcdr.c:

Go to the source code of this file.

Functions

static void ast_cdr_fork (struct ast_channel *chan)
char * description (void)
 Provides a description of the module.
static int forkcdr_exec (struct ast_channel *chan, void *data)
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static char * app = "ForkCDR"
static char * descrip
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static char * synopsis
static char * tdesc = "Fork The CDR into 2 separate entities."


Detailed Description

Fork CDR application.

Definition in file app_forkcdr.c.


Function Documentation

static void ast_cdr_fork ( struct ast_channel chan  )  [static]

Definition at line 56 of file app_forkcdr.c.

References ast_cdr_append(), ast_cdr_dup(), AST_CDR_FLAG_CHILD, AST_CDR_FLAG_KEEP_VARS, AST_CDR_FLAG_LOCKED, ast_cdr_free_vars(), ast_cdr_reset(), ast_set_flag, ast_test_flag, ast_channel::cdr, and ast_cdr::next.

Referenced by forkcdr_exec().

00057 {
00058    struct ast_cdr *cdr;
00059    struct ast_cdr *newcdr;
00060    struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
00061 
00062    cdr = chan->cdr;
00063 
00064    while (cdr->next)
00065       cdr = cdr->next;
00066    
00067    if (!(newcdr = ast_cdr_dup(cdr)))
00068       return;
00069    
00070    ast_cdr_append(cdr, newcdr);
00071    ast_cdr_reset(newcdr, &flags);
00072    
00073    if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
00074       ast_cdr_free_vars(cdr, 0);
00075    
00076    ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
00077 }

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 116 of file app_forkcdr.c.

00117 {
00118    return tdesc;
00119 }

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

Definition at line 79 of file app_forkcdr.c.

References AST_CDR_FLAG_KEEP_VARS, ast_cdr_fork(), ast_log(), ast_set2_flag, ast_strlen_zero(), ast_channel::cdr, LOCAL_USER_ADD, LOCAL_USER_REMOVE, and LOG_WARNING.

Referenced by load_module().

00080 {
00081    int res = 0;
00082    struct localuser *u;
00083 
00084    if (!chan->cdr) {
00085       ast_log(LOG_WARNING, "Channel does not have a CDR\n");
00086       return 0;
00087    }
00088 
00089    LOCAL_USER_ADD(u);
00090 
00091    if (!ast_strlen_zero(data))
00092       ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS);
00093    
00094    ast_cdr_fork(chan);
00095 
00096    LOCAL_USER_REMOVE(u);
00097    return res;
00098 }

char* key ( void   ) 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 128 of file app_forkcdr.c.

References ASTERISK_GPL_KEY.

00129 {
00130    return ASTERISK_GPL_KEY;
00131 }

int load_module ( void   ) 

Initialize the module.

This function is called at module load time. Put all code in here that needs to set up your module's hardware, software, registrations, etc.

Returns:
This function should return 0 on success and non-zero on failure. If the module is not loaded successfully, Asterisk will call its unload_module() function.
Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.
TE STUFF END

Definition at line 111 of file app_forkcdr.c.

References ast_register_application(), and forkcdr_exec().

00112 {
00113    return ast_register_application(app, forkcdr_exec, synopsis, descrip);
00114 }

int unload_module ( void   ) 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 100 of file app_forkcdr.c.

References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.

00101 {
00102    int res;
00103 
00104    res = ast_unregister_application(app);
00105 
00106    STANDARD_HANGUP_LOCALUSERS;
00107 
00108    return res; 
00109 }

int usecount ( void   ) 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 121 of file app_forkcdr.c.

References STANDARD_USECOUNT.

00122 {
00123    int res;
00124    STANDARD_USECOUNT(res);
00125    return res;
00126 }


Variable Documentation

char* app = "ForkCDR" [static]

Definition at line 42 of file app_forkcdr.c.

char* descrip [static]

Initial value:

 
"  ForkCDR([options]):  Causes the Call Data Record to fork an additional\n"
   "cdr record starting from the time of the fork call\n"
"If the option 'v' is passed all cdr variables will be passed along also.\n"
""

Definition at line 45 of file app_forkcdr.c.

Definition at line 54 of file app_forkcdr.c.

Definition at line 52 of file app_forkcdr.c.

char* synopsis [static]

Initial value:

 
"Forks the Call Data Record"

Definition at line 43 of file app_forkcdr.c.

char* tdesc = "Fork The CDR into 2 separate entities." [static]

Definition at line 41 of file app_forkcdr.c.


Generated on Wed Oct 28 15:48:05 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6