Ejemplo n.º 1
0
gboolean
convert_chunk_text_to_raw(const struct chunk_textinfo_s* text_chunk, struct meta2_raw_chunk_s* raw_chunk, GError** error)
{
	if (text_chunk == NULL) {
		GSETERROR(error, "text_chunk is null");
		return FALSE;
	}

	memset(raw_chunk, 0, sizeof(struct meta2_raw_chunk_s));

	if (text_chunk->id != NULL
		&& !oio_str_hex2bin(text_chunk->id, raw_chunk->id.id, sizeof(hash_sha256_t))) {
			GSETERROR(error, "Failed to convert chunk id from hex to bin");
			return FALSE;
	}

	if (text_chunk->hash != NULL
		&& !oio_str_hex2bin(text_chunk->hash, raw_chunk->hash, sizeof(chunk_hash_t))) {
			GSETERROR(error, "Failed to convert chunk hash from hex to bin");
			return FALSE;
	}

	if (text_chunk->size != NULL)
		raw_chunk->size = g_ascii_strtoll(text_chunk->size, NULL, 10);

	if (text_chunk->position != NULL)
		raw_chunk->position = g_ascii_strtoull(text_chunk->position, NULL, 10);

	if (text_chunk->metadata != NULL)
		raw_chunk->metadata = metautils_gba_from_string(text_chunk->metadata);

	return TRUE;
}
Ejemplo n.º 2
0
static gs_container_t*
gs_container_init_from_location(gs_grid_storage_t *client,
	struct gs_container_location_s *location, gs_error_t **gserr)
{
	GError *gerr = NULL;
	gs_container_t *container = NULL;

	container = calloc(1, sizeof(struct gs_container_s));
	container->meta2_cnx = -1;
	container->opened = 0;

	l4_address_init_with_url(&(container->meta2_addr), location->m2_url[0], NULL);

	if (!oio_str_hex2bin(location->container_hexid, container->cID, sizeof(container_id_t))) {
		GSERRORCAUSE(gserr, gerr, "Invalid hexadecimal container ID");
		g_error_free(gerr);
		free(container);
		return NULL;
	}

	if (gerr)
		g_clear_error(&gerr);

	container->info.gs = client;

	if (location->container_name)
		g_strlcpy(container->info.name, location->container_name,
				sizeof(container->info.name)-1);

	if (location->container_hexid)
		g_strlcpy(container->str_cID, location->container_hexid,
				sizeof(container->str_cID)-1);

	return container;
}
Ejemplo n.º 3
0
static void
test_bin (void)
{
	guint8 buf[64];
	gchar str[129];

	g_assert_false (oio_str_hex2bin ("0", buf, sizeof(buf)));
	g_assert_false (oio_str_hex2bin ("x", buf, sizeof(buf)));

	g_assert_false (oio_str_hex2bin ("0x", buf, sizeof(buf)));

	g_assert_true  (oio_str_hex2bin ("00", buf, 1));
	g_assert_false (oio_str_hex2bin ("0000", buf, 1));

	g_assert_true (oio_str_hex2bin ("00", buf, sizeof(buf)));
	g_assert_true (buf[0] == 0);
	g_assert (2 == oio_str_bin2hex (buf, 1, str, sizeof(str)));
	g_assert (!g_ascii_strcasecmp(str, "00"));
}