Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Macros | Enumerations | Functions | Variables
cdr_radius.c File Reference

RADIUS CDR Support. More...

#include "asterisk.h"
#include <RADIUS_HEADER_STR>
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
Include dependency graph for cdr_radius.c:

Go to the source code of this file.

Macros

#define DATE_FORMAT   "%Y-%m-%d %T %z"
 
#define VENDOR_CODE   22736
 

Enumerations

enum  {
  PW_AST_ACCT_CODE = 101 , PW_AST_SRC = 102 , PW_AST_DST = 103 , PW_AST_DST_CTX = 104 ,
  PW_AST_CLID = 105 , PW_AST_CHAN = 106 , PW_AST_DST_CHAN = 107 , PW_AST_LAST_APP = 108 ,
  PW_AST_LAST_DATA = 109 , PW_AST_START_TIME = 110 , PW_AST_ANSWER_TIME = 111 , PW_AST_END_TIME = 112 ,
  PW_AST_DURATION = 113 , PW_AST_BILL_SEC = 114 , PW_AST_DISPOSITION = 115 , PW_AST_AMA_FLAGS = 116 ,
  PW_AST_UNIQUE_ID = 117 , PW_AST_USER_FIELD = 118
}
 
enum  { RADIUS_FLAG_USEGMTIME = (1 << 0) , RADIUS_FLAG_LOGUNIQUEID = (1 << 1) , RADIUS_FLAG_LOGUSERFIELD = (1 << 2) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int build_radius_record (VALUE_PAIR **tosend, struct ast_cdr *cdr)
 
static int load_module (void)
 
static int radius_log (struct ast_cdr *cdr)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER, .description = "RADIUS CDR Backend", .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cdr", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const char cdr_config [] = "cdr.conf"
 
static const char desc [] = "RADIUS CDR Backend"
 
static struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD }
 
static const char name [] = "radius"
 
