Mon Apr 30 07:39:14 2007

Asterisk developer's documentation


cdr.h File Reference

Call Detail Record API. More...

#include <sys/time.h>
#include "asterisk/channel.h"
#include "asterisk/utils.h"

Include dependency graph for cdr.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_cdr

Defines

#define AST_CDR_ANSWERED   (1 << 3)
#define AST_CDR_BILLING   (2)
#define AST_CDR_BUSY   (1 << 1)
#define AST_CDR_DOCUMENTATION   (3)
#define AST_CDR_FAILED   (1 << 2)
#define AST_CDR_FLAG_CHILD   (1 << 3)
#define AST_CDR_FLAG_KEEP_VARS   (1 << 0)
#define AST_CDR_FLAG_LOCKED   (1 << 2)
#define AST_CDR_FLAG_POST_DISABLED   (1 << 4)
#define AST_CDR_FLAG_POSTED   (1 << 1)
#define AST_CDR_NOANSWER   (1 << 0)
#define AST_CDR_OMIT   (1)
#define AST_MAX_ACCOUNT_CODE   20
#define AST_MAX_USER_FIELD   256

Typedefs

typedef int(*) ast_cdrbe (struct ast_cdr *cdr)

Functions

ast_cdrast_cdr_alloc (void)
 Allocate a CDR record Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure).
int ast_cdr_amaflags2int (const char *flag)
void ast_cdr_answer (struct ast_cdr *cdr)
ast_cdrast_cdr_append (struct ast_cdr *cdr, struct ast_cdr *newcdr)
int ast_cdr_appenduserfield (struct ast_channel *chan, const char *userfield)
void ast_cdr_busy (struct ast_cdr *cdr)
int ast_cdr_copy_vars (struct ast_cdr *to_cdr, struct ast_cdr *from_cdr)
void ast_cdr_detach (struct ast_cdr *cdr)
void ast_cdr_discard (struct ast_cdr *cdr)
 Discard and free a CDR record.
char * ast_cdr_disp2str (int disposition)
int ast_cdr_disposition (struct ast_cdr *cdr, int cause)
ast_cdrast_cdr_dup (struct ast_cdr *cdr)
 Duplicate a record Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure).
void ast_cdr_end (struct ast_cdr *cdr)
int ast_cdr_engine_init (void)
int ast_cdr_engine_reload (void)
void ast_cdr_engine_term (void)
void ast_cdr_failed (struct ast_cdr *cdr)
char * ast_cdr_flags2str (int flags)
void ast_cdr_free (struct ast_cdr *cdr)
 Free a CDR record.
void ast_cdr_free_vars (struct ast_cdr *cdr, int recur)
void ast_cdr_getvar (struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw)
int ast_cdr_init (struct ast_cdr *cdr, struct ast_channel *chan)
 Initialize based on a channel.
void ast_cdr_merge (struct ast_cdr *to, struct ast_cdr *from)
int ast_cdr_register (const char *name, const char *desc, ast_cdrbe be)
void ast_cdr_reset (struct ast_cdr *cdr, struct ast_flags *flags)
int ast_cdr_serialize_variables (struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur)
int ast_cdr_setaccount (struct ast_channel *chan, const char *account)
int ast_cdr_setamaflags (struct ast_channel *chan, const char *amaflags)
void ast_cdr_setapp (struct ast_cdr *cdr, char *app, char *data)
int ast_cdr_setcid (struct ast_cdr *cdr, struct ast_channel *chan)
void ast_cdr_setdestchan (struct ast_cdr *cdr, const char *chan)
int ast_cdr_setuserfield (struct ast_channel *chan, const char *userfield)
int ast_cdr_setvar (struct ast_cdr *cdr, const char *name, const char *value, int recur)
void ast_cdr_start (struct ast_cdr *cdr)
void ast_cdr_submit_batch (int shutdown)
void ast_cdr_unregister (const char *name)
int ast_cdr_update (struct ast_channel *chan)

Variables

char ast_default_accountcode [AST_MAX_ACCOUNT_CODE]
int ast_default_amaflags


Detailed Description

Call Detail Record API.

Definition in file cdr.h.


Define Documentation

#define AST_CDR_ANSWERED   (1 << 3)

Definition at line 36 of file cdr.h.

Referenced by ast_cdr_answer(), ast_cdr_disp2str(), and ast_cdr_init().

#define AST_CDR_BILLING   (2)

Definition at line 40 of file cdr.h.

Referenced by ast_cdr_amaflags2int(), and ast_cdr_flags2str().

#define AST_CDR_BUSY   (1 << 1)

Definition at line 34 of file cdr.h.

Referenced by ast_cdr_busy(), and ast_cdr_disp2str().

#define AST_CDR_DOCUMENTATION   (3)

Definition at line 41 of file cdr.h.

Referenced by ast_cdr_amaflags2int(), and ast_cdr_flags2str().

#define AST_CDR_FAILED   (1 << 2)

Definition at line 35 of file cdr.h.

Referenced by ast_cdr_disp2str(), ast_cdr_end(), and ast_cdr_failed().

#define AST_CDR_FLAG_CHILD   (1 << 3)

Definition at line 30 of file cdr.h.

Referenced by ast_cdr_fork(), and ast_cdr_merge().

#define AST_CDR_FLAG_KEEP_VARS   (1 << 0)

Definition at line 27 of file cdr.h.

Referenced by ast_cdr_fork(), ast_cdr_merge(), ast_cdr_reset(), and forkcdr_exec().

#define AST_CDR_FLAG_LOCKED   (1 << 2)

Definition at line 29 of file cdr.h.

Referenced by ast_cdr_appenduserfield(), ast_cdr_busy(), ast_cdr_failed(), ast_cdr_fork(), ast_cdr_init(), ast_cdr_merge(), ast_cdr_reset(), ast_cdr_setaccount(), ast_cdr_setapp(), ast_cdr_setcid(), ast_cdr_setdestchan(), ast_cdr_setuserfield(), ast_cdr_start(), and ast_cdr_update().

#define AST_CDR_FLAG_POST_DISABLED   (1 << 4)

Definition at line 31 of file cdr.h.

Referenced by ast_cdr_detach(), ast_cdr_free(), ast_cdr_merge(), nocdr_exec(), and post_cdr().

#define AST_CDR_FLAG_POSTED   (1 << 1)

Definition at line 28 of file cdr.h.

Referenced by ast_cdr_free(), ast_cdr_merge(), ast_cdr_reset(), check_post(), disa_exec(), and post_cdr().

#define AST_CDR_NOANSWER   (1 << 0)

Definition at line 33 of file cdr.h.

Referenced by ast_cdr_disp2str(), ast_cdr_init(), ast_cdr_merge(), and ast_cdr_reset().

#define AST_CDR_OMIT   (1)

AMA Flags

Definition at line 39 of file cdr.h.

Referenced by ast_cdr_amaflags2int(), and ast_cdr_flags2str().

#define AST_MAX_ACCOUNT_CODE   20

Definition at line 44 of file cdr.h.

