Mon Jun 27 16:50:49 2011

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

Generated on Mon Jun 27 16:50:49 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7