2 * Asterisk -- A telephony toolkit for Linux.
4 * Call Detail Record API
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License.
13 * Includes code and algorithms from the Zapata library.
20 #include <asterisk/channel.h>
23 #define AST_CDR_NOANSWER (1 << 0)
24 #define AST_CDR_BUSY (1 << 1)
25 #define AST_CDR_ANSWERED (1 << 2)
28 #define AST_CDR_OMIT (1)
29 #define AST_CDR_BILLING (2)
30 #define AST_CDR_DOCUMENTATION (3)
34 //! Responsible for call detail data
36 /*! Caller*ID with text */
37 char clid[AST_MAX_EXTENSION];
38 /*! Caller*ID number */
39 char src[AST_MAX_EXTENSION];
40 /*! Destination extension */
41 char dst[AST_MAX_EXTENSION];
42 /*! Destination context */
43 char dcontext[AST_MAX_EXTENSION];
45 char channel[AST_MAX_EXTENSION];
46 /*! Destination channel if appropriate */
47 char dstchannel[AST_MAX_EXTENSION];
48 /*! Last application if appropriate */
49 char lastapp[AST_MAX_EXTENSION];
50 /*! Last application data */
51 char lastdata[AST_MAX_EXTENSION];
55 struct timeval answer;
58 /*! Total time in system, in seconds */
60 /*! Total time call is up, in seconds */
62 /*! What happened to the call */
64 /*! What flags to use */
66 /*! What account number to use */
68 /*! Whether or not the record has been posted */
72 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
76 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
78 extern struct ast_cdr *ast_cdr_alloc(void);
81 /* \param cdr ast_cdr structure to free
82 * Returns nothing important
84 extern void ast_cdr_free(struct ast_cdr *cdr);
86 //! Initialize based on a channel
88 * \param cdr Call Detail Record to use for channel
89 * \param chan Channel to bind CDR with
90 * Initializes a CDR and associates it with a particular channel
91 * Return is negligible. (returns 0 by default)
93 extern int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
95 //! Initialize based on a channel
97 * \param cdr Call Detail Record to use for channel
98 * \param chan Channel to bind CDR with
99 * Initializes a CDR and associates it with a particular channel
100 * Return is negligible. (returns 0 by default)
102 extern int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
104 //! Register a CDR handling engine
106 * \param name name associated with the particular CDR handler
107 * \param desc description of the CDR handler
108 * \param be function pointer to a CDR handler
109 * Used to register a Call Detail Record handler.
110 * Returns -1 on error, 0 on success.
112 extern int ast_cdr_register(char *name, char *desc, ast_cdrbe be);
114 //! Unregister a CDR handling engine
116 * \param name name of CDR handler to unregister
117 * Unregisters a CDR by it's name
119 extern void ast_cdr_unregister(char *name);
123 * \param cdr the cdr you wish to associate with the call
124 * Starts all CDR stuff necessary for monitoring a call
125 * Returns nothing important
127 extern void ast_cdr_start(struct ast_cdr *cdr);
131 * \param cdr the cdr you wish to associate with the call
132 * Starts all CDR stuff necessary for doing CDR when answering a call
134 extern void ast_cdr_answer(struct ast_cdr *cdr);
138 * \param cdr the cdr you wish to associate with the call
139 * Returns nothing important
141 extern void ast_cdr_busy(struct ast_cdr *cdr);
145 * \param cdr the cdr you have associated the call with
146 * Registers the end of call time in the cdr structure.
147 * Returns nothing important
149 extern void ast_cdr_end(struct ast_cdr *cdr);
151 //! Post the detail record
153 * \param cdr Which cdr to post
154 * Actually outputs the CDR record to the CDR plugins installed
157 extern void ast_cdr_post(struct ast_cdr *cdr);
159 //! Set the destination channel, if there was one
161 * \param cdr Which cdr it's applied to
162 * Sets the destination channel the CDR is applied to
165 extern void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chan);
167 //! Set the last executed application
169 * \param cdr which cdr to act upon
170 * \param app the name of the app you wish to change it to
171 * \param data the data you want in the data field of app you set it to
172 * Changes the value of the last executed app
175 extern void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
177 //! Convert a string to a detail record AMA flag
179 * \param flag string form of flag
180 * Converts the string form of the flag to the binary form.
181 * Returns the binary form of the flag
183 extern int ast_cdr_amaflags2int(char *flag);
185 //! Disposition to a string
187 * \param flag input binary form
188 * Converts the binary form of a disposition to string form.
189 * Returns a pointer to the string form
191 extern char *ast_cdr_disp2str(int disposition);
193 //! Reset the detail record, optionally posting it first
195 * \param cdr which cdr to act upon
196 * \param post whether or not to post the cdr first before resetting it
198 extern void ast_cdr_reset(struct ast_cdr *cdr, int post);
200 //! Flags to a string
202 * \param flags binary flag
203 * Converts binary flags to string flags
204 * Returns string with flag name
206 extern char *ast_cdr_flags2str(int flags);
208 extern int ast_cdr_setaccount(struct ast_channel *chan, char *account);
209 /* Update CDR on a channel */
210 extern int ast_cdr_update(struct ast_channel *chan);
213 extern int ast_default_amaflags;
215 extern char ast_default_accountcode[20];