Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:48:24 2009

## Asterisk developer's documentation

# cdr_manager.c File Reference

Asterisk Call Manager CDR records. More...

`#include <sys/types.h>`
`#include <strings.h>`
`#include <unistd.h>`
`#include <time.h>`
`#include "asterisk.h"`
`#include "asterisk/channel.h"`
`#include "asterisk/cdr.h"`
`#include "asterisk/module.h"`
`#include "asterisk/logger.h"`
`#include "asterisk/utils.h"`
`#include "asterisk/manager.h"`
`#include "asterisk/config.h"`

Include dependency graph for cdr_manager.c:

Go to the source code of this file.

## Defines

#define | CONF_FILE "cdr_manager.conf"
#define | DATE_FORMAT "%Y-%m-%d %T"

## Functions

char * | description (void)
| Provides a description of the module.
char * | key ()
| Returns the ASTERISK_GPL_KEY.
int | load_module (void)
| Initialize the module.
static void | loadconfigurationfile (void)
static int | manager_log (struct ast_cdr *cdr)
int | reload (void)
| Reload stuff.
int | unload_module (void)
| Cleanup all module structures, sockets, etc.
int | usecount (void)
| Provides a usecount.

## Variables

static char * | desc = "Asterisk Call Manager CDR Backend"
static int | enablecdr = 0
static char * | name = "cdr_manager"

## Detailed Description

Asterisk Call Manager CDR records.

See also

- CDR - Call Data Records and billing
- AMI - The Manager Interface
- AMI configuration

Definition in file cdr_manager.c.

## Define Documentation

#define CONF_FILE "cdr_manager.conf"

Definition at line 46 of file cdr_manager.c.

Referenced by loadconfigurationfile().

#define DATE_FORMAT "%Y-%m-%d %T"

Definition at line 45 of file cdr_manager.c.

## Function Documentation

char* description | ( | void |  | ) |

Provides a description of the module.

Returns:
  a short description of your module

Definition at line 138 of file cdr_manager.c.

    00139 {
    00140    return desc;
    00141 }

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 175 of file cdr_manager.c.

References ASTERISK_GPL_KEY.

    00176 {
    00177    return ASTERISK_GPL_KEY;
    00178 }

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 149 of file cdr_manager.c.

References ast_cdr_register(), ast_log(), loadconfigurationfile(), LOG_ERROR, and manager_log().

    00150 {
    00151    int res;
    00152
    00153    /* Configuration file */
    00154    loadconfigurationfile();
    00155
    00156    res = ast_cdr_register(name, desc, manager_log);
    00157    if (res) {
    00158       ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CDR handling\n");
    00159    }
    00160
    00161    return res;
    00162 }

static void loadconfigurationfile | ( | void |  | ) | `[static]`

Definition at line 53 of file cdr_manager.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_true(), ast_variable_browse(), cfg, CONF_FILE, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by load_module(), and reload().

    00054 {
    00055    char *cat;
    00056    struct ast_config *cfg;
    00057    struct ast_variable *v;
    00058
    00059    cfg = ast_config_load(CONF_FILE);
    00060    if (!cfg) {
    00061       /* Standard configuration */
    00062       enablecdr = 0;
    00063       return;
    00064    }
    00065
    00066    cat = ast_category_browse(cfg, NULL);
    00067    while (cat) {
    00068       if (!strcasecmp(cat, "general")) {
    00069          v = ast_variable_browse(cfg, cat);
    00070          while (v) {
    00071             if (!strcasecmp(v->name, "enabled")) {
    00072                enablecdr = ast_true(v->value);
    00073             }
    00074
    00075             v = v->next;
    00076          }
    00077       }
    00078
    00079       /* Next category */
    00080       cat = ast_category_browse(cfg, cat);
    00081    }
    00082
    00083    ast_config_destroy(cfg);
    00084 }

static int manager_log | ( | struct ast_cdr * | cdr | ) | `[static]`

Definition at line 86 of file cdr_manager.c.

References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_cdr::billsec, ast_cdr::channel, ast_cdr::clid, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, EVENT_FLAG_CALL, ast_cdr::lastapp, ast_cdr::lastdata, manager_event(), ast_cdr::src, ast_cdr::start, t, ast_cdr::uniqueid, and ast_cdr::userfield.

Referenced by load_module().

    00087 {
    00088    time_t t;
    00089    struct tm timeresult;
    00090    char strStartTime[80] = "";
    00091    char strAnswerTime[80] = "";
    00092    char strEndTime[80] = "";
    00093
    00094    if (!enablecdr)
    00095       return 0;
    00096
    00097    t = cdr->start.tv_sec;
    00098    localtime_r(&t, &timeresult);
    00099    strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
    00100
    00101    if (cdr->answer.tv_sec) {
    00102          t = cdr->answer.tv_sec;
    00103          localtime_r(&t, &timeresult);
    00104       strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
    00105    }
    00106
    00107    t = cdr->end.tv_sec;
    00108    localtime_r(&t, &timeresult);
    00109    strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
    00110
    00111    manager_event(EVENT_FLAG_CALL, "Cdr",
    00112        "AccountCode: %s\r\n"
    00113        "Source: %s\r\n"
    00114        "Destination: %s\r\n"
    00115        "DestinationContext: %s\r\n"
    00116        "CallerID: %s\r\n"
    00117        "Channel: %s\r\n"
    00118        "DestinationChannel: %s\r\n"
    00119        "LastApplication: %s\r\n"
    00120        "LastData: %s\r\n"
    00121        "StartTime: %s\r\n"
    00122        "AnswerTime: %s\r\n"
    00123        "EndTime: %s\r\n"
    00124        "Duration: %ld\r\n"
    00125        "BillableSeconds: %ld\r\n"
    00126        "Disposition: %s\r\n"
    00127        "AMAFlags: %s\r\n"
    00128        "UniqueID: %s\r\n"
    00129        "UserField: %s\r\n",
    00130        cdr->accountcode, cdr->src, cdr->dst, cdr->dcontext, cdr->clid, cdr->channel,
    00131        cdr->dstchannel, cdr->lastapp, cdr->lastdata, strStartTime, strAnswerTime, strEndTime,
    00132        cdr->duration, cdr->billsec, ast_cdr_disp2str(cdr->disposition),
    00133        ast_cdr_flags2str(cdr->amaflags), cdr->uniqueid, cdr->userfield);
    00134
    00135    return 0;
    00136 }

int reload | ( | void |  | ) |

Reload stuff.

This function is where any reload routines take place. Re-read config files, change signalling, whatever is appropriate on a reload.

Returns:
  The return value is not used.

Definition at line 164 of file cdr_manager.c.

References loadconfigurationfile().

    00165 {
    00166    loadconfigurationfile();
    00167    return 0;
    00168 }

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 143 of file cdr_manager.c.

References ast_cdr_unregister().

    00144 {
    00145    ast_cdr_unregister(name);
    00146    return 0;
    00147 }

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 170 of file cdr_manager.c.

    00171 {
    00172    return 0;
    00173 }

## Variable Documentation

char* desc = "Asterisk Call Manager CDR Backend"`[static]`

Definition at line 48 of file cdr_manager.c.

int enablecdr = 0`[static]`

Definition at line 51 of file cdr_manager.c.

char* name = "cdr_manager"`[static]`

Definition at line 49 of file cdr_manager.c.