/** Generate MRCP speech-length value */ static apt_bool_t mrcp_speech_length_generate(mrcp_speech_length_value_t *speech_length, apt_str_t *str, apr_pool_t *pool) { if(speech_length->type == SPEECH_LENGTH_TYPE_TEXT) { apt_str_t *tag = &speech_length->value.tag; if(tag->length) { apt_string_copy(str,tag,pool); } } else { char buf[256]; apt_text_stream_t stream; apt_text_stream_init(&stream,buf,sizeof(buf)); if(speech_length->type == SPEECH_LENGTH_TYPE_NUMERIC_POSITIVE) { *stream.pos++ = '+'; } else { *stream.pos++ = '-'; } apt_text_size_value_insert(&stream,speech_length->value.numeric.length); *stream.pos++ = APT_TOKEN_SP; apt_string_table_value_generate(speech_unit_string_table,SPEECH_UNIT_COUNT,speech_length->value.numeric.unit,&stream); apt_string_assign_n(str,stream.text.buf, stream.pos - stream.text.buf, pool); } 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 version */ static apt_bool_t mrcp_version_generate(mrcp_version_e version, apt_text_stream_t *stream) { if(stream->pos + MRCP_NAME_LENGTH + 1 >= stream->end) { return FALSE; } memcpy(stream->pos,MRCP_NAME,MRCP_NAME_LENGTH); stream->pos += MRCP_NAME_LENGTH; *stream->pos++ = MRCP_NAME_VERSION_SEPARATOR; if(apt_text_size_value_insert(stream,version) == FALSE) { return FALSE; } if(stream->pos + 2 >= stream->end) { return FALSE; } *stream->pos++ = MRCP_VERSION_MAJOR_MINOR_SEPARATOR; *stream->pos++ = '0'; return TRUE; }
/** Generate MRCP status-code */ static APR_INLINE size_t mrcp_status_code_generate(mrcp_status_code_e status_code, apt_text_stream_t *stream) { return apt_text_size_value_insert(stream,status_code); }