add app_forkcdr
authorAnthony Minessale II <anthmct@yahoo.com>
Fri, 24 Sep 2004 21:33:48 +0000 (21:33 +0000)
committerAnthony Minessale II <anthmct@yahoo.com>
Fri, 24 Sep 2004 21:33:48 +0000 (21:33 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3832 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/Makefile
apps/app_forkcdr.c [new file with mode: 0755]
cdr.c
include/asterisk/cdr.h
pbx.c

index 5aacce2..ebd149c 100755 (executable)
@@ -29,7 +29,7 @@ APPS=app_dial.so app_playback.so app_voicemail.so app_directory.so app_mp3.so\
      app_nbscat.so app_sendtext.so app_exec.so app_sms.so \
      app_groupcount.so app_txtcidname.so app_controlplayback.so \
      app_talkdetect.so app_alarmreceiver.so app_userevent.so app_verbose.so \
-     app_test.so
+     app_test.so app_forkcdr.so
 
 ifneq (${OSARCH},Darwin)
 APPS+=app_intercom.so
diff --git a/apps/app_forkcdr.c b/apps/app_forkcdr.c
new file mode 100755 (executable)
index 0000000..547bfa4
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Fork CDR application
+ * Copyright Anthony Minessale anthmct@yahoo.com
+ * Development of this app Sponsered/Funded  by TAAN Softworks Corp
+ * 
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <asterisk/file.h>
+#include <asterisk/logger.h>
+#include <asterisk/channel.h>
+#include <asterisk/pbx.h>
+#include <asterisk/cdr.h>
+#include <asterisk/module.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+static char *tdesc = "Fork The CDR into 2 seperate entities.";
+static char *app = "ForkCDR";
+static char *synopsis = 
+"Forks the Call Data Record\n"
+"  ForkCDR():  Causes the Call Data Record to fork an additional\n"
+       "cdr record starting from the time of the fork call\n";
+
+
+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);
+       gettimeofday(&newcdr->start, NULL);
+       memset(&newcdr->answer, 0, sizeof(newcdr->answer));
+       ast_cdr_add_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);
+       }
+}
+
+static int forkcdr_exec(struct ast_channel *chan, void *data)
+{
+       int res=0;
+       struct localuser *u;
+       LOCAL_USER_ADD(u);
+
+       ast_cdr_fork(chan);
+
+       LOCAL_USER_REMOVE(u);
+       return res;
+}
+
+int unload_module(void)
+{
+       STANDARD_HANGUP_LOCALUSERS;
+       return ast_unregister_application(app);
+}
+
+int load_module(void)
+{
+       return ast_register_application(app, forkcdr_exec, synopsis, tdesc);
+}
+
+char *description(void)
+{
+       return tdesc;
+}
+
+int usecount(void)
+{
+       int res;
+       STANDARD_USECOUNT(res);
+       return res;
+}
+
+char *key()
+{
+       return ASTERISK_GPL_KEY;
+}
diff --git a/cdr.c b/cdr.c
index 8057fa1..f4e97ef 100755 (executable)
--- a/cdr.c
+++ b/cdr.c
@@ -499,25 +499,29 @@ void ast_cdr_post(struct ast_cdr *cdr)
        }
 }
 
-void ast_cdr_reset(struct ast_cdr *cdr, int post)
+void ast_cdr_reset(struct ast_cdr *cdr, int flags)
 {
        while (cdr) {
                /* Post if requested */
-               if (post) {
-                       ast_cdr_end(cdr);
-                       ast_cdr_post(cdr);
+               if (ast_cdr_compare_flag(flags,AST_CDR_FLAG_LOCKED) || !ast_cdr_has_flag(cdr,AST_CDR_FLAG_LOCKED)) {
+                       if (ast_cdr_compare_flag(flags,AST_CDR_FLAG_POSTED)) {
+                               ast_cdr_end(cdr);
+                               ast_cdr_post(cdr);
+                       }
+                       /* Reset to initial state */
+                       cdr->flags=0;
+                       memset(&cdr->start, 0, sizeof(cdr->start));
+                       memset(&cdr->end, 0, sizeof(cdr->end));
+                       memset(&cdr->answer, 0, sizeof(cdr->answer));
+                       cdr->billsec = 0;
+                       cdr->duration = 0;
+                       ast_cdr_start(cdr);
+                       cdr->disposition = AST_CDR_NOANSWER;
                }
-               /* Reset to initial state */
-               cdr->flags=0;
-               memset(&cdr->start, 0, sizeof(cdr->start));
-               memset(&cdr->end, 0, sizeof(cdr->end));
-               memset(&cdr->answer, 0, sizeof(cdr->answer));
-               cdr->billsec = 0;
-               cdr->duration = 0;
-               ast_cdr_start(cdr);
-               cdr->disposition = AST_CDR_NOANSWER;
+                       
                cdr = cdr->next;
        }
+       
 }
 
 void ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr) {
index 05d5066..90d9433 100755 (executable)
@@ -220,9 +220,10 @@ extern char *ast_cdr_disp2str(int disposition);
 //! Reset the detail record, optionally posting it first
 /*!
  * \param cdr which cdr to act upon
- * \param post whether or not to post the cdr first before resetting it
+ * \param flags |AST_CDR_FLAG_POSTED whether or not to post the cdr first before resetting it
+ *              |AST_CDR_FLAG_LOCKED whether or not to reset locked CDR's
  */
-extern void ast_cdr_reset(struct ast_cdr *cdr, int post);
+extern void ast_cdr_reset(struct ast_cdr *cdr, int flags);
 
 //! Flags to a string
 /*!
@@ -248,6 +249,7 @@ extern int ast_default_amaflags;
 
 extern char ast_default_accountcode[20];
 
+#define ast_cdr_compare_flag(flags, flag) (flags & (flag))
 #define ast_cdr_has_flag(cdr, flag) ((cdr)->flags & (flag))
 #define ast_cdr_add_flag(cdr, flag) ((cdr)->flags |= (flag))
 #define ast_cdr_del_flag(cdr, flag) ((cdr)->flags &= ~(flag))
diff --git a/pbx.c b/pbx.c
index 2bc05ff..16888bd 100755 (executable)
--- a/pbx.c
+++ b/pbx.c
@@ -4387,11 +4387,16 @@ static int pbx_builtin_setlanguage(struct ast_channel *chan, void *data)
 
 static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data)
 {
+       int flags = 0;
        /* Reset the CDR as specified */
-       if (data)
-               ast_cdr_reset(chan->cdr, strchr((char *)data, 'w') ? 1 : 0);
-       else
-               ast_cdr_reset(chan->cdr, 0);
+       if(data) {
+               if(strchr((char *)data, 'w'))
+                       flags |= AST_CDR_FLAG_POSTED;
+               if(strchr((char *)data, 'a'))
+                       flags |= AST_CDR_FLAG_LOCKED;
+       }
+
+       ast_cdr_reset(chan->cdr, flags);
        return 0;
 }