Example #1
0
/*获得对应的domain名,从内存root结构中查找下面的字段
*<list name="domains" default="deny">
*<node type="allow" domain="192.168.17.123"/>
*</list>
*
*或者使用internal profile的配置项
*<param name="force-register-domain" value="192.168.17.123"/>
*/
char * CBaseModule::getDomainIP()
{
	if (NULL != m_localIP){
		return m_localIP;
	}

	//	char *profile_name = CARICCP_SIP_PROFILES_INTERNAL; //根据此internal.xml文件的结构设置
	//	char *domain_name = NULL;//"192.168.17.123";
	//	switch_xml_t x_root, x_section, x_config, x_networklists, x_list, x_node;
	//	x_root = switch_xml_root();
	//	if (!x_root) {
	//		goto mid_flag;
	//	}
	//
	//	//方法1 :通过访问控制列表ACL获得,但是这种方法不可靠
	//	//<section name="configuration" description="Various Configuration">
	//	x_section = switch_xml_find_child(x_root, "section", "name", "configuration");
	//	if (!x_section) {
	//		goto mid_flag;
	//	}
	//	//<configuration name="acl.conf" description="Network Lists">
	//	x_config = switch_xml_find_child(x_section, "configuration", "name", "acl.conf");
	//	if (!x_config) {
	//		goto mid_flag;
	//	}
	//	// <network-lists>
	//	//  <list name="domains" default="deny">
	//	//	  <node type="allow" domain="192.168.17.123"/>
	//	//	</list>
	//	x_networklists = switch_xml_child(x_config, "network-lists");
	//	if (!x_networklists) {
	//		goto mid_flag;
	//	}
	//	x_list = switch_xml_find_child(x_networklists, "list", "name", "domains");
	//	if (!x_list) {
	//		goto mid_flag;
	//	}
	//	x_node = switch_xml_find_child(x_list, "node", "type", "allow");
	//	if (!x_node) {
	//		goto mid_flag;
	//	}
	//	//<node type="allow" domain="192.168.17.123"/>
	//	domain_name = (char*) switch_xml_attr(x_node, "domain");
	//
	//mid_flag:
	//	if (!switch_strlen_zero(domain_name)) {
	//		goto end_flag;
	//	}

	//方法2 :通过获得本机的IP地址,如果是双网卡呢???
	char guess_ip4[256] = "";
	switch_find_local_ip(guess_ip4, sizeof(guess_ip4),NULL,AF_INET);//这个函数因为版本的不同而不同
	//domain_name = guess_ip4;//临时变量,直接赋值无效
	m_localIP = switch_mprintf("%s", guess_ip4);

	//end_flag:
	return /*domain_name*/m_localIP;
}
Example #2
0
SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
{
	/* try free dynamic data structures prior to resetting to 0 */
	FreeUPNPUrls(&nat_globals.urls);
	switch_safe_free(nat_globals.descURL);

	memset(&nat_globals, 0, sizeof(nat_globals));

	if (first_init) {
		memset(&nat_globals_perm, 0, sizeof(nat_globals_perm));
		nat_globals_perm.pool = pool;
	}

	switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET);


	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Scanning for NAT\n");

	init_pmp();

	if (!nat_globals.nat_type) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n");
		init_upnp();
	}

	if (nat_globals.nat_type) {
		switch_core_set_variable("nat_public_addr", nat_globals.pub_addr);
		switch_core_set_variable("nat_private_addr", nat_globals.pvt_addr);
		switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s, ExtIP: '%s'\n",
						  nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp", nat_globals.pub_addr);

		if (!nat_thread_p) {
			switch_nat_thread_start();
		}
	} else {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or UPnP NAT devices detected!\n");
	}
	first_init = SWITCH_FALSE;
	initialized = SWITCH_TRUE;
}
static int sangoma_parse_config(void)
{
	switch_xml_t cfg, settings, param, xml;
	struct in_addr rtpaddr;
	char localip[255];
	int mask = 0;
	int rc = 0;

	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Reading sangoma codec configuration\n");
	if (!(xml = switch_xml_open_cfg(SANGOMA_TRANSCODE_CONFIG, &cfg, NULL))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to open sangoma codec configuration %s\n", SANGOMA_TRANSCODE_CONFIG);
		return -1;
	}

	memset(&g_init_cfg, 0, sizeof(g_init_cfg));

	if ((settings = switch_xml_child(cfg, "settings"))) {
		for (param = switch_xml_child(settings, "param"); param; param = param->next) {
				char *var = (char *)switch_xml_attr_soft(param, "name");
				char *val = (char *)switch_xml_attr_soft(param, "value");

				/* this parameter overrides the default list of codecs to load */
				if (!strcasecmp(var, "register")) {
					strncpy(g_codec_register_list, val, sizeof(g_codec_register_list)-1);
					g_codec_register_list[sizeof(g_codec_register_list)-1] = 0;
				} else if (!strcasecmp(var, "noregister")) {
					strncpy(g_codec_noregister_list, val, sizeof(g_codec_noregister_list)-1);
					g_codec_noregister_list[sizeof(g_codec_noregister_list)-1] = 0;
				} else if (!strcasecmp(var, "soapserver")) {
					strncpy(g_soap_url, val, sizeof(g_soap_url)-1);
					g_soap_url[sizeof(g_soap_url)-1] = 0;
				} else if (!strcasecmp(var, "rtpip")) {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found Sangoma RTP IP %s\n", val);
					if (switch_inet_pton(AF_INET, val, &rtpaddr) <= 0) {
						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Sangoma RTP IP %s\n", val);
						break;
					}
					g_rtpip = ntohl(rtpaddr.s_addr);
				} else {
					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma codec setting %s\n", var);
				}
		}
	}

	if (!g_rtpip) {
		if (SWITCH_STATUS_SUCCESS != switch_find_local_ip(localip, sizeof(localip), &mask, AF_INET)) {
			rc = -1;
			goto done;
		}
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "No RTP IP specified, using %s\n", localip);
		switch_inet_pton(AF_INET, localip, &rtpaddr);
		g_rtpip = ntohl(rtpaddr.s_addr);
	}

done:
	switch_xml_free(xml);

	g_init_cfg.host_nic_vocallo_sz = 0;

	return rc;
}