Example #1
0
static utility_retcode_t get_header_list(struct rtsp_response *response)
{
	utility_retcode_t ret = UTILITY_SUCCESS;

	FUNC_ENTER;

	while (more_headers(response)) {
		ret = utility_copy_token(response->tmpbuf,
					 response->tmpbuflen,
					 response->parsep,
					 "\r\n",
					 NULL);

		if (UTILITY_SUCCESS != ret) {
			ERRR("Header line is not terminated by \\r\\n\n");
			goto failed;
		}

		DEBG("header line: \"%s\"\n", response->tmpbuf);

		ret = parse_one_header(response);

		if (UTILITY_SUCCESS != ret) {
			ERRR("Failed to parse header");
			goto failed;
		}

	}

	INFO("Got blank line (\\r\\n).  Finished parsing headers\n");

failed:
	FUNC_RETURN;
	return ret;
}
Example #2
0
utility_retcode_t compare_audio_data(uint8_t *buf1,
				     size_t buf1_size,
				     uint8_t *buf2,
				     size_t buf2_size)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	size_t size;
	int i;

	if (buf1_size != buf2_size) {
		ERRR("Buffer sizes are not equal, buf1_size: %d, buf2_size: %d\n",
		     buf1_size, buf2_size);
	}

	size = (buf1_size > buf2_size) ? buf1_size : buf2_size;

	INFO("Comparing %d bytes of data\n", size);

	for (i = 0 ; i < (int)size ; i++) {
		if (*(buf1 + i) != *(buf2 + i)) {
			ERRR("Audio data mismatch at byte %d (buf1: 0x%x buf2: 0x%x)\n",
			     i, *(buf1 + i), *(buf2 + i));
			ret = UTILITY_FAILURE;
		}
	}

	return ret;
}
Example #3
0
static utility_retcode_t parse_one_header(struct rtsp_response *response)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	char *start_value;
	char *header_name = response->current_header.name;
	char *header_value = response->current_header.value;

	FUNC_ENTER;

	ret = utility_copy_token(header_name,
				 MAX_HEADER_NAME_LEN,
				 response->parsep,
				 ": ",
				 NULL);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to copy header name\n");
		goto out;
	}

	start_value = begin_token(response->parsep, ": ");
	ret = utility_copy_token(header_value,
				 MAX_HEADER_VALUE_LEN,
				 start_value,
				 "\r\n",
				 NULL);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to copy header value\n");
		goto out;
	}

	DEBG("Found header name: \"%s\" value: \"%s\"\n",
	     header_name, header_value);

	if (0 == syscalls_strcmp(header_name, "Content-Length")) {
		ret = parse_content_length(response);
	} else if (0 == syscalls_strcmp(header_name, "Apple-Response")) {
		ret = parse_apple_response(response);
	} else if (0 == syscalls_strcmp(header_name, "Audio-Jack-Status")) {
		ret = parse_audio_jack_status(response);
	} else if (0 == syscalls_strcmp(header_name, "Session")) {
		ret = parse_session(response);
	} else if (0 == syscalls_strcmp(header_name, "Transport")) {
		ret = parse_transport(response);
	} else if (0 == syscalls_strcmp(header_name, "Public")) {
		ret = parse_public(response);
	} else {
		parse_unknown_header(response);
	}