#define AST_MAX_USER_FIELD   256

Definition at line 43 of file cdr.h.


Typedef Documentation

typedef int(*) ast_cdrbe(struct ast_cdr *cdr)

Definition at line 103 of file cdr.h.


Function Documentation

struct ast_cdr* ast_cdr_alloc ( void   ) 

Allocate a CDR record Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure).

Definition at line 464 of file cdr.c.

References ast_calloc, ast_log(), and LOG_ERROR.

Referenced by __agent_start_monitoring(), __ast_pbx_run(), __ast_read(), __ast_request_and_dial(), ast_bridge_call(), ast_cdr_dup(), ast_feature_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), builtin_blindtransfer(), clear_caller(), findmeexec(), and start_monitor_exec().

00465 {
00466    struct ast_cdr *x = ast_calloc(1, sizeof(struct ast_cdr));
00467    if (!x)
00468       ast_log(LOG_ERROR,"Allocation Failure for a CDR!\n");
00469    return x;
00470 }

int ast_cdr_amaflags2int ( const char *  flag  ) 

Parameters:
flag string form of flag Converts the string form of the flag to the binary form. Returns the binary form of the flag

Definition at line 891 of file cdr.c.

References AST_CDR_BILLING, AST_CDR_DOCUMENTATION, and AST_CDR_OMIT.

Referenced by ast_cdr_setamaflags(), build_device(), build_gateway(), build_peer(), build_user(), process_zap(), and set_config().

00892 {
00893    if (!strcasecmp(flag, "default"))
00894       return 0;
00895    if (!strcasecmp(flag, "omit"))
00896       return AST_CDR_OMIT;
00897    if (!strcasecmp(flag, "billing"))
00898       return AST_CDR_BILLING;
00899    if (!strcasecmp(flag, "documentation"))
00900       return AST_CDR_DOCUMENTATION;
00901    return -1;
00902 }

void ast_cdr_answer ( struct ast_cdr cdr  ) 

Parameters:
cdr the cdr you wish to associate with the call Starts all CDR stuff necessary for doing CDR when answering a call NULL argument is just fine.

Definition at line 638 of file cdr.c.

References ast_cdr::answer, AST_CDR_ANSWERED, check_post(), ast_cdr::disposition, and ast_cdr::next.

Referenced by __ast_read(), and ast_answer().

00639 {
00640 
00641    for (; cdr; cdr = cdr->next) {
00642       check_post(cdr);
00643       if (cdr->disposition < AST_CDR_ANSWERED)
00644          cdr->disposition = AST_CDR_ANSWERED;
00645       if (ast_tvzero(cdr->answer))
00646          cdr->answer = ast_tvnow();
00647    }
00648 }

struct ast_cdr* ast_cdr_append ( struct ast_cdr cdr,
struct ast_cdr newcdr 
)

Definition at line 964 of file cdr.c.

References ast_cdr::next.

Referenced by ast_cdr_fork(), ast_cdr_merge(), and attempt_transfer().

00965 {
00966    struct ast_cdr *ret;
00967 
00968    if (cdr) {
00969       ret = cdr;
00970 
00971       while (cdr->next)
00972          cdr = cdr->next;
00973       cdr->next = newcdr;
00974    } else {
00975       ret = newcdr;
00976    }
00977 
00978    return ret;
00979 }

int ast_cdr_appenduserfield ( struct ast_channel chan,
const char *  userfield 
)

Definition at line 858 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, ast_channel::cdr, len, ast_cdr::next, and ast_cdr::userfield.

Referenced by action_setcdruserfield(), appendcdruserfield_exec(), and ast_bridge_call().

00859 {
00860    struct ast_cdr *cdr = chan->cdr;
00861 
00862    for ( ; cdr ; cdr = cdr->next) {
00863       int len = strlen(cdr->userfield);
00864 
00865       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
00866          ast_copy_string(cdr->userfield + len, userfield, sizeof(cdr->userfield) - len);
00867    }
00868 
00869    return 0;
00870 }

void ast_cdr_busy ( struct ast_cdr cdr  ) 

Parameters:
cdr the cdr you wish to associate with the call Returns nothing

Definition at line 650 of file cdr.c.

References AST_CDR_BUSY, AST_CDR_FLAG_LOCKED, ast_test_flag, check_post(), and ast_cdr::next.

Referenced by ast_cdr_disposition(), and ring_entry().

00651 {
00652 
00653    for (; cdr; cdr = cdr->next) {
00654       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00655          check_post(cdr);
00656          if (cdr->disposition < AST_CDR_BUSY)
00657             cdr->disposition = AST_CDR_BUSY;
00658       }
00659    }
00660 }

int ast_cdr_copy_vars ( struct ast_cdr to_cdr,
struct ast_cdr from_cdr 
)

Definition at line 333 of file cdr.c.

References AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, ast_strlen_zero(), ast_var_assign(), ast_var_name(), ast_var_value(), var, and ast_cdr::varshead.

Referenced by ast_cdr_dup().

