ucl_internal.h revision 298166
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
90262395Sbapt
91262395Sbapt#include "utlist.h"
92262395Sbapt#include "utstring.h"
93262395Sbapt#include "uthash.h"
94262395Sbapt#include "ucl.h"
95262395Sbapt#include "ucl_hash.h"
96262395Sbapt#include "xxhash.h"
97262395Sbapt
98262395Sbapt#ifdef HAVE_OPENSSL
99262395Sbapt#include <openssl/evp.h>
100262395Sbapt#endif
101262395Sbapt
102264789Sbapt#ifndef __DECONST
103264789Sbapt#define __DECONST(type, var)    ((type)(uintptr_t)(const void *)(var))
104264789Sbapt#endif
105264789Sbapt
106262395Sbapt/**
107262395Sbapt * @file rcl_internal.h
108262395Sbapt * Internal structures and functions of UCL library
109262395Sbapt */
110262395Sbapt
111262395Sbapt#define UCL_MAX_RECURSION 16
112262395Sbapt#define UCL_TRASH_KEY 0
113262395Sbapt#define UCL_TRASH_VALUE 1
114262395Sbapt
115262395Sbaptenum ucl_parser_state {
116262395Sbapt	UCL_STATE_INIT = 0,
117262395Sbapt	UCL_STATE_OBJECT,
118262395Sbapt	UCL_STATE_ARRAY,
119262395Sbapt	UCL_STATE_KEY,
120262395Sbapt	UCL_STATE_VALUE,
121262395Sbapt	UCL_STATE_AFTER_VALUE,
122262395Sbapt	UCL_STATE_ARRAY_VALUE,
123262395Sbapt	UCL_STATE_SCOMMENT,
124262395Sbapt	UCL_STATE_MCOMMENT,
125262395Sbapt	UCL_STATE_MACRO_NAME,
126262395Sbapt	UCL_STATE_MACRO,
127262395Sbapt	UCL_STATE_ERROR
128262395Sbapt};
129262395Sbapt
130262395Sbaptenum ucl_character_type {
131262395Sbapt	UCL_CHARACTER_DENIED = 0,
132262395Sbapt	UCL_CHARACTER_KEY = 1,
133262395Sbapt	UCL_CHARACTER_KEY_START = 1 << 1,
134262395Sbapt	UCL_CHARACTER_WHITESPACE = 1 << 2,
135262395Sbapt	UCL_CHARACTER_WHITESPACE_UNSAFE = 1 << 3,
136262395Sbapt	UCL_CHARACTER_VALUE_END = 1 << 4,
137262395Sbapt	UCL_CHARACTER_VALUE_STR = 1 << 5,
138262395Sbapt	UCL_CHARACTER_VALUE_DIGIT = 1 << 6,
139262395Sbapt	UCL_CHARACTER_VALUE_DIGIT_START = 1 << 7,
140262395Sbapt	UCL_CHARACTER_ESCAPE = 1 << 8,
141262395Sbapt	UCL_CHARACTER_KEY_SEP = 1 << 9,
142262395Sbapt	UCL_CHARACTER_JSON_UNSAFE = 1 << 10,
143262395Sbapt	UCL_CHARACTER_UCL_UNSAFE = 1 << 11
144262395Sbapt};
145262395Sbapt
146262395Sbaptstruct ucl_macro {
147262395Sbapt	char *name;
148290071Sbapt	union {
149290071Sbapt		ucl_macro_handler handler;
150290071Sbapt		ucl_context_macro_handler context_handler;
151290071Sbapt	} h;
152262395Sbapt	void* ud;
153290071Sbapt	bool is_context;
154262395Sbapt	UT_hash_handle hh;
155262395Sbapt};
156262395Sbapt
157262395Sbaptstruct ucl_stack {
158262395Sbapt	ucl_object_t *obj;
159262395Sbapt	struct ucl_stack *next;
160290071Sbapt	uint64_t level;
161262395Sbapt};
162262395Sbapt
163262395Sbaptstruct ucl_chunk {
164262395Sbapt	const unsigned char *begin;
165262395Sbapt	const unsigned char *end;
166262395Sbapt	const unsigned char *pos;
167262395Sbapt	size_t remain;
168262395Sbapt	unsigned int line;
169262395Sbapt	unsigned int column;
170275223Sbapt	unsigned priority;
171290071Sbapt	enum ucl_duplicate_strategy strategy;
172290071Sbapt	enum ucl_parse_type parse_type;
173262395Sbapt	struct ucl_chunk *next;
174262395Sbapt};
175262395Sbapt
176262395Sbapt#ifdef HAVE_OPENSSL
177262395Sbaptstruct ucl_pubkey {
178262395Sbapt	EVP_PKEY *key;
179262395Sbapt	struct ucl_pubkey *next;
180262395Sbapt};
181262395Sbapt#else
182262395Sbaptstruct ucl_pubkey {
183262395Sbapt	struct ucl_pubkey *next;
184262395Sbapt};
185262395Sbapt#endif
186262395Sbapt
187262395Sbaptstruct ucl_variable {
188262395Sbapt	char *var;
189262395Sbapt	char *value;
190262395Sbapt	size_t var_len;
191262395Sbapt	size_t value_len;
192275223Sbapt	struct ucl_variable *prev, *next;
193262395Sbapt};
194262395Sbapt
195262395Sbaptstruct ucl_parser {
196262395Sbapt	enum ucl_parser_state state;
197262395Sbapt	enum ucl_parser_state prev_state;
198262395Sbapt	unsigned int recursion;
199262395Sbapt	int flags;
200290071Sbapt	unsigned default_priority;
201290071Sbapt	int err_code;
202262395Sbapt	ucl_object_t *top_obj;
203262395Sbapt	ucl_object_t *cur_obj;
204290071Sbapt	ucl_object_t *trash_objs;
205290071Sbapt	ucl_object_t *includepaths;
206275223Sbapt	char *cur_file;
207262395Sbapt	struct ucl_macro *macroes;
208262395Sbapt	struct ucl_stack *stack;
209262395Sbapt	struct ucl_chunk *chunks;
210262395Sbapt	struct ucl_pubkey *keys;
211262395Sbapt	struct ucl_variable *variables;
212266636Sbapt	ucl_variable_handler var_handler;
213266636Sbapt	void *var_data;
214298166Sbapt	ucl_object_t *comments;
215298166Sbapt	ucl_object_t *last_comment;
216262395Sbapt	UT_string *err;
217262395Sbapt};
218262395Sbapt
219275223Sbaptstruct ucl_object_userdata {
220275223Sbapt	ucl_object_t obj;
221275223Sbapt	ucl_userdata_dtor dtor;
222275223Sbapt	ucl_userdata_emitter emitter;
223275223Sbapt};
224275223Sbapt
225262395Sbapt/**
226262395Sbapt * Unescape json string inplace
227262395Sbapt * @param str
228262395Sbapt */
229262395Sbaptsize_t ucl_unescape_json_string (char *str, size_t len);
230262395Sbapt
231262395Sbapt/**
232262395Sbapt * Handle include macro
233262395Sbapt * @param data include data
234262395Sbapt * @param len length of data
235290071Sbapt * @param args UCL object representing arguments to the macro
236262395Sbapt * @param ud user data
237262395Sbapt * @return
238262395Sbapt */
239275223Sbaptbool ucl_include_handler (const unsigned char *data, size_t len,
240275223Sbapt		const ucl_object_t *args, void* ud);
241262395Sbapt
242290071Sbapt/**
243290071Sbapt * Handle tryinclude macro
244290071Sbapt * @param data include data
245290071Sbapt * @param len length of data
246290071Sbapt * @param args UCL object representing arguments to the macro
247290071Sbapt * @param ud user data
248290071Sbapt * @return
249290071Sbapt */
250275223Sbaptbool ucl_try_include_handler (const unsigned char *data, size_t len,
251275223Sbapt		const ucl_object_t *args, void* ud);
252262395Sbapt
253262395Sbapt/**
254262395Sbapt * Handle includes macro
255262395Sbapt * @param data include data
256262395Sbapt * @param len length of data
257290071Sbapt * @param args UCL object representing arguments to the macro
258262395Sbapt * @param ud user data
259262395Sbapt * @return
260262395Sbapt */
261275223Sbaptbool ucl_includes_handler (const unsigned char *data, size_t len,
262275223Sbapt		const ucl_object_t *args, void* ud);
263262395Sbapt
264290071Sbapt/**
265290071Sbapt * Handle priority macro
266290071Sbapt * @param data include data
267290071Sbapt * @param len length of data
268290071Sbapt * @param args UCL object representing arguments to the macro
269290071Sbapt * @param ud user data
270290071Sbapt * @return
271290071Sbapt */
272290071Sbaptbool ucl_priority_handler (const unsigned char *data, size_t len,
273290071Sbapt		const ucl_object_t *args, void* ud);
274290071Sbapt
275290071Sbapt/**
276290071Sbapt * Handle load macro
277290071Sbapt * @param data include data
278290071Sbapt * @param len length of data
279290071Sbapt * @param args UCL object representing arguments to the macro
280290071Sbapt * @param ud user data
281290071Sbapt * @return
282290071Sbapt */
283290071Sbaptbool ucl_load_handler (const unsigned char *data, size_t len,
284290071Sbapt		const ucl_object_t *args, void* ud);
285290071Sbapt/**
286290071Sbapt * Handle inherit macro
287290071Sbapt * @param data include data
288290071Sbapt * @param len length of data
289290071Sbapt * @param args UCL object representing arguments to the macro
290290071Sbapt * @param ctx the current context object
291290071Sbapt * @param ud user data
292290071Sbapt * @return
293290071Sbapt */
294290071Sbaptbool ucl_inherit_handler (const unsigned char *data, size_t len,
295290071Sbapt		const ucl_object_t *args, const ucl_object_t *ctx, void* ud);
296290071Sbapt
297262395Sbaptsize_t ucl_strlcpy (char *dst, const char *src, size_t siz);
298262395Sbaptsize_t ucl_strlcpy_unsafe (char *dst, const char *src, size_t siz);
299262395Sbaptsize_t ucl_strlcpy_tolower (char *dst, const char *src, size_t siz);
300262395Sbapt
301290071Sbaptchar *ucl_strnstr (const char *s, const char *find, int len);
302290071Sbaptchar *ucl_strncasestr (const char *s, const char *find, int len);
303262395Sbapt
304262395Sbapt#ifdef __GNUC__
305262395Sbaptstatic inline void
306262395Sbaptucl_create_err (UT_string **err, const char *fmt, ...)
307262395Sbapt__attribute__ (( format( printf, 2, 3) ));
308262395Sbapt#endif
309262395Sbapt
310290071Sbapt#undef UCL_FATAL_ERRORS
311290071Sbapt
312262395Sbaptstatic inline void
313262395Sbaptucl_create_err (UT_string **err, const char *fmt, ...)
314262395Sbapt{
315262395Sbapt	if (*err == NULL) {
316262395Sbapt		utstring_new (*err);
317262395Sbapt		va_list ap;
318262395Sbapt		va_start (ap, fmt);
319262395Sbapt		utstring_printf_va (*err, fmt, ap);
320262395Sbapt		va_end (ap);
321262395Sbapt	}
322290071Sbapt
323290071Sbapt#ifdef UCL_FATAL_ERRORS
324290071Sbapt	assert (0);
325290071Sbapt#endif
326262395Sbapt}
327262395Sbapt
328262395Sbapt/**
329262395Sbapt * Check whether a given string contains a boolean value
330262395Sbapt * @param obj object to set
331262395Sbapt * @param start start of a string
332262395Sbapt * @param len length of a string
333262395Sbapt * @return true if a string is a boolean value
334262395Sbapt */
335262395Sbaptstatic inline bool
336262395Sbaptucl_maybe_parse_boolean (ucl_object_t *obj, const unsigned char *start, size_t len)
337262395Sbapt{
338275223Sbapt	const char *p = (const char *)start;
339262395Sbapt	bool ret = false, val = false;
340262395Sbapt
341262395Sbapt	if (len == 5) {
342262395Sbapt		if ((p[0] == 'f' || p[0] == 'F') && strncasecmp (p, "false", 5) == 0) {
343262395Sbapt			ret = true;
344262395Sbapt			val = false;
345262395Sbapt		}
346262395Sbapt	}
347262395Sbapt	else if (len == 4) {
348262395Sbapt		if ((p[0] == 't' || p[0] == 'T') && strncasecmp (p, "true", 4) == 0) {
349262395Sbapt			ret = true;
350262395Sbapt			val = true;
351262395Sbapt		}
352262395Sbapt	}
353262395Sbapt	else if (len == 3) {
354262395Sbapt		if ((p[0] == 'y' || p[0] == 'Y') && strncasecmp (p, "yes", 3) == 0) {
355262395Sbapt			ret = true;
356262395Sbapt			val = true;
357262395Sbapt		}
358262395Sbapt		else if ((p[0] == 'o' || p[0] == 'O') && strncasecmp (p, "off", 3) == 0) {
359262395Sbapt			ret = true;
360262395Sbapt			val = false;
361262395Sbapt		}
362262395Sbapt	}
363262395Sbapt	else if (len == 2) {
364262395Sbapt		if ((p[0] == 'n' || p[0] == 'N') && strncasecmp (p, "no", 2) == 0) {
365262395Sbapt			ret = true;
366262395Sbapt			val = false;
367262395Sbapt		}
368262395Sbapt		else if ((p[0] == 'o' || p[0] == 'O') && strncasecmp (p, "on", 2) == 0) {
369262395Sbapt			ret = true;
370262395Sbapt			val = true;
371262395Sbapt		}
372262395Sbapt	}
373262395Sbapt
374290071Sbapt	if (ret && obj != NULL) {
375262395Sbapt		obj->type = UCL_BOOLEAN;
376262395Sbapt		obj->value.iv = val;
377262395Sbapt	}
378262395Sbapt
379262395Sbapt	return ret;
380262395Sbapt}
381262395Sbapt
382262395Sbapt/**
383262395Sbapt * Check numeric string
384262395Sbapt * @param obj object to set if a string is numeric
385262395Sbapt * @param start start of string
386262395Sbapt * @param end end of string
387262395Sbapt * @param pos position where parsing has stopped
388262395Sbapt * @param allow_double allow parsing of floating point values
389262395Sbapt * @return 0 if string is numeric and error code (EINVAL or ERANGE) in case of conversion error
390262395Sbapt */
391262395Sbaptint ucl_maybe_parse_number (ucl_object_t *obj,
392263648Sbapt		const char *start, const char *end, const char **pos,
393263648Sbapt		bool allow_double, bool number_bytes, bool allow_time);
394262395Sbapt
395262395Sbapt
396264789Sbaptstatic inline const ucl_object_t *
397262395Sbaptucl_hash_search_obj (ucl_hash_t* hashlin, ucl_object_t *obj)
398262395Sbapt{
399264789Sbapt	return (const ucl_object_t *)ucl_hash_search (hashlin, obj->key, obj->keylen);
400262395Sbapt}
401262395Sbapt
402279549Sbaptstatic inline ucl_hash_t * ucl_hash_insert_object (ucl_hash_t *hashlin,
403279549Sbapt		const ucl_object_t *obj,
404279549Sbapt		bool ignore_case) UCL_WARN_UNUSED_RESULT;
405262395Sbapt
406262395Sbaptstatic inline ucl_hash_t *
407279549Sbaptucl_hash_insert_object (ucl_hash_t *hashlin,
408279549Sbapt		const ucl_object_t *obj,
409279549Sbapt		bool ignore_case)
410262395Sbapt{
411262395Sbapt	if (hashlin == NULL) {
412279549Sbapt		hashlin = ucl_hash_create (ignore_case);
413262395Sbapt	}
414262395Sbapt	ucl_hash_insert (hashlin, obj, obj->key, obj->keylen);
415262395Sbapt
416262395Sbapt	return hashlin;
417262395Sbapt}
418262395Sbapt
419262395Sbapt/**
420268831Sbapt * Get standard emitter context for a specified emit_type
421268831Sbapt * @param emit_type type of emitter
422268831Sbapt * @return context or NULL if input is invalid
423268831Sbapt */
424268831Sbaptconst struct ucl_emitter_context *
425268831Sbaptucl_emit_get_standard_context (enum ucl_emitter emit_type);
426268831Sbapt
427268831Sbapt/**
428275223Sbapt * Serialize string as JSON string
429268831Sbapt * @param str string to emit
430268831Sbapt * @param buf target buffer
431268831Sbapt */
432268831Sbaptvoid ucl_elt_string_write_json (const char *str, size_t size,
433268831Sbapt		struct ucl_emitter_context *ctx);
434268831Sbapt
435268831Sbapt/**
436275223Sbapt * Write multiline string using `EOD` as string terminator
437275223Sbapt * @param str
438275223Sbapt * @param size
439275223Sbapt * @param ctx
440275223Sbapt */
441275223Sbaptvoid ucl_elt_string_write_multiline (const char *str, size_t size,
442275223Sbapt		struct ucl_emitter_context *ctx);
443275223Sbapt
444275223Sbapt/**
445262395Sbapt * Emit a single object to string
446262395Sbapt * @param obj
447262395Sbapt * @return
448262395Sbapt */
449264789Sbaptunsigned char * ucl_object_emit_single_json (const ucl_object_t *obj);
450262395Sbapt
451275223Sbapt/**
452275223Sbapt * Check whether a specified string is long and should be likely printed in
453275223Sbapt * multiline mode
454275223Sbapt * @param obj
455275223Sbapt * @return
456275223Sbapt */
457275223Sbaptbool ucl_maybe_long_string (const ucl_object_t *obj);
458275223Sbapt
459290071Sbapt/**
460290071Sbapt * Print integer to the msgpack output
461290071Sbapt * @param ctx
462290071Sbapt * @param val
463290071Sbapt */
464290071Sbaptvoid ucl_emitter_print_int_msgpack (struct ucl_emitter_context *ctx,
465290071Sbapt		int64_t val);
466290071Sbapt/**
467290071Sbapt * Print integer to the msgpack output
468290071Sbapt * @param ctx
469290071Sbapt * @param val
470290071Sbapt */
471290071Sbaptvoid ucl_emitter_print_double_msgpack (struct ucl_emitter_context *ctx,
472290071Sbapt		double val);
473290071Sbapt/**
474290071Sbapt * Print double to the msgpack output
475290071Sbapt * @param ctx
476290071Sbapt * @param val
477290071Sbapt */
478290071Sbaptvoid ucl_emitter_print_bool_msgpack (struct ucl_emitter_context *ctx,
479290071Sbapt		bool val);
480290071Sbapt/**
481290071Sbapt * Print string to the msgpack output
482290071Sbapt * @param ctx
483290071Sbapt * @param s
484290071Sbapt * @param len
485290071Sbapt */
486290071Sbaptvoid ucl_emitter_print_string_msgpack (struct ucl_emitter_context *ctx,
487290071Sbapt		const char *s, size_t len);
488290071Sbapt
489290071Sbapt/**
490290071Sbapt * Print binary string to the msgpack output
491290071Sbapt * @param ctx
492290071Sbapt * @param s
493290071Sbapt * @param len
494290071Sbapt */
495290071Sbaptvoid ucl_emitter_print_binary_string_msgpack (struct ucl_emitter_context *ctx,
496290071Sbapt		const char *s, size_t len);
497290071Sbapt
498290071Sbapt/**
499290071Sbapt * Print array preamble for msgpack
500290071Sbapt * @param ctx
501290071Sbapt * @param len
502290071Sbapt */
503290071Sbaptvoid ucl_emitter_print_array_msgpack (struct ucl_emitter_context *ctx,
504290071Sbapt		size_t len);
505290071Sbapt
506290071Sbapt/**
507290071Sbapt * Print object preamble for msgpack
508290071Sbapt * @param ctx
509290071Sbapt * @param len
510290071Sbapt */
511290071Sbaptvoid ucl_emitter_print_object_msgpack (struct ucl_emitter_context *ctx,
512290071Sbapt		size_t len);
513290071Sbapt/**
514290071Sbapt * Print NULL to the msgpack output
515290071Sbapt * @param ctx
516290071Sbapt */
517290071Sbaptvoid ucl_emitter_print_null_msgpack (struct ucl_emitter_context *ctx);
518290071Sbapt/**
519290071Sbapt * Print object's key if needed to the msgpack output
520290071Sbapt * @param print_key
521290071Sbapt * @param ctx
522290071Sbapt * @param obj
523290071Sbapt */
524290071Sbaptvoid ucl_emitter_print_key_msgpack (bool print_key,
525290071Sbapt		struct ucl_emitter_context *ctx,
526290071Sbapt		const ucl_object_t *obj);
527290071Sbapt
528290071Sbapt/**
529298166Sbapt * Fetch URL into a buffer
530298166Sbapt * @param url url to fetch
531298166Sbapt * @param buf pointer to buffer (must be freed by callee)
532298166Sbapt * @param buflen pointer to buffer length
533298166Sbapt * @param err pointer to error argument
534298166Sbapt * @param must_exist fail if cannot find a url
535298166Sbapt */
536298166Sbaptbool ucl_fetch_url (const unsigned char *url,
537298166Sbapt		unsigned char **buf,
538298166Sbapt		size_t *buflen,
539298166Sbapt		UT_string **err,
540298166Sbapt		bool must_exist);
541298166Sbapt
542298166Sbapt/**
543298166Sbapt * Fetch a file and save results to the memory buffer
544298166Sbapt * @param filename filename to fetch
545298166Sbapt * @param len length of filename
546298166Sbapt * @param buf target buffer
547298166Sbapt * @param buflen target length
548298166Sbapt * @return
549298166Sbapt */
550298166Sbaptbool ucl_fetch_file (const unsigned char *filename,
551298166Sbapt		unsigned char **buf,
552298166Sbapt		size_t *buflen,
553298166Sbapt		UT_string **err,
554298166Sbapt		bool must_exist);
555298166Sbapt
556298166Sbapt/**
557290071Sbapt * Add new element to an object using the current merge strategy and priority
558290071Sbapt * @param parser
559290071Sbapt * @param nobj
560290071Sbapt * @return
561290071Sbapt */
562290071Sbaptbool ucl_parser_process_object_element (struct ucl_parser *parser,
563290071Sbapt		ucl_object_t *nobj);
564290071Sbapt
565290071Sbapt/**
566290071Sbapt * Parse msgpack chunk
567290071Sbapt * @param parser
568290071Sbapt * @return
569290071Sbapt */
570290071Sbaptbool ucl_parse_msgpack (struct ucl_parser *parser);
571290071Sbapt
572262395Sbapt#endif /* UCL_INTERNAL_H_ */
573