Ejemplo n.º 1
0
/**
 * init module function
 */
static int mod_init(void)
{
	evrexec_task_t *it;

	if(rpc_register_array(evr_rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(_evrexec_list==NULL)
		return 0;

	/* init faked sip msg */
	if(faked_msg_init()<0) {
		LM_ERR("failed to init evrexec local sip msg\n");
		return -1;
	}

	/* register additional processes */
	it = _evrexec_list;
	while(it) {
		register_procs(it->workers);
		it = it->next;
	}

	return 0;
}
Ejemplo n.º 2
0
/**
 * register RPC commands
 */
static int ds_init_rpc(void)
{
	if(rpc_register_array(dispatcher_rpc_cmds) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 3
0
int statsc_init_rpc(void)
{
	if (rpc_register_array(statsc_rpc)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 4
0
static int domain_init_rpc(void)
{
    if (rpc_register_array(domain_rpc_list) != 0) {
	LM_ERR("failed to register RPC commands\n");
	return -1;
    }
    return 0;
}
Ejemplo n.º 5
0
int sctp_register_rpc(void)
{
	if(rpc_register_array(sctp_rpc_methods) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 6
0
static int permissions_init_rpc(void)
{
	if (rpc_register_array(permissions_rpc)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 7
0
static int presence_init_rpc(void)
{
	if (rpc_register_array(presence_rpc)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 8
0
static int mqueue_rpc_init(void)
{
	if (rpc_register_array(mqueue_rpc)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 9
0
/**
 * register RPC commands
 */
int curl_init_rpc(void)
{
    if (rpc_register_array(curl_rpc_cmds)!=0)
    {
        LM_ERR("failed to register RPC commands\n");
        return -1;
    }
    return 0;
}
Ejemplo n.º 10
0
/**
 * register RPC commands
 */
static int ap_init_rpc(void)
{
    if (rpc_register_array(app_perl_rpc_cmds)!=0)
    {
        LM_ERR("failed to register RPC commands\n");
        return -1;
    }
    return 0;
}
Ejemplo n.º 11
0
int pkg_proc_stats_init_rpc(void)
{
	if (rpc_register_array(kex_pkg_rpc)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 12
0
/**
 * register RPC commands
 */
static int xcap_client_init_rpc(void)
{
	if (rpc_register_array(xcap_client_rpc_cmds)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 13
0
int matrix_rpc_init(void)
{
	if (rpc_register_array(matrix_rpc_cmds)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;

}
Ejemplo n.º 14
0
/*! \brief
 * Module initialization function
 */
static int mod_init(void) {

	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);
	}

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats( exports.name, mod_stats)!=0 ) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}
#endif

	/* Compute the lengths of string parameters */
	usrloc_debug_file.len = strlen(usrloc_debug_file.s);

	if (ul_hash_size <= 1)
		ul_hash_size = 512;
	else
		ul_hash_size = 1 << ul_hash_size;
	ul_locks_no = ul_hash_size;

	if (ul_init_locks() != 0) {
		LM_ERR("locks array initialization failed\n");
		return -1;
	}

	/* Regsiter RPC */
	if (rpc_register_array(ul_rpc) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* Register cache timer */
	LM_DBG("Registering 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;
	}

	init_flag = 1;

	return 0;
}
Ejemplo n.º 15
0
/**
 * register RPC commands
 */
int corex_init_rpc(void)
{
	if (cfg_register_ctx(&_cfg_corex_ctx, NULL)) {
		LOG(L_ERR, "failed to register cfg context\n");
		return -1;
	}

	if (rpc_register_array(corex_rpc_cmds)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	return 0;
}
Ejemplo n.º 16
0
int km_mod_init(void)
{
	if (rpc_register_array(k_rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if (strlen(km_flat_delimiter) != 1) {
		LM_ERR("delimiter has to be exactly one character\n");
		return -1;
	}

	km_flat_rotate = (time_t*)shm_malloc(sizeof(time_t));
	if (!km_flat_rotate) {
		LM_ERR("no shared memory left\n");
		return -1;
	}

	*km_flat_rotate = time(0);
	km_local_timestamp = *km_flat_rotate;

	return 0;
}
Ejemplo n.º 17
0
/*! \brief
 * Module initialization function
 */
static int mod_init(void)
{
	int i;
	udomain_t* d;

	if(sruid_init(&_ul_sruid, '-', "ulcx", SRUID_INC)<0)
		return -1;

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats( exports.name, mod_stats)!=0 ) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}
#endif
	
	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	if (rpc_register_array(ul_rpc)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* Compute the lengths of string parameters */
	ruid_col.len = strlen(ruid_col.s);
	user_col.len = strlen(user_col.s);
	domain_col.len = strlen(domain_col.s);
	contact_col.len = strlen(contact_col.s);
	expires_col.len = strlen(expires_col.s);
	q_col.len = strlen(q_col.s);
	callid_col.len = strlen(callid_col.s);
	cseq_col.len = strlen(cseq_col.s);
	flags_col.len = strlen(flags_col.s);
	cflags_col.len = strlen(cflags_col.s);
	user_agent_col.len = strlen(user_agent_col.s);
	received_col.len = strlen(received_col.s);
	path_col.len = strlen(path_col.s);
	sock_col.len = strlen(sock_col.s);
	methods_col.len = strlen(methods_col.s);
	instance_col.len = strlen(instance_col.s);
	reg_id_col.len = strlen(reg_id_col.s);
	last_mod_col.len = strlen(last_mod_col.s);
	db_url.len = strlen(db_url.s);

	if(ul_xavp_contact_name.s!=NULL)
		ul_xavp_contact_name.len = strlen(ul_xavp_contact_name.s);

	if(ul_hash_size<=1)
		ul_hash_size = 512;
	else
		ul_hash_size = 1<<ul_hash_size;
	ul_locks_no = ul_hash_size;

	/* check matching mode */
	switch (matching_mode) {
		case CONTACT_ONLY:
		case CONTACT_CALLID:
		case CONTACT_PATH:
			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;
	}

	/* Register cache timer */
	if(ul_timer_procs<=0)
	{
		if (timer_interval > 0)
			register_timer(ul_core_timer, 0, timer_interval);
	}
	else
		register_sync_timers(ul_timer_procs);

	/* init the callbacks list */
	if ( init_ulcb_list() < 0) {
		LM_ERR("usrloc/callbacks initialization failed\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 (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;
	}

	for(i=0; i<ul_preload_index; i++) {
		if(register_udomain((const char*)ul_preload_list[i], &d)<0) {
			LM_ERR("cannot register preloaded table %s\n", ul_preload_list[i]);
			return -1;
		}
	}

	if (handle_lost_tcp && db_mode == DB_ONLY)
		LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");

	init_flag = 1;

	return 0;
}
Ejemplo n.º 18
0
static int mod_init(void)
{
	int method;

	if (tls_disable){
		LOG(L_WARN, "tls support is disabled "
				"(set enable_tls=1 in the config to enable it)\n");
		return 0;
	}
	if (fix_tls_cfg(&default_tls_cfg) < 0 ) {
		ERR("initial tls configuration fixup failed\n");
		return -1;
	}
	/* declare configuration */
	if (cfg_declare("tls", tls_cfg_def, &default_tls_cfg,
							cfg_sizeof(tls), (void **)&tls_cfg)) {
		ERR("failed to register the configuration\n");
		return -1;
	}
	/* Convert tls_method parameter to integer */
	method = tls_parse_method(&cfg_get(tls, tls_cfg, method));
	if (method < 0) {
		ERR("Invalid tls_method parameter value\n");
		return -1;
	}
	/* fill mod_params */
	mod_params.method = method;
	mod_params.verify_cert = cfg_get(tls, tls_cfg, verify_cert);
	mod_params.verify_depth = cfg_get(tls, tls_cfg, verify_depth);
	mod_params.require_cert = cfg_get(tls, tls_cfg, require_cert);
	mod_params.pkey_file = cfg_get(tls, tls_cfg, private_key);
	mod_params.ca_file = cfg_get(tls, tls_cfg, ca_list);
	mod_params.crl_file = cfg_get(tls, tls_cfg, crl);
	mod_params.cert_file = cfg_get(tls, tls_cfg, certificate);
	mod_params.cipher_list = cfg_get(tls, tls_cfg, cipher_list);
	mod_params.server_name = cfg_get(tls, tls_cfg, server_name);

	tls_domains_cfg =
			(tls_domains_cfg_t**)shm_malloc(sizeof(tls_domains_cfg_t*));
	if (!tls_domains_cfg) {
		ERR("Not enough shared memory left\n");
		goto error;
	}
	*tls_domains_cfg = NULL;

	register_select_table(tls_sel);
	/* register the rpc interface */
	if (rpc_register_array(tls_rpc)!=0) {
		LOG(L_ERR, "failed to register RPC commands\n");
		goto error;
	}

	 /* if (init_tls() < 0) return -1; */
	
	tls_domains_cfg_lock = lock_alloc();
	if (tls_domains_cfg_lock == 0) {
		ERR("Unable to create TLS configuration lock\n");
		goto error;
	}
	if (lock_init(tls_domains_cfg_lock) == 0) {
		lock_dealloc(tls_domains_cfg_lock);
		ERR("Unable to initialize TLS configuration lock\n");
		goto error;
	}
	if (tls_ct_wq_init() < 0) {
		ERR("Unable to initialize TLS buffering\n");
		goto error;
	}
	if (cfg_get(tls, tls_cfg, config_file).s) {
		*tls_domains_cfg = 
			tls_load_config(&cfg_get(tls, tls_cfg, config_file));
		if (!(*tls_domains_cfg)) goto error;
	} else {
		*tls_domains_cfg = tls_new_cfg();
		if (!(*tls_domains_cfg)) goto error;
	}

	if (tls_check_sockets(*tls_domains_cfg) < 0)
		goto error;

#ifndef OPENSSL_NO_ECDH
	LM_INFO("With ECDH-Support!\n");
#endif
#ifndef OPENSSL_NO_DH
	LM_INFO("With Diffie Hellman\n");
#endif
	tls_lookup_event_routes();
	return 0;
error:
	destroy_tls_h();
	return -1;
}
Ejemplo n.º 19
0
static int sca_mod_init(void)
{
	sca = (sca_mod *) shm_malloc(sizeof(sca_mod));
	if (sca == NULL) {
		LM_ERR("Failed to shm_malloc module object\n");
		return (-1);
	}
	memset(sca, 0, sizeof(sca_mod));

	if (sca_set_config(sca) != 0) {
		LM_ERR("Failed to set configuration\n");
		goto error;
	}

	if (rpc_register_array(sca_rpc) != 0) {
		LM_ERR("Failed to register RPC commands\n");
		goto error;
	}

	if (sca_bind_srdb1(sca, &dbf) != 0) {
		LM_ERR("Failed to initialize required DB API\n");
		goto error;
	}

	if (load_tm_api(&tmb) != 0) {
		LM_ERR("Failed to initialize required tm API. Check that the \"tm\" module is loaded before this module.\n");
		goto error;
	}
	sca->tm_api = &tmb;

	if (sca_bind_sl(sca, &slb) != 0) {
		LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n");
		goto error;
	}

	if (sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size)
			!= 0) {
		LM_ERR("Failed to create subscriptions hash table\n");
		goto error;
	}
	if (sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size)
			!= 0) {
		LM_ERR("Failed to create appearances hash table\n");
		goto error;
	}

	sca_subscriptions_restore_from_db(sca);

	register_timer(sca_subscription_purge_expired, sca,
			sca->cfg->purge_expired_interval);
	register_timer(sca_appearance_purge_stale, sca,
			sca->cfg->purge_expired_interval);

	// register separate timer process to write subscriptions to DB.
	// move to 3.3+ timer API (register_basic_timer) at some point.
	// timer process forks in sca_child_init, above.
	register_dummy_timers(1);

	LM_INFO("SCA initialized \n");

	return (0);

	error: if (sca != NULL) {
		if (sca->cfg != NULL) {
			shm_free(sca->cfg);
		}
		if (sca->subscriptions != NULL) {
			sca_hash_table_free(sca->subscriptions);
		}
		if (sca->appearances != NULL) {
			sca_hash_table_free(sca->appearances);
		}
		shm_free(sca);
		sca = NULL;
	}

	return (-1);
}
Ejemplo n.º 20
0
static int mod_init(void) {
    pv_spec_t avp_spec;
    str s;
    bind_usrloc_t bind_usrloc;
    qvalue_t dq;

	if (rpc_register_array(reg_rpc) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
    
    callback_singleton = shm_malloc(sizeof (int));
    *callback_singleton = 0;

    /*build the required strings */
    scscf_serviceroute_uri_str.s =
            (char*) pkg_malloc(orig_prefix.len + scscf_name_str.len);

    if (!scscf_serviceroute_uri_str.s) {
        LM_ERR("Unable to allocate memory for service route uri\n");
        return -1;
    }
    
    if (contact_expires_buffer_percentage < 0 || contact_expires_buffer_percentage > 90) {
        LM_ERR("contact expires percentage not valid, must be >0 and <=90");
        return -1;
    }

    memcpy(scscf_serviceroute_uri_str.s, orig_prefix.s, orig_prefix.len);
    scscf_serviceroute_uri_str.len = orig_prefix.len;
    if (scscf_name_str.len > 4
            && strncasecmp(scscf_name_str.s, "sip:", 4) == 0) {
        memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len,
                scscf_name_str.s + 4, scscf_name_str.len - 4);
        scscf_serviceroute_uri_str.len += scscf_name_str.len - 4;
    } else {
        memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len,
                scscf_name_str.s, scscf_name_str.len);
        scscf_serviceroute_uri_str.len += scscf_name_str.len;
    }
    
    pv_tmx_data_init();

    /* </build required strings> */

#ifdef STATISTICS
    /* register statistics */
    if (register_module_stats(exports.name, mod_stats) != 0) {
        LM_ERR("failed to register core statistics\n");
        return -1;
    }
    if (!register_stats()) {
        LM_ERR("Unable to register statistics\n");
        return -1;
    }
#endif

    /*register space for notification processors*/
    register_procs(notification_processes);
    cfg_register_child(notification_processes);
    
    /* bind the SL API */
    if (sl_load_api(&slb) != 0) {
        LM_ERR("cannot bind to SL API\n");
        return -1;
    }

    /* load the TM API */
    if (load_tm_api(&tmb) != 0) {
        LM_ERR("can't load TM API\n");
        return -1;
    }

    /* load the CDP API */
    if (load_cdp_api(&cdpb) != 0) {
        LM_ERR("can't load CDP API\n");
        return -1;
    }

    cdp_avp = load_cdp_avp();
    if (!cdp_avp) {
        LM_ERR("can't load CDP_AVP API\n");
        return -1;
    }

    if (cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg,
            cfg_sizeof(registrar), &registrar_cfg)) {
        LM_ERR("Fail to declare the configuration\n");
        return -1;
    }

    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.n = 0;
        rcv_avp_type = 0;
    }
    if (aor_avp_param && *aor_avp_param) {
        s.s = aor_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", aor_avp_param);
            return -1;
        }

        if (pv_get_avp_name(0, &avp_spec.pvp, &aor_avp_name, &aor_avp_type)
                != 0) {
            LM_ERR("[%s]- invalid AVP definition\n", aor_avp_param);
            return -1;
        }
    } else {
        aor_avp_name.n = 0;
        aor_avp_type = 0;
    }

    if (reg_callid_avp_param && *reg_callid_avp_param) {
        s.s = reg_callid_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", reg_callid_avp_param);
            return -1;
        }

        if (pv_get_avp_name(0, &avp_spec.pvp, &reg_callid_avp_name,
                &reg_callid_avp_type) != 0) {
            LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param);
            return -1;
        }
    } else {
        reg_callid_avp_name.n = 0;
        reg_callid_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 */
    dq = cfg_get(registrar, registrar_cfg, default_q);
    if (dq != Q_UNSPECIFIED) {
        if (dq > MAX_Q) {
            LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q);
            dq = MAX_Q;
        } else if (dq < MIN_Q) {
            LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q);
            dq = MIN_Q;
        }
    }
    cfg_get(registrar, registrar_cfg, default_q) = dq;

    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;
    }
    
    if (ul.register_ulcb(0, 0, UL_IMPU_INSERT, ul_impu_inserted, 0) < 0) {
        LM_ERR("can not register callback for insert\n");
        return -1;
    }

    if (sock_hdr_name.s) {
        if (sock_hdr_name.len == 0 || sock_flag == -1) {
            LM_WARN("empty sock_hdr_name or sock_flag no set -> resetting\n");
            sock_hdr_name.len = 0;
            sock_flag = -1;
        }
    } else if (sock_flag != -1) {
        LM_WARN("sock_flag defined but no sock_hdr_name -> resetting flag\n");
        sock_flag = -1;
    }

    /* fix the flags */
    sock_flag = (sock_flag != -1) ? (1 << sock_flag) : 0;
    tcp_persistent_flag =
            (tcp_persistent_flag != -1) ? (1 << tcp_persistent_flag) : 0;

    /* init the registrar notifications */
    if (!notify_init()) return -1;

    /* register the registrar notifications timer */
    //Currently we do not use this - we send notifies immediately
    //if (register_timer(notification_timer, notification_list, 5) < 0) return -1;

    return 0;
}
Ejemplo n.º 21
0
static int mod_init(void)
{
	/* Register RPC commands */
	if (rpc_register_array(rpc_cmds)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	if (!hash_file) {
		LM_INFO("no hash_file given, disable hash functionality\n");
	} else {
		if (MD5File(config_hash, hash_file) != 0) {
			LM_ERR("could not hash the config file");
			return -1;
		}
		LM_DBG("config file hash is %.*s", MD5_LEN, config_hash);
	}

	if (initial_prob > 100) {
		LM_ERR("invalid probability <%d>\n", initial_prob);
		return -1;
	}
	LM_DBG("initial probability %d percent\n", initial_prob);

	probability=(int *) shm_malloc(sizeof(int));

	if (!probability) {
		LM_ERR("no shmem available\n");
		return -1;
	}
	*probability = initial_prob;

	gflags=(unsigned int *) shm_malloc(sizeof(unsigned int));
	if (!gflags) {
		LM_ERR(" no shmem available\n");
		return -1;
	}
	*gflags=initial_gflags;
	gflags_lock = lock_alloc();
	if (gflags_lock==0) {
		LM_ERR("cannot allocate gflgas lock\n");
		return -1;
	}
	if (lock_init(gflags_lock)==NULL) {
		LM_ERR("cannot initiate gflags lock\n");
		lock_dealloc(gflags_lock);
		return -1;
	}
	if(_cfg_lock_size>0 && _cfg_lock_size<=10)
	{
		_cfg_lock_size = 1<<_cfg_lock_size;
		_cfg_lock_set = lock_set_alloc(_cfg_lock_size);
		if(_cfg_lock_set==NULL || lock_set_init(_cfg_lock_set)==NULL)
		{
			LM_ERR("cannot initiate lock set\n");
			return -1;
		}
	}
	return 0;
}
Ejemplo n.º 22
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;
}
Ejemplo n.º 23
0
/**
 * init module function
 */
static int mod_init(void)
{
	
	if(register_mi_mod(exports.name, mi_cmds)!=0) {
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	/* 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. TM module probably not loaded\n");
		return -1;
	}

	/* load peer list - the list containing the module callbacks for dmq */
	peer_list = init_peer_list();
	if(peer_list==NULL) {
		LM_ERR("cannot initialize peer list\n");
		return -1;
	}

	/* load the dmq node list - the list containing the dmq servers */
	node_list = init_dmq_node_list();
	if(node_list==NULL) {
		LM_ERR("cannot initialize node list\n");
		return -1;
	}

	if (rpc_register_array(rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* register worker processes - add one because of the ping process */
	register_procs(num_workers);
	
	/* check server_address and notification_address are not empty and correct */
	if(parse_uri(dmq_server_address.s, dmq_server_address.len, &dmq_server_uri) < 0) {
		LM_ERR("server address invalid\n");
		return -1;
	}

	if(parse_uri(dmq_notification_address.s, dmq_notification_address.len, &dmq_notification_uri) < 0) {
		LM_ERR("notification address invalid\n");
		return -1;
	}

	/* create socket string out of the server_uri */
	if(make_socket_str_from_uri(&dmq_server_uri, &dmq_server_socket) < 0) {
		LM_ERR("failed to create socket out of server_uri\n");
		return -1;
	}
	if (lookup_local_socket(&dmq_server_socket) == NULL) {
		LM_ERR("server_uri is not a socket the proxy is listening on\n");
		return -1;
	}

	/* allocate workers array */
	workers = shm_malloc(num_workers * sizeof(*workers));
	if(workers == NULL) {
		LM_ERR("error in shm_malloc\n");
		return -1;
	}

	dmq_init_callback_done = shm_malloc(sizeof(int));
	if (!dmq_init_callback_done) {
		LM_ERR("no more shm\n");
		return -1;
	}
	*dmq_init_callback_done = 0;

	/**
	 * add the dmq notification peer.
	 * the dmq is a peer itself so that it can receive node notifications
	 */
	if(add_notification_peer()<0) {
		LM_ERR("cannot add notification peer\n");
		return -1;
	}

	startup_time = (int) time(NULL);

	/**
	 * add the ping timer
	 * it pings the servers once in a while so that we know which failed
	 */
	if(ping_interval < MIN_PING_INTERVAL) {
		ping_interval = MIN_PING_INTERVAL;
	}
	if(register_timer(ping_servers, 0, ping_interval)<0) {
		LM_ERR("cannot register timer callback\n");
		return -1;
	}

	return 0;
}
Ejemplo n.º 24
0
/* initialize ratelimit module */
static int mod_init(void)
{
	if(rpc_register_array(rpc_methods)!=0)
	{
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}
	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}
	if(pl_hash_size<=0)
	{
		LM_ERR("invalid hash size parameter: %d\n", pl_hash_size);
		return -1;
	}
	if(pl_init_htable(1<<pl_hash_size)<0)
	{
		LM_ERR("could not allocate pipes htable\n");
		return -1;
	}
	if(pl_init_db()<0)
	{
		LM_ERR("could not load pipes description\n");
		return -1;
	}
	/* register timer to reset counters */
	if ((pl_timer = timer_alloc()) == NULL) {
		LM_ERR("could not allocate timer\n");
		return -1;
	}
	timer_init(pl_timer, pl_timer_handle, 0, F_TIMER_FAST);
	timer_add(pl_timer, MS_TO_TICKS(1000)); /* Start it after 1000ms */

	/* bind the SL API */
	if (sl_load_api(&slb)!=0) {
		LM_ERR("cannot bind to SL API\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;
	}

	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;
	}
	_pl_pid_setpoint = shm_malloc(sizeof(double));
	if (_pl_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;
	}

	*network_load_value = 0;
	*load_value = 0.0;
	*load_source = load_source_mp;
	*pid_kp = 0.0;
	*pid_ki = -25.0;
	*pid_kd = 0.0;
	*_pl_pid_setpoint = 0.01 * (double)_pl_cfg_setpoint;
	*drop_rate      = 0;

	return 0;
}
Ejemplo n.º 25
0
/*! \brief
 * Module initialization function
 */
static int mod_init(void) {

	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);
	}

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats( exports.name, mod_stats)!=0 ) {
		LM_ERR("failed to register core statistics\n");
		return -1;
	}
#endif

	if (ul_hash_size <= 1)
		ul_hash_size = 512;
	else
		ul_hash_size = 1 << ul_hash_size;
	ul_locks_no = ul_hash_size;

	if (ul_init_locks() != 0) {
		LM_ERR("locks array initialization failed\n");
		return -1;
	}

	/* Regsiter RPC */
	if (rpc_register_array(ul_rpc) != 0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	/* Register cache timer */
	LM_DBG("Registering 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;
	}

	/* Shall we use database ? */
	if (db_mode != NO_DB) { /* Yes */
		if(ul_fetch_rows<=0) {
			LM_ERR("invalid fetch_rows number '%d'\n", ul_fetch_rows);
			return -1;
		}

		if (init_db(&db_url, timer_interval, ul_fetch_rows) != 0) {
			LM_ERR("Error initializing db connection\n");
			return -1;
		}
		LM_DBG("Running in DB mode %i\n", db_mode);
	}

	init_flag = 1;

	return 0;
}
Ejemplo n.º 26
0
/* registers a module,  register_f= module register  functions
 * returns <0 on error, 0 on success */
static int register_module(unsigned ver, union module_exports_u* e,
					char* path, void* handle)
{
	int ret, i;
	struct sr_module* mod;
	char defmod[64];

	ret=-1;

	/* add module to the list */
	if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
		LM_ERR("memory allocation failure\n");
		ret=E_OUT_OF_MEM;
		goto error;
	}
	memset(mod,0, sizeof(struct sr_module));
	mod->path=path;
	mod->handle=handle;
	mod->orig_mod_interface_ver=ver;
	/* convert exports to sr31 format */
	if (ver == 0) {
		/* ser <= 3.0 */
		mod->exports.name = e->v0.name;
		if (e->v0.cmds) {
			mod->exports.cmds = sr_cmd_exports_convert(ver, e->v0.cmds, mod);
			if (mod->exports.cmds == 0) {
				LM_ERR("failed to convert module command exports to 3.1 format"
						" for module \"%s\" (%s), interface version %d\n",
						mod->exports.name, mod->path, ver);
				ret = E_UNSPEC;
				goto error;
			}
		}
		mod->exports.params = e->v0.params;
		mod->exports.init_f = e->v0.init_f;
		mod->exports.response_f = e->v0.response_f;
		mod->exports.destroy_f = e->v0.destroy_f;
		mod->exports.onbreak_f = e->v0.onbreak_f;
		mod->exports.init_child_f = e->v0.init_child_f;
		mod->exports.dlflags = 0; /* not used in ser <= 3.0 */
		mod->exports.rpc_methods = e->v0.rpc_methods;
		/* the rest are 0, not used in ser */
	} else if (ver == 1) {
		/* kamailio <= 3.0 */
		mod->exports.name = e->v1.name;
		if (e->v1.cmds) {
			mod->exports.cmds = sr_cmd_exports_convert(ver, e->v1.cmds, mod);
			if (mod->exports.cmds == 0) {
				LM_ERR("failed to convert module command exports to 3.1 format"
						" for module \"%s\" (%s), interface version %d\n",
						mod->exports.name, mod->path, ver);
				ret = E_UNSPEC;
				goto error;
			}
		}
		mod->exports.params = e->v1.params;
		mod->exports.init_f = e->v1.init_f;
		mod->exports.response_f = e->v1.response_f;
		mod->exports.destroy_f = e->v1.destroy_f;
		mod->exports.onbreak_f = 0; /* not used in k <= 3.0 */
		mod->exports.init_child_f = e->v1.init_child_f;
		mod->exports.dlflags = e->v1.dlflags;
		mod->exports.rpc_methods = 0; /* not used in k <= 3.0 */
		mod->exports.stats = e->v1.stats;
		mod->exports.mi_cmds = e->v1.mi_cmds;
		mod->exports.items = e->v1.items;
		mod->exports.procs = e->v1.procs;
	} else {
		LM_ERR("unsupported module interface version %d\n", ver);
		ret = E_UNSPEC;
		goto error;
	}

	if (mod->exports.items) {
		/* register module pseudo-variables for kamailio modules */
		LM_DBG("register PV from: %s\n", mod->exports.name);
		if (register_pvars_mod(mod->exports.name, mod->exports.items)!=0) {
			LM_ERR("failed to register pseudo-variables for module %s (%s)\n",
				mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}
	}
	if (mod->exports.rpc_methods){
		/* register rpcs for ser modules */
		i=rpc_register_array(mod->exports.rpc_methods);
		if (i<0){
			LM_ERR("failed to register RPCs for module %s (%s)\n",
					mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}else if (i>0){
			LM_ERR("%d duplicate RPCs name detected while registering RPCs"
					" declared in module %s (%s)\n",
					i, mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}
		/* i==0 => success */
	}

	/* add cfg define for each module: MOD_modulename */
	if(strlen(mod->exports.name)>=60) {
		LM_ERR("too long module name: %s\n", mod->exports.name);
		goto error;
	}
	strcpy(defmod, "MOD_");
	strcat(defmod, mod->exports.name);
	pp_define_set_type(0);
	if(pp_define(strlen(defmod), defmod)<0) {
		LM_ERR("unable to set cfg define for module: %s\n",
				mod->exports.name);
		goto error;
	}

	/* link module in the list */
	mod->next=modules;
	modules=mod;
	return 0;
error:
	if (mod)
		pkg_free(mod);
	return ret;
}
Ejemplo n.º 27
0
/* initialize ratelimit module */
static int mod_init(void)
{
	int i;

	if (rpc_register_array(rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	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 ((rl_timer = timer_alloc()) == NULL) {
		LM_ERR("could not allocate timer\n");
		return -1;
	}
	timer_init(rl_timer, rl_timer_handle, 0, F_TIMER_FAST);
	timer_add(rl_timer, MS_TO_TICKS(1000*timer_interval));

	network_load_value = shm_malloc(sizeof(int));
	if (network_load_value==NULL) {
		LM_ERR("oom for network_load_value\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;
	*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;
	}

	return 0;
}
Ejemplo n.º 28
0
static int mod_init(void) {
    unsigned int n;

    if (register_mi_mod(exports.name, mi_cmds) != 0) {
        LM_ERR("failed to register MI commands\n");
        return -1;
    }

    if (rpc_register_array(rpc_methods) != 0) {
        LM_ERR("failed to register RPC commands\n");
        return -1;
    }
    
    if (dialog_ng_stats_init() != 0) {
	LM_ERR("Failed to register dialog_ng counters\n");
	return -1;
    }

    if (faked_msg_init() < 0)
        return -1;

    if (timeout_spec.s)
        timeout_spec.len = strlen(timeout_spec.s);

    dlg_bridge_controller.len = strlen(dlg_bridge_controller.s);


    /* param checkings */
    if (dlg_flag == -1) {
        LM_ERR("no dlg flag set!!\n");
        return -1;
    } else if (dlg_flag > MAX_FLAG) {
        LM_ERR("invalid dlg flag %d!!\n", dlg_flag);
        return -1;
    }

    if (rr_param == 0 || rr_param[0] == 0) {
        LM_ERR("empty rr_param!!\n");
        return -1;
    } else if (strlen(rr_param) > MAX_DLG_RR_PARAM_NAME) {
        LM_ERR("rr_param too long (max=%d)!!\n", MAX_DLG_RR_PARAM_NAME);
        return -1;
    }

    if (timeout_spec.s) {
        if (pv_parse_spec(&timeout_spec, &timeout_avp) == 0
                && (timeout_avp.type != PVT_AVP)) {
            LM_ERR("malformed or non AVP timeout "
                    "AVP definition in '%.*s'\n", timeout_spec.len, timeout_spec.s);
            return -1;
        }
    }

    if (default_timeout <= 0) {
        LM_ERR("0 default_timeout not accepted!!\n");
        return -1;
    }

    if (ruri_pvar_param.s == NULL || *ruri_pvar_param.s == '\0') {
        LM_ERR("invalid r-uri PV string\n");
        return -1;
    }
    ruri_pvar_param.len = strlen(ruri_pvar_param.s);
    if (pv_parse_format(&ruri_pvar_param, &ruri_param_model) < 0
            || ruri_param_model == NULL) {
        LM_ERR("malformed r-uri PV string: %s\n", ruri_pvar_param.s);
        return -1;
    }

    /* update the len of the extra headers */
    if (dlg_extra_hdrs.s)
        dlg_extra_hdrs.len = strlen(dlg_extra_hdrs.s);

    if (seq_match_mode != SEQ_MATCH_NO_ID &&
            seq_match_mode != SEQ_MATCH_FALLBACK &&
            seq_match_mode != SEQ_MATCH_STRICT_ID) {
        LM_ERR("invalid value %d for seq_match_mode param!!\n", seq_match_mode);
        return -1;
    }

    if (detect_spirals != 0 && detect_spirals != 1) {
        LM_ERR("invalid value %d for detect_spirals param!!\n", detect_spirals);
        return -1;
    }

    /* create profile hashes */
    if (add_profile_definitions(profiles_nv_s, 0) != 0) {
        LM_ERR("failed to add profiles without value\n");
        return -1;
    }
    if (add_profile_definitions(profiles_wv_s, 1) != 0) {
        LM_ERR("failed to add profiles with value\n");
        return -1;
    }

    /* load the TM API */
    if (load_tm_api(&d_tmb) != 0) {
        LM_ERR("can't load TM API\n");
        return -1;
    }

    /* load RR API also */
    if (load_rr_api(&d_rrb) != 0) {
        LM_ERR("can't load RR API\n");
        return -1;
    }

    /* register callbacks*/
    /* listen for all incoming requests  */
    if (d_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, dlg_onreq, 0, 0) <= 0) {
        LM_ERR("cannot register TMCB_REQUEST_IN callback\n");
        return -1;
    }

    /* listen for all routed requests  */
    if (d_rrb.register_rrcb(dlg_onroute, 0) < 0) {
        LM_ERR("cannot register RR callback\n");
        return -1;
    }

    if (register_script_cb(profile_cleanup, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) {
        LM_ERR("cannot regsiter script callback");
        return -1;
    }
    if (register_script_cb(dlg_cfg_cb,
            PRE_SCRIPT_CB | REQUEST_CB, 0) < 0) {
        LM_ERR("cannot regsiter pre-script ctx callback\n");
        return -1;
    }
    if (register_script_cb(dlg_cfg_cb,
            POST_SCRIPT_CB | REQUEST_CB, 0) < 0) {
        LM_ERR("cannot regsiter post-script ctx callback\n");
        return -1;
    }

    if (register_script_cb(spiral_detect_reset, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) {
        LM_ERR("cannot register req pre-script spiral detection reset callback\n");
        return -1;
    }

    if (register_timer(dlg_timer_routine, 0, 1) < 0) {
        LM_ERR("failed to register timer \n");
        return -1;
    }

    /*for testing only!!!! setup timer to call print all dlg every 10 seconds!*/
    if (register_timer(print_all_dlgs, 0, 10) < 0) {
        LM_ERR("failed to register timer \n");
        return -1;
    }

    /* init handlers */
    init_dlg_handlers(rr_param, dlg_flag,
            timeout_spec.s ? &timeout_avp : 0, default_timeout, seq_match_mode);

    /* init timer */
    if (init_dlg_timer(dlg_ontimeout) != 0) {
        LM_ERR("cannot init timer list\n");
        return -1;
    }

    /* sanitize dlg_hash_zie */
    if (dlg_hash_size < 1) {
        LM_WARN("hash_size is smaller "
                "then 1  -> rounding from %d to 1\n",
                dlg_hash_size);
        dlg_hash_size = 1;
    }

    /* initialized the hash table */
    for (n = 0; n < (8 * sizeof (n)); n++) {
        if (dlg_hash_size == (1 << n))
            break;
        if (n && dlg_hash_size < (1 << n)) {
            LM_WARN("hash_size is not a power "
                    "of 2 as it should be -> rounding from %d to %d\n",
                    dlg_hash_size, 1 << (n - 1));
            dlg_hash_size = 1 << (n - 1);
        }
    }

    if (init_dlg_table(dlg_hash_size) < 0) {
        LM_ERR("failed to create hash table\n");
        return -1;
    }

    /* if a database should be used to store the dialogs' information */
	dlg_db_mode = dlg_db_mode_param;
	if (dlg_db_mode==DB_MODE_NONE) {
		db_url.s = 0; db_url.len = 0;
	} else {
		if (dlg_db_mode!=DB_MODE_REALTIME &&
		dlg_db_mode!=DB_MODE_DELAYED && dlg_db_mode!=DB_MODE_SHUTDOWN ) {
			LM_ERR("unsupported db_mode %d\n", dlg_db_mode);
			return -1;
		}
		if ( !db_url.s || db_url.len==0 ) {
			LM_ERR("db_url not configured for db_mode %d\n", dlg_db_mode);
			return -1;
		}
		if (init_dlg_db(&db_url, dlg_hash_size, db_update_period, db_fetch_rows)!=0) {
			LM_ERR("failed to initialize the DB support\n");
			return -1;
		}
		run_load_callbacks();
	}

    destroy_dlg_callbacks(DLGCB_LOADED);

    return 0;
}
Ejemplo n.º 29
0
/* registers a module,  register_f= module register  functions
 * returns <0 on error, 0 on success */
static int register_module(module_exports_t* e, char* path, void* handle)
{
	int ret, i;
	struct sr_module* mod;
	char defmod[64];
	int n = 0;

	ret=-1;

	/* add module to the list */
	if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
		LM_ERR("memory allocation failure\n");
		ret=E_OUT_OF_MEM;
		goto error;
	}
	memset(mod, 0, sizeof(struct sr_module));
	mod->path=path;
	mod->handle=handle;

	/* copy and convert fields */
	mod->exports.name = e->name;

	mod->exports.dlflags = e->dlflags;

	if(e->cmds) {
		for (n=0; e->cmds[n].name; n++);
	}
	mod->exports.cmds = pkg_malloc(sizeof(ksr_cmd_export_t)*(n+1));
	memset(mod->exports.cmds, 0, sizeof(ksr_cmd_export_t)*(n+1));
	for (i=0; i < n; i++) {
		mod->exports.cmds[i].name = e->cmds[i].name;
		mod->exports.cmds[i].function = e->cmds[i].function;
		mod->exports.cmds[i].param_no = e->cmds[i].param_no;
		mod->exports.cmds[i].fixup = e->cmds[i].fixup;
		mod->exports.cmds[i].free_fixup = e->cmds[i].free_fixup;
		mod->exports.cmds[i].flags = e->cmds[i].flags;

		mod->exports.cmds[i].fixup_flags = 0;
		mod->exports.cmds[i].module_exports = mod;
		/* fill known free fixups */
		if (mod->exports.cmds[i].fixup && mod->exports.cmds[i].free_fixup == 0) {
			mod->exports.cmds[i].free_fixup
					= get_fixup_free(mod->exports.cmds[i].fixup);
		}
	}

	mod->exports.params = e->params;
	mod->exports.rpc_methods = e->rpc_methods;
	mod->exports.pv_items = e->pv_items;
	mod->exports.response_f = e->response_f;
	mod->exports.init_mod_f = e->init_mod_f;
	mod->exports.init_child_f = e->init_child_f;
	mod->exports.destroy_mod_f = e->destroy_mod_f;

	if (mod->exports.pv_items) {
		/* register module pseudo-variables for kamailio modules */
		LM_DBG("register PV from: %s\n", mod->exports.name);
		if (register_pvars_mod(mod->exports.name, mod->exports.pv_items)!=0) {
			LM_ERR("failed to register pseudo-variables for module %s (%s)\n",
				mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}
	}
	if (mod->exports.rpc_methods){
		/* register rpcs for ser modules */
		i=rpc_register_array(mod->exports.rpc_methods);
		if (i<0){
			LM_ERR("failed to register RPCs for module %s (%s)\n",
					mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}else if (i>0){
			LM_ERR("%d duplicate RPCs name detected while registering RPCs"
					" declared in module %s (%s)\n",
					i, mod->exports.name, path);
			ret = E_UNSPEC;
			goto error;
		}
		/* i==0 => success */
	}

	/* add cfg define for each module: MOD_modulename */
	if(strlen(mod->exports.name)>=60) {
		LM_ERR("too long module name: %s\n", mod->exports.name);
		goto error;
	}
	strcpy(defmod, "MOD_");
	strcat(defmod, mod->exports.name);
	pp_define_set_type(0);
	if(pp_define(strlen(defmod), defmod)<0) {
		LM_ERR("unable to set cfg define for module: %s\n",
				mod->exports.name);
		goto error;
	}

	/* link module in the list */
	mod->next=modules;
	modules=mod;
	return 0;
error:
	if (mod)
		pkg_free(mod);
	return ret;
}
Ejemplo n.º 30
0
static int mod_init(void)
{
	unsigned int n;

	if(dlg_ka_interval!=0 && dlg_ka_interval<30) {
		LM_ERR("ka interval too low (%d), has to be at least 30\n",
				dlg_ka_interval);
		return -1;
	}

	dlg_event_rt[DLG_EVENTRT_START] = route_lookup(&event_rt, "dialog:start");
	dlg_event_rt[DLG_EVENTRT_END] = route_lookup(&event_rt, "dialog:end");
	dlg_event_rt[DLG_EVENTRT_FAILED] = route_lookup(&event_rt, "dialog:failed");

#ifdef STATISTICS
	/* register statistics */
	if (register_module_stats( exports.name, mod_stats)!=0 ) {
		LM_ERR("failed to register %s statistics\n", exports.name);
		return -1;
	}
#endif

	if(register_mi_mod(exports.name, mi_cmds)!=0)
	{
		LM_ERR("failed to register MI commands\n");
		return -1;
	}

	if (rpc_register_array(rpc_methods)!=0) {
		LM_ERR("failed to register RPC commands\n");
		return -1;
	}

	if(faked_msg_init()<0)
		return -1;

	if(dlg_bridge_init_hdrs()<0)
		return -1;

	/* param checkings */
	if (dlg_flag==-1) {
		LM_ERR("no dlg flag set!!\n");
		return -1;
	} else if (dlg_flag>MAX_FLAG) {
		LM_ERR("invalid dlg flag %d!!\n",dlg_flag);
		return -1;
	}

	if (rr_param==0 || rr_param[0]==0) {
		LM_ERR("empty rr_param!!\n");
		return -1;
	} else if (strlen(rr_param)>MAX_DLG_RR_PARAM_NAME) {
		LM_ERR("rr_param too long (max=%d)!!\n", MAX_DLG_RR_PARAM_NAME);
		return -1;
	}

	if (timeout_spec.s) {
		if ( pv_parse_spec(&timeout_spec, &timeout_avp)==0 
				&& (timeout_avp.type!=PVT_AVP)){
			LM_ERR("malformed or non AVP timeout "
				"AVP definition in '%.*s'\n", timeout_spec.len,timeout_spec.s);
			return -1;
		}
	}

	if (default_timeout<=0) {
		LM_ERR("0 default_timeout not accepted!!\n");
		return -1;
	}

	if (ruri_pvar_param.s==NULL || ruri_pvar_param.len<=0) {
		LM_ERR("invalid r-uri PV string\n");
		return -1;
	}

	if(pv_parse_format(&ruri_pvar_param, &ruri_param_model) < 0
				|| ruri_param_model==NULL) {
		LM_ERR("malformed r-uri PV string: %s\n", ruri_pvar_param.s);
		return -1;
	}

	if (initial_cbs_inscript != 0 && initial_cbs_inscript != 1) {
		LM_ERR("invalid parameter for running initial callbacks in-script"
				" (must be either 0 or 1)\n");
		return -1;
	}

	if (seq_match_mode!=SEQ_MATCH_NO_ID &&
	seq_match_mode!=SEQ_MATCH_FALLBACK &&
	seq_match_mode!=SEQ_MATCH_STRICT_ID ) {
		LM_ERR("invalid value %d for seq_match_mode param!!\n",seq_match_mode);
		return -1;
	}

	if (detect_spirals != 0 && detect_spirals != 1) {
		LM_ERR("invalid value %d for detect_spirals param!!\n",detect_spirals);
		return -1;
	}

	if (dlg_timeout_noreset != 0 && dlg_timeout_noreset != 1) {
		LM_ERR("invalid value %d for timeout_noreset param!!\n",
				dlg_timeout_noreset);
		return -1;
	}

	/* if statistics are disabled, prevent their registration to core */
	if (dlg_enable_stats==0)
		exports.stats = 0;

	/* create profile hashes */
	if (add_profile_definitions( profiles_nv_s, 0)!=0 ) {
		LM_ERR("failed to add profiles without value\n");
		return -1;
	}
	if (add_profile_definitions( profiles_wv_s, 1)!=0 ) {
		LM_ERR("failed to add profiles with value\n");
		return -1;
	}

	/* load the TM API */
	if (load_tm_api(&d_tmb)!=0) {
		LM_ERR("can't load TM API\n");
		return -1;
	}

	/* load RR API also */
	if (load_rr_api(&d_rrb)!=0) {
		LM_ERR("can't load RR API\n");
		return -1;
	}

	/* register callbacks*/
	/* listen for all incoming requests  */
	if ( d_tmb.register_tmcb( 0, 0, TMCB_REQUEST_IN, dlg_onreq, 0, 0 ) <=0 ) {
		LM_ERR("cannot register TMCB_REQUEST_IN callback\n");
		return -1;
	}

	/* listen for all routed requests  */
	if ( d_rrb.register_rrcb( dlg_onroute, 0 ) <0 ) {
		LM_ERR("cannot register RR callback\n");
		return -1;
	}

	if (register_script_cb( profile_cleanup, POST_SCRIPT_CB|REQUEST_CB,0)<0) {
		LM_ERR("cannot register script callback");
		return -1;
	}
	if (register_script_cb(dlg_cfg_cb,
				PRE_SCRIPT_CB|REQUEST_CB,0)<0)
	{
		LM_ERR("cannot register pre-script ctx callback\n");
		return -1;
	}
	if (register_script_cb(dlg_cfg_cb,
				POST_SCRIPT_CB|REQUEST_CB,0)<0)
	{
		LM_ERR("cannot register post-script ctx callback\n");
		return -1;
	}

	if (register_script_cb( spiral_detect_reset, POST_SCRIPT_CB|REQUEST_CB,0)<0) {
		LM_ERR("cannot register req pre-script spiral detection reset callback\n");
		return -1;
	}

	if(dlg_timer_procs<=0) {
		if ( register_timer( dlg_timer_routine, 0, 1)<0 ) {
			LM_ERR("failed to register timer \n");
			return -1;
		}
	} else {
		register_sync_timers(1);
	}

	/* init handlers */
	init_dlg_handlers( rr_param, dlg_flag,
		timeout_spec.s?&timeout_avp:0, default_timeout, seq_match_mode);

	/* init timer */
	if (init_dlg_timer(dlg_ontimeout)!=0) {
		LM_ERR("cannot init timer list\n");
		return -1;
	}

	/* sanitize dlg_hash_zie */
	if (dlg_hash_size < 1){
		LM_WARN("hash_size is smaller "
				"then 1  -> rounding from %d to 1\n",
				dlg_hash_size);
		dlg_hash_size = 1;
	}
	/* initialized the hash table */
	for( n=0 ; n<(8*sizeof(n)) ; n++) {
		if (dlg_hash_size==(1<<n))
			break;
		if (n && dlg_hash_size<(1<<n)) {
			LM_WARN("hash_size is not a power "
				"of 2 as it should be -> rounding from %d to %d\n",
				dlg_hash_size, 1<<(n-1));
			dlg_hash_size = 1<<(n-1);
		}
	}

	if ( init_dlg_table(dlg_hash_size)<0 ) {
		LM_ERR("failed to create hash table\n");
		return -1;
	}

	/* if a database should be used to store the dialogs' information */
	dlg_db_mode = dlg_db_mode_param;
	if (dlg_db_mode==DB_MODE_NONE) {
		db_url.s = 0; db_url.len = 0;
	} else {
		if (dlg_db_mode!=DB_MODE_REALTIME &&
		dlg_db_mode!=DB_MODE_DELAYED && dlg_db_mode!=DB_MODE_SHUTDOWN ) {
			LM_ERR("unsupported db_mode %d\n", dlg_db_mode);
			return -1;
		}
		if ( !db_url.s || db_url.len==0 ) {
			LM_ERR("db_url not configured for db_mode %d\n", dlg_db_mode);
			return -1;
		}
		if (init_dlg_db(&db_url, dlg_hash_size, db_update_period,db_fetch_rows)!=0) {
			LM_ERR("failed to initialize the DB support\n");
			return -1;
		}
		run_load_callbacks();
	}

	destroy_dlg_callbacks( DLGCB_LOADED );

	/* timer process to send keep alive requests */
	if(dlg_ka_timer>0 && dlg_ka_interval>0)
		register_sync_timers(1);

	/* timer process to clean old unconfirmed dialogs */
	register_sync_timers(1);

	return 0;
}