00334 {
00335    struct ast_var_t *variables, *newvariable = NULL;
00336    struct varshead *headpa, *headpb;
00337    const char *var, *val;
00338    int x = 0;
00339 
00340    if (!to_cdr || !from_cdr) /* don't die if one of the pointers is null */
00341       return 0;
00342 
00343    headpa = &from_cdr->varshead;
00344    headpb = &to_cdr->varshead;
00345 
00346    AST_LIST_TRAVERSE(headpa,variables,entries) {
00347       if (variables &&
00348           (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
00349           !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
00350          newvariable = ast_var_assign(var, val);
00351          AST_LIST_INSERT_HEAD(headpb, newvariable, entries);
00352          x++;
00353       }
00354    }
00355 
00356    return x;
00357 }

void ast_cdr_detach ( struct ast_cdr cdr  ) 

Parameters:
cdr Which CDR to detach from the channel thread Prevents the channel thread from blocking on the CDR handling Returns nothing

Definition at line 1076 of file cdr.c.

References ast_calloc, AST_CDR_FLAG_POST_DISABLED, ast_cdr_free(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, batch, batchmode, batchsize, ast_cdr_batch_item::cdr, enabled, ast_cdr_batch::head, init_batch(), LOG_DEBUG, ast_cdr_batch_item::next, option_debug, post_cdr(), ast_cdr_batch::size, submit_unscheduled_batch(), and ast_cdr_batch::tail.

Referenced by ast_cdr_reset(), ast_hangup(), and ast_pbx_outgoing_cdr_failed().

01077 {
01078    struct ast_cdr_batch_item *newtail;
01079    int curr;
01080 
01081    if (!cdr)
01082       return;
01083 
01084    /* maybe they disabled CDR stuff completely, so just drop it */
01085    if (!enabled) {
01086       if (option_debug)
01087          ast_log(LOG_DEBUG, "Dropping CDR !\n");
01088       ast_set_flag(cdr, AST_CDR_FLAG_POST_DISABLED);
01089       ast_cdr_free(cdr);
01090       return;
01091    }
01092 
01093    /* post stuff immediately if we are not in batch mode, this is legacy behaviour */
01094    if (!batchmode) {
01095       post_cdr(cdr);
01096       ast_cdr_free(cdr);
01097       return;
01098    }
01099 
01100    /* otherwise, each CDR gets put into a batch list (at the end) */
01101    if (option_debug)
01102       ast_log(LOG_DEBUG, "CDR detaching from this thread\n");
01103 
01104    /* we'll need a new tail for every CDR */
01105    if (!(newtail = ast_calloc(1, sizeof(*newtail)))) {
01106       post_cdr(cdr);
01107       ast_cdr_free(cdr);
01108       return;
01109    }
01110 
01111    /* don't traverse a whole list (just keep track of the tail) */
01112    ast_mutex_lock(&cdr_batch_lock);
01113    if (!batch)
01114       init_batch();
01115    if (!batch->head) {
01116       /* new batch is empty, so point the head at the new tail */
01117       batch->head = newtail;
01118    } else {
01119       /* already got a batch with something in it, so just append a new tail */
01120       batch->tail->next = newtail;
01121    }
01122    newtail->cdr = cdr;
01123    batch->tail = newtail;
01124    curr = batch->size++;
01125    ast_mutex_unlock(&cdr_batch_lock);
01126 
01127    /* if we have enough stuff to post, then do it */
01128    if (curr >= (batchsize - 1))
01129       submit_unscheduled_batch();
01130 }

void ast_cdr_discard ( struct ast_cdr cdr  ) 

Discard and free a CDR record.

Parameters:
cdr ast_cdr structure to free Returns nothing -- same as free, but no checks or complaints

Definition at line 453 of file cdr.c.

References ast_cdr_free_vars(), free, and ast_cdr::next.

Referenced by ast_bridge_call().

00454 {
00455    while (cdr) {
00456       struct ast_cdr *next = cdr->next;
00457 
00458       ast_cdr_free_vars(cdr, 0);
00459       free(cdr);
00460       cdr = next;
00461    }
00462 }

char* ast_cdr_disp2str ( int  disposition  ) 

Parameters:
disposition input binary form Converts the binary form of a disposition to string form. Returns a pointer to the string form

Definition at line 792 of file cdr.c.

References AST_CDR_ANSWERED, AST_CDR_BUSY, AST_CDR_FAILED, and AST_CDR_NOANSWER.

Referenced by ast_cdr_getvar(), build_csv_record(), build_radius_record(), csv_log(), manager_log(), mysql_log(), odbc_log(), pgsql_log(), and tds_log().

00793 {
00794    switch (disposition) {
00795    case AST_CDR_NOANSWER:
00796       return "NO ANSWER";
00797    case AST_CDR_FAILED:
00798       return "FAILED";     
00799    case AST_CDR_BUSY:
00800       return "BUSY";    
00801    case AST_CDR_ANSWERED:
00802       return "ANSWERED";
00803    }
00804    return "UNKNOWN";
00805 }

int ast_cdr_disposition ( struct ast_cdr cdr,
int  cause 
)

Parameters:
cdr the cdr you wish to associate with the call Returns nothing
cause the AST_CAUSE_*

Definition at line 673 of file cdr.c.

References AST_CAUSE_BUSY, AST_CAUSE_FAILURE, AST_CAUSE_NORMAL, AST_CAUSE_NOTDEFINED, ast_cdr_busy(), ast_cdr_failed(), ast_log(), LOG_WARNING, and ast_cdr::next.

Referenced by __ast_request_and_dial(), ast_feature_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), clear_caller(), and findmeexec().

00674 {
00675    int res = 0;
00676 
00677    for (; cdr; cdr = cdr->next) {
00678       switch(cause) {
00679       case AST_CAUSE_BUSY:
00680          ast_cdr_busy(cdr);
00681          break;
00682       case AST_CAUSE_FAILURE:
00683          ast_cdr_failed(cdr);
00684          break;
00685       case AST_CAUSE_NORMAL:
00686          break;
00687       case AST_CAUSE_NOTDEFINED:
00688          res = -1;
00689          break;
00690       default:
00691          res = -1;
00692          ast_log(LOG_WARNING, "Cause not handled\n");
00693       }
00694    }
00695    return res;
00696 }

struct ast_cdr* ast_cdr_dup ( struct ast_cdr cdr  ) 

Duplicate a record Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure).

Duplicate a CDR record

Returns:
Pointer to new CDR record

Definition at line 167 of file cdr.c.

References ast_cdr_alloc(), and ast_cdr_copy_vars().

Referenced by ast_async_goto(), ast_cdr_fork(), and ast_cdr_reset().

00168 {
00169    struct ast_cdr *newcdr;
00170    
00171    if (!cdr) /* don't die if we get a null cdr pointer */
00172       return NULL;
00173    newcdr = ast_cdr_alloc();
00174    if (!newcdr)
00175       return NULL;
00176 
00177    memcpy(newcdr, cdr, sizeof(*newcdr));
00178    /* The varshead is unusable, volatile even, after the memcpy so we take care of that here */
00179    memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
00180    ast_cdr_copy_vars(newcdr, cdr);
00181    newcdr->next = NULL;
00182 
00183    return newcdr;
00184 }

void ast_cdr_end ( struct ast_cdr cdr  ) 

Parameters:
cdr the cdr you have associated the call with Registers the end of call time in the cdr structure. Returns nothing

Definition at line 777 of file cdr.c.

References ast_cdr::answer, AST_CDR_FAILED, ast_log(), ast_cdr::billsec, ast_cdr::channel, check_post(), ast_cdr::disposition, ast_cdr::duration, ast_cdr::end, LOG_WARNING, ast_cdr::next, S_OR, and ast_cdr::start.

Referenced by __ast_read(), __ast_request_and_dial(), ast_cdr_reset(), ast_feature_request_and_dial(), ast_hangup(), ast_pbx_outgoing_cdr_failed(), clear_caller(), and findmeexec().

00778 {
00779    for ( ; cdr ; cdr = cdr->next) {
00780       check_post(cdr);
00781       if (ast_tvzero(cdr->end))
00782          cdr->end = ast_tvnow();
00783       if (ast_tvzero(cdr->start)) {
00784          ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", S_OR(cdr->channel, "<unknown>"));
00785          cdr->disposition = AST_CDR_FAILED;
00786       } else
00787          cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec;
00788       cdr->billsec = ast_tvzero(cdr->answer) ? 0 : cdr->end.tv_sec - cdr->answer.tv_sec;
00789    }
00790 }

int ast_cdr_engine_init ( void   ) 

Load the configuration file cdr.conf and possibly start the CDR scheduling thread

Definition at line 1330 of file cdr.c.

References ast_cli_register(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), cli_status, do_reload(), init_batch(), LOG_ERROR, and sched_context_create().

Referenced by main().

