Ejemplo n.º 1
0
GError*
sqlx_remote_execute_ADMGET(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, const gchar *k, gchar **v)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *encoded = sqlx_pack_ADMGET(name, k);
	GByteArray *gba_buf = g_byte_array_new();
	struct client_s *client = gridd_client_create(target, encoded,
			gba_buf, on_reply_gba);
	g_byte_array_unref(encoded);

	gridd_client_start(client);
	if (!(err = gridd_client_loop(client))) {
		if (!(err = gridd_client_error(client))) {
			gchar *buf = g_malloc0(gba_buf->len + 1);
			metautils_gba_data_to_string(gba_buf, buf, gba_buf->len + 1);
			*v = buf;
		}
	}

	gridd_client_free(client);
	metautils_gba_unref(gba_buf);
	return err;
}
GError *
peer_restore(const gchar *target, struct sqlx_name_s *name,
		GByteArray *dump)
{
	GError *err = NULL;

	if (!target) {
		g_byte_array_unref(dump);
		return NULL;
	}

	GByteArray *encoded = _pack_RESTORE(name, dump);
	struct gridd_client_s *client = gridd_client_create(target, encoded, NULL, NULL);
	g_byte_array_unref(encoded);

	if (!client)
		return NEWERROR(CODE_INTERNAL_ERROR, "Failed to create client to [%s], bad address?", target);

	gridd_client_set_timeout(client, SQLX_RESYNC_TIMEOUT);
	gridd_client_start(client);
	if (!(err = gridd_client_loop(client)))
		err = gridd_client_error(client);
	gridd_client_free(client);
	return err;
}
Ejemplo n.º 3
0
GError *
gridd_client_exec_and_concat (const gchar *to, gdouble seconds, GByteArray *req,
		GByteArray **out)
{
	if (!to) {
		g_byte_array_unref (req);
		return NEWERROR(CODE_INTERNAL_ERROR, "No target");
	}

	GByteArray *tmp = NULL;
	if (out)
		tmp = g_byte_array_new();

	struct gridd_client_s *client = gridd_client_create(to, req,
			out ? tmp : NULL, out ? (client_on_reply)_cb_exec_and_concat : NULL);
	g_byte_array_unref (req);
	if (!client) {
		if (tmp) g_byte_array_free (tmp, TRUE);
		return NEWERROR(CODE_INTERNAL_ERROR, "client creation");
	}
	if (seconds > 0.0)
		gridd_client_set_timeout (client, seconds);
	GError *err = gridd_client_run (client);
	gridd_client_free (client);

	if (!err && out) {
		*out = tmp;
		tmp = NULL;
	}
	if (tmp)
		metautils_gba_unref (tmp);
	return err;
}
Ejemplo n.º 4
0
GError*
sqlx_remote_execute_ADMSET(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, const gchar *k, const gchar *v)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *encoded = sqlx_pack_ADMSET(name, k, v);
	struct client_s *client = gridd_client_create(target, encoded, NULL, NULL);
	g_byte_array_unref(encoded);
	gridd_client_start(client);
	if (!(err = gridd_client_loop(client)))
		err = gridd_client_error(client);
	gridd_client_free(client);
	return err;
}
Ejemplo n.º 5
0
GError*
sqlx_remote_execute_DESTROY(const gchar *target, GByteArray *sid,
		struct sqlx_name_s *name, gboolean local)
{
	(void) sid;
	GError *err = NULL;
	GByteArray *req = sqlx_pack_DESTROY(name, local);

	struct gridd_client_s *client = gridd_client_create(target, req, NULL, NULL);
	g_byte_array_unref(req);

	gridd_client_start(client);
	if (!(err = gridd_client_loop(client))) {
		err = gridd_client_error(client);
	}

	gridd_client_free(client);
	return err;
}
Ejemplo n.º 6
0
GError *
gridd_client_exec4 (const gchar *to, gdouble seconds, GByteArray *req,
		GByteArray ***out)
{
	if (!to) {
		g_byte_array_unref (req);
		return NEWERROR(CODE_INTERNAL_ERROR, "No target");
	}

	GPtrArray *tmp = NULL;
	if (out)
		tmp = g_ptr_array_new();

	struct gridd_client_s *client = gridd_client_create(to, req,
			(out ? tmp : NULL), out ? (client_on_reply)_cb_exec4 : NULL);
	g_byte_array_unref (req);
	if (!client) {
		if (tmp) g_ptr_array_free (tmp, TRUE);
		return NEWERROR(CODE_INTERNAL_ERROR, "client creation");
	}
	if (seconds > 0.0)
		gridd_client_set_timeout (client, seconds);
	GError *err = gridd_client_run (client);
	gridd_client_free (client);

	if (!err && out) {
		*out = (GByteArray**) metautils_gpa_to_array (tmp, TRUE);
		tmp = NULL;
	}
	if (tmp) {
		g_ptr_array_set_free_func (tmp, (GDestroyNotify)g_byte_array_unref);
		g_ptr_array_free (tmp, TRUE);
		tmp = NULL;
	}
	return err;
}
Ejemplo n.º 7
0
			else
				resultlen=0;
			len = g_strv_length(tmpResult);
			v0 = g_realloc(result, sizeof(gchar*) * (len + resultlen+1));
			for ( i=0; i<len ; i++) {
				v0[resultlen+i] = g_strdup(tmpResult[i]);
			}
			v0[len+resultlen]=NULL;
			result = g_strdupv(v0);
			g_strfreev(v0);
			g_strfreev(tmpResult);
		}
		return TRUE;
	}

	MESSAGE request = metautils_message_create_named(NAME_MSGNAME_M0_GET_META1_INFO);
	GByteArray *packed = message_marshall_gba_and_clean(request);
	struct gridd_client_s *client = gridd_client_create(m0, packed, NULL, on_reply);
	g_byte_array_free(packed, TRUE);
	e = gridd_client_run (client);
	gridd_client_free(client);

	if (e) {
		g_strfreev(result);
		return e;
	}
	*out = result;
	return NULL;
}