#include <asterisk/lock.h>#include <asterisk/channel.h>#include <asterisk/cdr.h>#include <asterisk/logger.h>#include <asterisk/callerid.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <pthread.h>Go to the source code of this file.
Data Structures | |
| struct | ast_cdr_beitem |
Functions | |
| int | ast_cdr_register (char *name, char *desc, ast_cdrbe be) |
| Register a CDR handling engine. | |
| void | ast_cdr_unregister (char *name) |
| Unregister a CDR handling engine. | |
| void | ast_cdr_free (struct ast_cdr *cdr) |
| Free a record. | |
| ast_cdr * | ast_cdr_alloc (void) |
| Allocate a record. | |
| void | ast_cdr_start (struct ast_cdr *cdr) |
| Start a call. | |
| void | ast_cdr_answer (struct ast_cdr *cdr) |
| Answer a call. | |
| void | ast_cdr_busy (struct ast_cdr *cdr) |
| Busy a call. | |
| void | ast_cdr_setdestchan (struct ast_cdr *cdr, char *chann) |
| Set the destination channel, if there was one. | |
| void | ast_cdr_setapp (struct ast_cdr *cdr, char *app, char *data) |
| Set the last executed application. | |
| int | ast_cdr_setcid (struct ast_cdr *cdr, struct ast_channel *c) |
| Initialize based on a channel. | |
| int | ast_cdr_init (struct ast_cdr *cdr, struct ast_channel *c) |
| Initialize based on a channel. | |
| void | ast_cdr_end (struct ast_cdr *cdr) |
| End a call. | |
| char * | ast_cdr_disp2str (int disposition) |
| Disposition to a string. | |
| char * | ast_cdr_flags2str (int flag) |
| Flags to a string. | |
| int | ast_cdr_setaccount (struct ast_channel *chan, char *account) |
| int | ast_cdr_update (struct ast_channel *c) |
| int | ast_cdr_amaflags2int (char *flag) |
| Convert a string to a detail record AMA flag. | |
| void | ast_cdr_post (struct ast_cdr *cdr) |
| Post the detail record. | |
| void | ast_cdr_reset (struct ast_cdr *cdr, int post) |
| Reset the detail record, optionally posting it first. | |
Variables | |
| int | ast_default_amaflags = AST_CDR_DOCUMENTATION |
| char | ast_default_accountcode [20] = "" |
|
|
Allocate a record. Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure) Definition at line 116 of file cdr.c. References malloc. Referenced by ast_pbx_run().
|
|
|
Convert a string to a detail record AMA flag.
Definition at line 339 of file cdr.c. References AST_CDR_BILLING, AST_CDR_DOCUMENTATION, and AST_CDR_OMIT.
00340 {
00341 if (!strcasecmp(flag, "default"))
00342 return 0;
00343 if (!strcasecmp(flag, "omit"))
00344 return AST_CDR_OMIT;
00345 if (!strcasecmp(flag, "billing"))
00346 return AST_CDR_BILLING;
00347 if (!strcasecmp(flag, "documentation"))
00348 return AST_CDR_DOCUMENTATION;
00349 return -1;
00350 }
|
|
|
Answer a call.
Definition at line 139 of file cdr.c. References ast_cdr::answer, AST_CDR_ANSWERED, ast_log(), ast_cdr::channel, ast_cdr::disposition, LOG_WARNING, and ast_cdr::posted. Referenced by ast_answer(), and ast_read().
00140 {
00141 char *chan;
00142 if (cdr) {
00143 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00144 if (cdr->posted)
00145 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00146 if (cdr->disposition < AST_CDR_ANSWERED)
00147 cdr->disposition = AST_CDR_ANSWERED;
00148 if (!cdr->answer.tv_sec && !cdr->answer.tv_usec) {
00149 gettimeofday(&cdr->answer, NULL);
00150 }
00151 }
00152 }
|
|
|
Busy a call.
Definition at line 154 of file cdr.c. References AST_CDR_BUSY, ast_log(), ast_cdr::channel, ast_cdr::disposition, LOG_WARNING, and ast_cdr::posted.
00155 {
00156 char *chan;
00157 if (cdr) {
00158 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00159 if (cdr->posted)
00160 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00161 if (cdr->disposition < AST_CDR_BUSY)
00162 cdr->disposition = AST_CDR_BUSY;
00163 }
00164 }
|
|
|
Disposition to a string.
Definition at line 273 of file cdr.c. References AST_CDR_ANSWERED, AST_CDR_BUSY, and AST_CDR_NOANSWER.
00274 {
00275 switch (disposition) {
00276 case AST_CDR_NOANSWER:
00277 return "NO ANSWER";
00278 case AST_CDR_BUSY:
00279 return "BUSY";
00280 case AST_CDR_ANSWERED:
00281 return "ANSWERED";
00282 default:
00283 return "UNKNOWN";
00284 }
00285 }
|
|
|
End a call.
Definition at line 259 of file cdr.c. References ast_log(), ast_cdr::channel, ast_cdr::end, LOG_WARNING, ast_cdr::posted, and ast_cdr::start. Referenced by ast_cdr_reset(), ast_hangup(), and ast_read().
00260 {
00261 char *chan;
00262 if (cdr) {
00263 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00264 if (cdr->posted)
00265 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00266 if (!cdr->start.tv_sec && !cdr->start.tv_usec)
00267 ast_log(LOG_WARNING, "CDR on channel '%s' has not started\n", chan);
00268 if (!cdr->end.tv_sec && !cdr->end.tv_usec)
00269 gettimeofday(&cdr->end, NULL);
00270 }
00271 }
|
|
|
Flags to a string.
Definition at line 287 of file cdr.c. References AST_CDR_BILLING, AST_CDR_DOCUMENTATION, and AST_CDR_OMIT.
00288 {
00289 switch(flag) {
00290 case AST_CDR_OMIT:
00291 return "OMIT";
00292 case AST_CDR_BILLING:
00293 return "BILLING";
00294 case AST_CDR_DOCUMENTATION:
00295 return "DOCUMENTATION";
00296 }
00297 return "Unknown";
00298 }
|
|
|
Free a record.
Definition at line 101 of file cdr.c. References ast_log(), ast_cdr::channel, ast_cdr::end, free, LOG_WARNING, ast_cdr::posted, and ast_cdr::start. Referenced by ast_hangup().
00102 {
00103 char *chan;
00104 if (cdr) {
00105 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00106 if (!cdr->posted)
00107 ast_log(LOG_WARNING, "CDR on channel '%s' not posted\n", chan);
00108 if (!cdr->end.tv_sec && !cdr->end.tv_usec)
00109 ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
00110 if (!cdr->start.tv_sec && !cdr->start.tv_usec)
00111 ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
00112 free(cdr);
00113 }
00114 }
|
|
||||||||||||
|
Initialize based on a channel.
Definition at line 216 of file cdr.c. References ast_channel::_state, ast_cdr::accountcode, ast_channel::accountcode, ast_channel::amaflags, ast_cdr::amaflags, ast_channel::ani, ast_callerid_parse(), AST_CDR_ANSWERED, AST_CDR_NOANSWER, ast_default_amaflags, ast_log(), AST_MAX_EXTENSION, ast_shrink_phone_number(), AST_STATE_UP, ast_channel::callerid, ast_cdr::channel, ast_cdr::clid, ast_channel::context, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_channel::exten, LOG_WARNING, ast_channel::name, ast_cdr::src, ast_cdr::uniqueid, and ast_channel::uniqueid. Referenced by ast_pbx_run().
00217 {
00218 char *chan;
00219 char *num, *name;
00220 char tmp[AST_MAX_EXTENSION] = "";
00221 if (cdr) {
00222 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00223 if (strlen(cdr->channel))
00224 ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan);
00225 strncpy(cdr->channel, c->name, sizeof(cdr->channel) - 1);
00226 /* Grab source from ANI or normal Caller*ID */
00227 if (c->ani)
00228 strncpy(tmp, c->ani, sizeof(tmp) - 1);
00229 else if (c->callerid)
00230 strncpy(tmp, c->callerid, sizeof(tmp) - 1);
00231 if (c->callerid)
00232 strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
00233 name = NULL;
00234 num = NULL;
00235 ast_callerid_parse(tmp, &name, &num);
00236 if (num) {
00237 ast_shrink_phone_number(num);
00238 strncpy(cdr->src, num, sizeof(cdr->src) - 1);
00239 }
00240
00241 if (c->_state == AST_STATE_UP)
00242 cdr->disposition = AST_CDR_ANSWERED;
00243 else
00244 cdr->disposition = AST_CDR_NOANSWER;
00245 if (c->amaflags)
00246 cdr->amaflags = c->amaflags;
00247 else
00248 cdr->amaflags = ast_default_amaflags;
00249 strncpy(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode) - 1);
00250 /* Destination information */
00251 strncpy(cdr->dst, c->exten, sizeof(cdr->dst) - 1);
00252 strncpy(cdr->dcontext, c->context, sizeof(cdr->dcontext) - 1);
00253 /* Unique call identifier */
00254 strncpy(cdr->uniqueid, c->uniqueid, sizeof(cdr->uniqueid) - 1);
00255 }
00256 return 0;
00257 }
|
|
|
Post the detail record.
Definition at line 352 of file cdr.c. References ast_cdr::answer, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_cdr::billsec, ast_cdr::channel, ast_cdr::duration, ast_cdr::end, LOG_WARNING, ast_cdr::posted, and ast_cdr::start. Referenced by ast_cdr_reset(), and ast_hangup().
00353 {
00354 char *chan;
00355 struct ast_cdr_beitem *i;
00356 if (cdr) {
00357 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00358 if (cdr->posted)
00359 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00360 if (!cdr->end.tv_sec && !cdr->end.tv_usec)
00361 ast_log(LOG_WARNING, "CDR on channel '%s' lacks end\n", chan);
00362 if (!cdr->start.tv_sec && !cdr->start.tv_usec)
00363 ast_log(LOG_WARNING, "CDR on channel '%s' lacks start\n", chan);
00364 cdr->duration = cdr->end.tv_sec - cdr->start.tv_sec + (cdr->end.tv_usec - cdr->start.tv_usec) / 1000000;
00365 if (cdr->answer.tv_sec || cdr->answer.tv_usec) {
00366 cdr->billsec = cdr->end.tv_sec - cdr->answer.tv_sec + (cdr->end.tv_usec - cdr->answer.tv_usec) / 1000000;
00367 } else
00368 cdr->billsec = 0;
00369 cdr->posted = 1;
00370 ast_mutex_lock(&cdrlock);
00371 i = bes;
00372 while(i) {
00373 i->be(cdr);
00374 i = i->next;
00375 }
00376 ast_mutex_unlock(&cdrlock);
00377 }
00378 }
|
|
||||||||||||||||
|
Register a CDR handling engine.
Definition at line 46 of file cdr.c. References ast_cdrbe, ast_log(), ast_mutex_lock, ast_mutex_unlock, LOG_WARNING, and malloc.
00047 {
00048 struct ast_cdr_beitem *i;
00049 if (!name)
00050 return -1;
00051 if (!be) {
00052 ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
00053 return -1;
00054 }
00055 ast_mutex_lock(&cdrlock);
00056 i = bes;
00057 while(i) {
00058 if (!strcasecmp(name, i->name))
00059 break;
00060 i = i->next;
00061 }
00062 ast_mutex_unlock(&cdrlock);
00063 if (i) {
00064 ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
00065 return -1;
00066 }
00067 i = malloc(sizeof(struct ast_cdr_beitem));
00068 if (!i)
00069 return -1;
00070 memset(i, 0, sizeof(struct ast_cdr_beitem));
00071 strncpy(i->name, name, sizeof(i->name) - 1);
00072 strncpy(i->desc, desc, sizeof(i->desc) - 1);
00073 i->be = be;
00074 ast_mutex_lock(&cdrlock);
00075 i->next = bes;
00076 bes = i;
00077 ast_mutex_unlock(&cdrlock);
00078 return 0;
00079 }
|
|
||||||||||||
|
Reset the detail record, optionally posting it first.
Definition at line 380 of file cdr.c. References ast_cdr::answer, ast_cdr_end(), AST_CDR_NOANSWER, ast_cdr_post(), ast_cdr_start(), ast_cdr::billsec, ast_cdr::disposition, ast_cdr::duration, ast_cdr::end, ast_cdr::posted, and ast_cdr::start.
00381 {
00382 /* Post if requested */
00383 if (post) {
00384 ast_cdr_end(cdr);
00385 ast_cdr_post(cdr);
00386 }
00387 /* Reset to initial state */
00388 cdr->posted = 0;
00389 memset(&cdr->start, 0, sizeof(cdr->start));
00390 memset(&cdr->end, 0, sizeof(cdr->end));
00391 memset(&cdr->answer, 0, sizeof(cdr->answer));
00392 cdr->billsec = 0;
00393 cdr->duration = 0;
00394 ast_cdr_start(cdr);
00395 cdr->disposition = AST_CDR_NOANSWER;
00396 }
|
|
||||||||||||
|
Definition at line 300 of file cdr.c. References ast_channel::accountcode, and ast_channel::cdr.
00301 {
00302 struct ast_cdr *cdr = chan->cdr;
00303
00304 strncpy(chan->accountcode, account, sizeof(chan->accountcode) - 1);
00305 if (cdr)
00306 strncpy(cdr->accountcode, chan->accountcode, sizeof(cdr->accountcode) - 1);
00307 return 0;
00308 }
|
|
||||||||||||||||
|
Set the last executed application.
Definition at line 177 of file cdr.c. References ast_log(), ast_cdr::channel, ast_cdr::lastapp, ast_cdr::lastdata, LOG_WARNING, and ast_cdr::posted. Referenced by pbx_exec().
00178 {
00179 char *chan;
00180 if (cdr) {
00181 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00182 if (cdr->posted)
00183 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00184 if (!app)
00185 app = "";
00186 strncpy(cdr->lastapp, app, sizeof(cdr->lastapp) - 1);
00187 if (!data)
00188 data = "";
00189 strncpy(cdr->lastdata, data, sizeof(cdr->lastdata) - 1);
00190 }
00191 }
|
|
||||||||||||
|
Initialize based on a channel.
Definition at line 193 of file cdr.c. References ast_channel::ani, ast_callerid_parse(), AST_MAX_EXTENSION, ast_shrink_phone_number(), ast_channel::callerid, ast_cdr::clid, and ast_cdr::src. Referenced by ast_set_callerid().
00194 {
00195 char tmp[AST_MAX_EXTENSION] = "";
00196 char *num, *name;
00197 if (cdr) {
00198 /* Grab source from ANI or normal Caller*ID */
00199 if (c->ani)
00200 strncpy(tmp, c->ani, sizeof(tmp) - 1);
00201 else if (c->callerid)
00202 strncpy(tmp, c->callerid, sizeof(tmp) - 1);
00203 if (c->callerid)
00204 strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
00205 name = NULL;
00206 num = NULL;
00207 ast_callerid_parse(tmp, &name, &num);
00208 if (num) {
00209 ast_shrink_phone_number(num);
00210 strncpy(cdr->src, num, sizeof(cdr->src) - 1);
00211 }
00212 }
00213 return 0;
00214 }
|
|
||||||||||||
|
Set the destination channel, if there was one.
Definition at line 166 of file cdr.c. References ast_log(), ast_cdr::channel, ast_cdr::dstchannel, LOG_WARNING, and ast_cdr::posted.
00167 {
00168 char *chan;
00169 if (cdr) {
00170 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00171 if (cdr->posted)
00172 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00173 strncpy(cdr->dstchannel, chann, sizeof(cdr->dstchannel) - 1);
00174 }
00175 }
|
|
|
Start a call.
Definition at line 126 of file cdr.c. References ast_log(), ast_cdr::channel, LOG_WARNING, ast_cdr::posted, and ast_cdr::start. Referenced by ast_cdr_reset(), and ast_pbx_run().
00127 {
00128 char *chan;
00129 if (cdr) {
00130 chan = strlen(cdr->channel) ? cdr->channel : "<unknown>";
00131 if (cdr->posted)
00132 ast_log(LOG_WARNING, "CDR on channel '%s' already posted\n", chan);
00133 if (cdr->start.tv_sec || cdr->start.tv_usec)
00134 ast_log(LOG_WARNING, "CDR on channel '%s' already started\n", chan);
00135 gettimeofday(&cdr->start, NULL);
00136 }
00137 }
|
|
|
Unregister a CDR handling engine.
Definition at line 81 of file cdr.c. References ast_mutex_lock, ast_mutex_unlock, and free.
00082 {
00083 struct ast_cdr_beitem *i, *prev = NULL;
00084 ast_mutex_lock(&cdrlock);
00085 i = bes;
00086 while(i) {
00087 if (!strcasecmp(name, i->name)) {
00088 if (prev)
00089 prev->next = i->next;
00090 else
00091 bes = i->next;
00092 break;
00093 }
00094 i = i->next;
00095 }
00096 ast_mutex_unlock(&cdrlock);
00097 if (i)
00098 free(i);
00099 }
|
|
|
Definition at line 310 of file cdr.c. References ast_channel::accountcode, ast_channel::ani, ast_callerid_parse(), AST_MAX_EXTENSION, ast_shrink_phone_number(), ast_channel::callerid, ast_channel::cdr, ast_channel::context, and ast_channel::exten. Referenced by ast_pbx_run().
00311 {
00312 struct ast_cdr *cdr = c->cdr;
00313 char *name, *num;
00314 char tmp[AST_MAX_EXTENSION] = "";
00315 /* Grab source from ANI or normal Caller*ID */
00316 if (c->ani)
00317 strncpy(tmp, c->ani, sizeof(tmp) - 1);
00318 else if (c->callerid)
00319 strncpy(tmp, c->callerid, sizeof(tmp) - 1);
00320 if (c->callerid)
00321 strncpy(cdr->clid, c->callerid, sizeof(cdr->clid) - 1);
00322 else
00323 strcpy(cdr->clid, "");
00324 name = NULL;
00325 num = NULL;
00326 ast_callerid_parse(tmp, &name, &num);
00327 if (num) {
00328 ast_shrink_phone_number(num);
00329 strncpy(cdr->src, num, sizeof(cdr->src) - 1);
00330 }
00331 /* Copy account code et-al */
00332 strncpy(cdr->accountcode, c->accountcode, sizeof(cdr->accountcode) - 1);
00333 /* Destination information */
00334 strncpy(cdr->dst, c->exten, sizeof(cdr->dst) - 1);
00335 strncpy(cdr->dcontext, c->context, sizeof(cdr->dcontext) - 1);
00336 return 0;
00337 }
|
|
|
Definition at line 28 of file cdr.c. Referenced by ast_channel_alloc(). |
|
|
Definition at line 27 of file cdr.c. Referenced by ast_cdr_init(), and ast_channel_alloc(). |
1.3.4