Skip to content

Commit

Permalink
lib/filterx: style fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Dec 12, 2023
1 parent 5448003 commit b29ccba
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 71 deletions.
3 changes: 2 additions & 1 deletion lib/filterx/expr-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ _eval(FilterXExpr *s)
/* FIXME: we could go directly to filterx_string_new() here to avoid a round trip in FilterXMessageValue */
/* FIXME/2: let's make this handle literal and trivial templates */

log_template_format_value_and_type_with_context(self->template, context->msgs, context->num_msg, context->template_eval_options, value, &t);
log_template_format_value_and_type_with_context(self->template, context->msgs, context->num_msg,
context->template_eval_options, value, &t);

/* NOTE: we borrow value->str here which is stored in a scratch buffer
* that should be valid as long as we are traversing the filter
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/filterx-eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ gboolean
filterx_eval_exec_statements(GList *statements, LogMessage **pmsg, const LogPathOptions *path_options)
{
FilterXScope *scope = filterx_scope_new();
FilterXEvalContext local_context = {
FilterXEvalContext local_context =
{
.msgs = pmsg,
.num_msg = 1,
.template_eval_options = &DEFAULT_TEMPLATE_EVAL_OPTIONS,
Expand Down
10 changes: 5 additions & 5 deletions lib/filterx/filterx-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ void filterx_type_init(FilterXType *type);
#define FILTERX_DECLARE_TYPE(_name) \
extern FilterXType FILTERX_TYPE_NAME(_name)
#define FILTERX_DEFINE_TYPE(_name, _super_type, ...) \
FilterXType FILTERX_TYPE_NAME(_name) = \
{ \
.super_type = &_super_type, \
.name = # _name, \
__VA_ARGS__ \
FilterXType FILTERX_TYPE_NAME(_name) = \
{ \
.super_type = &_super_type, \
.name = # _name, \
__VA_ARGS__ \
}


Expand Down
8 changes: 4 additions & 4 deletions lib/filterx/object-datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ filterx_datetime_new(const UnixTime *ut)
}

FILTERX_DEFINE_TYPE(datetime, FILTERX_TYPE_NAME(object),
.truthy = _truthy,
.map_to_json = _map_to_json,
.marshal = _marshal,
);
.truthy = _truthy,
.map_to_json = _map_to_json,
.marshal = _marshal,
);
27 changes: 14 additions & 13 deletions lib/filterx/object-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ _convert_json_to_object(FilterXJSON *self, struct json_object *object)
case json_type_object:
case json_type_array:
default:
return filterx_json_new_sub(json_object_get(object), filterx_weakref_get(&self->root_container) ? : filterx_object_ref(&self->super));
return filterx_json_new_sub(json_object_get(object),
filterx_weakref_get(&self->root_container) ? : filterx_object_ref(&self->super));
}
}

Expand All @@ -125,14 +126,14 @@ _convert_json_to_object_cached(FilterXJSON *self, struct json_object *object)
if (json_object_get_type(object) == json_type_double)
{
/* this is a workaround to ditch builtin serializer for double objects
* that are set when parsing from a string representation.
* that are set when parsing from a string representation.
* json_object_double_new_ds() will set userdata to the string
* representation of the number, as extracted from the JSON source.
*
*
* Changing the value of the double to the same value, ditches this,
* but only if necessary.
*/

json_object_set_double(object, json_object_get_double(object));
}

Expand Down Expand Up @@ -256,12 +257,12 @@ filterx_json_associate_cached_object(struct json_object *jso, FilterXObject *obj
}

FILTERX_DEFINE_TYPE(json, FILTERX_TYPE_NAME(object),
.mutable = TRUE,
.free_fn = _free,
.truthy = _truthy,
.marshal = _marshal,
.clone = _clone,
.getattr = _getattr,
.setattr = _setattr,
.map_to_json = _map_to_json,
);
.mutable = TRUE,
.free_fn = _free,
.truthy = _truthy,
.marshal = _marshal,
.clone = _clone,
.getattr = _getattr,
.setattr = _setattr,
.map_to_json = _map_to_json,
);
12 changes: 6 additions & 6 deletions lib/filterx/object-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ _free(FilterXObject *s)
}

