Asterisk - The Open Source Telephony Project GIT-master-f36a736
Macros | Enumerations | Functions | Variables
cel_radius.c File Reference

RADIUS CEL Support. More...

#include "asterisk.h"
#include <RADIUS_HEADER_STR>
#include "asterisk/channel.h"
#include "asterisk/cel.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
Include dependency graph for cel_radius.c:

Go to the source code of this file.

Macros

#define ADD_VENDOR_CODE(x, y)   (rc_avpair_add(rh, send, x, (void *)y, strlen(y), VENDOR_CODE))
 
#define DATE_FORMAT   "%Y-%m-%d %T %z"
 
#define RADIUS_BACKEND_NAME   "CEL Radius Logging"
 
#define VENDOR_CODE   22736
 

Enumerations

enum  {
  PW_AST_ACCT_CODE = 101 , PW_AST_CIDNUM = 102 , PW_AST_CIDNAME = 103 , PW_AST_CIDANI = 104 ,
  PW_AST_CIDRDNIS = 105 , PW_AST_CIDDNID = 106 , PW_AST_EXTEN = 107 , PW_AST_CONTEXT = 108 ,
  PW_AST_CHANNAME = 109 , PW_AST_APPNAME = 110 , PW_AST_APPDATA = 111 , PW_AST_EVENT_TIME = 112 ,
  PW_AST_AMA_FLAGS = 113 , PW_AST_UNIQUE_ID = 114 , PW_AST_USER_NAME = 115 , PW_AST_LINKED_ID = 116
}
 
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 **send, struct ast_cel_event_record *record)
 
static int load_module (void)
 
static void radius_log (struct ast_event *event)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER, .description = "RADIUS CEL 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 = "cel", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static char * cel_config = "cel.conf"
 
static struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD }
 
static char radiuscfg [PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf"
 
static rc_handle * rh = NULL
 

Detailed Description

RADIUS CEL Support.

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

Definition in file cel_radius.c.

Macro Definition Documentation

◆ ADD_VENDOR_CODE

#define ADD_VENDOR_CODE (   x,
 
)    (rc_avpair_add(rh, send, x, (void *)y, strlen(y), VENDOR_CODE))

Definition at line 90 of file cel_radius.c.

◆ DATE_FORMAT

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

ISO 8601 standard format

Definition at line 44 of file cel_radius.c.

◆ RADIUS_BACKEND_NAME

#define RADIUS_BACKEND_NAME   "CEL Radius Logging"

Definition at line 88 of file cel_radius.c.

◆ VENDOR_CODE

#define VENDOR_CODE   22736

Definition at line 46 of file cel_radius.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PW_AST_ACCT_CODE 
PW_AST_CIDNUM 
PW_AST_CIDNAME 
PW_AST_CIDANI 
PW_AST_CIDRDNIS 
PW_AST_CIDDNID 
PW_AST_EXTEN 
PW_AST_CONTEXT 
PW_AST_CHANNAME 
PW_AST_APPNAME 
PW_AST_APPDATA 
PW_AST_EVENT_TIME 
PW_AST_AMA_FLAGS 
PW_AST_UNIQUE_ID 
PW_AST_USER_NAME 
PW_AST_LINKED_ID 

Definition at line 48 of file cel_radius.c.

48 {
49 PW_AST_ACCT_CODE = 101,
50 PW_AST_CIDNUM = 102,
51 PW_AST_CIDNAME = 103,
52 PW_AST_CIDANI = 104,
53 PW_AST_CIDRDNIS = 105,
54 PW_AST_CIDDNID = 106,
55 PW_AST_EXTEN = 107,
56 PW_AST_CONTEXT = 108,
57 PW_AST_CHANNAME = 109,
58 PW_AST_APPNAME = 110,
59 PW_AST_APPDATA = 111,
61 PW_AST_AMA_FLAGS = 113,
62 PW_AST_UNIQUE_ID = 114,
63 PW_AST_USER_NAME = 115,
64 PW_AST_LINKED_ID = 116,
65};
@ PW_AST_CIDNAME
Definition: cel_radius.c:51
@ PW_AST_ACCT_CODE
Definition: cel_radius.c:49
@ PW_AST_USER_NAME
Definition: cel_radius.c:63
@ PW_AST_LINKED_ID
Definition: cel_radius.c:64
@ PW_AST_CIDDNID
Definition: cel_radius.c:54
@ PW_AST_UNIQUE_ID
Definition: cel_radius.c:62
@ PW_AST_CIDNUM
Definition: cel_radius.c:50
@ PW_AST_AMA_FLAGS
Definition: cel_radius.c:61
@ PW_AST_CIDRDNIS
Definition: cel_radius.c:53
@ PW_AST_APPDATA
Definition: cel_radius.c:59
@ PW_AST_CONTEXT
Definition: cel_radius.c:56
@ PW_AST_EXTEN
Definition: cel_radius.c:55
@ PW_AST_APPNAME
Definition: cel_radius.c:58
@ PW_AST_EVENT_TIME
Definition: cel_radius.c:60
@ PW_AST_CIDANI
Definition: cel_radius.c:52
@ PW_AST_CHANNAME
Definition: cel_radius.c:57

