aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_setcdruserfield.c
blob: 19eb1d4e3bd8c75e743d382075f073490d2ad4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * Asterisk -- A telephony toolkit for Linux.
 *
 * Applictions connected with CDR engine
 * 
 * Copyright (C) 2003, Digium
 *
 * Justin Huff <jjhuff@mspin.net>
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License
 */

#include <sys/types.h>
#include <asterisk/channel.h>
#include <asterisk/cdr.h>
#include <asterisk/module.h>
#include <asterisk/pbx.h>
#include <asterisk/logger.h>

#include <stdlib.h>
#include <string.h>


static char *tdesc = "CDR user field apps";

static char *setcdruserfield_descrip = 
		"SetCDRUserField(value): Set the CDR user field to value\n";
		
static char *setcdruserfield_app = "SetCDRUserField";
static char *setcdruserfield_synopsis = "Set the CDR user field";

static char *appendcdruserfield_descrip = 
		"AppendCDRUserField(value): Append value to the CDR user field\n";
		
static char *appendcdruserfield_app = "AppendCDRUserField";
static char *appendcdruserfield_synopsis = "Append to the CDR user field";

STANDARD_LOCAL_USER;

LOCAL_USER_DECL;

static int setcdruserfield_exec(struct ast_channel *chan, void *data)
{
	struct localuser *u;
	int res = 0;
	
	LOCAL_USER_ADD(u)
	if (chan->cdr && data) 
	{
		ast_cdr_setuserfield(chan, (char*)data);
	}

	LOCAL_USER_REMOVE(u);
	
	return res;
}

static int appendcdruserfield_exec(struct ast_channel *chan, void *data)
{
	struct localuser *u;
	int res = 0;
	
	LOCAL_USER_ADD(u)
	if (chan->cdr && data) 
	{
		ast_cdr_appenduserfield(chan, (char*)data);
	}

	LOCAL_USER_REMOVE(u);
	
	return res;
}

int unload_module(void)
{
	int res;
	STANDARD_HANGUP_LOCALUSERS;
	res = ast_unregister_application(setcdruserfield_app);
	res |= ast_unregister_application(appendcdruserfield_app);
	return res;
}

int load_module(void)
{
	int res;
	res = ast_register_application(setcdruserfield_app, setcdruserfield_exec, setcdruserfield_synopsis, setcdruserfield_descrip);
	res |= ast_register_application(appendcdruserfield_app, appendcdruserfield_exec, appendcdruserfield_synopsis, appendcdruserfield_descrip);

	return res;
}

char *description(void)
{
	return tdesc;
}

int usecount(void)
{
	int res;
	STANDARD_USECOUNT(res);
	return res;
}

char *key()
{
	return ASTERISK_GPL_KEY;
}