ucl.h (290071) | ucl.h (298166) |
---|---|
1/* Copyright (c) 2013-2015, Vsevolod Stakhov 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright --- 93 unchanged lines hidden (view full) --- 102typedef enum ucl_error { 103 UCL_EOK = 0, /**< No error */ 104 UCL_ESYNTAX, /**< Syntax error occurred during parsing */ 105 UCL_EIO, /**< IO error occurred during parsing */ 106 UCL_ESTATE, /**< Invalid state machine state */ 107 UCL_ENESTED, /**< Input has too many recursion levels */ 108 UCL_EMACRO, /**< Error processing a macro */ 109 UCL_EINTERNAL, /**< Internal unclassified error */ | 1/* Copyright (c) 2013-2015, Vsevolod Stakhov 2 * All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright --- 93 unchanged lines hidden (view full) --- 102typedef enum ucl_error { 103 UCL_EOK = 0, /**< No error */ 104 UCL_ESYNTAX, /**< Syntax error occurred during parsing */ 105 UCL_EIO, /**< IO error occurred during parsing */ 106 UCL_ESTATE, /**< Invalid state machine state */ 107 UCL_ENESTED, /**< Input has too many recursion levels */ 108 UCL_EMACRO, /**< Error processing a macro */ 109 UCL_EINTERNAL, /**< Internal unclassified error */ |
110 UCL_ESSL /**< SSL error */ | 110 UCL_ESSL, /**< SSL error */ 111 UCL_EMERGE /**< A merge error occured */ |
111} ucl_error_t; 112 113/** 114 * #ucl_object_t may have one of specified types, some types are compatible with each other and some are not. 115 * For example, you can always convert #UCL_TIME to #UCL_FLOAT. Also you can convert #UCL_FLOAT to #UCL_INTEGER 116 * by loosing floating point. Every object may be converted to a string by #ucl_object_tostring_forced() function. 117 * 118 */ --- 23 unchanged lines hidden (view full) --- 142 143/** 144 * These flags defines parser behaviour. If you specify #UCL_PARSER_ZEROCOPY you must ensure 145 * that the input memory is not freed if an object is in use. Moreover, if you want to use 146 * zero-terminated keys and string values then you should not use zero-copy mode, as in this case 147 * UCL still has to perform copying implicitly. 148 */ 149typedef enum ucl_parser_flags { | 112} ucl_error_t; 113 114/** 115 * #ucl_object_t may have one of specified types, some types are compatible with each other and some are not. 116 * For example, you can always convert #UCL_TIME to #UCL_FLOAT. Also you can convert #UCL_FLOAT to #UCL_INTEGER 117 * by loosing floating point. Every object may be converted to a string by #ucl_object_tostring_forced() function. 118 * 119 */ --- 23 unchanged lines hidden (view full) --- 143 144/** 145 * These flags defines parser behaviour. If you specify #UCL_PARSER_ZEROCOPY you must ensure 146 * that the input memory is not freed if an object is in use. Moreover, if you want to use 147 * zero-terminated keys and string values then you should not use zero-copy mode, as in this case 148 * UCL still has to perform copying implicitly. 149 */ 150typedef enum ucl_parser_flags { |
150 UCL_PARSER_DEFAULT = 0x0, /**< No special flags */ 151 UCL_PARSER_KEY_LOWERCASE = 0x1, /**< Convert all keys to lower case */ 152 UCL_PARSER_ZEROCOPY = 0x2, /**< Parse input in zero-copy mode if possible */ 153 UCL_PARSER_NO_TIME = 0x4, /**< Do not parse time and treat time values as strings */ 154 UCL_PARSER_NO_IMPLICIT_ARRAYS = 0x8 /** Create explicit arrays instead of implicit ones */ | 151 UCL_PARSER_DEFAULT = 0, /**< No special flags */ 152 UCL_PARSER_KEY_LOWERCASE = (1 << 0), /**< Convert all keys to lower case */ 153 UCL_PARSER_ZEROCOPY = (1 << 1), /**< Parse input in zero-copy mode if possible */ 154 UCL_PARSER_NO_TIME = (1 << 2), /**< Do not parse time and treat time values as strings */ 155 UCL_PARSER_NO_IMPLICIT_ARRAYS = (1 << 3), /** Create explicit arrays instead of implicit ones */ 156 UCL_PARSER_SAVE_COMMENTS = (1 << 4), /** Save comments in the parser context */ 157 UCL_PARSER_DISABLE_MACRO = (1 << 5) /** Treat macros as comments */ |
155} ucl_parser_flags_t; 156 157/** 158 * String conversion flags, that are used in #ucl_object_fromstring_common function. 159 */ 160typedef enum ucl_string_flags { 161 UCL_STRING_RAW = 0x0, /**< Treat string as is */ | 158} ucl_parser_flags_t; 159 160/** 161 * String conversion flags, that are used in #ucl_object_fromstring_common function. 162 */ 163typedef enum ucl_string_flags { 164 UCL_STRING_RAW = 0x0, /**< Treat string as is */ |
162 UCL_STRING_ESCAPE = 0x1, /**< Perform JSON escape */ 163 UCL_STRING_TRIM = 0x2, /**< Trim leading and trailing whitespaces */ 164 UCL_STRING_PARSE_BOOLEAN = 0x4, /**< Parse passed string and detect boolean */ 165 UCL_STRING_PARSE_INT = 0x8, /**< Parse passed string and detect integer number */ 166 UCL_STRING_PARSE_DOUBLE = 0x10, /**< Parse passed string and detect integer or float number */ 167 UCL_STRING_PARSE_TIME = 0x20, /**< Parse time strings */ | 165 UCL_STRING_ESCAPE = (1 << 0), /**< Perform JSON escape */ 166 UCL_STRING_TRIM = (1 << 1), /**< Trim leading and trailing whitespaces */ 167 UCL_STRING_PARSE_BOOLEAN = (1 << 2), /**< Parse passed string and detect boolean */ 168 UCL_STRING_PARSE_INT = (1 << 3), /**< Parse passed string and detect integer number */ 169 UCL_STRING_PARSE_DOUBLE = (1 << 4), /**< Parse passed string and detect integer or float number */ 170 UCL_STRING_PARSE_TIME = (1 << 5), /**< Parse time strings */ |
168 UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE|UCL_STRING_PARSE_TIME, /**< 169 Parse passed string and detect number */ 170 UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER, /**< 171 Parse passed string (and detect booleans and numbers) */ | 171 UCL_STRING_PARSE_NUMBER = UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE|UCL_STRING_PARSE_TIME, /**< 172 Parse passed string and detect number */ 173 UCL_STRING_PARSE = UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER, /**< 174 Parse passed string (and detect booleans and numbers) */ |
172 UCL_STRING_PARSE_BYTES = 0x40 /**< Treat numbers as bytes */ | 175 UCL_STRING_PARSE_BYTES = (1 << 6) /**< Treat numbers as bytes */ |
173} ucl_string_flags_t; 174 175/** 176 * Basic flags for an object 177 */ 178typedef enum ucl_object_flags { 179 UCL_OBJECT_ALLOCATED_KEY = (1 << 0), /**< An object has key allocated internally */ 180 UCL_OBJECT_ALLOCATED_VALUE = (1 << 1), /**< An object has a string value allocated internally */ --- 100 unchanged lines hidden (view full) --- 281 * @return new object 282 */ 283UCL_EXTERN ucl_object_t* ucl_object_new_full (ucl_type_t type, unsigned priority) 284 UCL_WARN_UNUSED_RESULT; 285 286/** 287 * Create new object with userdata dtor 288 * @param dtor destructor function | 176} ucl_string_flags_t; 177 178/** 179 * Basic flags for an object 180 */ 181typedef enum ucl_object_flags { 182 UCL_OBJECT_ALLOCATED_KEY = (1 << 0), /**< An object has key allocated internally */ 183 UCL_OBJECT_ALLOCATED_VALUE = (1 << 1), /**< An object has a string value allocated internally */ --- 100 unchanged lines hidden (view full) --- 284 * @return new object 285 */ 286UCL_EXTERN ucl_object_t* ucl_object_new_full (ucl_type_t type, unsigned priority) 287 UCL_WARN_UNUSED_RESULT; 288 289/** 290 * Create new object with userdata dtor 291 * @param dtor destructor function |
292 * @param emitter emitter for userdata 293 * @param ptr opaque pointer |
|
289 * @return new object 290 */ 291UCL_EXTERN ucl_object_t* ucl_object_new_userdata (ucl_userdata_dtor dtor, | 294 * @return new object 295 */ 296UCL_EXTERN ucl_object_t* ucl_object_new_userdata (ucl_userdata_dtor dtor, |
292 ucl_userdata_emitter emitter) UCL_WARN_UNUSED_RESULT; | 297 ucl_userdata_emitter emitter, void *ptr) UCL_WARN_UNUSED_RESULT; |
293 294/** 295 * Perform deep copy of an object copying everything 296 * @param other object to copy 297 * @return new object with refcount equal to 1 298 */ 299UCL_EXTERN ucl_object_t * ucl_object_copy (const ucl_object_t *other) 300 UCL_WARN_UNUSED_RESULT; 301 302/** 303 * Return the type of an object 304 * @return the object type 305 */ 306UCL_EXTERN ucl_type_t ucl_object_type (const ucl_object_t *obj); 307 308/** | 298 299/** 300 * Perform deep copy of an object copying everything 301 * @param other object to copy 302 * @return new object with refcount equal to 1 303 */ 304UCL_EXTERN ucl_object_t * ucl_object_copy (const ucl_object_t *other) 305 UCL_WARN_UNUSED_RESULT; 306 307/** 308 * Return the type of an object 309 * @return the object type 310 */ 311UCL_EXTERN ucl_type_t ucl_object_type (const ucl_object_t *obj); 312 313/** |
314 * Converts ucl object type to its string representation 315 * @param type type of object 316 * @return constant string describing type 317 */ 318UCL_EXTERN const char * ucl_object_type_to_string (ucl_type_t type); 319 320/** 321 * Converts string that represents ucl type to real ucl type enum 322 * @param input C string with name of type 323 * @param res resulting target 324 * @return true if `input` is a name of type stored in `res` 325 */ 326UCL_EXTERN bool ucl_object_string_to_type (const char *input, ucl_type_t *res); 327 328/** |
|
309 * Convert any string to an ucl object making the specified transformations 310 * @param str fixed size or NULL terminated string 311 * @param len length (if len is zero, than str is treated as NULL terminated) 312 * @param flags conversion flags 313 * @return new object 314 */ 315UCL_EXTERN ucl_object_t * ucl_object_fromstring_common (const char *str, size_t len, 316 enum ucl_string_flags flags) UCL_WARN_UNUSED_RESULT; --- 320 unchanged lines hidden (view full) --- 637UCL_EXTERN const char* ucl_object_tolstring (const ucl_object_t *obj, size_t *tlen); 638 639/** 640 * Return object identified by a key in the specified object 641 * @param obj object to get a key from (must be of type UCL_OBJECT) 642 * @param key key to search 643 * @return object matching the specified key or NULL if key was not found 644 */ | 329 * Convert any string to an ucl object making the specified transformations 330 * @param str fixed size or NULL terminated string 331 * @param len length (if len is zero, than str is treated as NULL terminated) 332 * @param flags conversion flags 333 * @return new object 334 */ 335UCL_EXTERN ucl_object_t * ucl_object_fromstring_common (const char *str, size_t len, 336 enum ucl_string_flags flags) UCL_WARN_UNUSED_RESULT; --- 320 unchanged lines hidden (view full) --- 657UCL_EXTERN const char* ucl_object_tolstring (const ucl_object_t *obj, size_t *tlen); 658 659/** 660 * Return object identified by a key in the specified object 661 * @param obj object to get a key from (must be of type UCL_OBJECT) 662 * @param key key to search 663 * @return object matching the specified key or NULL if key was not found 664 */ |
645UCL_EXTERN const ucl_object_t* ucl_object_find_key (const ucl_object_t *obj, | 665UCL_EXTERN const ucl_object_t* ucl_object_lookup (const ucl_object_t *obj, |
646 const char *key); | 666 const char *key); |
667#define ucl_object_find_key ucl_object_lookup |
|
647 648/** 649 * Return object identified by a key in the specified object, if the first key is 650 * not found then look for the next one. This process is repeated unless 651 * the next argument in the list is not NULL. So, `ucl_object_find_any_key(obj, key, NULL)` 652 * is equal to `ucl_object_find_key(obj, key)` 653 * @param obj object to get a key from (must be of type UCL_OBJECT) 654 * @param key key to search 655 * @param ... list of alternative keys to search (NULL terminated) 656 * @return object matching the specified key or NULL if key was not found 657 */ | 668 669/** 670 * Return object identified by a key in the specified object, if the first key is 671 * not found then look for the next one. This process is repeated unless 672 * the next argument in the list is not NULL. So, `ucl_object_find_any_key(obj, key, NULL)` 673 * is equal to `ucl_object_find_key(obj, key)` 674 * @param obj object to get a key from (must be of type UCL_OBJECT) 675 * @param key key to search 676 * @param ... list of alternative keys to search (NULL terminated) 677 * @return object matching the specified key or NULL if key was not found 678 */ |
658UCL_EXTERN const ucl_object_t* ucl_object_find_any_key (const ucl_object_t *obj, | 679UCL_EXTERN const ucl_object_t* ucl_object_lookup_any (const ucl_object_t *obj, |
659 const char *key, ...); | 680 const char *key, ...); |
681#define ucl_object_find_any_key ucl_object_lookup_any |
|
660 661/** 662 * Return object identified by a fixed size key in the specified object 663 * @param obj object to get a key from (must be of type UCL_OBJECT) 664 * @param key key to search 665 * @param klen length of a key 666 * @return object matching the specified key or NULL if key was not found 667 */ | 682 683/** 684 * Return object identified by a fixed size key in the specified object 685 * @param obj object to get a key from (must be of type UCL_OBJECT) 686 * @param key key to search 687 * @param klen length of a key 688 * @return object matching the specified key or NULL if key was not found 689 */ |
668UCL_EXTERN const ucl_object_t* ucl_object_find_keyl (const ucl_object_t *obj, | 690UCL_EXTERN const ucl_object_t* ucl_object_lookup_len (const ucl_object_t *obj, |
669 const char *key, size_t klen); | 691 const char *key, size_t klen); |
692#define ucl_object_find_keyl ucl_object_lookup_len |
|
670 671/** 672 * Return object identified by dot notation string 673 * @param obj object to search in 674 * @param path dot.notation.path to the path to lookup. May use numeric .index on arrays 675 * @return object matched the specified path or NULL if path is not found 676 */ | 693 694/** 695 * Return object identified by dot notation string 696 * @param obj object to search in 697 * @param path dot.notation.path to the path to lookup. May use numeric .index on arrays 698 * @return object matched the specified path or NULL if path is not found 699 */ |
677UCL_EXTERN const ucl_object_t *ucl_lookup_path (const ucl_object_t *obj, | 700UCL_EXTERN const ucl_object_t *ucl_object_lookup_path (const ucl_object_t *obj, |
678 const char *path); | 701 const char *path); |
702#define ucl_lookup_path ucl_object_lookup_path |
|
679 680/** 681 * Return object identified by object notation string using arbitrary delimiter 682 * @param obj object to search in 683 * @param path dot.notation.path to the path to lookup. May use numeric .index on arrays 684 * @param sep the sepatorator to use in place of . (incase keys have . in them) 685 * @return object matched the specified path or NULL if path is not found 686 */ | 703 704/** 705 * Return object identified by object notation string using arbitrary delimiter 706 * @param obj object to search in 707 * @param path dot.notation.path to the path to lookup. May use numeric .index on arrays 708 * @param sep the sepatorator to use in place of . (incase keys have . in them) 709 * @return object matched the specified path or NULL if path is not found 710 */ |
687UCL_EXTERN const ucl_object_t *ucl_lookup_path_char (const ucl_object_t *obj, | 711UCL_EXTERN const ucl_object_t *ucl_object_lookup_path_char (const ucl_object_t *obj, |
688 const char *path, char sep); | 712 const char *path, char sep); |
713#define ucl_lookup_path_char ucl_object_lookup_path_char |
|
689 690/** 691 * Returns a key of an object as a NULL terminated string 692 * @param obj CL object 693 * @return key or NULL if there is no key 694 */ 695UCL_EXTERN const char* ucl_object_key (const ucl_object_t *obj); 696 --- 33 unchanged lines hidden (view full) --- 730 * 1) Type of objects 731 * 2) Size of objects 732 * 3) Content of objects 733 */ 734UCL_EXTERN int ucl_object_compare (const ucl_object_t *o1, 735 const ucl_object_t *o2); 736 737/** | 714 715/** 716 * Returns a key of an object as a NULL terminated string 717 * @param obj CL object 718 * @return key or NULL if there is no key 719 */ 720UCL_EXTERN const char* ucl_object_key (const ucl_object_t *obj); 721 --- 33 unchanged lines hidden (view full) --- 755 * 1) Type of objects 756 * 2) Size of objects 757 * 3) Content of objects 758 */ 759UCL_EXTERN int ucl_object_compare (const ucl_object_t *o1, 760 const ucl_object_t *o2); 761 762/** |
763 * Compare objects `o1` and `o2` useful for sorting 764 * @param o1 the first object 765 * @param o2 the second object 766 * @return values >0, 0 and <0 if `o1` is more than, equal and less than `o2`. 767 * The order of comparison: 768 * 1) Type of objects 769 * 2) Size of objects 770 * 3) Content of objects 771 */ 772UCL_EXTERN int ucl_object_compare_qsort (const ucl_object_t **o1, 773 const ucl_object_t **o2); 774 775/** |
|
738 * Sort UCL array using `cmp` compare function 739 * @param ar 740 * @param cmp 741 */ 742UCL_EXTERN void ucl_object_array_sort (ucl_object_t *ar, 743 int (*cmp)(const ucl_object_t **o1, const ucl_object_t **o2)); 744 745/** --- 19 unchanged lines hidden (view full) --- 765/** 766 * Get next key from an object 767 * @param obj object to iterate 768 * @param iter opaque iterator, must be set to NULL on the first call: 769 * ucl_object_iter_t it = NULL; 770 * while ((cur = ucl_iterate_object (obj, &it)) != NULL) ... 771 * @return the next object or NULL 772 */ | 776 * Sort UCL array using `cmp` compare function 777 * @param ar 778 * @param cmp 779 */ 780UCL_EXTERN void ucl_object_array_sort (ucl_object_t *ar, 781 int (*cmp)(const ucl_object_t **o1, const ucl_object_t **o2)); 782 783/** --- 19 unchanged lines hidden (view full) --- 803/** 804 * Get next key from an object 805 * @param obj object to iterate 806 * @param iter opaque iterator, must be set to NULL on the first call: 807 * ucl_object_iter_t it = NULL; 808 * while ((cur = ucl_iterate_object (obj, &it)) != NULL) ... 809 * @return the next object or NULL 810 */ |
773UCL_EXTERN const ucl_object_t* ucl_iterate_object (const ucl_object_t *obj, | 811UCL_EXTERN const ucl_object_t* ucl_object_iterate (const ucl_object_t *obj, |
774 ucl_object_iter_t *iter, bool expand_values); | 812 ucl_object_iter_t *iter, bool expand_values); |
813#define ucl_iterate_object ucl_object_iterate |
|
775 776/** 777 * Create new safe iterator for the specified object 778 * @param obj object to iterate 779 * @return new iterator object that should be used with safe iterators API only 780 */ 781UCL_EXTERN ucl_object_iter_t ucl_object_iterate_new (const ucl_object_t *obj) 782 UCL_WARN_UNUSED_RESULT; --- 252 unchanged lines hidden (view full) --- 1035 */ 1036UCL_EXTERN ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser); 1037 1038/** 1039 * Get the error string if parsing has been failed 1040 * @param parser parser object 1041 * @return error description 1042 */ | 814 815/** 816 * Create new safe iterator for the specified object 817 * @param obj object to iterate 818 * @return new iterator object that should be used with safe iterators API only 819 */ 820UCL_EXTERN ucl_object_iter_t ucl_object_iterate_new (const ucl_object_t *obj) 821 UCL_WARN_UNUSED_RESULT; --- 252 unchanged lines hidden (view full) --- 1074 */ 1075UCL_EXTERN ucl_object_t* ucl_parser_get_object (struct ucl_parser *parser); 1076 1077/** 1078 * Get the error string if parsing has been failed 1079 * @param parser parser object 1080 * @return error description 1081 */ |
1043UCL_EXTERN const char *ucl_parser_get_error(struct ucl_parser *parser); | 1082UCL_EXTERN const char *ucl_parser_get_error (struct ucl_parser *parser); |
1044 1045/** 1046 * Get the code of the last error 1047 * @param parser parser object 1048 * @return error code 1049 */ | 1083 1084/** 1085 * Get the code of the last error 1086 * @param parser parser object 1087 * @return error code 1088 */ |
1050UCL_EXTERN int ucl_parser_get_error_code(struct ucl_parser *parser); | 1089UCL_EXTERN int ucl_parser_get_error_code (struct ucl_parser *parser); |
1051 1052/** 1053 * Get the current column number within parser 1054 * @param parser parser object 1055 * @return current column number 1056 */ | 1090 1091/** 1092 * Get the current column number within parser 1093 * @param parser parser object 1094 * @return current column number 1095 */ |
1057UCL_EXTERN unsigned ucl_parser_get_column(struct ucl_parser *parser); | 1096UCL_EXTERN unsigned ucl_parser_get_column (struct ucl_parser *parser); |
1058 1059/** 1060 * Get the current line number within parser 1061 * @param parser parser object 1062 * @return current line number 1063 */ | 1097 1098/** 1099 * Get the current line number within parser 1100 * @param parser parser object 1101 * @return current line number 1102 */ |
1064UCL_EXTERN unsigned ucl_parser_get_linenum(struct ucl_parser *parser); | 1103UCL_EXTERN unsigned ucl_parser_get_linenum (struct ucl_parser *parser); |
1065 1066/** 1067 * Clear the error in the parser 1068 * @param parser parser object 1069 */ | 1104 1105/** 1106 * Clear the error in the parser 1107 * @param parser parser object 1108 */ |
1070UCL_EXTERN void ucl_parser_clear_error(struct ucl_parser *parser); | 1109UCL_EXTERN void ucl_parser_clear_error (struct ucl_parser *parser); |
1071 1072/** 1073 * Free ucl parser object 1074 * @param parser parser object 1075 */ 1076UCL_EXTERN void ucl_parser_free (struct ucl_parser *parser); 1077 1078/** | 1110 1111/** 1112 * Free ucl parser object 1113 * @param parser parser object 1114 */ 1115UCL_EXTERN void ucl_parser_free (struct ucl_parser *parser); 1116 1117/** |
1118 * Get constant opaque pointer to comments structure for this parser. Increase 1119 * refcount to prevent this object to be destroyed on parser's destruction 1120 * @param parser parser structure 1121 * @return ucl comments pointer or NULL 1122 */ 1123UCL_EXTERN const ucl_object_t * ucl_parser_get_comments (struct ucl_parser *parser); 1124 1125/** 1126 * Utility function to find a comment object for the specified object in the input 1127 * @param comments comments object 1128 * @param srch search object 1129 * @return string comment enclosed in ucl_object_t 1130 */ 1131UCL_EXTERN const ucl_object_t * ucl_comments_find (const ucl_object_t *comments, 1132 const ucl_object_t *srch); 1133 1134/** 1135 * Move comment from `from` object to `to` object 1136 * @param comments comments object 1137 * @param what source object 1138 * @param whith destination object 1139 * @return `true` if `from` has comment and it has been moved to `to` 1140 */ 1141UCL_EXTERN bool ucl_comments_move (ucl_object_t *comments, 1142 const ucl_object_t *from, const ucl_object_t *to); 1143 1144/** 1145 * Adds a new comment for an object 1146 * @param comments comments object 1147 * @param obj object to add comment to 1148 * @param comment string representation of a comment 1149 */ 1150UCL_EXTERN void ucl_comments_add (ucl_object_t *comments, 1151 const ucl_object_t *obj, const char *comment); 1152 1153/** |
|
1079 * Add new public key to parser for signatures check 1080 * @param parser parser object 1081 * @param key PEM representation of a key 1082 * @param len length of the key 1083 * @param err if *err is NULL it is set to parser error 1084 * @return true if a key has been successfully added 1085 */ | 1154 * Add new public key to parser for signatures check 1155 * @param parser parser object 1156 * @param key PEM representation of a key 1157 * @param len length of the key 1158 * @param err if *err is NULL it is set to parser error 1159 * @return true if a key has been successfully added 1160 */ |
1086UCL_EXTERN bool ucl_pubkey_add (struct ucl_parser *parser, const unsigned char *key, size_t len); | 1161UCL_EXTERN bool ucl_parser_pubkey_add (struct ucl_parser *parser, 1162 const unsigned char *key, size_t len); |
1087 1088/** 1089 * Set FILENAME and CURDIR variables in parser 1090 * @param parser parser object 1091 * @param filename filename to set or NULL to set FILENAME to "undef" and CURDIR to getcwd() 1092 * @param need_expand perform realpath() if this variable is true and filename is not NULL 1093 * @return true if variables has been set 1094 */ --- 56 unchanged lines hidden (view full) --- 1151 /** A set of output functions */ 1152 const struct ucl_emitter_functions *func; 1153 /** A set of output operations */ 1154 const struct ucl_emitter_operations *ops; 1155 /** Current amount of indent tabs */ 1156 unsigned int indent; 1157 /** Top level object */ 1158 const ucl_object_t *top; | 1163 1164/** 1165 * Set FILENAME and CURDIR variables in parser 1166 * @param parser parser object 1167 * @param filename filename to set or NULL to set FILENAME to "undef" and CURDIR to getcwd() 1168 * @param need_expand perform realpath() if this variable is true and filename is not NULL 1169 * @return true if variables has been set 1170 */ --- 56 unchanged lines hidden (view full) --- 1227 /** A set of output functions */ 1228 const struct ucl_emitter_functions *func; 1229 /** A set of output operations */ 1230 const struct ucl_emitter_operations *ops; 1231 /** Current amount of indent tabs */ 1232 unsigned int indent; 1233 /** Top level object */ 1234 const ucl_object_t *top; |
1159 /** The rest of context */ 1160 unsigned char data[1]; | 1235 /** Optional comments */ 1236 const ucl_object_t *comments; |
1161}; 1162 1163/** 1164 * Emit object to a string 1165 * @param obj object 1166 * @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is 1167 * #UCL_EMIT_CONFIG then emit config like object 1168 * @return dump of an object (must be freed after using) or NULL in case of error --- 13 unchanged lines hidden (view full) --- 1182 enum ucl_emitter emit_type, size_t *len); 1183 1184/** 1185 * Emit object to a string 1186 * @param obj object 1187 * @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is 1188 * #UCL_EMIT_CONFIG then emit config like object 1189 * @param emitter a set of emitter functions | 1237}; 1238 1239/** 1240 * Emit object to a string 1241 * @param obj object 1242 * @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is 1243 * #UCL_EMIT_CONFIG then emit config like object 1244 * @return dump of an object (must be freed after using) or NULL in case of error --- 13 unchanged lines hidden (view full) --- 1258 enum ucl_emitter emit_type, size_t *len); 1259 1260/** 1261 * Emit object to a string 1262 * @param obj object 1263 * @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is 1264 * #UCL_EMIT_CONFIG then emit config like object 1265 * @param emitter a set of emitter functions |
1266 * @param comments optional comments for the parser |
|
1190 * @return dump of an object (must be freed after using) or NULL in case of error 1191 */ 1192UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj, 1193 enum ucl_emitter emit_type, | 1267 * @return dump of an object (must be freed after using) or NULL in case of error 1268 */ 1269UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj, 1270 enum ucl_emitter emit_type, |
1194 struct ucl_emitter_functions *emitter); | 1271 struct ucl_emitter_functions *emitter, 1272 const ucl_object_t *comments); |
1195 1196/** 1197 * Start streamlined UCL object emitter 1198 * @param obj top UCL object 1199 * @param emit_type emit type 1200 * @param emitter a set of emitter functions 1201 * @return new streamlined context that should be freed by 1202 * `ucl_object_emit_streamline_finish` --- 72 unchanged lines hidden (view full) --- 1275 */ 1276enum ucl_schema_error_code { 1277 UCL_SCHEMA_OK = 0, /**< no error */ 1278 UCL_SCHEMA_TYPE_MISMATCH, /**< type of object is incorrect */ 1279 UCL_SCHEMA_INVALID_SCHEMA, /**< schema is invalid */ 1280 UCL_SCHEMA_MISSING_PROPERTY,/**< one or more missing properties */ 1281 UCL_SCHEMA_CONSTRAINT, /**< constraint found */ 1282 UCL_SCHEMA_MISSING_DEPENDENCY, /**< missing dependency */ | 1273 1274/** 1275 * Start streamlined UCL object emitter 1276 * @param obj top UCL object 1277 * @param emit_type emit type 1278 * @param emitter a set of emitter functions 1279 * @return new streamlined context that should be freed by 1280 * `ucl_object_emit_streamline_finish` --- 72 unchanged lines hidden (view full) --- 1353 */ 1354enum ucl_schema_error_code { 1355 UCL_SCHEMA_OK = 0, /**< no error */ 1356 UCL_SCHEMA_TYPE_MISMATCH, /**< type of object is incorrect */ 1357 UCL_SCHEMA_INVALID_SCHEMA, /**< schema is invalid */ 1358 UCL_SCHEMA_MISSING_PROPERTY,/**< one or more missing properties */ 1359 UCL_SCHEMA_CONSTRAINT, /**< constraint found */ 1360 UCL_SCHEMA_MISSING_DEPENDENCY, /**< missing dependency */ |
1361 UCL_SCHEMA_EXTERNAL_REF_MISSING, /**< cannot fetch external ref */ 1362 UCL_SCHEMA_EXTERNAL_REF_INVALID, /**< invalid external ref */ 1363 UCL_SCHEMA_INTERNAL_ERROR, /**< something bad happened */ |
|
1283 UCL_SCHEMA_UNKNOWN /**< generic error */ 1284}; 1285 1286/** 1287 * Generic ucl schema error 1288 */ 1289struct ucl_schema_error { 1290 enum ucl_schema_error_code code; /**< error code */ --- 7 unchanged lines hidden (view full) --- 1298 * @param obj object to validate 1299 * @param err error pointer, if this parameter is not NULL and error has been 1300 * occured, then `err` is filled with the exact error definition. 1301 * @return true if `obj` is valid using `schema` 1302 */ 1303UCL_EXTERN bool ucl_object_validate (const ucl_object_t *schema, 1304 const ucl_object_t *obj, struct ucl_schema_error *err); 1305 | 1364 UCL_SCHEMA_UNKNOWN /**< generic error */ 1365}; 1366 1367/** 1368 * Generic ucl schema error 1369 */ 1370struct ucl_schema_error { 1371 enum ucl_schema_error_code code; /**< error code */ --- 7 unchanged lines hidden (view full) --- 1379 * @param obj object to validate 1380 * @param err error pointer, if this parameter is not NULL and error has been 1381 * occured, then `err` is filled with the exact error definition. 1382 * @return true if `obj` is valid using `schema` 1383 */ 1384UCL_EXTERN bool ucl_object_validate (const ucl_object_t *schema, 1385 const ucl_object_t *obj, struct ucl_schema_error *err); 1386 |
1387/** 1388 * Validate object `obj` using schema object `schema` and root schema at `root`. 1389 * @param schema schema object 1390 * @param obj object to validate 1391 * @param root root schema object 1392 * @param err error pointer, if this parameter is not NULL and error has been 1393 * occured, then `err` is filled with the exact error definition. 1394 * @return true if `obj` is valid using `schema` 1395 */ 1396UCL_EXTERN bool ucl_object_validate_root (const ucl_object_t *schema, 1397 const ucl_object_t *obj, 1398 const ucl_object_t *root, 1399 struct ucl_schema_error *err); 1400 1401/** 1402 * Validate object `obj` using schema object `schema` and root schema at `root` 1403 * using some external references provided. 1404 * @param schema schema object 1405 * @param obj object to validate 1406 * @param root root schema object 1407 * @param ext_refs external references (might be modified during validation) 1408 * @param err error pointer, if this parameter is not NULL and error has been 1409 * occured, then `err` is filled with the exact error definition. 1410 * @return true if `obj` is valid using `schema` 1411 */ 1412UCL_EXTERN bool ucl_object_validate_root_ext (const ucl_object_t *schema, 1413 const ucl_object_t *obj, 1414 const ucl_object_t *root, 1415 ucl_object_t *ext_refs, 1416 struct ucl_schema_error *err); 1417 |
|
1306/** @} */ 1307 1308#ifdef __cplusplus 1309} 1310#endif 1311/* 1312 * XXX: Poorly named API functions, need to replace them with the appropriate 1313 * named function. All API functions *must* use naming ucl_object_*. Usage of --- 19 unchanged lines hidden --- | 1418/** @} */ 1419 1420#ifdef __cplusplus 1421} 1422#endif 1423/* 1424 * XXX: Poorly named API functions, need to replace them with the appropriate 1425 * named function. All API functions *must* use naming ucl_object_*. Usage of --- 19 unchanged lines hidden --- |