static char radiuscfg [PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf"
 
static rc_handle * rh = NULL
 

Detailed Description

RADIUS CDR Support.

Author
Philippe Sultan The Radius Client Library http://developer.berlios.de/projects/radiusclient-ng/

Definition in file cdr_radius.c.

Macro Definition Documentation

◆ DATE_FORMAT

#define DATE_FORMAT   "%Y-%m-%d %T %z"

ISO 8601 standard format

Definition at line 50 of file cdr_radius.c.

◆ VENDOR_CODE

#define VENDOR_CODE   22736

Definition at line 52 of file cdr_radius.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PW_AST_ACCT_CODE 
PW_AST_SRC 
PW_AST_DST 
PW_AST_DST_CTX 
PW_AST_CLID 
PW_AST_CHAN 
PW_AST_DST_CHAN 
PW_AST_LAST_APP 
PW_AST_LAST_DATA 
PW_AST_START_TIME 
PW_AST_ANSWER_TIME 
PW_AST_END_TIME 
PW_AST_DURATION 
PW_AST_BILL_SEC 
PW_AST_DISPOSITION 
PW_AST_AMA_FLAGS 
PW_AST_UNIQUE_ID 
PW_AST_USER_FIELD 

Definition at line 54 of file cdr_radius.c.

54 {
55 PW_AST_ACCT_CODE = 101,
56 PW_AST_SRC = 102,
57 PW_AST_DST = 103,
58 PW_AST_DST_CTX = 104,
59 PW_AST_CLID = 105,
60 PW_AST_CHAN = 106,
61 PW_AST_DST_CHAN = 107,
62 PW_AST_LAST_APP = 108,
63 PW_AST_LAST_DATA = 109,
66 PW_AST_END_TIME = 112,
67 PW_AST_DURATION = 113,
68 PW_AST_BILL_SEC = 114,
70 PW_AST_AMA_FLAGS = 116,
71 PW_AST_UNIQUE_ID = 117,
73};
@ PW_AST_DST_CHAN
Definition: cdr_radius.c:61
@ PW_AST_DURATION
Definition: cdr_radius.c:67
@ PW_AST_SRC
Definition: cdr_radius.c:56
@ PW_AST_ACCT_CODE
Definition: cdr_radius.c:55
@ PW_AST_END_TIME
Definition: cdr_radius.c:66
@ PW_AST_UNIQUE_ID
Definition: cdr_radius.c:71
@ PW_AST_DISPOSITION
Definition: cdr_radius.c:69
@ PW_AST_LAST_APP
Definition: cdr_radius.c:62
@ PW_AST_USER_FIELD
Definition: cdr_radius.c:72
@ PW_AST_AMA_FLAGS
Definition: cdr_radius.c:70
@ PW_AST_CHAN
Definition: cdr_radius.c:60
@ PW_AST_ANSWER_TIME
Definition: cdr_radius.c:65
@ PW_AST_START_TIME
Definition: cdr_radius.c:64
@ PW_AST_DST_CTX
Definition: cdr_radius.c:58
@ PW_AST_CLID
Definition: cdr_radius.c:59
@ PW_AST_BILL_SEC
Definition: cdr_radius.c:68
@ PW_AST_DST
Definition: cdr_radius.c:57
@ PW_AST_LAST_DATA
Definition: cdr_radius.c:63

◆ anonymous enum

anonymous enum
Enumerator
RADIUS_FLAG_USEGMTIME 

Log dates and times in UTC

RADIUS_FLAG_LOGUNIQUEID 

Log Unique ID

RADIUS_FLAG_LOGUSERFIELD 

Log User Field

Definition at line 75 of file cdr_radius.c.

75 {
76 /*! Log dates and times in UTC */
77 RADIUS_FLAG_USEGMTIME = (1 << 0),
78 /*! Log Unique ID */
79 RADIUS_FLAG_LOGUNIQUEID = (1 << 1),
80 /*! Log User Field */
82};
@ RADIUS_FLAG_USEGMTIME
Definition: cdr_radius.c:77
@ RADIUS_FLAG_LOGUNIQUEID
Definition: cdr_radius.c:79
@ RADIUS_FLAG_LOGUSERFIELD
Definition: cdr_radius.c:81

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 291 of file cdr_radius.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 291 of file cdr_radius.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 291 of file cdr_radius.c.

◆ build_radius_record()

static int build_radius_record ( VALUE_PAIR **  tosend,
struct ast_cdr cdr 
)
static

Definition at line 98 of file cdr_radius.c.

99{
100 int recordtype = PW_STATUS_STOP;
101 struct ast_tm tm;
102 char timestr[128];
103 char *tmp;
104
105 if (!rc_avpair_add(rh, tosend, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0))
106 return -1;
107
108 /* Account code */
109 if (!rc_avpair_add(rh, tosend, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE))
110 return -1;
111
112 /* Source */
113 if (!rc_avpair_add(rh, tosend, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE))
114 return -1;
115
116 /* Destination */
117 if (!rc_avpair_add(rh, tosend, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE))
118 return -1;
119
120 /* Destination context */
121 if (!rc_avpair_add(rh, tosend, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE))
122 return -1;
123
124 /* Caller ID */
125 if (!rc_avpair_add(rh, tosend, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE))
126 return -1;
127
128 /* Channel */
129 if (!rc_avpair_add(rh, tosend, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE))
130 return -1;
131
132 /* Destination Channel */
133 if (!rc_avpair_add(rh, tosend, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE))
134 return -1;
135
136 /* Last Application */
137 if (!rc_avpair_add(rh, tosend, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE))
138 return -1;
139
140 /* Last Data */
141 if (!rc_avpair_add(rh, tosend, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE))
142 return -1;
143
144
145 /* Start Time */
146 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
147 ast_localtime(&cdr->start, &tm,
149 if (!rc_avpair_add(rh, tosend, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE))
150 return -1;
151
152 /* Answer Time */
153 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
154 ast_localtime(&cdr->answer, &tm,
156 if (!rc_avpair_add(rh, tosend, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE))
157 return -1;
158
159 /* End Time */
160 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT,
161 ast_localtime(&cdr->end, &tm,
163 if (!rc_avpair_add(rh, tosend, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE))
164 return -1;
165
166 /* Duration */
167 if (!rc_avpair_add(rh, tosend, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE))
168 return -1;
169
170 /* Billable seconds */
171 if (!rc_avpair_add(rh, tosend, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE))
172 return -1;
173
174 /* Disposition */
176 if (!rc_avpair_add(rh, tosend, PW_AST_DISPOSITION, tmp, strlen(tmp), VENDOR_CODE))
177 return -1;
178
179 /* AMA Flags */
181 if (!rc_avpair_add(rh, tosend, PW_AST_AMA_FLAGS, tmp, strlen(tmp), VENDOR_CODE))
182 return -1;
183
185 /* Unique ID */
186 if (!rc_avpair_add(rh, tosend, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE))
187 return -1;
188 }
189
191 /* append the user field */
192 if (!rc_avpair_add(rh, tosend, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE))
193 return -1;
194 }
195
196 /* Setting Acct-Session-Id & User-Name attributes for proper generation
197 * of Acct-Unique-Session-Id on server side
198 */
199 /* Channel */
200 if (!rc_avpair_add(rh, tosend, PW_USER_NAME, &cdr->channel, strlen(cdr->channel), 0))
201 return -1;
202
203 /* Unique ID */
204 if (!rc_avpair_add(rh, tosend, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0))
205 return -1;
206
207 return 0;
208}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
static int tmp()
Definition: bt_open.c:389
const char * ast_cdr_disp2str(int disposition)
Disposition to a string.
Definition: cdr.c:3492
#define VENDOR_CODE
Definition: cdr_radius.c:52
static rc_handle * rh
Definition: cdr_radius.c:96
static struct ast_flags global_flags
Definition: cdr_radius.c:94
#define DATE_FORMAT
Definition: cdr_radius.c:50
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
Definition: channel.c:4372
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
Definition: localtime.c:2524
#define NULL
Definition: resample.c:96
char dstchannel[AST_MAX_EXTENSION]
Definition: cdr.h:291
long int disposition
Definition: cdr.h:307
char lastdata[AST_MAX_EXTENSION]
Definition: cdr.h:295
char userfield[AST_MAX_USER_FIELD]
Definition: cdr.h:321
long int billsec
Definition: cdr.h:305
struct timeval answer
Definition: cdr.h:299
char channel[AST_MAX_EXTENSION]
Definition: cdr.h:289
long int duration
Definition: cdr.h:303
long int amaflags
Definition: cdr.h:309
char src[AST_MAX_EXTENSION]
Definition: cdr.h:283
char dst[AST_MAX_EXTENSION]
Definition: cdr.h:285
char clid[AST_MAX_EXTENSION]
Definition: cdr.h:281
char uniqueid[AST_MAX_UNIQUEID]
Definition: cdr.h:317
struct timeval start
Definition: cdr.h:297
char accountcode[AST_MAX_ACCOUNT_CODE]
Definition: cdr.h:311
char lastapp[AST_MAX_EXTENSION]
Definition: cdr.h:293
char dcontext[AST_MAX_EXTENSION]
Definition: cdr.h:287
struct timeval end
Definition: cdr.h:301
#define ast_test_flag(p, flag)
Definition: utils.h:63

References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_channel_amaflags2string(), ast_localtime(), ast_strdupa, ast_strftime(), ast_test_flag, ast_cdr::billsec, ast_cdr::channel, ast_cdr::clid, DATE_FORMAT, ast_cdr::dcontext, ast_cdr::disposition, ast_cdr::dst, ast_cdr::dstchannel, ast_cdr::duration, ast_cdr::end, global_flags, ast_cdr::lastapp, ast_cdr::lastdata, NULL, PW_AST_ACCT_CODE, PW_AST_AMA_FLAGS, PW_AST_ANSWER_TIME, PW_AST_BILL_SEC, PW_AST_CHAN, PW_AST_CLID, PW_AST_DISPOSITION, PW_AST_DST, PW_AST_DST_CHAN, PW_AST_DST_CTX, PW_AST_DURATION, PW_AST_END_TIME, PW_AST_LAST_APP, PW_AST_LAST_DATA, PW_AST_SRC, PW_AST_START_TIME, PW_AST_UNIQUE_ID, PW_AST_USER_FIELD, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_LOGUSERFIELD, RADIUS_FLAG_USEGMTIME, rh, ast_cdr::src, ast_cdr::start, tmp(), ast_cdr::uniqueid, ast_cdr::userfield, and VENDOR_CODE.

Referenced by radius_log().

◆ load_module()

static int load_module ( void  )
static

Definition at line 246 of file cdr_radius.c.

247{
248 struct ast_config *cfg;
249 struct ast_flags config_flags = { 0 };
250 const char *tmp;
251
252 if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) {
256 if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg")))
259 } else
261
262 /* read radiusclient-ng config file */
263 if (!(rh = rc_read_config(radiuscfg))) {
264 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
266 }
267
268 /* read radiusclient-ng dictionaries */
269 if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
270 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
271 rc_destroy(rh);
272 rh = NULL;
274 }
275
277 rc_destroy(rh);
278 rh = NULL;
280 } else {
282 }
283}
#define ast_log
Definition: astobj2.c:42
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
Register a CDR handling engine.
Definition: cdr.c:3005
static const char cdr_config[]
Definition: cdr_radius.c:86
static const char name[]
Definition: cdr_radius.c:85
static const char desc[]
Definition: cdr_radius.c:84
static char radiuscfg[PATH_MAX]
Definition: cdr_radius.c:91
static int radius_log(struct ast_cdr *cdr)
Definition: cdr_radius.c:210
#define ast_config_load(filename, flags)
Load a config file.
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: extconf.c:1289
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:783
#define LOG_NOTICE
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Structure used to handle boolean flags.
Definition: utils.h:199
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94

