Beispiel #1
0
/** Parse MRCP message (excluding message body) */
MRCP_DECLARE(apt_bool_t) mrcp_message_parse(mrcp_resource_factory_t *resource_factory, mrcp_message_t *message, apt_text_stream_t *stream)
{
	mrcp_resource_t *resource;

	/* parse start-line */
	if(mrcp_start_line_parse(&message->start_line,stream,message->pool) == FALSE) {
		return FALSE;
	}

	if(message->start_line.version == MRCP_VERSION_2) {
		mrcp_channel_id_parse(&message->channel_id,stream,message->pool);
	}

	/* find resource */
	resource = mrcp_resource_find(resource_factory,&message->channel_id.resource_name);
	if(!resource) {
		return FALSE;
	}

	if(mrcp_message_resource_set(message,resource) == FALSE) {
		return FALSE;
	}

	/* parse header */
	if(mrcp_message_header_parse(&message->header,stream,message->pool) == FALSE) {
		return FALSE;
	}

	return TRUE;
}
/** Create message and read start line */
static apt_bool_t mrcp_parser_on_start(apt_message_parser_t *parser, apt_message_context_t *context, apt_text_stream_t *stream, apr_pool_t *pool)
{
	mrcp_message_t *mrcp_message;
	apt_str_t start_line;
	/* read start line */
	if(apt_text_line_read(stream,&start_line) == FALSE) {
		return FALSE;
	}

	/* create new MRCP message */
	mrcp_message = mrcp_message_create(pool);
	/* parse start-line */
	if(mrcp_start_line_parse(&mrcp_message->start_line,&start_line,mrcp_message->pool) == FALSE) {
		return FALSE;
	}

	if(mrcp_message->start_line.version == MRCP_VERSION_1) {
		mrcp_parser_t *mrcp_parser = apt_message_parser_object_get(parser);
		if(!mrcp_parser->resource) {
			return FALSE;
		}
		apt_string_copy(
			&mrcp_message->channel_id.resource_name,
			&mrcp_parser->resource->name,
			pool);

		if(mrcp_message_resource_set(mrcp_message,mrcp_parser->resource) == FALSE) {
			return FALSE;
		}
	}

	context->message = mrcp_message;
	context->header = &mrcp_message->header.header_section;
	context->body = &mrcp_message->body;
	return TRUE;
}