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

Generated on Fri Sep 24 21:03:46 2004 for Asterisk by doxygen 1.3.8