use CDR API calls instead of re-implementing them (bug #4726)
authorKevin P. Fleming <kpfleming@digium.com>
Mon, 25 Jul 2005 22:56:18 +0000 (22:56 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Mon, 25 Jul 2005 22:56:18 +0000 (22:56 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6213 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_forkcdr.c
cdr.c
include/asterisk/cdr.h

index 9300dc2..23be3bc 100755 (executable)
@@ -40,28 +40,21 @@ STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
 
-
-static void ast_cdr_clone(struct ast_cdr *cdr) 
-{
-       struct ast_cdr *newcdr = ast_cdr_alloc();
-       memcpy(newcdr,cdr,sizeof(struct ast_cdr));
-       ast_cdr_append(cdr,newcdr);
-       newcdr->start = ast_tvnow();
-       memset(&newcdr->answer, 0, sizeof(newcdr->answer));
-       memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
-       ast_cdr_copy_vars(newcdr, cdr);
-       if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS)) {
-               ast_cdr_free_vars(cdr, 0);
-       }
-       newcdr->disposition = AST_CDR_NOANSWER;
-       ast_set_flag(cdr, AST_CDR_FLAG_CHILD|AST_CDR_FLAG_LOCKED);
-}
-
 static void ast_cdr_fork(struct ast_channel *chan) 
 {
-       if(chan && chan->cdr) {
-               ast_cdr_clone(chan->cdr);
-       }
+       struct ast_cdr *cdr;
+       struct ast_cdr *newcdr;
+       if (!chan || !(cdr = chan->cdr))
+               return;
+       while (cdr->next)
+               cdr = cdr->next;
+       if (!(newcdr = ast_cdr_dup(cdr)))
+               return;
+       ast_cdr_append(cdr, newcdr);
+       ast_cdr_reset(newcdr, AST_CDR_FLAG_KEEP_VARS);
+       if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
+               ast_cdr_free_vars(cdr, 0);
+       ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
 }
 
 static int forkcdr_exec(struct ast_channel *chan, void *data)
diff --git a/cdr.c b/cdr.c
index a77048a..64e2aae 100755 (executable)
--- a/cdr.c
+++ b/cdr.c
@@ -147,7 +147,7 @@ void ast_cdr_unregister(char *name)
        AST_LIST_UNLOCK(&be_list);
 }
 
-static struct ast_cdr *cdr_dup(struct ast_cdr *cdr) 
+struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr) 
 {
        struct ast_cdr *newcdr;
 
@@ -809,7 +809,7 @@ void ast_cdr_reset(struct ast_cdr *cdr, int flags)
                if (ast_test_flag(&tmp, AST_CDR_FLAG_LOCKED) || !ast_test_flag(cdr, AST_CDR_FLAG_LOCKED)) {
                        if (ast_test_flag(&tmp, AST_CDR_FLAG_POSTED)) {
                                ast_cdr_end(cdr);
-                               if ((dup = cdr_dup(cdr))) {
+                               if ((dup = ast_cdr_dup(cdr))) {
                                        ast_cdr_detach(dup);
                                }
                                ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
index e9b8aad..e42a4e6 100755 (executable)
@@ -104,6 +104,12 @@ typedef int (*ast_cdrbe)(struct ast_cdr *cdr);
  */
 extern struct ast_cdr *ast_cdr_alloc(void);
 
+/*! Duplicate a record */
+/*! 
+ * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
+ */
+extern struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr);
+
 /*! Free a record */
 /* \param cdr ast_cdr structure to free
  * Returns nothing important