aboutgitcodelistschat:MatrixIRC
path: root/cooker/parse.c
diff options
context:
space:
mode:
authorAlice Frosi <afrosi@redhat.com>2023-06-07 16:54:53 +0200
committerAlice Frosi <afrosi@redhat.com>2023-06-07 16:57:23 +0200
commit1c1a9da7a4f9c4c1990192e14763ebf423d812a9 (patch)
treee7fea8962d166cd3d1cf70c84c9098cf6f8b3987 /cooker/parse.c
parentb2e31a6e7493c56f923cb7d86f7a8a32940393ec (diff)
downloadseitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar.gz
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar.bz2
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar.lz
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar.xz
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.tar.zst
seitan-1c1a9da7a4f9c4c1990192e14763ebf423d812a9.zip
seitan, cooker: refactor op_return
Refactor OP_RETURN: - merged OP_BLOCK and OP_CONT into OP_RETURN - add desc field for op_return - updated the demo files
Diffstat (limited to 'cooker/parse.c')
-rw-r--r--cooker/parse.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/cooker/parse.c b/cooker/parse.c
index 81ad159..353947e 100644
--- a/cooker/parse.c
+++ b/cooker/parse.c
@@ -6,6 +6,7 @@
*
* Copyright 2023 Red Hat GmbH
* Author: Stefano Brivio <sbrivio@redhat.com>
+ * Alice Frosi <afrosi@redhat.com>
*/
#include "parson.h"
@@ -73,14 +74,34 @@ static void handle_limit(struct gluten_ctx *g, JSON_Value *value)
static void handle_return(struct gluten_ctx *g, JSON_Value *value)
{
- union value v = { .v_u64 = json_value_get_number(value) };
+ JSON_Object *obj = json_value_get_object(value);
+ JSON_Value *jvalue;
+ union value v = { .v_u64 = 0 };
+ int32_t error = 0;
+ bool cont = false;
- emit_return(g, emit_data(g, U64, sizeof(v.v_u64), &v));
-}
+ debug(" Parsing \"return\"");
-static void handle_block(struct gluten_ctx *g, JSON_Value *value)
-{
- emit_block(g, json_value_get_number(value));
+ jvalue = json_object_get_value(obj, "error");
+ if (json_value_get_type(jvalue) == JSONNumber) {
+ error = json_value_get_number(jvalue);
+ }
+
+ jvalue = json_object_get_value(obj, "value");
+ if (json_value_get_type(jvalue) == JSONNumber) {
+ v.v_u64 = json_value_get_number(jvalue);
+ }
+
+ jvalue = json_object_get_value(obj, "continue");
+ if (json_value_get_type(jvalue) == JSONBoolean) {
+ cont = json_value_get_boolean(jvalue);
+ }
+ if (cont && (v.v_u64 != 0 || error != 0))
+ die(" if continue is true, error and value needs to be zero");
+
+ debug(" emit return: val=%ld errno=%d cont=%s", v.v_u64, error,
+ cont ? "true" : "false");
+ emit_return(g, emit_data(g, U64, sizeof(v.v_u64), &v), error, cont);
}
static void handle_context(struct gluten_ctx *g, JSON_Value *value)
@@ -103,7 +124,6 @@ struct rule_parser {
{ "fd", handle_fd },
{ "limit", handle_limit },
{ "return", handle_return },
- { "block", handle_block },
{ "context", handle_context },
{ NULL, NULL },
};