References ast_cdr_register(), ast_config_destroy(), ast_config_load, ast_copy_string(), ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_set2_flag, ast_true(), ast_variable_retrieve(), cdr_config, CONFIG_STATUS_FILEINVALID, desc, global_flags, LOG_NOTICE, name, NULL, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_LOGUSERFIELD, RADIUS_FLAG_USEGMTIME, radius_log(), radiuscfg, rh, and tmp().

◆ radius_log()

static int radius_log ( struct ast_cdr cdr)
static

Definition at line 210 of file cdr_radius.c.

211{
212 int result = ERROR_RC;
213 VALUE_PAIR *tosend = NULL;
214
215 if (build_radius_record(&tosend, cdr)) {
216 ast_debug(1, "Unable to create RADIUS record. CDR not recorded!\n");
217 goto return_cleanup;
218 }
219
220 result = rc_acct(rh, 0, tosend);
221 if (result != OK_RC) {
222 ast_log(LOG_ERROR, "Failed to record Radius CDR record!\n");
223 }
224
225return_cleanup:
226 if (tosend) {
227 rc_avpair_free(tosend);
228 }
229
230 return result;
231}
static int build_radius_record(VALUE_PAIR **tosend, struct ast_cdr *cdr)
Definition: cdr_radius.c:98
static PGresult * result
Definition: cel_pgsql.c:84
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR

