/* * init module function */ static int mod_init(void) { presence_api_t pres; LM_INFO("initializing...\n"); bind_presence_t bind_presence; 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 pua\n"); return -1; } pres_add_event = pres.add_event; if (pres_add_event == NULL) { LM_ERR("could not import add_event\n"); return -1; } if(callinfo_add_events() < 0) { LM_ERR("failed to add call-info events\n"); return -1; } return 0; }
/* * init module function */ static int mod_init(void) { bind_presence_t bind_presence; bind_presence= (bind_presence_t)find_export("bind_presence", 1,0); if (!bind_presence) { LM_ERR("cannot find bind_presence\n"); return -1; } if (bind_presence(&pres) < 0) { LM_ERR("cannot bind to presence module\n"); return -1; } pres_add_event = pres.add_event; if (pres_add_event == NULL) { LM_ERR("could not import add_event function\n"); return -1; } if(conference_add_events() < 0) { LM_ERR("failed to add conference-info events\n"); return -1; } return 0; }
/* * init module function */ static int mod_init(void) { presence_api_t pres; bind_presence_t bind_presence; 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 pua\n"); return -1; } pres_add_event = pres.add_event; if (pres_add_event == NULL) { LM_ERR("could not import add_event\n"); return -1; } if(mwi_add_events() < 0) { LM_ERR("failed to add mwi events\n"); return -1; } return 0; }
/* * init module function */ static int mod_init(void) { bind_presence_t bind_presence; LM_INFO("initializing...\n"); /* bind to presence module */ 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 pua\n"); return -1; } if (pres.add_event == NULL) { LM_ERR("could not import add_event\n"); return -1; } if(callinfo_add_events() < 0) { LM_ERR("failed to add call-info events\n"); return -1; } if (no_dialog_support==0) { /* bind to the dialog API */ if (init_dialog_support()<0 ) { LM_ERR("failed to enable the dialog support\n"); return -1; } /* init internal hash table to keep the SCA/lines status */ if ( init_sca_hash(hash_size) < 0 ) { LM_ERR("failed to init hash table for SCA lines\n"); return -1; } } return 0; }
/*! \brief * Module initialization function */ static int mod_init(void) { int i; load_dlg_f load_dlg; if (usrloc_debug){ LM_INFO("Logging usrloc records to %.*s\n", usrloc_debug_file.len, usrloc_debug_file.s); debug_file = fopen(usrloc_debug_file.s, "a"); fprintf(debug_file, "starting\n"); fflush(debug_file); } if (rpc_register_array(ul_rpc) != 0) { LM_ERR("failed to register RPC commands\n"); return -1; } if (ul_hash_size <= 1) ul_hash_size = 512; else ul_hash_size = 1 << ul_hash_size; ul_locks_no = ul_hash_size; if (subs_hash_size <= 1) subs_hash_size = 512; else subs_hash_size = 1 << subs_hash_size; subs_locks_no = subs_hash_size; if (contacts_hash_size <= 1) contacts_hash_size = 512; else contacts_hash_size = 1 << contacts_hash_size; contacts_locks_no = contacts_hash_size; /* check matching mode */ switch (matching_mode) { case CONTACT_ONLY: case CONTACT_CALLID: case CONTACT_PATH: case CONTACT_PORT_IP_ONLY: break; default: LM_ERR("invalid matching mode %d\n", matching_mode); } if (ul_init_locks() != 0) { LM_ERR("locks array initialization failed\n"); return -1; } /* create hash table for storing registered contacts */ if (init_contacts_locks() !=0) { LM_ERR("failed to initialise locks array for contacts\n"); return -1; } contact_list = (struct contact_list*)shm_malloc(sizeof(struct contact_list)); if (!contact_list) { LM_ERR("no more memory to create contact list structure\n"); return -1; } contact_list->slot = (struct contact_hslot*) shm_malloc(sizeof(struct contact_hslot) * contacts_hash_size); if (!contact_list->slot) { LM_ERR("no more memory to create contact list structure\n"); return -1; } for (i=0; i<contacts_hash_size;i++) { init_contact_slot(&contact_list->slot[i], i); } contact_list->size = contacts_hash_size; if (subs_init_locks() != 0) { LM_ERR("IMS Subscription locks array initialization failed\n"); return -1; } ims_subscription_list = (struct ims_subscription_list*) shm_malloc(sizeof(struct ims_subscription_list)); if (!ims_subscription_list) { LM_ERR("no more shm memory to create ims subscription list\n"); return -1; } ims_subscription_list->slot = (struct hslot_sp*) shm_malloc(sizeof(struct hslot_sp) * subs_hash_size); if (!ims_subscription_list->slot) { LM_ERR("no more memory to create subscription list structure\n"); return -1; } for (i=0; i<subs_hash_size;i++) { subs_init_slot(&ims_subscription_list->slot[i], i); } ims_subscription_list->size = subs_hash_size; /* presence binding for subscribe processing*/ presence_api_t pres; bind_presence_t bind_presence; 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 pua\n"); return -1; } pres_extract_sdialog_info= pres.extract_sdialog_info; 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; if(!pres_new_shtable || !pres_destroy_shtable || !pres_insert_shtable || !pres_delete_shtable || !pres_update_shtable || !pres_search_shtable || !pres_extract_sdialog_info) { LM_ERR("could not import add_event\n"); return -1; } /* subscriber dialog hash table */ if(sub_dialog_hash_size<=1) { sub_dialog_hash_size= 512; } else { sub_dialog_hash_size = 1<<sub_dialog_hash_size; } sub_dialog_table= pres_new_shtable(sub_dialog_hash_size); if(sub_dialog_table== NULL) { LM_ERR("while creating new hash table\n"); return -1; } /* Shall we use database ? */ if (db_mode != NO_DB) { /* Yes */ if (db_bind_mod(&db_url, &ul_dbf) < 0) { /* Find database module */ LM_ERR("failed to bind database module\n"); return -1; } if (!DB_CAPABILITY(ul_dbf, DB_CAP_ALL)) { LM_ERR("database module does not implement all functions" " needed by the module\n"); return -1; } if (ul_fetch_rows <= 0) { LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows); return -1; } } 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) { return -1; } if (load_dlg_api(&dlgb) != 0) { /* load the dialog API */ LM_ERR("can't load Dialog API\n"); return -1; } /* Register counters */ if (ul_scscf_init_counters() != 0) { LM_ERR("Failed to register counters\n"); return -1; } /* Register cache timer */ register_timer(timer, 0, timer_interval); /* init the callbacks list */ if (init_ulcb_list() < 0) { LM_ERR("usrloc/callbacks initialization failed\n"); return -1; } if (nat_bflag == (unsigned int) -1) { nat_bflag = 0; } else if (nat_bflag >= 8 * sizeof(nat_bflag)) { LM_ERR("bflag index (%d) too big!\n", nat_bflag); return -1; } else { nat_bflag = 1 << nat_bflag; } init_flag = 1; /* From contact_dlg_handlers.c * * V1.1*/ if (dlgb.register_dlgcb(0x00, DLGCB_CREATED, contact_dlg_create_handler, 0x00, 0x00) ) { LM_ERR("Unable to setup DLGCB_CREATED"); return -1; } else { LM_DBG(" DLGCB_CREATED created successfully"); } 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; load_tm_f load_tm; bind_pua_t bind_pua; bind_libxml_t bind_libxml; /* bind the SL API */ if (sl_load_api(&slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* import the TM auto-loading function */ if((load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))==NULL) { LM_ERR("can't import load_tm\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; } if (pres.add_event == NULL) { LM_ERR("could not import add_event\n"); return -1; } 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; } /* 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; } if(libxml_api.xmlNodeGetNodeByName==NULL) { LM_ERR("can not bind libxml api\n"); return -1; } if(dfks_add_events() < 0) { LM_ERR("failed to add as-feature-event events\n"); return -1; } outbound_proxy.len = outbound_proxy.s ? strlen(outbound_proxy.s) : 0; 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_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) { 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; }