Esempio n. 1
0
	void test(struct meta2_backend_s *m2, struct hc_url_s *url) {
		GError *err;
		/* Generate a list of beans */
		GSList *beans = create_alias(m2, url, NULL);
		/* Change the hash of the chunk beans (0 by default) */
		change_chunk_hash(beans, 0);
		/* Put the beans in the database */
		err = meta2_backend_put_alias(m2, url, beans, NULL, NULL);
		g_assert_no_error(err);
		_bean_cleanl2(beans);

		/* Generate other contents with same hashes */
		for (guint counter = 1; counter <= num_duplicates; counter++) {
			/* Suffix the base url */
			gchar *url_str = g_strdup_printf("%s_%d", hc_url_get(url, HCURL_WHOLE),
					counter);
			struct hc_url_s *url2 = hc_url_oldinit(url_str);
			g_free(url_str);
			GSList *beans2 = create_alias(m2, url2, NULL);
			change_chunk_hash(beans2, counter);
			err = meta2_backend_put_alias(m2, url2, beans2, NULL, NULL);
			g_assert_no_error(err);
			_bean_cleanl2(beans2);
		}

		err = meta2_backend_deduplicate_chunks(m2, url);
		g_assert_no_error(err);
	}
static void
_plist_cleaner(gpointer ptr)
{
	GSList **lists = ptr;
	_bean_cleanl2(lists[0]);
	_bean_cleanl2(lists[1]);
	g_free (lists);
}
Esempio n. 3
0
int meta2_filter_action_purge_container(struct gridd_filter_ctx_s *ctx,
		struct gridd_reply_ctx_s *reply)
{
	(void) reply;

	SRVSTUB_PRINTF("packet received...PURGE");

	// M2V2_MODE_DRYRUN, ...
	guint32 flags = 0;
	const char *fstr = NULL;
	if (NULL != fstr)
		flags = (guint32) g_ascii_strtoull(fstr, NULL, 10);

	GSList* del_chunks_list = NULL;

	if (NULL != g_err) {
		GRID_DEBUG("Container purge failed (%d) : %s", g_err->code, g_err->message);
		//meta2_filter_ctx_set_error(ctx, err);
		return FILTER_KO;
	}


	reply->add_body(bean_sequence_marshall(g_responsedata));
	reply->send_reply(200, "OK");
	_bean_cleanl2(del_chunks_list);
	return FILTER_OK;
}
Esempio n. 4
0
static GError *
_jarray_to_beans (GSList **out, struct json_object *jv, jbean_mapper map)
{
	if (!json_object_is_type(jv, json_type_array))
		return NEWERROR(CODE_BAD_REQUEST, "Invalid JSON, exepecting array of beans");

	GSList *l = NULL;
	int vlen = json_object_array_length (jv);
	for (int i=0; i<vlen ;++i) {
		struct json_object *j = json_object_array_get_idx (jv, i);
		if (!json_object_is_type (j, json_type_object))
			return NEWERROR(CODE_BAD_REQUEST, "Invalid JSON for a bean");
		gpointer bean = NULL;
		GError *err = map(j, &bean);
		EXTRA_ASSERT((bean != NULL) ^ (err != NULL));
		if (err) {
			_bean_cleanl2 (l);
			return err;
		}
		l = g_slist_prepend(l, bean);
	}

	*out = g_slist_reverse (l);
	return NULL;
}
Esempio n. 5
0
void
m2v2_list_result_clean (struct list_result_s *p)
{
	if (!p) return;
	_bean_cleanl2(p->beans);
	p->beans = NULL;
	oio_str_clean(&p->next_marker);
	p->truncated = FALSE;
}
Esempio n. 6
0
static gs_error_t *
_dl_nocache(gs_container_t *c, struct hc_url_s *url,
		gs_download_info_t *dlinfo, gchar *stgpol)
{
	gs_error_t *e = NULL;
	GError *err = NULL;
	gs_content_t *content = NULL;
	namespace_info_t *ni = NULL;
	GSList *filtered = NULL, *beans = NULL;

	/*find the content*/
	content  = gs_get_content_from_path_full(c, hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_SNAPORVERS), &filtered, &beans, &e);

	if(NULL != content) {
		GRID_DEBUG("Content %s found in container %s\n",
				hc_url_get(url, HCURL_PATH), hc_url_get(url, HCURL_REFERENCE));

		ni = get_namespace_info(hc_url_get(url, HCURL_NS), &err);
		if (!ni) {
			GSERRORCAUSE(&e, err, "Cannot get namespace info for NS [%s]",
					hc_url_get(url, HCURL_NS));
			g_clear_error(&err);
			return e;
		}

		namespace_info_copy(ni, &(content->info.container->info.gs->ni), &err);

		/*download the content*/
		(void) gs_download_content_full (content, dlinfo, stgpol, filtered,
				beans, &e);
		namespace_info_clear(ni);
		g_free(ni);
		gs_content_free (content);
		g_slist_free(filtered);
		_bean_cleanl2(beans);
		return e;
	}

	g_printerr("'%s' not found in '%s'\n", hc_url_get(url, HCURL_PATH),
			hc_url_get(url, HCURL_REFERENCE));
	return e;
}
Esempio n. 7
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);
}
int
meta2_filter_extract_body_beans(struct gridd_filter_ctx_s *ctx,
                struct gridd_reply_ctx_s *reply)
{
	GSList *l = NULL;
	const char *opt = meta2_filter_ctx_get_param(ctx, "BODY_OPT");

