static apt_bool_t mrcp_client_message_handler(mrcp_connection_t *connection, mrcp_message_t *message, apt_message_status_e status)
{
	if(status == APT_MESSAGE_STATUS_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel;
		apt_str_t identifier;
		apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,message->pool);
		channel = mrcp_connection_channel_find(connection,&identifier);
		if(channel) {
			mrcp_connection_agent_t *agent = connection->agent;
			if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
				if(!channel->active_request || 
					channel->active_request->start_line.request_id != message->start_line.request_id) {
					apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Unexpected MRCP Response "APT_SIDRES_FMT" [%d]",
						MRCP_MESSAGE_SIDRES(message),
						message->start_line.request_id);
					return FALSE;
				}
				if(channel->request_timer) {
					apt_timer_kill(channel->request_timer);
				}
				channel->active_request = NULL;
			}

			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel "APT_SIDRES_FMT" in Connection %s [%d]",
				MRCP_MESSAGE_SIDRES(message),
				connection->id,
				apr_hash_count(connection->channel_table));
		}
	}
	return TRUE;
}
static mrcp_control_channel_t* mrcp_connection_channel_associate(mrcp_connection_agent_t *agent, mrcp_connection_t *connection, const mrcp_message_t *message)
{
	apt_str_t identifier;
	mrcp_control_channel_t *channel;
	if(!connection || !message) {
		return NULL;
	}
	apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,connection->pool);
	channel = mrcp_connection_channel_find(connection,&identifier);
	if(!channel) {
		channel = mrcp_connection_channel_find(agent->null_connection,&identifier);
		if(channel) {
			mrcp_connection_channel_remove(agent->null_connection,channel);
			mrcp_connection_channel_add(connection,channel);
			apt_log(APT_PRIO_INFO,"Move Control Channel <%s> to Connection [%d]",
				channel->identifier.buf,
				apr_hash_count(connection->channel_table));
		}
	}
	return channel;
}
static apt_bool_t mrcp_client_message_handler(void *obj, mrcp_message_t *message, mrcp_stream_result_e result)
{
	if(result == MRCP_STREAM_MESSAGE_COMPLETE) {
		/* message is completely parsed */
		mrcp_connection_t *connection = obj;
		mrcp_control_channel_t *channel;
		apt_str_t identifier;
		apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,message->pool);
		channel = mrcp_connection_channel_find(connection,&identifier);
		if(channel) {
			mrcp_connection_agent_t *agent = connection->agent;
			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel <%s@%s>",
				message->channel_id.session_id.buf,
				message->channel_id.resource_name.buf);
		}
	}
	return TRUE;
}
static mrcp_control_channel_t* mrcp_connection_channel_associate(mrcp_connection_agent_t *agent, mrcp_connection_t *connection, const mrcp_message_t *message)
{
	apt_str_t identifier;
	mrcp_control_channel_t *channel;
	if(!connection || !message) {
		return NULL;
	}
	apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,connection->pool);
	channel = mrcp_connection_channel_find(connection,&identifier);
	if(!channel) {
		channel = apr_hash_get(agent->pending_channel_table,identifier.buf,identifier.length);
		if(channel) {
			apr_hash_set(agent->pending_channel_table,identifier.buf,identifier.length,NULL);
			mrcp_connection_channel_add(connection,channel);
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Assign Control Channel <%s> to Connection %s [%d] -> [%d]",
				channel->identifier.buf,
				connection->id,
				apr_hash_count(agent->pending_channel_table),
				apr_hash_count(connection->channel_table));
		}
	}
	return channel;
}
static apt_bool_t mrcp_client_agent_messsage_receive(mrcp_connection_agent_t *agent, mrcp_connection_t *connection)
{
	char buffer[MRCP_MESSAGE_MAX_SIZE];
	apt_bool_t more_messages_on_buffer = FALSE;
	apr_status_t status;
	apt_text_stream_t text_stream;
	mrcp_message_t *message;

	if(!connection || !connection->sock) {
		return FALSE;
	}

	text_stream.text.buf = buffer;
	text_stream.text.length = sizeof(buffer)-1;
	status = apr_socket_recv(connection->sock, text_stream.text.buf, &text_stream.text.length);
	if(status == APR_EOF || text_stream.text.length == 0) {
		apt_log(APT_PRIO_NOTICE,"TCP/MRCPv2 Connection Disconnected");
		apr_pollset_remove(agent->pollset,&connection->sock_pfd);
		apr_socket_close(connection->sock);
		connection->sock = NULL;

//		agent->vtable->on_disconnect(agent,connection);
		return TRUE;
	}
	text_stream.text.buf[text_stream.text.length] = '\0';
	text_stream.pos = text_stream.text.buf;

	apt_log(APT_PRIO_INFO,"Receive MRCPv2 Message size=%lu\n%s",text_stream.text.length,text_stream.text.buf);
	if(!connection->access_count) {
		return FALSE;
	}

	do {
		message = mrcp_message_create(connection->pool);
		if(mrcp_message_parse(agent->resource_factory,message,&text_stream) == TRUE) {
			mrcp_control_channel_t *channel;
			apt_str_t identifier;
			apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,connection->pool);
			channel = mrcp_connection_channel_find(connection,&identifier);
			if(channel) {
				mrcp_connection_message_receive(agent->vtable,channel,message);
			}
			else {
				apt_log(APT_PRIO_WARNING,"Failed to Find Channel <%s@%s>",
					message->channel_id.session_id.buf,
					message->channel_id.resource_name.buf);
			}
		}
		else {
			apt_log(APT_PRIO_WARNING,"Failed to Parse MRCPv2 Message");
			if(message->start_line.version == MRCP_VERSION_2) {
				/* assume that at least message length field is valid */
				if(message->start_line.length <= text_stream.text.length) {
					/* skip to the end of the message */
					text_stream.pos = text_stream.text.buf + message->start_line.length;
				}
				else {
					/* skip to the end of the buffer (support incomplete) */
					text_stream.pos = text_stream.text.buf + text_stream.text.length;
				}
			}
		}

		more_messages_on_buffer = FALSE;
		if(text_stream.text.length > (apr_size_t)(text_stream.pos - text_stream.text.buf)) {
			/* there are more MRCPv2 messages to signal */
			more_messages_on_buffer = TRUE;
			text_stream.text.length -= text_stream.pos - text_stream.text.buf;
			text_stream.text.buf = text_stream.pos;
			apt_log(APT_PRIO_DEBUG,"Saving Remaining Buffer for Next Message");
		}
	}
	while(more_messages_on_buffer);
	return TRUE;
}