/** * init module function */ static int mod_init(void) { bind_xcap_t bind_xcap; xcap_api_t xcap_api; /* load XCAP API */ bind_xcap = (bind_xcap_t)find_export("bind_xcap", 1, 0); if (!bind_xcap) { LM_ERR("Can't bind xcap\n"); return -1; } if (bind_xcap(&xcap_api) < 0) { LM_ERR("Can't bind xcap\n"); return -1; } xcap_db_url = xcap_api.db_url; xcap_db_table = xcap_api.xcap_table; /* binding to mysql module */ if (db_bind_mod(&xcap_db_url, &xcap_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(xcap_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } xcap_db = xcap_dbf.init(&xcap_db_url); if (!xcap_db) { LM_ERR("while connecting to database\n"); return -1; } curl_global_init(CURL_GLOBAL_ALL); if(periodical_query) { register_timer("xcapc-update", query_xcap_update, 0, query_period, TIMER_FLAG_DELAY_ON_DELAY); } if(xcap_db) xcap_dbf.close(xcap_db); xcap_db = NULL; return 0; }
/** * init module function */ static int mod_init(void) { bind_presence_t bind_presence; presence_api_t pres; if(passive_mode==1) return 0; if(register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); return -1; } LM_DBG("db_url=%s/%d/%p\n",ZSW(db_url.s),db_url.len, db_url.s); /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("Can't bind presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("Can't bind to presence module\n"); return -1; } pres_get_sphere= pres.get_sphere; pres_add_event= pres.add_event; pres_update_watchers= pres.update_watchers_status; pres_contains_event= pres.contains_event; pres_get_presentity= pres.get_presentity; pres_free_presentity= pres.free_presentity; if (pres_add_event == NULL || pres_update_watchers== NULL) { LM_ERR("Can't import add_event\n"); return -1; } if(xml_add_events()< 0) { LM_ERR("adding xml events\n"); return -1; } if(force_active== 0) { /* binding to mysql module */ if (db_bind_mod(&db_url, &pxml_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(pxml_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } pxml_db = pxml_dbf.init(&db_url); if (!pxml_db) { LM_ERR("while connecting to database\n"); return -1; } if(db_check_table_version(&pxml_dbf, pxml_db, &xcap_table, S_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } if(!integrated_xcap_server ) { xcap_api_t xcap_api; bind_xcap_t bind_xcap; /* bind xcap */ bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0); if (!bind_xcap) { LM_ERR("Can't bind xcap_client\n"); return -1; } if (bind_xcap(&xcap_api) < 0) { LM_ERR("Can't bind xcap_api\n"); return -1; } xcap_GetNewDoc= xcap_api.getNewDoc; if(xcap_GetNewDoc== NULL) { LM_ERR("can't import get_elem from xcap_client module\n"); return -1; } if(xcap_api.register_xcb(PRES_RULES, xcap_doc_updated)< 0) { LM_ERR("registering xcap callback function\n"); return -1; } } } if(shm_copy_xcap_list()< 0) { LM_ERR("copying xcap server list in share memory\n"); return -1; } if(pxml_db) pxml_dbf.close(pxml_db); pxml_db = NULL; return 0; }
/** * init module function */ static int mod_init(void) { bind_presence_t bind_presence; presence_api_t pres; bind_pua_t bind_pua; pua_api_t pua; bind_libxml_t bind_libxml; libxml_api_t libxml_api; bind_xcap_t bind_xcap; xcap_api_t xcap_api; char* sep; LM_DBG("start\n"); if (register_mi_mod(exports.name, mi_cmds)!=0) { LM_ERR("failed to register MI commands\n"); return -1; } if (dbmode <RLS_DB_DEFAULT || dbmode > RLS_DB_ONLY) { LM_ERR( "Invalid dbmode-set to default mode\n" ); dbmode = 0; } if(!rls_server_address.s || rls_server_address.len<=0) { LM_ERR("server_address parameter not set in configuration file\n"); return -1; } if(!rls_integrated_xcap_server && xcap_root== NULL) { LM_ERR("xcap_root parameter not set\n"); return -1; } /* extract port if any */ if(xcap_root) { sep= strchr(xcap_root, ':'); if(sep) { char* sep2= NULL; sep2= strchr(sep+ 1, ':'); if(sep2) sep= sep2; str port_str; port_str.s= sep+ 1; port_str.len= strlen(xcap_root)- (port_str.s-xcap_root); if(str2int(&port_str, &xcap_port)< 0) { LM_ERR("converting string to int [port]= %.*s\n", port_str.len, port_str.s); return -1; } if(xcap_port< 0 || xcap_port> 65535) { LM_ERR("wrong xcap server port\n"); return -1; } *sep= '\0'; } } /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* load all TM stuff */ if(load_tm_api(&tmb)==-1) { LM_ERR("can't load tm functions\n"); return -1; } bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("Can't bind presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("Can't bind presence\n"); return -1; } pres_contains_event = pres.contains_event; pres_search_event = pres.search_event; pres_get_ev_list = pres.get_event_list; if (rls_expires_offset < 0 ) { LM_ERR( "Negative expires_offset, defaulted to zero\n" ); rls_expires_offset = 0; } if (dbmode == RLS_DB_ONLY) { pres_new_shtable = rls_new_shtable; pres_destroy_shtable = rls_destroy_shtable; pres_insert_shtable = rls_insert_shtable; pres_delete_shtable = rls_delete_shtable; pres_update_shtable = rls_update_shtable; pres_search_shtable = rls_search_shtable; pres_update_db_subs_timer = rls_update_db_subs_timer; } else { pres_new_shtable = pres.new_shtable; pres_destroy_shtable = pres.destroy_shtable; pres_insert_shtable = pres.insert_shtable; pres_delete_shtable = pres.delete_shtable; pres_update_shtable = pres.update_shtable; pres_search_shtable = pres.search_shtable; pres_update_db_subs_timer = pres.update_db_subs_timer; } pres_copy_subs = pres.mem_copy_subs; pres_extract_sdialog_info= pres.extract_sdialog_info; if(!pres_contains_event || !pres_get_ev_list || !pres_new_shtable || !pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable || !pres_update_shtable || !pres_search_shtable || !pres_copy_subs || !pres_extract_sdialog_info) { LM_ERR("importing functions from presence module\n"); return -1; } LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); if(xcap_db_url.len==0) { xcap_db_url.s = db_url.s; xcap_db_url.len = db_url.len; } LM_DBG("db_url=%s/%d/%p\n", ZSW(xcap_db_url.s), xcap_db_url.len, xcap_db_url.s); if(rlpres_db_url.len==0) { rlpres_db_url.s = db_url.s; rlpres_db_url.len = db_url.len; } LM_DBG("db_url=%s/%d/%p\n", ZSW(rlpres_db_url.s), rlpres_db_url.len, rlpres_db_url.s); /* binding to mysql module */ if (db_bind_mod(&db_url, &rls_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (db_bind_mod(&rlpres_db_url, &rlpres_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (db_bind_mod(&xcap_db_url, &rls_xcap_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } if (!DB_CAPABILITY(rlpres_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } if (!DB_CAPABILITY(rls_xcap_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } rls_db = rls_dbf.init(&db_url); if (!rls_db) { LM_ERR("while connecting database\n"); return -1; } rlpres_db = rlpres_dbf.init(&rlpres_db_url); if (!rlpres_db) { LM_ERR("while connecting database\n"); return -1; } rls_xcap_db = rls_xcap_dbf.init(&xcap_db_url); if (!rls_xcap_db) { LM_ERR("while connecting database\n"); return -1; } /* verify table version */ if(db_check_table_version(&rls_dbf, rls_db, &rlsubs_table, W_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } /* verify table version */ if(db_check_table_version(&rlpres_dbf, rlpres_db, &rlpres_table, P_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } /* verify table version */ if(db_check_table_version(&rls_xcap_dbf, rls_xcap_db, &rls_xcap_table, X_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } if (dbmode != RLS_DB_ONLY) { if(hash_size<=1) hash_size= 512; else hash_size = 1<<hash_size; rls_table= pres_new_shtable(hash_size); if(rls_table== NULL) { LM_ERR("while creating new hash table\n"); return -1; } if(rls_reload_db_subs!=0) { if(rls_restore_db_subs()< 0) { LM_ERR("while restoring rl watchers table\n"); return -1; } } } if(rls_db) rls_dbf.close(rls_db); rls_db = NULL; if(rlpres_db) rlpres_dbf.close(rlpres_db); rlpres_db = NULL; if(rls_xcap_db) rls_xcap_dbf.close(rls_xcap_db); rls_xcap_db = NULL; if(waitn_time<= 0) waitn_time= 5; if(rls_notifier_poll_rate<= 0) rls_notifier_poll_rate= 10; if(rls_notifier_processes<= 0) rls_notifier_processes= 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 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("mod_init Can't bind pua\n"); return -1; } if(pua.send_subscribe == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_send_subscribe= pua.send_subscribe; if(pua.get_record_id == NULL) { LM_ERR("Could not import get_record_id\n"); return -1; } pua_get_record_id= pua.get_record_id; if(pua.get_subs_list == NULL) { LM_ERR("Could not import get_subs_list\n"); return -1; } pua_get_subs_list= pua.get_subs_list; if(!rls_integrated_xcap_server) { /* bind xcap */ bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0); if (!bind_xcap) { LM_ERR("Can't bind xcap_client\n"); return -1; } if (bind_xcap(&xcap_api) < 0) { LM_ERR("Can't bind xcap\n"); return -1; } xcap_GetNewDoc= xcap_api.getNewDoc; if(xcap_GetNewDoc== NULL) { LM_ERR("Can't import xcap_client functions\n"); return -1; } } if (rlpres_clean_period < 0) rlpres_clean_period = clean_period; if (clean_period > 0) register_timer(rlsubs_table_update, 0, clean_period); if (rlpres_clean_period > 0) register_timer(rls_presentity_clean, 0, rlpres_clean_period); if(dbmode == RLS_DB_ONLY) { if ((rls_notifier_id = shm_malloc(sizeof(int) * rls_notifier_processes)) == NULL) { LM_ERR("allocating shared memory\n"); return -1; } register_basic_timers(rls_notifier_processes); } else register_timer(timer_send_notify, 0, waitn_time); if ((rls_update_subs_lock = lock_alloc()) == NULL) { LM_ERR("Failed to alloc rls_update_subs_lock\n"); return -1; } if (lock_init(rls_update_subs_lock) == NULL) { LM_ERR("Failed to init rls_updae_subs_lock\n"); return -1; } return 0; }
/** * init module function */ static int mod_init(void) { str _s; int ver = 0; bind_presence_t bind_presence; presence_api_t pres; bind_pua_t bind_pua; pua_api_t pua; bind_libxml_t bind_libxml; libxml_api_t libxml_api; bind_xcap_t bind_xcap; xcap_api_t xcap_api; char* sep; LM_DBG("start\n"); if(server_address.s== NULL) { LM_DBG("server_address parameter not set in configuration file\n"); } if(server_address.s) server_address.len= strlen(server_address.s); else server_address.len= 0; if(xcap_root== NULL) { LM_ERR("xcap_root parameter not set\n"); return -1; } /* extract port if any */ sep= strchr(xcap_root, ':'); if(sep) { char* sep2= NULL; sep2= strchr(sep+ 1, ':'); if(sep2) sep= sep2; str port_str; port_str.s= sep+ 1; port_str.len= strlen(xcap_root)- (port_str.s-xcap_root); if(str2int(&port_str, &xcap_port)< 0) { LM_ERR("converting string to int [port]= %.*s\n",port_str.len, port_str.s); return -1; } if(xcap_port< 0 || xcap_port> 65535) { LM_ERR("wrong xcap server port\n"); return -1; } *sep= '\0'; } /* load SL API */ if(load_sl_api(&slb)==-1) { LM_ERR("can't load sl functions\n"); return -1; } /* load all TM stuff */ if(load_tm_api(&tmb)==-1) { LM_ERR("can't load tm functions\n"); return -1; } bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("Can't bind presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("Can't bind presence\n"); return -1; } pres_contains_event = pres.contains_event; pres_search_event = pres.search_event; pres_get_ev_list = pres.get_event_list; pres_new_shtable = pres.new_shtable; pres_destroy_shtable= pres.destroy_shtable; pres_insert_shtable = pres.insert_shtable; pres_delete_shtable = pres.delete_shtable; pres_update_shtable = pres.update_shtable; pres_search_shtable = pres.search_shtable; pres_copy_subs = pres.mem_copy_subs; pres_update_db_subs = pres.update_db_subs; pres_extract_sdialog_info= pres.extract_sdialog_info; if(!pres_contains_event || !pres_get_ev_list || !pres_new_shtable || !pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable || !pres_update_shtable || !pres_search_shtable || !pres_copy_subs || !pres_extract_sdialog_info) { LM_ERR("importing functions from presence module\n"); return -1; } db_url.len = db_url.s ? strlen(db_url.s) : 0; LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len, db_url.s); /* binding to mysql module */ if (bind_dbmod(db_url.s, &rls_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by the module\n"); return -1; } rls_db = rls_dbf.init(db_url.s); if (!rls_db) { LM_ERR("while connecting database\n"); return -1; } /* verify table version */ _s.s = rlsubs_table; _s.len = strlen(rlsubs_table); ver = table_version(&rls_dbf, rls_db, &_s); if(ver!=W_TABLE_VERSION) { LM_ERR("Wrong version v%d for table <%s>," " need v%d\n", ver, _s.s, W_TABLE_VERSION); return -1; } _s.s = rlpres_table; _s.len = strlen(rlpres_table); ver = table_version(&rls_dbf, rls_db, &_s); if(ver!=P_TABLE_VERSION) { LM_ERR("Wrong version v%d for table <%s>," " need v%d\n", ver, _s.s, P_TABLE_VERSION); return -1; } if(hash_size<=1) hash_size= 512; else hash_size = 1<<hash_size; rls_table= pres_new_shtable(hash_size); if(rls_table== NULL) { LM_ERR("while creating new hash table\n"); return -1; } if(rls_restore_db_subs()< 0) { LM_ERR("while restoring rl watchers table\n"); return -1; } if(rls_db) rls_dbf.close(rls_db); rls_db = NULL; if(waitn_time<= 0) waitn_time= 5; if(waitn_time<= 0) waitn_time= 100; /* 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 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("mod_init Can't bind pua\n"); return -1; } if(pua.send_subscribe == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_send_subscribe= pua.send_subscribe; if(pua.get_record_id == NULL) { LM_ERR("Could not import send_subscribe\n"); return -1; } pua_get_record_id= pua.get_record_id; if(!rls_integrated_xcap_server) { /* bind xcap */ bind_xcap= (bind_xcap_t)find_export("bind_xcap", 1, 0); if (!bind_xcap) { LM_ERR("Can't bind xcap_client\n"); return -1; } if (bind_xcap(&xcap_api) < 0) { LM_ERR("Can't bind xcap\n"); return -1; } xcap_GetNewDoc= xcap_api.getNewDoc; if(xcap_GetNewDoc== NULL) { LM_ERR("Can't import xcap_client functions\n"); return -1; } } register_timer(timer_send_notify,0, waitn_time); register_timer(rls_presentity_clean, 0, clean_period); register_timer(rlsubs_table_update, 0, clean_period); return 0; }
/** * init module function */ static int mod_init(void) { bind_presence_t bind_presence; presence_api_t pres; bind_xcap_t bind_xcap; xcap_api_t xcap_api; /* load XCAP API */ bind_xcap = (bind_xcap_t)find_export("bind_xcap", 1, 0); if (!bind_xcap) { LM_ERR("Can't bind xcap\n"); return -1; } if (bind_xcap(&xcap_api) < 0) { LM_ERR("Can't bind xcap\n"); return -1; } integrated_xcap_server = xcap_api.integrated_server; db_url = xcap_api.db_url; xcap_table = xcap_api.xcap_table; normalizeSipUri = xcap_api.normalize_sip_uri; xcapParseUri = xcap_api.parse_xcap_uri; xcapDbGetDoc = xcap_api.get_xcap_doc; if(force_active==0) { if ( verify_db() < 0 ) return -1; } /* load SL API */ if(load_sig_api(&xml_sigb)==-1) { LM_ERR("can't load signaling functions\n"); return -1; } bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("Can't bind presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("Can't bind module pua\n"); return -1; } pres_get_sphere= pres.get_sphere; pres_add_event= pres.add_event; pres_update_watchers= pres.update_watchers_status; if (pres_add_event == NULL || pres_update_watchers== NULL) { LM_ERR("Can't import add_event\n"); return -1; } if(xml_add_events()< 0) { LM_ERR("adding xml events\n"); return -1; } if(pres_rules_auid.s) { pres_rules_auid.len = strlen(pres_rules_auid.s); if (pres_rules_auid.len == IETF_PRES_RULES_AUID_LEN && strncmp(pres_rules_auid.s, IETF_PRES_RULES_AUID, IETF_PRES_RULES_AUID_LEN) == 0) { LM_INFO("using IETF mode for pres-rules\n"); pres_rules_doc_id = PRES_RULES; } if (pres_rules_auid.len == OMA_PRES_RULES_AUID_LEN && strncmp(pres_rules_auid.s, OMA_PRES_RULES_AUID, OMA_PRES_RULES_AUID_LEN) == 0) { LM_INFO("using OMA mode for pres-rules\n"); pres_rules_doc_id = OMA_PRES_RULES; } else { LM_ERR("unrecognized AUID for pres-rules: %.*s\n", pres_rules_auid.len, pres_rules_auid.s); return -1; } } if(force_active== 0 && !integrated_xcap_server ) { xcap_client_api_t xcap_client_api; bind_xcap_client_t bind_xcap_client; /* bind xcap */ bind_xcap_client = (bind_xcap_client_t)find_export("bind_xcap_client", 1, 0); if (!bind_xcap_client) { LM_ERR("Can't bind xcap_client\n"); return -1; } if (bind_xcap_client(&xcap_client_api) < 0) { LM_ERR("Can't bind xcap_client_api\n"); return -1; } xcap_GetNewDoc= xcap_client_api.getNewDoc; if(xcap_GetNewDoc== NULL) { LM_ERR("can't import getNewDoc from xcap_client module\n"); return -1; } if(xcap_client_api.register_xcb(pres_rules_doc_id, xcap_doc_updated) < 0) { LM_ERR("registering xcap callback function\n"); return -1; } if(pres_rules_filename.s) pres_rules_filename.len = strlen(pres_rules_filename.s); } if(shm_copy_xcap_list()< 0) { LM_ERR("copying xcap server list in share memory\n"); return -1; } if(pxml_db) pxml_dbf.close(pxml_db); pxml_db = NULL; return 0; }