01331 {
01332    int res;
01333 
01334    sched = sched_context_create();
01335    if (!sched) {
01336       ast_log(LOG_ERROR, "Unable to create schedule context.\n");
01337       return -1;
01338    }
01339 
01340    ast_cli_register(&cli_status);
01341 
01342    res = do_reload();
01343    if (res) {
01344       ast_mutex_lock(&cdr_batch_lock);
01345       res = init_batch();
01346       ast_mutex_unlock(&cdr_batch_lock);
01347    }
01348 
01349    return res;
01350 }

int ast_cdr_engine_reload ( void   ) 

Reload the configuration file cdr.conf and start/stop CDR scheduling thread

Definition at line 1359 of file cdr.c.

References do_reload().

01360 {
01361    return do_reload();
01362 }

void ast_cdr_engine_term ( void   ) 

Submit any remaining CDRs and prepare for shutdown

Definition at line 1354 of file cdr.c.

References ast_cdr_submit_batch(), and batchsafeshutdown.

Referenced by do_reload(), and quit_handler().

01355 {
01356    ast_cdr_submit_batch(batchsafeshutdown);
01357 }

void ast_cdr_failed ( struct ast_cdr cdr  ) 

Parameters:
cdr the cdr you wish to associate with the call Returns nothing

Definition at line 662 of file cdr.c.

References AST_CDR_FAILED, AST_CDR_FLAG_LOCKED, ast_test_flag, check_post(), ast_cdr::disposition, and ast_cdr::next.

Referenced by __ast_request_and_dial(), ast_cdr_disposition(), ast_feature_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), clear_caller(), and findmeexec().

00663 {
00664    for (; cdr; cdr = cdr->next) {
00665       check_post(cdr);
00666       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00667          if (cdr->disposition < AST_CDR_FAILED)
00668             cdr->disposition = AST_CDR_FAILED;
00669       }
00670    }
00671 }

char* ast_cdr_flags2str ( int  flag  ) 

Converts AMA flag to printable string

Definition at line 808 of file cdr.c.

References AST_CDR_BILLING, AST_CDR_DOCUMENTATION, and AST_CDR_OMIT.

Referenced by _sip_show_peer(), ast_cdr_getvar(), build_csv_record(), build_radius_record(), csv_log(), manager_log(), sip_show_user(), and tds_log().

00809 {
00810    switch(flag) {
00811    case AST_CDR_OMIT:
00812       return "OMIT";
00813    case AST_CDR_BILLING:
00814       return "BILLING";
00815    case AST_CDR_DOCUMENTATION:
00816       return "DOCUMENTATION";
00817    }
00818    return "Unknown";
00819 }

void ast_cdr_free ( struct ast_cdr cdr  ) 

Free a CDR record.

Parameters:
cdr ast_cdr structure to free Returns nothing

Definition at line 433 of file cdr.c.

References AST_CDR_FLAG_POST_DISABLED, AST_CDR_FLAG_POSTED, ast_cdr_free_vars(), ast_log(), ast_test_flag, ast_cdr::channel, ast_cdr::end, free, LOG_NOTICE, ast_cdr::next, S_OR, and ast_cdr::start.

Referenced by ast_cdr_detach(), and do_batch_backend_process().

00434 {
00435 
00436    while (cdr) {
00437       struct ast_cdr *next = cdr->next;
00438       char *chan = S_OR(cdr->channel, "<unknown>");
00439       if (!ast_test_flag(cdr, AST_CDR_FLAG_POSTED) && !ast_test_flag(cdr, AST_CDR_FLAG_POST_DISABLED))
00440          ast_log(LOG_NOTICE, "CDR on channel '%s' not posted\n", chan);
00441       if (ast_tvzero(cdr->end))
00442          ast_log(LOG_NOTICE, "CDR on channel '%s' lacks end\n", chan);
00443       if (ast_tvzero(cdr->start))
00444          ast_log(LOG_NOTICE, "CDR on channel '%s' lacks start\n", chan);
00445 
00446       ast_cdr_free_vars(cdr, 0);
00447       free(cdr);
00448       cdr = next;
00449    }
00450 }

void ast_cdr_free_vars ( struct ast_cdr cdr,
int  recur 
)

Definition at line 403 of file cdr.c.

References AST_LIST_REMOVE_HEAD, ast_var_delete(), ast_cdr::next, and ast_cdr::varshead.

Referenced by ast_cdr_discard(), ast_cdr_fork(), ast_cdr_free(), and ast_cdr_reset().

00404 {
00405 
00406    /* clear variables */
00407    for (; cdr; cdr = recur ? cdr->next : NULL) {
00408       struct ast_var_t *vardata;
00409       struct varshead *headp = &cdr->varshead;
00410       while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
00411          ast_var_delete(vardata);
00412    }
00413 }

void ast_cdr_getvar ( struct ast_cdr cdr,
const char *  name,
char **  ret,
char *  workspace,
int  workspacelen,
int  recur,
int  raw 
)

CDR channel variable retrieval

Definition at line 218 of file cdr.c.

References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_cdr_getvar_internal(), ast_strlen_zero(), ast_cdr::billsec, cdr_get_tv(), ast_cdr::channel, ast_cdr::clid, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, fmt, ast_cdr::lastapp, ast_cdr::lastdata, ast_cdr::src, ast_cdr::start, ast_cdr::uniqueid, and ast_cdr::userfield.

Referenced by ast_cdr_serialize_variables(), and cdr_read().

00219 {
00220    const char *fmt = "%Y-%m-%d %T";
00221    const char *varbuf;
00222 
00223    if (!cdr)  /* don't die if the cdr is null */
00224       return;
00225 
00226    *ret = NULL;
00227    /* special vars (the ones from the struct ast_cdr when requested by name) 
00228       I'd almost say we should convert all the stringed vals to vars */
00229 
00230    if (!strcasecmp(name, "clid"))
00231       ast_copy_string(workspace, cdr->clid, workspacelen);
00232    else if (!strcasecmp(name, "src"))
00233       ast_copy_string(workspace, cdr->src, workspacelen);
00234    else if (!strcasecmp(name, "dst"))
00235       ast_copy_string(workspace, cdr->dst, workspacelen);
00236    else if (!strcasecmp(name, "dcontext"))
00237       ast_copy_string(workspace, cdr->dcontext, workspacelen);
00238    else if (!strcasecmp(name, "channel"))
00239       ast_copy_string(workspace, cdr->channel, workspacelen);
00240    else if (!strcasecmp(name, "dstchannel"))
00241       ast_copy_string(workspace, cdr->dstchannel, workspacelen);
00242    else if (!strcasecmp(name, "lastapp"))
00243       ast_copy_string(workspace, cdr->lastapp, workspacelen);
00244    else if (!strcasecmp(name, "lastdata"))
00245       ast_copy_string(workspace, cdr->lastdata, workspacelen);
00246    else if (!strcasecmp(name, "start"))
00247       cdr_get_tv(cdr->start, raw ? NULL : fmt, workspace, workspacelen);
00248    else if (!strcasecmp(name, "answer"))
00249       cdr_get_tv(cdr->answer, raw ? NULL : fmt, workspace, workspacelen);
00250    else if (!strcasecmp(name, "end"))
00251       cdr_get_tv(cdr->end, raw ? NULL : fmt, workspace, workspacelen);
00252    else if (!strcasecmp(name, "duration"))
00253       snprintf(workspace, workspacelen, "%ld", cdr->duration);
00254    else if (!strcasecmp(name, "billsec"))
00255       snprintf(workspace, workspacelen, "%ld", cdr->billsec);
00256    else if (!strcasecmp(name, "disposition")) {
00257       if (raw) {
00258          snprintf(workspace, workspacelen, "%ld", cdr->disposition);
00259       } else {
00260          ast_copy_string(workspace, ast_cdr_disp2str(cdr->disposition), workspacelen);
00261       }
00262    } else if (!strcasecmp(name, "amaflags")) {
00263       if (raw) {
00264          snprintf(workspace, workspacelen, "%ld", cdr->amaflags);
00265       } else {
00266          ast_copy_string(workspace, ast_cdr_flags2str(cdr->amaflags), workspacelen);
00267       }
00268    } else if (!strcasecmp(name, "accountcode"))
00269       ast_copy_string(workspace, cdr->accountcode, workspacelen);
00270    else if (!strcasecmp(name, "uniqueid"))
00271       ast_copy_string(workspace, cdr->uniqueid, workspacelen);
00272    else if (!strcasecmp(name, "userfield"))
00273       ast_copy_string(workspace, cdr->userfield, workspacelen);
00274    else if ((varbuf = ast_cdr_getvar_internal(cdr, name, recur)))
00275       ast_copy_string(workspace, varbuf, workspacelen);
00276    else
00277       workspace[0] = '\0';
00278 
00279    if (!ast_strlen_zero(workspace))
00280       *ret = workspace;
00281 }

