Wed Jan 8 2020 09:49:53

Asterisk developer's documentation


app_forkcdr.c File Reference

Fork CDR application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/cdr.h"
#include "asterisk/app.h"
#include "asterisk/module.h"

Go to the source code of this file.

Enumerations

enum  {
  OPT_SETANS = (1 << 0), OPT_SETDISP = (1 << 1), OPT_RESETDEST = (1 << 2), OPT_ENDCDR = (1 << 3),
  OPT_NORESET = (1 << 4), OPT_KEEPVARS = (1 << 5), OPT_VARSET = (1 << 6), OPT_ANSLOCK = (1 << 7),
  OPT_DONTOUCH = (1 << 8)
}
 
enum  { OPT_ARG_VARSET = 0, OPT_ARG_ARRAY_SIZE }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ast_cdr_fork (struct ast_channel *chan, struct ast_flags optflags, char *set)
 
static int forkcdr_exec (struct ast_channel *chan, const char *data)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Fork The CDR into 2 separate entities" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app = "ForkCDR"
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_app_option forkcdr_exec_options [128] = { [ 'a' ] = { .flag = OPT_SETANS }, [ 'A' ] = { .flag = OPT_ANSLOCK }, [ 'd' ] = { .flag = OPT_SETDISP }, [ 'D' ] = { .flag = OPT_RESETDEST }, [ 'e' ] = { .flag = OPT_ENDCDR }, [ 'R' ] = { .flag = OPT_NORESET }, [ 's' ] = { .flag = OPT_VARSET , .arg_index = OPT_ARG_VARSET + 1 }, [ 'T' ] = { .flag = OPT_DONTOUCH }, [ 'v' ] = { .flag = OPT_KEEPVARS }, }
 

Detailed Description

Fork CDR application.

Author
Anthony Minessale anthm.nosp@m.ct@y.nosp@m.ahoo..nosp@m.com
Note
Development of this app Sponsored/Funded by TAAN Softworks Corp

Definition in file app_forkcdr.c.

Enumeration Type Documentation

anonymous enum
Enumerator
OPT_SETANS 
OPT_SETDISP 
OPT_RESETDEST 
OPT_ENDCDR 
OPT_NORESET 
OPT_KEEPVARS 
OPT_VARSET 
OPT_ANSLOCK 
OPT_DONTOUCH 

Definition at line 150 of file app_forkcdr.c.

150  {
151  OPT_SETANS = (1 << 0),
152  OPT_SETDISP = (1 << 1),
153  OPT_RESETDEST = (1 << 2),
154  OPT_ENDCDR = (1 << 3),
155  OPT_NORESET = (1 << 4),
156  OPT_KEEPVARS = (1 << 5),
157  OPT_VARSET = (1 << 6),
158  OPT_ANSLOCK = (1 << 7),
159  OPT_DONTOUCH = (1 << 8),
160 };
anonymous enum
Enumerator
OPT_ARG_VARSET 
OPT_ARG_ARRAY_SIZE 

Definition at line 162 of file app_forkcdr.c.

162  {
163  OPT_ARG_VARSET = 0,
164  /* note: this entry _MUST_ be the last one in the enum */
166 };

Function Documentation

static void __reg_module ( void  )
static

Definition at line 286 of file app_forkcdr.c.

static void __unreg_module ( void  )
static

Definition at line 286 of file app_forkcdr.c.

static void ast_cdr_fork ( struct ast_channel chan,
struct ast_flags  optflags,
char *  set 
)
static

Definition at line 180 of file app_forkcdr.c.

References ast_cdr::answer, ast_cdr_append(), ast_cdr_dup_unique(), ast_cdr_end(), AST_CDR_FLAG_ANSLOCKED, AST_CDR_FLAG_CHILD, AST_CDR_FLAG_DONT_TOUCH, AST_CDR_FLAG_KEEP_VARS, AST_CDR_FLAG_LOCKED, ast_cdr_free_vars(), ast_cdr_reset(), ast_cdr_setvar(), ast_set_flag, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tvzero(), ast_channel::cdr, ast_cdr::disposition, ast_cdr::dstchannel, ast_cdr::next, OPT_ANSLOCK, OPT_DONTOUCH, OPT_ENDCDR, OPT_NORESET, OPT_RESETDEST, OPT_SETANS, OPT_SETDISP, and ast_cdr::start.

Referenced by forkcdr_exec().

