diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-10-23 16:51:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2013-10-23 16:51:01 +0100 |
commit | 7ecc32babdc9ea9db7f051923d95715fbcc3a30f (patch) | |
tree | 23578250d07203192834310cd7e43d5acb6ef668 /src/ucl/include | |
parent | 0039ba84e6bca24128cbc75f7f20137ff4070368 (diff) | |
download | rspamd-7ecc32babdc9ea9db7f051923d95715fbcc3a30f.tar.gz rspamd-7ecc32babdc9ea9db7f051923d95715fbcc3a30f.zip |
Sync with libucl.
Diffstat (limited to 'src/ucl/include')
-rw-r--r-- | src/ucl/include/ucl.h | 135 |
1 files changed, 65 insertions, 70 deletions
diff --git a/src/ucl/include/ucl.h b/src/ucl/include/ucl.h index 1b8fa8631..0f132a375 100644 --- a/src/ucl/include/ucl.h +++ b/src/ucl/include/ucl.h @@ -35,7 +35,6 @@ #include "uthash.h" #include "utlist.h" -#include "utstring.h" /** * @file rcl.h @@ -90,29 +89,65 @@ enum ucl_error { UCL_ESSL //!< UCL_ESSL }; +/** + * Object types + */ enum ucl_type { - UCL_OBJECT = 0, - UCL_ARRAY, - UCL_INT, - UCL_FLOAT, - UCL_STRING, - UCL_BOOLEAN, - UCL_TIME, - UCL_USERDATA + UCL_OBJECT = 0,//!< UCL_OBJECT + UCL_ARRAY, //!< UCL_ARRAY + UCL_INT, //!< UCL_INT + UCL_FLOAT, //!< UCL_FLOAT + UCL_STRING, //!< UCL_STRING + UCL_BOOLEAN, //!< UCL_BOOLEAN + UCL_TIME, //!< UCL_TIME + UCL_USERDATA //!< UCL_USERDATA }; +/** + * Emitting types + */ enum ucl_emitter { - UCL_EMIT_JSON = 0, - UCL_EMIT_JSON_COMPACT, - UCL_EMIT_CONFIG, - UCL_EMIT_YAML + UCL_EMIT_JSON = 0, //!< UCL_EMIT_JSON + UCL_EMIT_JSON_COMPACT,//!< UCL_EMIT_JSON_COMPACT + UCL_EMIT_CONFIG, //!< UCL_EMIT_CONFIG + UCL_EMIT_YAML //!< UCL_EMIT_YAML +}; + +/** + * Parsing flags + */ +enum ucl_parser_flags { + UCL_PARSER_KEY_LOWERCASE = 0x1,//!< UCL_FLAG_KEY_LOWERCASE + UCL_PARSER_ZEROCOPY = 0x2 //!< UCL_FLAG_ZEROCOPY +}; + +/** + * String conversion flags + */ +enum ucl_string_flags { + UCL_STRING_ESCAPE = 0x1, /**< UCL_STRING_ESCAPE perform JSON escape */ + UCL_STRING_TRIM = 0x2, /**< UCL_STRING_TRIM trim leading and trailing whitespaces */ + UCL_STRING_PARSE_BOOLEAN = 0x4, /**< UCL_STRING_PARSE_BOOLEAN parse passed string and detect boolean */ + UCL_STRING_PARSE_INT = 0x8, /**< UCL_STRING_PARSE_INT parse passed string and detect integer number */ + UCL_STRING_PARSE_DOUBLE = 0x10, /**< UCL_STRING_PARSE_DOUBLE parse passed string and detect integer or float number */ + UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE , /**< + UCL_STRING_PARSE_NUMBER parse passed string and detect number */ + UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER /**< + UCL_STRING_PARSE parse passed string (and detect booleans and numbers) */ }; -enum ucl_flags { - UCL_FLAG_KEY_LOWERCASE = 0x1, - UCL_FLAG_ZEROCOPY = 0x2 +/** + * Basic flags for an object + */ +enum ucl_object_flags { + UCL_OBJECT_ALLOCATED_KEY = 1, //!< UCL_OBJECT_ALLOCATED_KEY + UCL_OBJECT_ALLOCATED_VALUE = 2, //!< UCL_OBJECT_ALLOCATED_VALUE + UCL_OBJECT_NEED_KEY_ESCAPE = 4 //!< UCL_OBJECT_NEED_KEY_ESCAPE }; +/** + * UCL object + */ typedef struct ucl_object_s { union { int64_t iv; /**< int value of an object */ @@ -122,7 +157,8 @@ typedef struct ucl_object_s { void* ud; /**< opaque user data */ } value; enum ucl_type type; /**< real type */ - int ref; /**< reference count */ + short int ref; /**< reference count */ + short int flags; /**< object flags */ size_t len; /**< size of an object */ struct ucl_object_s *next; /**< array handle */ struct ucl_object_s *prev; /**< array handle */ @@ -162,21 +198,6 @@ ucl_object_new (void) } /** - * String conversion flags - */ -enum ucl_string_flags { - UCL_STRING_ESCAPE = 0x1, /**< UCL_STRING_ESCAPE perform JSON escape */ - UCL_STRING_TRIM = 0x2, /**< UCL_STRING_TRIM trim leading and trailing whitespaces */ - UCL_STRING_PARSE_BOOLEAN = 0x4, /**< UCL_STRING_PARSE_BOOLEAN parse passed string and detect boolean */ - UCL_STRING_PARSE_INT = 0x8, /**< UCL_STRING_PARSE_INT parse passed string and detect integer number */ - UCL_STRING_PARSE_DOUBLE = 0x10, /**< UCL_STRING_PARSE_DOUBLE parse passed string and detect integer or float number */ - UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE , /**< - UCL_STRING_PARSE_NUMBER parse passed string and detect number */ - UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER /**< - UCL_STRING_PARSE parse passed string (and detect booleans and numbers) */ -}; - -/** * Convert any string to an ucl object making the specified transformations * @param str fixed size or NULL terminated string * @param len length (if len is zero, than str is treated as NULL terminated) @@ -274,37 +295,8 @@ ucl_object_frombool (bool bv) * @param copy_key make an internal copy of key * @return new value of top object */ -static inline ucl_object_t * -ucl_object_insert_key (ucl_object_t *top, ucl_object_t *elt, - const char *key, size_t keylen, bool copy_key) -{ - ucl_object_t *found; - - if (elt == NULL || key == NULL) { - return NULL; - } - - if (top == NULL) { - top = ucl_object_new (); - top->type = UCL_OBJECT; - } - if (keylen == 0) { - keylen = strlen (key); - } - - HASH_FIND (hh, top->value.ov, key, keylen, found); - - if (!found) { - HASH_ADD_KEYPTR (hh, top->value.ov, key, keylen, elt); - } - DL_APPEND (found, elt); - - if (copy_key) { - ucl_copy_key_trash (elt); - } - - return top; -} +ucl_object_t* ucl_object_insert_key (ucl_object_t *top, ucl_object_t *elt, + const char *key, size_t keylen, bool copy_key); /** * Append an element to the array object @@ -625,7 +617,7 @@ ucl_object_keyl (ucl_object_t *obj, size_t *len) * @param err error pointer * @return true if macro has been parsed */ -typedef bool (*ucl_macro_handler) (const unsigned char *data, size_t len, void* ud, UT_string **err); +typedef bool (*ucl_macro_handler) (const unsigned char *data, size_t len, void* ud); /* Opaque parser */ struct ucl_parser; @@ -655,8 +647,7 @@ void ucl_parser_register_macro (struct ucl_parser *parser, const char *macro, * @param err if *err is NULL it is set to parser error * @return true if chunk has been added and false in case of error */ -bool ucl_parser_add_chunk (struct ucl_parser *parser, const unsigned char *data, - size_t len, UT_string **err); +bool ucl_parser_add_chunk (struct ucl_parser *parser, const unsigned char *data, size_t len); /** * Load and add data from a file @@ -665,8 +656,7 @@ bool ucl_parser_add_chunk (struct ucl_parser *parser, const unsigned char *data, * @param err if *err is NULL it is set to parser error * @return true if chunk has been added and false in case of error */ -bool ucl_parser_add_file (struct ucl_parser *parser, const char *filename, - UT_string **err); +bool ucl_parser_add_file (struct ucl_parser *parser, const char *filename); /** * Get a top object for a parser @@ -674,9 +664,14 @@ bool ucl_parser_add_file (struct ucl_parser *parser, const char *filename, * @param err if *err is NULL it is set to parser error * @return top parser object or NULL */ -ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser, UT_string **err); +ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser); /** + * Get the error string if failing + * @param parser parser object + */ +const char *ucl_parser_get_error(struct ucl_parser *parser); +/** * Free cl parser object * @param parser parser object */ @@ -726,6 +721,6 @@ unsigned char *ucl_object_emit (ucl_object_t *obj, enum ucl_emitter emit_type); * @param err if *err is NULL it is set to parser error * @return true if a key has been successfully added */ -bool ucl_pubkey_add (struct ucl_parser *parser, const unsigned char *key, size_t len, UT_string **err); +bool ucl_pubkey_add (struct ucl_parser *parser, const unsigned char *key, size_t len); #endif /* RCL_H_ */ |