Beispiel #1
0
int dispatch_remreq_buffer_set_data(struct client_list_entry* client, struct remreq_buffer_set_data* message) {

  struct client_buffer* target = MAP_DEREF(uint32_t, struct client_buffer*, buffermap, &client->screen->buffers, message->buffer);

  if(target->remote_texture_layout_may_differ)
    return texture_set_data(client, message, target);
  else
    return buffer_set_data(client, message, target);

}
Beispiel #2
0
static int _parent_do(Buffer * x509, int fd)
{
	size_t len;
	ssize_t cnt;
	char buf[8192]; /* BUFSIZ is not enough on NetBSD (1024) */

	for(len = 0; (cnt = read(fd, &buf[len], sizeof(buf) - len - 1)) > 0;
			len += cnt);
	if(cnt < 0)
		return error_set_code(1, "%s%s", "read: ", strerror(errno));
	close(fd);
#ifdef DEBUG
	fprintf(stderr, "DEBUG: read %zu bytes\n", len);
#endif
	if(len == sizeof(buf) - 1)
		return error_set_code(1, "%s", "Buffer overrun");
	buf[len] = '\0';
#ifdef DEBUG
	fprintf(stderr, "%s%s%s", "DEBUG: x509 \"", buf, "\"\n");
#endif
	if(buffer_set_data(x509, 0, buf, len) != 0)
		return 1;
	return 0;
}
Beispiel #3
0
static int _serialize_append(Buffer * buffer, Buffer * b)
{
	return buffer_set_data(buffer, buffer_get_size(buffer),
			buffer_get_data(b), buffer_get_size(b));
}
Beispiel #4
0
/* variable_serialize */
int variable_serialize(Variable * variable, Buffer * buffer, int type)
{
	size_t size = 0;
	size_t offset;
	void * p;
	uint8_t u8;
	int16_t i16;
	uint16_t u16;
	int32_t i32;
	uint32_t u32;
	char buf[16];

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%u)\n", __func__, variable->type);
#endif
	switch(variable->type)
	{
		case VT_NULL:
			p = NULL;
			break;
		case VT_BOOL:
		case VT_INT8:
		case VT_UINT8:
			size = sizeof(variable->u.int8);
			p = &variable->u.int8;
			break;
		case VT_INT16:
			size = sizeof(i16);
			i16 = htons(variable->u.int16);
			p = &i16;
			break;
		case VT_UINT16:
			size = sizeof(u16);
			u16 = htons(variable->u.uint16);
			p = &u16;
			break;
		case VT_INT32:
			size = sizeof(i32);
			i32 = htonl(variable->u.int32);
			p = &i32;
			break;
		case VT_UINT32:
			size = sizeof(u32);
			u32 = htonl(variable->u.uint32);
			p = &u32;
			break;
		case VT_INT64:
		case VT_UINT64:
			/* FIXME convert to network endian */
			size = sizeof(variable->u.int64);
			p = &variable->u.int64;
			break;
		case VT_FLOAT:
			size = snprintf(buf, sizeof(buf), "%.e", variable->u.f);
			p = buf;
			break;
		case VT_DOUBLE:
			size = snprintf(buf, sizeof(buf), "%.e", variable->u.d);
			p = buf;
			break;
		case VT_BUFFER:
			size = buffer_get_size(variable->u.buffer);
			u32 = buffer_get_size(variable->u.buffer);
			u32 = htonl(u32);
			p = buffer_get_data(variable->u.buffer);
			break;
		case VT_STRING:
			size = string_get_length(variable->u.string) + 1;
			p = variable->u.string;
			break;
	}
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() %lu\n", __func__, size);
#endif
	if(size == 0 && variable->type != VT_NULL)
		return -error_set_code(1, "Unable to serialize type %u", type);
	if(type)
	{
		/* prefix with the type */
		u8 = variable->type;
		if(buffer_set(buffer, sizeof(u8), (char *)&u8) != 0)
			return -1;
		offset = sizeof(u8);
		if(variable->type == VT_BUFFER)
		{
			if(buffer_set_data(buffer, offset, (char *)&u32,
						sizeof(u32)) != 0)
				return -1;
			offset += sizeof(u32);
		}
		return buffer_set_data(buffer, offset, p, size);
	}
	if(variable->type == VT_BUFFER)
	{
		if(buffer_set(buffer, sizeof(u32), (char *)&u32) != 0)
			return -1;
		return buffer_set_data(buffer, sizeof(u32), p, size);
	}
	return buffer_set(buffer, size, p);
}