00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <string.h>
00028 #include <unistd.h>
00029
00030 #include "asterisk.h"
00031
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $")
00033
00034 #include "asterisk/file.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/cdr.h"
00039 #include "asterisk/module.h"
00040
00041 static char *tdesc = "Fork The CDR into 2 separate entities.";
00042 static char *app = "ForkCDR";
00043 static char *synopsis =
00044 "Forks the Call Data Record";
00045 static char *descrip =
00046 " ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
00047 "cdr record starting from the time of the fork call\n"
00048 "If the option 'v' is passed all cdr variables will be passed along also.\n"
00049 "";
00050
00051
00052 STANDARD_LOCAL_USER;
00053
00054 LOCAL_USER_DECL;
00055
00056 static void ast_cdr_fork(struct ast_channel *chan)
00057 {
00058 struct ast_cdr *cdr;
00059 struct ast_cdr *newcdr;
00060 struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
00061
00062 cdr = chan->cdr;
00063
00064 while (cdr->next)
00065 cdr = cdr->next;
00066
00067 if (!(newcdr = ast_cdr_dup(cdr)))
00068 return;
00069
00070 ast_cdr_append(cdr, newcdr);
00071 ast_cdr_reset(newcdr, &flags);
00072
00073 if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
00074 ast_cdr_free_vars(cdr, 0);
00075
00076 ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
00077 }
00078
00079 static int forkcdr_exec(struct ast_channel *chan, void *data)
00080 {
00081 int res = 0;
00082 struct localuser *u;
00083
00084 if (!chan->cdr) {
00085 ast_log(LOG_WARNING, "Channel does not have a CDR\n");
00086 return 0;
00087 }
00088
00089 LOCAL_USER_ADD(u);
00090
00091 if (!ast_strlen_zero(data))
00092 ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS);
00093
00094 ast_cdr_fork(chan);
00095
00096 LOCAL_USER_REMOVE(u);
00097 return res;
00098 }
00099
00100 int unload_module(void)
00101 {
00102 int res;
00103
00104 res = ast_unregister_application(app);
00105
00106 STANDARD_HANGUP_LOCALUSERS;
00107
00108 return res;
00109 }
00110
00111 int load_module(void)
00112 {
00113 return ast_register_application(app, forkcdr_exec, synopsis, descrip);
00114 }
00115
00116 char *description(void)
00117 {
00118 return tdesc;
00119 }
00120
00121 int usecount(void)
00122 {
00123 int res;
00124 STANDARD_USECOUNT(res);
00125 return res;
00126 }
00127
00128 char *key()
00129 {
00130 return ASTERISK_GPL_KEY;
00131 }