Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:49 2009

## Asterisk developer's documentation

# cdr.h

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  * \brief Call Detail Record API
    00021  */
    00022
    00023 #ifndef _ASTERISK_CDR_H
    00024 #define _ASTERISK_CDR_H
    00025
    00026 #include <sys/time.h>
    00027 #define AST_CDR_FLAG_KEEP_VARS         (1 << 0)
    00028 #define AST_CDR_FLAG_POSTED         (1 << 1)
    00029 #define AST_CDR_FLAG_LOCKED         (1 << 2)
    00030 #define AST_CDR_FLAG_CHILD       (1 << 3)
    00031 #define AST_CDR_FLAG_POST_DISABLED     (1 << 4)
    00032
    00033 #define AST_CDR_NULL                0
    00034 #define AST_CDR_FAILED           (1 << 0)
    00035 #define AST_CDR_BUSY          (1 << 1)
    00036 #define AST_CDR_NOANSWER         (1 << 2)
    00037 #define AST_CDR_ANSWERED         (1 << 3)
    00038
    00039 /*! AMA Flags */
    00040 #define AST_CDR_OMIT          (1)
    00041 #define AST_CDR_BILLING          (2)
    00042 #define AST_CDR_DOCUMENTATION       (3)
    00043
    00044 #define AST_MAX_USER_FIELD       256
    00045 #define AST_MAX_ACCOUNT_CODE        20
    00046
    00047 /* Include channel.h after relevant declarations it will need */
    00048 #include "asterisk/channel.h"
    00049 #include "asterisk/utils.h"
    00050
    00051 struct ast_channel;
    00052
    00053 /*! Responsible for call detail data */
    00054 struct ast_cdr {
    00055    /*! Caller*ID with text */
    00056    char clid[AST_MAX_EXTENSION];
    00057    /*! Caller*ID number */
    00058    char src[AST_MAX_EXTENSION];
    00059    /*! Destination extension */
    00060    char dst[AST_MAX_EXTENSION];
    00061    /*! Destination context */
    00062    char dcontext[AST_MAX_EXTENSION];
    00063
    00064    char channel[AST_MAX_EXTENSION];
    00065    /*! Destination channel if appropriate */
    00066    char dstchannel[AST_MAX_EXTENSION];
    00067    /*! Last application if appropriate */
    00068    char lastapp[AST_MAX_EXTENSION];
    00069    /*! Last application data */
    00070    char lastdata[AST_MAX_EXTENSION];
    00071
    00072    struct timeval start;
    00073
    00074    struct timeval answer;
    00075
    00076    struct timeval end;
    00077    /*! Total time in system, in seconds */
    00078    long int duration;
    00079    /*! Total time call is up, in seconds */
    00080    long int billsec;
    00081    /*! What happened to the call */
    00082    long int disposition;
    00083    /*! What flags to use */
    00084    long int amaflags;
    00085    /*! What account number to use */
    00086    char accountcode[AST_MAX_ACCOUNT_CODE];
    00087    /*! flags */
    00088    unsigned int flags;
    00089    /* Unique Channel Identifier */
    00090    char uniqueid[32];
    00091    /* User field */
    00092    char userfield[AST_MAX_USER_FIELD];
    00093
    00094    /* A linked list for variables */
    00095    struct varshead varshead;
    00096
    00097    struct ast_cdr *next;
    00098 };
    00099
    00100 extern void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur);
    00101 extern int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
    00102 extern int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
    00103 extern void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
    00104 extern int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
    00105
    00106 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
    00107
    00108 /*! \brief Allocate a CDR record
    00109  * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
    00110  */
    00111 extern struct ast_cdr *ast_cdr_alloc(void);
    00112
    00113 /*! \brief Duplicate a record
    00114  * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
    00115  */
    00116 extern struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
    00117
    00118 /*! \brief Free a CDR record
    00119  * \param cdr ast_cdr structure to free
    00120  * Returns nothing important
    00121  */
    00122 extern void ast_cdr_free(struct ast_cdr *cdr);
    00123
    00124 /*! \brief Initialize based on a channel
    00125  * \param cdr Call Detail Record to use for channel
    00126  * \param chan Channel to bind CDR with
    00127  * Initializes a CDR and associates it with a particular channel
    00128  * Return is negligible.  (returns 0 by default)
    00129  */
    00130 extern int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
    00131
    00132 /*! Initialize based on a channel */
    00133 /*!
    00134  * \param cdr Call Detail Record to use for channel
    00135  * \param chan Channel to bind CDR with
    00136  * Initializes a CDR and associates it with a particular channel
    00137  * Return is negligible.  (returns 0 by default)
    00138  */
    00139 extern int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
    00140
    00141 /*! Register a CDR handling engine */
    00142 /*!
    00143  * \param name name associated with the particular CDR handler
    00144  * \param desc description of the CDR handler
    00145  * \param be function pointer to a CDR handler
    00146  * Used to register a Call Detail Record handler.
    00147  * Returns -1 on error, 0 on success.
    00148  */
    00149 extern int ast_cdr_register(char *name, char *desc, ast_cdrbe be);
    00150
    00151 /*! Unregister a CDR handling engine */
    00152 /*!
    00153  * \param name name of CDR handler to unregister
    00154  * Unregisters a CDR by it's name
    00155  */
    00156 extern void ast_cdr_unregister(char *name);
    00157
    00158 /*! Start a call */
    00159 /*!
    00160  * \param cdr the cdr you wish to associate with the call
    00161  * Starts all CDR stuff necessary for monitoring a call
    00162  * Returns nothing important
    00163  */
    00164 extern void ast_cdr_start(struct ast_cdr *cdr);
    00165
    00166 /*! Answer a call */
    00167 /*!
    00168  * \param cdr the cdr you wish to associate with the call
    00169  * Starts all CDR stuff necessary for doing CDR when answering a call
    00170  */
    00171 extern void ast_cdr_answer(struct ast_cdr *cdr);
    00172
    00173 /*! A call wasn't answered */
    00174 /*!
    00175  * \param cdr the cdr you wish to associate with the call
    00176  * Marks the channel disposition as "NO ANSWER"
    00177  */
    00178 extern void ast_cdr_noanswer(struct ast_cdr *cdr);
    00179
    00180 /*! Busy a call */
    00181 /*!
    00182  * \param cdr the cdr you wish to associate with the call
    00183  * Returns nothing important
    00184  */
    00185 extern void ast_cdr_busy(struct ast_cdr *cdr);
    00186
    00187 /*! Fail a call */
    00188 /*!
    00189  * \param cdr the cdr you wish to associate with the call
    00190  * Returns nothing important
    00191  */
    00192 extern void ast_cdr_failed(struct ast_cdr *cdr);
    00193
    00194 /*! Save the result of the call based on the AST_CAUSE_* */
    00195 /*!
    00196  * \param cdr the cdr you wish to associate with the call
    00197  * Returns nothing important
    00198  * \param cause the AST_CAUSE_*
    00199  */
    00200 extern int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
    00201
    00202 /*! End a call */
    00203 /*!
    00204  * \param cdr the cdr you have associated the call with
    00205  * Registers the end of call time in the cdr structure.
    00206  * Returns nothing important
    00207  */
    00208 extern void ast_cdr_end(struct ast_cdr *cdr);
    00209
    00210 /*! Detaches the detail record for posting (and freeing) either now or at a
    00211  * later time in bulk with other records during batch mode operation */
    00212 /*!
    00213  * \param cdr Which CDR to detach from the channel thread
    00214  * Prevents the channel thread from blocking on the CDR handling
    00215  * Returns nothing
    00216  */
    00217 extern void ast_cdr_detach(struct ast_cdr *cdr);
    00218
    00219 /*! Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines */
    00220 /*!
    00221  * \param shutdown Whether or not we are shutting down
    00222  * Blocks the asterisk shutdown procedures until the CDR data is submitted.
    00223  * Returns nothing
    00224  */
    00225 extern void ast_cdr_submit_batch(int shutdown);
    00226
    00227 /*! Set the destination channel, if there was one */
    00228 /*!
    00229  * \param cdr Which cdr it's applied to
    00230  * \param chan Channel to which dest will be
    00231  * Sets the destination channel the CDR is applied to
    00232  * Returns nothing
    00233  */
    00234 extern void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chan);
    00235
    00236 /*! Set the last executed application */
    00237 /*!
    00238  * \param cdr which cdr to act upon
    00239  * \param app the name of the app you wish to change it to
    00240  * \param data the data you want in the data field of app you set it to
    00241  * Changes the value of the last executed app
    00242  * Returns nothing
    00243  */
    00244 extern void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
    00245
    00246 /*! Convert a string to a detail record AMA flag */
    00247 /*!
    00248  * \param flag string form of flag
    00249  * Converts the string form of the flag to the binary form.
    00250  * Returns the binary form of the flag
    00251  */
    00252 extern int ast_cdr_amaflags2int(const char *flag);
    00253
    00254 /*! Disposition to a string */
    00255 /*!
    00256  * \param disposition input binary form
    00257  * Converts the binary form of a disposition to string form.
    00258  * Returns a pointer to the string form
    00259  */
    00260 extern char *ast_cdr_disp2str(int disposition);
    00261
    00262 /*! Reset the detail record, optionally posting it first */
    00263 /*!
    00264  * \param cdr which cdr to act upon
    00265  * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
    00266  *              |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
    00267  */
    00268 extern void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
    00269
    00270 /*! Flags to a string */
    00271 /*!
    00272  * \param flags binary flag
    00273  * Converts binary flags to string flags
    00274  * Returns string with flag name
    00275  */
    00276 extern char *ast_cdr_flags2str(int flags);
    00277
    00278 extern int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
    00279 extern int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
    00280
    00281
    00282 extern int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
    00283 extern int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
    00284
    00285
    00286 /* Update CDR on a channel */
    00287 extern int ast_cdr_update(struct ast_channel *chan);
    00288
    00289
    00290 extern int ast_default_amaflags;
    00291
    00292 extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
    00293
    00294 extern struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
    00295
    00296 /*! Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
    00297 extern void ast_cdr_engine_reload(void);
    00298
    00299 /*! Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
    00300 extern int ast_cdr_engine_init(void);
    00301
    00302 /*! Submit any remaining CDRs and prepare for shutdown */
    00303 extern void ast_cdr_engine_term(void);
    00304
    00305 #endif /* _ASTERISK_CDR_H */