181 {
182  struct ast_cdr *cdr;
183  struct ast_cdr *newcdr;
185 
186  cdr = chan->cdr;
187 
188  while (cdr->next)
189  cdr = cdr->next;
190 
191  if (!(newcdr = ast_cdr_dup_unique(cdr)))
192  return;
193 
194  /*
195  * End the original CDR if requested BEFORE appending the new CDR
196  * otherwise we incorrectly end the new CDR also.
197  */
198  if (ast_test_flag(&optflags, OPT_ENDCDR)) {
199  ast_cdr_end(cdr);
200  }
201 
202  ast_cdr_append(cdr, newcdr);
203 
204  if (!ast_test_flag(&optflags, OPT_NORESET))
205  ast_cdr_reset(newcdr, &flags);
206 
208  ast_cdr_free_vars(cdr, 0);
209 
210  if (!ast_strlen_zero(set)) {
211  char *varname = ast_strdupa(set), *varval;
212  varval = strchr(varname,'=');
213  if (varval) {
214  *varval = 0;
215  varval++;
216  ast_cdr_setvar(cdr, varname, varval, 0);
217  }
218  }
219 
220  if (ast_test_flag(&optflags, OPT_SETANS) && !ast_tvzero(cdr->answer))
221  newcdr->answer = newcdr->start;
222 
223  if (ast_test_flag(&optflags, OPT_SETDISP))
224  newcdr->disposition = cdr->disposition;
225 
226  if (ast_test_flag(&optflags, OPT_RESETDEST))
227  newcdr->dstchannel[0] = 0;
228 
229  if (ast_test_flag(&optflags, OPT_ANSLOCK))
231 
232  if (ast_test_flag(&optflags, OPT_DONTOUCH))
234 
236 }
int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int recur)
Definition: cdr.c:343
char dstchannel[AST_MAX_EXTENSION]
Definition: cdr.h:94
void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags)
Reset the detail record, optionally posting it first.
Definition: cdr.c:1149
#define ast_test_flag(p, flag)
Definition: utils.h:63
void ast_cdr_end(struct ast_cdr *cdr)
End a call.
Definition: cdr.c:933
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_cdr * next
Definition: cdr.h:132
unsigned int flags
Definition: utils.h:201
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:100
struct ast_cdr * cdr
Definition: channel.h:766
struct ast_cdr * ast_cdr_append(struct ast_cdr *cdr, struct ast_cdr *newcdr)
Definition: cdr.c:1216
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
struct timeval answer
Definition: cdr.h:102
Responsible for call detail data.
Definition: cdr.h:82
struct timeval start
Definition: cdr.h:100
Structure used to handle boolean flags.
Definition: utils.h:200
struct ast_cdr * ast_cdr_dup_unique(struct ast_cdr *cdr)
Duplicate a record and increment the sequence number.
Definition: cdr.c:190
static int set(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:208
long int disposition
Definition: cdr.h:110
void ast_cdr_free_vars(struct ast_cdr *cdr, int recur)
Definition: cdr.c:454
static int forkcdr_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 238 of file app_forkcdr.c.

References AST_APP_ARG, ast_app_parse_options(), AST_CDR_FLAG_KEEP_VARS, ast_cdr_fork(), AST_DECLARE_APP_ARGS, ast_log(), ast_set2_flag, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_channel::cdr, forkcdr_exec_options, LOG_WARNING, ast_cdr::next, OPT_ARG_ARRAY_SIZE, OPT_ARG_VARSET, and OPT_KEEPVARS.

Referenced by load_module().

239 {
240  int res = 0;
241  char *argcopy = NULL;
242  struct ast_cdr *cdr;
243  struct ast_flags flags = {0};
244  char *opts[OPT_ARG_ARRAY_SIZE];
245  AST_DECLARE_APP_ARGS(arglist,
246  AST_APP_ARG(options);
247  );
248 
249  if (!(cdr = chan->cdr)) {
250  ast_log(LOG_WARNING, "Channel does not have a CDR\n");
251  return 0;
252  }
253 
254  argcopy = ast_strdupa(data);
255 
256  AST_STANDARD_APP_ARGS(arglist, argcopy);
257 
258  opts[OPT_ARG_VARSET] = 0;
259 
260  if (!ast_strlen_zero(arglist.options))
261  ast_app_parse_options(forkcdr_exec_options, &flags, opts, arglist.options);
262 
263  if (!ast_strlen_zero(data)) {
264  int keepvars = ast_test_flag(&flags, OPT_KEEPVARS) ? 1 : 0;
265  while (cdr->next) {
266  cdr = cdr->next;
267  }
268  ast_set2_flag(cdr, keepvars, AST_CDR_FLAG_KEEP_VARS);
269  }
270 
271  ast_cdr_fork(chan, flags, opts[OPT_ARG_VARSET]);
272 
273  return res;
274 }
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:144
struct ast_cdr * next
Definition: cdr.h:132
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int flags
Definition: utils.h:201
struct ast_cdr * cdr
Definition: channel.h:766
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static struct ast_app_option forkcdr_exec_options[128]
Definition: app_forkcdr.c:178
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
Responsible for call detail data.
Definition: cdr.h:82
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void ast_cdr_fork(struct ast_channel *chan, struct ast_flags optflags, char *set)
Definition: app_forkcdr.c:180
Structure used to handle boolean flags.
Definition: utils.h:200
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int load_module ( void  )
static

Definition at line 281 of file app_forkcdr.c.

References ast_register_application_xml, and forkcdr_exec().

282 {
284 }
static char * app
Definition: app_forkcdr.c:148
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int forkcdr_exec(struct ast_channel *chan, const char *data)
Definition: app_forkcdr.c:238
static int unload_module ( void  )
static

Definition at line 276 of file app_forkcdr.c.

References ast_unregister_application().

277 {
279 }
static char * app
Definition: app_forkcdr.c:148
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Fork The CDR into 2 separate entities" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 286 of file app_forkcdr.c.

char* app = "ForkCDR"
static

Definition at line 148 of file app_forkcdr.c.

Definition at line 286 of file app_forkcdr.c.

struct ast_app_option forkcdr_exec_options[128] = { [ 'a' ] = { .flag = OPT_SETANS }, [ 'A' ] = { .flag = OPT_ANSLOCK }, [ 'd' ] = { .flag = OPT_SETDISP }, [ 'D' ] = { .flag = OPT_RESETDEST }, [ 'e' ] = { .flag = OPT_ENDCDR }, [ 'R' ] = { .flag = OPT_NORESET }, [ 's' ] = { .flag = OPT_VARSET , .arg_index = OPT_ARG_VARSET + 1 }, [ 'T' ] = { .flag = OPT_DONTOUCH }, [ 'v' ] = { .flag = OPT_KEEPVARS }, }
static

Definition at line 178 of file app_forkcdr.c.

Referenced by forkcdr_exec().