Properly play a holdtime message if the announce-holdtime option is
[asterisk-bristuff.git] / include / asterisk / cdr.h
blob3f0c25c47231dbfd0c67e8a622ef7b1443329301
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>
27 #define AST_CDR_FLAG_KEEP_VARS (1 << 0)
28 #define AST_CDR_FLAG_POSTED (1 << 1)
29 #define AST_CDR_FLAG_LOCKED (1 << 2)
30 #define AST_CDR_FLAG_CHILD (1 << 3)
31 #define AST_CDR_FLAG_POST_DISABLED (1 << 4)
32 #define AST_CDR_FLAG_ANSLOCKED (1 << 5)
33 #define AST_CDR_FLAG_DONT_TOUCH (1 << 6)
35 #define AST_CDR_NULL 0
36 #define AST_CDR_FAILED (1 << 0)
37 #define AST_CDR_BUSY (1 << 1)
38 #define AST_CDR_NOANSWER (1 << 2)
39 #define AST_CDR_ANSWERED (1 << 3)
41 /*! AMA Flags */
42 #define AST_CDR_OMIT (1)
43 #define AST_CDR_BILLING (2)
44 #define AST_CDR_DOCUMENTATION (3)
46 #define AST_MAX_USER_FIELD 256
47 #define AST_MAX_ACCOUNT_CODE 20
49 /* Include channel.h after relevant declarations it will need */
50 #include "asterisk/channel.h"
51 #include "asterisk/utils.h"
53 /*! Responsible for call detail data */
54 struct ast_cdr {
55 /*! Caller*ID with text */
56 char clid[AST_MAX_EXTENSION];
57 /*! Caller*ID number */
58 char src[AST_MAX_EXTENSION];
59 /*! Destination extension */
60 char dst[AST_MAX_EXTENSION];
61 /*! Destination context */
62 char dcontext[AST_MAX_EXTENSION];
64 char channel[AST_MAX_EXTENSION];
65 /*! Destination channel if appropriate */
66 char dstchannel[AST_MAX_EXTENSION];
67 /*! Last application if appropriate */
68 char lastapp[AST_MAX_EXTENSION];
69 /*! Last application data */
70 char lastdata[AST_MAX_EXTENSION];
72 struct timeval start;
74 struct timeval answer;
76 struct timeval end;
77 /*! Total time in system, in seconds */
78 long int duration;
79 /*! Total time call is up, in seconds */
80 long int billsec;
81 /*! What happened to the call */
82 long int disposition;
83 /*! What flags to use */
84 long int amaflags;
85 /*! What account number to use */
86 char accountcode[AST_MAX_ACCOUNT_CODE];
87 /*! flags */
88 unsigned int flags;
89 /* Unique Channel Identifier */
90 char uniqueid[32];
91 /* User field */
92 char userfield[AST_MAX_USER_FIELD];
94 /* A linked list for variables */
95 struct varshead varshead;
97 struct ast_cdr *next;
100 void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
101 int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
102 int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
103 void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
104 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
106 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
108 /*! \brief Allocate a CDR record
109 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
111 struct ast_cdr *ast_cdr_alloc(void);
113 /*! \brief Duplicate a record
114 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
116 struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
118 /*! \brief Free a CDR record
119 * \param cdr ast_cdr structure to free
120 * Returns nothing
122 void ast_cdr_free(struct ast_cdr *cdr);
124 /*! \brief Discard and free a CDR record
125 * \param cdr ast_cdr structure to free
126 * Returns nothing -- same as free, but no checks or complaints
128 void ast_cdr_discard(struct ast_cdr *cdr);
130 /*! \brief Initialize based on a channel
131 * \param cdr Call Detail Record to use for channel
132 * \param chan Channel to bind CDR with
133 * Initializes a CDR and associates it with a particular channel
134 * Return is negligible. (returns 0 by default)
136 int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
138 /*! Initialize based on a channel */
139 /*!
140 * \param cdr Call Detail Record to use for channel
141 * \param chan Channel to bind CDR with
142 * Initializes a CDR and associates it with a particular channel
143 * Return is negligible. (returns 0 by default)
145 int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
147 /*! Register a CDR handling engine */
149 * \param name name associated with the particular CDR handler
150 * \param desc description of the CDR handler
151 * \param be function pointer to a CDR handler
152 * Used to register a Call Detail Record handler.
153 * Returns -1 on error, 0 on success.
155 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be);
157 /*! Unregister a CDR handling engine */
159 * \param name name of CDR handler to unregister
160 * Unregisters a CDR by it's name
162 void ast_cdr_unregister(const char *name);
164 /*! Start a call */
166 * \param cdr the cdr you wish to associate with the call
167 * Starts all CDR stuff necessary for monitoring a call
168 * Returns nothing
170 void ast_cdr_start(struct ast_cdr *cdr);
172 /*! Answer a call */
174 * \param cdr the cdr you wish to associate with the call
175 * Starts all CDR stuff necessary for doing CDR when answering a call
176 * NULL argument is just fine.
178 void ast_cdr_answer(struct ast_cdr *cdr);
180 /*! A call wasn't answered */
182 * \param cdr the cdr you wish to associate with the call
183 * Marks the channel disposition as "NO ANSWER"
184 * Will skip CDR's in chain with ANS_LOCK bit set. (see
185 * forkCDR() application.
187 extern void ast_cdr_noanswer(struct ast_cdr *cdr);
189 /*! Busy a call */
191 * \param cdr the cdr you wish to associate with the call
192 * Marks the channel disposition as "BUSY"
193 * Will skip CDR's in chain with ANS_LOCK bit set. (see
194 * forkCDR() application.
195 * Returns nothing
197 void ast_cdr_busy(struct ast_cdr *cdr);
199 /*! Fail a call */
201 * \param cdr the cdr you wish to associate with the call
202 * Marks the channel disposition as "FAILED"
203 * Will skip CDR's in chain with ANS_LOCK bit set. (see
204 * forkCDR() application.
205 * Returns nothing
207 void ast_cdr_failed(struct ast_cdr *cdr);
209 /*! Save the result of the call based on the AST_CAUSE_* */
211 * \param cdr the cdr you wish to associate with the call
212 * \param cause the AST_CAUSE_*
213 * Returns nothing
215 int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
217 /*! End a call */
219 * \param cdr the cdr you have associated the call with
220 * Registers the end of call time in the cdr structure.
221 * Returns nothing
223 void ast_cdr_end(struct ast_cdr *cdr);
225 /*! Detaches the detail record for posting (and freeing) either now or at a
226 * later time in bulk with other records during batch mode operation */
227 /*!
228 * \param cdr Which CDR to detach from the channel thread
229 * Prevents the channel thread from blocking on the CDR handling
230 * Returns nothing
232 void ast_cdr_detach(struct ast_cdr *cdr);
234 /*! Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines */
236 * \param shutdown Whether or not we are shutting down
237 * Blocks the asterisk shutdown procedures until the CDR data is submitted.
238 * Returns nothing
240 void ast_cdr_submit_batch(int shutdown);
242 /*! Set the destination channel, if there was one */
244 * \param cdr Which cdr it's applied to
245 * \param chan Channel to which dest will be
246 * Sets the destination channel the CDR is applied to
247 * Returns nothing
249 void ast_cdr_setdestchan(struct ast_cdr *cdr, const char *chan);
251 /*! Set the last executed application */
253 * \param cdr which cdr to act upon
254 * \param app the name of the app you wish to change it to
255 * \param data the data you want in the data field of app you set it to
256 * Changes the value of the last executed app
257 * Returns nothing
259 void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
261 /*! Convert a string to a detail record AMA flag */
263 * \param flag string form of flag
264 * Converts the string form of the flag to the binary form.
265 * Returns the binary form of the flag
267 int ast_cdr_amaflags2int(const char *flag);
269 /*! Disposition to a string */
271 * \param disposition input binary form
272 * Converts the binary form of a disposition to string form.
273 * Returns a pointer to the string form
275 char *ast_cdr_disp2str(int disposition);
277 /*! Reset the detail record, optionally posting it first */
279 * \param cdr which cdr to act upon
280 * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
281 * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
283 void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
285 /*! Flags to a string */
287 * \param flags binary flag
288 * Converts binary flags to string flags
289 * Returns string with flag name
291 char *ast_cdr_flags2str(int flags);
293 /*! Move the non-null data from the "from" cdr to the "to" cdr
294 * \param to the cdr to get the goodies
295 * \param from the cdr to give the goodies
297 void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from);
299 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
300 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
303 int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
304 int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
307 /* Update CDR on a channel */
308 int ast_cdr_update(struct ast_channel *chan);
311 extern int ast_default_amaflags;
313 extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
315 struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
317 /*! Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
318 int ast_cdr_engine_reload(void);
320 /*! Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
321 int ast_cdr_engine_init(void);
323 /*! Submit any remaining CDRs and prepare for shutdown */
324 void ast_cdr_engine_term(void);
326 #endif /* _ASTERISK_CDR_H */