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

Generated on Thu May 14 15:12:48 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7