◆ 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 67 of file cel_radius.c.

67 {
68 /*! Log dates and times in UTC */
69 RADIUS_FLAG_USEGMTIME = (1 << 0),
70 /*! Log Unique ID */
71 RADIUS_FLAG_LOGUNIQUEID = (1 << 1),
72 /*! Log User Field */
74};
@ RADIUS_FLAG_USEGMTIME
Definition: cel_radius.c:69
@ RADIUS_FLAG_LOGUNIQUEID
Definition: cel_radius.c:71
@ RADIUS_FLAG_LOGUSERFIELD
Definition: cel_radius.c:73

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 261 of file cel_radius.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 261 of file cel_radius.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 261 of file cel_radius.c.

◆ build_radius_record()

static int build_radius_record ( VALUE_PAIR **  send,
struct ast_cel_event_record record 
)
static

Definition at line 92 of file cel_radius.c.

93{
94 int recordtype = PW_STATUS_STOP;
95 struct ast_tm tm;
96 char timestr[128];
97 char *amaflags;
98
99 if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) {
100 return -1;
101 }
102 /* Account code */
104 return -1;
105 }
106 /* Source */
108 return -1;
109 }
110 /* Destination */
111 if (!ADD_VENDOR_CODE(PW_AST_EXTEN, record->extension)) {
112 return -1;
113 }
114 /* Destination context */
115 if (!ADD_VENDOR_CODE(PW_AST_CONTEXT, record->context)) {
116 return -1;
117 }
118 /* Caller ID */
120 return -1;
121 }
122 /* Caller ID ani */
124 return -1;
125 }
126 /* Caller ID rdnis */
128 return -1;
129 }
130 /* Caller ID dnid */
132 return -1;
133 }
134 /* Channel */
136 return -1;
137 }
138 /* Last Application */
140 return -1;
141 }
142 /* Last Data */
144 return -1;
145 }
146 /* Event Time */
147 ast_localtime(&record->event_time, &tm,
149 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
150 if (!rc_avpair_add(rh, send, PW_AST_EVENT_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
151 return -1;
152 }
153 /* AMA Flags */
155 if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, amaflags, strlen(amaflags), VENDOR_CODE)) {
156 return -1;
157 }
159 /* Unique ID */
161 return -1;
162 }
163 }
164 /* LinkedID */
166 return -1;
167 }
168 /* Setting Acct-Session-Id & User-Name attributes for proper generation
169 of Acct-Unique-Session-Id on server side */
170 /* Channel */
171 if (!rc_avpair_add(rh, send, PW_USER_NAME, (void *)record->channel_name,
172 strlen(record->channel_name), 0)) {
173 return -1;
174 }
175 return 0;
176}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define VENDOR_CODE
Definition: cel_radius.c:46
static rc_handle * rh
Definition: cel_radius.c:86
#define ADD_VENDOR_CODE(x, y)
Definition: cel_radius.c:90
static struct ast_flags global_flags
Definition: cel_radius.c:84
#define DATE_FORMAT
Definition: cel_radius.c:44
static int amaflags
Definition: chan_iax2.c:476
const char * ast_channel_amaflags2string(enum ama_flags flags)
Convert the enum representation of an AMA flag to a string representation.
Definition: channel.c:4392
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
const char * caller_id_dnid
Definition: cel.h:157
const char * application_data
Definition: cel.h:162
const char * account_code
Definition: cel.h:163
const char * caller_id_rdnis
Definition: cel.h:156
const char * extension
Definition: cel.h:158
const char * caller_id_num
Definition: cel.h:154
const char * channel_name
Definition: cel.h:160
const char * linked_id
Definition: cel.h:166
const char * unique_id
Definition: cel.h:165
const char * context
Definition: cel.h:159
const char * application_name
Definition: cel.h:161
struct timeval event_time
Definition: cel.h:150
const char * caller_id_ani
Definition: cel.h:155
const char * caller_id_name
Definition: cel.h:153
#define ast_test_flag(p, flag)
Definition: utils.h:63

