static int mod_init(void) { load_tm_f load_tm; LOG(L_INFO,"UAC - initializing\n"); from_param.s = from_param_chr; from_param.len = strlen(from_param_chr); if (from_param.len==0) { LOG(L_ERR,"ERROR:uac:mod_init: from_tag cannot be empty\n"); goto error; } if (from_restore_mode!=FROM_NO_RESTORE && from_restore_mode!=FROM_AUTO_RESTORE && from_restore_mode!=FROM_MANUAL_RESTORE ) { LOG(L_ERR,"ERROR:uac:mod_init: invalid (%d) restore_from mode\n", from_restore_mode); } /* load the tm functions */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:uac:mod_init: cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm( &uac_tmb )==-1) goto error; if (from_restore_mode==FROM_AUTO_RESTORE) { /* get all transactions */ if (uac_tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, tr_checker, 0, 0)!=1) { LOG(L_ERR,"ERROR:uac:mod_init: failed to install TM callback\n"); goto error; } } init_from_replacer(); return 0; error: return -1; }
static int mod_init(void) { pv_spec_t avp_spec; if (restore_mode_str && *restore_mode_str) { if (strcasecmp(restore_mode_str,"none")==0) { restore_mode = UAC_NO_RESTORE; } else if (strcasecmp(restore_mode_str,"manual")==0) { restore_mode = UAC_MANUAL_RESTORE; } else if (strcasecmp(restore_mode_str,"auto")==0) { restore_mode = UAC_AUTO_RESTORE; } else { LM_ERR("unsupported value '%s' for restore_mode\n", restore_mode_str); goto error; } } if ( (rr_from_param.len==0 || rr_to_param.len==0) && restore_mode!=UAC_NO_RESTORE) { LM_ERR("rr_store_param cannot be empty if FROM is restoreable\n"); goto error; } /* parse the auth AVP spesc, if any */ if ( auth_username_avp || auth_password_avp || auth_realm_avp) { if (!auth_username_avp || !auth_password_avp || !auth_realm_avp) { LM_ERR("partial definition of auth AVP!"); goto error; } if ( parse_auth_avp(auth_realm_avp, &auth_realm_spec, "realm")<0 || parse_auth_avp(auth_username_avp, &auth_username_spec, "username")<0 || parse_auth_avp(auth_password_avp, &auth_password_spec, "password")<0 ) { goto error; } } else { memset( &auth_realm_spec, 0, sizeof(pv_spec_t)); memset( &auth_password_spec, 0, sizeof(pv_spec_t)); memset( &auth_username_spec, 0, sizeof(pv_spec_t)); } /* load the TM API - FIXME it should be loaded only * if NO_RESTORE and AUTH */ if (load_tm_api(&uac_tmb)!=0) { LM_ERR("can't load TM API\n"); goto error; } if (restore_mode!=UAC_NO_RESTORE) { /* load the RR API */ if (load_rr_api(&uac_rrb)!=0) { LM_ERR("can't load RR API\n"); goto error; } if(restore_from_avp.s) { if (pv_parse_spec(&restore_from_avp, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_from_avp.len, restore_from_avp.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &restore_from_avp_name, &restore_from_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", restore_from_avp.len, restore_from_avp.s); return -1; } restore_from_avp_type |= AVP_VAL_STR; } if(restore_to_avp.s) { if (pv_parse_spec(&restore_to_avp, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_to_avp.len, restore_to_avp.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &restore_to_avp_name, &restore_to_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", restore_to_avp.len, restore_to_avp.s); return -1; } restore_to_avp_type |= AVP_VAL_STR; } if (restore_mode==UAC_AUTO_RESTORE) { /* we need the append_fromtag on in RR */ memset(&dlg_api, 0, sizeof(struct dlg_binds)); if (uac_restore_dlg==0 || load_dlg_api(&dlg_api)!=0) { if (!uac_rrb.append_fromtag) { LM_ERR("'append_fromtag' RR param is not enabled!" " - required by AUTO restore mode\n"); goto error; } if (uac_restore_dlg!=0) LM_DBG("failed to find dialog API - is dialog module loaded?\n"); } /* get all requests doing loose route */ if (uac_rrb.register_rrcb( rr_checker, 0)!=0) { LM_ERR("failed to install RR callback\n"); goto error; } } } if(reg_db_url.s && reg_db_url.len>=0) { if(!reg_contact_addr.s || reg_contact_addr.len<=0) { LM_ERR("contact address parameter not set\n"); goto error; } if(reg_htable_size>14) reg_htable_size = 14; if(reg_htable_size<2) reg_htable_size = 2; reg_htable_size = 1<<reg_htable_size; if(uac_reg_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); goto error; } if(uac_reg_init_ht(reg_htable_size)<0) { LM_ERR("failed to init reg htable\n"); goto error; } register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); } init_from_replacer(); uac_req_init(); return 0; error: return -1; }
static int mod_init(void) { LM_INFO("initializing...\n"); int rr_api_loaded=0; if ( is_script_func_used("uac_auth", -1) ) { /* load the UAC_AUTH API as uac_auth() is invoked from script */ if(load_uac_auth_api(&uac_auth_api)<0){ LM_ERR("can't load UAC_AUTH API, needed for uac_auth()\n"); goto error; } } /* load the TM API - FIXME it should be loaded only * if NO_RESTORE and AUTH */ if (load_tm_api(&uac_tmb)!=0) { LM_ERR("can't load TM API\n"); goto error; } if (restore_mode_str && *restore_mode_str) { if (strcasecmp(restore_mode_str,"none")==0) { restore_mode = UAC_NO_RESTORE; } else if (strcasecmp(restore_mode_str,"manual")==0) { restore_mode = UAC_MANUAL_RESTORE; } else if (strcasecmp(restore_mode_str,"auto")==0) { restore_mode = UAC_AUTO_RESTORE; } else { LM_ERR("unsupported value '%s' for restore_mode\n", restore_mode_str); goto error; } } if ( is_script_func_used("uac_replace_from", -1) || is_script_func_used("uac_replace_to", -1) ) { /* replace TO/FROM stuff is used, get prepared */ rr_from_param.len = strlen(rr_from_param.s); rr_to_param.len = strlen(rr_to_param.s); if ( (rr_from_param.len==0 || rr_to_param.len==0) && restore_mode!=UAC_NO_RESTORE) { LM_ERR("rr_store_param cannot be empty if FROM is restoreable\n"); goto error; } uac_passwd.len = strlen(uac_passwd.s); if (restore_mode!=UAC_NO_RESTORE) { /* load the RR API */ if (load_rr_api(&uac_rrb)!=0) { LM_ERR("can't load RR API\n"); goto error; } rr_api_loaded=1; if (restore_mode==UAC_AUTO_RESTORE) { /* we need the append_fromtag on in RR */ if (!force_dialog && !uac_rrb.append_fromtag) { LM_ERR("'append_fromtag' RR param is not enabled!" " - required by AUTO restore mode\n"); goto error; } /* trying to load dialog module */ memset(&dlg_api, 0, sizeof(struct dlg_binds)); if (load_dlg_api(&dlg_api)!=0) { if (force_dialog) { LM_ERR("cannot force dialog. dialog module not loaded\n"); goto error; } LM_DBG("failed to find dialog API - is dialog module loaded?\n"); } else { if ( (parse_store_bavp(&store_to_bavp, &to_bavp_spec) || parse_store_bavp(&store_from_bavp, &from_bavp_spec))) { LM_ERR("cannot set correct store parameters\n"); goto error; } /* install calback to catch all loaded dialogs */ if ( dlg_api.register_dlgcb( NULL, DLGCB_LOADED, dlg_restore_callback, NULL, NULL) != 0 ) { LM_ERR("failed to install dialog restore callback\n"); goto error; } } /* get all requests doing loose route */ if (uac_rrb.register_rrcb( rr_checker, 0, 2)!=0) { LM_ERR("failed to install RR callback\n"); goto error; } } } /* init from replacer */ init_from_replacer(); } if (is_script_func_used("uac_auth", -1)) { if (!rr_api_loaded) { if (load_rr_api(&uac_rrb)!=0) { LM_ERR("can't load RR API\n"); goto error; } } if (!uac_rrb.append_fromtag) { LM_ERR("'append_fromtag' RR param is not enabled!" " - required by uac_auth() restore mode\n"); goto error; } if (uac_rrb.register_rrcb( rr_uac_auth_checker, 0, 2)!=0) { LM_ERR("failed to install RR callback\n"); goto error; } } return 0; error: return -1; }