cel_radius.c File Reference

RADIUS CEL Support. More...

#include "asterisk.h"
#include <radiusclient-ng.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.

Defines

#define ADD_VENDOR_CODE(x, y)   (rc_avpair_add(rh, send, x, &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)
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, }
static 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.


Define Documentation

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

Definition at line 98 of file cel_radius.c.

Referenced by build_radius_record().

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

ISO 8601 standard format

Definition at line 52 of file cel_radius.c.

#define RADIUS_BACKEND_NAME   "CEL Radius Logging"

Definition at line 96 of file cel_radius.c.

Referenced by load_module(), and unload_module().

#define VENDOR_CODE   22736

Definition at line 54 of file cel_radius.c.


Enumeration Type Documentation

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

00056      {
00057    PW_AST_ACCT_CODE =    101,
00058    PW_AST_CIDNUM =       102,
00059    PW_AST_CIDNAME =      103,
00060    PW_AST_CIDANI =       104,
00061    PW_AST_CIDRDNIS =     105,
00062    PW_AST_CIDDNID =      106,
00063    PW_AST_EXTEN =        107,
00064    PW_AST_CONTEXT =      108,
00065    PW_AST_CHANNAME =     109,
00066    PW_AST_APPNAME =      110,
00067    PW_AST_APPDATA =      111,
00068    PW_AST_EVENT_TIME =   112,
00069    PW_AST_AMA_FLAGS =    113,
00070    PW_AST_UNIQUE_ID =    114,
00071    PW_AST_USER_NAME =    115,
00072    PW_AST_LINKED_ID =    116,
00073 };

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 cel_radius.c.

00075      {
00076    /*! Log dates and times in UTC */
00077    RADIUS_FLAG_USEGMTIME = (1 << 0),
00078    /*! Log Unique ID */
00079    RADIUS_FLAG_LOGUNIQUEID = (1 << 1),
00080    /*! Log User Field */
00081    RADIUS_FLAG_LOGUSERFIELD = (1 << 2)
00082 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 280 of file cel_radius.c.

static void __unreg_module ( void   )  [static]

Definition at line 280 of file cel_radius.c.

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

Definition at line 100 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.

00101 {
00102    int recordtype = PW_STATUS_STOP;
00103    struct ast_tm tm;
00104    char timestr[128];
00105    char *amaflags;
00106 
00107    if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) {
00108       return -1;
00109    }
00110    /* Account code */
00111    if (!ADD_VENDOR_CODE(PW_AST_ACCT_CODE, record->account_code)) {
00112       return -1;
00113    }
00114    /* Source */
00115    if (!ADD_VENDOR_CODE(PW_AST_CIDNUM, record->caller_id_num)) {
00116       return -1;
00117    }
00118    /* Destination */
00119    if (!ADD_VENDOR_CODE(PW_AST_EXTEN, record->extension)) {
00120       return -1;
00121    }
00122    /* Destination context */
00123    if (!ADD_VENDOR_CODE(PW_AST_CONTEXT, record->context)) {
00124       return -1;
00125    }
00126    /* Caller ID */
00127    if (!ADD_VENDOR_CODE(PW_AST_CIDNAME, record->caller_id_name)) {
00128       return -1;
00129    }
00130    /* Caller ID ani */
00131    if (!ADD_VENDOR_CODE(PW_AST_CIDANI, record->caller_id_ani)) {
00132       return -1;
00133    }
00134    /* Caller ID rdnis */
00135    if (!ADD_VENDOR_CODE(PW_AST_CIDRDNIS, record->caller_id_rdnis)) {
00136       return -1;
00137    }
00138    /* Caller ID dnid */
00139    if (!ADD_VENDOR_CODE(PW_AST_CIDDNID, record->caller_id_dnid)) {
00140       return -1;
00141    }
00142    /* Channel */
00143    if (!ADD_VENDOR_CODE(PW_AST_CHANNAME, record->channel_name)) {
00144       return -1;
00145    }
00146    /* Last Application */
00147    if (!ADD_VENDOR_CODE(PW_AST_APPNAME, record->application_name)) {
00148       return -1;
00149    }
00150    /* Last Data */
00151    if (!ADD_VENDOR_CODE(PW_AST_APPDATA, record->application_data)) {
00152       return -1;
00153    }
00154    /* Event Time */
00155    ast_localtime(&record->event_time, &tm,
00156       ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL);
00157    ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
00158    if (!rc_avpair_add(rh, send, PW_AST_EVENT_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
00159       return -1;
00160    }
00161    /* AMA Flags */
00162    amaflags = ast_strdupa(ast_channel_amaflags2string(record->amaflag));
00163    if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, amaflags, strlen(amaflags), VENDOR_CODE)) {
00164       return -1;
00165    }
00166    if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUNIQUEID)) {
00167       /* Unique ID */
00168       if (!ADD_VENDOR_CODE(PW_AST_UNIQUE_ID, record->unique_id)) {
00169          return -1;
00170       }
00171    }
00172    /* LinkedID */
00173    if (!ADD_VENDOR_CODE(PW_AST_LINKED_ID, record->linked_id)) {
00174       return -1;
00175    }
00176    /* Setting Acct-Session-Id & User-Name attributes for proper generation
00177       of Acct-Unique-Session-Id on server side */
00178    /* Channel */
00179    if (!rc_avpair_add(rh, send, PW_USER_NAME, &record->channel_name,
00180          strlen(record->channel_name), 0)) {
00181       return -1;
00182    }
00183    return 0;
00184 }