FILTERX_DEFINE_TYPE(list, FILTERX_TYPE_NAME(object),
.mutable = TRUE,
.free_fn = _free,
.map_to_json = _map_to_json,
.marshal = _marshal,
.truthy = _truthy,
);
.mutable = TRUE,
.free_fn = _free,
.map_to_json = _map_to_json,
.marshal = _marshal,
.truthy = _truthy,
);
12 changes: 6 additions & 6 deletions lib/filterx/object-message-value.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ _free(FilterXObject *s)


FILTERX_DEFINE_TYPE(message_value, FILTERX_TYPE_NAME(object),
.free_fn = _free,
.truthy = _truthy,
.marshal = _marshal,
.unmarshal = _unmarshal,
.map_to_json = _map_to_json,
);
.free_fn = _free,
.truthy = _truthy,
.marshal = _marshal,
.unmarshal = _unmarshal,
.map_to_json = _map_to_json,
);
8 changes: 4 additions & 4 deletions lib/filterx/object-null.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ filterx_null_new(void)
}

FILTERX_DEFINE_TYPE(null, FILTERX_TYPE_NAME(object),
.map_to_json = _map_to_json,
.marshal = _marshal,
.truthy = _truthy,
);
.map_to_json = _map_to_json,
.marshal = _marshal,
.truthy = _truthy,
);
24 changes: 12 additions & 12 deletions lib/filterx/object-primitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@ filterx_boolean_new(gboolean value)
}

FILTERX_DEFINE_TYPE(integer, FILTERX_TYPE_NAME(object),
.truthy = _truthy,
.marshal = _integer_marshal,
.map_to_json = _integer_map_to_json,
);
.truthy = _truthy,
.marshal = _integer_marshal,
.map_to_json = _integer_map_to_json,
);

FILTERX_DEFINE_TYPE(double, FILTERX_TYPE_NAME(object),
.truthy = _truthy,
.marshal = _double_marshal,
.map_to_json = _double_map_to_json,
);
.truthy = _truthy,
.marshal = _double_marshal,
.map_to_json = _double_map_to_json,
);

FILTERX_DEFINE_TYPE(boolean, FILTERX_TYPE_NAME(object),
.truthy = _truthy,
.marshal = _bool_marshal,
.map_to_json = _bool_map_to_json,
);
.truthy = _truthy,
.marshal = _bool_marshal,
.map_to_json = _bool_map_to_json,
);
24 changes: 12 additions & 12 deletions lib/filterx/object-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,19 @@ filterx_protobuf_new(const gchar *mem, gssize mem_len)
/* these types are independent type-wise but share a lot of the details */

FILTERX_DEFINE_TYPE(string, FILTERX_TYPE_NAME(object),
.marshal = _marshal,
.map_to_json = _map_to_json,
.truthy = _truthy,
);
.marshal = _marshal,
.map_to_json = _map_to_json,
.truthy = _truthy,
);

FILTERX_DEFINE_TYPE(bytes, FILTERX_TYPE_NAME(object),
.marshal = _bytes_marshal,
.map_to_json = _bytes_map_to_json,
.truthy = _truthy,
);
.marshal = _bytes_marshal,
.map_to_json = _bytes_map_to_json,
.truthy = _truthy,
);

FILTERX_DEFINE_TYPE(protobuf, FILTERX_TYPE_NAME(object),
.marshal = _bytes_marshal,
.map_to_json = _bytes_map_to_json,
.truthy = _truthy,
);
.marshal = _bytes_marshal,
.map_to_json = _bytes_map_to_json,
.truthy = _truthy,
);
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_primitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down
3 changes: 2 additions & 1 deletion lib/filterx/tests/test_object_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ assert_object_json_equals(FilterXObject *obj, const gchar *expected_json_repr)
{
struct json_object *jso = NULL;

cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s", expected_json_repr);
cr_assert(filterx_object_map_to_json(obj, &jso) == TRUE, "error mapping to json, expected json was: %s",
expected_json_repr);
const gchar *json_repr = json_object_to_json_string_ext(jso, JSON_C_TO_STRING_PLAIN);
cr_assert_str_eq(json_repr, expected_json_repr);
json_object_put(jso);
Expand Down

0 comments on commit b29ccba

Please sign in to comment.