int ast_cdr_init ( struct ast_cdr cdr,
struct ast_channel chan 
)

Initialize based on a channel.

Parameters:
cdr Call Detail Record to use for channel
chan Channel to bind CDR with Initializes a CDR and associates it with a particular channel Return is negligible. (returns 0 by default)

Definition at line 752 of file cdr.c.

References ast_channel::_state, ast_cdr::accountcode, ast_channel::amaflags, ast_cdr::amaflags, AST_CDR_ANSWERED, AST_CDR_FLAG_LOCKED, AST_CDR_NOANSWER, ast_log(), AST_STATE_UP, ast_strlen_zero(), ast_test_flag, ast_cdr::channel, ast_channel::context, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_channel::exten, LOG_WARNING, ast_cdr::next, S_OR, set_one_cid(), and ast_cdr::uniqueid.

Referenced by __ast_pbx_run(), __ast_read(), __ast_request_and_dial(), ast_bridge_call(), ast_feature_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), builtin_blindtransfer(), clear_caller(), and findmeexec().

00753 {
00754    char *chan;
00755 
00756    for ( ; cdr ; cdr = cdr->next) {
00757       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00758          chan = S_OR(cdr->channel, "<unknown>");
00759          if (!ast_strlen_zero(cdr->channel)) 
00760             ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan); 
00761          ast_copy_string(cdr->channel, c->name, sizeof(cdr->channel));
00762          set_one_cid(cdr, c);
00763 
00764          cdr->disposition = (c->_state == AST_STATE_UP) ?  AST_CDR_ANSWERED : AST_CDR_NOANSWER;
00765          cdr->amaflags = c->amaflags ? c->amaflags :  ast_default_amaflags;
00766          ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
00767          /* Destination information */
00768          ast_copy_string(cdr->dst, c->exten, sizeof(cdr->dst));
00769          ast_copy_string(cdr->dcontext, c->context, sizeof(cdr->dcontext));
00770          /* Unique call identifier */
00771          ast_copy_string(cdr->uniqueid, c->uniqueid, sizeof(cdr->uniqueid));
00772       }
00773    }
00774    return 0;
00775 }

void ast_cdr_merge ( struct ast_cdr to,
struct ast_cdr from 
)

Move the non-null data from the "from" cdr to the "to" cdr

Parameters:
to the cdr to get the goodies
from the cdr to give the goodies

Definition at line 508 of file cdr.c.

References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_append(), AST_CDR_FLAG_CHILD, AST_CDR_FLAG_KEEP_VARS, AST_CDR_FLAG_LOCKED, AST_CDR_FLAG_POST_DISABLED, AST_CDR_FLAG_POSTED, AST_CDR_NOANSWER, ast_set_flag, ast_strlen_zero(), ast_test_flag, ast_cdr::billsec, cdr_merge_vars(), ast_cdr::channel, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, ast_cdr::lastapp, ast_cdr::lastdata, ast_cdr::next, ast_cdr::src, ast_cdr::start, and ast_cdr::userfield.

Referenced by ast_bridge_call().

