aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libucl/ucl_util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-27 15:12:28 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-27 15:12:28 +0000
commit2275d0b9ebeda6a1edffb3f1f38d3b3af7c9c8a3 (patch)
tree31435c51aa1e9f6b7f79b5d272f367c3ef134e3a /contrib/libucl/ucl_util.c
parent4ce549ad001660aaf60b3804921a70f2bd8c503a (diff)
downloadrspamd-2275d0b9ebeda6a1edffb3f1f38d3b3af7c9c8a3.tar.gz
rspamd-2275d0b9ebeda6a1edffb3f1f38d3b3af7c9c8a3.zip
Sync with libucl
Diffstat (limited to 'contrib/libucl/ucl_util.c')
-rw-r--r--contrib/libucl/ucl_util.c90
1 files changed, 79 insertions, 11 deletions
diff --git a/contrib/libucl/ucl_util.c b/contrib/libucl/ucl_util.c
index 730a5c4af..2bd0c2a3f 100644
--- a/contrib/libucl/ucl_util.c
+++ b/contrib/libucl/ucl_util.c
@@ -437,7 +437,7 @@ ucl_copy_value_trash (const ucl_object_t *obj)
}
deconst->flags |= UCL_OBJECT_ALLOCATED_VALUE;
}
-
+
return obj->trash_stack[UCL_TRASH_VALUE];
}
@@ -628,7 +628,7 @@ ucl_curl_write_callback (void* contents, size_t size, size_t nmemb, void* ud)
* @param buflen target length
* @return
*/
-static bool
+bool
ucl_fetch_url (const unsigned char *url, unsigned char **buf, size_t *buflen,
UT_string **err, bool must_exist)
{
@@ -690,8 +690,8 @@ ucl_fetch_url (const unsigned char *url, unsigned char **buf, size_t *buflen,
return false;
}
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ucl_curl_write_callback);
- cbdata.buf = *buf;
- cbdata.buflen = *buflen;
+ cbdata.buf = NULL;
+ cbdata.buflen = 0;
curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbdata);
if ((r = curl_easy_perform (curl)) != CURLE_OK) {
@@ -723,7 +723,7 @@ ucl_fetch_url (const unsigned char *url, unsigned char **buf, size_t *buflen,
* @param buflen target length
* @return
*/
-static bool
+bool
ucl_fetch_file (const unsigned char *filename, unsigned char **buf, size_t *buflen,
UT_string **err, bool must_exist)
{
@@ -739,7 +739,7 @@ ucl_fetch_file (const unsigned char *filename, unsigned char **buf, size_t *bufl
}
if (st.st_size == 0) {
/* Do not map empty files */
- *buf = "";
+ *buf = NULL;
*buflen = 0;
}
else {
@@ -848,7 +848,7 @@ ucl_include_url (const unsigned char *data, size_t len,
snprintf (urlbuf, sizeof (urlbuf), "%.*s", (int)len, data);
if (!ucl_fetch_url (urlbuf, &buf, &buflen, &parser->err, params->must_exist)) {
- return (!params->must_exist || false);
+ return !params->must_exist;
}
if (params->check_signature) {
@@ -1232,7 +1232,7 @@ ucl_include_file (const unsigned char *data, size_t len,
treat allow_glob/need_glob as a NOOP and just return */
return ucl_include_file_single (data, len, parser, params);
#endif
-
+
return true;
}
@@ -1252,7 +1252,7 @@ ucl_include_common (const unsigned char *data, size_t len,
bool default_try,
bool default_sign)
{
- bool allow_url, search;
+ bool allow_url = false, search = false;
const char *duplicate;
const ucl_object_t *param;
ucl_object_iter_t it = NULL, ip = NULL;
@@ -1271,8 +1271,6 @@ ucl_include_common (const unsigned char *data, size_t len,
params.strat = UCL_DUPLICATE_APPEND;
params.must_exist = !default_try;
- search = false;
-
/* Process arguments */
if (args != NULL && args->type == UCL_OBJECT) {
while ((param = ucl_iterate_object (args, &it, true)) != NULL) {
@@ -3255,3 +3253,73 @@ ucl_object_set_priority (ucl_object_t *obj,
obj->flags = priority;
}
}
+
+bool
+ucl_object_string_to_type (const char *input, ucl_type_t *res)
+{
+ if (strcasecmp (input, "object") == 0) {
+ *res = UCL_OBJECT;
+ }
+ else if (strcasecmp (input, "array") == 0) {
+ *res = UCL_ARRAY;
+ }
+ else if (strcasecmp (input, "integer") == 0) {
+ *res = UCL_INT;
+ }
+ else if (strcasecmp (input, "number") == 0) {
+ *res = UCL_FLOAT;
+ }
+ else if (strcasecmp (input, "string") == 0) {
+ *res = UCL_STRING;
+ }
+ else if (strcasecmp (input, "boolean") == 0) {
+ *res = UCL_BOOLEAN;
+ }
+ else if (strcasecmp (input, "null") == 0) {
+ *res = UCL_NULL;
+ }
+ else if (strcasecmp (input, "userdata") == 0) {
+ *res = UCL_USERDATA;
+ }
+ else {
+ return false;
+ }
+
+ return true;
+}
+
+const char *
+ucl_object_type_to_string (ucl_type_t type)
+{
+ const char *res = "unknown";
+
+ switch (type) {
+ case UCL_OBJECT:
+ res = "object";
+ break;
+ case UCL_ARRAY:
+ res = "array";
+ break;
+ case UCL_INT:
+ res = "integer";
+ break;
+ case UCL_FLOAT:
+ case UCL_TIME:
+ res = "number";
+ break;
+ case UCL_STRING:
+ res = "string";
+ break;
+ case UCL_BOOLEAN:
+ res = "boolean";
+ break;
+ case UCL_USERDATA:
+ res = "userdata";
+ break;
+ case UCL_NULL:
+ res = "null";
+ break;
+ }
+
+ return res;
+}