2004-09-24 21:33:48 +00:00
|
|
|
/*
|
2005-09-15 15:44:26 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-09-24 21:33:48 +00:00
|
|
|
*
|
2005-09-15 15:44:26 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Anthony Minessale anthmct@yahoo.com
|
2004-09-24 21:33:48 +00:00
|
|
|
* Development of this app Sponsered/Funded by TAAN Softworks Corp
|
2005-09-15 15:44:26 +00:00
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2004-09-24 21:33:48 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-15 15:44:26 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-15 15:44:26 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Fork CDR application
|
2005-09-15 15:44:26 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2004-09-24 21:33:48 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/cdr.h"
|
|
|
|
#include "asterisk/module.h"
|
2004-09-24 21:33:48 +00:00
|
|
|
|
2005-02-16 02:58:18 +00:00
|
|
|
static char *tdesc = "Fork The CDR into 2 separate entities.";
|
2004-09-24 21:33:48 +00:00
|
|
|
static char *app = "ForkCDR";
|
|
|
|
static char *synopsis =
|
2004-10-23 12:17:46 +00:00
|
|
|
"Forks the Call Data Record";
|
|
|
|
static char *descrip =
|
2005-02-23 22:48:47 +00:00
|
|
|
" ForkCDR([options]): Causes the Call Data Record to fork an additional\n"
|
|
|
|
"cdr record starting from the time of the fork call\n"
|
|
|
|
"If the option 'v' is passed all cdr variables will be passed along also.\n"
|
|
|
|
"";
|
2004-09-24 21:33:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
2005-02-23 22:48:47 +00:00
|
|
|
static void ast_cdr_fork(struct ast_channel *chan)
|
|
|
|
{
|
2005-07-25 22:56:18 +00:00
|
|
|
struct ast_cdr *cdr;
|
|
|
|
struct ast_cdr *newcdr;
|
2005-11-07 04:14:48 +00:00
|
|
|
struct ast_flags flags = { AST_CDR_FLAG_KEEP_VARS };
|
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
if (!chan || !(cdr = chan->cdr))
|
|
|
|
return;
|
2005-11-07 04:14:48 +00:00
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
while (cdr->next)
|
|
|
|
cdr = cdr->next;
|
2005-11-07 04:14:48 +00:00
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
if (!(newcdr = ast_cdr_dup(cdr)))
|
|
|
|
return;
|
2005-11-07 04:14:48 +00:00
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
ast_cdr_append(cdr, newcdr);
|
2005-11-07 04:14:48 +00:00
|
|
|
ast_cdr_reset(newcdr, &flags);
|
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
if (!ast_test_flag(cdr, AST_CDR_FLAG_KEEP_VARS))
|
|
|
|
ast_cdr_free_vars(cdr, 0);
|
2005-11-07 04:14:48 +00:00
|
|
|
|
2005-07-25 22:56:18 +00:00
|
|
|
ast_set_flag(cdr, AST_CDR_FLAG_CHILD | AST_CDR_FLAG_LOCKED);
|
2004-09-24 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int forkcdr_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=0;
|
|
|
|
struct localuser *u;
|
|
|
|
LOCAL_USER_ADD(u);
|
2005-10-26 19:48:14 +00:00
|
|
|
if (!ast_strlen_zero(data))
|
2005-03-25 16:24:12 +00:00
|
|
|
ast_set2_flag(chan->cdr, strchr((char *)data, 'v'), AST_CDR_FLAG_KEEP_VARS);
|
2005-02-23 22:48:47 +00:00
|
|
|
|
2004-09-24 21:33:48 +00:00
|
|
|
ast_cdr_fork(chan);
|
|
|
|
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2004-09-24 21:33:48 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2005-10-18 22:52:21 +00:00
|
|
|
|
|
|
|
return res;
|
2004-09-24 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
2004-10-23 12:17:46 +00:00
|
|
|
return ast_register_application(app, forkcdr_exec, synopsis, descrip);
|
2004-09-24 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|