Ejemplo n.º 1
0
static int _serialize_call(AppMessage * message, Buffer * buffer, Buffer * b)
{
	int ret;
	Variable * v;
	size_t i;

	if(_serialize_id(message, buffer, b) != 0)
		return -1;
	if((v = variable_new(VT_STRING, message->t.call.method)) == NULL)
		return -1;
	ret = (variable_serialize(v, b, 0) == 0
			&& _serialize_append(buffer, b) == 0) ? 0 : -1;
	variable_delete(v);
	if(ret != 0)
		return ret;
	for(i = 0; i < message->t.call.args_cnt; i++)
	{
		if(message->t.call.args[i].direction == AMCD_OUT)
			continue;
		if(variable_serialize(message->t.call.args[i].arg, b, 1) != 0
				|| _serialize_append(buffer, b) != 0)
			break;
	}
	buffer_delete(b);
	return (i == message->t.call.args_cnt) ? 0 : -1;
}
Ejemplo n.º 2
0
static inline struct variable *cfnc_serialize(struct context *context)
{
    struct variable *args = (struct variable*)stack_pop(context->operand_stack);
    struct variable *indexable = (struct variable*)array_get(args->list.ordered, 0);

    struct byte_array *bits = variable_serialize(context, NULL, indexable);
    byte_array_reset(bits);
    struct variable *result = variable_new_str(context, bits);
    byte_array_del(bits);
    return result;
}
Ejemplo n.º 3
0
struct variable *sys_save(struct context *context)
{
    struct variable *args = (struct variable*)stack_pop(context->operand_stack);
    struct variable *v = param_var(args, 1);
    struct variable *path = param_var(args, 2);
    struct byte_array *bytes = byte_array_new();
    variable_serialize(context, bytes, v);
    int w = write_file(path->str, bytes, 0, -1);
    byte_array_del(bytes);
    return variable_new_int(context, w);
}
Ejemplo n.º 4
0
static int _serialize_type(AppMessage * message, Buffer * buffer, Buffer * b)
{
	int ret;
	Variable * v;

	if((v = variable_new(VT_UINT8, &message->type)) == NULL)
		return -1;
	ret = (variable_serialize(v, b, 0) == 0
			&& _serialize_append(buffer, b) == 0) ? 0 : -1;
	variable_delete(v);
	return ret;
}
Ejemplo n.º 5
0
/**
 * @TODO
 */
static int nod_dispatcher_get(packet_t *pkt) {
	packet_dest_t *dest = packet_get_dest(pkt);
	int wi,mi,vi;
	ndebug("dest=(%d,%d,%d)\n",dest->waveform_id,dest->module_id,dest->variable_id);
	if (!dest->waveform_id) {
		return -1;
	}
	for (wi=0;wi<anode.max_waveforms;wi++) {
		if (anode.loaded_waveforms[wi].id == dest->waveform_id)
			break;
	}
	if (wi == anode.max_waveforms) {
		return -1;
	}
	ndebug("found wi=%d\n",wi);
	if (!dest->module_id && !dest->variable_id) {
		if (nod_waveform_serialize(&anode.loaded_waveforms[wi],pkt, 0, NONE)) {
			return -1;
		}
		return 0;
	}
	if (!dest->module_id) {
		return -1;
	}
	for (mi=0;mi<anode.loaded_waveforms[mi].nof_modules;mi++) {
		if (anode.loaded_waveforms[wi].modules[mi].parent.id == dest->module_id)
			break;
	}
	if (mi == anode.loaded_waveforms[wi].nof_modules) {
		return -1;
	}
	ndebug("found mi=%d\n",mi);
	if (!dest->variable_id) {
		aerror("Not implemented\n");
		return -1;
	}
	for (vi=0;vi<anode.loaded_waveforms[mi].modules[mi].parent.nof_variables;vi++) {
		if (anode.loaded_waveforms[wi].modules[mi].parent.variables[vi].id ==
				dest->variable_id)
			break;
	}
	if (vi == anode.loaded_waveforms[mi].modules[mi].parent.nof_variables) {
		return -1;
	}
	if (variable_serialize(&anode.loaded_waveforms[wi].modules[mi].parent.variables[vi], pkt,
			CP_VALUE,anode.loaded_waveforms[mi].nof_modes)) {
		return -1;
	}
	return 0;
}
Ejemplo n.º 6
0
/* ssl_socket_queue */
static int _ssl_socket_queue(SSLSocket * sslsocket, Buffer * buffer)
{
	uint32_t len;
	char * p;
	Variable * v;
	Buffer * b = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%d)\n", __func__, sslsocket->fd);
#endif
	/* serialize the buffer */
	v = variable_new(VT_BUFFER, buffer);
	b = buffer_new(0, NULL);
	if(v == NULL || b == NULL || variable_serialize(v, b, 0) != 0)
	{
		if(v != NULL)
			variable_delete(v);
		if(b != NULL)
			buffer_delete(b);
		return -1;
	}
	variable_delete(v);
	len = buffer_get_size(b);
	/* FIXME queue the serialized buffer directly as a message instead */
	if((p = realloc(sslsocket->bufout, sslsocket->bufout_cnt + len))
			== NULL)
	{
		buffer_delete(b);
		return -1;
	}
	sslsocket->bufout = p;
	memcpy(&p[sslsocket->bufout_cnt], buffer_get_data(b), len);
	/* register the callback if necessary */
	if(sslsocket->bufout_cnt == 0)
		event_register_io_write(sslsocket->transport->helper->event,
				sslsocket->fd,
				(EventIOFunc)_ssl_socket_callback_write,
				sslsocket);
	sslsocket->bufout_cnt += len;
	buffer_delete(b);
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%d) => %d\n", __func__, sslsocket->fd, 0);
#endif
	return 0;
}