Index: include/asterisk/cdr.h =================================================================== --- include/asterisk/cdr.h (revision 184257) +++ include/asterisk/cdr.h (working copy) @@ -103,6 +103,8 @@ /*! Unique Channel Identifier * 150 = 127 (max systemname) + "-" + 10 (epoch timestamp) + "." + 10 (monotonically incrementing integer) + NULL */ char uniqueid[150]; + /*! CDR Instance per Channel ID. Incremented by a CDR reset if it posts a CDR */ + int cdrinstance; /*! User field */ char userfield[AST_MAX_USER_FIELD]; Index: main/cdr.c =================================================================== --- main/cdr.c (revision 184257) +++ main/cdr.c (working copy) @@ -270,6 +270,8 @@ ast_copy_string(workspace, cdr->accountcode, workspacelen); else if (!strcasecmp(name, "uniqueid")) ast_copy_string(workspace, cdr->uniqueid, workspacelen); + else if (!strcasecmp(name, "cdrinstance")) + snprintf(workspace, workspacelen, "%d",cdr->cdrinstance); else if (!strcasecmp(name, "userfield")) ast_copy_string(workspace, cdr->userfield, workspacelen); else if ((varbuf = ast_cdr_getvar_internal(cdr, name, recur))) @@ -284,7 +286,7 @@ /* readonly cdr variables */ static const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel", "lastapp", "lastdata", "start", "answer", "end", "duration", - "billsec", "disposition", "amaflags", "accountcode", "uniqueid", + "billsec", "disposition", "amaflags", "accountcode", "uniqueid", "cdrinstance", "userfield", NULL }; /*! Set a CDR channel variable \note You can't set the CDR variables that belong to the actual CDR record, like "billsec". @@ -835,6 +837,7 @@ ast_copy_string(cdr->dcontext, S_OR(c->macrocontext,c->context), sizeof(cdr->dcontext)); /* Unique call identifier */ ast_copy_string(cdr->uniqueid, c->uniqueid, sizeof(cdr->uniqueid)); + cdr->cdrinstance = 0; } } return 0; @@ -1039,6 +1042,7 @@ ast_cdr_end(cdr); if ((dup = ast_cdr_dup(cdr))) { ast_cdr_detach(dup); + cdr->cdrinstance++; } ast_set_flag(cdr, AST_CDR_FLAG_POSTED); } @@ -1063,6 +1067,7 @@ cdr->duration = 0; ast_cdr_start(cdr); cdr->disposition = AST_CDR_NULL; + ast_log(LOG_DEBUG, "CDR is Reset. Instance is now %d .\n",cdr->cdrinstance); } } }