Ejemplo n.º 1
0
gboolean
check_chunk(const char *chunk_path, void *data, GError ** error)
{
	struct chunk_textinfo_s text_chunk;
	GSList *list_mismatch = NULL;

	CHECK_ARG_POINTER(chunk_path, error);
	CHECK_ARG_VALID_FILE(chunk_path, error);

	/* Get content from chunk file attr */
	if (!get_chunk_info_in_attr(chunk_path, error, &text_chunk)) {
		GSETERROR(error, "Failed to read chunk infos from chunk file attributes");
		return FALSE;
	}

	/* Check chunk integrity */
	if (!check_chunk_integrity(chunk_path, &text_chunk, &list_mismatch, error)) {
		GSETERROR(error, "Chunk integrity check failed");
		return FALSE;
	}

	/* if list_mismatch == NULL => chunk integrity ok, we can test chunk referencing  */
	if (list_mismatch==NULL){
	}
	
	/* Send broken events if any */
	if (list_mismatch != NULL) {
		struct broken_event_s * broken_event = NULL;

		broken_event = g_new0(struct broken_event_s, 1);
		memcpy(&(broken_event->service_info), data, sizeof(service_info_t));
		broken_event->broken_elements = list_mismatch;

		if (!record_broken_event(broken_event, error)) {
			GSETERROR(error, "Failed to record a broken event");
			g_free(broken_event);
			g_slist_foreach(list_mismatch, broken_element_gfree, NULL);
			g_slist_free(list_mismatch);
			return FALSE;
		}
	}
	return TRUE;
}
Ejemplo n.º 2
0
int
lzo_compressed_chunk_init(struct compressed_chunk_s *chunk, const gchar *path)
{
	int r = 0;	
	gsize nb_read;
	guint8 headers[HEADER_SIZE];
	GError * error = NULL;
	struct chunk_textinfo_s cti;
	DEBUG("compressed_chunk_init: START\n");

	if(!chunk)
		ERROR("Invalid parameter : %p\n", chunk);

	memset(headers, 0, sizeof(headers));
	memset(&cti, 0, sizeof(cti));
	
	/* Get chunk uncompressed size in his attr */
	if (!get_chunk_info_in_attr(path, &error, &cti)){
		DEBUG("Failed to get chunk info in attr : %s\n", error->message);
		g_clear_error(&error);
		return 1;
	}

	chunk->uncompressed_size = g_strdup(cti.size);
	DEBUG("size get in attr = %s", chunk->uncompressed_size);

	/* Read magic header & flags */
	/* place block at top of buffer */
	/*
 	 * Step 1: check magic header, read flags & block size, init checksum
 	*/

	chunk->fd = fopen(path, "r");

	if (!chunk->fd) {
		r = 1;
		goto err;
	}
	
	DEBUG("compressed_chunk_init: compressed chunk open");

	/* compile for read all header info in one call */
	nb_read = 0;
	nb_read = fread(headers, sizeof(headers), 1, chunk->fd);
	if (nb_read != 1) {
		DEBUG("Failed to read headers from chunk file");
		r = 2;
		goto err;
	}

	do { /* extract all headers */
#define GETNEXTPTR(Res,Ptr,Type) do { Res = *((Type *)Ptr); Ptr = Ptr + sizeof(Type); } while (0)
		guint32 bsize32 = 0;

		char *ptr = (char*)headers + sizeof(lzo_magic);
		GETNEXTPTR(chunk->flags, ptr, lzo_uint32);
		GETNEXTPTR(chunk->method, ptr, char);
		GETNEXTPTR(chunk->level, ptr, char);
		GETNEXTPTR(bsize32, ptr, lzo_uint32);
		chunk->block_size = bsize32;
	} while (0);

	if (memcmp(headers, lzo_magic, sizeof(lzo_magic)) != 0) {
		r = 4;
		goto err;
	}
    	if (chunk->method != 1) {
        	r = 5;
        	goto err;
    	}
    	if (chunk->block_size < 1024 || chunk->block_size > 8*1024*1024L){
        	r = 6;
        	goto err;
    	}

	DEBUG("ck.block_size : %"G_GUINT32_FORMAT"\n", chunk->block_size);

	chunk->checksum = lzo_adler32(0, NULL, 0);

	DEBUG("chunk->uncompressed_size = %s\n", chunk->uncompressed_size);

	r=0;

err:
	if(error)
		g_clear_error(&error);
	chunk_textinfo_free_content(&cti);
	
	return r;
}