Thu Oct 11 06:33:36 2012

Asterisk developer's documentation


cdr.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020  * \file
00021  * \brief Call Detail Record API
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  */
00025 
00026 #ifndef _ASTERISK_CDR_H
00027 #define _ASTERISK_CDR_H
00028 
00029 #include <sys/time.h>
00030 
00031 #include "asterisk/data.h"
00032 
00033 /*!
00034  * \brief CDR Flags
00035  */
00036 enum {
00037    AST_CDR_FLAG_KEEP_VARS     = (1 << 0),
00038    AST_CDR_FLAG_POSTED        = (1 << 1),
00039    AST_CDR_FLAG_LOCKED        = (1 << 2),
00040    AST_CDR_FLAG_CHILD         = (1 << 3),
00041    AST_CDR_FLAG_POST_DISABLED = (1 << 4),
00042    AST_CDR_FLAG_BRIDGED       = (1 << 5),
00043    AST_CDR_FLAG_MAIN          = (1 << 6),
00044    AST_CDR_FLAG_ENABLE        = (1 << 7),
00045    AST_CDR_FLAG_ANSLOCKED     = (1 << 8),
00046    AST_CDR_FLAG_DONT_TOUCH    = (1 << 9),
00047    AST_CDR_FLAG_POST_ENABLE   = (1 << 10),
00048    AST_CDR_FLAG_DIALED        = (1 << 11),
00049    AST_CDR_FLAG_ORIGINATED    = (1 << 12),
00050 };
00051 
00052 /*!
00053  * \brief CDR Flags - Disposition
00054  */
00055 enum {
00056    AST_CDR_NOANSWER = 0,
00057    AST_CDR_NULL     = (1 << 0),
00058    AST_CDR_FAILED   = (1 << 1),
00059    AST_CDR_BUSY     = (1 << 2),
00060    AST_CDR_ANSWERED = (1 << 3),
00061    AST_CDR_CONGESTION = (1 << 4),
00062 };
00063 
00064 /*!
00065  * \brief CDR AMA Flags
00066  */
00067 enum {
00068    AST_CDR_OMIT          = 1,
00069    AST_CDR_BILLING       = 2,
00070    AST_CDR_DOCUMENTATION = 3,
00071 };
00072 
00073 #define AST_MAX_USER_FIELD     256
00074 #define AST_MAX_ACCOUNT_CODE   20
00075 
00076 /* Include channel.h after relevant declarations it will need */
00077 #include "asterisk/channel.h"
00078 #include "asterisk/utils.h"
00079 
00080 /*!
00081  * \brief Responsible for call detail data
00082  */
00083 struct ast_cdr {
00084    /*! Caller*ID with text */
00085    char clid[AST_MAX_EXTENSION];
00086    /*! Caller*ID number */
00087    char src[AST_MAX_EXTENSION];
00088    /*! Destination extension */
00089    char dst[AST_MAX_EXTENSION];
00090    /*! Destination context */
00091    char dcontext[AST_MAX_EXTENSION];
00092 
00093    char channel[AST_MAX_EXTENSION];
00094    /*! Destination channel if appropriate */
00095    char dstchannel[AST_MAX_EXTENSION];
00096    /*! Last application if appropriate */
00097    char lastapp[AST_MAX_EXTENSION];
00098    /*! Last application data */
00099    char lastdata[AST_MAX_EXTENSION];
00100 
00101    struct timeval start;
00102 
00103    struct timeval answer;
00104 
00105    struct timeval end;
00106    /*! Total time in system, in seconds */
00107    long int duration;
00108    /*! Total time call is up, in seconds */
00109    long int billsec;
00110    /*! What happened to the call */
00111    long int disposition;
00112    /*! What flags to use */
00113    long int amaflags;
00114    /*! What account number to use */
00115    char accountcode[AST_MAX_ACCOUNT_CODE];
00116    /*! Account number of the last person we talked to */
00117    char peeraccount[AST_MAX_ACCOUNT_CODE];
00118    /*! flags */
00119    unsigned int flags;
00120    /*! Unique Channel Identifier
00121     * 150 = 127 (max systemname) + "-" + 10 (epoch timestamp) + "." + 10 (monotonically incrementing integer) + NULL */
00122    char uniqueid[150];
00123    /* Linked group Identifier */
00124    char linkedid[32];
00125    /*! User field */
00126    char userfield[AST_MAX_USER_FIELD];
00127    /*! Sequence field */
00128    int sequence;
00129 
00130    /*! A linked list for variables */
00131    struct varshead varshead;
00132 
00133    struct ast_cdr *next;
00134 };
00135 
00136 int ast_cdr_isset_unanswered(void);
00137 int ast_cdr_isset_congestion(void);
00138 void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *workspace, int workspacelen, int recur, int raw);
00139 int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur);
00140 int ast_cdr_serialize_variables(struct ast_cdr *cdr, struct ast_str **buf, char delim, char sep, int recur);
00141 void ast_cdr_free_vars(struct ast_cdr *cdr, int recur);
00142 int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr);
00143 
00144 /*!
00145  * \brief CDR backend callback
00146  * \warning CDR backends should NOT attempt to access the channel associated
00147  * with a CDR record.  This channel is not guaranteed to exist when the CDR
00148  * backend is invoked.
00149  */
00150 typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
00151 
00152 /*! \brief Return TRUE if CDR subsystem is enabled */
00153 int check_cdr_enabled(void);
00154 
00155 /*!
00156  * \brief Allocate a CDR record
00157  * \retval a malloc'd ast_cdr structure
00158  * \retval NULL on error (malloc failure)
00159  */
00160 struct ast_cdr *ast_cdr_alloc(void);
00161 
00162 /*!
00163  * \brief Duplicate a record and increment the sequence number.
00164  * \param cdr the record to duplicate
00165  * \retval a malloc'd ast_cdr structure,
00166  * \retval NULL on error (malloc failure)
00167  * \see ast_cdr_dup()
00168  * \see ast_cdr_dup_unique_swap()
00169  */
00170 struct ast_cdr *ast_cdr_dup_unique(struct ast_cdr *cdr);
00171 
00172 /*!
00173  * \brief Duplicate a record and increment the sequence number of the old
00174  * record.
00175  * \param cdr the record to duplicate
00176  * \retval a malloc'd ast_cdr structure,
00177  * \retval NULL on error (malloc failure)
00178  * \note This version increments the original CDR's sequence number rather than
00179  * the duplicate's sequence number. The effect is as if the original CDR's
00180  * sequence number was swapped with the duplicate's sequence number.
00181  *
00182  * \see ast_cdr_dup()
00183  * \see ast_cdr_dup_unique()
00184  */
00185 struct ast_cdr *ast_cdr_dup_unique_swap(struct ast_cdr *cdr);
00186 
00187 /*!
00188  * \brief Duplicate a record
00189  * \param cdr the record to duplicate
00190  * \retval a malloc'd ast_cdr structure,
00191  * \retval NULL on error (malloc failure)
00192  * \see ast_cdr_dup_unique()
00193  * \see ast_cdr_dup_unique_swap()
00194  */
00195 struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
00196 
00197 /*!
00198  * \brief Free a CDR record
00199  * \param cdr ast_cdr structure to free
00200  * Returns nothing
00201  */
00202 void ast_cdr_free(struct ast_cdr *cdr);
00203 
00204 /*!
00205  * \brief Discard and free a CDR record
00206  * \param cdr ast_cdr structure to free
00207  * Returns nothing  -- same as free, but no checks or complaints
00208  */
00209 void ast_cdr_discard(struct ast_cdr *cdr);
00210 
00211 /*!
00212  * \brief Initialize based on a channel
00213  * \param cdr Call Detail Record to use for channel
00214  * \param chan Channel to bind CDR with
00215  * Initializes a CDR and associates it with a particular channel
00216  * \note The channel should be locked before calling.
00217  * \return 0 by default
00218  */
00219 int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
00220 
00221 /*!
00222  * \brief Initialize based on a channel
00223  * \param cdr Call Detail Record to use for channel
00224  * \param chan Channel to bind CDR with
00225  * Initializes a CDR and associates it with a particular channel
00226  * \note The channel should be locked before calling.
00227  * \return 0 by default
00228  */
00229 int ast_cdr_setcid(struct ast_cdr *cdr, struct ast_channel *chan);
00230 
00231 /*!
00232  * \brief Register a CDR handling engine
00233  * \param name name associated with the particular CDR handler
00234  * \param desc description of the CDR handler
00235  * \param be function pointer to a CDR handler
00236  * Used to register a Call Detail Record handler.
00237  * \retval 0 on success.
00238  * \retval -1 on error
00239  */
00240 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be);
00241 
00242 /*!
00243  * \brief Unregister a CDR handling engine
00244  * \param name name of CDR handler to unregister
00245  * Unregisters a CDR by it's name
00246  */
00247 void ast_cdr_unregister(const char *name);
00248 
00249 /*!
00250  * \brief Start a call
00251  * \param cdr the cdr you wish to associate with the call
00252  * Starts all CDR stuff necessary for monitoring a call
00253  * Returns nothing
00254  */
00255 void ast_cdr_start(struct ast_cdr *cdr);
00256 
00257 /*! \brief Answer a call
00258  * \param cdr the cdr you wish to associate with the call
00259  * Starts all CDR stuff necessary for doing CDR when answering a call
00260  * \note NULL argument is just fine.
00261  */
00262 void ast_cdr_answer(struct ast_cdr *cdr);
00263 
00264 /*!
00265  * \brief A call wasn't answered
00266  * \param cdr the cdr you wish to associate with the call
00267  * Marks the channel disposition as "NO ANSWER"
00268  * Will skip CDR's in chain with ANS_LOCK bit set. (see
00269  * forkCDR() application.
00270  */
00271 extern void ast_cdr_noanswer(struct ast_cdr *cdr);
00272 
00273 /*!
00274  * \brief A call was set to congestion
00275  * \param cdr the cdr you wish to associate with the call
00276  * Markst he channel disposition as "CONGESTION"
00277  * Will skip CDR's in chain with ANS_LOCK bit set. (see
00278  * forkCDR() application
00279  */
00280 extern void ast_cdr_congestion(struct ast_cdr *cdr);
00281 
00282 /*!
00283  * \brief Busy a call
00284  * \param cdr the cdr you wish to associate with the call
00285  * Marks the channel disposition as "BUSY"
00286  * Will skip CDR's in chain with ANS_LOCK bit set. (see
00287  * forkCDR() application.
00288  * Returns nothing
00289  */
00290 void ast_cdr_busy(struct ast_cdr *cdr);
00291 
00292 /*!
00293  * \brief Fail a call
00294  * \param cdr the cdr you wish to associate with the call
00295  * Marks the channel disposition as "FAILED"
00296  * Will skip CDR's in chain with ANS_LOCK bit set. (see
00297  * forkCDR() application.
00298  * Returns nothing
00299  */
00300 void ast_cdr_failed(struct ast_cdr *cdr);
00301 
00302 /*!
00303  * \brief Save the result of the call based on the AST_CAUSE_*
00304  * \param cdr the cdr you wish to associate with the call
00305  * \param cause the AST_CAUSE_*
00306  * Returns nothing
00307  */
00308 int ast_cdr_disposition(struct ast_cdr *cdr, int cause);
00309 
00310 /*!
00311  * \brief End a call
00312  * \param cdr the cdr you have associated the call with
00313  * Registers the end of call time in the cdr structure.
00314  * Returns nothing
00315  */
00316 void ast_cdr_end(struct ast_cdr *cdr);
00317 
00318 /*!
00319  * \brief Detaches the detail record for posting (and freeing) either now or at a
00320  * later time in bulk with other records during batch mode operation.
00321  * \param cdr Which CDR to detach from the channel thread
00322  * Prevents the channel thread from blocking on the CDR handling
00323  * Returns nothing
00324  */
00325 void ast_cdr_detach(struct ast_cdr *cdr);
00326 
00327 /*!
00328  * \brief Spawns (possibly) a new thread to submit a batch of CDRs to the backend engines
00329  * \param shutdown Whether or not we are shutting down
00330  * Blocks the asterisk shutdown procedures until the CDR data is submitted.
00331  * Returns nothing
00332  */
00333 void ast_cdr_submit_batch(int shutdown);
00334 
00335 /*!
00336  * \brief Set the destination channel, if there was one
00337  * \param cdr Which cdr it's applied to
00338  * \param chan Channel to which dest will be
00339  * Sets the destination channel the CDR is applied to
00340  * Returns nothing
00341  */
00342 void ast_cdr_setdestchan(struct ast_cdr *cdr, const char *chan);
00343 
00344 /*!
00345  * \brief Set the last executed application
00346  * \param cdr which cdr to act upon
00347  * \param app the name of the app you wish to change it to
00348  * \param data the data you want in the data field of app you set it to
00349  * Changes the value of the last executed app
00350  * Returns nothing
00351  */
00352 void ast_cdr_setapp(struct ast_cdr *cdr, const char *app, const char *data);
00353 
00354 /*!
00355  * \brief Set the answer time for a call
00356  * \param cdr the cdr you wish to associate with the call
00357  * \param t the answer time
00358  * Starts all CDR stuff necessary for doing CDR when answering a call
00359  * NULL argument is just fine.
00360  */
00361 void ast_cdr_setanswer(struct ast_cdr *cdr, struct timeval t);
00362 
00363 /*!
00364  * \brief Set the disposition for a call
00365  * \param cdr the cdr you wish to associate with the call
00366  * \param disposition the new disposition
00367  * Set the disposition on a call.
00368  * NULL argument is just fine.
00369  */
00370 void ast_cdr_setdisposition(struct ast_cdr *cdr, long int disposition);
00371 
00372 /*!
00373  * \brief Convert a string to a detail record AMA flag
00374  * \param flag string form of flag
00375  * Converts the string form of the flag to the binary form.
00376  * \return the binary form of the flag
00377  */
00378 int ast_cdr_amaflags2int(const char *flag);
00379 
00380 /*!
00381  * \brief Disposition to a string
00382  * \param disposition input binary form
00383  * Converts the binary form of a disposition to string form.
00384  * \return a pointer to the string form
00385  */
00386 char *ast_cdr_disp2str(int disposition);
00387 
00388 /*!
00389  * \brief Reset the detail record, optionally posting it first
00390  * \param cdr which cdr to act upon
00391  * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
00392  *              |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
00393  */
00394 void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags);
00395 
00396 /*! Reset the detail record times, flags */
00397 /*!
00398  * \param cdr which cdr to act upon
00399  * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
00400  *              |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
00401  */
00402 void ast_cdr_specialized_reset(struct ast_cdr *cdr, struct ast_flags *flags);
00403 
00404 /*! Flags to a string */
00405 /*!
00406  * \param flags binary flag
00407  * Converts binary flags to string flags
00408  * Returns string with flag name
00409  */
00410 char *ast_cdr_flags2str(int flags);
00411 
00412 /*!
00413  * \brief Move the non-null data from the "from" cdr to the "to" cdr
00414  * \param to the cdr to get the goodies
00415  * \param from the cdr to give the goodies
00416  */
00417 void ast_cdr_merge(struct ast_cdr *to, struct ast_cdr *from);
00418 
00419 /*!
00420  * \brief Set account code, will generate AMI event
00421  * \note The channel should be locked before calling.
00422  */
00423 int ast_cdr_setaccount(struct ast_channel *chan, const char *account);
00424 
00425 /*!
00426  * \brief Set the peer account
00427  * \note The channel should be locked before calling.
00428  */
00429 int ast_cdr_setpeeraccount(struct ast_channel *chan, const char *account);
00430 
00431 /*!
00432  * \brief Set AMA flags for channel
00433  * \note The channel should be locked before calling.
00434  */
00435 int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags);
00436 
00437 /*!
00438  * \brief Set CDR user field for channel (stored in CDR)
00439  * \note The channel should be locked before calling.
00440  */
00441 int ast_cdr_setuserfield(struct ast_channel *chan, const char *userfield);
00442 /*!
00443  * \brief Append to CDR user field for channel (stored in CDR)
00444  * \note The channel should be locked before calling.
00445  */
00446 int ast_cdr_appenduserfield(struct ast_channel *chan, const char *userfield);
00447 
00448 
00449 /*!
00450  * \brief Update CDR on a channel
00451  * \note The channel should be locked before calling.
00452  */
00453 int ast_cdr_update(struct ast_channel *chan);
00454 
00455 
00456 extern int ast_default_amaflags;
00457 
00458 extern char ast_default_accountcode[AST_MAX_ACCOUNT_CODE];
00459 
00460 struct ast_cdr *ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr);
00461 
00462 /*! \brief Reload the configuration file cdr.conf and start/stop CDR scheduling thread */
00463 int ast_cdr_engine_reload(void);
00464 
00465 /*! \brief Load the configuration file cdr.conf and possibly start the CDR scheduling thread */
00466 int ast_cdr_engine_init(void);
00467 
00468 /*! Submit any remaining CDRs and prepare for shutdown */
00469 void ast_cdr_engine_term(void);
00470 
00471 /*!
00472  * \brief
00473  * \param[in] tree Where to insert the cdr.
00474  * \param[in] cdr The cdr structure to insert in 'tree'.
00475  * \param[in] recur Go throw all the cdr levels.
00476  * \retval <0 on error.
00477  * \retval 0 on success.
00478  */
00479 int ast_cdr_data_add_structure(struct ast_data *tree, struct ast_cdr *cdr, int recur);
00480 
00481 #endif /* _ASTERISK_CDR_H */

Generated on Thu Oct 11 06:33:36 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6