/** * The initialization function, called when the module is loaded by * the script. This function is called only once. * * Bind to the dialog module and setup the callbacks. Also initialize * the shared memory to store our interninal information in. * * @return 0 to continue to load the OpenSIPS, -1 to stop the loading * and abort OpenSIPS. */ static int mod_init(void) { str s; LM_INFO("SIP Session Timer module - initializing\n"); /* * if statistics are disabled, prevent their registration to core. */ if (sst_enable_stats==0) { exports.stats = 0; } if (sst_flag == -1) { LM_ERR("no sst flag set!!\n"); return -1; } else if (sst_flag > MAX_FLAG) { LM_ERR("invalid sst flag %d!!\n", sst_flag); return -1; } if (timeout_spec != NULL) { LM_DBG("Dialog AVP is %s", timeout_spec); s.s = timeout_spec; s.len = strlen(s.s); if (pv_parse_spec(&s, &timeout_avp)==0 && (timeout_avp.type != PVT_AVP)){ LM_ERR("malformed or non AVP timeout AVP definition in '%s'\n", timeout_spec); return -1; } } /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } /* * Init the handlers */ sst_handler_init((timeout_spec?&timeout_avp:0), sst_minSE, sst_flag, sst_reject,sst_interval); /* * Register the main (static) dialog call back. */ if (load_dlg_api(&dialog_st) != 0) { LM_ERR("failed to load dialog hooks"); return(-1); } /* Load dialog hooks */ dialog_st.register_dlgcb(NULL, DLGCB_CREATED, sst_dialog_created_CB, NULL, NULL); /* * We are GOOD-TO-GO. */ return 0; }
/* * Module initialization function */ static int mod_init(void) { LM_DBG("auth_diameter - Initializing\n"); /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } return 0; }
/* * initialize module */ static int mod_init(void) { LM_INFO("initializing...\n"); /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } if (acpt_c) { acpt_s.len = strlen(acpt_c); acpt_s.s = acpt_c; } else { acpt_s.len = ACPT_DEF_LEN; acpt_s.s = ACPT_DEF; } if (acpt_enc_c) { acpt_enc_s.len = strlen(acpt_enc_c); acpt_enc_s.s = acpt_enc_c; } else { acpt_enc_s.len = ACPT_ENC_DEF_LEN; acpt_enc_s.s = ACPT_ENC_DEF; } if (acpt_lan_c) { acpt_lan_s.len = strlen(acpt_lan_c); acpt_lan_s.s = acpt_lan_c; } else { acpt_lan_s.len = ACPT_LAN_DEF_LEN; acpt_lan_s.s = ACPT_LAN_DEF; } if (supt_c) { supt_s.len = strlen(supt_c); supt_s.s = supt_c; } else { supt_s.len = SUPT_DEF_LEN; supt_s.s = SUPT_DEF; } return 0; }
static int mod_init(void) { bind_auth_t bind_auth; LM_INFO("initializing...\n"); init_db_url( db_url , 0 /*cannot be null*/); user_column.len = strlen(user_column.s); domain_column.len = strlen(domain_column.s); pass_column.len = strlen(pass_column.s); pass_column_2.len = strlen(pass_column_2.s); /* Find a database module */ if (db_bind_mod(&db_url, &auth_dbf) < 0){ LM_ERR("unable to bind to a database driver\n"); return -1; } /* bind to auth module and import the API */ bind_auth = (bind_auth_t)find_export("bind_auth", 0, 0); if (!bind_auth) { LM_ERR("unable to find bind_auth function. Check if you load the auth module.\n"); return -2; } if (bind_auth(&auth_api) < 0) { LM_ERR("unable to bind auth module\n"); return -3; } /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } /* process additional list of credentials */ if (parse_aaa_avps( credentials_list, &credentials, &credentials_n)!=0) { LM_ERR("failed to parse credentials\n"); return -5; } return 0; }
/* * mod_init * Called by opensips at init time */ static int mod_init(void) { int ret = 0; static int argc = 1; static char *argv_name = "opensips"; static char **argv = { &argv_name }; LM_INFO("initializing...\n"); if (!filename) { LM_ERR("insufficient module parameters. Module not loaded.\n"); return -1; } /** * We will need reply() from signaling * module for sending replies */ /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } PERL_SYS_INIT3(&argc, &argv, &environ); if ((my_perl = parser_init())) { ret = 0; #ifdef PERL_EXIT_DESTRUCT_END PL_exit_flags |= PERL_EXIT_DESTRUCT_END; #else PL_exit_flags |= PERL_EXIT_EXPECTED; #endif } else { ret = -1; } return ret; }
static int mod_init(void) { str stmp; LM_INFO("initializing...\n"); /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } /* If the parameter was not used */ if (sec_param == 0) { /* Generate secret using random generator */ if (generate_random_secret() < 0) { LM_ERR("failed to generate random secret\n"); return -3; } } else { /* Otherwise use the parameter's value */ secret.s = sec_param; secret.len = strlen(secret.s); } if ( init_rpid_avp(rpid_avp_param)<0 ) { LM_ERR("failed to process rpid AVPs\n"); return -4; } rpid_prefix.len = strlen(rpid_prefix.s); rpid_suffix.len = strlen(rpid_suffix.s); realm_prefix.len = strlen(realm_prefix.s); if(user_spec_param!=0) { stmp.s = user_spec_param; stmp.len = strlen(stmp.s); if(pv_parse_spec(&stmp, &user_spec)==NULL) { LM_ERR("failed to parse username spec\n"); return -5; } switch(user_spec.type) { case PVT_NONE: case PVT_EMPTY: case PVT_NULL: case PVT_MARKER: case PVT_COLOR: LM_ERR("invalid username spec\n"); return -6; default: ; } } if(passwd_spec_param!=0) { stmp.s = passwd_spec_param; stmp.len = strlen(stmp.s); if(pv_parse_spec(&stmp, &passwd_spec)==NULL) { LM_ERR("failed to parse password spec\n"); return -7; } switch(passwd_spec.type) { case PVT_NONE: case PVT_EMPTY: case PVT_NULL: case PVT_MARKER: case PVT_COLOR: LM_ERR("invalid password spec\n"); return -8; default: ; } } if(!disable_nonce_check) { nonce_lock = (gen_lock_t*)lock_alloc(); if(nonce_lock== NULL) { LM_ERR("no more shared memory\n"); return -1; } /* initialize lock_nonce */ if(lock_init(nonce_lock)== 0) { LM_ERR("failed to init lock\n"); return -9; } nonce_buf= (char*)shm_malloc(NBUF_LEN); if(nonce_buf== NULL) { LM_ERR("no more share memory\n"); return -10; } memset(nonce_buf, 255, NBUF_LEN); sec_monit= (int*)shm_malloc((nonce_expire +1)* sizeof(int)); if(sec_monit== NULL) { LM_ERR("no more share memory\n"); return -10; } memset(sec_monit, -1, (nonce_expire +1)* sizeof(int)); second= (int*)shm_malloc(sizeof(int)); next_index= (int*)shm_malloc(sizeof(int)); if(second== NULL || next_index== NULL) { LM_ERR("no more share memory\n"); return -10; } *next_index= -1; } return 0; }
/*! \brief * Initialize parent */ static int mod_init(void) { pv_spec_t avp_spec; str s; bind_usrloc_t bind_usrloc; LM_INFO("initializing...\n"); /* load SIGNALING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } /* load TM API */ memset(&tmb, 0, sizeof(struct tm_binds)); load_tm_api(&tmb); realm_prefix.s = realm_pref; realm_prefix.len = strlen(realm_pref); rcv_param.len = strlen(rcv_param.s); if (rcv_avp_param && *rcv_avp_param) { s.s = rcv_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rcv_avp_param); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &rcv_avp_name, &rcv_avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", rcv_avp_param); return -1; } } else { rcv_avp_name = -1; rcv_avp_type = 0; } if (mct_avp_param && *mct_avp_param) { s.s = mct_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", mct_avp_param); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &mct_avp_name, &mct_avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", mct_avp_param); return -1; } } else { mct_avp_name = -1; mct_avp_type = 0; } if (attr_avp_param && *attr_avp_param) { s.s = attr_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", attr_avp_param); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &attr_avp_name, &attr_avp_type)!=0) { LM_ERR("[%s]- invalid AVP definition\n", attr_avp_param); return -1; } } else { attr_avp_name = -1; attr_avp_type = 0; } bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } /* Normalize default_q parameter */ if (default_q != Q_UNSPECIFIED) { if (default_q > MAX_Q) { LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", default_q, MAX_Q); default_q = MAX_Q; } else if (default_q < MIN_Q) { LM_DBG("default_q = %d, raising to MIN_Q: %d\n", default_q, MIN_Q); default_q = MIN_Q; } } if (bind_usrloc(&ul) < 0) { return -1; } /* * Import use_domain parameter from usrloc */ reg_use_domain = ul.use_domain; if (sock_hdr_name.s) sock_hdr_name.len = strlen(sock_hdr_name.s); if (gruu_secret.s) gruu_secret.len = strlen(gruu_secret.s); /* fix the flags */ fix_flag_name(tcp_persistent_flag_s, tcp_persistent_flag); tcp_persistent_flag = get_flag_id_by_name(FLAG_TYPE_MSG, tcp_persistent_flag_s); tcp_persistent_flag = (tcp_persistent_flag!=-1)?(1<<tcp_persistent_flag):0; return 0; }
static int cpl_init(void) { bind_usrloc_t bind_usrloc; struct stat stat_t; char *ptr; int val; init_db_url( db_url , 0 /*cannot be null*/); db_table.len = strlen(db_table.s); LM_INFO("initializing...\n"); if (proxy_route && proxy_route[0]) { cpl_env.proxy_route = get_script_route_ID_by_name( proxy_route, rlist, RT_NO); if (cpl_env.proxy_route==-1) { LM_ERR("route <%s> does not exist\n",proxy_route); return -1; } } if (cpl_env.proxy_recurse>MAX_PROXY_RECURSE) { LM_CRIT("value of proxy_recurse param (%d) exceeds " "the maximum safety value (%d)\n", cpl_env.proxy_recurse,MAX_PROXY_RECURSE); goto error; } if (dtd_file==0) { LM_CRIT("mandatory parameter \"cpl_dtd_file\" found empty\n"); goto error; } else { /* check if the dtd file exists */ if (stat( dtd_file, &stat_t)==-1) { LM_ERR("checking file \"%s\" status failed; stat returned %s\n", dtd_file,strerror(errno)); goto error; } if ( !S_ISREG( stat_t.st_mode ) ) { LM_ERR("dir \"%s\" is not a regular file!\n", dtd_file); goto error; } if (access( dtd_file, R_OK )==-1) { LM_ERR("checking file \"%s\" for permissions " "failed; access returned %s\n",dtd_file,strerror(errno)); goto error; } } if (cpl_env.log_dir==0) { LM_INFO("log_dir param found empty -> logging disabled!\n"); } else { if ( strlen(cpl_env.log_dir)>MAX_LOG_DIR_SIZE ) { LM_ERR("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) { LM_ERR("checking dir \"%s\" status failed;" " stat returned %s\n",cpl_env.log_dir,strerror(errno)); goto error; } if ( !S_ISDIR( stat_t.st_mode ) ) { LM_ERR("dir \"%s\" is not a directory!\n", cpl_env.log_dir); goto error; } if (access( cpl_env.log_dir, R_OK|W_OK )==-1) { LM_ERR("checking dir \"%s\" for permissions failed; access " "returned %s\n", cpl_env.log_dir, strerror(errno)); goto error; } } /* bind to the mysql module */ if (cpl_db_bind(&db_url, &db_table)<0) goto error; /* load TM API */ if (load_tm_api(&cpl_fct.tmb)!=0) { LM_ERR("can't load TM API\n"); goto error; } /* load SIGNALING API */ if(load_sig_api(&cpl_fct.sigb)< 0) { LM_ERR("can't load signaling functions\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) { LM_ERR("can't bind usrloc\n"); goto error; } if (bind_usrloc( &(cpl_fct.ulb) ) < 0) { LM_ERR("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) { LM_ERR("failed to register domain <%s>\n",lookup_domain); goto error; } } else { LM_NOTICE("no lookup_domain given -> disable lookup node\n"); } /* build a pipe for sending commands to aux process */ if ( pipe( cpl_env.cmd_pipe )==-1 ) { LM_CRIT("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 ) { LM_ERR("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) ) { LM_ERR("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 ) { LM_ERR("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 ) { LM_ERR("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) { cpl_env.realm_prefix.len = strlen(cpl_env.realm_prefix.s); /* convert the realm_prefix to lower cases */ strlower( &cpl_env.realm_prefix ); } return 0; error: return -1; }
/* initialize ratelimit module */ static int mod_init(void) { int i; LM_DBG("initializing ...\n"); rl_lock = lock_alloc(); if (! rl_lock) { LM_ERR("oom in lock_alloc()\n"); return -1; } if (lock_init(rl_lock)==0) { LM_ERR("failed to init lock\n"); return -1; } /* register timer to reset counters */ if (register_timer_process(rl_timer, NULL, timer_interval, TIMER_PROC_INIT_FLAG) == NULL) { LM_ERR("could not register timer function\n"); return -1; } /* load the SIGNALLING API */ if(load_sig_api(&sigb)< 0) { LM_ERR("can't load signaling functions\n"); return -1; } network_load_value = shm_malloc(sizeof(int)); if (network_load_value==NULL) { LM_ERR("oom for network_load_value\n"); return -1; } check_network_load = shm_malloc(sizeof(int)); if (check_network_load==NULL) { LM_ERR("oom for check_network_load\n"); return -1; } load_value = shm_malloc(sizeof(double)); if (load_value==NULL) { LM_ERR("oom for load_value\n"); return -1; } load_source = shm_malloc(sizeof(int)); if (load_source==NULL) { LM_ERR("oom for load_source\n"); return -1; } pid_kp = shm_malloc(sizeof(double)); if (pid_kp==NULL) { LM_ERR("oom for pid_kp\n"); return -1; } pid_ki = shm_malloc(sizeof(double)); if (pid_ki==NULL) { LM_ERR("oom for pid_ki\n"); return -1; } pid_kd = shm_malloc(sizeof(double)); if (pid_kd==NULL) { LM_ERR("oom for pid_kd\n"); return -1; } pid_setpoint = shm_malloc(sizeof(double)); if (pid_setpoint==NULL) { LM_ERR("oom for pid_setpoint\n"); return -1; } drop_rate = shm_malloc(sizeof(int)); if (drop_rate==NULL) { LM_ERR("oom for drop_rate\n"); return -1; } nqueues = shm_malloc(sizeof(int)); if (nqueues==NULL) { LM_ERR("oom for nqueues\n"); return -1; } rl_dbg_str = shm_malloc(sizeof(str)); if (rl_dbg_str==NULL) { LM_ERR("oom for rl_dbg_str\n"); return -1; } *network_load_value = 0; *check_network_load = 0; *load_value = 0.0; *load_source = load_source_mp; *pid_kp = 0.0; *pid_ki = -25.0; *pid_kd = 0.0; *pid_setpoint = 0.01 * (double)cfg_setpoint; *drop_rate = 0; *nqueues = nqueues_mp; rl_dbg_str->s = NULL; rl_dbg_str->len = 0; for (i=0; i<MAX_PIPES; i++) { pipes[i].algo = shm_malloc(sizeof(int)); if (pipes[i].algo==NULL) { LM_ERR("oom for pipes[%d].algo\n", i); return -1; } pipes[i].limit = shm_malloc(sizeof(int)); if (pipes[i].limit==NULL) { LM_ERR("oom for pipes[%d].limit\n", i); return -1; } pipes[i].load = shm_malloc(sizeof(int)); if (pipes[i].load==NULL) { LM_ERR("oom for pipes[%d].load\n", i); return -1; } pipes[i].counter = shm_malloc(sizeof(int)); if (pipes[i].counter==NULL) { LM_ERR("oom for pipes[%d].counter\n", i); return -1; } pipes[i].last_counter = shm_malloc(sizeof(int)); if (pipes[i].last_counter==NULL) { LM_ERR("oom for pipes[%d].last_counter\n", i); return -1; } *pipes[i].algo = pipes[i].algo_mp; *pipes[i].limit = pipes[i].limit_mp; *pipes[i].load = 0; *pipes[i].counter = 0; *pipes[i].last_counter = 0; } for (i=0; i<*nqueues; i++) { queues[i].pipe = shm_malloc(sizeof(int)); if (queues[i].pipe==NULL) { LM_ERR("oom for queues[%d].pipe\n", i); return -1; } queues[i].method = shm_malloc(sizeof(str)); if (queues[i].method==NULL) { LM_ERR("oom for queues[%d].method\n", i); return -1; } *queues[i].pipe = queues[i].pipe_mp; if (queues[i].method_mp.s == NULL) { LM_ERR("unexpected NULL method for queues[%d].method_mp\n", i); return -1; } if(str_cpy(queues[i].method, &queues[i].method_mp)) { LM_ERR("oom str_cpy(queues[%d].method\n", i); return -1; } pkg_free(queues[i].method_mp.s); queues[i].method_mp.s = NULL; queues[i].method_mp.len = 0; } set_check_network_load(); rl_drop_reason.len = strlen(rl_drop_reason.s); 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; }