Пример #1
0
static GError*
_list (const char *target, GByteArray *request,
		struct list_result_s *out, gchar ***out_properties)
{
	GError *err = NULL;
	GTree *props = NULL;
	gboolean _cb(gpointer ctx, MESSAGE reply) {
		(void) ctx;

		/* Extract replied aliases */
		GSList *l = NULL;
		GError *e = metautils_message_extract_body_encoded(reply, FALSE, &l, bean_sequence_decoder);
		if (e) {
			GRID_DEBUG("Callback error : %s", e->message);
			err = e;
			return FALSE;
		}

		out->beans = metautils_gslist_precat (out->beans, l);

		/* Extract list flags */
		e = metautils_message_extract_boolean (reply,
				NAME_MSGKEY_TRUNCATED, FALSE, &out->truncated);
		if (e)
			g_clear_error (&e);
		gchar *tok = NULL;
		tok = metautils_message_extract_string_copy (reply, NAME_MSGKEY_NEXTMARKER);
		oio_str_reuse (&out->next_marker, tok);

		/* Extract properties and merge them into the temporary TreeSet. */
		if (out_properties) {
			gchar **names = metautils_message_get_field_names (reply);
			for (gchar **n=names ; n && *n ;++n) {
				if (!g_str_has_prefix (*n, NAME_MSGKEY_PREFIX_PROPERTY))
					continue;
				g_tree_replace (props,
						g_strdup((*n) + sizeof(NAME_MSGKEY_PREFIX_PROPERTY) - 1),
						metautils_message_extract_string_copy(reply, *n));
			}
			if (names) g_strfreev (names);
		}

		return TRUE;
	}
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;
}