1262395Sbapt/* Copyright (c) 2013, Vsevolod Stakhov 2262395Sbapt * All rights reserved. 3262395Sbapt * 4262395Sbapt * Redistribution and use in source and binary forms, with or without 5262395Sbapt * modification, are permitted provided that the following conditions are met: 6262395Sbapt * * Redistributions of source code must retain the above copyright 7262395Sbapt * notice, this list of conditions and the following disclaimer. 8262395Sbapt * * Redistributions in binary form must reproduce the above copyright 9262395Sbapt * notice, this list of conditions and the following disclaimer in the 10262395Sbapt * documentation and/or other materials provided with the distribution. 11262395Sbapt * 12262395Sbapt * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY 13262395Sbapt * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14262395Sbapt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15262395Sbapt * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY 16262395Sbapt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17262395Sbapt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18262395Sbapt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 19262395Sbapt * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20262395Sbapt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21262395Sbapt * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22262395Sbapt */ 23262395Sbapt 24262395Sbapt#ifndef UCL_INTERNAL_H_ 25262395Sbapt#define UCL_INTERNAL_H_ 26262395Sbapt 27263648Sbapt#ifdef HAVE_CONFIG_H 28263648Sbapt#include "config.h" 29263648Sbapt#else 30263648Sbapt/* Help embedded builds */ 31263648Sbapt#define HAVE_SYS_TYPES_H 32263648Sbapt#define HAVE_SYS_MMAN_H 33263648Sbapt#define HAVE_SYS_STAT_H 34263648Sbapt#define HAVE_SYS_PARAM_H 35263648Sbapt#define HAVE_LIMITS_H 36263648Sbapt#define HAVE_FCNTL_H 37263648Sbapt#define HAVE_ERRNO_H 38263648Sbapt#define HAVE_UNISTD_H 39263648Sbapt#define HAVE_CTYPE_H 40263648Sbapt#define HAVE_STDIO_H 41263648Sbapt#define HAVE_STRING_H 42263648Sbapt#define HAVE_FLOAT_H 43263648Sbapt#define HAVE_LIBGEN_H 44263648Sbapt#define HAVE_MATH_H 45263648Sbapt#define HAVE_STDBOOL_H 46263648Sbapt#define HAVE_STDINT_H 47263648Sbapt#define HAVE_STDARG_H 48264789Sbapt#ifndef _WIN32 49264789Sbapt# define HAVE_REGEX_H 50263648Sbapt#endif 51264789Sbapt#endif 52263648Sbapt 53263648Sbapt#ifdef HAVE_SYS_TYPES_H 54262395Sbapt#include <sys/types.h> 55262975Sbapt#endif 56263648Sbapt 57263648Sbapt#ifdef HAVE_SYS_MMAN_H 58263648Sbapt# ifndef _WIN32 59263648Sbapt# include <sys/mman.h> 60263648Sbapt# endif 61263648Sbapt#endif 62263648Sbapt#ifdef HAVE_SYS_STAT_H 63262395Sbapt#include <sys/stat.h> 64263648Sbapt#endif 65263648Sbapt#ifdef HAVE_SYS_PARAM_H 66262395Sbapt#include <sys/param.h> 67263648Sbapt#endif 68262395Sbapt 69263648Sbapt#ifdef HAVE_LIMITS_H 70262395Sbapt#include <limits.h> 71263648Sbapt#endif 72263648Sbapt#ifdef HAVE_FCNTL_H 73262395Sbapt#include <fcntl.h> 74263648Sbapt#endif 75263648Sbapt#ifdef HAVE_ERRNO_H 76262395Sbapt#include <errno.h> 77263648Sbapt#endif 78263648Sbapt#ifdef HAVE_UNISTD_H 79262395Sbapt#include <unistd.h> 80263648Sbapt#endif 81263648Sbapt#ifdef HAVE_CTYPE_H 82262395Sbapt#include <ctype.h> 83263648Sbapt#endif 84263648Sbapt#ifdef HAVE_STDIO_H 85263648Sbapt#include <stdio.h> 86263648Sbapt#endif 87263648Sbapt#ifdef HAVE_STRING_H 88263648Sbapt#include <string.h> 89263648Sbapt#endif 90314278Sbapt#ifdef HAVE_STRINGS_H 91314278Sbapt#include <strings.h> 92314278Sbapt#endif 93262395Sbapt 94262395Sbapt#include "utlist.h" 95262395Sbapt#include "utstring.h" 96262395Sbapt#include "uthash.h" 97262395Sbapt#include "ucl.h" 98262395Sbapt#include "ucl_hash.h" 99262395Sbapt 100262395Sbapt#ifdef HAVE_OPENSSL 101262395Sbapt#include <openssl/evp.h> 102262395Sbapt#endif 103262395Sbapt 104264789Sbapt#ifndef __DECONST 105264789Sbapt#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 106264789Sbapt#endif 107264789Sbapt 108262395Sbapt/** 109262395Sbapt * @file rcl_internal.h 110262395Sbapt * Internal structures and functions of UCL library 111262395Sbapt */ 112262395Sbapt 113262395Sbapt#define UCL_MAX_RECURSION 16 114262395Sbapt#define UCL_TRASH_KEY 0 115262395Sbapt#define UCL_TRASH_VALUE 1 116262395Sbapt 117262395Sbaptenum ucl_parser_state { 118262395Sbapt UCL_STATE_INIT = 0, 119262395Sbapt UCL_STATE_OBJECT, 120262395Sbapt UCL_STATE_ARRAY, 121262395Sbapt UCL_STATE_KEY, 122262395Sbapt UCL_STATE_VALUE, 123262395Sbapt UCL_STATE_AFTER_VALUE, 124262395Sbapt UCL_STATE_ARRAY_VALUE, 125262395Sbapt UCL_STATE_SCOMMENT, 126262395Sbapt UCL_STATE_MCOMMENT, 127262395Sbapt UCL_STATE_MACRO_NAME, 128262395Sbapt UCL_STATE_MACRO, 129262395Sbapt UCL_STATE_ERROR 130262395Sbapt}; 131262395Sbapt 132262395Sbaptenum ucl_character_type { 133314278Sbapt UCL_CHARACTER_DENIED = (1 << 0), 134314278Sbapt UCL_CHARACTER_KEY = (1 << 1), 135314278Sbapt UCL_CHARACTER_KEY_START = (1 << 2), 136314278Sbapt UCL_CHARACTER_WHITESPACE = (1 << 3), 137314278Sbapt UCL_CHARACTER_WHITESPACE_UNSAFE = (1 << 4), 138314278Sbapt UCL_CHARACTER_VALUE_END = (1 << 5), 139314278Sbapt UCL_CHARACTER_VALUE_STR = (1 << 6), 140314278Sbapt UCL_CHARACTER_VALUE_DIGIT = (1 << 7), 141314278Sbapt UCL_CHARACTER_VALUE_DIGIT_START = (1 << 8), 142314278Sbapt UCL_CHARACTER_ESCAPE = (1 << 9), 143314278Sbapt UCL_CHARACTER_KEY_SEP = (1 << 10), 144314278Sbapt UCL_CHARACTER_JSON_UNSAFE = (1 << 11), 145314278Sbapt UCL_CHARACTER_UCL_UNSAFE = (1 << 12) 146262395Sbapt}; 147262395Sbapt 148262395Sbaptstruct ucl_macro { 149262395Sbapt char *name; 150290071Sbapt union { 151290071Sbapt ucl_macro_handler handler; 152290071Sbapt ucl_context_macro_handler context_handler; 153290071Sbapt } h; 154262395Sbapt void* ud; 155290071Sbapt bool is_context; 156262395Sbapt UT_hash_handle hh; 157262395Sbapt}; 158262395Sbapt 159262395Sbaptstruct ucl_stack { 160262395Sbapt ucl_object_t *obj; 161262395Sbapt struct ucl_stack *next; 162290071Sbapt uint64_t level; 163262395Sbapt}; 164262395Sbapt 165262395Sbaptstruct ucl_chunk { 166262395Sbapt const unsigned char *begin; 167262395Sbapt const unsigned char *end; 168262395Sbapt const unsigned char *pos; 169262395Sbapt size_t remain; 170262395Sbapt unsigned int line; 171262395Sbapt unsigned int column; 172275223Sbapt unsigned priority; 173290071Sbapt enum ucl_duplicate_strategy strategy; 174290071Sbapt enum ucl_parse_type parse_type; 175262395Sbapt struct ucl_chunk *next; 176262395Sbapt}; 177262395Sbapt 178262395Sbapt#ifdef HAVE_OPENSSL 179262395Sbaptstruct ucl_pubkey { 180262395Sbapt EVP_PKEY *key; 181262395Sbapt struct ucl_pubkey *next; 182262395Sbapt}; 183262395Sbapt#else 184262395Sbaptstruct ucl_pubkey { 185262395Sbapt struct ucl_pubkey *next; 186262395Sbapt}; 187262395Sbapt#endif 188262395Sbapt 189262395Sbaptstruct ucl_variable { 190262395Sbapt char *var; 191262395Sbapt char *value; 192262395Sbapt size_t var_len; 193262395Sbapt size_t value_len; 194275223Sbapt struct ucl_variable *prev, *next; 195262395Sbapt}; 196262395Sbapt 197262395Sbaptstruct ucl_parser { 198262395Sbapt enum ucl_parser_state state; 199262395Sbapt enum ucl_parser_state prev_state; 200262395Sbapt unsigned int recursion; 201262395Sbapt int flags; 202290071Sbapt unsigned default_priority; 203290071Sbapt int err_code; 204262395Sbapt ucl_object_t *top_obj; 205262395Sbapt ucl_object_t *cur_obj; 206290071Sbapt ucl_object_t *trash_objs; 207290071Sbapt ucl_object_t *includepaths; 208275223Sbapt char *cur_file; 209262395Sbapt struct ucl_macro *macroes; 210262395Sbapt struct ucl_stack *stack; 211262395Sbapt struct ucl_chunk *chunks; 212262395Sbapt struct ucl_pubkey *keys; 213262395Sbapt struct ucl_variable *variables; 214266636Sbapt ucl_variable_handler var_handler; 215266636Sbapt void *var_data; 216298166Sbapt ucl_object_t *comments; 217298166Sbapt ucl_object_t *last_comment; 218262395Sbapt UT_string *err; 219262395Sbapt}; 220262395Sbapt 221275223Sbaptstruct ucl_object_userdata { 222275223Sbapt ucl_object_t obj; 223275223Sbapt ucl_userdata_dtor dtor; 224275223Sbapt ucl_userdata_emitter emitter; 225275223Sbapt}; 226275223Sbapt 227262395Sbapt/** 228262395Sbapt * Unescape json string inplace 229262395Sbapt * @param str 230262395Sbapt */ 231262395Sbaptsize_t ucl_unescape_json_string (char *str, size_t len); 232262395Sbapt 233262395Sbapt/** 234262395Sbapt * Handle include macro 235262395Sbapt * @param data include data 236262395Sbapt * @param len length of data 237290071Sbapt * @param args UCL object representing arguments to the macro 238262395Sbapt * @param ud user data 239262395Sbapt * @return 240262395Sbapt */ 241275223Sbaptbool ucl_include_handler (const unsigned char *data, size_t len, 242275223Sbapt const ucl_object_t *args, void* ud); 243262395Sbapt 244290071Sbapt/** 245290071Sbapt * Handle tryinclude macro 246290071Sbapt * @param data include data 247290071Sbapt * @param len length of data 248290071Sbapt * @param args UCL object representing arguments to the macro 249290071Sbapt * @param ud user data 250290071Sbapt * @return 251290071Sbapt */ 252275223Sbaptbool ucl_try_include_handler (const unsigned char *data, size_t len, 253275223Sbapt const ucl_object_t *args, void* ud); 254262395Sbapt 255262395Sbapt/** 256262395Sbapt * Handle includes macro 257262395Sbapt * @param data include data 258262395Sbapt * @param len length of data 259290071Sbapt * @param args UCL object representing arguments to the macro 260262395Sbapt * @param ud user data 261262395Sbapt * @return 262262395Sbapt */ 263275223Sbaptbool ucl_includes_handler (const unsigned char *data, size_t len, 264275223Sbapt const ucl_object_t *args, void* ud); 265262395Sbapt 266290071Sbapt/** 267290071Sbapt * Handle priority macro 268290071Sbapt * @param data include data 269290071Sbapt * @param len length of data 270290071Sbapt * @param args UCL object representing arguments to the macro 271290071Sbapt * @param ud user data 272290071Sbapt * @return 273290071Sbapt */ 274290071Sbaptbool ucl_priority_handler (const unsigned char *data, size_t len, 275290071Sbapt const ucl_object_t *args, void* ud); 276290071Sbapt 277290071Sbapt/** 278290071Sbapt * Handle load macro 279290071Sbapt * @param data include data 280290071Sbapt * @param len length of data 281290071Sbapt * @param args UCL object representing arguments to the macro 282290071Sbapt * @param ud user data 283290071Sbapt * @return 284290071Sbapt */ 285290071Sbaptbool ucl_load_handler (const unsigned char *data, size_t len, 286290071Sbapt const ucl_object_t *args, void* ud); 287290071Sbapt/** 288290071Sbapt * Handle inherit macro 289290071Sbapt * @param data include data 290290071Sbapt * @param len length of data 291290071Sbapt * @param args UCL object representing arguments to the macro 292290071Sbapt * @param ctx the current context object 293290071Sbapt * @param ud user data 294290071Sbapt * @return 295290071Sbapt */ 296290071Sbaptbool ucl_inherit_handler (const unsigned char *data, size_t len, 297290071Sbapt const ucl_object_t *args, const ucl_object_t *ctx, void* ud); 298290071Sbapt 299262395Sbaptsize_t ucl_strlcpy (char *dst, const char *src, size_t siz); 300262395Sbaptsize_t ucl_strlcpy_unsafe (char *dst, const char *src, size_t siz); 301262395Sbaptsize_t ucl_strlcpy_tolower (char *dst, const char *src, size_t siz); 302262395Sbapt 303290071Sbaptchar *ucl_strnstr (const char *s, const char *find, int len); 304290071Sbaptchar *ucl_strncasestr (const char *s, const char *find, int len); 305262395Sbapt 306262395Sbapt#ifdef __GNUC__ 307262395Sbaptstatic inline void 308262395Sbaptucl_create_err (UT_string **err, const char *fmt, ...) 309262395Sbapt__attribute__ (( format( printf, 2, 3) )); 310262395Sbapt#endif 311262395Sbapt 312290071Sbapt#undef UCL_FATAL_ERRORS 313290071Sbapt 314262395Sbaptstatic inline void 315262395Sbaptucl_create_err (UT_string **err, const char *fmt, ...) 316262395Sbapt{ 317262395Sbapt if (*err == NULL) { 318262395Sbapt utstring_new (*err); 319262395Sbapt va_list ap; 320262395Sbapt va_start (ap, fmt); 321262395Sbapt utstring_printf_va (*err, fmt, ap); 322262395Sbapt va_end (ap); 323262395Sbapt } 324290071Sbapt 325290071Sbapt#ifdef UCL_FATAL_ERRORS 326290071Sbapt assert (0); 327290071Sbapt#endif 328262395Sbapt} 329262395Sbapt 330262395Sbapt/** 331262395Sbapt * Check whether a given string contains a boolean value 332262395Sbapt * @param obj object to set 333262395Sbapt * @param start start of a string 334262395Sbapt * @param len length of a string 335262395Sbapt * @return true if a string is a boolean value 336262395Sbapt */ 337262395Sbaptstatic inline bool 338262395Sbaptucl_maybe_parse_boolean (ucl_object_t *obj, const unsigned char *start, size_t len) 339262395Sbapt{ 340275223Sbapt const char *p = (const char *)start; 341262395Sbapt bool ret = false, val = false; 342262395Sbapt 343262395Sbapt if (len == 5) { 344262395Sbapt if ((p[0] == 'f' || p[0] == 'F') && strncasecmp (p, "false", 5) == 0) { 345262395Sbapt ret = true; 346262395Sbapt val = false; 347262395Sbapt } 348262395Sbapt } 349262395Sbapt else if (len == 4) { 350262395Sbapt if ((p[0] == 't' || p[0] == 'T') && strncasecmp (p, "true", 4) == 0) { 351262395Sbapt ret = true; 352262395Sbapt val = true; 353262395Sbapt } 354262395Sbapt } 355262395Sbapt else if (len == 3) { 356262395Sbapt if ((p[0] == 'y' || p[0] == 'Y') && strncasecmp (p, "yes", 3) == 0) { 357262395Sbapt ret = true; 358262395Sbapt val = true; 359262395Sbapt } 360262395Sbapt else if ((p[0] == 'o' || p[0] == 'O') && strncasecmp (p, "off", 3) == 0) { 361262395Sbapt ret = true; 362262395Sbapt val = false; 363262395Sbapt } 364262395Sbapt } 365262395Sbapt else if (len == 2) { 366262395Sbapt if ((p[0] == 'n' || p[0] == 'N') && strncasecmp (p, "no", 2) == 0) { 367262395Sbapt ret = true; 368262395Sbapt val = false; 369262395Sbapt } 370262395Sbapt else if ((p[0] == 'o' || p[0] == 'O') && strncasecmp (p, "on", 2) == 0) { 371262395Sbapt ret = true; 372262395Sbapt val = true; 373262395Sbapt } 374262395Sbapt } 375262395Sbapt 376290071Sbapt if (ret && obj != NULL) { 377262395Sbapt obj->type = UCL_BOOLEAN; 378262395Sbapt obj->value.iv = val; 379262395Sbapt } 380262395Sbapt 381262395Sbapt return ret; 382262395Sbapt} 383262395Sbapt 384262395Sbapt/** 385262395Sbapt * Check numeric string 386262395Sbapt * @param obj object to set if a string is numeric 387262395Sbapt * @param start start of string 388262395Sbapt * @param end end of string 389262395Sbapt * @param pos position where parsing has stopped 390262395Sbapt * @param allow_double allow parsing of floating point values 391262395Sbapt * @return 0 if string is numeric and error code (EINVAL or ERANGE) in case of conversion error 392262395Sbapt */ 393262395Sbaptint ucl_maybe_parse_number (ucl_object_t *obj, 394263648Sbapt const char *start, const char *end, const char **pos, 395263648Sbapt bool allow_double, bool number_bytes, bool allow_time); 396262395Sbapt 397262395Sbapt 398264789Sbaptstatic inline const ucl_object_t * 399262395Sbaptucl_hash_search_obj (ucl_hash_t* hashlin, ucl_object_t *obj) 400262395Sbapt{ 401264789Sbapt return (const ucl_object_t *)ucl_hash_search (hashlin, obj->key, obj->keylen); 402262395Sbapt} 403262395Sbapt 404279549Sbaptstatic inline ucl_hash_t * ucl_hash_insert_object (ucl_hash_t *hashlin, 405279549Sbapt const ucl_object_t *obj, 406279549Sbapt bool ignore_case) UCL_WARN_UNUSED_RESULT; 407262395Sbapt 408262395Sbaptstatic inline ucl_hash_t * 409279549Sbaptucl_hash_insert_object (ucl_hash_t *hashlin, 410279549Sbapt const ucl_object_t *obj, 411279549Sbapt bool ignore_case) 412262395Sbapt{ 413262395Sbapt if (hashlin == NULL) { 414279549Sbapt hashlin = ucl_hash_create (ignore_case); 415262395Sbapt } 416262395Sbapt ucl_hash_insert (hashlin, obj, obj->key, obj->keylen); 417262395Sbapt 418262395Sbapt return hashlin; 419262395Sbapt} 420262395Sbapt 421262395Sbapt/** 422268831Sbapt * Get standard emitter context for a specified emit_type 423268831Sbapt * @param emit_type type of emitter 424268831Sbapt * @return context or NULL if input is invalid 425268831Sbapt */ 426268831Sbaptconst struct ucl_emitter_context * 427268831Sbaptucl_emit_get_standard_context (enum ucl_emitter emit_type); 428268831Sbapt 429268831Sbapt/** 430275223Sbapt * Serialize string as JSON string 431268831Sbapt * @param str string to emit 432268831Sbapt * @param buf target buffer 433268831Sbapt */ 434268831Sbaptvoid ucl_elt_string_write_json (const char *str, size_t size, 435268831Sbapt struct ucl_emitter_context *ctx); 436268831Sbapt 437268831Sbapt/** 438275223Sbapt * Write multiline string using `EOD` as string terminator 439275223Sbapt * @param str 440275223Sbapt * @param size 441275223Sbapt * @param ctx 442275223Sbapt */ 443275223Sbaptvoid ucl_elt_string_write_multiline (const char *str, size_t size, 444275223Sbapt struct ucl_emitter_context *ctx); 445275223Sbapt 446275223Sbapt/** 447262395Sbapt * Emit a single object to string 448262395Sbapt * @param obj 449262395Sbapt * @return 450262395Sbapt */ 451264789Sbaptunsigned char * ucl_object_emit_single_json (const ucl_object_t *obj); 452262395Sbapt 453275223Sbapt/** 454275223Sbapt * Check whether a specified string is long and should be likely printed in 455275223Sbapt * multiline mode 456275223Sbapt * @param obj 457275223Sbapt * @return 458275223Sbapt */ 459275223Sbaptbool ucl_maybe_long_string (const ucl_object_t *obj); 460275223Sbapt 461290071Sbapt/** 462290071Sbapt * Print integer to the msgpack output 463290071Sbapt * @param ctx 464290071Sbapt * @param val 465290071Sbapt */ 466290071Sbaptvoid ucl_emitter_print_int_msgpack (struct ucl_emitter_context *ctx, 467290071Sbapt int64_t val); 468290071Sbapt/** 469290071Sbapt * Print integer to the msgpack output 470290071Sbapt * @param ctx 471290071Sbapt * @param val 472290071Sbapt */ 473290071Sbaptvoid ucl_emitter_print_double_msgpack (struct ucl_emitter_context *ctx, 474290071Sbapt double val); 475290071Sbapt/** 476290071Sbapt * Print double to the msgpack output 477290071Sbapt * @param ctx 478290071Sbapt * @param val 479290071Sbapt */ 480290071Sbaptvoid ucl_emitter_print_bool_msgpack (struct ucl_emitter_context *ctx, 481290071Sbapt bool val); 482290071Sbapt/** 483290071Sbapt * Print string to the msgpack output 484290071Sbapt * @param ctx 485290071Sbapt * @param s 486290071Sbapt * @param len 487290071Sbapt */ 488290071Sbaptvoid ucl_emitter_print_string_msgpack (struct ucl_emitter_context *ctx, 489290071Sbapt const char *s, size_t len); 490290071Sbapt 491290071Sbapt/** 492290071Sbapt * Print binary string to the msgpack output 493290071Sbapt * @param ctx 494290071Sbapt * @param s 495290071Sbapt * @param len 496290071Sbapt */ 497290071Sbaptvoid ucl_emitter_print_binary_string_msgpack (struct ucl_emitter_context *ctx, 498290071Sbapt const char *s, size_t len); 499290071Sbapt 500290071Sbapt/** 501290071Sbapt * Print array preamble for msgpack 502290071Sbapt * @param ctx 503290071Sbapt * @param len 504290071Sbapt */ 505290071Sbaptvoid ucl_emitter_print_array_msgpack (struct ucl_emitter_context *ctx, 506290071Sbapt size_t len); 507290071Sbapt 508290071Sbapt/** 509290071Sbapt * Print object preamble for msgpack 510290071Sbapt * @param ctx 511290071Sbapt * @param len 512290071Sbapt */ 513290071Sbaptvoid ucl_emitter_print_object_msgpack (struct ucl_emitter_context *ctx, 514290071Sbapt size_t len); 515290071Sbapt/** 516290071Sbapt * Print NULL to the msgpack output 517290071Sbapt * @param ctx 518290071Sbapt */ 519290071Sbaptvoid ucl_emitter_print_null_msgpack (struct ucl_emitter_context *ctx); 520290071Sbapt/** 521290071Sbapt * Print object's key if needed to the msgpack output 522290071Sbapt * @param print_key 523290071Sbapt * @param ctx 524290071Sbapt * @param obj 525290071Sbapt */ 526290071Sbaptvoid ucl_emitter_print_key_msgpack (bool print_key, 527290071Sbapt struct ucl_emitter_context *ctx, 528290071Sbapt const ucl_object_t *obj); 529290071Sbapt 530290071Sbapt/** 531298166Sbapt * Fetch URL into a buffer 532298166Sbapt * @param url url to fetch 533298166Sbapt * @param buf pointer to buffer (must be freed by callee) 534298166Sbapt * @param buflen pointer to buffer length 535298166Sbapt * @param err pointer to error argument 536298166Sbapt * @param must_exist fail if cannot find a url 537298166Sbapt */ 538298166Sbaptbool ucl_fetch_url (const unsigned char *url, 539298166Sbapt unsigned char **buf, 540298166Sbapt size_t *buflen, 541298166Sbapt UT_string **err, 542298166Sbapt bool must_exist); 543298166Sbapt 544298166Sbapt/** 545298166Sbapt * Fetch a file and save results to the memory buffer 546298166Sbapt * @param filename filename to fetch 547298166Sbapt * @param len length of filename 548298166Sbapt * @param buf target buffer 549298166Sbapt * @param buflen target length 550298166Sbapt * @return 551298166Sbapt */ 552298166Sbaptbool ucl_fetch_file (const unsigned char *filename, 553298166Sbapt unsigned char **buf, 554298166Sbapt size_t *buflen, 555298166Sbapt UT_string **err, 556298166Sbapt bool must_exist); 557298166Sbapt 558298166Sbapt/** 559290071Sbapt * Add new element to an object using the current merge strategy and priority 560290071Sbapt * @param parser 561290071Sbapt * @param nobj 562290071Sbapt * @return 563290071Sbapt */ 564290071Sbaptbool ucl_parser_process_object_element (struct ucl_parser *parser, 565290071Sbapt ucl_object_t *nobj); 566290071Sbapt 567290071Sbapt/** 568290071Sbapt * Parse msgpack chunk 569290071Sbapt * @param parser 570290071Sbapt * @return 571290071Sbapt */ 572290071Sbaptbool ucl_parse_msgpack (struct ucl_parser *parser); 573290071Sbapt 574314278Sbaptbool ucl_parse_csexp (struct ucl_parser *parser); 575314278Sbapt 576262395Sbapt#endif /* UCL_INTERNAL_H_ */ 577