00509 {
00510    struct ast_cdr *tcdr;
00511    
00512    if (!to || !from)
00513       return;
00514    
00515    if (!ast_tvzero(from->start)) {
00516       if (!ast_tvzero(to->start)) {
00517          if (ast_tvcmp(to->start, from->start) > 0 ) {
00518             to->start = from->start; /* use the earliest time */
00519             from->start = ast_tv(0,0); /* we actively "steal" these values */
00520          }
00521          /* else nothing to do */
00522       } else {
00523          to->start = from->start;
00524          from->start = ast_tv(0,0); /* we actively "steal" these values */
00525       }
00526    }
00527    if (!ast_tvzero(from->answer)) {
00528       if (!ast_tvzero(to->answer)) {
00529          if (ast_tvcmp(to->answer, from->answer) > 0 ) {
00530             to->answer = from->answer; /* use the earliest time */
00531             from->answer = ast_tv(0,0); /* we actively "steal" these values */
00532          }
00533          /* we got the earliest answer time, so we'll settle for that? */
00534       } else {
00535          to->answer = from->answer;
00536          from->answer = ast_tv(0,0); /* we actively "steal" these values */
00537       }
00538    }
00539    if (!ast_tvzero(from->end)) {
00540       if (!ast_tvzero(to->end)) {
00541          if (ast_tvcmp(to->end, from->end) < 0 ) {
00542             to->end = from->end; /* use the latest time */
00543             from->end = ast_tv(0,0); /* we actively "steal" these values */
00544             to->duration = to->end.tv_sec - to->start.tv_sec;  /* don't forget to update the duration, billsec, when we set end */
00545             to->billsec = ast_tvzero(to->answer) ? 0 : to->end.tv_sec - to->answer.tv_sec;
00546          }
00547          /* else, nothing to do */
00548       } else {
00549          to->end = from->end;
00550          from->end = ast_tv(0,0); /* we actively "steal" these values */
00551          to->duration = to->end.tv_sec - to->start.tv_sec;
00552          to->billsec = ast_tvzero(to->answer) ? 0 : to->end.tv_sec - to->answer.tv_sec;
00553       }
00554    }
00555    if (to->disposition < from->disposition) {
00556       to->disposition = from->disposition;
00557       from->disposition = AST_CDR_NOANSWER;
00558    }
00559    if (ast_strlen_zero(to->lastapp) && !ast_strlen_zero(from->lastapp)) {
00560       ast_copy_string(to->lastapp, from->lastapp, sizeof(to->lastapp));
00561       from->lastapp[0] = 0; /* theft */
00562    }
00563    if (ast_strlen_zero(to->lastdata) && !ast_strlen_zero(from->lastdata)) {
00564       ast_copy_string(to->lastdata, from->lastdata, sizeof(to->lastdata));
00565       from->lastdata[0] = 0; /* theft */
00566    }
00567    if (ast_strlen_zero(to->dcontext) && !ast_strlen_zero(from->dcontext)) {
00568       ast_copy_string(to->dcontext, from->dcontext, sizeof(to->dcontext));
00569       from->dcontext[0] = 0; /* theft */
00570    }
00571    if (ast_strlen_zero(to->dstchannel) && !ast_strlen_zero(from->dstchannel)) {
00572       ast_copy_string(to->dstchannel, from->dstchannel, sizeof(to->dstchannel));
00573       from->dstchannel[0] = 0; /* theft */
00574    }
00575    if (ast_strlen_zero(to->channel) && !ast_strlen_zero(from->channel)) {
00576       ast_copy_string(to->channel, from->channel, sizeof(to->channel));
00577       from->channel[0] = 0; /* theft */
00578    }
00579    if (ast_strlen_zero(to->src) && !ast_strlen_zero(from->src)) {
00580       ast_copy_string(to->src, from->src, sizeof(to->src));
00581       from->src[0] = 0; /* theft */
00582    }
00583    if (ast_strlen_zero(to->dst) && !ast_strlen_zero(from->dst)) {
00584       ast_copy_string(to->dst, from->dst, sizeof(to->dst));
00585       from->dst[0] = 0; /* theft */
00586    }
00587    if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (!to->amaflags && from->amaflags)) {
00588       to->amaflags = from->amaflags;
00589       from->amaflags = 0; /* theft */
00590    }
00591    if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (ast_strlen_zero(to->accountcode) && !ast_strlen_zero(from->accountcode))) {
00592       ast_copy_string(to->accountcode, from->accountcode, sizeof(to->accountcode));
00593       from->accountcode[0] = 0; /* theft */
00594    }
00595    if (ast_test_flag(from, AST_CDR_FLAG_LOCKED) || (ast_strlen_zero(to->userfield) && !ast_strlen_zero(from->userfield))) {
00596       ast_copy_string(to->userfield, from->userfield, sizeof(to->userfield));
00597       from->userfield[0] = 0; /* theft */
00598    }
00599    /* flags, varsead, ? */
00600    cdr_merge_vars(from, to);
00601 
00602    if (ast_test_flag(from, AST_CDR_FLAG_KEEP_VARS))
00603       ast_set_flag(to, AST_CDR_FLAG_KEEP_VARS);
00604    if (ast_test_flag(from, AST_CDR_FLAG_POSTED))
00605       ast_set_flag(to, AST_CDR_FLAG_POSTED);
00606    if (ast_test_flag(from, AST_CDR_FLAG_LOCKED))
00607       ast_set_flag(to, AST_CDR_FLAG_LOCKED);
00608    if (ast_test_flag(from, AST_CDR_FLAG_CHILD))
00609       ast_set_flag(to, AST_CDR_FLAG_CHILD);
00610    if (ast_test_flag(from, AST_CDR_FLAG_POST_DISABLED))
00611       ast_set_flag(to, AST_CDR_FLAG_POST_DISABLED);
00612 
00613    /* last, but not least, we need to merge any forked CDRs to the 'to' cdr */
00614    while (from->next) {
00615       /* just rip 'em off the 'from' and insert them on the 'to' */
00616       tcdr = from->next;
00617       from->next = tcdr->next;
00618       tcdr->next = NULL;
00619       /* tcdr is now ripped from the current list; */
00620       ast_cdr_append(to, tcdr);
00621    }
00622 }

int ast_cdr_register ( const char *  name,
const char *  desc,
ast_cdrbe  be 
)

Register a CDR driver. Each registered CDR driver generates a CDR

Returns:
0 on success, -1 on failure

Definition at line 108 of file cdr.c.

References ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), LOG_WARNING, and ast_cdr_beitem::name.

Referenced by load_module(), my_load_module(), odbc_load_module(), process_my_load_module(), and tds_load_module().

00109 {
00110    struct ast_cdr_beitem *i;
00111 
00112    if (!name)
00113       return -1;
00114    if (!be) {
00115       ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
00116       return -1;
00117    }
00118 
00119    AST_LIST_LOCK(&be_list);
00120    AST_LIST_TRAVERSE(&be_list, i, list) {
00121       if (!strcasecmp(name, i->name))
00122          break;
00123    }
00124    AST_LIST_UNLOCK(&be_list);
00125 
00126    if (i) {
00127       ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
00128       return -1;
00129    }
00130 
00131    if (!(i = ast_calloc(1, sizeof(*i))))  
00132       return -1;
00133 
00134    i->be = be;
00135    ast_copy_string(i->name, name, sizeof(i->name));
00136    ast_copy_string(i->desc, desc, sizeof(i->desc));
00137 
00138    AST_LIST_LOCK(&be_list);
00139    AST_LIST_INSERT_HEAD(&be_list, i, list);
00140    AST_LIST_UNLOCK(&be_list);
00141 
00142    return 0;
00143 }

void ast_cdr_reset ( struct ast_cdr cdr,
struct ast_flags flags 
)

Parameters:
cdr which cdr to act upon
flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's

Definition at line 927 of file cdr.c.

References ast_cdr::answer, ast_cdr_detach(), ast_cdr_dup(), ast_cdr_end(), AST_CDR_FLAG_KEEP_VARS, AST_CDR_FLAG_LOCKED, AST_CDR_FLAG_POSTED, ast_cdr_free_vars(), AST_CDR_NOANSWER, ast_cdr_start(), ast_clear_flag, ast_copy_flags, AST_FLAGS_ALL, ast_set_flag, ast_test_flag, ast_cdr::billsec, ast_cdr::disposition, ast_cdr::duration, ast_cdr::end, ast_cdr::next, and ast_cdr::start.

Referenced by ast_bridge_call_thread(), ast_cdr_fork(), disa_exec(), and pbx_builtin_resetcdr().

00928 {
00929    struct ast_cdr *dup;
00930    struct ast_flags flags = { 0 };
00931 
00932    if (_flags)
00933       ast_copy_flags(&flags, _flags, AST_FLAGS_ALL);
00934 
00935    for ( ; cdr ; cdr = cdr->next) {
00936       /* Detach if post is requested */
00937       if (ast_test_flag(&flags, AST_CDR_FLAG_LOCKED) || !ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00938          if (ast_test_flag(&flags, AST_CDR_FLAG_POSTED)) {
00939             ast_cdr_end(cdr);
00940             if ((dup = ast_cdr_dup(cdr))) {
00941                ast_cdr_detach(dup);
00942             }
00943             ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
00944          }
00945 
00946          /* clear variables */
00947          if (!ast_test_flag(&flags, AST_CDR_FLAG_KEEP_VARS)) {
00948             ast_cdr_free_vars(cdr, 0);
00949          }
00950 
00951          /* Reset to initial state */
00952          ast_clear_flag(cdr, AST_FLAGS_ALL); 
00953          memset(&cdr->start, 0, sizeof(cdr->start));
00954          memset(&cdr->end, 0, sizeof(cdr->end));
00955          memset(&cdr->answer, 0, sizeof(cdr->answer));
00956          cdr->billsec = 0;
00957          cdr->duration = 0;
00958          ast_cdr_start(cdr);
00959          cdr->disposition = AST_CDR_NOANSWER;
00960       }
00961    }
00962 }

