Wed Aug 15 01:24:16 2007

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 /*! Responsible for call detail data */
00052 struct ast_cdr {
00053    /*! Caller*ID with text */
00054    char clid[AST_MAX_EXTENSION];
00055    /*! Caller*ID number */
00056    char src[AST_MAX_EXTENSION];     
00057    /*! Destination extension */
00058    char dst[AST_MAX_EXTENSION];     
00059    /*! Destination context */
00060    char dcontext[AST_MAX_EXTENSION];   
00061    
00062    char channel[AST_MAX_EXTENSION];
00063    /*! Destination channel if appropriate */
00064    char dstchannel[AST_MAX_EXTENSION]; 
00065    /*! Last application if appropriate */
00066    char lastapp[AST_MAX_EXTENSION]; 
00067    /*! Last application data */
00068    char lastdata[AST_MAX_EXTENSION];   
00069    
00070    struct timeval start;
00071    
00072    struct timeval answer;
00073    
00074    struct timeval end;
00075    /*! Total time in system, in seconds */
00076    long int duration;            
00077    /*! Total time call is up, in seconds */
00078    long int billsec;          
00079    /*! What happened to the call */
00080    long int disposition;         
00081    /*! What flags to use */
00082    long int amaflags;            
00083    /*! What account number to use */
00084    char accountcode[AST_MAX_ACCOUNT_CODE];         
00085    /*! flags */
00086    unsigned int flags;           
00087    /* Unique Channel Identifier */
00088    char uniqueid[32];
00089    /* User field */
00090    char userfield[AST_MAX_USER_FIELD];
00091 
00092    /* A linked list for variables */
00093    struct varshead varshead;
00094 
00095    struct ast_cdr *next;
00096 };
00097 
00098 void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
00099 int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
00100 int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
00101 void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
00102 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
00103 
00104 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
00105 
00106 /*! \brief Allocate a CDR record 
00107  * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
00108  */
00109 struct ast_cdr *ast_cdr_alloc(void);
00110 
00111 /*! \brief Duplicate a record 
00112  * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
00113  */
00114 struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
00115 
00116 /*! \brief Free a CDR record 
00117  * \param cdr ast_cdr structure to free
00118  * Returns nothing
00119  */
00120 void ast_cdr_free(struct ast_cdr *cdr);
00121 
00122 /*! \brief Discard and free a CDR record 
00123  * \param cdr ast_cdr structure to free
00124  * Returns nothing  -- same as free, but no checks or complaints
00125  */
00126 void ast_cdr_discard(struct ast_cdr *cdr);
00127 
00128 /*! \brief Initialize based on a channel
00129  * \param cdr Call Detail Record to use for channel
00130  * \param chan Channel to bind CDR with
00131  * Initializes a CDR and associates it with a particular channel
00132  * Return is negligible.  (returns 0 by default)
00133  */
00134 int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
00135 
00136 /*! Initialize based on a channel */
00137 /*! 
00138  * \param cdr Call Detail Record to use for channel
00139  * \param chan Channel to bind CDR with
00140  * Initializes a CDR and associates it with a particular channel
00141  * Return is negligible.  (returns 0 by default)
00142  */
00143 int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
00144 
00145 /*! Register a CDR handling engine */
00146 /*!
00147  * \param name name associated with the particular CDR handler
00148  * \param desc description of the CDR handler
00149  * \param be function pointer to a CDR handler
00150  * Used to register a Call Detail Record handler.
00151  * Returns -1 on error, 0 on success.
00152  */
00153 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be);
00154 
00155 /*! Unregister a CDR handling engine */
00156 /*!
00157  * \param name name of CDR handler to unregister
00158  * Unregisters a CDR by it's name
00159  */
00160 void ast_cdr_unregister(const char *name);
00161 
00162 /*! Start a call */
00163 /*!
00164  * \param cdr the cdr you wish to associate with the call
00165  * Starts all CDR stuff necessary for monitoring a call
00166  * Returns nothing
00167  */
00168 void ast_cdr_start(struct ast_cdr *cdr);
00169 
00170 /*! Answer a call */
00171 /*!
00172  * \param cdr the cdr you wish to associate with the call
00173  * Starts all CDR stuff necessary for doing CDR when answering a call
00174  * NULL argument is just fine.
00175  */
00176 void ast_cdr_answer(struct ast_cdr *cdr);
00177 
00178 /*! A call wasn't answered */
00179 /*!
00180  * \param cdr the cdr you wish to associate with the call
00181  * Marks the channel disposition as "NO ANSWER"
00182  */
00183 extern void ast_cdr_noanswer(struct ast_cdr *cdr);
00184 
00185 /*! Busy a call */
00186 /*!
00187  * \param cdr the cdr you wish to associate with the call
00188  * Returns nothing
00189  */
00190 void ast_cdr_busy(struct ast_cdr *cdr);
00191 
00192 /*! Fail a call */
00193 /*!
00194  * \param cdr the cdr you wish to associate with the call
00195  * Returns nothing
00196  */
00197 void ast_cdr_failed(struct ast_cdr *cdr);
00198 
00199 /*! Save the result of the call based on the AST_CAUSE_* */
00200 /*!
00201  * \param cdr the cdr you wish to associate with the call
00202  * Returns nothing
00203  * \param cause the AST_CAUSE_*
00204  */
00205 int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
00206    
00207 /*! End a call */
00208 /*!
00209  * \param cdr the cdr you have associated the call with
00210  * Registers the end of call time in the cdr structure.
00211  * Returns nothing
00212  */
00213 void ast_cdr_end(struct ast_cdr *cdr);
00214 
00215 /*! Detaches the detail record for posting (and freeing) either now or at a
00216  * later time in bulk with other records during batch mode operation */
00217 /*! 
00218  * \param cdr Which CDR to detach from the channel thread
00219  * Prevents the channel thread from blocking on the CDR handling
00220  * Returns nothing
00221  */
00222 void ast_cdr_detach(struct ast_cdr *cdr);
00223 
00224 /*! Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines */
00225 /*!
00226  * \param shutdown Whether or not we are shutting down
00227  * Blocks the asterisk shutdown procedures until the CDR data is submitted.
00228  * Returns nothing
00229  */
00230 void ast_cdr_submit_batch(int shutdown);
00231 
00232 /*! Set the destination channel, if there was one */
00233 /*!
00234  * \param cdr Which cdr it's applied to
00235  * \param chan Channel to which dest will be
00236  * Sets the destination channel the CDR is applied to
00237  * Returns nothing
00238  */
00239 void ast_cdr_setdestchan(struct ast_cdr *cdr, const char *chan);
00240 
00241 /*! Set the last executed application */
00242 /*!
00243  * \param cdr which cdr to act upon
00244  * \param app the name of the app you wish to change it to
00245  * \param data the data you want in the data field of app you set it to
00246  * Changes the value of the last executed app
00247  * Returns nothing
00248  */
00249 void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
00250 
00251 /*! Convert a string to a detail record AMA flag */
00252 /*!
00253  * \param flag string form of flag
00254  * Converts the string form of the flag to the binary form.
00255  * Returns the binary form of the flag
00256  */
00257 int ast_cdr_amaflags2int(const char *flag);
00258 
00259 /*! Disposition to a string */
00260 /*!
00261  * \param disposition input binary form
00262  * Converts the binary form of a disposition to string form.
00263  * Returns a pointer to the string form
00264  */
00265 char *ast_cdr_disp2str(int disposition);
00266 
00267 /*! Reset the detail record, optionally posting it first */
00268 /*!
00269  * \param cdr which cdr to act upon
00270  * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
00271  *              |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
00272  */
00273 void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
00274 
00275 /*! Flags to a string */
00276 /*!
00277  * \param flags binary flag
00278  * Converts binary flags to string flags
00279  * Returns string with flag name
00280  */
00281 char *ast_cdr_flags2str(int flags);
00282 
00283 /*! Move the non-null data from the "from" cdr to the "to" cdr
00284  * \param to   the cdr to get the goodies
00285  * \param from the cdr to give the goodies
00286  */
00287 void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from);
00288 
00289 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
00290 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
00291 
00292 
00293 int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
00294 int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
00295 
00296 
00297 /* Update CDR on a channel */
00298 int ast_cdr_update(struct ast_channel *chan);
00299 
00300 
00301 extern int ast_default_amaflags;
00302 
00303 extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
00304 
00305 struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
00306 
00307 /*! Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
00308 int ast_cdr_engine_reload(void);
00309 
00310 /*! Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
00311 int ast_cdr_engine_init(void);
00312 
00313 /*! Submit any remaining CDRs and prepare for shutdown */
00314 void ast_cdr_engine_term(void);
00315 
00316 #endif /* _ASTERISK_CDR_H */

Generated on Wed Aug 15 01:24:16 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.3