2 * Asterisk -- A telephony toolkit for Linux.
4 * Call Detail Record API
6 * Copyright (C) 1999 - 2005, Digium, Inc.
8 * Mark Spencer <markster@digium.com>
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>
22 #define AST_CDR_FLAG_KEEP_VARS (1 << 0)
23 #define AST_CDR_FLAG_POSTED (1 << 1)
24 #define AST_CDR_FLAG_LOCKED (1 << 2)
25 #define AST_CDR_FLAG_CHILD (1 << 3)
26 #define AST_CDR_FLAG_SETVAR (1 << 4)
27 #define AST_CDR_FLAG_RECUR (1 << 5)
29 #define AST_CDR_NOANSWER (1 << 0)
30 #define AST_CDR_BUSY (1 << 1)
31 #define AST_CDR_ANSWERED (1 << 2)
32 #define AST_CDR_FAILED (1 << 3)
35 #define AST_CDR_OMIT (1)
36 #define AST_CDR_BILLING (2)
37 #define AST_CDR_DOCUMENTATION (3)
39 #define AST_MAX_USER_FIELD 256
42 AST_LIST_HEAD(varshead,ast_var_t);
44 /*! Responsible for call detail data */
46 /*! Caller*ID with text */
47 char clid[AST_MAX_EXTENSION];
48 /*! Caller*ID number */
49 char src[AST_MAX_EXTENSION];
50 /*! Destination extension */
51 char dst[AST_MAX_EXTENSION];
52 /*! Destination context */
53 char dcontext[AST_MAX_EXTENSION];
55 char channel[AST_MAX_EXTENSION];
56 /*! Destination channel if appropriate */
57 char dstchannel[AST_MAX_EXTENSION];
58 /*! Last application if appropriate */
59 char lastapp[AST_MAX_EXTENSION];
60 /*! Last application data */
61 char lastdata[AST_MAX_EXTENSION];
65 struct timeval answer;
68 /*! Total time in system, in seconds */
70 /*! Total time call is up, in seconds */
72 /*! What happened to the call */
74 /*! What flags to use */
76 /*! What account number to use */
80 /* Unique Channel Identifier */
83 char userfield[AST_MAX_USER_FIELD];
85 /* A linked list for variables */
86 struct varshead varshead;
91 extern void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur);
92 extern int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, char *value, int recur);
93 extern int ast_cdr_serialize_variables(struct ast_cdr *cdr, char *buf, size_t size, char delim, char sep, int recur);
94 extern void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
95 extern int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
97 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
99 /*! Allocate a record */
101 * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
103 extern struct ast_cdr *ast_cdr_alloc(void);
106 /* \param cdr ast_cdr structure to free
107 * Returns nothing important
109 extern void ast_cdr_free(struct ast_cdr *cdr);
111 /*! Initialize based on a channel */
113 * \param cdr Call Detail Record to use for channel
114 * \param chan Channel to bind CDR with
115 * Initializes a CDR and associates it with a particular channel
116 * Return is negligible. (returns 0 by default)
118 extern int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
120 /*! Initialize based on a channel */
122 * \param cdr Call Detail Record to use for channel
123 * \param chan Channel to bind CDR with
124 * Initializes a CDR and associates it with a particular channel
125 * Return is negligible. (returns 0 by default)
127 extern int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
129 /*! Register a CDR handling engine */
131 * \param name name associated with the particular CDR handler
132 * \param desc description of the CDR handler
133 * \param be function pointer to a CDR handler
134 * Used to register a Call Detail Record handler.
135 * Returns -1 on error, 0 on success.
137 extern int ast_cdr_register(char *name, char *desc, ast_cdrbe be);
139 /*! Unregister a CDR handling engine */
141 * \param name name of CDR handler to unregister
142 * Unregisters a CDR by it's name
144 extern void ast_cdr_unregister(char *name);
148 * \param cdr the cdr you wish to associate with the call
149 * Starts all CDR stuff necessary for monitoring a call
150 * Returns nothing important
152 extern void ast_cdr_start(struct ast_cdr *cdr);
156 * \param cdr the cdr you wish to associate with the call
157 * Starts all CDR stuff necessary for doing CDR when answering a call
159 extern void ast_cdr_answer(struct ast_cdr *cdr);
163 * \param cdr the cdr you wish to associate with the call
164 * Returns nothing important
166 extern void ast_cdr_busy(struct ast_cdr *cdr);
170 * \param cdr the cdr you wish to associate with the call
171 * Returns nothing important
173 extern void ast_cdr_failed(struct ast_cdr *cdr);
175 /*! Save the result of the call based on the AST_CAUSE_* */
177 * \param cdr the cdr you wish to associate with the call
178 * Returns nothing important
179 * \param cause the AST_CAUSE_*
181 extern int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
185 * \param cdr the cdr you have associated the call with
186 * Registers the end of call time in the cdr structure.
187 * Returns nothing important
189 extern void ast_cdr_end(struct ast_cdr *cdr);
191 /*! Post the detail record */
193 * \param cdr Which cdr to post
194 * Actually outputs the CDR record to the CDR plugins installed
197 extern void ast_cdr_post(struct ast_cdr *cdr);
199 /*! Set the destination channel, if there was one */
201 * \param cdr Which cdr it's applied to
202 * Sets the destination channel the CDR is applied to
205 extern void ast_cdr_setdestchan(struct ast_cdr *cdr, char *chan);
207 /*! Set the last executed application */
209 * \param cdr which cdr to act upon
210 * \param app the name of the app you wish to change it to
211 * \param data the data you want in the data field of app you set it to
212 * Changes the value of the last executed app
215 extern void ast_cdr_setapp(struct ast_cdr *cdr, char *app, char *data);
217 /*! Convert a string to a detail record AMA flag */
219 * \param flag string form of flag
220 * Converts the string form of the flag to the binary form.
221 * Returns the binary form of the flag
223 extern int ast_cdr_amaflags2int(const char *flag);
225 /*! Disposition to a string */
227 * \param flag input binary form
228 * Converts the binary form of a disposition to string form.
229 * Returns a pointer to the string form
231 extern char *ast_cdr_disp2str(int disposition);
233 /*! Reset the detail record, optionally posting it first */
235 * \param cdr which cdr to act upon
236 * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
237 * |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
239 extern void ast_cdr_reset(struct ast_cdr *cdr, int flags);
241 /*! Flags to a string */
243 * \param flags binary flag
244 * Converts binary flags to string flags
245 * Returns string with flag name
247 extern char *ast_cdr_flags2str(int flags);
249 extern int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
250 extern int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
253 extern int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
254 extern int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
257 /* Update CDR on a channel */
258 extern int ast_cdr_update(struct ast_channel *chan);
261 extern int ast_default_amaflags;
263 extern char ast_default_accountcode[20];
265 extern struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);