Esempio n. 1
0
/* Receive RTSP message through RTSP connection */
static apt_bool_t rtsp_server_message_receive(apt_net_server_task_t *task, apt_net_server_connection_t *connection)
{
	rtsp_server_t *server = apt_net_server_task_object_get(task);
	char buffer[RTSP_MESSAGE_MAX_SIZE];
	apt_bool_t more_messages_on_buffer = FALSE;
	apr_status_t status;
	apt_text_stream_t text_stream;
	rtsp_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) {
		return apt_net_server_connection_close(task,connection);
	}
	text_stream.text.buf[text_stream.text.length] = '\0';
	text_stream.pos = text_stream.text.buf;

	apt_log(APT_PRIO_INFO,"Receive RTSP Message size=%lu\n%s",text_stream.text.length,text_stream.text.buf);
	do {
		message = rtsp_message_create(RTSP_MESSAGE_TYPE_UNKNOWN,connection->pool);
		if(rtsp_message_parse(message,&text_stream) == TRUE) {
			apt_str_t *destination = &message->header.transport.destination;
			if(!destination->buf && connection->client_ip) {
				apt_string_assign(destination,connection->client_ip,connection->pool);
			}
			rtsp_server_session_request_process(server,connection->obj,message);
		}
		else {
			rtsp_message_t *response;
			apt_log(APT_PRIO_WARNING,"Failed to Parse RTSP Message");
			response = rtsp_response_create(message,RTSP_STATUS_CODE_BAD_REQUEST,
									RTSP_REASON_PHRASE_BAD_REQUEST,message->pool);
			if(rtsp_server_message_send(server,connection,response) == FALSE) {
				apt_log(APT_PRIO_WARNING,"Failed to Send RTSP Response");
			}
		}

		more_messages_on_buffer = FALSE;
		if(text_stream.text.length > (apr_size_t)(text_stream.pos - text_stream.text.buf)) {
			/* there are more RTSP 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;
}
Esempio n. 2
0
static apt_bool_t test_file_process(apt_test_suite_t *suite, const char *file_path)
{
	apr_file_t *file;
	char buf_in[1500];
	apt_text_stream_t stream_in;
	rtsp_message_t *message;
	apt_str_t resource_name;

	if(apr_file_open(&file,file_path,APR_FOPEN_READ | APR_FOPEN_BINARY,APR_OS_DEFAULT,suite->pool) != APR_SUCCESS) {
		return FALSE;
	}

	stream_in.text.length = sizeof(buf_in)-1;
	stream_in.text.buf = buf_in;
	stream_in.pos = stream_in.text.buf;
	if(apr_file_read(file,stream_in.text.buf,&stream_in.text.length) != APR_SUCCESS) {
		return FALSE;
	}
	stream_in.text.buf[stream_in.text.length]='\0';

	apt_string_reset(&resource_name);
	apt_log(APT_PRIO_INFO,"Open File [%s] [%d bytes]\n%s",file_path,stream_in.text.length,stream_in.text.buf);

	do {
		const char *pos = stream_in.pos;
		message = rtsp_message_create(RTSP_MESSAGE_TYPE_UNKNOWN,suite->pool);
		if(rtsp_message_parse(message,&stream_in) == TRUE) {
			char buf_out[1500];
			apt_text_stream_t stream_out;
			apt_log(APT_PRIO_INFO,"Parsed Stream [%d bytes]",stream_in.pos - pos);

			stream_out.text.length = sizeof(buf_out)-1;
			stream_out.text.buf = buf_out;
			stream_out.pos = stream_out.text.buf;
			if(rtsp_message_generate(message,&stream_out) == TRUE) {
				*stream_out.pos = '\0';
				apt_log(APT_PRIO_INFO,"Generated Stream [%d bytes]\n%s",stream_out.text.length,stream_out.text.buf);
			}
			else {
				apt_log(APT_PRIO_WARNING,"Failed to Generate Message");
			}
		}
		else {
			apt_log(APT_PRIO_WARNING,"Failed to Parse Message");
		}
		getchar();
	}
	while(stream_in.pos < stream_in.text.buf + stream_in.text.length);
	apr_file_close(file);

	return TRUE;
}
Esempio n. 3
0
/** Create message and read start line */
static apt_bool_t rtsp_parser_on_start(apt_message_parser_t *parser, apt_message_context_t *context, apt_text_stream_t *stream, apr_pool_t *pool)
{
	rtsp_message_t *message;
	apt_str_t start_line;
	/* read start line */
	if(apt_text_line_read(stream,&start_line) == FALSE) {
		return FALSE;
	}
	
	message = rtsp_message_create(RTSP_MESSAGE_TYPE_UNKNOWN,pool);
	if(rtsp_start_line_parse(&message->start_line,&start_line,message->pool) == FALSE) {
		return FALSE;
	}
	
	context->message = message;
	context->header = &message->header.header_section;
	context->body = &message->body;
	return TRUE;
}