	TRACE_FILTER();

	/* get the message body */
	GError *err = metautils_message_extract_body_encoded (reply->request, (opt==NULL), &l, bean_sequence_decoder);
	if (err) {
		_bean_cleanl2 (l);
		meta2_filter_ctx_set_error(ctx, NEWERROR(CODE_BAD_REQUEST,
					"Invalid request, Empty / Invalid body"));
		return FILTER_KO;
	}

	meta2_filter_ctx_set_input_udata(ctx, l, (GDestroyNotify)_bean_cleanl2);
	return FILTER_OK;
}
Esempio n. 9
0
GError *
m2v2_json_load_setof_xbean (struct json_object *jv, GSList **out)
{
	if (!json_object_is_type(jv, json_type_array))
		return NEWERROR(CODE_BAD_REQUEST, "Invalid JSON, exepecting array of beans");

	GSList *l = NULL;
	int vlen = json_object_array_length (jv);
	for (int i=0; i<vlen ;++i) {
		struct json_object *j = json_object_array_get_idx (jv, i);
		gpointer bean = NULL;
		GError *err = m2v2_json_load_single_xbean(j, &bean);
		EXTRA_ASSERT((bean != NULL) ^ (err != NULL));
		if (err) {
			_bean_cleanl2 (l);
			return err;
		}
		l = g_slist_prepend(l, bean);
	}

	*out = g_slist_reverse(l); // Serve the beans in the same order!
	return NULL;
}
Esempio n. 10
0
void
_on_bean_ctx_append_udata_list(struct on_bean_ctx_s *obc)
{
	struct meta2_backend_s *m2b = meta2_filter_ctx_get_backend(obc->ctx);
	struct hc_url_s *url = meta2_filter_ctx_get_url(obc->ctx);
	struct event_config_s * evt_config = meta2_backend_get_event_config(m2b,
			hc_url_get(url, HCURL_NS));

	if (event_is_enabled(evt_config) || event_is_notifier_enabled(evt_config)) {
		if (obc->first) {
			obc->first = FALSE;
			meta2_filter_ctx_set_input_udata(obc->ctx, obc->l,
					(GDestroyNotify)_bean_cleanl2);
		} else {
			meta2_filter_ctx_set_input_udata2(obc->ctx,
					g_slist_concat(obc->l,
						(GSList*)meta2_filter_ctx_get_input_udata(obc->ctx)),
					(GDestroyNotify) _bean_cleanl2, FALSE);
		}
	} else {
		GRID_TRACE("Events disabled, cleaning beans immediately");
		_bean_cleanl2(obc->l);
	}
}