Пример #1
0
GByteArray*
m2v2_remote_pack_SPARE(GByteArray *sid, struct hc_url_s *url,
		const gchar *pol, GSList *notin_list, GSList *broken_list)
{
	struct message_s *msg;
	gchar *spare_type = M2V2_SPARE_BY_STGPOL;
	GByteArray *body = NULL;
	GSList *beans = NULL;

	if (notin_list != NULL) {
		spare_type = M2V2_SPARE_BY_BLACKLIST;
		for (GSList *l = notin_list; l != NULL; l = l->next) {
			if (DESCR(l->data) != &descr_struct_CHUNKS)
				continue;
			beans = g_slist_prepend(beans, _bean_dup(l->data));
		}
	}

	for (GSList *l = broken_list; l != NULL; l = l->next) {
		if (DESCR(l->data) != &descr_struct_CHUNKS)
			continue;
		struct bean_CHUNKS_s *chunk = _bean_dup(l->data);
		// This makes difference between valid and broken chunks
		CHUNKS_set_size(chunk, -1);
		beans = g_slist_prepend(beans, chunk);
	}

	/* body is only mandatory for M2V2_SPARE_BY_BLACKLIST so when
	 * notin_list != NULL. If not_in_list != NULL, beans is always
	 * != NULL so body is sent.
	 */
	if (beans != NULL)
		body = bean_sequence_marshall(beans);

	msg = _m2v2_build_request("M2V2_BEANS", sid, url, body);
	message_add_fields_str(msg,
			M2_KEY_STORAGE_POLICY, pol,
			M2_KEY_SPARE, spare_type,
			NULL);

	_bean_cleanl2(beans);
	return message_marshall_gba_and_clean(msg);
}
Пример #2
0
static struct beans_content_s *
_beans_to_content(const GSList *beans)
{
	struct beans_content_s *c = g_malloc0(sizeof(struct beans_content_s));
	GPtrArray *contents, *chunks;
	chunk_pair_t pair;
	contents = g_ptr_array_new();
	chunks = g_ptr_array_new();

	/*dispatch */
	for(; beans; beans = beans->next) {
		if (DESCR(beans->data) == &descr_struct_CHUNKS)
			g_ptr_array_add(chunks, _bean_dup(beans->data));
		else if (DESCR(beans->data) == &descr_struct_CONTENTS)
			g_ptr_array_add(contents, _bean_dup(beans->data));
		else if (DESCR(beans->data) == &descr_struct_CONTENTS_HEADERS)
			c->header = _bean_dup(beans->data);
		else if (DESCR(beans->data) == &descr_struct_ALIASES)
			c->alias = _bean_dup(beans->data);
		else if (DESCR(beans->data) == &descr_struct_PROPERTIES)
			c->properties = g_slist_append(c->properties, _bean_dup(beans->data));
	}

	/* build pairs */
	c->pairs = g_array_new(FALSE, FALSE, sizeof(chunk_pair_t));
	for(guint i=0; i < contents->len ; i++) {
		init_chunk_pair(chunks, &pair, g_ptr_array_index(contents, i));
		if(pair.chunk != NULL)
			g_array_append_vals(c->pairs, &pair, 1);
	}
	g_array_sort(c->pairs, (GCompareFunc) compare_pairs_positions);                                             

	// what we want to preserve are the pointers to beans created by
	// _bean_dup, not the GPtrArray -> we can safely free the arrays.
	g_ptr_array_unref(contents);
	g_ptr_array_unref(chunks);

	return c;
}