out:
	FUNC_RETURN;
	return ret;
}
Example #4
0
utility_retcode_t add_rtsp_header(struct utility_locked_list *list,
				  const char *name,
				  const char *value,
				  const char *description)
{
	utility_retcode_t ret;
	struct key_value_pair *header;

	header = syscalls_malloc(sizeof(*header));
	if (NULL == header) {
		ERRR("Could not allocate memory for RTSP header \"%s\"\n",
		     description);
		goto malloc_failed;
	}

	header->name = syscalls_strndup(name, MAX_HEADER_NAME_LEN);
	if (NULL == header->name) {
		ERRR("Could not allocate memory for RTSP header name \"%s\"\n",
		     name);
		goto strndup_name_failed;
	}

	header->value = syscalls_strndup(value, MAX_HEADER_VALUE_LEN);
	if (NULL == header->value) {
		ERRR("Could not allocate memory for RTSP header value \"%s\"\n",
		     value);
		goto strndup_value_failed;
	}

	if (UTILITY_FAILURE == utility_list_add(list, header, description)) {
		ERRR("Failed to add RTSP header \"%s\""
		     "to request headers list\n",
		     description);
		goto list_add_failed;
	}

	ret = UTILITY_SUCCESS;
	goto out;

list_add_failed:
	syscalls_free(header->value);
strndup_value_failed:
	syscalls_free(header->name);
strndup_name_failed:
	syscalls_free(header);
malloc_failed:
	ret = UTILITY_FAILURE;
out:
	FUNC_RETURN;
	return ret;
}
Example #5
0
void test_audio(void)
{
	struct aes_data aes_data;
	struct audio_stream audio_stream;
	char pcm_testdata[] = "pcm_testfile";

	CRIT("Testing audio send routines; no connections "
	     "will be made to the server\n");

	lt_set_level(LT_AUDIO_STREAM, LT_INFO);
	lt_set_level(LT_RAOP_PLAY_SEND_AUDIO, LT_INFO);

	generate_aes_data(&aes_data);

	syscalls_strncpy(audio_stream.pcm_data_file,
			 pcm_testdata,
			 sizeof(audio_stream.pcm_data_file));

	audio_stream.session_fd = syscalls_open("./fake_session",
						O_RDWR | O_CREAT | O_TRUNC,
						S_IRUSR | S_IWUSR);

	if (-1 == audio_stream.session_fd) {
		ERRR("Failed to open fake session file descriptor\n");
		goto out;
	}

	init_audio_stream(&audio_stream);
	send_audio_stream(&audio_stream, &aes_data);

out:
	CRIT("Audio test done; exiting\n");
	exit (1);
}
Example #6
0
stockPosition *HoldPosition::_checkStockId(string StockID) {
	if (_stockPosition.count(StockID) > 0) {
		return &_stockPosition[StockID];
	} else {
		ERRR("Stock ID %s not exist in map @HoldPosition::_checkStockId\n", StockID.c_str());
		return nullptr;
	}
}
Example #7
0
int HoldPosition::GetPosition(string StockID, int idx) {
	stockPosition *tmpPosition = _checkStockId(StockID);
	if (nullptr == tmpPosition) {
		ERRR("StockID:%s doesn't exist @GetPosition\n", StockID.c_str());
		return 0;
	}
	if (-1 != idx) {
		if (tmpPosition->subType > idx) {
			return tmpPosition->subBuyCount[idx];
		} else {
			ERRR("idx:%d >= _subType:%d @GetPosition\n", idx, tmpPosition->subType);
			return 0;
		}
	} else {
		return tmpPosition->buyCount;
	}
	return tmpPosition->GetMount();
}
Example #8
0
utility_retcode_t dump_raw_pcm(uint8_t *buf, size_t size)
{
	utility_retcode_t ret = UTILITY_SUCCESS;

	FUNC_ENTER;

	ret = dump_audio(rawpcmfd, buf, size);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Dump of raw PCM data failed\n");
	}

	FUNC_RETURN;
	return ret;
}
Example #9
0
utility_retcode_t dump_encrypted(uint8_t *buf, size_t size)
{
	utility_retcode_t ret = UTILITY_SUCCESS;

	FUNC_ENTER;

	ret = dump_audio(encryptedfd, buf, size);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Dump of encrypted data failed\n");
	}

	FUNC_RETURN;
	return ret;
}
Example #10
0
utility_retcode_t rtsp_parse_response(struct rtsp_response *response)
{
	utility_retcode_t ret;
	FUNC_ENTER;

	ret = parse_status_line(response);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to parse status line\n");
		goto out;
	}

	ret = get_header_list(response);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to parse headers\n");
		goto out;
	}

	/* Here we will need to parse the message body, if any. */

out:
	FUNC_RETURN;
	return ret;
}
Example #11
0
utility_retcode_t dump_complete_raop_play(uint8_t *buf, size_t size)
{
	utility_retcode_t ret = UTILITY_SUCCESS;

	FUNC_ENTER;

	ret = dump_audio(raop_playcompletefd, buf, size);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Dump of raop_play complete data failed\n");
	}

	FUNC_RETURN;
	return ret;
}
Example #12
0
const searchResult* Write2Buffer::getData(int idx) {
	for (vector<bufferStatus>::iterator it = searchStatus.begin(); it != searchStatus.end(); ++it) {
		if (it->NaviNum == idx) {
			// 不管有没有finish都返回读取到的sinaDailyData
			if (true != it->IsFinished) {
				INFO("Unexpected end when analyze daily history data, mostly no impact!\n");
			}
			return &mapSearchResult[it->NaviNum];
		}
	}
	// 没有找到index则返回NULL
	ERRR("Can not find index %d in searchResult\n", idx);
	return nullptr;
}
Example #13
0
static utility_retcode_t get_status_code(struct rtsp_response *response)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	char *begincode;
	char code[4];

	FUNC_ENTER;

	begincode = begin_token((const char *)response->parsep, " ");
	if (NULL == begincode) {
		ERRR("Could not find beginning of status "
		     "code in status line\n");
		goto failed;
	}

	ret = utility_copy_token(code, sizeof(code), begincode, " ", NULL);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Could not find status code in response status line\n");
		goto failed;
	}

	DEBG("status code string is \"%s\"\n", code);

	response->status_line.status_code = syscalls_strtoul(code, NULL, 0);
	INFO("response status code is: %d\n",
	     response->status_line.status_code);

	ret = UTILITY_SUCCESS;
	goto out;