int ast_cdr_serialize_variables ( struct ast_cdr cdr,
char *  buf,
size_t  size,
char  delim,
char  sep,
int  recur 
)

Definition at line 359 of file cdr.c.

References ast_build_string(), ast_cdr_getvar(), AST_LIST_TRAVERSE, ast_log(), ast_strlen_zero(), ast_var_name(), ast_var_value(), cdr_readonly_vars, LOG_ERROR, ast_cdr::next, total, var, and ast_cdr::varshead.

Referenced by handle_showchan(), and handle_showchan_deprecated().

00360 {
00361    struct ast_var_t *variables;
00362    const char *var, *val;
00363    char *tmp;
00364    char workspace[256];
00365    int total = 0, x = 0, i;
00366 
00367    memset(buf, 0, size);
00368 
00369    for (; cdr; cdr = recur ? cdr->next : NULL) {
00370       if (++x > 1)
00371          ast_build_string(&buf, &size, "\n");
00372 
00373       AST_LIST_TRAVERSE(&cdr->varshead, variables, entries) {
00374          if (variables &&
00375              (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
00376              !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
00377             if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, var, delim, val, sep)) {
00378                ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
00379                break;
00380             } else
00381                total++;
00382          } else 
00383             break;
00384       }
00385 
00386       for (i = 0; cdr_readonly_vars[i]; i++) {
00387          ast_cdr_getvar(cdr, cdr_readonly_vars[i], &tmp, workspace, sizeof(workspace), 0, 0);
00388          if (!tmp)
00389             continue;
00390          
00391          if (ast_build_string(&buf, &size, "level %d: %s%c%s%c", x, cdr_readonly_vars[i], delim, tmp, sep)) {
00392             ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
00393             break;
00394          } else
00395             total++;
00396       }
00397    }
00398 
00399    return total;
00400 }

int ast_cdr_setaccount ( struct ast_channel chan,
const char *  account 
)

Definition at line 821 of file cdr.c.

References ast_cdr::accountcode, accountcode, AST_CDR_FLAG_LOCKED, ast_string_field_set, ast_test_flag, ast_channel::cdr, and ast_cdr::next.

Referenced by __ast_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), auth_exec(), and cdr_write().

00822 {
00823    struct ast_cdr *cdr = chan->cdr;
00824 
00825    ast_string_field_set(chan, accountcode, account);
00826    for ( ; cdr ; cdr = cdr->next) {
00827       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00828          ast_copy_string(cdr->accountcode, chan->accountcode, sizeof(cdr->accountcode));
00829       }
00830    }
00831    return 0;
00832 }

int ast_cdr_setamaflags ( struct ast_channel chan,
const char *  amaflags 
)

Definition at line 834 of file cdr.c.

References ast_cdr::amaflags, ast_cdr_amaflags2int(), ast_channel::cdr, and ast_cdr::next.

Referenced by cdr_write(), and pbx_builtin_setamaflags().

00835 {
00836    struct ast_cdr *cdr;
00837    int newflag = ast_cdr_amaflags2int(flag);
00838    if (newflag) {
00839       for (cdr = chan->cdr; cdr; cdr = cdr->next)
00840          cdr->amaflags = newflag;
00841    }
00842 
00843    return 0;
00844 }

void ast_cdr_setapp ( struct ast_cdr cdr,
char *  app,
char *  data 
)

Parameters:
cdr which cdr to act upon
app the name of the app you wish to change it to
data the data you want in the data field of app you set it to Changes the value of the last executed app Returns nothing

Definition at line 707 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, check_post(), and ast_cdr::next.

Referenced by __ast_request_and_dial(), ast_feature_request_and_dial(), builtin_blindtransfer(), clear_caller(), findmeexec(), and pbx_exec().

00708 {
00709 
00710    for (; cdr; cdr = cdr->next) {
00711       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00712          check_post(cdr);
00713          if (!app)
00714             app = "";
00715          ast_copy_string(cdr->lastapp, app, sizeof(cdr->lastapp));
00716          if (!data)
00717             data = "";
00718          ast_copy_string(cdr->lastdata, data, sizeof(cdr->lastdata));
00719       }
00720    }
00721 }

int ast_cdr_setcid ( struct ast_cdr cdr,
struct ast_channel chan 
)

Parameters:
cdr Call Detail Record to use for channel
chan Channel to bind CDR with Initializes a CDR and associates it with a particular channel Return is negligible. (returns 0 by default)

Definition at line 743 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, ast_cdr::next, and set_one_cid().

Referenced by ast_set_callerid().

00744 {
00745    for (; cdr; cdr = cdr->next) {
00746       if (ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
00747          set_one_cid(cdr, c);
00748    }
00749    return 0;
00750 }

void ast_cdr_setdestchan ( struct ast_cdr cdr,
const char *  chan 
)

Parameters:
cdr Which cdr it's applied to
chan Channel to which dest will be Sets the destination channel the CDR is applied to Returns nothing

Definition at line 698 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, check_post(), ast_cdr::dstchannel, and ast_cdr::next.

Referenced by ast_bridge_call(), ast_bridge_call_thread(), builtin_blindtransfer(), park_exec(), and try_calling().

00699 {
00700    for (; cdr; cdr = cdr->next) {
00701       check_post(cdr);
00702       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED))
00703          ast_copy_string(cdr->dstchannel, chann, sizeof(cdr->dstchannel));
00704    }
00705 }

int ast_cdr_setuserfield ( struct ast_channel chan,
const char *  userfield 
)

Definition at line 846 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, ast_channel::cdr, ast_cdr::next, and ast_cdr::userfield.

Referenced by __agent_start_monitoring(), action_setcdruserfield(), ast_bridge_call(), cdr_write(), handle_request_info(), setcdruserfield_exec(), and start_monitor_exec().

00847 {
00848    struct ast_cdr *cdr = chan->cdr;
00849 
00850    for ( ; cdr ; cdr = cdr->next) {
00851       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) 
00852          ast_copy_string(cdr->userfield, userfield, sizeof(cdr->userfield));
00853    }
00854 
00855    return 0;
00856 }

int ast_cdr_setvar ( struct ast_cdr cdr,
const char *  name,
const char *  value,
int  recur 
)

Set a CDR channel variable

Note:
You can't set the CDR variables that belong to the actual CDR record, like "billsec".

Definition at line 291 of file cdr.c.

References AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_var_assign(), ast_var_delete(), ast_var_name(), cdr_readonly_vars, LOG_ERROR, ast_cdr::next, and ast_cdr::varshead.

Referenced by cdr_write().

00292 {
00293    struct ast_var_t *newvariable;
00294    struct varshead *headp;
00295    int x;
00296    
00297    if (!cdr)  /* don't die if the cdr is null */
00298       return -1;
00299    
00300    for(x = 0; cdr_readonly_vars[x]; x++) {
00301       if (!strcasecmp(name, cdr_readonly_vars[x])) {
00302          ast_log(LOG_ERROR, "Attempt to set the '%s' read-only variable!.\n", name);
00303          return -1;
00304       }
00305    }
00306 
00307    if (!cdr) {
00308       ast_log(LOG_ERROR, "Attempt to set a variable on a nonexistent CDR record.\n");
00309       return -1;
00310    }
00311 
00312    for (; cdr; cdr = recur ? cdr->next : NULL) {
00313       headp = &cdr->varshead;
00314       AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
00315          if (!strcasecmp(ast_var_name(newvariable), name)) {
00316             /* there is already such a variable, delete it */
00317             AST_LIST_REMOVE_CURRENT(headp, entries);
00318             ast_var_delete(newvariable);
00319             break;
00320          }
00321       }
00322       AST_LIST_TRAVERSE_SAFE_END;
00323 
00324       if (value) {
00325          newvariable = ast_var_assign(name, value);
00326          AST_LIST_INSERT_HEAD(headp, newvariable, entries);
00327       }
00328    }
00329 
00330    return 0;
00331 }

void ast_cdr_start ( struct ast_cdr cdr  ) 

Parameters:
cdr the cdr you wish to associate with the call Starts all CDR stuff necessary for monitoring a call Returns nothing

Definition at line 624 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, ast_cdr::channel, check_post(), check_start(), ast_cdr::next, and S_OR.

Referenced by __ast_pbx_run(), __ast_read(), __ast_request_and_dial(), ast_bridge_call(), ast_cdr_reset(), ast_feature_request_and_dial(), ast_pbx_outgoing_app(), ast_pbx_outgoing_cdr_failed(), ast_pbx_outgoing_exten(), builtin_blindtransfer(), clear_caller(), and findmeexec().

00625 {
00626    char *chan; 
00627 
00628    for (; cdr; cdr = cdr->next) {
00629       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00630          chan = S_OR(cdr->channel, "<unknown>");
00631          check_post(cdr);
00632          check_start(cdr);
00633          cdr->start = ast_tvnow();
00634       }
00635    }
00636 }

void ast_cdr_submit_batch ( int  shutdown  ) 

Parameters:
shutdown Whether or not we are shutting down Blocks the asterisk shutdown procedures until the CDR data is submitted. Returns nothing

Definition at line 1018 of file cdr.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, AST_PTHREADT_NULL, batch, batchscheduleronly, do_batch_backend_process(), ast_cdr_batch::head, LOG_DEBUG, LOG_WARNING, option_debug, and reset_batch().

Referenced by ast_cdr_engine_term(), and submit_scheduled_batch().

01019 {
01020    struct ast_cdr_batch_item *oldbatchitems = NULL;
01021    pthread_attr_t attr;
01022    pthread_t batch_post_thread = AST_PTHREADT_NULL;
01023 
01024    /* if there's no batch, or no CDRs in the batch, then there's nothing to do */
01025    if (!batch || !batch->head)
01026       return;
01027 
01028    /* move the old CDRs aside, and prepare a new CDR batch */
01029    ast_mutex_lock(&cdr_batch_lock);
01030    oldbatchitems = batch->head;
01031    reset_batch();
01032    ast_mutex_unlock(&cdr_batch_lock);
01033 
01034    /* if configured, spawn a new thread to post these CDRs,
01035       also try to save as much as possible if we are shutting down safely */
01036    if (batchscheduleronly || shutdown) {
01037       if (option_debug)
01038          ast_log(LOG_DEBUG, "CDR single-threaded batch processing begins now\n");
01039       do_batch_backend_process(oldbatchitems);
01040    } else {
01041       pthread_attr_init(&attr);
01042       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
01043       if (ast_pthread_create_background(&batch_post_thread, &attr, do_batch_backend_process, oldbatchitems)) {
01044          ast_log(LOG_WARNING, "CDR processing thread could not detach, now trying in this thread\n");
01045          do_batch_backend_process(oldbatchitems);
01046       } else {
01047          if (option_debug)
01048             ast_log(LOG_DEBUG, "CDR multi-threaded batch processing begins now\n");
01049       }
01050       pthread_attr_destroy(&attr);
01051    }
01052 }

void ast_cdr_unregister ( const char *  name  ) 

unregister a CDR driver

Definition at line 146 of file cdr.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_verbose(), free, ast_cdr_beitem::name, option_verbose, and VERBOSE_PREFIX_2.

Referenced by my_unload_module(), odbc_unload_module(), tds_unload_module(), and unload_module().

00147 {
00148    struct ast_cdr_beitem *i = NULL;
00149 
00150    AST_LIST_LOCK(&be_list);
00151    AST_LIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
00152       if (!strcasecmp(name, i->name)) {
00153          AST_LIST_REMOVE_CURRENT(&be_list, list);
00154          if (option_verbose > 1)
00155             ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s' CDR backend\n", name);
00156          free(i);
00157          break;
00158       }
00159    }
00160    AST_LIST_TRAVERSE_SAFE_END;
00161    AST_LIST_UNLOCK(&be_list);
00162 }

int ast_cdr_update ( struct ast_channel chan  ) 

Definition at line 872 of file cdr.c.

References AST_CDR_FLAG_LOCKED, ast_test_flag, ast_channel::cdr, ast_channel::context, ast_channel::exten, ast_channel::macrocontext, ast_channel::macroexten, ast_cdr::next, S_OR, and set_one_cid().

Referenced by __ast_request_and_dial(), ast_feature_request_and_dial(), ast_parseable_goto(), cb_events(), clear_caller(), and findmeexec().

00873 {
00874    struct ast_cdr *cdr = c->cdr;
00875 
00876    for ( ; cdr ; cdr = cdr->next) {
00877       if (!ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
00878          set_one_cid(cdr, c);
00879 
00880          /* Copy account code et-al */ 
00881          ast_copy_string(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode));
00882          /* Destination information */ /* XXX privilege macro* ? */
00883          ast_copy_string(cdr->dst, S_OR(c->macroexten, c->exten), sizeof(cdr->dst));
00884          ast_copy_string(cdr->dcontext, S_OR(c->macrocontext, c->context), sizeof(cdr->dcontext));
00885       }
00886    }
00887 
00888    return 0;
00889 }


Variable Documentation

char ast_default_accountcode[AST_MAX_ACCOUNT_CODE]

Definition at line 60 of file cdr.c.

int ast_default_amaflags

Default AMA flag for billing records (CDR's)

Definition at line 59 of file cdr.c.


Generated on Mon Apr 30 07:39:20 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1