From a9cb85bea36d6c02960d060df99786f0d4ebf0de Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 4 Aug 2013 17:02:33 +0100 Subject: [PATCH] Add skeleton files for RCL library. --- CMakeLists.txt | 1 + src/rcl/rcl.h | 42 ++++++++++++++++++++++++++++++++++++++++-- src/rcl/rcl_emitter.c | 31 +++++++++++++++++++++++++++++++ src/rcl/rcl_internal.h | 34 ++++++++++++++++++++++++++++++++++ src/rcl/rcl_parser.c | 31 +++++++++++++++++++++++++++++++ src/rcl/rcl_util.c | 31 +++++++++++++++++++++++++++++++ 6 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 src/rcl/rcl_emitter.c create mode 100644 src/rcl/rcl_internal.h create mode 100644 src/rcl/rcl_parser.c create mode 100644 src/rcl/rcl_util.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a42dfb6d..a25183305 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1054,6 +1054,7 @@ ENDIF(NOT HIREDIS_FOUND) ADD_SUBDIRECTORY(src/lua) ADD_SUBDIRECTORY(src/json) ADD_SUBDIRECTORY(src/cdb) +ADD_SUBDIRECTORY(src/rcl) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(src/client) diff --git a/src/rcl/rcl.h b/src/rcl/rcl.h index 07dcd5b92..27bfc32de 100644 --- a/src/rcl/rcl.h +++ b/src/rcl/rcl.h @@ -39,8 +39,9 @@ enum rspamd_cl_type { RSPAMD_CL_OBJECT = 0, RSPAMD_CL_ARRAY, RSPAMD_CL_NUMBER, + RSPAMD_CL_FLOAT, RSPAMD_CL_STRING, - RSPAMD_CL_FLOAT + RSPAMD_CL_BOOLEAN }; enum rspamd_cl_emitter { @@ -138,6 +139,43 @@ rspamd_cl_obj_toint (rspamd_cl_object_t *obj) return result; } +/** + * Converts an object to boolean value + * @param obj CL object + * @param target target boolean variable + * @return TRUE if conversion was successful + */ +static inline gboolean +rspamd_cl_obj_toboolean_safe (rspamd_cl_object_t *obj, gboolean *target) +{ + if (obj == NULL) { + return FALSE; + } + switch (obj->type) { + case RSPAMD_CL_BOOLEAN: + *target = (obj->value.iv == TRUE); + break; + default: + return FALSE; + } + + return TRUE; +} + +/** + * Unsafe version of \ref rspamd_cl_obj_toboolean_safe + * @param obj CL object + * @return boolean value + */ +static inline gboolean +rspamd_cl_obj_toboolean (rspamd_cl_object_t *obj) +{ + gboolean result = FALSE; + + rspamd_cl_obj_toboolean_safe (obj, &result); + return result; +} + /** * Converts an object to string value * @param obj CL object @@ -167,7 +205,7 @@ rspamd_cl_obj_tostring_safe (rspamd_cl_object_t *obj, const gchar **target) * @return string value */ static inline const gchar * -rspamd_cl_obj_toint (rspamd_cl_object_t *obj) +rspamd_cl_obj_tostring (rspamd_cl_object_t *obj) { const gchar *result = NULL; diff --git a/src/rcl/rcl_emitter.c b/src/rcl/rcl_emitter.c new file mode 100644 index 000000000..d967ba7d2 --- /dev/null +++ b/src/rcl/rcl_emitter.c @@ -0,0 +1,31 @@ +/* Copyright (c) 2013, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "rcl.h" +#include "rcl_internal.h" + +/** + * @file rcl_emitter.c + * Serialise RCL object to the RCL format + */ diff --git a/src/rcl/rcl_internal.h b/src/rcl/rcl_internal.h new file mode 100644 index 000000000..b94ecd90f --- /dev/null +++ b/src/rcl/rcl_internal.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2013, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RCL_INTERNAL_H_ +#define RCL_INTERNAL_H_ + +#include "rcl.h" + +/** + * @file rcl_internal.h + * Internal structures and functions of RCL library + */ + +#endif /* RCL_INTERNAL_H_ */ diff --git a/src/rcl/rcl_parser.c b/src/rcl/rcl_parser.c new file mode 100644 index 000000000..574edf8c0 --- /dev/null +++ b/src/rcl/rcl_parser.c @@ -0,0 +1,31 @@ +/* Copyright (c) 2013, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "rcl.h" +#include "rcl_internal.h" + +/** + * @file rcl_parser.c + * The implementation of rcl parser + */ diff --git a/src/rcl/rcl_util.c b/src/rcl/rcl_util.c new file mode 100644 index 000000000..96fc8dda4 --- /dev/null +++ b/src/rcl/rcl_util.c @@ -0,0 +1,31 @@ +/* Copyright (c) 2013, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "rcl.h" +#include "rcl_internal.h" + +/** + * @file rcl_util.c + * Utilities for rcl parsing + */ -- 2.39.5