failed:
	ret = UTILITY_FAILURE;
out:
	FUNC_RETURN;
	return ret;
}
Example #14
0
utility_retcode_t clear_rtsp_response(struct rtsp_response *response)
{
	utility_retcode_t ret;

	ret = allocate_response_buffers(response);
	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to allocate response buffer "
		     "for options request.\n");
		ret = UTILITY_FAILURE;
	}

	response->parsep = response->buf;

	return ret;
}
Example #15
0
// 什么价卖多少
bool HoldPosition::Sell(float Price, int Position, string StockName, int idx) {
	float SellPosition = Price*(float)Position;
	stockPosition *tmpPosition;
	if (nullptr == (tmpPosition = _checkStockId(StockName))) {
		ERRR("StockName:%s not exist @HoldPosition::sell\n", StockName.c_str());
		return false;
	}
	if (tmpPosition->Sell(Position, idx)) {
		_remain += SellPosition;
		_recordTotal(Price, idx);
		return true;
	} else {
		return false;
	}
}
Example #16
0
static utility_retcode_t dump_audio(int fd, uint8_t *buf, size_t size)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	int write_ret = 0;

	FUNC_ENTER;

	write_ret = syscalls_write(fd, buf, size);

	if (write_ret != (int)size) {
		ERRR("Write of audio data returned %d\n", write_ret);
		ret = UTILITY_FAILURE;
	}

	FUNC_RETURN;
	return ret;
}
Example #17
0
void HoldPosition::_recordTotal(float Price, int idx) {
	_lastTotal = _total;
	float tmp = 0.0f;
	for (map<string, stockPosition>::iterator iter = _stockPosition.begin(); iter != _stockPosition.end(); ++iter) {
		tmp += Price*iter->second.GetMount();
		if (-1 != idx) {
			if (iter->second.subType > idx) {
				iter->second.subLastTotal[idx] = iter->second.subTotal[idx];
				iter->second.subTotal[idx] = iter->second.subMount[idx]*Price;
			} else {
				ERRR("idx:%d >= _subType:%d when record\n", idx, iter->second.subType);
			}
		}

	}
	_total = _remain + tmp;
}
Example #18
0
bool HoldPosition::Buy(float Price, int Position, string StockName, int idx) {
	float BuyPosition = Price*(float)Position;
	if (_remain < BuyPosition) {
		INFO("买入量%.2f大于剩余量%.2f @HoldPosition::buy\n", BuyPosition, _remain);
		return false;
	}
	stockPosition *tmpPosition;
	if (nullptr == (tmpPosition = _checkStockId(StockName))) {
		ERRR("StockName:%s not exist @HoldPosition::buy\n", StockName.c_str());
		return false;
	}
	if (tmpPosition->Buy(Position, idx)) {
		_remain -= BuyPosition;
		_recordTotal(Price, idx);
		return true;
	} else {
		return false;
	}
}
Example #19
0
utility_retcode_t build_request_string(struct rtsp_request *request)
{
	utility_retcode_t ret;

	FUNC_ENTER;

	if (NULL == request->buf) {
		request->buf = syscalls_malloc(RTSP_MAX_REQUEST_LEN);
		request->buflen = RTSP_MAX_REQUEST_LEN;

		if (NULL == request->buf) {
			ERRR("Failed to allocate %d bytes for request\n",
			     RTSP_MAX_REQUEST_LEN);
			ret = UTILITY_FAILURE;
			goto out;
		}

	} else {
		syscalls_memset(request->buf, 0, request->buflen);
	}

	request->bufp = request->buf;
	request->bytes_remaining = request->buflen;

	build_request_line(request);
	build_headers(request);
	add_blank_line(request);

	if (NULL != request->msg_body) {
		syscalls_strncpy(request->bufp,
				 request->msg_body,
				 request->bytes_remaining);
	}

	request->request_length = syscalls_strlen(request->buf);

	ret = UTILITY_SUCCESS;
out:
	FUNC_RETURN;
	return ret;
}
Example #20
0
static int open_one_dumpfile(const char *name)
{
	char dumpfile[64];
	int fd, pid;

	INFO("Opening audio dumpfiles\n");

	pid = syscalls_getpid();

	snprintf(dumpfile,
		 sizeof(dumpfile),
		 "./audio_debug/%s.%s.%d", name, CODE_VERSION, pid);

	fd = open(dumpfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);

	if (fd < 0) {
		ERRR("Failed to open audio dump file \"%s\"\n", name);
	}

	return fd;
}
Example #21
0
static utility_retcode_t parse_audio_jack_status(struct rtsp_response *response)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	char *value = response->current_header.value;

	FUNC_ENTER;

	DEBG("value: \"%s\"\n", value);

	if (0 != syscalls_strncmp(value, "connected", sizeof("connected") - 1)) {

		response->session->server->audio_jack_status =
			AUDIO_JACK_DISCONNECTED;

		ERRR("Server reports audio jack is not connected\n");
		ret = UTILITY_FAILURE;
	}

	FUNC_RETURN;
	return UTILITY_SUCCESS;
}
Example #22
0
static utility_retcode_t next_line(struct rtsp_response *response)
{
	utility_retcode_t ret = UTILITY_SUCCESS;
	char *nextline;

	FUNC_ENTER;

	nextline = begin_token((const char *)response->parsep, "\r\n");
	if (NULL == nextline) {

		ERRR("Could not find beginning of next line in response\n");
		ret = UTILITY_FAILURE;

	} else {

		response->parsep = nextline;

	}

	FUNC_RETURN;
	return ret;
}
Example #23
0
static utility_retcode_t parse_status_line(struct rtsp_response *response)
{
	utility_retcode_t ret;
	char status_line[64];

	FUNC_ENTER;

	syscalls_memset(status_line, 0, sizeof(status_line));

	ret = utility_copy_token(status_line,
				 sizeof(status_line),
				 response->parsep,
				 "\r\n",
				 NULL);

	if (UTILITY_SUCCESS != ret) {
		ERRR("Failed to locate end of line in status line\n");
		ret = UTILITY_FAILURE;
		goto out;
	}

	INFO("Status line: \"%s\"\n", status_line);

	/* RTSP/1.0 200 OK We don't actually care about the version or
	 * the reason string */

	ret = get_status_code(response);
	if (UTILITY_SUCCESS != ret) {
		goto out;
	}

	ret = next_line(response);

out:
	FUNC_RETURN;
	return ret;
}
Example #24
0
static utility_retcode_t allocate_response_buffers(struct rtsp_response *response)
{
	utility_retcode_t ret;

	FUNC_ENTER;

	if (NULL != response->buf) {
		syscalls_memset(response->buf, 0, response->buflen);
	} else {
		response->buf = syscalls_malloc(RTSP_MAX_RESPONSE_LEN);
		if (NULL == response->buf) {
			ERRR("Failed to allocate %d bytes for response\n",
			     RTSP_MAX_RESPONSE_LEN);
			goto buf_failed;
		}
		response->buflen = RTSP_MAX_RESPONSE_LEN;
	}

	if (response->tmpbuf != NULL) {
		syscalls_memset(response->tmpbuf, 0, response->tmpbuflen);
	} else {
		response->tmpbuf = syscalls_malloc(RTSP_MAX_RESPONSE_LEN);
		if (NULL == response->tmpbuf) {
			ERRR("Failed to allocate %d bytes for response\n",
			     RTSP_MAX_RESPONSE_LEN);
			goto tmpbuf_failed;
		}
		response->tmpbuflen = RTSP_MAX_RESPONSE_LEN;
	}

	if (NULL != response->current_header.name) {
		syscalls_memset(response->current_header.name, 0, MAX_HEADER_NAME_LEN);
	} else {
		response->current_header.name = syscalls_malloc(MAX_HEADER_NAME_LEN);
		if (NULL == response->current_header.name) {
			ERRR("Failed to allocate %d bytes for header name\n",
			     MAX_HEADER_NAME_LEN);
			goto header_name_failed;
		}
	}

	if (NULL != response->current_header.value) {
		syscalls_memset(response->current_header.value, 0, MAX_HEADER_VALUE_LEN);
	} else {
		response->current_header.value = syscalls_malloc(MAX_HEADER_VALUE_LEN);
		if (NULL == response->current_header.value) {
			ERRR("Failed to allocate %d bytes for header value\n",
			     MAX_HEADER_VALUE_LEN);
			goto header_value_failed;
		}
	}

	ret = UTILITY_SUCCESS;
	goto out;

header_value_failed:
	syscalls_free(response->current_header.name);
header_name_failed:
	syscalls_free(response->tmpbuf);
	response->tmpbuflen = 0;
tmpbuf_failed:
	syscalls_free(response->buf);
	response->buflen = 0;
buf_failed:
	ret = UTILITY_FAILURE;
out:
	FUNC_RETURN;
	return ret;
}