Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

cdr.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * Call Detail Record API 
00005  * 
00006  * Copyright (C) 1999, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License.
00012  *
00013  * Includes code and algorithms from the Zapata library.
00014  *
00015  */
00016 
00017 #ifndef _CDR_H
00018 #define _CDR_H
00019 
00020 #include <asterisk/channel.h>
00021 #include <sys/time.h>
00022 
00023 #define AST_CDR_NOANSWER         (1 << 0)
00024 #define AST_CDR_BUSY          (1 << 1)
00025 #define AST_CDR_ANSWERED         (1 << 2)
00026 #define AST_CDR_FAILED           (1 << 3)
00027 
00028 //! AMA Flags
00029 #define AST_CDR_OMIT          (1)
00030 #define AST_CDR_BILLING          (2)
00031 #define AST_CDR_DOCUMENTATION       (3)
00032 
00033 #define AST_MAX_USER_FIELD       256
00034 
00035 struct ast_channel;
00036 
00037 //! Responsible for call detail data
00038 struct ast_cdr {
00039    /*! Caller*ID with text */
00040    char clid[AST_MAX_EXTENSION];    
00041    /*! Caller*ID number */
00042    char src[AST_MAX_EXTENSION];     
00043    /*! Destination extension */
00044    char dst[AST_MAX_EXTENSION];     
00045    /*! Destination context */
00046    char dcontext[AST_MAX_EXTENSION];   
00047    
00048    char channel[AST_MAX_EXTENSION];
00049    /*! Destination channel if appropriate */
00050    char dstchannel[AST_MAX_EXTENSION]; 
00051    /*! Last application if appropriate */
00052    char lastapp[AST_MAX_EXTENSION]; 
00053    /*! Last application data */
00054    char lastdata[AST_MAX_EXTENSION];   
00055    
00056    struct timeval start;
00057    
00058    struct timeval answer;
00059    
00060    struct timeval end;
00061    /*! Total time in system, in seconds */
00062    int duration;           
00063    /*! Total time call is up, in seconds */
00064    int billsec;            
00065    /*! What happened to the call */
00066    int disposition;        
00067    /*! What flags to use */
00068    int amaflags;           
00069    /*! What account number to use */
00070    char accountcode[20];         
00071    /*! Whether or not the record has been posted */
00072    int posted;          
00073         /* Unique Channel Identifier */
00074         char uniqueid[32];
00075    /* User field */
00076    char userfield[AST_MAX_USER_FIELD];
00077 };
00078 
00079 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
00080 
00081 //! Allocate a record
00082 /*! 
00083  * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
00084  */
00085 extern struct ast_cdr *ast_cdr_alloc(void);
00086 
00087 //! Free a record
00088 /* \param cdr ast_cdr structure to free
00089  * Returns nothing important
00090  */
00091 extern void ast_cdr_free(struct ast_cdr *cdr);
00092 
00093 //! Initialize based on a channel
00094 /*! 
00095  * \param cdr Call Detail Record to use for channel
00096  * \param chan Channel to bind CDR with
00097  * Initializes a CDR and associates it with a particular channel
00098  * Return is negligible.  (returns 0 by default)
00099  */
00100 extern int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
00101 
00102 //! Initialize based on a channel
00103 /*! 
00104  * \param cdr Call Detail Record to use for channel
00105  * \param chan Channel to bind CDR with
00106  * Initializes a CDR and associates it with a particular channel
00107  * Return is negligible.  (returns 0 by default)
00108  */
00109 extern int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
00110 
00111 //! Register a CDR handling engine
00112 /*!
00113  * \param name name associated with the particular CDR handler
00114  * \param desc description of the CDR handler
00115  * \param be function pointer to a CDR handler
00116  * Used to register a Call Detail Record handler.
00117  * Returns -1 on error, 0 on success.
00118  */
00119 extern int ast_cdr_register(char *name, char *desc, ast_cdrbe be);
00120 
00121 //! Unregister a CDR handling engine
00122 /*!
00123  * \param name name of CDR handler to unregister
00124  * Unregisters a CDR by it's name
00125  */
00126 extern void ast_cdr_unregister(char *name);
00127 
00128 //! Start a call
00129 /*!
00130  * \param cdr the cdr you wish to associate with the call
00131  * Starts all CDR stuff necessary for monitoring a call
00132  * Returns nothing important
00133  */
00134 extern void ast_cdr_start(struct ast_cdr *cdr);
00135 
00136 //! Answer a call
00137 /*!
00138  * \param cdr the cdr you wish to associate with the call
00139  * Starts all CDR stuff necessary for doing CDR when answering a call
00140  */
00141 extern void ast_cdr_answer(struct ast_cdr *cdr);
00142 
00143 //! Busy a call
00144 /*!
00145  * \param cdr the cdr you wish to associate with the call
00146  * Returns nothing important
00147  */
00148 extern void ast_cdr_busy(struct ast_cdr *cdr);
00149 
00150 //! Fail a call
00151 /*!
00152  * \param cdr the cdr you wish to associate with the call
00153  * Returns nothing important
00154  */
00155 extern void ast_cdr_failed(struct ast_cdr *cdr);
00156 
00157 //! Save the result of the call based on the AST_CAUSE_*
00158 /*!
00159  * \param cdr the cdr you wish to associate with the call
00160  * Returns nothing important
00161  * \param cause the AST_CAUSE_*
00162  */
00163 extern int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
00164    
00165 //! End a call
00166 /*!
00167  * \param cdr the cdr you have associated the call with
00168  * Registers the end of call time in the cdr structure.
00169  * Returns nothing important
00170  */
00171 extern void ast_cdr_end(struct ast_cdr *cdr);
00172 
00173 //! Post the detail record
00174 /*! 
00175  * \param cdr Which cdr to post
00176  * Actually outputs the CDR record to the CDR plugins installed
00177  * Returns nothing
00178  */
00179 extern void ast_cdr_post(struct ast_cdr *cdr);
00180 
00181 //! Set the destination channel, if there was one
00182 /*!
00183  * \param cdr Which cdr it's applied to
00184  * Sets the destination channel the CDR is applied to
00185  * Returns nothing
00186  */
00187 extern void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chan);
00188 
00189 //! Set the last executed application
00190 /*!
00191  * \param cdr which cdr to act upon
00192  * \param app the name of the app you wish to change it to
00193  * \param data the data you want in the data field of app you set it to
00194  * Changes the value of the last executed app
00195  * Returns nothing
00196  */
00197 extern void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
00198 
00199 //! Convert a string to a detail record AMA flag
00200 /*!
00201  * \param flag string form of flag
00202  * Converts the string form of the flag to the binary form.
00203  * Returns the binary form of the flag
00204  */
00205 extern int ast_cdr_amaflags2int(char *flag);
00206 
00207 //! Disposition to a string
00208 /*!
00209  * \param flag input binary form
00210  * Converts the binary form of a disposition to string form.
00211  * Returns a pointer to the string form
00212  */
00213 extern char *ast_cdr_disp2str(int disposition);
00214 
00215 //! Reset the detail record, optionally posting it first
00216 /*!
00217  * \param cdr which cdr to act upon
00218  * \param post whether or not to post the cdr first before resetting it
00219  */
00220 extern void ast_cdr_reset(struct ast_cdr *cdr, int post);
00221 
00222 //! Flags to a string
00223 /*!
00224  * \param flags binary flag
00225  * Converts binary flags to string flags
00226  * Returns string with flag name
00227  */
00228 extern char *ast_cdr_flags2str(int flags);
00229 
00230 extern int ast_cdr_setaccount(struct ast_channel *chan, char *account);
00231 
00232 
00233 extern int ast_cdr_setuserfield(struct ast_channel *chan, char *userfield);
00234 extern int ast_cdr_appenduserfield(struct ast_channel *chan, char *userfield);
00235 
00236 
00237 /* Update CDR on a channel */
00238 extern int ast_cdr_update(struct ast_channel *chan);
00239 
00240 
00241 extern int ast_default_amaflags;
00242 
00243 extern char ast_default_accountcode[20];
00244 
00245 #endif /* _CDR_H */

Generated on Fri Feb 27 12:19:41 2004 for Asterisk by doxygen 1.3.5