The CDRfix4/5/6 omnibus cdr fixes.
[asterisk-bristuff.git] / include / asterisk / cdr.h
blobdc53f39322b06b2b4419ee73b5f5e88d93d533e0
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
19 /*! \file
20 * \brief Call Detail Record API
23 #ifndef _ASTERISK_CDR_H
24 #define _ASTERISK_CDR_H
26 #include <sys/time.h>
28 /*! Flags */
29 #define AST_CDR_FLAG_KEEP_VARS (1 << 0)
30 #define AST_CDR_FLAG_POSTED (1 << 1)
31 #define AST_CDR_FLAG_LOCKED (1 << 2)
32 #define AST_CDR_FLAG_CHILD (1 << 3)
33 #define AST_CDR_FLAG_POST_DISABLED (1 << 4)
34 #define AST_CDR_FLAG_BRIDGED (1 << 5)
35 #define AST_CDR_FLAG_MAIN (1 << 6)
36 #define AST_CDR_FLAG_ENABLE (1 << 7)
37 #define AST_CDR_FLAG_ANSLOCKED (1 << 8)
38 #define AST_CDR_FLAG_DONT_TOUCH (1 << 9)
40 /*! Disposition */
41 #define AST_CDR_NULL 0
42 #define AST_CDR_FAILED (1 << 0)
43 #define AST_CDR_BUSY (1 << 1)
44 #define AST_CDR_NOANSWER (1 << 2)
45 #define AST_CDR_ANSWERED (1 << 3)
47 /*! AMA Flags */
48 #define AST_CDR_OMIT (1)
49 #define AST_CDR_BILLING (2)
50 #define AST_CDR_DOCUMENTATION (3)
52 #define AST_MAX_USER_FIELD 256
53 #define AST_MAX_ACCOUNT_CODE 20
55 /* Include channel.h after relevant declarations it will need */
56 #include "asterisk/channel.h"
57 #include "asterisk/utils.h"
59 /*! Responsible for call detail data */
60 struct ast_cdr {
61 /*! Caller*ID with text */
62 char clid[AST_MAX_EXTENSION];
63 /*! Caller*ID number */
64 char src[AST_MAX_EXTENSION];
65 /*! Destination extension */
66 char dst[AST_MAX_EXTENSION];
67 /*! Destination context */
68 char dcontext[AST_MAX_EXTENSION];
70 char channel[AST_MAX_EXTENSION];
71 /*! Destination channel if appropriate */
72 char dstchannel[AST_MAX_EXTENSION];
73 /*! Last application if appropriate */
74 char lastapp[AST_MAX_EXTENSION];
75 /*! Last application data */
76 char lastdata[AST_MAX_EXTENSION];
78 struct timeval start;
80 struct timeval answer;
82 struct timeval end;
83 /*! Total time in system, in seconds */
84 long int duration;
85 /*! Total time call is up, in seconds */
86 long int billsec;
87 /*! What happened to the call */
88 long int disposition;
89 /*! What flags to use */
90 long int amaflags;
91 /*! What account number to use */
92 char accountcode[AST_MAX_ACCOUNT_CODE];
93 /*! flags */
94 unsigned int flags;
95 /* Unique Channel Identifier */
96 char uniqueid[32];
97 /* User field */
98 char userfield[AST_MAX_USER_FIELD];
100 /* A linked list for variables */
101 struct varshead varshead;
103 struct ast_cdr *next;
106 void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
107 int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
108 int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
109 void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
110 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
112 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
114 /*! \brief Allocate a CDR record
115 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
117 struct ast_cdr *ast_cdr_alloc(void);
119 /*! \brief Duplicate a record
120 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
122 struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
124 /*! \brief Free a CDR record
125 * \param cdr ast_cdr structure to free
126 * Returns nothing
128 void ast_cdr_free(struct ast_cdr *cdr);
130 /*! \brief Discard and free a CDR record
131 * \param cdr ast_cdr structure to free
132 * Returns nothing -- same as free, but no checks or complaints
134 void ast_cdr_discard(struct ast_cdr *cdr);
136 /*! \brief Initialize based on a channel
137 * \param cdr Call Detail Record to use for channel
138 * \param chan Channel to bind CDR with
139 * Initializes a CDR and associates it with a particular channel
140 * Return is negligible. (returns 0 by default)
142 int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
144 /*! Initialize based on a channel */
145 /*!
146 * \param cdr Call Detail Record to use for channel
147 * \param chan Channel to bind CDR with
148 * Initializes a CDR and associates it with a particular channel
149 * Return is negligible. (returns 0 by default)
151 int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
153 /*! Register a CDR handling engine */
155 * \param name name associated with the particular CDR handler
156 * \param desc description of the CDR handler
157 * \param be function pointer to a CDR handler
158 * Used to register a Call Detail Record handler.
159 * Returns -1 on error, 0 on success.
161 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be);
163 /*! Unregister a CDR handling engine */
165 * \param name name of CDR handler to unregister
166 * Unregisters a CDR by it's name
168 void ast_cdr_unregister(const char *name);
170 /*! Start a call */
172 * \param cdr the cdr you wish to associate with the call
173 * Starts all CDR stuff necessary for monitoring a call
174 * Returns nothing
176 void ast_cdr_start(struct ast_cdr *cdr);
178 /*! Answer a call */
180 * \param cdr the cdr you wish to associate with the call
181 * Starts all CDR stuff necessary for doing CDR when answering a call
182 * NULL argument is just fine.
184 void ast_cdr_answer(struct ast_cdr *cdr);
186 /*! A call wasn't answered */
188 * \param cdr the cdr you wish to associate with the call
189 * Marks the channel disposition as "NO ANSWER"
190 * Will skip CDR's in chain with ANS_LOCK bit set. (see
191 * forkCDR() application.
193 extern void ast_cdr_noanswer(struct ast_cdr *cdr);
195 /*! Busy a call */
197 * \param cdr the cdr you wish to associate with the call
198 * Marks the channel disposition as "BUSY"
199 * Will skip CDR's in chain with ANS_LOCK bit set. (see
200 * forkCDR() application.
201 * Returns nothing
203 void ast_cdr_busy(struct ast_cdr *cdr);
205 /*! Fail a call */
207 * \param cdr the cdr you wish to associate with the call
208 * Marks the channel disposition as "FAILED"
209 * Will skip CDR's in chain with ANS_LOCK bit set. (see
210 * forkCDR() application.
211 * Returns nothing
213 void ast_cdr_failed(struct ast_cdr *cdr);
215 /*! Save the result of the call based on the AST_CAUSE_* */
217 * \param cdr the cdr you wish to associate with the call
218 * \param cause the AST_CAUSE_*
219 * Returns nothing
221 int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
223 /*! End a call */
225 * \param cdr the cdr you have associated the call with
226 * Registers the end of call time in the cdr structure.
227 * Returns nothing
229 void ast_cdr_end(struct ast_cdr *cdr);
231 /*! Detaches the detail record for posting (and freeing) either now or at a
232 * later time in bulk with other records during batch mode operation */
233 /*!
234 * \param cdr Which CDR to detach from the channel thread
235 * Prevents the channel thread from blocking on the CDR handling
236 * Returns nothing
238 void ast_cdr_detach(struct ast_cdr *cdr);
240 /*! Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines */
242 * \param shutdown Whether or not we are shutting down
243 * Blocks the asterisk shutdown procedures until the CDR data is submitted.
244 * Returns nothing
246 void ast_cdr_submit_batch(int shutdown);
248 /*! Set the destination channel, if there was one */
250 * \param cdr Which cdr it's applied to
251 * \param chan Channel to which dest will be
252 * Sets the destination channel the CDR is applied to
253 * Returns nothing
255 void ast_cdr_setdestchan(struct ast_cdr *cdr, const char *chan);
257 /*! Set the last executed application */
259 * \param cdr which cdr to act upon
260 * \param app the name of the app you wish to change it to
261 * \param data the data you want in the data field of app you set it to
262 * Changes the value of the last executed app
263 * Returns nothing
265 void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
267 /*! Convert a string to a detail record AMA flag */
269 * \param flag string form of flag
270 * Converts the string form of the flag to the binary form.
271 * Returns the binary form of the flag
273 int ast_cdr_amaflags2int(const char *flag);
275 /*! Disposition to a string */
277 * \param disposition input binary form
278 * Converts the binary form of a disposition to string form.
279 * Returns a pointer to the string form
281 char *ast_cdr_disp2str(int disposition);
283 /*! Reset the detail record, optionally posting it first */
285 * \param cdr which cdr to act upon
286 * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
287 * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
289 void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
291 /*! Reset the detail record times, flags */
293 * \param cdr which cdr to act upon
294 * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
295 * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
297 void ast_cdr_specialized_reset(struct ast_cdr *cdr, struct ast_flags *flags);
299 /*! Flags to a string */
301 * \param flags binary flag
302 * Converts binary flags to string flags
303 * Returns string with flag name
305 char *ast_cdr_flags2str(int flags);
307 /*! Move the non-null data from the "from" cdr to the "to" cdr
308 * \param to the cdr to get the goodies
309 * \param from the cdr to give the goodies
311 void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from);
313 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
314 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
317 int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
318 int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
321 /* Update CDR on a channel */
322 int ast_cdr_update(struct ast_channel *chan);
325 extern int ast_default_amaflags;
327 extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
329 struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
331 /*! Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
332 int ast_cdr_engine_reload(void);
334 /*! Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
335 int ast_cdr_engine_init(void);
337 /*! Submit any remaining CDRs and prepare for shutdown */
338 void ast_cdr_engine_term(void);
340 #endif /* _ASTERISK_CDR_H */