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
00026
00027
00028
00029 #include "asterisk.h"
00030
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 40722 $")
00032
00033 #include <stdlib.h>
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <unistd.h>
00037
00038 #include "asterisk/file.h"
00039 #include "asterisk/logger.h"
00040 #include "asterisk/channel.h"
00041 #include "asterisk/pbx.h"
00042 #include "asterisk/cdr.h"
00043 #include "asterisk/module.h"
00044
00045 static char *app = "ForkCDR";
00046 static char *synopsis =
00047 "Forks the Call Data Record";
00048 static char *descrip =
00049 " ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
00050 "cdr record starting from the time of the fork call\n"
00051 "If the option 'v' is passed all cdr variables will be passed along also.\n";
00052
00053
00054 static void ast_cdr_fork(struct ast_channel *chan)
00055 {
00056 struct ast_cdr *cdr;
00057 struct ast_cdr *newcdr;
00058 struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
00059
00060 cdr = chan->cdr;
00061
00062 while (cdr->next)
00063 cdr = cdr->next;
00064
00065 if (!(newcdr = ast_cdr_dup(cdr)))
00066 return;
00067
00068 ast_cdr_append(cdr, newcdr);
00069 ast_cdr_reset(newcdr, &flags);
00070
00071 if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
00072 ast_cdr_free_vars(cdr, 0);
00073
00074 ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
00075 }
00076
00077 static int forkcdr_exec(struct ast_channel *chan, void *data)
00078 {
00079 int res = 0;
00080 struct ast_module_user *u;
00081
00082 if (!chan->cdr) {
00083 ast_log(LOG_WARNING, "Channel does not have a CDR\n");
00084 return 0;
00085 }
00086
00087 u = ast_module_user_add(chan);
00088
00089 if (!ast_strlen_zero(data))
00090 ast_set2_flag(chan->cdr, strchr(data, 'v'), AST_CDR_FLAG_KEEP_VARS);
00091
00092 ast_cdr_fork(chan);
00093
00094 ast_module_user_remove(u);
00095 return res;
00096 }
00097
00098 static int unload_module(void)
00099 {
00100 int res;
00101
00102 res = ast_unregister_application(app);
00103
00104 ast_module_user_hangup_all();
00105
00106 return res;
00107 }
00108
00109 static int load_module(void)
00110 {
00111 return ast_register_application(app, forkcdr_exec, synopsis, descrip);
00112 }
00113
00114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Fork The CDR into 2 separate entities");