References ast_cel_event_record::account_code, ADD_VENDOR_CODE, ast_cel_event_record::amaflag, amaflags, ast_cel_event_record::application_data, ast_cel_event_record::application_name, ast_channel_amaflags2string(), ast_localtime(), ast_strdupa, ast_strftime(), ast_test_flag, ast_cel_event_record::caller_id_ani, ast_cel_event_record::caller_id_dnid, ast_cel_event_record::caller_id_name, ast_cel_event_record::caller_id_num, ast_cel_event_record::caller_id_rdnis, ast_cel_event_record::channel_name, ast_cel_event_record::context, DATE_FORMAT, ast_cel_event_record::event_time, ast_cel_event_record::extension, global_flags, ast_cel_event_record::linked_id, NULL, PW_AST_ACCT_CODE, PW_AST_AMA_FLAGS, PW_AST_APPDATA, PW_AST_APPNAME, PW_AST_CHANNAME, PW_AST_CIDANI, PW_AST_CIDDNID, PW_AST_CIDNAME, PW_AST_CIDNUM, PW_AST_CIDRDNIS, PW_AST_CONTEXT, PW_AST_EVENT_TIME, PW_AST_EXTEN, PW_AST_LINKED_ID, PW_AST_UNIQUE_ID, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_USEGMTIME, rh, ast_cel_event_record::unique_id, and VENDOR_CODE.

Referenced by radius_log().

◆ load_module()

static int load_module ( void  )
static

Definition at line 216 of file cel_radius.c.

217{
218 struct ast_config *cfg;
219 struct ast_flags config_flags = { 0 };
220 const char *tmp;
221
222 if ((cfg = ast_config_load(cel_config, config_flags))) {
224 if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) {
226 }
228 } else {
230 }
231
232 /* read radiusclient-ng config file */
233 if (!(rh = rc_read_config(radiuscfg))) {
234 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
236 }
237
238 /* read radiusclient-ng dictionaries */
239 if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
240 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
241 rc_destroy(rh);
242 rh = NULL;
244 }
245
247 rc_destroy(rh);
248 rh = NULL;
250 } else {
252 }
253}
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition: cel.c:1783
#define RADIUS_BACKEND_NAME
Definition: cel_radius.c:88
static void radius_log(struct ast_event *event)
Definition: cel_radius.c:178
static char radiuscfg[PATH_MAX]
Definition: cel_radius.c:81
#define ast_config_load(filename, flags)
Load a config file.
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:784
#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
A container that holds all config-related information.
Definition: cel_custom.c:52
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94

References ast_cel_backend_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(), global_flags, LOG_NOTICE, NULL, RADIUS_BACKEND_NAME, RADIUS_FLAG_USEGMTIME, radius_log(), radiuscfg, rh, and tmp().

◆ radius_log()

static void radius_log ( struct ast_event event)
static

Definition at line 178 of file cel_radius.c.

179{
180 int result = ERROR_RC;
181 VALUE_PAIR *send = NULL;
182 struct ast_cel_event_record record = {
184 };
185
186 if (ast_cel_fill_record(event, &record)) {
187 return;
188 }
189
190 if (build_radius_record(&send, &record)) {
191 ast_debug(1, "Unable to create RADIUS record. CEL not recorded!\n");
192 goto return_cleanup;
193 }
194
195 result = rc_acct(rh, 0, send);
196 if (result != OK_RC) {
197 ast_log(LOG_ERROR, "Failed to record Radius CEL record!\n");
198 }
199
200return_cleanup:
201 if (send) {
202 rc_avpair_free(send);
203 }
204}
int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r)
Fill in an ast_cel_event_record from a CEL event.
Definition: cel.c:822
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Definition: cel.h:143
static PGresult * result
Definition: cel_pgsql.c:84
static int build_radius_record(VALUE_PAIR **send, struct ast_cel_event_record *record)
Definition: cel_radius.c:92
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:138
uint32_t version
struct ABI version
Definition: cel.h:148
Definition: astman.c:222

References AST_CEL_EVENT_RECORD_VERSION, ast_cel_fill_record(), ast_debug, ast_log, build_radius_record(), LOG_ERROR, NULL, result, rh, and ast_cel_event_record::version.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 206 of file cel_radius.c.

207{
209 if (rh) {
210 rc_destroy(rh);
211 rh = NULL;
212 }
214}
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
Definition: cel.c:1771

References ast_cel_backend_unregister(), AST_MODULE_LOAD_SUCCESS, NULL, RADIUS_BACKEND_NAME, and rh.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER, .description = "RADIUS CEL 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 = "cel", }
static

Definition at line 261 of file cel_radius.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 261 of file cel_radius.c.

◆ cel_config

char* cel_config = "cel.conf"
static

Definition at line 76 of file cel_radius.c.

◆ global_flags

Definition at line 84 of file cel_radius.c.

Referenced by build_radius_record(), and load_module().

◆ radiuscfg

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

Definition at line 81 of file cel_radius.c.

Referenced by load_module().

◆ rh

rc_handle* rh = NULL
static

Definition at line 86 of file cel_radius.c.

Referenced by build_radius_record(), load_module(), radius_log(), and unload_module().