Sat Aug 6 00:39:23 2011

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

Generated on Sat Aug 6 00:39:23 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7