static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } event_sub = ast_event_subscribe(AST_EVENT_CEL, radius_log, "CEL Radius Logging", NULL, AST_EVENT_IE_END); if (!event_sub) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cdr_register(name, desc, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
void ovrc_client_delete(ovrc_cli_ctx*cli_ctx){ ovrc_client_finalize(cli_ctx); ovrc_task_delete(cli_ctx->task); rc_destroy(cli_ctx->rc_h); ovrc_free(cli_ctx); }
/** Initialise a configuration structure * * Initialize the configuration structure from an external program. For use when not * running a standalone client that reads from a config file. * * @param rh a handle to parsed configuration. * @return rc_handle on success, NULL on failure. */ rc_handle *rc_config_init(rc_handle *rh) { int i; SERVER *authservers; SERVER *acctservers; OPTION *acct; OPTION *auth; rh->config_options = malloc(sizeof(config_options_default)); if (rh->config_options == NULL) { rc_log(LOG_CRIT, "rc_config_init: out of memory"); rc_destroy(rh); return NULL; } memcpy(rh->config_options, &config_options_default, sizeof(config_options_default)); acct = find_option(rh, "acctserver", OT_ANY); auth = find_option(rh, "authserver", OT_ANY); authservers = malloc(sizeof(SERVER)); acctservers = malloc(sizeof(SERVER)); if(authservers == NULL || acctservers == NULL) { rc_log(LOG_CRIT, "rc_config_init: error initializing server structs"); rc_destroy(rh); if(authservers) free(authservers); if(acctservers) free(acctservers); return NULL; } authservers->max = 0; acctservers->max = 0; for(i=0; i < SERVER_MAX; i++) { authservers->name[i] = NULL; authservers->secret[i] = NULL; acctservers->name[i] = NULL; acctservers->secret[i] = NULL; } acct->val = acctservers; auth->val = authservers; return rh; }
static int unload_module(void) { ast_cdr_unregister(name); if (rh) { rc_destroy(rh); rh = NULL; } return 0; }
static int unload_module(void) { ast_cel_backend_unregister(RADIUS_BACKEND_NAME); if (rh) { rc_destroy(rh); rh = NULL; } return AST_MODULE_LOAD_SUCCESS; }
switch_status_t mod_xml_radius_accounting_end(switch_core_session_t *session){ VALUE_PAIR *send = NULL; uint32_t service = PW_STATUS_STOP; rc_handle *new_handle = NULL; switch_xml_t fields = NULL, conditions = NULL; switch_channel_t *channel = switch_core_session_get_channel(session); if (GLOBAL_DEBUG ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting accounting stop\n"); switch_core_session_execute_application(session, "info", NULL); } /* If there are conditions defined, and none of them pass, then skip this accounting */ if ((conditions = switch_xml_child(globals.acct_start_configs, "conditions")) != NULL && mod_xml_radius_check_conditions(channel, conditions) != SWITCH_STATUS_SUCCESS ) { goto end; } if ( mod_xml_radius_new_handle(&new_handle, globals.acct_end_configs) != SWITCH_STATUS_SUCCESS || new_handle == NULL ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create new accounting_end handle for call: %s\n", switch_channel_get_variable(channel, "uuid")); goto end; } if ((fields = switch_xml_child(globals.acct_end_configs, "fields")) == NULL ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'fields' section in config file.\n"); goto end; } if ( mod_xml_radius_add_params(session, NULL, new_handle, &send, fields) != SWITCH_STATUS_SUCCESS ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to add params to rc_handle\n"); goto end; } if (rc_avpair_add(new_handle, &send, PW_ACCT_STATUS_TYPE, &service, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: failed to add option to handle\n"); goto end; } if (rc_acct(new_handle, 0, send) == OK_RC) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "mod_xml_radius: Accounting Stop success\n"); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: Accounting Stop failed\n"); } end: if ( send ) { rc_avpair_free(send); send = NULL; } if ( new_handle) { rc_destroy(new_handle); new_handle = NULL; } return SWITCH_STATUS_SUCCESS; }
static int unload_module(void) { if (event_sub) { event_sub = ast_event_unsubscribe(event_sub); } if (rh) { rc_destroy(rh); rh = NULL; } return AST_MODULE_LOAD_SUCCESS; }
/** Initialise a configuration structure * * Initialize the configuration structure from an external program. For use when not * running a standalone client that reads from a config file. * * @param rh a handle to parsed configuration. * @return rc_handle on success, NULL on failure. */ rc_handle *rc_config_init(rc_handle *rh) { SERVER *authservers = NULL; SERVER *acctservers; OPTION *acct; OPTION *auth; rh->config_options = malloc(sizeof(config_options_default)); if (rh->config_options == NULL) { rc_log(LOG_CRIT, "rc_config_init: out of memory"); rc_destroy(rh); return NULL; } memcpy(rh->config_options, &config_options_default, sizeof(config_options_default)); auth = find_option(rh, "authserver", OT_ANY); if (auth) { authservers = calloc(1, sizeof(SERVER)); if(authservers == NULL) { rc_log(LOG_CRIT, "rc_config_init: error initializing server structs"); rc_destroy(rh); return NULL; } auth->val = authservers; } acct = find_option(rh, "acctserver", OT_ANY); if (acct) { acctservers = calloc(1, sizeof(SERVER)); if(acctservers == NULL) { rc_log(LOG_CRIT, "rc_config_init: error initializing server structs"); rc_destroy(rh); if(authservers) free(authservers); return NULL; } acct->val = acctservers; } return rh; }
void free_radius_auth_value_pair(VALUE_PAIR *send, VALUE_PAIR *received, rc_handle *rh) { if (send) rc_avpair_free(send); if (received) rc_avpair_free(received); if (rh) rc_destroy(rh); rh = NULL; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cdr_config, config_flags)) && cfg != CONFIG_STATUS_FILEINVALID) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid")), RADIUS_FLAG_LOGUNIQUEID); ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield")), RADIUS_FLAG_LOGUSERFIELD); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); ast_config_destroy(cfg); } else return AST_MODULE_LOAD_DECLINE; /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cdr_register(name, desc, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
switch_status_t mod_xml_radius_new_handle(rc_handle **new_handle, switch_xml_t xml) { switch_xml_t server, param; *new_handle = rc_new(); if ( *new_handle == NULL ) { goto err; } *new_handle = rc_config_init(*new_handle); if ( *new_handle == NULL ) { goto err; } if (rc_add_config(*new_handle, "auth_order", "radius", "mod_radius_cdr.c", 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error adding auth_order\n"); goto err; } if ((server = switch_xml_child(xml, "connection")) == NULL ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'connection' section in config file.\n"); goto err; } for (param = switch_xml_child(server, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); if ( GLOBAL_DEBUG ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Attempting to add param '%s' with value '%s' \n", var, val); } if (strncmp(var, "dictionary", 10) == 0) { rc_read_dictionary(*new_handle, val); } else if (rc_add_config(*new_handle, var, val, "mod_xml_radius", 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error adding param '%s' with value '%s' \n", var, val); goto err; } } return SWITCH_STATUS_SUCCESS; err: if ( *new_handle ) { rc_destroy( *new_handle ); *new_handle = NULL; } return SWITCH_STATUS_GENERR; }
void r300_translate_vertex_shader(struct r300_context* r300, struct r300_vertex_shader* vs) { struct r300_vertex_program_compiler compiler; struct tgsi_to_rc ttr; /* Initialize. */ r300_shader_read_vs_outputs(&vs->info, &vs->outputs); /* Setup the compiler */ rc_init(&compiler.Base); compiler.Base.Debug = DBG_ON(r300, DBG_VP); compiler.code = &vs->code; compiler.UserData = vs; if (compiler.Base.Debug) { debug_printf("r300: Initial vertex program\n"); tgsi_dump(vs->state.tokens, 0); } /* Translate TGSI to our internal representation */ ttr.compiler = &compiler.Base; ttr.info = &vs->info; ttr.use_half_swizzles = FALSE; r300_tgsi_to_rc(&ttr, vs->state.tokens); compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs+1)); compiler.SetHwInputOutput = &set_vertex_inputs_outputs; /* Insert the WPOS output. */ r300_insert_wpos(&compiler, &vs->outputs); r300_shader_vap_output_fmt(vs); r300_stream_locations_notcl(&vs->outputs, vs->stream_loc_notcl); /* Invoke the compiler */ r3xx_compile_vertex_program(&compiler); if (compiler.Base.Error) { /* XXX We should fallback using Draw. */ fprintf(stderr, "r300 VP: Compiler error\n"); abort(); } /* And, finally... */ rc_destroy(&compiler.Base); vs->translated = TRUE; }
struct rc_struct *cli_rc_create(void) { struct rc_struct *result; result = rc_create(); if (!result) return NULL; if (rc_register(result, opts)) { rc_destroy(result); return NULL; } return result; }
void r300_translate_fragment_shader(struct r300_context* r300, struct r300_fragment_shader* fs) { struct r300_fragment_program_compiler compiler; struct tgsi_to_rc ttr; memset(&compiler, 0, sizeof(compiler)); rc_init(&compiler.Base); compiler.Base.Debug = DBG_ON(r300, DBG_FP); compiler.code = &fs->code; compiler.is_r500 = r300_screen(r300->context.screen)->caps->is_r500; compiler.AllocateHwInputs = &allocate_hardware_inputs; compiler.UserData = fs; /* TODO: Program compilation depends on texture compare modes, * which are sampler state. Therefore, programs need to be recompiled * depending on this state as in the classic Mesa driver. * * This is not yet handled correctly. */ find_output_registers(&compiler, fs); if (compiler.Base.Debug) { debug_printf("r300: Initial fragment program\n"); tgsi_dump(fs->state.tokens, 0); } /* Translate TGSI to our internal representation */ ttr.compiler = &compiler.Base; ttr.info = &fs->info; r300_tgsi_to_rc(&ttr, fs->state.tokens); /* Invoke the compiler */ r3xx_compile_fragment_program(&compiler); if (compiler.Base.Error) { /* XXX failover maybe? */ DBG(r300, DBG_FP, "r300: Error compiling fragment program: %s\n", compiler.Base.ErrorMsg); } /* And, finally... */ rc_destroy(&compiler.Base); fs->translated = TRUE; }
void cli_frontend_exit(void) { #ifdef MESS if (win_write_config) write_config(NULL, Machine->gamedrv); #endif /* MESS */ free(gamename); gamename = NULL; rc_destroy(rc); rc = NULL; /* close open files */ if (logfile) { fclose(logfile); logfile = NULL; } if (options.playback) { mame_fclose(options.playback); options.playback = NULL; } if (options.record) { mame_fclose(options.record); options.record = NULL; } if (options.language_file) { mame_fclose(options.language_file); options.language_file = NULL; } }
switch_xml_t mod_xml_radius_auth_reg(switch_event_t *params) { int result = 0, param_idx = 0; VALUE_PAIR *send = NULL, *recv = NULL, *service_vp = NULL; char msg[512 * 10 + 1] = {0}; uint32_t service = PW_AUTHENTICATE_ONLY; rc_handle *new_handle = NULL; switch_xml_t fields, xml, dir, dom, usr, vars, var; char name[512], value[512], *strtmp; if (GLOBAL_DEBUG ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: starting registration authentication\n"); } if ( mod_xml_radius_new_handle(&new_handle, globals.auth_invite_configs) != SWITCH_STATUS_SUCCESS ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to load radius handle for registration authentication\n"); goto err; } if ( new_handle == NULL ) { goto err; } if ((fields = switch_xml_child(globals.auth_reg_configs, "fields")) == NULL ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find 'fields' section in config file.\n"); goto err; } if ( mod_xml_radius_add_params(NULL, params, new_handle, &send, fields) != SWITCH_STATUS_SUCCESS ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to add params to rc_handle\n"); goto err; } if (rc_avpair_add(new_handle, &send, PW_SERVICE_TYPE, &service, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: failed to add option to handle\n"); goto err; } result = rc_auth(new_handle, 0, send, &recv, msg); if ( GLOBAL_DEBUG ){ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: result(RC=%d) %s \n", result, msg); } if ( result != 0 ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mod_xml_radius: Failed to authenticate\n"); goto err; } xml = switch_xml_new("document"); switch_xml_set_attr_d(xml, "type", "freeswitch/xml"); dir = switch_xml_add_child_d(xml, "section", 0); switch_xml_set_attr_d(dir, "name", "directory"); dom = switch_xml_add_child_d(dir, "domain", 0); switch_xml_set_attr_d(dom, "name", switch_event_get_header(params, "domain")); usr = switch_xml_add_child_d(dom, "user", 0); vars = switch_xml_add_child_d(usr, "variables", 0); switch_xml_set_attr_d(usr, "id", switch_event_get_header(params, "user")); service_vp = recv; while (service_vp != NULL) { rc_avpair_tostr(new_handle, service_vp, name, 512, value, 512); if ( GLOBAL_DEBUG ) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "\tattribute (%s)[%s] found in radius packet\n", name, value); var = switch_xml_add_child_d(vars, "variable", param_idx++); strtmp = strdup(name); switch_xml_set_attr_d(var, "name", strtmp); free(strtmp); strtmp = strdup(value); switch_xml_set_attr_d(var, "value", strtmp); free(strtmp); service_vp = service_vp->next; } if ( GLOBAL_DEBUG ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XML: %s \n", switch_xml_toxml(xml, 1)); } if ( recv ) { rc_avpair_free(recv); recv = NULL; } if ( send ) { rc_avpair_free(send); send = NULL; } if ( new_handle ) { rc_destroy(new_handle); new_handle = NULL; } return xml; err: if ( recv ) { rc_avpair_free(recv); recv = NULL; } if ( send ) { rc_avpair_free(send); send = NULL; } if ( new_handle ) { rc_destroy(new_handle); new_handle = NULL; } return NULL; }
void r300_translate_vertex_shader(struct r300_context *r300, struct r300_vertex_shader *vs) { struct r300_vertex_program_compiler compiler; struct tgsi_to_rc ttr; unsigned i; /* Setup the compiler */ memset(&compiler, 0, sizeof(compiler)); rc_init(&compiler.Base, NULL); DBG_ON(r300, DBG_VP) ? compiler.Base.Debug |= RC_DBG_LOG : 0; DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0; compiler.code = &vs->code; compiler.UserData = vs; compiler.Base.is_r500 = r300->screen->caps.is_r500; compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT); compiler.Base.has_half_swizzles = FALSE; compiler.Base.has_presub = FALSE; compiler.Base.has_omod = FALSE; compiler.Base.max_temp_regs = 32; compiler.Base.max_constants = 256; compiler.Base.max_alu_insts = r300->screen->caps.is_r500 ? 1024 : 256; if (compiler.Base.Debug & RC_DBG_LOG) { DBG(r300, DBG_VP, "r300: Initial vertex program\n"); tgsi_dump(vs->state.tokens, 0); } /* Translate TGSI to our internal representation */ ttr.compiler = &compiler.Base; ttr.info = &vs->info; ttr.use_half_swizzles = FALSE; r300_tgsi_to_rc(&ttr, vs->state.tokens); if (ttr.error) { fprintf(stderr, "r300 VP: Cannot translate a shader. " "Using a dummy shader instead.\n"); r300_dummy_vertex_shader(r300, vs); return; } if (compiler.Base.Program.Constants.Count > 200) { compiler.Base.remove_unused_constants = TRUE; } compiler.RequiredOutputs = ~(~0 << (vs->info.num_outputs + 1)); compiler.SetHwInputOutput = &set_vertex_inputs_outputs; /* Insert the WPOS output. */ rc_copy_output(&compiler.Base, 0, vs->outputs.wpos); /* Invoke the compiler */ r3xx_compile_vertex_program(&compiler); if (compiler.Base.Error) { fprintf(stderr, "r300 VP: Compiler error:\n%sUsing a dummy shader" " instead.\n", compiler.Base.ErrorMsg); if (vs->dummy) { fprintf(stderr, "r300 VP: Cannot compile the dummy shader! " "Giving up...\n"); abort(); } rc_destroy(&compiler.Base); r300_dummy_vertex_shader(r300, vs); return; } /* Initialize numbers of constants for each type. */ vs->externals_count = 0; for (i = 0; i < vs->code.constants.Count && vs->code.constants.Constants[i].Type == RC_CONSTANT_EXTERNAL; i++) { vs->externals_count = i+1; } for (; i < vs->code.constants.Count; i++) { assert(vs->code.constants.Constants[i].Type == RC_CONSTANT_IMMEDIATE); } vs->immediates_count = vs->code.constants.Count - vs->externals_count; /* And, finally... */ rc_destroy(&compiler.Base); }
static struct r300_vertex_program *build_program(GLcontext *ctx, struct r300_vertex_program_key *wanted_key, const struct gl_vertex_program *mesa_vp) { struct r300_vertex_program *vp; struct r300_vertex_program_compiler compiler; vp = _mesa_calloc(sizeof(*vp)); vp->Base = (struct gl_vertex_program *) _mesa_clone_program(ctx, &mesa_vp->Base); _mesa_memcpy(&vp->key, wanted_key, sizeof(vp->key)); rc_init(&compiler.Base); compiler.Base.Debug = (RADEON_DEBUG & RADEON_VERTS) ? GL_TRUE : GL_FALSE; compiler.code = &vp->code; compiler.RequiredOutputs = compute_required_outputs(vp->Base, vp->key.FpReads); compiler.SetHwInputOutput = &t_inputs_outputs; if (compiler.Base.Debug) { fprintf(stderr, "Initial vertex program:\n"); _mesa_print_program(&vp->Base->Base); fflush(stderr); } if (mesa_vp->IsPositionInvariant) { _mesa_insert_mvp_code(ctx, vp->Base); } radeon_mesa_to_rc_program(&compiler.Base, &vp->Base->Base); if (mesa_vp->IsNVProgram) initialize_NV_registers(&compiler.Base); rc_move_output(&compiler.Base, VERT_RESULT_PSIZ, VERT_RESULT_PSIZ, WRITEMASK_X); if (vp->key.WPosAttr != FRAG_ATTRIB_MAX) { rc_copy_output(&compiler.Base, VERT_RESULT_HPOS, vp->key.WPosAttr - FRAG_ATTRIB_TEX0 + VERT_RESULT_TEX0); } if (vp->key.FogAttr != FRAG_ATTRIB_MAX) { rc_move_output(&compiler.Base, VERT_RESULT_FOGC, vp->key.FogAttr - FRAG_ATTRIB_TEX0 + VERT_RESULT_TEX0, WRITEMASK_X); } r3xx_compile_vertex_program(&compiler); if (vp->code.constants.Count > ctx->Const.VertexProgram.MaxParameters) { rc_error(&compiler.Base, "Program exceeds constant buffer size limit\n"); } vp->error = compiler.Base.Error; vp->Base->Base.InputsRead = vp->code.InputsRead; vp->Base->Base.OutputsWritten = vp->code.OutputsWritten; rc_destroy(&compiler.Base); return vp; }
static void r300_translate_fragment_shader( struct r300_context* r300, struct r300_fragment_shader_code* shader, const struct tgsi_token *tokens) { struct r300_fragment_program_compiler compiler; struct tgsi_to_rc ttr; int wpos, face; unsigned i; tgsi_scan_shader(tokens, &shader->info); r300_shader_read_fs_inputs(&shader->info, &shader->inputs); wpos = shader->inputs.wpos; face = shader->inputs.face; /* Setup the compiler. */ memset(&compiler, 0, sizeof(compiler)); rc_init(&compiler.Base); DBG_ON(r300, DBG_FP) ? compiler.Base.Debug |= RC_DBG_LOG : 0; DBG_ON(r300, DBG_P_STAT) ? compiler.Base.Debug |= RC_DBG_STATS : 0; compiler.code = &shader->code; compiler.state = shader->compare_state; compiler.Base.is_r500 = r300->screen->caps.is_r500; compiler.Base.is_r400 = r300->screen->caps.is_r400; compiler.Base.disable_optimizations = DBG_ON(r300, DBG_NO_OPT); compiler.Base.has_half_swizzles = TRUE; compiler.Base.has_presub = TRUE; compiler.Base.max_temp_regs = compiler.Base.is_r500 ? 128 : (compiler.Base.is_r400 ? 64 : 32); compiler.Base.max_constants = compiler.Base.is_r500 ? 256 : 32; compiler.Base.max_alu_insts = (compiler.Base.is_r500 || compiler.Base.is_r400) ? 512 : 64; compiler.Base.max_tex_insts = (compiler.Base.is_r500 || compiler.Base.is_r400) ? 512 : 32; compiler.AllocateHwInputs = &allocate_hardware_inputs; compiler.UserData = &shader->inputs; find_output_registers(&compiler, shader); shader->write_all = FALSE; for (i = 0; i < shader->info.num_properties; i++) { if (shader->info.properties[i].name == TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS) { shader->write_all = TRUE; } } if (compiler.Base.Debug & RC_DBG_LOG) { DBG(r300, DBG_FP, "r300: Initial fragment program\n"); tgsi_dump(tokens, 0); } /* Translate TGSI to our internal representation */ ttr.compiler = &compiler.Base; ttr.info = &shader->info; ttr.use_half_swizzles = TRUE; r300_tgsi_to_rc(&ttr, tokens); if (ttr.error) { fprintf(stderr, "r300 FP: Cannot translate a shader. " "Using a dummy shader instead.\n"); r300_dummy_fragment_shader(r300, shader); return; } if (!r300->screen->caps.is_r500 || compiler.Base.Program.Constants.Count > 200) { compiler.Base.remove_unused_constants = TRUE; } /** * Transform the program to support WPOS. * * Introduce a small fragment at the start of the program that will be * the only code that directly reads the WPOS input. * All other code pieces that reference that input will be rewritten * to read from a newly allocated temporary. */ if (wpos != ATTR_UNUSED) { /* Moving the input to some other reg is not really necessary. */ rc_transform_fragment_wpos(&compiler.Base, wpos, wpos, TRUE); } if (face != ATTR_UNUSED) { rc_transform_fragment_face(&compiler.Base, face); } /* Invoke the compiler */ r3xx_compile_fragment_program(&compiler); if (compiler.Base.Error) { fprintf(stderr, "r300 FP: Compiler Error:\n%sUsing a dummy shader" " instead.\n", compiler.Base.ErrorMsg); if (shader->dummy) { fprintf(stderr, "r300 FP: Cannot compile the dummy shader! " "Giving up...\n"); abort(); } rc_destroy(&compiler.Base); r300_dummy_fragment_shader(r300, shader); return; } /* Shaders with zero instructions are invalid, * use the dummy shader instead. */ if (shader->code.code.r500.inst_end == -1) { rc_destroy(&compiler.Base); r300_dummy_fragment_shader(r300, shader); return; } /* Initialize numbers of constants for each type. */ shader->externals_count = 0; for (i = 0; i < shader->code.constants.Count && shader->code.constants.Constants[i].Type == RC_CONSTANT_EXTERNAL; i++) { shader->externals_count = i+1; } shader->immediates_count = 0; shader->rc_state_count = 0; for (i = shader->externals_count; i < shader->code.constants.Count; i++) { switch (shader->code.constants.Constants[i].Type) { case RC_CONSTANT_IMMEDIATE: ++shader->immediates_count; break; case RC_CONSTANT_STATE: ++shader->rc_state_count; break; default: assert(0); } } /* Setup shader depth output. */ if (shader->code.writes_depth) { shader->fg_depth_src = R300_FG_DEPTH_SRC_SHADER; shader->us_out_w = R300_W_FMT_W24 | R300_W_SRC_US; } else { shader->fg_depth_src = R300_FG_DEPTH_SRC_SCAN; shader->us_out_w = R300_W_FMT_W0 | R300_W_SRC_US; } /* And, finally... */ rc_destroy(&compiler.Base); /* Build the command buffer. */ r300_emit_fs_code_to_buffer(r300, shader); }
static void radius_global_deinit() { if (rh != NULL) rc_destroy(rh); }
rc_handle * rc_read_config(const char *filename) { FILE *configfd; char buffer[512], *p; OPTION *option; int line; size_t pos; rc_handle *rh; rh = rc_new(); if (rh == NULL) return NULL; rh->config_options = malloc(sizeof(config_options_default)); if (rh->config_options == NULL) { rc_log(LOG_CRIT, "rc_read_config: out of memory"); rc_destroy(rh); return NULL; } memcpy(rh->config_options, &config_options_default, sizeof(config_options_default)); if ((configfd = fopen(filename,"r")) == NULL) { rc_log(LOG_ERR,"rc_read_config: can't open %s: %s", filename, strerror(errno)); rc_destroy(rh); return NULL; } line = 0; while ((fgets(buffer, sizeof(buffer), configfd) != NULL)) { line++; p = buffer; if ((*p == '\n') || (*p == '#') || (*p == '\0')) continue; p[strlen(p)-1] = '\0'; if ((pos = strcspn(p, "\t ")) == 0) { rc_log(LOG_ERR, "%s: line %d: bogus format: %s", filename, line, p); fclose(configfd); rc_destroy(rh); return NULL; } p[pos] = '\0'; if ((option = find_option(rh, p, OT_ANY)) == NULL) { rc_log(LOG_ERR, "%s: line %d: unrecognized keyword: %s", filename, line, p); fclose(configfd); rc_destroy(rh); return NULL; } if (option->status != ST_UNDEF) { rc_log(LOG_ERR, "%s: line %d: duplicate option line: %s", filename, line, p); fclose(configfd); rc_destroy(rh); return NULL; } p += pos+1; while (isspace(*p)) p++; pos = strlen(p) - 1; while(pos >= 0 && isspace(p[pos])) pos--; p[pos + 1] = '\0'; switch (option->type) { case OT_STR: if (set_option_str(filename, line, option, p) < 0) { fclose(configfd); rc_destroy(rh); return NULL; } break; case OT_INT: if (set_option_int(filename, line, option, p) < 0) { fclose(configfd); rc_destroy(rh); return NULL; } break; case OT_SRV: if (set_option_srv(filename, line, option, p) < 0) { fclose(configfd); rc_destroy(rh); return NULL; } break; case OT_AUO: if (set_option_auo(filename, line, option, p) < 0) { fclose(configfd); rc_destroy(rh); return NULL; } break; default: rc_log(LOG_CRIT, "rc_read_config: impossible case branch!"); abort(); } } fclose(configfd); if (test_config(rh, filename) == -1) { rc_destroy(rh); return NULL; } return rh; }
static switch_status_t my_on_reporting(switch_core_session_t *session) { switch_xml_t cdr = NULL; switch_channel_t *channel = switch_core_session_get_channel(session); rc_handle *rad_config; switch_status_t retval = SWITCH_STATUS_TERM; VALUE_PAIR *send = NULL; uint32_t client_port = 0; uint32_t framed_addr = 0; uint32_t status_type = PW_STATUS_STOP; switch_time_t callstartdate = 0; switch_time_t callanswerdate = 0; switch_time_t callenddate = 0; switch_time_t calltransferdate = 0; switch_time_t billusec = 0; uint32_t billsec = 0; char *uuid_str; switch_time_exp_t tm; char buffer[32] = ""; if (globals.shutdown) { return SWITCH_STATUS_FALSE; } if (channel) { const char *disable_flag = switch_channel_get_variable(channel, "disable_radius_stop"); if (switch_true(disable_flag)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Not Sending RADIUS Stop\n"); return SWITCH_STATUS_SUCCESS; } } switch_thread_rwlock_rdlock(globals.rwlock); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Entering my_on_reporting\n"); rad_config = my_radius_init(); if (rad_config == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing radius, session not logged.\n"); goto end; } if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) { uuid_str = switch_core_session_get_uuid(session); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[mod_radius_cdr] Error Generating Data!\n"); goto end; } /* Create the radius packet */ /* Set Status Type */ if (rc_avpair_add(rad_config, &send, PW_ACCT_STATUS_TYPE, &status_type, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str); rc_destroy(rad_config); goto end; } if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_ID, uuid_str, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Acct-Session-ID: %s\n", uuid_str); rc_destroy(rad_config); goto end; } /* Add VSAs */ if (channel) { switch_call_cause_t cause; switch_caller_profile_t *profile; cause = switch_channel_get_cause(channel); if (rc_avpair_add(rad_config, &send, PW_FS_HANGUPCAUSE, &cause, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Hangupcause: %d\n", cause); rc_destroy(rad_config); goto end; } profile = switch_channel_get_caller_profile(channel); if (profile) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Calculating billable time\n"); /* calculate billable time */ callstartdate = profile->times->created; callanswerdate = profile->times->answered; calltransferdate = profile->times->transferred; callenddate = profile->times->hungup; if (switch_channel_test_flag(channel, CF_ANSWERED)) { if (callstartdate && callanswerdate) { if (callenddate) billusec = callenddate - callanswerdate; else if (calltransferdate) billusec = calltransferdate - callanswerdate; } } else if (switch_channel_test_flag(channel, CF_TRANSFER)) { if (callanswerdate && calltransferdate) billusec = calltransferdate - callanswerdate; } billsec = (billusec / 1000000); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Finished calculating billable time\n"); if (profile->username) { if (rc_avpair_add(rad_config, &send, PW_USER_NAME, (void *) profile->username, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding User-Name: %s\n", profile->username); rc_destroy(rad_config); goto end; } } if (profile->caller_id_number) { if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number); rc_destroy(rad_config); goto end; } } if (profile->caller_id_name) { if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name); rc_destroy(rad_config); goto end; } } if (profile->destination_number) { if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number); rc_destroy(rad_config); goto end; } } if (profile->dialplan) { if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan); rc_destroy(rad_config); goto end; } } if (profile->network_addr) { inet_pton(AF_INET, (void *) profile->network_addr, &framed_addr); framed_addr = htonl(framed_addr); if (rc_avpair_add(rad_config, &send, PW_FRAMED_IP_ADDRESS, &framed_addr, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Framed-IP-Address: %s\n", profile->network_addr); rc_destroy(rad_config); goto end; } } if (profile->rdnis) { if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis); rc_destroy(rad_config); goto end; } } if (profile->context) { if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context); rc_destroy(rad_config); goto end; } } if (profile->ani) { if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani); rc_destroy(rad_config); goto end; } } if (profile->aniii) { if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii); rc_destroy(rad_config); goto end; } } if (profile->source) { if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source); rc_destroy(rad_config); goto end; } } if (profile->caller_extension && profile->caller_extension->last_application && profile->caller_extension->last_application->application_name) { if (rc_avpair_add(rad_config, &send, PW_FS_LASTAPP, (void *) profile->caller_extension->last_application->application_name, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Lastapp: %s\n", profile->source); rc_destroy(rad_config); goto end; } } if (rc_avpair_add(rad_config, &send, PW_FS_BILLUSEC, &billusec, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Billusec: %u\n", (uint32_t) billusec); rc_destroy(rad_config); goto end; } if (callstartdate > 0) { switch_time_exp_lt(&tm, callstartdate); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600); if (rc_avpair_add(rad_config, &send, PW_FS_CALLSTARTDATE, &buffer, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Callstartdate: %s\n", buffer); rc_destroy(rad_config); goto end; } } if (callanswerdate > 0) { switch_time_exp_lt(&tm, callanswerdate); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600); if (rc_avpair_add(rad_config, &send, PW_FS_CALLANSWERDATE, &buffer, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Callanswerdate: %s\n", buffer); rc_destroy(rad_config); goto end; } } if (calltransferdate > 0) { switch_time_exp_lt(&tm, calltransferdate); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600); if (rc_avpair_add(rad_config, &send, PW_FS_CALLTRANSFERDATE, &buffer, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Calltransferdate: %s\n", buffer); rc_destroy(rad_config); goto end; } } if (callenddate > 0) { switch_time_exp_lt(&tm, callenddate); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600); if (rc_avpair_add(rad_config, &send, PW_FS_CALLENDDATE, &buffer, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Callenddate: %s\n", buffer); rc_destroy(rad_config); goto end; } } if (rc_avpair_add(rad_config, &send, PW_ACCT_SESSION_TIME, &billsec, -1, 0) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Acct-Session-Time: %u\n", billsec); rc_destroy(rad_config); goto end; } { const char *direction_str = profile->direction == SWITCH_CALL_DIRECTION_INBOUND ? "inbound" : "outbound"; if (rc_avpair_add(rad_config, &send, PW_FS_DIRECTION, (void *) direction_str, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Direction: %s\n", direction_str); rc_destroy(rad_config); goto end; } } } else { /* no profile, can't create data to send */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "profile == NULL\n"); } } if (rc_acct(rad_config, client_port, send) == OK_RC) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "RADIUS Accounting OK\n"); retval = SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "RADIUS Accounting Failed\n"); retval = SWITCH_STATUS_TERM; } rc_avpair_free(send); rc_destroy(rad_config); end: switch_xml_free(cdr); switch_thread_rwlock_unlock(globals.rwlock); return (retval); }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* create dir /var/lib/cdr if it does not exist. add by liucl */ if (access(cdr_directory,F_OK) == -1){ ast_log(LOG_DEBUG,"cdr_directory %s is not exist, I will create it.\n",cdr_directory); if(ast_mkdir(cdr_directory, 0755) == -1) { ast_log(LOG_ERROR,"Failed to create %s\n", cdr_directory); }else{ ast_log(LOG_DEBUG,"Create directory %s is OK\n",cdr_directory); } } /* liucl add end*/ /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { /* * * Create a independent thread to monitoring /var/lib/cdr. * * If there is file in the directory, then send it to radius. * * add by liucl * */ start_monitor(); return AST_MODULE_LOAD_SUCCESS; } }
static rc_handle *my_radius_init(void) { int i = 0; rc_handle *rad_config; rad_config = rc_new(); if (rad_config == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[mod_radius_cdr] Error initializing rc_handle!\n"); return NULL; } rad_config = rc_config_init(rad_config); if (rad_config == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error initializing radius config!\n"); rc_destroy(rad_config); return NULL; } /* Some hardcoded ( for now ) defaults needed to initialize radius */ if (rc_add_config(rad_config, "auth_order", "radius", "mod_radius_cdr.c", 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting auth_order = radius failed\n"); rc_destroy(rad_config); return NULL; } if (rc_add_config(rad_config, "seqfile", my_seqfile, "mod_radius_cdr.c", 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting seqfile = %s failed\n", my_seqfile); rc_destroy(rad_config); return NULL; } /* Add the module configs to initialize rad_config */ for (i = 0; i < SERVER_MAX && my_servers[i][0] != '\0'; i++) { if (rc_add_config(rad_config, "acctserver", my_servers[i], cf, 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting acctserver = %s failed\n", my_servers[i]); rc_destroy(rad_config); return NULL; } } if (rc_add_config(rad_config, "dictionary", my_dictionary, cf, 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed setting dictionary = %s failed\n", my_dictionary); rc_destroy(rad_config); return NULL; } if (rc_add_config(rad_config, "radius_deadtime", my_deadtime, cf, 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_deadtime = %s failed\n", my_deadtime); rc_destroy(rad_config); return NULL; } if (rc_add_config(rad_config, "radius_timeout", my_timeout, cf, 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_timeout = %s failed\n", my_timeout); rc_destroy(rad_config); return NULL; } if (rc_add_config(rad_config, "radius_retries", my_retries, cf, 0) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setting radius_retries = %s failed\n", my_retries); rc_destroy(rad_config); return NULL; } /* Read the dictionary file(s) */ if (rc_read_dictionary(rad_config, rc_conf_str(rad_config, "dictionary")) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "reading dictionary file(s): %s\n", my_dictionary); rc_destroy(rad_config); return NULL; } return rad_config; }