corrected version (with typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE;) included in the sources

Dependents:   STM32F746_iothub_client_sample_mqtt

Fork of iothub_client by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers parson.h Source File

parson.h

00001 /*
00002  Parson ( http://kgabis.github.com/parson/ )
00003  Copyright (c) 2012 - 2016 Krzysztof Gabis
00004 
00005  Permission is hereby granted, free of charge, to any person obtaining a copy
00006  of this software and associated documentation files (the "Software"), to deal
00007  in the Software without restriction, including without limitation the rights
00008  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  copies of the Software, and to permit persons to whom the Software is
00010  furnished to do so, subject to the following conditions:
00011 
00012  The above copyright notice and this permission notice shall be included in
00013  all copies or substantial portions of the Software.
00014 
00015  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  THE SOFTWARE.
00022 */
00023 
00024 #ifndef parson_parson_h
00025 #define parson_parson_h
00026 
00027 #ifdef __cplusplus
00028 extern "C"
00029 {
00030 #endif
00031 
00032 #include <stddef.h>   /* size_t */
00033 
00034 /* Types and enums */
00035 typedef struct json_object_t JSON_Object;
00036 typedef struct json_array_t  JSON_Array;
00037 typedef struct json_value_t  JSON_Value;
00038 
00039 enum json_value_type {
00040     JSONError   = -1,
00041     JSONNull    = 1,
00042     JSONString  = 2,
00043     JSONNumber  = 3,
00044     JSONObject  = 4,
00045     JSONArray   = 5,
00046     JSONBoolean = 6
00047 };
00048 typedef int JSON_Value_Type;
00049 
00050 enum json_result_t {
00051     JSONSuccess = 0,
00052     JSONFailure = -1
00053 };
00054 typedef int JSON_Status;
00055 
00056 typedef void * (*JSON_Malloc_Function)(size_t);
00057 typedef void   (*JSON_Free_Function)(void *);
00058 
00059 /* Call only once, before calling any other function from parson API. If not called, malloc and free
00060    from stdlib will be used for all allocations */
00061 void json_set_allocation_functions(JSON_Malloc_Function malloc_fun, JSON_Free_Function free_fun);
00062 
00063 /* Parses first JSON value in a file, returns NULL in case of error */
00064 JSON_Value * json_parse_file(const char *filename);
00065 
00066 /* Parses first JSON value in a file and ignores comments (/ * * / and //),
00067    returns NULL in case of error */
00068 JSON_Value * json_parse_file_with_comments(const char *filename);
00069 
00070 /*  Parses first JSON value in a string, returns NULL in case of error */
00071 JSON_Value * json_parse_string(const char *string);
00072 
00073 /*  Parses first JSON value in a string and ignores comments (/ * * / and //),
00074     returns NULL in case of error */
00075 JSON_Value * json_parse_string_with_comments(const char *string);
00076 
00077 /* Serialization */
00078 size_t      json_serialization_size(const JSON_Value *value); /* returns 0 on fail */
00079 JSON_Status json_serialize_to_buffer(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
00080 JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename);
00081 char *      json_serialize_to_string(const JSON_Value *value);
00082 
00083 /* Pretty serialization */
00084 size_t      json_serialization_size_pretty(const JSON_Value *value); /* returns 0 on fail */
00085 JSON_Status json_serialize_to_buffer_pretty(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
00086 JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *filename);
00087 char *      json_serialize_to_string_pretty(const JSON_Value *value);
00088 
00089 void        json_free_serialized_string(char *string); /* frees string from json_serialize_to_string and json_serialize_to_string_pretty */
00090 
00091 /* Comparing */
00092 int  json_value_equals(const JSON_Value *a, const JSON_Value *b);
00093 
00094 /* Validation
00095    This is *NOT* JSON Schema. It validates json by checking if object have identically
00096    named fields with matching types.
00097    For example schema {"name":"", "age":0} will validate
00098    {"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
00099    but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
00100    In case of arrays, only first value in schema is checked against all values in tested array.
00101    Empty objects ({}) validate all objects, empty arrays ([]) validate all arrays,
00102    null validates values of every type.
00103  */
00104 JSON_Status json_validate(const JSON_Value *schema, const JSON_Value *value);
00105 
00106 /*
00107  * JSON Object
00108  */
00109 JSON_Value  * json_object_get_value  (const JSON_Object *object, const char *name);
00110 const char  * json_object_get_string (const JSON_Object *object, const char *name);
00111 JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
00112 JSON_Array  * json_object_get_array  (const JSON_Object *object, const char *name);
00113 double        json_object_get_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
00114 int           json_object_get_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
00115 
00116 /* dotget functions enable addressing values with dot notation in nested objects,
00117  just like in structs or c++/java/c# objects (e.g. objectA.objectB.value).
00118  Because valid names in JSON can contain dots, some values may be inaccessible
00119  this way. */
00120 JSON_Value  * json_object_dotget_value  (const JSON_Object *object, const char *name);
00121 const char  * json_object_dotget_string (const JSON_Object *object, const char *name);
00122 JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
00123 JSON_Array  * json_object_dotget_array  (const JSON_Object *object, const char *name);
00124 double        json_object_dotget_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
00125 int           json_object_dotget_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
00126 
00127 /* Functions to get available names */
00128 size_t        json_object_get_count   (const JSON_Object *object);
00129 const char  * json_object_get_name    (const JSON_Object *object, size_t index);
00130 JSON_Value  * json_object_get_value_at(const JSON_Object *object, size_t index);
00131 
00132 /* Creates new name-value pair or frees and replaces old value with a new one.
00133  * json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
00134 JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
00135 JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string);
00136 JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number);
00137 JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean);
00138 JSON_Status json_object_set_null(JSON_Object *object, const char *name);
00139 
00140 /* Works like dotget functions, but creates whole hierarchy if necessary.
00141  * json_object_dotset_value does not copy passed value so it shouldn't be freed afterwards. */
00142 JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value);
00143 JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string);
00144 JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number);
00145 JSON_Status json_object_dotset_boolean(JSON_Object *object, const char *name, int boolean);
00146 JSON_Status json_object_dotset_null(JSON_Object *object, const char *name);
00147 
00148 /* Frees and removes name-value pair */
00149 JSON_Status json_object_remove(JSON_Object *object, const char *name);
00150 
00151 /* Works like dotget function, but removes name-value pair only on exact match. */
00152 JSON_Status json_object_dotremove(JSON_Object *object, const char *key);
00153 
00154 /* Removes all name-value pairs in object */
00155 JSON_Status json_object_clear(JSON_Object *object);
00156 
00157 /*
00158  *JSON Array
00159  */
00160 JSON_Value  * json_array_get_value  (const JSON_Array *array, size_t index);
00161 const char  * json_array_get_string (const JSON_Array *array, size_t index);
00162 JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
00163 JSON_Array  * json_array_get_array  (const JSON_Array *array, size_t index);
00164 double        json_array_get_number (const JSON_Array *array, size_t index); /* returns 0 on fail */
00165 int           json_array_get_boolean(const JSON_Array *array, size_t index); /* returns -1 on fail */
00166 size_t        json_array_get_count  (const JSON_Array *array);
00167 
00168 /* Frees and removes value at given index, does nothing and returns JSONFailure if index doesn't exist.
00169  * Order of values in array may change during execution.  */
00170 JSON_Status json_array_remove(JSON_Array *array, size_t i);
00171 
00172 /* Frees and removes from array value at given index and replaces it with given one.
00173  * Does nothing and returns JSONFailure if index doesn't exist.
00174  * json_array_replace_value does not copy passed value so it shouldn't be freed afterwards. */
00175 JSON_Status json_array_replace_value(JSON_Array *array, size_t i, JSON_Value *value);
00176 JSON_Status json_array_replace_string(JSON_Array *array, size_t i, const char* string);
00177 JSON_Status json_array_replace_number(JSON_Array *array, size_t i, double number);
00178 JSON_Status json_array_replace_boolean(JSON_Array *array, size_t i, int boolean);
00179 JSON_Status json_array_replace_null(JSON_Array *array, size_t i);
00180 
00181 /* Frees and removes all values from array */
00182 JSON_Status json_array_clear(JSON_Array *array);
00183 
00184 /* Appends new value at the end of array.
00185  * json_array_append_value does not copy passed value so it shouldn't be freed afterwards. */
00186 JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value);
00187 JSON_Status json_array_append_string(JSON_Array *array, const char *string);
00188 JSON_Status json_array_append_number(JSON_Array *array, double number);
00189 JSON_Status json_array_append_boolean(JSON_Array *array, int boolean);
00190 JSON_Status json_array_append_null(JSON_Array *array);
00191 
00192 /*
00193  *JSON Value
00194  */
00195 JSON_Value * json_value_init_object (void);
00196 JSON_Value * json_value_init_array  (void);
00197 JSON_Value * json_value_init_string (const char *string); /* copies passed string */
00198 JSON_Value * json_value_init_number (double number);
00199 JSON_Value * json_value_init_boolean(int boolean);
00200 JSON_Value * json_value_init_null   (void);
00201 JSON_Value * json_value_deep_copy   (const JSON_Value *value);
00202 void         json_value_free        (JSON_Value *value);
00203 
00204 JSON_Value_Type json_value_get_type   (const JSON_Value *value);
00205 JSON_Object *   json_value_get_object (const JSON_Value *value);
00206 JSON_Array  *   json_value_get_array  (const JSON_Value *value);
00207 const char  *   json_value_get_string (const JSON_Value *value);
00208 double          json_value_get_number (const JSON_Value *value);
00209 int             json_value_get_boolean(const JSON_Value *value);
00210 
00211 /* Same as above, but shorter */
00212 JSON_Value_Type json_type   (const JSON_Value *value);
00213 JSON_Object *   json_object (const JSON_Value *value);
00214 JSON_Array  *   json_array  (const JSON_Value *value);
00215 const char  *   json_string (const JSON_Value *value);
00216 double          json_number (const JSON_Value *value);
00217 int             json_boolean(const JSON_Value *value);
00218 
00219 #ifdef __cplusplus
00220 }
00221 #endif
00222 
00223 #endif