References ast_debug, ast_log, build_radius_record(), LOG_ERROR, NULL, result, and rh.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 233 of file cdr_radius.c.

234{
236 return -1;
237 }
238
239 if (rh) {
240 rc_destroy(rh);
241 rh = NULL;
242 }
243 return 0;
244}
int ast_cdr_unregister(const char *name)
Unregister a CDR handling engine.
Definition: cdr.c:3050

References ast_cdr_unregister(), name, NULL, and rh.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER, .description = "RADIUS CDR Backend", .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cdr", }
static

Definition at line 291 of file cdr_radius.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 291 of file cdr_radius.c.

◆ cdr_config

const char cdr_config[] = "cdr.conf"
static

Definition at line 86 of file cdr_radius.c.

Referenced by load_module(), and module_config_alloc().

◆ desc

const char desc[] = "RADIUS CDR Backend"
static

◆ global_flags

Definition at line 94 of file cdr_radius.c.

Referenced by build_radius_record(), and load_module().

◆ name

const char name[] = "radius"
static

Definition at line 85 of file cdr_radius.c.

Referenced by load_module(), and unload_module().

◆ radiuscfg

char radiuscfg[PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf"
static

Definition at line 91 of file cdr_radius.c.

Referenced by load_module().

◆ rh

rc_handle* rh = NULL
static