/* * Load TM API * return 0 success, -1 failure */ int ospInitTm(void) { load_tm_f load_tm; LOG(L_DBG, "osp: ospInitTm\n"); if ((load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0)) == 0) { LOG(L_ERR, "osp: ERROR: failed to import load_tm\n"); return -1; } if (load_tm(&osp_tmb) == -1) { LOG(L_ERR, "osp: ERROR: failed to load TM API\n"); LOG(L_ERR, "osp: ERROR: TM is required for reporting call setup usage\n"); return -1; } /* Register callbacks, listen for all incoming requests */ if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0) <= 0) { LOG(L_ERR, "osp: ERROR: failed to register TMCB_REQUEST_IN callback\n"); LOG(L_ERR, "osp: ERROR: TM callbacks are required for reporting call set up usage\n"); return -1; } return 0; }
static int mod_init(void) { load_tm_f load_tm; /* import the TM auto-loading function */ if ( !(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; if (verify_fmt(log_fmt)==-1) return -1; /* register callbacks*/ /* listen for all incoming requests */ if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0, 0) <= 0) { LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN " "callback\n"); return -1; } init_data(log_fmt); if (parse_attrs(&avps, &avps_n, attrs) < 0) { ERR("Error while parsing 'attrs' module parameter\n"); return -1; } return 0; }
static int mod_init(void) { load_tm_f load_tm; /* load the tm functions */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:jsonrpc:mod_init: cannot import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; if (servers_param == NULL) { LM_ERR("servers parameter missing.\n"); return -1; } register_procs(1); if (pipe(pipe_fds) < 0) { LM_ERR("pipe() failed\n"); return -1; } return(0); }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; DBG("MSILO: initializing ...\n"); /* binding to mysql module */ if (bind_dbmod()) { DBG("MSILO: ERROR: Database module not found\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: msilo: mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; ml = msg_list_init(); if(!ml) { DBG("ERROR: msilo: mod_init: can't initialize msg list\n"); return -1; } register_timer( m_clean_silo, 0, check_time); reg_addr.s = registrar; reg_addr.len = (registrar)?strlen(registrar):0; return 0; }
int mod_init_tm() { load_tm_f load_tm; INFO("osp/tm - initializing\n"); /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { ERR("osp:mod_init_tm: can't import load_tm\n"); ERR("osp:mod_init_tm: tm is required for reporting call set up usage info\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &_tmb )==-1) return -1; /* register callbacks*/ /* listen for all incoming requests */ if ( _tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, onreq, 0 ) <=0 ) { ERR("osp:mod_init_tm: cannot register TMCB_REQUEST_IN callback\n"); ERR("osp:mod_init_tm: tm callbacks are required for reporting call set up usage info\n"); return -1; } return 0; }
int prepare () { /* using pre-compiled expressions to speed things up*/ compile_expresions(PORT_REGEX,IP_REGEX); #ifdef DEMO load_tm_f load_tm; fprintf(stdout,"===============NEW RUN================\n"); //register callbacks if (!(load_tm=(load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { printf("Error:FCP:prepare:cannot import load_tm\n"); return -1; } if (load_tm(&tmb)==-1) return -1; if (tmb.register_tmcb(TMCB_REQUEST_OUT, func_invite, 0, 0) <= 0) return -1; #endif return 0; }
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; }
/** * Module init function. * Initializes the ISC structures */ static int isc_init( void ) { load_tm_f load_tm; load_scscf_f load_scscf; LOG( L_INFO, "INFO:"M_NAME": - init\n" ); /* import the TM auto-loading function */ if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { LOG(L_ERR,"ERROR:"M_NAME":isc_init: cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm(&isc_tmb) == -1) goto error; /* import the SCSCF auto-loading function */ if (!(load_scscf = (load_scscf_f)find_export("load_scscf",NO_SCRIPT,0))) { LOG(L_ERR,"ERROR:"M_NAME":isc_init: cannot import load_scscf\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_scscf(&isc_scscfb) == -1) goto error; /* Init the isc_my_uri parameter */ if (!isc_my_uri_c) { LOG( L_CRIT, "ERROR:"M_NAME":isc_init: mandatory parameter \"isc_my_uri\" found empty\n" ); goto error; } isc_my_uri.s = isc_my_uri_c; isc_my_uri.len = strlen(isc_my_uri_c); isc_my_uri_sip.len = 4+isc_my_uri.len; isc_my_uri_sip.s = shm_malloc(isc_my_uri_sip.len+1); memcpy(isc_my_uri_sip.s,"sip:",4); memcpy(isc_my_uri_sip.s+4,isc_my_uri.s,isc_my_uri.len); isc_my_uri_sip.s[isc_my_uri_sip.len]=0; #ifdef WITH_IMS_PM ims_pm_init(isc_my_uri_sip,ims_pm_node_type, ims_pm_logfile); #endif /* WITH_IMS_PM */ return 0; error: return -1; }
static int mod_init(void) { load_tm_f load_tm; /* import the TM auto-loading function */ if ( !(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; if (verify_fmt(log_fmt)==-1) return -1; /* register callbacks*/ /* listen for all incoming requests */ if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0 ) <= 0) { LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN " "callback\n"); return -1; } if (bind_dbmod(db_url.s, &acc_dbf) < 0) { LOG(L_ERR, "ERROR:acc:mod_init: bind_db failed\n"); return -1; } /* Check database capabilities */ if (!DB_CAPABILITY(acc_dbf, DB_CAP_INSERT)) { LOG(L_ERR, "ERROR:acc:mod_init: Database module does not implement insert function\n"); return -1; } init_data(log_fmt); if (parse_attrs(&avps, &avps_n, attrs) < 0) { ERR("Error while parsing 'attrs' module parameter\n"); return -1; } return 0; }
int natpinger_init(void) { bind_usrloc_t bind_usrloc; load_tm_f load_tm; char *p; if (natping_interval > 0) { bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LOG(L_ERR, "ERROR: nathelper: natpinger_init: Can't find usrloc module\n"); return -1; } if (bind_usrloc(&ul) < 0) { return -1; } if (natping_method != NULL) { for (p = natping_method; *p != '\0'; ++p) *p = toupper(*p); if (strcmp(natping_method, "NULL") == 0) natping_method = NULL; } if (natping_method != NULL) { /* import the TM auto-loading function */ if (!(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: nathelper: natpinger_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm(&tmb) == -1) return -1; } register_timer(natping, NULL, natping_interval); } return 0; }
static int dlg_mod_init(void) { load_tm_f load_tm; if (init_dialog_mutex() < 0) { ERR("can't initialize mutex\n"); return -1; } init_dialog_tags(); load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0); if (!load_tm) { LOG(L_ERR, "dlg_mod_init(): Can't import tm\n"); return -1; } if (load_tm(&tmb) < 0) { LOG(L_ERR, "dlg_mod_init(): Can't import tm functions\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; load_sl_f load_sl; LM_NOTICE("initializing module ...\n"); /* load TM API*/ if ( (load_tm=(load_tm_f)find_export("load_tm", 0))) { if (load_tm( &tmb )==-1) { LM_ERR("failed to load tm api\n"); return -1; } tm_loaded = 1; } /* load SL API */ if ((load_sl=(load_sl_f)find_export("load_sl", 0))) { if (load_sl( &slb )==-1) { LM_ERR("failed to load sl api although sl module is loaded\n"); return -1; } sl_loaded = 1; } if(!tm_loaded && !sl_loaded) { LM_ERR("neither 'tm' nor 'sl' module loaded! Sipreply module requires" " loading at least one of these two\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { pv_spec_t avp_spec; LM_DBG("initializing ...\n"); if (dst_avp_param.s) dst_avp_param.len = strlen(dst_avp_param.s); if (grp_avp_param.s) grp_avp_param.len = strlen(grp_avp_param.s); if (cnt_avp_param.s) cnt_avp_param.len = strlen(cnt_avp_param.s); if (attrs_avp_param.s) attrs_avp_param.len = strlen(attrs_avp_param.s); if (hash_pvar_param.s) hash_pvar_param.len = strlen(hash_pvar_param.s); if (ds_setid_pvname.s) ds_setid_pvname.len = strlen(ds_setid_pvname.s); if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s); if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s); if(options_reply_codes_str.s) { options_reply_codes_str.len = strlen(options_reply_codes_str.s); if(parse_reply_codes( &options_reply_codes_str, &options_reply_codes, &options_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } if(init_data()!= 0) return -1; if(ds_db_url.s) { ds_db_url.len = strlen(ds_db_url.s); ds_table_name.len = strlen(ds_table_name.s); ds_set_id_col.len = strlen(ds_set_id_col.s); ds_dest_uri_col.len = strlen(ds_dest_uri_col.s); ds_dest_flags_col.len = strlen(ds_dest_flags_col.s); ds_dest_weight_col.len= strlen(ds_dest_weight_col.s); ds_dest_attrs_col.len = strlen(ds_dest_attrs_col.s); if(init_ds_db()!= 0) { LM_ERR("could not initiate a connect to the database\n"); return -1; } } else { if(ds_load_list(dslistfile)!=0) { LM_ERR("no dispatching list loaded from file\n"); return -1; } else { LM_DBG("loaded dispatching list\n"); } } if (dst_avp_param.s && dst_avp_param.len > 0) { if (pv_parse_spec(&dst_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", dst_avp_param.len, dst_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &dst_avp_name,&dst_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", dst_avp_param.len, dst_avp_param.s); return -1; } } else { dst_avp_name.n = 0; dst_avp_type = 0; } if (grp_avp_param.s && grp_avp_param.len > 0) { if (pv_parse_spec(&grp_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", grp_avp_param.len, grp_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &grp_avp_name,&grp_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", grp_avp_param.len, grp_avp_param.s); return -1; } } else { grp_avp_name.n = 0; grp_avp_type = 0; } if (cnt_avp_param.s && cnt_avp_param.len > 0) { if (pv_parse_spec(&cnt_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", cnt_avp_param.len, cnt_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &cnt_avp_name,&cnt_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", cnt_avp_param.len, cnt_avp_param.s); return -1; } } else { cnt_avp_name.n = 0; cnt_avp_type = 0; } if (attrs_avp_param.s && attrs_avp_param.len > 0) { if (pv_parse_spec(&attrs_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", attrs_avp_param.len, attrs_avp_param.s); return -1; } if (pv_get_avp_name(0, &(avp_spec.pvp), &attrs_avp_name, &attrs_avp_type)!=0){ LM_ERR("[%.*s]- invalid AVP definition\n", attrs_avp_param.len, attrs_avp_param.s); return -1; } } else { attrs_avp_name.n = 0; attrs_avp_type = 0; } if (hash_pvar_param.s && *hash_pvar_param.s) { if(pv_parse_format(&hash_pvar_param, &hash_param_model) < 0 || hash_param_model==NULL) { LM_ERR("malformed PV string: %s\n", hash_pvar_param.s); return -1; } } else { hash_param_model = NULL; } if(ds_setid_pvname.s!=0) { if(pv_parse_spec(&ds_setid_pvname, &ds_setid_pv)==NULL || !pv_is_w(&ds_setid_pv)) { LM_ERR("[%s]- invalid setid_pvname\n", ds_setid_pvname.s); return -1; } } /* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */ if (ds_ping_interval > 0) { load_tm_f load_tm; str host; int port,proto; if (probing_sock_s && probing_sock_s[0]!=0 ) { if (parse_phostport( probing_sock_s, strlen(probing_sock_s), &host.s, &host.len, &port, &proto)!=0 ) { LM_ERR("socket description <%s> is not valid\n", probing_sock_s); return -1; } probing_sock = grep_sock_info( &host, port, proto); if (probing_sock==NULL) { LM_ERR("socket <%s> is not local to opensips (we must listen " "on it\n", probing_sock_s); return -1; } } /* TM-Bindings */ load_tm=(load_tm_f)find_export("load_tm", 0, 0); if (load_tm==NULL) { LM_ERR("failed to bind to the TM-Module - required for probing\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb ) == -1) { LM_ERR("could not load the TM-functions - disable DS ping\n"); return -1; } /* Register the PING-Timer */ if (register_timer(ds_check_timer, NULL, ds_ping_interval)<0) { LM_ERR("failed to register timer for probing!\n"); return -1; } } return 0; }
/** * Initializes the module. */ static int mod_init(void) { load_tm_f load_tm; load_cdp_f load_cdp; bind_dlg_mod_f load_dlg; str algo; callback_singleton=shm_malloc(sizeof(int)); *callback_singleton=0; shutdown_singleton=shm_malloc(sizeof(int)); *shutdown_singleton=0; LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n"); /* fix the parameters */ scscf_name_str.s = scscf_name; scscf_name_str.len = strlen(scscf_name); if (!build_record_service_route()) goto error; scscf_forced_hss_peer_str.s = scscf_forced_hss_peer; scscf_forced_hss_peer_str.len = strlen(scscf_forced_hss_peer); algo.s = registration_default_algorithm; algo.len = strlen(registration_default_algorithm); registration_default_algorithm_type = get_algorithm_type(algo); #ifdef WITH_IMS_PM ims_pm_init(scscf_name_str,ims_pm_node_type, ims_pm_logfile); ims_pm_init_scscf(); #endif /* WITH_IMS_PM */ /* load the send_reply function from sl module */ sl_reply = find_export("sl_send_reply", 2, 0); if (!sl_reply) { LOG(L_ERR, "ERR"M_NAME":mod_init: This module requires sl module\n"); goto error; } /* bind to the db module */ if(scscf_persistency_mode==WITH_DATABASE_BULK || scscf_persistency_mode==WITH_DATABASE_CACHE){ if (!scscf_db_url) { LOG(L_ERR, "ERR:"M_NAME":mod_init: no db_url specified but DB has to be used " "(scscf_persistency_mode=%d\n", scscf_persistency_mode); return -1; } if (!scscf_db_init(scscf_db_url)<0){ LOG(L_ERR, "ERR:"M_NAME": mod_init: Error while connecting database\n"); return -1; } /* db lock */ db_lock = (gen_lock_t*)lock_alloc(); if(!db_lock){ LOG(L_ERR, "ERR:"M_NAME": mod_init: No memory left\n"); return -1; } lock_init(db_lock); /* snapshot and step versions */ auth_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!auth_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_snapshot_version, no memory left\n"); return -1; } *auth_snapshot_version=0; auth_step_version=(int*)shm_malloc(sizeof(int)); if(!auth_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: auth_step_version, no memory left\n"); return -1; } *auth_step_version=0; dialogs_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!dialogs_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_snapshot_version, no memory left\n"); return -1; } *dialogs_snapshot_version=0; dialogs_step_version=(int*)shm_malloc(sizeof(int)); if(!dialogs_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: dialogs_step_version, no memory left\n"); return -1; } *dialogs_step_version=0; registrar_snapshot_version=(int*)shm_malloc(sizeof(int)); if(!registrar_snapshot_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_snapshot_version, no memory left\n"); return -1; } *registrar_snapshot_version=0; registrar_step_version=(int*)shm_malloc(sizeof(int)); if(!registrar_step_version){ LOG(L_ERR, "ERR:"M_NAME":mod_init: registrar_step_version, no memory left\n"); return -1; } *registrar_step_version=0; } /* bind to the tm module */ if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; /* bind to the cdp module */ if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module\n"); goto error; } if (load_cdp(&cdpb) == -1) goto error; /* bind to the dialog module */ load_dlg = (bind_dlg_mod_f)find_export("bind_dlg_mod", -1, 0); if (!load_dlg) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import bind_dlg_mod. This module requires dialog module\n"); return -1; } if (load_dlg(&dialogb) != 0) { return -1; } /* Init the authorization data storage */ if (!auth_data_init(auth_data_hash_size)) goto error; if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_authdata(); if (register_timer(persistency_timer_authdata,0,scscf_persistency_timer_authdata)<0) goto error; } /* register the authentication vectors timer */ if (register_timer(reg_await_timer,auth_data,10)<0) goto error; /* init the registrar storage */ if (!r_storage_init(registrar_hash_size)) goto error; if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_registrar(); if (register_timer(persistency_timer_registrar,0,scscf_persistency_timer_registrar)<0) goto error; } /* register the registrar timer */ if (register_timer(registrar_timer,registrar,10)<0) goto error; /* init the registrar notifications */ if (!r_notify_init()) goto error; /* register the registrar notifications timer */ if (register_timer(notification_timer,notification_list,5)<0) goto error; /* init the dialog storage */ if (!s_dialogs_init(scscf_dialogs_hash_size)){ LOG(L_ERR, "ERR"M_NAME":mod_init: Error initializing the Hash Table for stored dialogs\n"); goto error; } scscf_dialog_count = shm_malloc(sizeof(int)); *scscf_dialog_count = 0; scscf_dialog_count_lock = lock_alloc(); scscf_dialog_count_lock = lock_init(scscf_dialog_count_lock); if (scscf_persistency_mode!=NO_PERSISTENCY){ load_snapshot_dialogs(); if (register_timer(persistency_timer_dialogs,0,scscf_persistency_timer_dialogs)<0) goto error; } /* register the dialog timer */ if (register_timer(dialog_timer,s_dialogs,60)<0) goto error; /* don't register response callback as we always set callback per transactions * and we're not interested in other responses */ /*AAAAddResponseHandler(&CxAnswerHandler,0);*/ return 0; error: return -1; }
static int mod_init( void ) { load_tm_f load_tm; fprintf( stderr, "acc - initializing\n"); /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: acc: mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; if (verify_fmt(log_fmt)==-1) return -1; /* register callbacks */ /* report on completed transactions */ if (tmb.register_tmcb( TMCB_RESPONSE_OUT, acc_onreply, 0 /* empty param */ ) <= 0) return -1; /* account e2e acks if configured to do so */ if (tmb.register_tmcb( TMCB_E2EACK_IN, acc_onack, 0 /* empty param */ ) <=0 ) return -1; /* disable silent c-timer for registered calls */ if (tmb.register_tmcb( TMCB_REQUEST_IN, acc_onreq, 0 /* empty param */ ) <=0 ) return -1; /* report on missed calls */ if (tmb.register_tmcb( TMCB_ON_FAILURE, on_missed, 0 /* empty param */ ) <=0 ) return -1; /* get incoming replies ready for processing */ if (tmb.register_tmcb( TMCB_RESPONSE_IN, acc_onreply_in, 0 /* empty param */)<=0) return -1; #ifdef SQL_ACC if (bind_dbmod()) { LOG(L_ERR, "ERROR: acc: init_child bind_db failed..." "did you load a database module?\n"); return -1; } #endif #ifdef RAD_ACC /* open log */ rc_openlog("ser"); /* read config */ if (rc_read_config(radius_config)!=0) { LOG(L_ERR, "ERROR: acc: error opening radius config file: %s\n", radius_config ); return -1; } /* read dictionary */ if (rc_read_dictionary(rc_conf_str("dictionary"))!=0) { LOG(L_ERR, "ERROR: acc: error reading radius dictionary\n"); return -1; } #endif return 0; }
int global_init(void) { load_tm_f load_tm; int i, net_pipe[2], foo; char *p; struct socket_info* si; /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) goto error; /*fix domain*/ if (!domain.s){ si=get_first_socket(); if (si==0){ LM_CRIT("null listen socket list\n"); goto error; } /*do I have to add port?*/ i = (si->port_no_str.len && si->port_no!=5060); domain.len = si->name.len + i*(si->port_no_str.len+1); domain.s = (char*)pkg_malloc(domain.len); if (!domain.s) { LM_ERR("no free pkg memory!\n"); goto error; } p = domain.s; memcpy(p,si->name.s,si->name.len); p += si->name.len; if (i) { *p=':'; p++; memcpy(p,si->port_no_str.s, si->port_no_str.len); p += si->port_no_str.len; } } /* creates pipes for networks */ for(i=0;i<nr_of_networks;i++) { /* create the pipe*/ if (pipe(net_pipe)==-1) { LM_ERR("failed to create pipe!\n"); goto error; } networks[i].pipe_out = net_pipe[0]; net_pipes_in[i] = net_pipe[1]; /* sets reading from pipe to non blocking */ if ((foo=fcntl(net_pipe[0],F_GETFL,0))<0) { LM_ERR("failed to get flag for pipe - fcntl\n"); goto error; } foo |= O_NONBLOCK; if (fcntl(net_pipe[0],F_SETFL,foo)<0) { LM_ERR("failed to set flag for pipe - fcntl\n"); goto error; } } /* if report will be used, init the report queue */ if (sms_report_type!=NO_REPORT && !init_report_queue()) { LM_ERR("cannot get shm memory!\n"); goto error; } /* alloc in shm for queued_msgs */ queued_msgs = (int*)shm_malloc(sizeof(int)); if (!queued_msgs) { LM_ERR("cannot get shm memory!\n"); goto error; } *queued_msgs = 0; /* register nr_of_modems number of child processes that will * update their local configuration */ cfg_register_child(nr_of_modems); return 1; error: return -1; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; #ifdef HAVE_IHTTP load_ih_f load_ih; #endif int i; DBG("XJAB:mod_init: initializing ...\n"); if(!jdomain) { LOG(L_ERR, "XJAB:mod_init: ERROR jdomain is NULL\n"); return -1; } /* import mysql functions */ if (bind_dbmod()) { LOG(L_ERR, "XJAB:mod_init: error - database module not found\n"); return -1; } db_con = (db_con_t**)shm_malloc(nrw*sizeof(db_con_t*)); if (db_con == NULL) { LOG(L_ERR, "XJAB:mod_init: Error while allocating db_con's\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: xjab:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; #ifdef HAVE_IHTTP /* import the iHTTP auto-loading function */ if ( !(load_ih=(load_ih_f)find_export("load_ih", IH_NO_SCRIPT_F, 0))) { LOG(L_ERR, "ERROR:xjab:mod_init: can't import load_ih\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_ih( &ihb )==-1) return -1; #endif pipes = (int**)pkg_malloc(nrw*sizeof(int*)); if (pipes == NULL) { LOG(L_ERR, "XJAB:mod_init:Error while allocating pipes\n"); return -1; } for(i=0; i<nrw; i++) { pipes[i] = (int*)pkg_malloc(2*sizeof(int)); if (!pipes[i]) { LOG(L_ERR, "XJAB:mod_init: Error while allocating pipes\n"); return -1; } } for(i=0; i<nrw; i++) { db_con[i] = db_init(db_url); if (!db_con[i]) { LOG(L_ERR, "XJAB:mod_init: Error while connecting database\n"); return -1; } else { db_use_table(db_con[i], db_table); DBG("XJAB:mod_init: Database connection opened successfuly\n"); } } /** creating the pipees */ for(i=0;i<nrw;i++) { /* create the pipe*/ if (pipe(pipes[i])==-1) { LOG(L_ERR, "XJAB:mod_init: error - cannot create pipe!\n"); return -1; } DBG("XJAB:mod_init: pipe[%d] = <%d>-<%d>\n", i, pipes[i][0], pipes[i][1]); } if((jwl = xj_wlist_init(pipes,nrw,max_jobs,cache_time,sleep_time, delay_time)) == NULL) { LOG(L_ERR, "XJAB:mod_init: error initializing workers list\n"); return -1; } if(xj_wlist_set_aliases(jwl, jaliases, jdomain, proxy) < 0) { LOG(L_ERR, "XJAB:mod_init: error setting aliases and outbound proxy\n"); return -1; } DBG("XJAB:mod_init: initialized ...\n"); return 0; }
static int mod_init(void) { DICT_VENDOR *vend; load_tm_f load_tm; /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:acc:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; if (verify_fmt(log_fmt)==-1) return -1; /* register callbacks*/ /* listen for all incoming requests */ if (tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, on_req, 0, 0) <= 0) { LOG(L_ERR,"ERROR:acc:mod_init: cannot register TMCB_REQUEST_IN " "callback\n"); return -1; } memset(attrs, 0, sizeof(attrs)); memset(vals, 0, sizeof(vals)); attrs[A_USER_NAME].n = "User-Name"; attrs[A_SERVICE_TYPE].n = "Service-Type"; attrs[A_CALLED_STATION_ID].n = "Called-Station-Id"; attrs[A_CALLING_STATION_ID].n = "Calling-Station-Id"; attrs[A_ACCT_STATUS_TYPE].n = "Acct-Status-Type"; attrs[A_ACCT_SESSION_ID].n = "Acct-Session-Id"; attrs[A_SIP_METHOD].n = "Sip-Method"; attrs[A_SIP_RESPONSE_CODE].n = "Sip-Response-Code"; attrs[A_SIP_CSEQ].n = "Sip-CSeq"; attrs[A_SIP_TO_TAG].n = "Sip-To-Tag"; attrs[A_SIP_FROM_TAG].n = "Sip-From-Tag"; attrs[A_SIP_TRANSLATED_REQUEST_ID].n = "Sip-Translated-Request-Id"; attrs[A_SIP_SOURCE_IP_ADDRESS].n = "Sip-Source-IP-Address"; attrs[A_SIP_SOURCE_PORT].n = "Sip-Source-Port"; attrs[A_SER_ATTR].n = "SER-Attr"; attrs[A_SER_FROM].n = "SER-From"; attrs[A_SER_FLAGS].n = "SER-Flags"; attrs[A_SER_ORIGINAL_REQUEST_ID].n = "SER-Original-Request-Id"; attrs[A_SER_TO].n = "SER-To"; attrs[A_SER_DIGEST_USERNAME].n = "SER-Digest-Username"; attrs[A_SER_DIGEST_REALM].n = "SER-Digest-Realm"; attrs[A_SER_REQUEST_TIMESTAMP].n = "SER-Request-Timestamp"; attrs[A_SER_TO_DID].n = "SER-To-DID"; attrs[A_SER_FROM_UID].n = "SER-From-UID"; attrs[A_SER_FROM_DID].n = "SER-From-DID"; attrs[A_SER_TO_UID].n = "SER-To-UID"; attrs[A_SER_RESPONSE_TIMESTAMP].n = "SER-Response-Timestamp"; attrs[A_SER_SERVER_ID].n = "SER-Server-ID"; vals[V_START].n = "Start"; vals[V_STOP].n = "Stop"; vals[V_INTERIM_UPDATE].n = "Interim-Update"; vals[V_FAILED].n = "Failed"; vals[V_SIP_SESSION].n = "Sip-Session"; /* open log */ rc_openlog("ser"); /* read config */ if ((rh = rc_read_config(radius_config)) == NULL) { LOG(L_ERR, "ERROR:acc:mod_init: Error opening radius config file: %s\n", radius_config); return -1; } /* read dictionary */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) { LOG(L_ERR, "ERROR:acc:mod_init: Error reading radius dictionary\n"); return -1; } vend = rc_dict_findvend(rh, "iptelorg"); if (vend == NULL) { ERR("RADIUS dictionary is missing required vendor 'iptelorg'\n"); return -1; } INIT_AV(rh, attrs, vals, "acc", -1, -1); if (service_type != -1) { vals[V_SIP_SESSION].v = service_type; } if (parse_attrs(&avps, &avps_n, attrs_param) < 0) { ERR("Error while parsing 'attrs' module parameter\n"); return -1; } return 0; }
static int icscf_mod_init(void) { load_tm_f load_tm; load_cdp_f load_cdp; LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n"); /* fix the parameters */ if (!fix_parameters()) goto error; #ifdef WITH_IMS_PM ims_pm_init(icscf_name_str,ims_pm_node_type, ims_pm_logfile); ims_pm_init_icscf(); #endif /* WITH_IMS_PM */ cscf_icid_value_count = shm_malloc(sizeof(unsigned int)); *cscf_icid_value_count = 0; cscf_icid_value_count_lock = lock_alloc(); cscf_icid_value_count_lock = lock_init(cscf_icid_value_count_lock); /* load the send_reply function from sl module */ sl_reply = find_export("sl_send_reply", 2, 0); if (!sl_reply) { LOG(L_ERR, "ERR"M_NAME":mod_init: This module requires sl module\n"); goto error; } /* bind to the tm module */ if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; /* bind to the cdp module */ if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) { LOG(L_ERR, "ERR"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module\n"); goto error; } if (load_cdp(&cdpb) == -1) goto error; /* cache the trusted domain names and capabilities */ /* bind to the db module */ if ( icscf_db_bind( icscf_db_url ) < 0 ) goto error; icscf_db_init( icscf_db_url, icscf_db_nds_table, icscf_db_scscf_table, icscf_db_capabilities_table); I_NDS_get_trusted_domains(); I_get_capabilities(); icscf_db_close(); if (!i_hash_table_init(icscf_hash_size)){ LOG(L_ERR, "ERR"M_NAME":mod_init: Error initializing the Hash Table for stored S-CSCF lists\n"); goto error; } // //TODO - only for S-CSCF - I-CSCF does not respond to request //// AAAAddRequestHandler(&CxRequestHandler,0); // /* don't register response callback as we always set callback per transactions // * and we're not interested in other responses */ // /*AAAAddResponseHandler(&CxAnswerHandler,0);*/ // /** initialize twofish variables and tables (THIG)**/ srand((unsigned) time(NULL)); thig_key_and_cipher_init(&ki,&ci); LOG(L_INFO,"Twofish encryption ready\n"); int route_no; /* try to fix the icscf_route_on_term_user_unknown route */ if (icscf_route_on_term_user_unknown){ route_no=route_get(&main_rt, icscf_route_on_term_user_unknown); if (route_no==-1){ LOG(L_ERR, "ERR"M_NAME":mod_init: failed to fix route \"%s\": route_get() failed\n", icscf_route_on_term_user_unknown); return -1; } if (main_rt.rlist[route_no]==0){ LOG(L_ERR, "ERR"M_NAME":mod_init: icscf_route_on_term_user_unknown \"%s\" is empty / doesn't exist\n", icscf_route_on_term_user_unknown); } route_on_term_user_unknown_n=route_no; } return 0; error: return -1; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; bind_pua_t bind_pua; bind_xmpp_t bind_xmpp; bind_libxml_t bind_libxml; libxml_api_t libxml_api; /* check if compulsory parameter server_address is set */ if(server_address.s== NULL) { LM_ERR("compulsory 'server_address' parameter not set!"); return -1; } server_address.len= strlen(server_address.s); if(presence_server.s) presence_server.len = strlen(presence_server.s); /* import the TM auto-loading function */ if((load_tm=(load_tm_f)find_export("load_tm", 0, 0))==NULL) { LM_ERR("can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if(load_tm(&tmb)==-1) { LM_ERR("can't load tm functions\n"); return -1; } /* bind libxml wrapper functions */ if((bind_libxml= (bind_libxml_t)find_export("bind_libxml_api", 1, 0))== NULL) { LM_ERR("can't import bind_libxml_api\n"); return -1; } if(bind_libxml(&libxml_api)< 0) { LM_ERR("can not bind libxml api\n"); return -1; } XMLNodeGetAttrContentByName= libxml_api.xmlNodeGetAttrContentByName; XMLDocGetNodeByName= libxml_api.xmlDocGetNodeByName; XMLNodeGetNodeByName= libxml_api.xmlNodeGetNodeByName; XMLNodeGetNodeContentByName= libxml_api.xmlNodeGetNodeContentByName; if(XMLNodeGetAttrContentByName== NULL || XMLDocGetNodeByName== NULL || XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL) { LM_ERR("libxml wrapper functions could not be bound\n"); return -1; } /* bind xmpp */ bind_xmpp= (bind_xmpp_t)find_export("bind_xmpp", 0,0); if (!bind_xmpp) { LM_ERR("Can't bind xmpp\n"); return -1; } if(bind_xmpp(&xmpp_api)< 0) { LM_ERR("Can't bind xmpp\n"); return -1; } if(xmpp_api.xsubscribe== NULL) { LM_ERR("Could not import xsubscribe from xmpp\n"); return -1; } xmpp_subscribe= xmpp_api.xsubscribe; if(xmpp_api.xnotify== NULL) { LM_ERR("Could not import xnotify from xmpp\n"); return -1; } xmpp_notify= xmpp_api.xnotify; if(xmpp_api.xpacket== NULL) { LM_ERR("Could not import xnotify from xmpp\n"); return -1; } xmpp_packet= xmpp_api.xpacket; xmpp_uri_xmpp2sip = xmpp_api.uri_xmpp2sip; xmpp_uri_sip2xmpp = xmpp_api.uri_sip2xmpp; if(xmpp_api.register_callback== NULL) { LM_ERR("Could not import register_callback" " to xmpp\n"); return -1; } if(xmpp_api.register_callback(XMPP_RCV_PRESENCE, pres_Xmpp2Sip, NULL)< 0) { LM_ERR("ERROR while registering callback" " to xmpp\n"); return -1; } /* bind pua */ bind_pua= (bind_pua_t)find_export("bind_pua", 1,0); if (!bind_pua) { LM_ERR("Can't bind pua\n"); return -1; } if (bind_pua(&pua) < 0) { LM_ERR("Can't bind pua\n"); return -1; } if(pua.send_publish == NULL) { LM_ERR("Could not import send_publish\n"); return -1; } pua_send_publish= pua.send_publish; if(pua.send_subscribe == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_send_subscribe= pua.send_subscribe; if(pua.is_dialog == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_is_dialog= pua.is_dialog; if(pua.register_puacb(XMPP_INITIAL_SUBS, Sipreply2Xmpp, NULL)< 0) { LM_ERR("Could not register callback\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; LM_DBG("...\n"); if(min_expires< 0) min_expires= 0; if(default_expires< 600) default_expires= 3600; /* import the TM auto-loading function */ if((load_tm=(load_tm_f)find_export("load_tm", 0, 0))==NULL) { LM_ERR("can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if(load_tm(&tmb)==-1) { LM_ERR("can't load tm functions\n"); return -1; } init_db_url( db_url , 0 /*cannot be null*/); db_table.len = strlen(db_table.s); /* binding to database module */ if (db_bind_mod(&db_url, &pua_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(pua_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions needed" " by the module\n"); return -1; } pua_db = pua_dbf.init(&db_url); if (!pua_db) { LM_ERR("while connecting database\n"); return -1; } /* verify table version */ if(db_check_table_version(&pua_dbf, pua_db, &db_table, PUA_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } if(HASH_SIZE<=1) HASH_SIZE= 512; else HASH_SIZE = 1<<HASH_SIZE; HashT= new_htable(); if(HashT== NULL) { LM_ERR("while creating new hash table\n"); return -1; } if(db_restore()< 0) { LM_ERR("while restoring hash_table\n"); return -1; } if(update_period<=0) { LM_ERR("wrong clean_period\n"); return -1; } if ( init_puacb_list() < 0) { LM_ERR("callbacks initialization failed\n"); return -1; } pua_evlist= init_pua_evlist(); if(pua_evlist==0) { LM_ERR("when initializing pua_evlist\n"); return -1; } if(pua_add_events()< 0) { LM_ERR("while adding events\n"); return -1; } register_timer("pua_clean", hashT_clean, 0, update_period-5, TIMER_FLAG_DELAY_ON_DELAY); register_timer("pua_dbupdate", db_update, 0, update_period, TIMER_FLAG_SKIP_ON_DELAY); if(pua_db) pua_dbf.close(pua_db); pua_db = NULL; return 0; }
/** * Initializes the module. */ static int mod_init(void) { load_tm_f load_tm; load_cdp_f load_cdp; cdp_avp_get_bind_f load_cdp_avp; LOG(L_INFO,"INFO:"M_NAME":mod_init: Initialization of module\n"); shutdown_singleton=shm_malloc(sizeof(int)); *shutdown_singleton=0; /* fix the parameters */ if (!fix_parameters()) goto error; /* load the send_reply function from sl module */ sl_reply = find_export("sl_send_reply", 2, 0); if (!sl_reply) { LOG(L_ERR, "ERR"M_NAME":mod_init: This module requires sl module\n"); goto error; } /* bind to the tm module */ if (!(load_tm = (load_tm_f)find_export("load_tm",NO_SCRIPT,0))) { LOG(L_ERR, "ERR:"M_NAME":mod_init: Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; if (!(load_cdp = (load_cdp_f)find_export("load_cdp",NO_SCRIPT,0))) { LOG(L_ERR, "DBG:"M_NAME":mod_init: Can not import load_cdp. This module requires cdp module.\n"); goto error; } if (!(load_cdp_avp = (cdp_avp_get_bind_f)find_export("cdp_avp_get_bind",NO_SCRIPT,0))) { LOG(L_ERR, "DBG:"M_NAME":mod_init: loading cdp_avp module unsuccessful. exiting\n"); goto error; } cavpb = load_cdp_avp(); if (!cavpb) goto error; if (!init_acct_records()){ LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local accounting records\n"); goto error; } if(!init_an_charg_info()){ LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local user charging info\n"); goto error; } if(!init_ims_charg_info()){ LOG(L_ERR, "DBG:"M_NAME":mod_init: failed to initiate local user charging info\n"); goto error; } return 0; error: return -1; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; #ifdef HAVE_IHTTP load_ih_f load_ih; #endif int i; DBG("XJAB:mod_init: initializing ...\n"); if(!jdomain) { LOG(L_ERR, "XJAB:mod_init: ERROR jdomain is NULL\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: xjab:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; #ifdef HAVE_IHTTP /* import the iHTTP auto-loading function */ if ( !(load_ih=(load_ih_f)find_export("load_ih", IH_NO_SCRIPT_F, 0))) { LOG(L_ERR, "ERROR:xjab:mod_init: can't import load_ih\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_ih( &ihb )==-1) return -1; #endif pipes = (int**)pkg_malloc(nrw*sizeof(int*)); if (pipes == NULL) { LOG(L_ERR, "XJAB:mod_init:Error while allocating pipes\n"); return -1; } for(i=0; i<nrw; i++) { pipes[i] = (int*)pkg_malloc(2*sizeof(int)); if (!pipes[i]) { LOG(L_ERR, "XJAB:mod_init: Error while allocating pipes\n"); return -1; } } /** creating the pipes */ for(i=0;i<nrw;i++) { /* create the pipe*/ if (pipe(pipes[i])==-1) { LOG(L_ERR, "XJAB:mod_init: error - cannot create pipe!\n"); return -1; } DBG("XJAB:mod_init: pipe[%d] = <%d>-<%d>\n", i, pipes[i][0], pipes[i][1]); } if((jwl = xj_wlist_init(pipes,nrw,max_jobs,cache_time,sleep_time, delay_time)) == NULL) { LOG(L_ERR, "XJAB:mod_init: error initializing workers list\n"); return -1; } if(xj_wlist_set_aliases(jwl, jaliases, jdomain, proxy) < 0) { LOG(L_ERR, "XJAB:mod_init: error setting aliases and outbound proxy\n"); return -1; } /* register nrw + 1 number of children that will keep * updating their local configuration */ cfg_register_child(nrw + 1); DBG("XJAB:mod_init: initialized ...\n"); return 0; }
static int mod_init(void) { int n; load_dlg_f load_dlg; load_tm_f load_tm; bind_usrloc_t bind_usrloc; if (!fix_parameters()) { LM_ERR("unable to set Ro configuration parameters correctly\n"); goto error; } /* bind to the tm module */ if (!(load_tm = (load_tm_f) find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("Can not import load_tm. This module requires tm module\n"); goto error; } if (load_tm(&tmb) == -1) goto error; if (!(load_dlg = (load_dlg_f) find_export("load_dlg", 0, 0))) { /* bind to dialog module */ LM_ERR("can not import load_dlg. This module requires Kamailio dialog module.\n"); } if (load_dlg(&dlgb) == -1) { goto error; } if (load_cdp_api(&cdpb) != 0) { /* load the CDP API */ LM_ERR("can't load CDP API\n"); goto error; } if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */ LM_ERR("can't load Dialog API\n"); goto error; } cdp_avp = load_cdp_avp(); /* load CDP_AVP API */ if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); goto error; } /* init timer lists*/ if (init_ro_timer(ro_session_ontimeout) != 0) { LM_ERR("cannot init timer list\n"); return -1; } /* initialized the hash table */ for (n = 0; n < (8 * sizeof(n)); n++) { if (ro_session_hash_size == (1 << n)) break; if (ro_session_hash_size < (1 << n)) { LM_WARN("hash_size is not a power of 2 as it should be -> rounding from %d to %d\n", ro_session_hash_size, 1 << (n - 1)); ro_session_hash_size = 1 << (n - 1); } } if (init_ro_session_table(ro_session_hash_size) < 0) { LM_ERR("failed to create ro session hash table\n"); return -1; } /* register global timer */ if (register_timer(ro_timer_routine, 0/*(void*)ro_session_list*/, 1) < 0) { LM_ERR("failed to register timer \n"); return -1; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } /* register statistics */ if (register_module_stats(exports.name, charging_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } /*if (register_stat(MOD_NAME, "ccr_responses_time", &ccr_responses_time, 0)) { LM_ERR("failed to register core statistics\n"); return -1; }*/ /* if a database should be used to store the dialogs' information */ ro_db_mode = ro_db_mode_param; if (ro_db_mode == DB_MODE_NONE) { db_url.s = 0; db_url.len = 0; } else { if (ro_db_mode != DB_MODE_REALTIME && ro_db_mode != DB_MODE_SHUTDOWN) { LM_ERR("unsupported db_mode %d\n", ro_db_mode); return -1; } if (!db_url.s || db_url.len == 0) { LM_ERR("db_url not configured for db_mode %d\n", ro_db_mode); return -1; } if (init_ro_db(&db_url, ro_session_hash_size, db_update_period, db_fetch_rows) != 0) { LM_ERR("failed to initialize the DB support\n"); return -1; } // run_load_callbacks(); } return 0; error: LM_ERR("Failed to initialise ims_qos module\n"); return RO_RETURN_FALSE; }
/** * init module function */ static int mod_init(void) { pv_spec_t avp_spec; LM_DBG("initializing ...\n"); /* Load stuff from DB */ init_db_url( ds_db_url , 0 /*cannot be null*/); ds_table_name.len = strlen(ds_table_name.s); ds_set_id_col.len = strlen(ds_set_id_col.s); ds_dest_uri_col.len = strlen(ds_dest_uri_col.s); ds_dest_sock_col.len = strlen(ds_dest_sock_col.s); ds_dest_state_col.len = strlen(ds_dest_state_col.s); ds_dest_weight_col.len = strlen(ds_dest_weight_col.s); ds_dest_attrs_col.len = strlen(ds_dest_attrs_col.s); /* handle AVPs spec */ dst_avp_param.len = strlen(dst_avp_param.s); if (pv_parse_spec(&dst_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", dst_avp_param.len, dst_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &dst_avp_name,&dst_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", dst_avp_param.len, dst_avp_param.s); return -1; } grp_avp_param.len=strlen(grp_avp_param.s); if (pv_parse_spec(&grp_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", grp_avp_param.len, grp_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &grp_avp_name,&grp_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", grp_avp_param.len, grp_avp_param.s); return -1; } cnt_avp_param.len=strlen(cnt_avp_param.s); if (pv_parse_spec(&cnt_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", cnt_avp_param.len, cnt_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &cnt_avp_name,&cnt_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", cnt_avp_param.len, cnt_avp_param.s); return -1; } sock_avp_param.len=strlen(sock_avp_param.s); if (pv_parse_spec(&sock_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", sock_avp_param.len, sock_avp_param.s); return -1; } if(pv_get_avp_name(0, &(avp_spec.pvp), &sock_avp_name,&sock_avp_type)!=0){ LM_ERR("[%.*s]- invalid AVP definition\n", sock_avp_param.len, sock_avp_param.s); return -1; } if (attrs_avp_param.s && (attrs_avp_param.len=strlen(attrs_avp_param.s)) > 0) { if (pv_parse_spec(&attrs_avp_param, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", attrs_avp_param.len, attrs_avp_param.s); return -1; } if (pv_get_avp_name(0, &(avp_spec.pvp), &attrs_avp_name, &attrs_avp_type)!=0){ LM_ERR("[%.*s]- invalid AVP definition\n", attrs_avp_param.len, attrs_avp_param.s); return -1; } } else { attrs_avp_name = -1; attrs_avp_type = 0; } if (hash_pvar_param.s && (hash_pvar_param.len=strlen(hash_pvar_param.s))>0 ) { if(pv_parse_format(&hash_pvar_param, &hash_param_model) < 0 || hash_param_model==NULL) { LM_ERR("malformed PV string: %s\n", hash_pvar_param.s); return -1; } } else { hash_param_model = NULL; } if (ds_setid_pvname.s && (ds_setid_pvname.len=strlen(ds_setid_pvname.s))>0 ) { if(pv_parse_spec(&ds_setid_pvname, &ds_setid_pv)==NULL || !pv_is_w(&ds_setid_pv)) { LM_ERR("[%s]- invalid setid_pvname\n", ds_setid_pvname.s); return -1; } } pvar_algo_param.len = strlen(pvar_algo_param.s); if (pvar_algo_param.len) ds_pvar_parse_pattern(pvar_algo_param); if (init_ds_bls()!=0) { LM_ERR("failed to init DS blacklists\n"); return E_CFG; } if (init_ds_data()!=0) { LM_ERR("failed to init DS data holder\n"); return -1; } /* open DB connection to load provisioning data */ if (init_ds_db()!= 0) { LM_ERR("failed to init database support\n"); return -1; } /* do the actula data load */ if (ds_reload_db()!=0) { LM_ERR("failed to load data from DB\n"); return -1; } /* close DB connection */ ds_disconnect_db(); /* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */ if (ds_ping_interval > 0) { load_tm_f load_tm; str host; int port,proto; if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s); if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s); /* parse the list of reply codes to be counted as success */ if(options_reply_codes_str.s) { options_reply_codes_str.len = strlen(options_reply_codes_str.s); if(parse_reply_codes( &options_reply_codes_str, &options_reply_codes, &options_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } /* parse and look for the socket to ping from */ if (probing_sock_s && probing_sock_s[0]!=0 ) { if (parse_phostport( probing_sock_s, strlen(probing_sock_s), &host.s, &host.len, &port, &proto)!=0 ) { LM_ERR("socket description <%s> is not valid\n", probing_sock_s); return -1; } probing_sock = grep_sock_info( &host, port, proto); if (probing_sock==NULL) { LM_ERR("socket <%s> is not local to opensips (we must listen " "on it\n", probing_sock_s); return -1; } } /* TM-Bindings */ load_tm=(load_tm_f)find_export("load_tm", 0, 0); if (load_tm==NULL) { LM_ERR("failed to bind to the TM-Module - required for probing\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb ) == -1) { LM_ERR("could not load the TM-functions - disable DS ping\n"); return -1; } /* Register the PING-Timer */ if (register_timer("ds-pinger",ds_check_timer,NULL,ds_ping_interval)<0){ LM_ERR("failed to register timer for probing!\n"); return -1; } } /* register timer to flush the state of destination back to DB */ if (register_timer("ds-flusher",ds_flusher_routine,NULL, 30)<0){ LM_ERR("failed to register timer for DB flushing!\n"); return -1; } dispatch_evi_id = evi_publish_event(dispatcher_event); if (dispatch_evi_id == EVI_ERROR) LM_ERR("cannot register dispatcher event\n"); return 0; }
static int cpl_init(void) { bind_usrloc_t bind_usrloc; load_tm_f load_tm; struct stat stat_t; char *ptr; int val; str foo; LOG(L_INFO,"CPL - initializing\n"); /* check the module params */ if (DB_URL==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_db\" " "found empty\n"); goto error; } if (DB_TABLE==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_table\" " "found empty\n"); goto error; } if (cpl_env.proxy_recurse>MAX_PROXY_RECURSE) { LOG(L_CRIT,"ERROR:cpl_init: value of proxy_recurse param (%d) exceeds " "the maximum safety value (%d)\n", cpl_env.proxy_recurse,MAX_PROXY_RECURSE); goto error; } /* fix the timer_avp name */ if (timer_avp) { foo.s = timer_avp; foo.len = strlen(foo.s); if (parse_avp_spec(&foo,&cpl_env.timer_avp_type,&cpl_env.timer_avp,0)<0){ LOG(L_CRIT,"ERROR:cpl_init: invalid timer AVP specs \"%s\"\n", timer_avp); goto error; } if (cpl_env.timer_avp_type&AVP_NAME_STR && cpl_env.timer_avp.s.s==foo.s) { cpl_env.timer_avp.s = foo; } } if (dtd_file==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_dtd_file\" " "found empty\n"); goto error; } else { /* check if the dtd file exists */ if (stat( dtd_file, &stat_t)==-1) { LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" status failed;" " stat returned %s\n",dtd_file,strerror(errno)); goto error; } if ( !S_ISREG( stat_t.st_mode ) ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a regular file!\n", dtd_file); goto error; } if (access( dtd_file, R_OK )==-1) { LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" for permissions " "failed; access returned %s\n",dtd_file,strerror(errno)); goto error; } } if (cpl_env.log_dir==0) { LOG(L_INFO,"INFO:cpl_init: log_dir param found void -> logging " " disabled!\n"); } else { if ( strlen(cpl_env.log_dir)>MAX_LOG_DIR_SIZE ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" has a too long name :-(!\n", cpl_env.log_dir); goto error; } /* check if the dir exists */ if (stat( cpl_env.log_dir, &stat_t)==-1) { LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" status failed;" " stat returned %s\n",cpl_env.log_dir,strerror(errno)); goto error; } if ( !S_ISDIR( stat_t.st_mode ) ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a directory!\n", cpl_env.log_dir); goto error; } if (access( cpl_env.log_dir, R_OK|W_OK )==-1) { LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" for permissions " "failed; access returned %s\n", cpl_env.log_dir, strerror(errno)); goto error; } } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm( &(cpl_fct.tmb) )==-1) goto error; /* bind the SL API */ if (sl_load_api(&cpl_fct.slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* bind to usrloc module if requested */ if (lookup_domain) { /* import all usrloc functions */ bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: Can't bind usrloc\n"); goto error; } if (bind_usrloc( &(cpl_fct.ulb) ) < 0) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: importing usrloc failed\n"); goto error; } /* convert lookup_domain from char* to udomain_t* pointer */ if (cpl_fct.ulb.register_udomain( lookup_domain, &cpl_env.lu_domain) < 0) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: Error while registering domain " "<%s>\n",lookup_domain); goto error; } } else { LOG(L_NOTICE,"NOTICE:cpl_init: no lookup_domain given -> disable " " lookup node\n"); } /* build a pipe for sending commands to aux process */ if ( pipe( cpl_env.cmd_pipe )==-1 ) { LOG(L_CRIT,"ERROR:cpl_init: cannot create command pipe: %s!\n", strerror(errno) ); goto error; } /* set the writing non blocking */ if ( (val=fcntl(cpl_env.cmd_pipe[1], F_GETFL, 0))<0 ) { LOG(L_ERR,"ERROR:cpl_init: getting flags from pipe[1] failed: fcntl " "said %s!\n",strerror(errno)); goto error; } if ( fcntl(cpl_env.cmd_pipe[1], F_SETFL, val|O_NONBLOCK) ) { LOG(L_ERR,"ERROR:cpl_init: setting flags to pipe[1] failed: fcntl " "said %s!\n",strerror(errno)); goto error; } /* init the CPL parser */ if (init_CPL_parser( dtd_file )!=1 ) { LOG(L_ERR,"ERROR:cpl_init: init_CPL_parser failed!\n"); goto error; } /* make a copy of the original TZ env. variable */ ptr = getenv("TZ"); cpl_env.orig_tz.len = 3/*"TZ="*/ + (ptr?(strlen(ptr)+1):0); if ( (cpl_env.orig_tz.s=shm_malloc( cpl_env.orig_tz.len ))==0 ) { LOG(L_ERR,"ERROR:cpl_init: no more shm mem. for saving TZ!\n"); goto error; } memcpy(cpl_env.orig_tz.s,"TZ=",3); if (ptr) strcpy(cpl_env.orig_tz.s+3,ptr); /* convert realm_prefix from string null terminated to str */ if (cpl_env.realm_prefix.s) { /* convert the realm_prefix to lower cases */ strlower( &cpl_env.realm_prefix ); } /* Register a child process that will keep updating * its local configuration */ cfg_register_child(1); return 0; error: return -1; }
/** * init module function */ static int mod_init(void) { LM_DBG("initializing ...\n"); if (check_if_default_head_is_ok()) { default_db_head.next = ds_db_heads; ds_db_heads = &default_db_head; } set_default_head_values(&default_db_head); ds_set_id_col.len = strlen(ds_set_id_col.s); ds_dest_uri_col.len = strlen(ds_dest_uri_col.s); ds_dest_sock_col.len = strlen(ds_dest_sock_col.s); ds_dest_state_col.len = strlen(ds_dest_state_col.s); ds_dest_weight_col.len = strlen(ds_dest_weight_col.s); ds_dest_attrs_col.len = strlen(ds_dest_attrs_col.s); if(hash_pvar_param.s && (hash_pvar_param.len=strlen(hash_pvar_param.s))>0){ if(pv_parse_format(&hash_pvar_param, &hash_param_model) < 0 || hash_param_model==NULL) { LM_ERR("malformed PV string: %s\n", hash_pvar_param.s); return -1; } } else { hash_param_model = NULL; } if(ds_setid_pvname.s && (ds_setid_pvname.len=strlen(ds_setid_pvname.s))>0){ if(pv_parse_spec(&ds_setid_pvname, &ds_setid_pv)==NULL || !pv_is_w(&ds_setid_pv)) { LM_ERR("[%s]- invalid setid_pvname\n", ds_setid_pvname.s); return -1; } } pvar_algo_param.len = strlen(pvar_algo_param.s); if (pvar_algo_param.len) ds_pvar_parse_pattern(pvar_algo_param); if (init_ds_bls()!=0) { LM_ERR("failed to init DS blacklists\n"); return E_CFG; } /* Creating partitions from head */ ds_db_head_t *head_it = ds_db_heads; while (head_it){ if (inherit_from_default_head(head_it) != 0) return -1; ds_partition_t *partition = shm_malloc (sizeof(ds_partition_t)); if (partition_init(head_it, partition) != 0) return -1; partition->next = partitions; partitions = partition; if (init_ds_data(partition)!=0) { LM_ERR("failed to init DS data holder\n"); return -1; } /* open DB connection to load provisioning data */ if (init_ds_db(partition)!= 0) { LM_ERR("failed to init database support\n"); return -1; } /* do the actual data load */ if (ds_reload_db(partition)!=0) { LM_ERR("failed to load data from DB\n"); return -1; } /* close DB connection */ ds_disconnect_db(partition); ds_db_head_t *aux = head_it; /* We keep track of corespondig default parition */ if (head_it == &default_db_head) default_partition = partition; head_it = head_it->next; if (aux != &default_db_head) pkg_free(aux); } /* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */ if (ds_ping_interval > 0) { load_tm_f load_tm; str host; int port,proto; if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s); if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s); /* parse the list of reply codes to be counted as success */ if(options_reply_codes_str.s) { options_reply_codes_str.len = strlen(options_reply_codes_str.s); if(parse_reply_codes(&options_reply_codes_str,&options_reply_codes, &options_codes_no )< 0) { LM_ERR("Bad format for options_reply_code parameter" " - Need a code list separated by commas\n"); return -1; } } /* parse and look for the socket to ping from */ if (probing_sock_s && probing_sock_s[0]!=0 ) { if (parse_phostport( probing_sock_s, strlen(probing_sock_s), &host.s, &host.len, &port, &proto)!=0 ) { LM_ERR("socket description <%s> is not valid\n", probing_sock_s); return -1; } probing_sock = grep_sock_info( &host, port, proto); if (probing_sock==NULL) { LM_ERR("socket <%s> is not local to opensips (we must listen " "on it\n", probing_sock_s); return -1; } } /* TM-Bindings */ load_tm=(load_tm_f)find_export("load_tm", 0, 0); if (load_tm==NULL) { LM_ERR("failed to bind to the TM-Module - required for probing\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb ) == -1) { LM_ERR("could not load the TM-functions - disable DS ping\n"); return -1; } /* Register the PING-Timer */ if (register_timer("ds-pinger", ds_check_timer, NULL, ds_ping_interval, TIMER_FLAG_DELAY_ON_DELAY)<0) { LM_ERR("failed to register timer for probing!\n"); return -1; } } /* register timer to flush the state of destination back to DB */ if (ds_persistent_state && register_timer("ds-flusher", ds_flusher_routine, NULL, 30 , TIMER_FLAG_SKIP_ON_DELAY)<0) { LM_ERR("failed to register timer for DB flushing!\n"); return -1; } dispatch_evi_id = evi_publish_event(dispatcher_event); if (dispatch_evi_id == EVI_ERROR) LM_ERR("cannot register dispatcher event\n"); return 0; }
int rls_mod_init(void) { load_tm_f load_tm; bind_dlg_mod_f bind_dlg; struct timer_ln *i_timer = NULL; DEBUG_LOG("RLS module initialization\n"); /* ??? if other module uses this libraries it might be a problem ??? */ xmlInitParser(); DEBUG_LOG(" ... common libraries\n"); qsa_initialize(); if (time_event_management_init() != 0) { LOG(L_ERR, "rls_mod_init(): Can't initialize time event management!\n"); return -1; } if (subscription_management_init() != 0) { LOG(L_ERR, "rls_mod_init(): Can't initialize time event management!\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "rls_mod_init(): Can't import tm!\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm(&tmb)==-1) { LOG(L_ERR, "rls_mod_init(): load_tm() failed\n"); return -1; } bind_dlg = (bind_dlg_mod_f)find_export("bind_dlg_mod", -1, 0); if (!bind_dlg) { LOG(L_ERR, "Can't import dlg\n"); return -1; } if (bind_dlg(&dlg_func) != 0) { return -1; } if (rls_init() != 0) { return -1; } if (vs_init() != 0) { return -1; } /* xcap_servers = (ptr_vector_t*)mem_alloc(sizeof(ptr_vector_t)); if (!xcap_servers) { LOG(L_ERR, "rls_mod_init(): can't allocate memory for XCAP servers vector\n"); return -1; } ptr_vector_init(xcap_servers, 8); */ /* set authorization type according to requested "auth type name" * and other (type specific) parameters */ if (set_auth_params(&rls_auth_params, auth_type_str) != 0) return -1; use_db = 0; if (db_mode > 0) { int db_url_len = db_url ? strlen(db_url) : 0; if (!db_url_len) { LOG(L_ERR, "rls_mod_init(): no db_url specified but db_mode > 0\n"); db_mode = 0; } } if (db_mode > 0) { if (bind_dbmod(db_url, &rls_dbf) < 0) { LOG(L_ERR, "rls_mod_init(): Can't bind database module via url %s\n", db_url); return -1; } if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) { /* ? */ LOG(L_ERR, "rls_mod_init(): Database module does not implement all functions needed by the module\n"); return -1; } use_db = 1; } /* once-shot timer for reloading data from DB - * needed because it can trigger database operations * in other modules and they mostly intialize their * database connection in child_init functions */ i_timer = timer_alloc(); if (!i_timer) { ERR("can't allocate memory for DB init timer\n"); return -1; } else { timer_init(i_timer, init_timer_cb, i_timer, 0); timer_add(i_timer, S_TO_TICKS(init_timer_delay)); } fill_xcap_params = (fill_xcap_params_func)find_export("fill_xcap_params", 0, -1); return 0; }