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

RADIUS CEL Support. More...

#include "asterisk.h"
#include <radcli/radcli.h>
#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 = "30ef0c93b36035ec78c9cfd712d36d9b", .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 92 of file cel_radius.c.

Referenced by build_radius_record().

◆ DATE_FORMAT

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

ISO 8601 standard format

Definition at line 46 of file cel_radius.c.

Referenced by build_radius_record().

◆ RADIUS_BACKEND_NAME

#define RADIUS_BACKEND_NAME   "CEL Radius Logging"

Definition at line 90 of file cel_radius.c.

Referenced by load_module(), and unload_module().

◆ VENDOR_CODE

#define VENDOR_CODE   22736

Definition at line 48 of file cel_radius.c.

Referenced by build_radius_record().

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

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

69  {
70  /*! Log dates and times in UTC */
71  RADIUS_FLAG_USEGMTIME = (1 << 0),
72  /*! Log Unique ID */
73  RADIUS_FLAG_LOGUNIQUEID = (1 << 1),
74  /*! Log User Field */
75  RADIUS_FLAG_LOGUSERFIELD = (1 << 2)
76 };

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 263 of file cel_radius.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 263 of file cel_radius.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 263 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 94 of file cel_radius.c.

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, 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, ast_cel_event_record::unique_id, and VENDOR_CODE.

Referenced by radius_log().

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

◆ load_module()

static int load_module ( void  )
static

Definition at line 218 of file cel_radius.c.

References ast_cel_backend_register(), ast_config_destroy(), ast_config_load, ast_copy_string(), ast_log, AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CDR_DRIVER, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_EXTENDED, ast_set2_flag, ast_true(), ast_variable_retrieve(), ASTERISK_GPL_KEY, LOG_NOTICE, NULL, RADIUS_BACKEND_NAME, RADIUS_FLAG_USEGMTIME, radius_log(), tmp(), and unload_module().

219 {
220  struct ast_config *cfg;
221  struct ast_flags config_flags = { 0 };
222  const char *tmp;
223 
224  if ((cfg = ast_config_load(cel_config, config_flags))) {
226  if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) {
227  ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
228  }
229  ast_config_destroy(cfg);
230  } else {
232  }
233 
234  /* read radiusclient-ng config file */
235  if (!(rh = rc_read_config(radiuscfg))) {
236  ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
238  }
239 
240  /* read radiusclient-ng dictionaries */
241  if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
242  ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
243  rc_destroy(rh);
244  rh = NULL;
246  }
247 
249  rc_destroy(rh);
250  rh = NULL;
252  } else {
254  }
255 }
A container that holds all config-related information.
Definition: cel_custom.c:56
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
int ast_cel_backend_register(const char *name, ast_cel_backend_cb backend_callback)
Register a CEL backend.
Definition: cel.c:1740
static int tmp()
Definition: bt_open.c:389
#define RADIUS_BACKEND_NAME
Definition: cel_radius.c:90
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define ast_config_load(filename, flags)
Load a config file.
static char radiuscfg[PATH_MAX]
Definition: cel_radius.c:83
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
static struct ast_flags global_flags
Definition: cel_radius.c:86
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
static void radius_log(struct ast_event *event)
Definition: cel_radius.c:180
#define LOG_NOTICE
Definition: logger.h:263
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Structure used to handle boolean flags.
Definition: utils.h:199
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static rc_handle * rh
Definition: cel_radius.c:88

◆ radius_log()

static void radius_log ( struct ast_event event)
static

Definition at line 180 of file cel_radius.c.

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

Referenced by load_module().

181 {
182  int result = ERROR_RC;
183  VALUE_PAIR *send = NULL;
184  struct ast_cel_event_record record = {
186  };
187 
188  if (ast_cel_fill_record(event, &record)) {
189  return;
190  }
191 
192  if (build_radius_record(&send, &record)) {
193  ast_debug(1, "Unable to create RADIUS record. CEL not recorded!\n");
194  goto return_cleanup;
195  }
196 
197  result = rc_acct(rh, 0, send);
198  if (result != OK_RC) {
199  ast_log(LOG_ERROR, "Failed to record Radius CEL record!\n");
200  }
201 
202 return_cleanup:
203  if (send) {
204  rc_avpair_free(send);
205  }
206 }
Helper struct for getting the fields out of a CEL event.
Definition: cel.h:136
static int build_radius_record(VALUE_PAIR **send, struct ast_cel_event_record *record)
Definition: cel_radius.c:94
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
uint32_t version
struct ABI version
Definition: cel.h:146
#define LOG_ERROR
Definition: logger.h:285
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
Definition: cel.h:141
static PGresult * result
Definition: cel_pgsql.c:88
static rc_handle * rh
Definition: cel_radius.c:88
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:819

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 208 of file cel_radius.c.

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

Referenced by load_module().

209 {
211  if (rh) {
212  rc_destroy(rh);
213  rh = NULL;
214  }
216 }
#define RADIUS_BACKEND_NAME
Definition: cel_radius.c:90
#define NULL
Definition: resample.c:96
int ast_cel_backend_unregister(const char *name)
Unregister a CEL backend.
Definition: cel.c:1728
static rc_handle * rh
Definition: cel_radius.c:88

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 = "30ef0c93b36035ec78c9cfd712d36d9b", .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, .requires = "cel", }
static

Definition at line 263 of file cel_radius.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 263 of file cel_radius.c.

◆ cel_config

char* cel_config = "cel.conf"
static

Definition at line 78 of file cel_radius.c.

◆ global_flags

Definition at line 86 of file cel_radius.c.

◆ radiuscfg

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

Definition at line 83 of file cel_radius.c.

◆ rh

rc_handle* rh = NULL
static

Definition at line 88 of file cel_radius.c.