/** * @brief fixup for SL reply config file functions */ static int fixup_sl_reply(void** param, int param_no) { if (param_no == 1) { return fixup_var_int_12(param, 1); } else if (param_no == 2) { return fixup_var_pve_str_12(param, 2); } return 0; }
static int change_reply_status_fixup(void** param, int param_no) { if (param_no == 1) { return fixup_var_int_12(param, param_no); } else if (param_no == 2) return fixup_var_pve_str_12(param, param_no); else return 0; }
static int acc_fixup(void** param, int param_no) { struct acc_param *accp; char *p; p = (char*)*param; if (p==0 || p[0]==0) { LM_ERR("first parameter is empty\n"); return E_SCRIPT; } if (param_no == 1) { accp = (struct acc_param*)pkg_malloc(sizeof(struct acc_param)); if (!accp) { LM_ERR("no more pkg mem\n"); return E_OUT_OF_MEM; } memset( accp, 0, sizeof(struct acc_param)); accp->reason.s = p; accp->reason.len = strlen(p); if (strchr(p,PV_MARKER)!=NULL) { /* is a variable $xxxxx */ if (pv_parse_format(&accp->reason, &accp->elem)<0) { LM_ERR("bad param 1 - parse format error [%.*s]\n", accp->reason.len, accp->reason.s); pkg_free(accp); return E_UNSPEC; } } else { if(acc_parse_code(p,accp)<0) { LM_ERR("bad param 1 - parse code error\n"); pkg_free(accp); return E_UNSPEC; } } *param = (void*)accp; #ifdef SQL_ACC } else if (param_no == 2) { /* only for db acc - the table name */ if (db_url.s==0) { pkg_free(p); *param = 0; } else { return fixup_var_pve_str_12(param, 2); } #endif } return 0; }
/** * @brief fixup function for pv_{www,proxy}_authenticate */ static int fixup_pv_auth(void **param, int param_no) { if(strlen((char*)*param)<=0) { LM_ERR("empty parameter %d not allowed\n", param_no); return -1; } switch(param_no) { case 1: case 2: return fixup_var_pve_str_12(param, 1); case 3: return fixup_var_int_12(param, 1); } return 0; }
static int acc_fixup(void** param, int param_no) { struct acc_param *accp; char *p; p = (char*)*param; if (p==0 || p[0]==0) { LM_ERR("first parameter is empty\n"); return E_SCRIPT; } if (param_no == 1) { accp = (struct acc_param*)pkg_malloc(sizeof(struct acc_param)); if (!accp) { LM_ERR("no more pkg mem\n"); return E_OUT_OF_MEM; } memset( accp, 0, sizeof(struct acc_param)); accp->reason.s = p; accp->reason.len = strlen(p); /* any code? */ if (accp->reason.len>=3 && isdigit((int)p[0]) && isdigit((int)p[1]) && isdigit((int)p[2]) ) { accp->code = (p[0]-'0')*100 + (p[1]-'0')*10 + (p[2]-'0'); accp->code_s.s = p; accp->code_s.len = 3; accp->reason.s += 3; for( ; isspace((int)accp->reason.s[0]) ; accp->reason.s++ ); accp->reason.len = strlen(accp->reason.s); } *param = (void*)accp; #ifdef SQL_ACC } else if (param_no == 2) { /* only for db acc - the table name */ if (db_url.s==0) { pkg_free(p); *param = 0; } else { return fixup_var_pve_str_12(param, 2); } #endif } return 0; }
static int mod_init( void ) { #ifdef SQL_ACC if (db_url.s) { if(db_url.len<=0) { db_url.s = NULL; db_url.len = 0; } } if(db_table_acc.len!=3 || strncmp(db_table_acc.s, "acc", 3)!=0) { db_table_acc_data = db_table_acc.s; if(fixup_var_pve_str_12(&db_table_acc_data, 1)<0) { LM_ERR("unable to parse acc table name [%.*s]\n", db_table_acc.len, db_table_acc.s); return -1; } } if(db_table_mc.len!=12 || strncmp(db_table_mc.s, "missed_calls", 12)!=0) { db_table_mc_data = db_table_mc.s; if(fixup_var_pve_str_12(&db_table_mc_data, 1)<0) { LM_ERR("unable to parse mc table name [%.*s]\n", db_table_mc.len, db_table_mc.s); return -1; } } #endif if (log_facility_str) { int tmp = str2facility(log_facility_str); if (tmp != -1) log_facility = tmp; else { LM_ERR("invalid log facility configured"); return -1; } } /* ----------- GENERIC INIT SECTION ----------- */ /* failed transaction handling */ if ((failed_transaction_flag != -1) && !flag_in_range(failed_transaction_flag)) { LM_ERR("failed_transaction_flag set to invalid value\n"); return -1; } if (failed_filter_str) { if (parse_failed_filter(failed_filter_str, failed_filter) == 0) { LM_ERR("failed to parse failed_filter param\n"); return -1; } } else { failed_filter[0] = 0; } /* load the TM API */ if (load_tm_api(&tmb)!=0) { LM_ERR("can't load TM API\n"); return -1; } /* if detect_direction is enabled, load rr also */ if (detect_direction) { if (load_rr_api(&rrb)!=0) { LM_ERR("can't load RR API\n"); return -1; } /* we need the append_fromtag on in RR */ if (!rrb.append_fromtag) { LM_ERR("'append_fromtag' RR param is not enabled!" " - required by 'detect_direction'\n"); return -1; } } /* listen for all incoming requests */ if ( tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, acc_onreq, 0, 0 ) <=0 ) { LM_ERR("cannot register TMCB_REQUEST_IN callback\n"); return -1; } /* configure multi-leg accounting */ if (leg_info_str && (leg_info=parse_acc_leg(leg_info_str))==0 ) { LM_ERR("failed to parse multileg_info param\n"); return -1; } /* ----------- SYSLOG INIT SECTION ----------- */ /* parse the extra string, if any */ if (log_extra_str && (log_extra=parse_acc_extra(log_extra_str))==0 ) { LM_ERR("failed to parse log_extra param\n"); return -1; } if ((log_flag != -1) && !flag_in_range(log_flag)) { LM_ERR("log_flag set to invalid value\n"); return -1; } if ((log_missed_flag != -1) && !flag_in_range(log_missed_flag)) { LM_ERR("log_missed_flag set to invalid value\n"); return -1; } acc_log_init(); /* ----------- INIT CDR GENERATION ----------- */ if( cdr_enable < 0 || cdr_enable > 1) { LM_ERR("cdr_enable is out of range\n"); return -1; } if( cdr_expired_dlg_enable < 0 || cdr_expired_dlg_enable > 1) { LM_ERR("cdr_expired_dlg_enable is out of range\n"); return -1; } if( cdr_enable) { if( !cdr_start_str.s || !cdr_end_str.s || !cdr_duration_str.s) { LM_ERR( "necessary cdr_parameters are not set\n"); return -1; } if( !cdr_start_str.len || !cdr_end_str.len || !cdr_duration_str.len) { LM_ERR( "necessary cdr_parameters are empty\n"); return -1; } if( set_cdr_extra( cdr_log_extra_str) != 0) { LM_ERR( "failed to set cdr extra '%s'\n", cdr_log_extra_str); return -1; } if( cdr_facility_str && set_cdr_facility( cdr_facility_str) != 0) { LM_ERR( "failed to set cdr facility '%s'\n", cdr_facility_str); return -1; } if( init_cdr_generation() != 0) { LM_ERR("failed to init cdr generation\n"); return -1; } } /* ------------ SQL INIT SECTION ----------- */ #ifdef SQL_ACC if (db_url.s && db_url.len > 0) { /* parse the extra string, if any */ if (db_extra_str && (db_extra=parse_acc_extra(db_extra_str))==0 ) { LM_ERR("failed to parse db_extra param\n"); return -1; } if (acc_db_init(&db_url)<0){ LM_ERR("failed...did you load a database module?\n"); return -1; } /* fix the flags */ if ((db_flag != -1) && !flag_in_range(db_flag)) { LM_ERR("db_flag set to invalid value\n"); return -1; } if ((db_missed_flag != -1) && !flag_in_range(db_missed_flag)) { LM_ERR("db_missed_flag set to invalid value\n"); return -1; } } else { db_url.s = NULL; db_url.len = 0; db_flag = -1; db_missed_flag = -1; } #endif /* ------------ RADIUS INIT SECTION ----------- */ #ifdef RAD_ACC if (radius_config && radius_config[0]) { /* parse the extra string, if any */ if (rad_extra_str && (rad_extra=parse_acc_extra(rad_extra_str))==0 ) { LM_ERR("failed to parse rad_extra param\n"); return -1; } /* fix the flags */ if ((radius_flag != -1) && !flag_in_range(radius_flag)) { LM_ERR("radius_flag set to invalid value\n"); return -1; } if ((radius_missed_flag != -1) && !flag_in_range(radius_missed_flag)) { LM_ERR("radius_missed_flag set to invalid value\n"); return -1; } if (init_acc_rad( radius_config, service_type)!=0 ) { LM_ERR("failed to init radius\n"); return -1; } } else { radius_config = 0; radius_flag = -1; radius_missed_flag = -1; } #endif /* ------------ DIAMETER INIT SECTION ----------- */ #ifdef DIAM_ACC /* fix the flags */ if (flag_idx2mask(&diameter_flag)<0) return -1; if (flag_idx2mask(&diameter_missed_flag)<0) return -1; /* parse the extra string, if any */ if (dia_extra_str && (dia_extra=parse_acc_extra(dia_extra_str))==0 ) { LM_ERR("failed to parse dia_extra param\n"); return -1; } if (acc_diam_init()!=0) { LM_ERR("failed to init diameter engine\n"); return -1; } #endif _acc_module_initialized = 1; if(acc_init_engines()<0) { LM_ERR("failed to init extra engines\n"); return -1; } return 0; }
/* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */ int fixup_var_pve_str_2(void** param, int param_no) { if (param_no == 2) return fixup_var_pve_str_12(param, param_no); else return 0; }
static int redirect_init(void) { regex_t *filter; void *p; cmd_function fct; /* load the TM API */ if (load_tm_api(&rd_tmb)!=0) { LM_ERR("failed to load TM API\n"); goto error; } p = (void*)acc_db_table; /* fixup table name */ if(fixup_var_pve_str_12(&p, 1)<0) { LM_ERR("failed to fixup acc db table\n"); goto error; } acc_db_table = p; /* init filter */ init_filters(); /* what's the default rule? */ if (def_filter_s) { if ( !strcasecmp(def_filter_s,ACCEPT_RULE_STR) ) { set_default_rule( ACCEPT_RULE ); } else if ( !strcasecmp(def_filter_s,DENY_RULE_STR) ) { set_default_rule( DENY_RULE ); } else { LM_ERR("unknown default filter <%s>\n",def_filter_s); } } /* if accept filter specify, compile it */ if (regexp_compile(accept_filter_s, &filter)<0) { LM_ERR("failed to init accept filter\n"); goto error; } add_default_filter( ACCEPT_FILTER, filter); /* if deny filter specify, compile it */ if (regexp_compile(deny_filter_s, &filter)<0) { LM_ERR("failed to init deny filter\n"); goto error; } add_default_filter( DENY_FILTER, filter); if(sruid_init(&_redirect_sruid, '-', "rdir", SRUID_INC)<0) return -1; if(rd_acc_fct == 0) { /* import the acc stuff */ if(acc_fct_s != 0 && acc_fct_s[0] == '\0') { fct = find_export(acc_fct_s, 2, REQUEST_ROUTE); if(fct == 0) fct = find_export(acc_fct_s, 1, REQUEST_ROUTE); if(fct == 0) { LM_ERR("cannot import %s function; is acc loaded and" " configured\n", acc_fct_s); return E_UNSPEC; } rd_acc_fct = fct; } } return 0; error: return -1; }