static MESSAGE
build_request(gchar * req_name, void *body, gsize body_size, GError ** error)
{
	MESSAGE req = NULL;

	/*create a request and serializes it */
	if (!message_create(&req, error)) {
		GSETERROR(error, "Failed to create a new message");
		goto error_create;
	}

	if (body && !message_set_BODY(req, body, body_size, error)) {
		GSETERROR(error, "Failed to set message body");
		goto error_set_body;
	}

	/*sets the request name */
	if (!message_set_NAME(req, req_name, strlen(req_name), error)) {
		GSETERROR(error, "Failed to set message name");
		goto error_set_name;
	}

	return (req);

error_set_name:
error_set_body:
	message_destroy(req, NULL);
error_create:

	return (NULL);
}
Exemple #2
0
GByteArray*
sqlx_pack_REPLICATE(struct sqlx_name_s *name, struct TableSequence *tabseq)
{
	GError *err = NULL;
	GByteArray *body, *encoded;
	MESSAGE req;

	EXTRA_ASSERT(name != NULL);
	EXTRA_ASSERT(tabseq != NULL);

	body = sqlx_encode_TableSequence(tabseq, &err);
	if (!body) {
		GRID_WARN("Transaction encoding error : (%d) %s",
				err->code, err->message);
		return NULL;
	}

	req = make_request("SQLX_REPLICATE", name);
	(void) message_set_BODY(req, body->data, body->len, NULL);
	encoded = message_marshall_gba(req, NULL);
	g_byte_array_free(body, TRUE);
	(void) message_destroy(req, NULL);

	return encoded;
}
Exemple #3
0
GByteArray *
sqlx_pack_LOAD(struct sqlx_name_s *name, GByteArray *dump)
{
	struct message_s *req;

	req = make_request("SQLX_LOAD", name);
	g_assert(req != NULL);

	message_set_BODY(req, dump->data, dump->len, NULL);
	return message_marshall_gba_and_clean(req);
}
Exemple #4
0
GByteArray*
sqlx_pack_RESTORE(struct sqlx_name_s *name, const guint8 *raw, gsize rawsize)
{
	MESSAGE req;
	GByteArray *gba;

	req = make_request("SQLX_RESTORE", name);
	(void) message_set_BODY(req, raw, rawsize, NULL);
	gba = message_marshall_gba(req, NULL);
	(void) message_destroy(req, NULL);
	return gba;
}
Exemple #5
0
GByteArray*
sqlx_pack_QUERY(struct sqlxsrv_name_s *name, const gchar *query,
		struct TableSequence *params, gboolean autocreate)
{
	MESSAGE req;
	guint8 ac = (guint8) autocreate;

	EXTRA_ASSERT(name != NULL);
	EXTRA_ASSERT(query != NULL);

	req = make_srv_request("SQLX_QUERY", name);
	message_add_field(req, "AUTOCREATE", 10, &ac, 1, NULL);
	message_add_fields_str(req, "QUERY", query, NULL);

	if (!params) {
		GByteArray *body;
		body = sqlx_encode_TableSequence(params, NULL);
		message_set_BODY(req, body->data, body->len, NULL);
		g_byte_array_free(body, TRUE);
	}

	return message_marshall_gba_and_clean(req);
}
Exemple #6
0
GByteArray*
sqlx_pack_QUERY_single(struct sqlxsrv_name_s *name, const gchar *query,
		gboolean autocreate)
{
	struct message_s *req = NULL;
	guint8 ac = (guint8) autocreate;

	EXTRA_ASSERT(name != NULL);
	EXTRA_ASSERT(query != NULL);

	req = make_srv_request("SQLX_QUERY", name);
	g_assert(req != NULL);

	do {
		Table_t *t;
		TableSequence_t *ts;
		GByteArray *body;

		t = g_malloc0(sizeof(Table_t));
		g_assert(t != NULL);
		ts = g_malloc0(sizeof(TableSequence_t));
		g_assert(ts != NULL);

		OCTET_STRING_fromBuf(&(t->name), query, strlen(query));
		asn_sequence_add(&(ts->list), t);
		body = sqlx_encode_TableSequence(ts, NULL);
		g_assert(body != NULL);
		message_set_BODY(req, body->data, body->len, NULL);
		message_add_field(req, "AUTOCREATE", 10, &ac, 1, NULL);

		asn_DEF_TableSequence.free_struct(&asn_DEF_TableSequence, ts, FALSE);
		g_byte_array_free(body, TRUE);
	} while (0);

	return message_marshall_gba_and_clean(req);
}