int binary_reader_read_string_buffer(uint8_t *buf, int pos, int *out_len, char **out_value)
{
	if (binary_reader_read_7bit_int(buf, &pos, out_len) < 0) {
		return -1;
	}

	*out_value = (char *)(buf + pos);
	
	return 0;
}
Beispiel #2
0
int disconnect_read(struct packet *packet, const uv_buf_t *buf)
{
	TALLOC_CTX *temp_context;
	int ret = -1, pos = 0, str_len;
	struct disconnect *disconnect;
	char *reason;

	temp_context = talloc_new(NULL);
	if (temp_context == NULL) {
		_ERROR("%s: out of memory allocating temp context for disconnect.\n", __FUNCTION__);
		ret = -ENOMEM;
		goto out;
	}

	disconnect = talloc_zero(temp_context, struct disconnect);
	if (disconnect == NULL) {
		_ERROR("%s: out of memory allocating disconnect.\n", __FUNCTION__);
		ret = -ENOMEM;
		goto out;
	}

	binary_reader_read_7bit_int(buf->base, &pos, &str_len);

	reason = talloc_size(temp_context, str_len + 1);
	if (reason == NULL) {
		_ERROR("%s: out of memory copying reason to packet.\n", __FUNCTION__);
		ret = -ENOMEM;
		goto out;
	}

	memcpy(reason, buf->base + pos, str_len);

	reason[str_len] = '\0';

	disconnect->reason = talloc_steal(disconnect, reason);

	disconnect->packet = packet;
	packet->data = (void *)talloc_steal(packet, disconnect);

	ret = 0;
out:
	talloc_free(temp_context);

	return ret;
}