#include "asterisk.h"
#include <radiusclient-ng.h>
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Defines | |
#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) |
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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, } |
static struct ast_module_info * | ast_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 |
Definition in file cdr_radius.c.
#define DATE_FORMAT "%Y-%m-%d %T %z" |
ISO 8601 standard format
Definition at line 46 of file cdr_radius.c.
#define VENDOR_CODE 22736 |
anonymous enum |
Definition at line 50 of file cdr_radius.c.
00050 { 00051 PW_AST_ACCT_CODE = 101, 00052 PW_AST_SRC = 102, 00053 PW_AST_DST = 103, 00054 PW_AST_DST_CTX = 104, 00055 PW_AST_CLID = 105, 00056 PW_AST_CHAN = 106, 00057 PW_AST_DST_CHAN = 107, 00058 PW_AST_LAST_APP = 108, 00059 PW_AST_LAST_DATA = 109, 00060 PW_AST_START_TIME = 110, 00061 PW_AST_ANSWER_TIME = 111, 00062 PW_AST_END_TIME = 112, 00063 PW_AST_DURATION = 113, 00064 PW_AST_BILL_SEC = 114, 00065 PW_AST_DISPOSITION = 115, 00066 PW_AST_AMA_FLAGS = 116, 00067 PW_AST_UNIQUE_ID = 117, 00068 PW_AST_USER_FIELD = 118 00069 };
anonymous enum |
RADIUS_FLAG_USEGMTIME | Log dates and times in UTC |
RADIUS_FLAG_LOGUNIQUEID | Log Unique ID |
RADIUS_FLAG_LOGUSERFIELD | Log User Field |
Definition at line 71 of file cdr_radius.c.
00071 { 00072 /*! Log dates and times in UTC */ 00073 RADIUS_FLAG_USEGMTIME = (1 << 0), 00074 /*! Log Unique ID */ 00075 RADIUS_FLAG_LOGUNIQUEID = (1 << 1), 00076 /*! Log User Field */ 00077 RADIUS_FLAG_LOGUSERFIELD = (1 << 2) 00078 };
static void __reg_module | ( | void | ) | [static] |
Definition at line 270 of file cdr_radius.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 270 of file cdr_radius.c.
static int build_radius_record | ( | VALUE_PAIR ** | tosend, | |
struct ast_cdr * | cdr | |||
) | [static] |
Definition at line 90 of file cdr_radius.c.
References ast_cdr::accountcode, ast_cdr::amaflags, ast_cdr::answer, ast_cdr_disp2str(), ast_cdr_flags2str(), ast_localtime(), 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, 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, ast_cdr::src, ast_cdr::start, ast_cdr::uniqueid, ast_cdr::userfield, and VENDOR_CODE.
Referenced by radius_log().
00091 { 00092 int recordtype = PW_STATUS_STOP; 00093 struct ast_tm tm; 00094 char timestr[128]; 00095 char *tmp; 00096 00097 if (!rc_avpair_add(rh, tosend, PW_ACCT_STATUS_TYPE, &recordtype, 0, 0)) 00098 return -1; 00099 00100 /* Account code */ 00101 if (!rc_avpair_add(rh, tosend, PW_AST_ACCT_CODE, &cdr->accountcode, strlen(cdr->accountcode), VENDOR_CODE)) 00102 return -1; 00103 00104 /* Source */ 00105 if (!rc_avpair_add(rh, tosend, PW_AST_SRC, &cdr->src, strlen(cdr->src), VENDOR_CODE)) 00106 return -1; 00107 00108 /* Destination */ 00109 if (!rc_avpair_add(rh, tosend, PW_AST_DST, &cdr->dst, strlen(cdr->dst), VENDOR_CODE)) 00110 return -1; 00111 00112 /* Destination context */ 00113 if (!rc_avpair_add(rh, tosend, PW_AST_DST_CTX, &cdr->dcontext, strlen(cdr->dcontext), VENDOR_CODE)) 00114 return -1; 00115 00116 /* Caller ID */ 00117 if (!rc_avpair_add(rh, tosend, PW_AST_CLID, &cdr->clid, strlen(cdr->clid), VENDOR_CODE)) 00118 return -1; 00119 00120 /* Channel */ 00121 if (!rc_avpair_add(rh, tosend, PW_AST_CHAN, &cdr->channel, strlen(cdr->channel), VENDOR_CODE)) 00122 return -1; 00123 00124 /* Destination Channel */ 00125 if (!rc_avpair_add(rh, tosend, PW_AST_DST_CHAN, &cdr->dstchannel, strlen(cdr->dstchannel), VENDOR_CODE)) 00126 return -1; 00127 00128 /* Last Application */ 00129 if (!rc_avpair_add(rh, tosend, PW_AST_LAST_APP, &cdr->lastapp, strlen(cdr->lastapp), VENDOR_CODE)) 00130 return -1; 00131 00132 /* Last Data */ 00133 if (!rc_avpair_add(rh, tosend, PW_AST_LAST_DATA, &cdr->lastdata, strlen(cdr->lastdata), VENDOR_CODE)) 00134 return -1; 00135 00136 00137 /* Start Time */ 00138 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, 00139 ast_localtime(&cdr->start, &tm, 00140 ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL)); 00141 if (!rc_avpair_add(rh, tosend, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00142 return -1; 00143 00144 /* Answer Time */ 00145 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, 00146 ast_localtime(&cdr->answer, &tm, 00147 ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL)); 00148 if (!rc_avpair_add(rh, tosend, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00149 return -1; 00150 00151 /* End Time */ 00152 ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, 00153 ast_localtime(&cdr->end, &tm, 00154 ast_test_flag(&global_flags, RADIUS_FLAG_USEGMTIME) ? "GMT" : NULL)); 00155 if (!rc_avpair_add(rh, tosend, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE)) 00156 return -1; 00157 00158 /* Duration */ 00159 if (!rc_avpair_add(rh, tosend, PW_AST_DURATION, &cdr->duration, 0, VENDOR_CODE)) 00160 return -1; 00161 00162 /* Billable seconds */ 00163 if (!rc_avpair_add(rh, tosend, PW_AST_BILL_SEC, &cdr->billsec, 0, VENDOR_CODE)) 00164 return -1; 00165 00166 /* Disposition */ 00167 tmp = ast_cdr_disp2str(cdr->disposition); 00168 if (!rc_avpair_add(rh, tosend, PW_AST_DISPOSITION, tmp, strlen(tmp), VENDOR_CODE)) 00169 return -1; 00170 00171 /* AMA Flags */ 00172 tmp = ast_cdr_flags2str(cdr->amaflags); 00173 if (!rc_avpair_add(rh, tosend, PW_AST_AMA_FLAGS, tmp, strlen(tmp), VENDOR_CODE)) 00174 return -1; 00175 00176 if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUNIQUEID)) { 00177 /* Unique ID */ 00178 if (!rc_avpair_add(rh, tosend, PW_AST_UNIQUE_ID, &cdr->uniqueid, strlen(cdr->uniqueid), VENDOR_CODE)) 00179 return -1; 00180 } 00181 00182 if (ast_test_flag(&global_flags, RADIUS_FLAG_LOGUSERFIELD)) { 00183 /* append the user field */ 00184 if (!rc_avpair_add(rh, tosend, PW_AST_USER_FIELD, &cdr->userfield, strlen(cdr->userfield), VENDOR_CODE)) 00185 return -1; 00186 } 00187 00188 /* Setting Acct-Session-Id & User-Name attributes for proper generation 00189 of Acct-Unique-Session-Id on server side */ 00190 /* Channel */ 00191 if (!rc_avpair_add(rh, tosend, PW_USER_NAME, &cdr->channel, strlen(cdr->channel), 0)) 00192 return -1; 00193 00194 /* Unique ID */ 00195 if (!rc_avpair_add(rh, tosend, PW_ACCT_SESSION_ID, &cdr->uniqueid, strlen(cdr->uniqueid), 0)) 00196 return -1; 00197 00198 return 0; 00199 }
static int load_module | ( | void | ) | [static] |
Definition at line 230 of file cdr_radius.c.
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(), config_flags, CONFIG_STATUS_FILEINVALID, global_flags, LOG_NOTICE, RADIUS_FLAG_LOGUNIQUEID, RADIUS_FLAG_LOGUSERFIELD, RADIUS_FLAG_USEGMTIME, and radius_log().
00231 { 00232 struct ast_config *cfg; 00233 struct ast_flags config_flags = { 0 }; 00234 int res; 00235 const char *tmp; 00236 00237 if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { 00238 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); 00239 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); 00240 ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); 00241 if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) 00242 ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); 00243 ast_config_destroy(cfg); 00244 } else 00245 return AST_MODULE_LOAD_DECLINE; 00246 00247 /* start logging */ 00248 rc_openlog("asterisk"); 00249 00250 /* read radiusclient-ng config file */ 00251 if (!(rh = rc_read_config(radiuscfg))) { 00252 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); 00253 return AST_MODULE_LOAD_DECLINE; 00254 } 00255 00256 /* read radiusclient-ng dictionaries */ 00257 if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { 00258 ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); 00259 return AST_MODULE_LOAD_DECLINE; 00260 } 00261 00262 res = ast_cdr_register(name, desc, radius_log); 00263 return AST_MODULE_LOAD_SUCCESS; 00264 }
static int radius_log | ( | struct ast_cdr * | cdr | ) | [static] |
Definition at line 201 of file cdr_radius.c.
References ast_debug, ast_log(), build_radius_record(), and LOG_ERROR.
Referenced by load_module().
00202 { 00203 int result = ERROR_RC; 00204 VALUE_PAIR *tosend = NULL; 00205 00206 if (build_radius_record(&tosend, cdr)) { 00207 ast_debug(1, "Unable to create RADIUS record. CDR not recorded!\n"); 00208 goto return_cleanup; 00209 } 00210 00211 result = rc_acct(rh, 0, tosend); 00212 if (result != OK_RC) { 00213 ast_log(LOG_ERROR, "Failed to record Radius CDR record!\n"); 00214 } 00215 00216 return_cleanup: 00217 if (tosend) { 00218 rc_avpair_free(tosend); 00219 } 00220 00221 return result; 00222 }
static int unload_module | ( | void | ) | [static] |
Definition at line 224 of file cdr_radius.c.
References ast_cdr_unregister().
00225 { 00226 ast_cdr_unregister(name); 00227 return 0; 00228 }
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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CDR_DRIVER, } [static] |
Definition at line 270 of file cdr_radius.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 270 of file cdr_radius.c.
const char cdr_config[] = "cdr.conf" [static] |
Definition at line 82 of file cdr_radius.c.
const char desc[] = "RADIUS CDR Backend" [static] |
Definition at line 80 of file cdr_radius.c.
Referenced by acf_retrieve_docs(), ast_data_add_codecs(), ast_tcptls_client_create(), ast_tcptls_client_start(), ast_tcptls_server_root(), ast_tcptls_server_start(), ast_tcptls_server_stop(), dump_cause(), handle_cli_ulimit(), init_acf_query(), load_rpt_vars(), misdn_cfg_get_desc(), and show_config_description().
struct ast_flags global_flags = { RADIUS_FLAG_USEGMTIME | RADIUS_FLAG_LOGUNIQUEID | RADIUS_FLAG_LOGUSERFIELD } [static] |
Definition at line 86 of file cdr_radius.c.
Referenced by build_peer(), build_radius_record(), get_destination(), load_module(), load_moh_classes(), local_ast_moh_start(), reload_config(), set_peer_defaults(), sip_alloc(), sip_show_settings(), and transmit_response_using_temp().
const char name[] = "radius" [static] |
Definition at line 81 of file cdr_radius.c.
char radiuscfg[PATH_MAX] = "/etc/radiusclient-ng/radiusclient.conf" [static] |
Definition at line 84 of file cdr_radius.c.
rc_handle* rh = NULL [static] |