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

Generated on Thu Jul 9 13:40:23 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7