/** Finalize multipart content generation */
APT_DECLARE(apt_str_t*) apt_multipart_content_finalize(apt_multipart_content_t *multipart_content)
{
	apt_text_stream_t *stream = &multipart_content->stream;
	/* insert preceding end-of-line */
	if(apt_text_eol_insert(&multipart_content->stream) == FALSE) {
		return NULL;
	}
	/* insert hyphens */
	if(apt_text_string_insert(&multipart_content->stream,&multipart_content->hyphens) == FALSE) {
		return NULL;
	}
	/* insert boundary */
	if(apt_text_string_insert(&multipart_content->stream,&multipart_content->boundary) == FALSE) {
		return NULL;
	}
	/* insert final hyphens */
	if(apt_text_string_insert(&multipart_content->stream,&multipart_content->hyphens) == FALSE) {
		return NULL;
	}
	if(apt_text_eol_insert(&multipart_content->stream) == FALSE) {
		return NULL;
	}

	stream->text.length = stream->pos - stream->text.buf;
	stream->text.buf[stream->text.length] = '\0';
	return &stream->text;
}
Exemple #2
0
/** Generate RTSP header */
RTSP_DECLARE(apt_bool_t) rtsp_header_generate(rtsp_header_t *header, apt_text_stream_t *text_stream)
{
    const apt_str_t *name;
    apr_size_t i;
    rtsp_header_property_t property_set;

    property_set = header->property_set;
    for(i=0; i<RTSP_HEADER_FIELD_COUNT && property_set != 0; i++) {
        if(rtsp_header_property_check(&property_set,i) == TRUE) {
            name = apt_string_table_str_get(rtsp_header_string_table,RTSP_HEADER_FIELD_COUNT,i);
            if(!name) {
                continue;
            }

            apt_text_header_name_generate(name,text_stream);
            rtsp_header_field_generate(header,i,text_stream);
            apt_text_eol_insert(text_stream);

            rtsp_header_property_remove(&property_set,i);
        }
    }

    apt_text_eol_insert(text_stream);
    return TRUE;
}
/** Add content part to multipart content by specified header fields and body */
APT_DECLARE(apt_bool_t) apt_multipart_content_add2(apt_multipart_content_t *multipart_content, const apt_str_t *content_type, const apt_str_t *content_id, const apt_str_t *body)
{
	/* insert preceding eol, hyppens and boudnary */
	if(apt_multipart_content_initialize(multipart_content) == FALSE) {
		return FALSE;
	}

	/* insert content-type */
	if(content_type) {
		apt_str_t name = {CONTENT_TYPE_HEADER,sizeof(CONTENT_TYPE_HEADER)-1};
		if(apt_text_name_value_insert(&multipart_content->stream,&name,content_type) == FALSE) {
			return FALSE;
		}
	}

	/* insert content-id */
	if(content_id) {
		apt_str_t name = {CONTENT_ID_HEADER,sizeof(CONTENT_ID_HEADER)-1};
		if(apt_text_name_value_insert(&multipart_content->stream,&name,content_id) == FALSE) {
			return FALSE;
		}
	}

	/* insert content-length */
	if(body) {
		apt_str_t name = {CONTENT_LENGTH_HEADER,sizeof(CONTENT_LENGTH_HEADER)-1};
		if(apt_text_header_name_insert(&multipart_content->stream,&name) == FALSE) {
			return FALSE;
		}
		if(apt_text_size_value_insert(&multipart_content->stream,body->length) == FALSE) {
			return FALSE;
		}
		if(apt_text_eol_insert(&multipart_content->stream) == FALSE) {
			return FALSE;
		}
	}

	/* insert empty line */
	if(apt_text_eol_insert(&multipart_content->stream) == FALSE) {
		return FALSE;
	}

	/* insert body */
	if(body) {
		if(apt_text_string_insert(&multipart_content->stream,body) == FALSE) {
			return FALSE;
		}
	}
	return TRUE;
}
/** Generate MRCP start-line */
MRCP_DECLARE(apt_bool_t) mrcp_start_line_generate(mrcp_start_line_t *start_line, apt_text_stream_t *text_stream)
{
	apt_bool_t status = FALSE;
	if(start_line->version == MRCP_VERSION_1) {
		switch(start_line->message_type) {
			case MRCP_MESSAGE_TYPE_REQUEST:
				status = mrcp_request_line_generate(start_line,text_stream);
				break;
			case MRCP_MESSAGE_TYPE_RESPONSE:
				status = mrcp_response_line_generate(start_line,text_stream);
				break;
			case MRCP_MESSAGE_TYPE_EVENT:
				status = mrcp_request_line_generate(start_line,text_stream);
				break;
			default:
				break;
		}
	}
	else if(start_line->version == MRCP_VERSION_2) {
		status = mrcp_v2_start_line_generate(start_line,text_stream);
	}

	if(status == FALSE) {
		return FALSE;
	}

	return apt_text_eol_insert(text_stream);
}
/** Initialize content part generation */
static apt_bool_t apt_multipart_content_initialize(apt_multipart_content_t *multipart_content)
{
	/* insert preceding end-of-line */
	if(apt_text_eol_insert(&multipart_content->stream) == FALSE) {
		return FALSE;
	}
	/* insert hyphens */
	if(apt_text_string_insert(&multipart_content->stream,&multipart_content->hyphens) == FALSE) {
		return FALSE;
	}
	/* insert boundary */
	if(apt_text_string_insert(&multipart_content->stream,&multipart_content->boundary) == FALSE) {
		return FALSE;
	}
	return apt_text_eol_insert(&multipart_content->stream);
}
MRCP_DECLARE(apt_bool_t) mrcp_header_generate(mrcp_header_accessor_t *accessor, apt_text_stream_t *text_stream)
{
	const apt_str_t *name;
	apr_size_t i,j;
	char prop;

	if(!accessor->vtable) {
		return FALSE;
	}

	for(i=0, j=0; i<accessor->vtable->field_count && j<accessor->counter; i++) {
		prop = accessor->properties[i];
		if((prop & MRCP_HEADER_FIELD_NAME) == MRCP_HEADER_FIELD_NAME) {
			j++;
			name = apt_string_table_str_get(accessor->vtable->field_table,accessor->vtable->field_count,i);
			if(!name) continue;
			
			apt_text_header_name_generate(name,text_stream);
			if((prop & MRCP_HEADER_FIELD_VALUE) == MRCP_HEADER_FIELD_VALUE) {
				accessor->vtable->generate_field(accessor,i,text_stream);
			}
			apt_text_eol_insert(text_stream);
		}
	}

	return TRUE;
}
Exemple #7
0
/** Generate MRCP message-header */
MRCP_DECLARE(apt_bool_t) mrcp_message_header_generate(mrcp_message_header_t *message_header, apt_text_stream_t *text_stream)
{
	mrcp_header_generate(&message_header->resource_header_accessor,text_stream);
	mrcp_header_generate(&message_header->generic_header_accessor,text_stream);
	apt_text_eol_insert(text_stream);
	return TRUE;
}
Exemple #8
0
/** Generate MRCP channel-identifier */
MRCP_DECLARE(apt_bool_t) mrcp_channel_id_generate(mrcp_channel_id *channel_id, apt_text_stream_t *stream)
{
	apt_str_t *str;
	char *pos = stream->pos;
	if(pos + MRCP_CHANNEL_ID_LENGTH + 2 + channel_id->session_id.length + 1 + 
		channel_id->resource_name.length >= stream->end) {
		return FALSE;
	}
	memcpy(pos,MRCP_CHANNEL_ID,MRCP_CHANNEL_ID_LENGTH);
	pos += MRCP_CHANNEL_ID_LENGTH;
	*pos++ = ':';
	*pos++ = APT_TOKEN_SP;
		
	str = &channel_id->session_id;
	memcpy(pos,str->buf,str->length);
	pos += str->length;
	*pos++ = '@';

	str = &channel_id->resource_name;
	memcpy(pos,str->buf,str->length);
	pos += str->length;

	stream->pos = pos;
	return apt_text_eol_insert(stream);
}
MRCP_DECLARE(apt_bool_t) mrcp_header_generate(mrcp_header_accessor_t *accessor, apt_text_stream_t *text_stream)
{
	const apt_str_t *name;
	apr_size_t i;
	mrcp_header_property_t property_set;

	if(!accessor->vtable) {
		return FALSE;
	}

	property_set = accessor->property_set;
	for(i=0; i<accessor->vtable->field_count && property_set != 0; i++) {
		if(mrcp_header_property_check(&property_set,i) == TRUE) {
			name = apt_string_table_str_get(accessor->vtable->field_table,accessor->vtable->field_count,i);
			if(!name) {
				continue;
			}
			
			apt_text_header_name_generate(name,text_stream);
			if(accessor->empty_values == FALSE) {
				accessor->vtable->generate_field(accessor,i,text_stream);
			}
			apt_text_eol_insert(text_stream);
			
			mrcp_header_property_remove(&property_set,i);
		}
	}
	return TRUE;
}
/** Generate header section */
APT_DECLARE(apt_bool_t) apt_header_section_generate(const apt_header_section_t *header, apt_text_stream_t *stream)
{
	apt_header_field_t *header_field;
	for(header_field = APR_RING_FIRST(&header->ring);
			header_field != APR_RING_SENTINEL(&header->ring, apt_header_field_t, link);
				header_field = APR_RING_NEXT(header_field, link)) {
		apt_header_field_generate(header_field,stream);
	}

	return apt_text_eol_insert(stream);
}
/** Finalize multipart content generation */
APT_DECLARE(apt_str_t*) apt_multipart_content_finalize(apt_multipart_content_t *multipart_content)
{
	apt_text_stream_t *stream = &multipart_content->stream;
	if(stream->pos + 4 + 2*multipart_content->hyphens.length + 
		multipart_content->boundary.length > stream->end) {
		return NULL;
	}

	/* insert preceding end-of-line */
	apt_text_eol_insert(&multipart_content->stream);
	/* insert hyphens */
	apt_string_value_generate(&multipart_content->hyphens,&multipart_content->stream);
	/* insert boundary */
	apt_string_value_generate(&multipart_content->boundary,&multipart_content->stream);
	/* insert final hyphens */
	apt_string_value_generate(&multipart_content->hyphens,&multipart_content->stream);
	apt_text_eol_insert(&multipart_content->stream);

	stream->text.length = stream->pos - stream->text.buf;
	stream->text.buf[stream->text.length] = '\0';
	return &stream->text;
}
/** Add content part to multipart content */
APT_DECLARE(apt_bool_t) apt_multipart_content_add(apt_multipart_content_t *multipart_content, const apt_str_t *content_type, const apt_str_t *content)
{
	if(!content || !content_type) {
		return FALSE;
	}

	if(multipart_content->hyphens.length + multipart_content->boundary.length + 
		multipart_content->content_type_header.length + content_type->length +
		multipart_content->content_length_header.length + 10 /* max number of digits in content-length */ +
		content->length + 10 /* 5*2 eol */ + multipart_content->stream.pos > multipart_content->stream.end  ) { 
		return FALSE;
	}

	/* insert preceding end-of-line */
	apt_text_eol_insert(&multipart_content->stream);
	/* insert hyphens */
	apt_string_value_generate(&multipart_content->hyphens,&multipart_content->stream);
	/* insert boundary */
	apt_string_value_generate(&multipart_content->boundary,&multipart_content->stream);
	apt_text_eol_insert(&multipart_content->stream);

	/* insert content-type */
	apt_text_header_name_generate(&multipart_content->content_type_header,&multipart_content->stream);
	apt_string_value_generate(content_type,&multipart_content->stream);
	apt_text_eol_insert(&multipart_content->stream);

	/* insert content-lebgth */
	apt_text_header_name_generate(&multipart_content->content_length_header,&multipart_content->stream);
	apt_size_value_generate(content->length,&multipart_content->stream);
	apt_text_eol_insert(&multipart_content->stream);

	/* insert empty line */
	apt_text_eol_insert(&multipart_content->stream);

	/* insert content */
	apt_string_value_generate(content, &multipart_content->stream);
	return TRUE;
}
/** Generate name-value pair line */
APT_DECLARE(apt_bool_t) apt_text_name_value_insert(apt_text_stream_t *stream, const apt_str_t *name, const apt_str_t *value)
{
	char *pos = stream->pos;
	if(pos + name->length + value->length + 2 >= stream->end) {
		return FALSE;
	}
	memcpy(pos,name->buf,name->length);
	pos += name->length;
	*pos++ = ':';
	*pos++ = APT_TOKEN_SP;
	if(apt_string_is_empty(value) == FALSE) {
		memcpy(pos,value->buf,value->length);
		pos += value->length;
	}
	stream->pos = pos;
	return apt_text_eol_insert(stream);
}
Exemple #14
0
/** Generate MRCP channel-identifier */
MRCP_DECLARE(apt_bool_t) mrcp_channel_id_generate(mrcp_channel_id *channel_id, apt_text_stream_t *text_stream)
{
	apt_str_t *str;
	char *pos = text_stream->pos;

	memcpy(pos,MRCP_CHANNEL_ID,MRCP_CHANNEL_ID_LENGTH);
	pos += MRCP_CHANNEL_ID_LENGTH;
	*pos++ = ':';
	
	str = &channel_id->session_id;
	memcpy(pos,str->buf,str->length);
	pos += str->length;
	*pos++ = '@';

	str = &channel_id->resource_name;
	memcpy(pos,str->buf,str->length);
	pos += str->length;

	text_stream->pos = pos;
	apt_text_eol_insert(text_stream);
	return TRUE;
}