<commit_before>/*
 * Copyright 2008 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "unimrcp_server.h"
#include "mrcp_default_factory.h"
#include "mpf_engine.h"
#include "mpf_rtp_termination_factory.h"
#include "mrcp_sofiasip_agent.h"
#include "apt_log.h"

static mrcp_sig_agent_t* mrcpv2_sig_agent_create(apr_pool_t *pool);
static mrcp_sig_agent_t* mrcpv1_sig_agent_create(apr_pool_t *pool);

/** Start UniMRCP server */
MRCP_DECLARE(mrcp_server_t*) unimrcp_server_start()
{
	apr_pool_t *pool;
	mrcp_resource_factory_t *resource_factory;
	mpf_engine_t *media_engine;
	mrcp_sig_agent_t *sig_agent;
	mrcp_server_t *server = mrcp_server_create();
	if(!server) {
		return NULL;
	}
	pool = mrcp_server_memory_pool_get(server);

	resource_factory = mrcp_default_factory_create(pool);
	if(resource_factory) {
		mrcp_server_resource_factory_register(server,resource_factory);
	}
	media_engine = mpf_engine_create(pool);
	if(media_engine) {
		mpf_termination_factory_t *rtp_termination_factory = mpf_rtp_termination_factory_create(
			"127.0.0.1",5000,6000,pool);

		mrcp_server_media_engine_register(server,media_engine);
		mrcp_server_rtp_termination_factory_register(server,rtp_termination_factory);
	}
	sig_agent = mrcpv2_sig_agent_create(pool);
	if(sig_agent) {
		mrcp_server_signaling_agent_register(server,sig_agent);
	}

	mrcp_server_start(server);
	return server;
}

/** Shutdown UniMRCP server */
MRCP_DECLARE(apt_bool_t) unimrcp_server_shutdown(mrcp_server_t *server)
{
	if(mrcp_server_shutdown(server) == FALSE) {
		return FALSE;
	}
	return mrcp_server_destroy(server);
}

static mrcp_sig_agent_t* mrcpv2_sig_agent_create(apr_pool_t *pool)
{
	mrcp_sofia_config_t *config = mrcp_sofiasip_config_alloc(pool);
	config->local_ip = "0.0.0.0";
	config->local_port = 8060;
	config->user_agent_name = "UniMRCP Sofia-SIP";
	config->origin = "UniMRCPServer";
	return mrcp_sofiasip_agent_create(config,pool);
}

static mrcp_sig_agent_t* mrcpv1_sig_agent_create(apr_pool_t *pool)
{
	return NULL;
}
<commit_msg>multiple signaling agents might be registered at the same time<commit_after>/*
 * Copyright 2008 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "unimrcp_server.h"
#include "mrcp_default_factory.h"
#include "mpf_engine.h"
#include "mpf_rtp_termination_factory.h"
#include "mrcp_sofiasip_agent.h"
#include "apt_log.h"

static mrcp_sig_agent_t* mrcpv2_sig_agent_create(apr_pool_t *pool);
static mrcp_sig_agent_t* mrcpv1_sig_agent_create(apr_pool_t *pool);

/** Start UniMRCP server */
MRCP_DECLARE(mrcp_server_t*) unimrcp_server_start()
{
	apr_pool_t *pool;
	mrcp_resource_factory_t *resource_factory;
	mpf_engine_t *media_engine;
	mrcp_sig_agent_t *sig_agent;
	mrcp_server_t *server = mrcp_server_create();
	if(!server) {
		return NULL;
	}
	pool = mrcp_server_memory_pool_get(server);

	resource_factory = mrcp_default_factory_create(pool);
	if(resource_factory) {
		mrcp_server_resource_factory_register(server,resource_factory);
	}
	media_engine = mpf_engine_create(pool);
	if(media_engine) {
		mpf_termination_factory_t *rtp_termination_factory = mpf_rtp_termination_factory_create(
			"127.0.0.1",5000,6000,pool);

		mrcp_server_media_engine_register(server,media_engine);
		mrcp_server_rtp_termination_factory_register(server,rtp_termination_factory);
	}
	sig_agent = mrcpv2_sig_agent_create(pool);
	if(sig_agent) {
		mrcp_server_signaling_agent_register(server,sig_agent);
	}
	sig_agent = mrcpv1_sig_agent_create(pool);
	if(sig_agent) {
		mrcp_server_signaling_agent_register(server,sig_agent);
	}

	mrcp_server_start(server);
	return server;
}

/** Shutdown UniMRCP server */
MRCP_DECLARE(apt_bool_t) unimrcp_server_shutdown(mrcp_server_t *server)
{
	if(mrcp_server_shutdown(server) == FALSE) {
		return FALSE;
	}
	return mrcp_server_destroy(server);
}

static mrcp_sig_agent_t* mrcpv2_sig_agent_create(apr_pool_t *pool)
{
	mrcp_sofia_config_t *config = mrcp_sofiasip_config_alloc(pool);
	config->local_ip = "0.0.0.0";
	config->local_port = 8060;
	config->user_agent_name = "UniMRCP Sofia-SIP";
	config->origin = "UniMRCPServer";
	return mrcp_sofiasip_agent_create(config,pool);
}

static mrcp_sig_agent_t* mrcpv1_sig_agent_create(apr_pool_t *pool)
{
	return NULL;
}

{'fraction_non_alphanumeric': 0.09547450830628222, 'fraction_numerical': 0.013557380179492075, 'mean_word_length': 6.569364161849711, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863706', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1977, 'n_words': 371}