-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4871 from alltilla/filterx-format-json
filterx: add `format_json()`
- Loading branch information
Showing
23 changed files
with
831 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2024 Attila Szakacs | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#include "filterx.h" | ||
#include "filterx/object-json.h" | ||
|
||
FilterXObject * | ||
filterx_test_dict_new(void) | ||
{ | ||
FilterXObject *result = filterx_json_object_new_empty(); | ||
result->type = &FILTERX_TYPE_NAME(test_dict); | ||
return result; | ||
} | ||
|
||
FilterXObject * | ||
filterx_test_list_new(void) | ||
{ | ||
FilterXObject *result = filterx_json_array_new_empty(); | ||
result->type = &FILTERX_TYPE_NAME(test_list); | ||
return result; | ||
} | ||
|
||
const gchar * | ||
filterx_test_unknown_object_marshaled_repr(gssize *len) | ||
{ | ||
static const gchar *marshalled = "test_unknown_object"; | ||
if (len) | ||
*len = strlen(marshalled); | ||
return marshalled; | ||
} | ||
|
||
static gboolean | ||
_unknown_marshal(FilterXObject *s, GString *repr, LogMessageValueType *t) | ||
{ | ||
*t = LM_VT_STRING; | ||
g_string_append(repr, filterx_test_unknown_object_marshaled_repr(NULL)); | ||
return TRUE; | ||
} | ||
|
||
static gboolean | ||
_unknown_truthy(FilterXObject *s) | ||
{ | ||
return TRUE; | ||
} | ||
|
||
static gboolean | ||
_unknown_map_to_json(FilterXObject *s, struct json_object **object) | ||
{ | ||
gssize len; | ||
const gchar *repr = filterx_test_unknown_object_marshaled_repr(&len); | ||
*object = json_object_new_string_len(repr, len); | ||
return TRUE; | ||
} | ||
|
||
FilterXObject * | ||
filterx_test_unknown_object_new(void) | ||
{ | ||
return filterx_object_new(&FILTERX_TYPE_NAME(test_unknown_object)); | ||
} | ||
|
||
void | ||
init_libtest_filterx(void) | ||
{ | ||
filterx_type_init(&FILTERX_TYPE_NAME(test_unknown_object)); | ||
|
||
/* These will use the json implementations, but won't be json typed. */ | ||
filterx_type_init(&FILTERX_TYPE_NAME(test_dict)); | ||
filterx_type_init(&FILTERX_TYPE_NAME(test_list)); | ||
FILTERX_TYPE_NAME(test_dict) = FILTERX_TYPE_NAME(json_object); | ||
FILTERX_TYPE_NAME(test_list) = FILTERX_TYPE_NAME(json_array); | ||
} | ||
|
||
void | ||
deinit_libtest_filterx(void) | ||
{ | ||
} | ||
|
||
FILTERX_DEFINE_TYPE(test_dict, FILTERX_TYPE_NAME(object)); | ||
FILTERX_DEFINE_TYPE(test_list, FILTERX_TYPE_NAME(object)); | ||
FILTERX_DEFINE_TYPE(test_unknown_object, FILTERX_TYPE_NAME(object), | ||
.is_mutable = FALSE, | ||
.truthy = _unknown_truthy, | ||
.marshal = _unknown_marshal, | ||
.map_to_json = _unknown_map_to_json, | ||
.list_factory = filterx_test_list_new, | ||
.dict_factory = filterx_test_dict_new); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2024 Attila Szakacs | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#ifndef LIBTEST_FILTERX_H_INCLUDED | ||
#define LIBTEST_FILTERX_H_INCLUDED | ||
|
||
#include "filterx/filterx-object.h" | ||
|
||
FILTERX_DECLARE_TYPE(test_dict); | ||
FILTERX_DECLARE_TYPE(test_list); | ||
FILTERX_DECLARE_TYPE(test_unknown_object); | ||
|
||
FilterXObject *filterx_test_dict_new(void); | ||
FilterXObject *filterx_test_list_new(void); | ||
FilterXObject *filterx_test_unknown_object_new(void); | ||
|
||
const gchar *filterx_test_unknown_object_marshaled_repr(gssize *len); | ||
|
||
void init_libtest_filterx(void); | ||
void deinit_libtest_filterx(void); | ||
|
||
#endif |
Oops, something went wrong.