예제 #1
0
/** Load UniRTSP signaling agent */
static apt_bool_t unimrcp_client_rtsp_uac_load(unimrcp_client_loader_t *loader, const apr_xml_elem *root, const char *id)
{
	const apr_xml_elem *elem;
	mrcp_sig_agent_t *agent;
	rtsp_client_config_t *config;

	config = mrcp_unirtsp_client_config_alloc(loader->pool);
	config->origin = DEFAULT_SDP_ORIGIN;

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading UniRTSP Agent <%s>",id);
	for(elem = root->first_child; elem; elem = elem->next) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Element <%s>",elem->name);
		if(strcasecmp(elem->name,"sdp-origin") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->origin = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"max-connection-count") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->max_connection_count = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"request-timeout") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->request_timeout = atol(cdata_text_get(elem));
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name);
		}
	}
	
	agent = mrcp_unirtsp_client_agent_create(id,config,loader->pool);
	return mrcp_client_signaling_agent_register(loader->client,agent);
}
예제 #2
0
/** Load SofiaSIP signaling agent */
static apt_bool_t unimrcp_client_sip_uac_load(unimrcp_client_loader_t *loader, const apr_xml_elem *root, const char *id)
{
	const apr_xml_elem *elem;
	mrcp_sig_agent_t *agent;
	mrcp_sofia_client_config_t *config;

	config = mrcp_sofiasip_client_config_alloc(loader->pool);
	config->local_port = DEFAULT_SIP_PORT;
	config->user_agent_name = DEFAULT_SOFIASIP_UA_NAME;
	config->origin = DEFAULT_SDP_ORIGIN;

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading SofiaSIP Agent <%s>",id);
	for(elem = root->first_child; elem; elem = elem->next) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Element <%s>",elem->name);
		if(strcasecmp(elem->name,"sip-ip") == 0) {
			config->local_ip = unimrcp_client_ip_address_get(loader,elem,loader->ip);
		}
		else if(strcasecmp(elem->name,"sip-ext-ip") == 0) {
			config->ext_ip = unimrcp_client_ip_address_get(loader,elem,loader->ext_ip);
		}
		else if(strcasecmp(elem->name,"sip-port") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->local_port = (apr_port_t)atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-transport") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->transport = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"ua-name") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->user_agent_name = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"sdp-origin") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->origin = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"sip-t1") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t1 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t2") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t2 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t4") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t4 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t1x64") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t1x64 = atol(cdata_text_get(elem));
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name);
		}
	}

	if(!config->local_ip) {
		/* use default ip address if not specified */
		config->local_ip = apr_pstrdup(loader->pool,loader->ip);
	}
	if(!config->ext_ip && loader->ext_ip) {
		/* use default ext ip address if not specified */
		config->ext_ip = apr_pstrdup(loader->pool,loader->ext_ip);
	}

	agent = mrcp_sofiasip_client_agent_create(id,config,loader->pool);
	return mrcp_client_signaling_agent_register(loader->client,agent);
}
예제 #3
0
/** Load SofiaSIP signaling agent */
static apt_bool_t unimrcp_client_sip_uac_load(unimrcp_client_loader_t *loader, const apr_xml_elem *root, const char *id)
{
	const apr_xml_elem *elem;
	mrcp_sig_agent_t *agent;
	mrcp_sofia_client_config_t *config;

	config = mrcp_sofiasip_client_config_alloc(loader->pool);
	config->local_port = DEFAULT_SIP_PORT;
	config->user_agent_name = DEFAULT_SOFIASIP_UA_NAME;
	config->origin = DEFAULT_SDP_ORIGIN;

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading SofiaSIP Agent <%s>",id);
	for(elem = root->first_child; elem; elem = elem->next) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Loading Element <%s>",elem->name);
		if(strcasecmp(elem->name,"sip-ip") == 0) {
			config->local_ip = unimrcp_client_ip_address_get(loader,elem,loader->ip);
		}
		else if(strcasecmp(elem->name,"sip-ext-ip") == 0) {
			config->ext_ip = unimrcp_client_ip_address_get(loader,elem,loader->ext_ip);
		}
		else if(strcasecmp(elem->name,"sip-port") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->local_port = (apr_port_t)atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-transport") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->transport = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"ua-name") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				const apr_xml_attr *attr = NULL;
				for(attr = elem->attr; attr; attr = attr->next) {
					if(strcasecmp(attr->name,"appendversion") == 0) {
						break;
					}
				}
				if(is_attr_enabled(attr)) {
					config->user_agent_name = apr_psprintf(loader->pool,"%s "UNI_VERSION_STRING,cdata_text_get(elem));
				}
				else {
					config->user_agent_name = cdata_copy(elem,loader->pool);
				}
			}
		}
		else if(strcasecmp(elem->name,"sdp-origin") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->origin = cdata_copy(elem,loader->pool);
			}
		}
		else if(strcasecmp(elem->name,"sip-t1") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t1 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t2") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t2 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t4") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t4 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-t1x64") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->sip_t1x64 = atol(cdata_text_get(elem));
			}
		}
		else if(strcasecmp(elem->name,"sip-message-output") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				config->tport_log = cdata_bool_get(elem);
			}
		}
		else if(strcasecmp(elem->name,"sip-message-dump") == 0) {
			if(is_cdata_valid(elem) == TRUE) {
				const char *root_path;
				const char *path = cdata_text_get(elem);
				if(loader->dir_layout && apr_filepath_root(&root_path,&path,0,loader->pool) == APR_ERELATIVE)
					config->tport_dump_file = apt_dir_layout_path_compose(
													loader->dir_layout,
													APT_LAYOUT_LOG_DIR,
													path,
													loader->pool);
				else
					config->tport_dump_file = cdata_copy(elem,loader->pool);
			}
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Unknown Element <%s>",elem->name);
		}
	}

	if(!config->local_ip) {
		/* use default IP address if not specified */
		config->local_ip = apr_pstrdup(loader->pool,loader->ip);
	}
	if(!config->ext_ip && loader->ext_ip) {
		/* use default ext IP address if not specified */
		config->ext_ip = apr_pstrdup(loader->pool,loader->ext_ip);
	}

	agent = mrcp_sofiasip_client_agent_create(id,config,loader->pool);
	return mrcp_client_signaling_agent_register(loader->client,agent);
}
예제 #4
0
/* --- MRCP CLIENT --- */
static int load_profiles(mrcp_client_t *client, mrcp_connection_agent_t *shared_connection_agent, mpf_engine_t *shared_media_engine, apr_pool_t *pool)
{
	apr_hash_index_t *hi;

	for (hi = apr_hash_first(NULL, globals.profiles); hi; hi = apr_hash_next(hi)) {
		const char *k;
		ast_mrcp_profile_t *v;
		const void *key;
		void *val;

		apr_hash_this(hi, &key, NULL, &val);

		k = (const char *)key;
		v = (ast_mrcp_profile_t *)val;

		if (v == NULL) continue;

		ast_log(LOG_DEBUG, "Processing profile %s:%s\n", k, v->version);

		/* A profile is a signaling agent + termination factory + media engine + connection agent (MRCPv2 only). */
		mrcp_sig_agent_t *agent = NULL;
		mpf_termination_factory_t *termination_factory = NULL;
		mrcp_profile_t * mprofile = NULL;
		mpf_rtp_config_t *rtp_config = NULL;
		mpf_rtp_settings_t *rtp_settings = mpf_rtp_settings_alloc(pool);
		mrcp_sig_settings_t *sig_settings = mrcp_signaling_settings_alloc(pool);
		ast_mrcp_profile_t *mod_profile = NULL;
		mrcp_connection_agent_t *connection_agent = NULL;
		mpf_engine_t *media_engine = shared_media_engine;

		/* Get profile attributes. */
		const char *name = apr_pstrdup(pool, k);
		const char *version = apr_pstrdup(pool, v->version);

		if ((name == NULL) || (strlen(name) == 0) || (version == NULL) || (strlen(version) == 0)) {
			ast_log(LOG_ERROR, "Profile %s missing name or version attribute\n", k);
			return -1;
		}

		// i6net Get the profile set before from the configuration file.
    mod_profile = (ast_mrcp_profile_t *)apr_hash_get(globals.profiles, name, APR_HASH_KEY_STRING);

		/* Create RTP config, common to MRCPv1 and MRCPv2. */
		if ((rtp_config = mpf_rtp_config_alloc(pool)) == NULL) {
			ast_log(LOG_ERROR, "Unable to create RTP configuration\n");
			return -1;
		}

		rtp_config->rtp_port_min = DEFAULT_RTP_PORT_MIN;
		rtp_config->rtp_port_max = DEFAULT_RTP_PORT_MAX;
		apt_string_set(&rtp_config->ip, DEFAULT_LOCAL_IP_ADDRESS);

		if (strcmp("1", version) == 0) {
			/* MRCPv1 configuration. */
			rtsp_client_config_t *config = mrcp_unirtsp_client_config_alloc(pool);

			if (config == NULL) {
				ast_log(LOG_ERROR, "Unable to create RTSP configuration\n");
				return -1;
			}

			config->origin = DEFAULT_SDP_ORIGIN;
			if (globals.unimrcp_request_timeout != NULL) {
				config->request_timeout = (apr_size_t)atol(globals.unimrcp_request_timeout);
			}
			sig_settings->resource_location = DEFAULT_RESOURCE_LOCATION;

			ast_log(LOG_DEBUG, "Loading MRCPv1 profile: %s\n", name);

			apr_hash_index_t *hicfg;

			for (hicfg = apr_hash_first(NULL, v->cfg); hicfg; hicfg = apr_hash_next(hicfg)) {
				const char *param_name;
				const char *param_value;
				const void *keyc;
				void *valc;

				apr_hash_this(hicfg, &keyc, NULL, &valc);

				param_name = (const char *)keyc;
				param_value = (const char *)valc;

				if ((param_name != NULL) && (param_value != NULL)) {
					if (strlen(param_name) == 0) {
						ast_log(LOG_ERROR, "Missing parameter name\n");
						return -1;
					}

					ast_log(LOG_DEBUG, "Loading parameter %s:%s\n", param_name, param_value);

					if ((!process_mrcpv1_config(config, sig_settings, param_name, param_value, pool)) &&
						(!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool)) &&
						(!process_profile_config(mod_profile, param_name, param_value, pool))) {
						ast_log(LOG_WARNING, "Unknown parameter %s\n", param_name);
					}
				}
			}

			agent = mrcp_unirtsp_client_agent_create(name, config, pool);
		} else if (strcmp("2", version) == 0) {
			/* MRCPv2 configuration. */
			mrcp_sofia_client_config_t *config = mrcp_sofiasip_client_config_alloc(pool);

			if (config == NULL) {
				ast_log(LOG_ERROR, "Unable to create SIP configuration\n");
				return -1;
			}

			config->local_ip = DEFAULT_LOCAL_IP_ADDRESS;
			config->local_port = DEFAULT_SIP_LOCAL_PORT;
			sig_settings->server_ip = DEFAULT_REMOTE_IP_ADDRESS;
			sig_settings->server_port = DEFAULT_SIP_REMOTE_PORT;
			config->ext_ip = NULL;
			config->user_agent_name = DEFAULT_SOFIASIP_UA_NAME;
			config->origin = DEFAULT_SDP_ORIGIN;

			ast_log(LOG_DEBUG, "Loading MRCPv2 profile: %s\n", name);

			apr_hash_index_t *hicfg;

			for (hicfg = apr_hash_first(NULL, v->cfg); hicfg; hicfg = apr_hash_next(hicfg)) {
				const char *param_name;
				const char *param_value;
				const void *keyc;
				void *valc;

				apr_hash_this(hicfg, &keyc, NULL, &valc);

				param_name = (const char *)keyc;
				param_value = (const char *)valc;

				if ((param_name != NULL) && (param_value != NULL)) {
					if (strlen(param_name) == 0) {
						ast_log(LOG_ERROR, "Missing parameter name\n");
						return -1;
					}

					ast_log(LOG_DEBUG, "Loading parameter %s:%s\n", param_name, param_value);

					if ((!process_mrcpv2_config(config, sig_settings, param_name, param_value, pool)) &&
						(!process_rtp_config(client, rtp_config, rtp_settings, param_name, param_value, pool)) &&
						(!process_profile_config(mod_profile, param_name, param_value, pool))) {
						ast_log(LOG_WARNING, "Unknown parameter %s\n", param_name);
					}
				}
			}

			agent = mrcp_sofiasip_client_agent_create(name, config, pool);
			connection_agent = shared_connection_agent;
		} else {
			ast_log(LOG_ERROR, "Version must be either \"1\" or \"2\"\n");
			return -1;
		}

		if ((termination_factory = mpf_rtp_termination_factory_create(rtp_config, pool)) != NULL)
			mrcp_client_rtp_factory_register(client, termination_factory, name);

		mrcp_client_rtp_settings_register(client, rtp_settings, "RTP-Settings");
		mrcp_client_signaling_settings_register(client, sig_settings, "Signalling-Settings");

		if (agent != NULL)
			mrcp_client_signaling_agent_register(client, agent);

		/* Create the profile and register it. */
		if ((mprofile = mrcp_client_profile_create(NULL, agent, connection_agent, media_engine, termination_factory, rtp_settings, sig_settings, pool)) != NULL) {
			if (!mrcp_client_profile_register(client, mprofile, name))
				ast_log(LOG_WARNING, "Unable to register MRCP client profile\n");
		}
	}

	return 0;
}