static int load_module ( void   )  [static]

Definition at line 224 of file cel_radius.c.

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_strdup, ast_true(), ast_variable_retrieve(), LOG_NOTICE, NULL, RADIUS_BACKEND_NAME, RADIUS_FLAG_USEGMTIME, radius_log(), and tmp().

00225 {
00226    struct ast_config *cfg;
00227    struct ast_flags config_flags = { 0 };
00228    const char *tmp;
00229 
00230    if ((cfg = ast_config_load(cel_config, config_flags))) {
00231       ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME);
00232       if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) {
00233          ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg));
00234       }
00235       ast_config_destroy(cfg);
00236    } else {
00237       return AST_MODULE_LOAD_DECLINE;
00238    }
00239 
00240    /*
00241     * start logging
00242     *
00243     * NOTE: Yes this causes a slight memory leak if the module is
00244     * unloaded.  However, it is better than a crash if cdr_radius
00245     * and cel_radius are both loaded.
00246     */
00247    tmp = ast_strdup("asterisk");
00248    if (tmp) {
00249       rc_openlog((char *) tmp);
00250    }
00251 
00252    /* read radiusclient-ng config file */
00253    if (!(rh = rc_read_config(radiuscfg))) {
00254       ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg);
00255       return AST_MODULE_LOAD_DECLINE;
00256    }
00257 
00258    /* read radiusclient-ng dictionaries */
00259    if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) {
00260       ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n");
00261       rc_destroy(rh);
00262       rh = NULL;
00263       return AST_MODULE_LOAD_DECLINE;
00264    }
00265 
00266    if (ast_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) {
00267       rc_destroy(rh);
00268       rh = NULL;
00269       return AST_MODULE_LOAD_DECLINE;
00270    } else {
00271       return AST_MODULE_LOAD_SUCCESS;
00272    }
00273 }

static void radius_log ( struct ast_event event  )  [static]

Definition at line 186 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.

00187 {
00188    int result = ERROR_RC;
00189    VALUE_PAIR *send = NULL;
00190    struct ast_cel_event_record record = {
00191       .version = AST_CEL_EVENT_RECORD_VERSION,
00192    };
00193 
00194    if (ast_cel_fill_record(event, &record)) {
00195       return;
00196    }
00197 
00198    if (build_radius_record(&send, &record)) {
00199       ast_debug(1, "Unable to create RADIUS record. CEL not recorded!\n");
00200       goto return_cleanup;
00201    }
00202 
00203    result = rc_acct(rh, 0, send);
00204    if (result != OK_RC) {
00205       ast_log(LOG_ERROR, "Failed to record Radius CEL record!\n");
00206    }
00207 
00208 return_cleanup:
00209    if (send) {
00210       rc_avpair_free(send);
00211    }
00212 }

static int unload_module ( void   )  [static]

Definition at line 214 of file cel_radius.c.

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

00215 {
00216    ast_cel_backend_unregister(RADIUS_BACKEND_NAME);
00217    if (rh) {
00218       rc_destroy(rh);
00219       rh = NULL;
00220    }
00221    return AST_MODULE_LOAD_SUCCESS;
00222 }


Variable Documentation

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, } [static]

Definition at line 280 of file cel_radius.c.

Definition at line 280 of file cel_radius.c.

char* cel_config = "cel.conf" [static]

Definition at line 84 of file cel_radius.c.

struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD } [static]

Definition at line 92 of file cel_radius.c.

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

Definition at line 89 of file cel_radius.c.

rc_handle* rh = NULL [static]

Definition at line 94 of file cel_radius.c.


Generated on Thu Apr 16 06:29:29 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6