Microsoft Azure IoTHub client libraries

Dependents:   sht15_remote_monitoring RobotArmDemo iothub_client_sample_amqp f767zi_mqtt ... more

This library implements the Microsoft Azure IoTHub client library. The code is replicated from https://github.com/Azure/azure-iot-sdks

Committer:
AzureIoTClient
Date:
Fri Mar 10 11:47:36 2017 -0800
Revision:
61:8b85a4e797cf
Parent:
50:bbc71457b0ea
Child:
93:7c0bbb86b167
1.1.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzureIoTClient 42:448eecc3676e 1 /*
AzureIoTClient 42:448eecc3676e 2 Parson ( http://kgabis.github.com/parson/ )
AzureIoTClient 61:8b85a4e797cf 3 Copyright (c) 2012 - 2017 Krzysztof Gabis
AzureIoTClient 42:448eecc3676e 4
AzureIoTClient 42:448eecc3676e 5 Permission is hereby granted, free of charge, to any person obtaining a copy
AzureIoTClient 42:448eecc3676e 6 of this software and associated documentation files (the "Software"), to deal
AzureIoTClient 42:448eecc3676e 7 in the Software without restriction, including without limitation the rights
AzureIoTClient 42:448eecc3676e 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AzureIoTClient 42:448eecc3676e 9 copies of the Software, and to permit persons to whom the Software is
AzureIoTClient 42:448eecc3676e 10 furnished to do so, subject to the following conditions:
AzureIoTClient 42:448eecc3676e 11
AzureIoTClient 42:448eecc3676e 12 The above copyright notice and this permission notice shall be included in
AzureIoTClient 42:448eecc3676e 13 all copies or substantial portions of the Software.
AzureIoTClient 42:448eecc3676e 14
AzureIoTClient 42:448eecc3676e 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AzureIoTClient 42:448eecc3676e 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AzureIoTClient 42:448eecc3676e 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AzureIoTClient 42:448eecc3676e 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AzureIoTClient 42:448eecc3676e 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AzureIoTClient 42:448eecc3676e 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AzureIoTClient 42:448eecc3676e 21 THE SOFTWARE.
AzureIoTClient 42:448eecc3676e 22 */
AzureIoTClient 42:448eecc3676e 23
AzureIoTClient 42:448eecc3676e 24 #ifndef parson_parson_h
AzureIoTClient 42:448eecc3676e 25 #define parson_parson_h
AzureIoTClient 42:448eecc3676e 26
AzureIoTClient 42:448eecc3676e 27 #ifdef __cplusplus
AzureIoTClient 42:448eecc3676e 28 extern "C"
AzureIoTClient 42:448eecc3676e 29 {
AzureIoTClient 42:448eecc3676e 30 #endif
AzureIoTClient 42:448eecc3676e 31
AzureIoTClient 42:448eecc3676e 32 #include <stddef.h> /* size_t */
AzureIoTClient 42:448eecc3676e 33
AzureIoTClient 42:448eecc3676e 34 /* Types and enums */
AzureIoTClient 42:448eecc3676e 35 typedef struct json_object_t JSON_Object;
AzureIoTClient 42:448eecc3676e 36 typedef struct json_array_t JSON_Array;
AzureIoTClient 42:448eecc3676e 37 typedef struct json_value_t JSON_Value;
AzureIoTClient 42:448eecc3676e 38
AzureIoTClient 42:448eecc3676e 39 enum json_value_type {
AzureIoTClient 42:448eecc3676e 40 JSONError = -1,
AzureIoTClient 42:448eecc3676e 41 JSONNull = 1,
AzureIoTClient 42:448eecc3676e 42 JSONString = 2,
AzureIoTClient 42:448eecc3676e 43 JSONNumber = 3,
AzureIoTClient 42:448eecc3676e 44 JSONObject = 4,
AzureIoTClient 42:448eecc3676e 45 JSONArray = 5,
AzureIoTClient 42:448eecc3676e 46 JSONBoolean = 6
AzureIoTClient 42:448eecc3676e 47 };
AzureIoTClient 42:448eecc3676e 48 typedef int JSON_Value_Type;
AzureIoTClient 42:448eecc3676e 49
AzureIoTClient 42:448eecc3676e 50 enum json_result_t {
AzureIoTClient 42:448eecc3676e 51 JSONSuccess = 0,
AzureIoTClient 42:448eecc3676e 52 JSONFailure = -1
AzureIoTClient 42:448eecc3676e 53 };
AzureIoTClient 42:448eecc3676e 54 typedef int JSON_Status;
AzureIoTClient 42:448eecc3676e 55
AzureIoTClient 42:448eecc3676e 56 typedef void * (*JSON_Malloc_Function)(size_t);
AzureIoTClient 42:448eecc3676e 57 typedef void (*JSON_Free_Function)(void *);
AzureIoTClient 42:448eecc3676e 58
AzureIoTClient 42:448eecc3676e 59 /* Call only once, before calling any other function from parson API. If not called, malloc and free
AzureIoTClient 42:448eecc3676e 60 from stdlib will be used for all allocations */
AzureIoTClient 42:448eecc3676e 61 void json_set_allocation_functions(JSON_Malloc_Function malloc_fun, JSON_Free_Function free_fun);
AzureIoTClient 42:448eecc3676e 62
AzureIoTClient 42:448eecc3676e 63 /* Parses first JSON value in a file, returns NULL in case of error */
AzureIoTClient 42:448eecc3676e 64 JSON_Value * json_parse_file(const char *filename);
AzureIoTClient 42:448eecc3676e 65
AzureIoTClient 42:448eecc3676e 66 /* Parses first JSON value in a file and ignores comments (/ * * / and //),
AzureIoTClient 42:448eecc3676e 67 returns NULL in case of error */
AzureIoTClient 42:448eecc3676e 68 JSON_Value * json_parse_file_with_comments(const char *filename);
AzureIoTClient 42:448eecc3676e 69
AzureIoTClient 42:448eecc3676e 70 /* Parses first JSON value in a string, returns NULL in case of error */
AzureIoTClient 42:448eecc3676e 71 JSON_Value * json_parse_string(const char *string);
AzureIoTClient 42:448eecc3676e 72
AzureIoTClient 42:448eecc3676e 73 /* Parses first JSON value in a string and ignores comments (/ * * / and //),
AzureIoTClient 42:448eecc3676e 74 returns NULL in case of error */
AzureIoTClient 42:448eecc3676e 75 JSON_Value * json_parse_string_with_comments(const char *string);
AzureIoTClient 42:448eecc3676e 76
AzureIoTClient 42:448eecc3676e 77 /* Serialization */
AzureIoTClient 42:448eecc3676e 78 size_t json_serialization_size(const JSON_Value *value); /* returns 0 on fail */
AzureIoTClient 42:448eecc3676e 79 JSON_Status json_serialize_to_buffer(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
AzureIoTClient 42:448eecc3676e 80 JSON_Status json_serialize_to_file(const JSON_Value *value, const char *filename);
AzureIoTClient 42:448eecc3676e 81 char * json_serialize_to_string(const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 82
AzureIoTClient 42:448eecc3676e 83 /* Pretty serialization */
AzureIoTClient 42:448eecc3676e 84 size_t json_serialization_size_pretty(const JSON_Value *value); /* returns 0 on fail */
AzureIoTClient 42:448eecc3676e 85 JSON_Status json_serialize_to_buffer_pretty(const JSON_Value *value, char *buf, size_t buf_size_in_bytes);
AzureIoTClient 42:448eecc3676e 86 JSON_Status json_serialize_to_file_pretty(const JSON_Value *value, const char *filename);
AzureIoTClient 42:448eecc3676e 87 char * json_serialize_to_string_pretty(const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 88
AzureIoTClient 42:448eecc3676e 89 void json_free_serialized_string(char *string); /* frees string from json_serialize_to_string and json_serialize_to_string_pretty */
AzureIoTClient 42:448eecc3676e 90
AzureIoTClient 42:448eecc3676e 91 /* Comparing */
AzureIoTClient 42:448eecc3676e 92 int json_value_equals(const JSON_Value *a, const JSON_Value *b);
AzureIoTClient 42:448eecc3676e 93
AzureIoTClient 42:448eecc3676e 94 /* Validation
AzureIoTClient 42:448eecc3676e 95 This is *NOT* JSON Schema. It validates json by checking if object have identically
AzureIoTClient 42:448eecc3676e 96 named fields with matching types.
AzureIoTClient 42:448eecc3676e 97 For example schema {"name":"", "age":0} will validate
AzureIoTClient 42:448eecc3676e 98 {"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
AzureIoTClient 42:448eecc3676e 99 but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
AzureIoTClient 42:448eecc3676e 100 In case of arrays, only first value in schema is checked against all values in tested array.
AzureIoTClient 42:448eecc3676e 101 Empty objects ({}) validate all objects, empty arrays ([]) validate all arrays,
AzureIoTClient 42:448eecc3676e 102 null validates values of every type.
AzureIoTClient 42:448eecc3676e 103 */
AzureIoTClient 42:448eecc3676e 104 JSON_Status json_validate(const JSON_Value *schema, const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 105
AzureIoTClient 42:448eecc3676e 106 /*
AzureIoTClient 42:448eecc3676e 107 * JSON Object
AzureIoTClient 42:448eecc3676e 108 */
AzureIoTClient 42:448eecc3676e 109 JSON_Value * json_object_get_value (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 110 const char * json_object_get_string (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 111 JSON_Object * json_object_get_object (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 112 JSON_Array * json_object_get_array (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 113 double json_object_get_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
AzureIoTClient 42:448eecc3676e 114 int json_object_get_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
AzureIoTClient 42:448eecc3676e 115
AzureIoTClient 42:448eecc3676e 116 /* dotget functions enable addressing values with dot notation in nested objects,
AzureIoTClient 42:448eecc3676e 117 just like in structs or c++/java/c# objects (e.g. objectA.objectB.value).
AzureIoTClient 42:448eecc3676e 118 Because valid names in JSON can contain dots, some values may be inaccessible
AzureIoTClient 42:448eecc3676e 119 this way. */
AzureIoTClient 42:448eecc3676e 120 JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 121 const char * json_object_dotget_string (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 122 JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 123 JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 124 double json_object_dotget_number (const JSON_Object *object, const char *name); /* returns 0 on fail */
AzureIoTClient 42:448eecc3676e 125 int json_object_dotget_boolean(const JSON_Object *object, const char *name); /* returns -1 on fail */
AzureIoTClient 42:448eecc3676e 126
AzureIoTClient 42:448eecc3676e 127 /* Functions to get available names */
AzureIoTClient 42:448eecc3676e 128 size_t json_object_get_count (const JSON_Object *object);
AzureIoTClient 42:448eecc3676e 129 const char * json_object_get_name (const JSON_Object *object, size_t index);
AzureIoTClient 42:448eecc3676e 130 JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index);
AzureIoTClient 61:8b85a4e797cf 131 JSON_Value * json_object_get_wrapping_value(const JSON_Object *object);
AzureIoTClient 42:448eecc3676e 132
AzureIoTClient 50:bbc71457b0ea 133 /* Functions to check if object has a value with a specific name. Returned value is 1 if object has
AzureIoTClient 50:bbc71457b0ea 134 * a value and 0 if it doesn't. dothas functions behave exactly like dotget functions. */
AzureIoTClient 50:bbc71457b0ea 135 int json_object_has_value (const JSON_Object *object, const char *name);
AzureIoTClient 50:bbc71457b0ea 136 int json_object_has_value_of_type(const JSON_Object *object, const char *name, JSON_Value_Type type);
AzureIoTClient 50:bbc71457b0ea 137
AzureIoTClient 50:bbc71457b0ea 138 int json_object_dothas_value (const JSON_Object *object, const char *name);
AzureIoTClient 50:bbc71457b0ea 139 int json_object_dothas_value_of_type(const JSON_Object *object, const char *name, JSON_Value_Type type);
AzureIoTClient 50:bbc71457b0ea 140
AzureIoTClient 42:448eecc3676e 141 /* Creates new name-value pair or frees and replaces old value with a new one.
AzureIoTClient 42:448eecc3676e 142 * json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
AzureIoTClient 42:448eecc3676e 143 JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
AzureIoTClient 42:448eecc3676e 144 JSON_Status json_object_set_string(JSON_Object *object, const char *name, const char *string);
AzureIoTClient 42:448eecc3676e 145 JSON_Status json_object_set_number(JSON_Object *object, const char *name, double number);
AzureIoTClient 42:448eecc3676e 146 JSON_Status json_object_set_boolean(JSON_Object *object, const char *name, int boolean);
AzureIoTClient 42:448eecc3676e 147 JSON_Status json_object_set_null(JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 148
AzureIoTClient 42:448eecc3676e 149 /* Works like dotget functions, but creates whole hierarchy if necessary.
AzureIoTClient 42:448eecc3676e 150 * json_object_dotset_value does not copy passed value so it shouldn't be freed afterwards. */
AzureIoTClient 42:448eecc3676e 151 JSON_Status json_object_dotset_value(JSON_Object *object, const char *name, JSON_Value *value);
AzureIoTClient 42:448eecc3676e 152 JSON_Status json_object_dotset_string(JSON_Object *object, const char *name, const char *string);
AzureIoTClient 42:448eecc3676e 153 JSON_Status json_object_dotset_number(JSON_Object *object, const char *name, double number);
AzureIoTClient 42:448eecc3676e 154 JSON_Status json_object_dotset_boolean(JSON_Object *object, const char *name, int boolean);
AzureIoTClient 42:448eecc3676e 155 JSON_Status json_object_dotset_null(JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 156
AzureIoTClient 42:448eecc3676e 157 /* Frees and removes name-value pair */
AzureIoTClient 42:448eecc3676e 158 JSON_Status json_object_remove(JSON_Object *object, const char *name);
AzureIoTClient 42:448eecc3676e 159
AzureIoTClient 42:448eecc3676e 160 /* Works like dotget function, but removes name-value pair only on exact match. */
AzureIoTClient 42:448eecc3676e 161 JSON_Status json_object_dotremove(JSON_Object *object, const char *key);
AzureIoTClient 42:448eecc3676e 162
AzureIoTClient 42:448eecc3676e 163 /* Removes all name-value pairs in object */
AzureIoTClient 42:448eecc3676e 164 JSON_Status json_object_clear(JSON_Object *object);
AzureIoTClient 42:448eecc3676e 165
AzureIoTClient 42:448eecc3676e 166 /*
AzureIoTClient 42:448eecc3676e 167 *JSON Array
AzureIoTClient 42:448eecc3676e 168 */
AzureIoTClient 42:448eecc3676e 169 JSON_Value * json_array_get_value (const JSON_Array *array, size_t index);
AzureIoTClient 42:448eecc3676e 170 const char * json_array_get_string (const JSON_Array *array, size_t index);
AzureIoTClient 42:448eecc3676e 171 JSON_Object * json_array_get_object (const JSON_Array *array, size_t index);
AzureIoTClient 42:448eecc3676e 172 JSON_Array * json_array_get_array (const JSON_Array *array, size_t index);
AzureIoTClient 42:448eecc3676e 173 double json_array_get_number (const JSON_Array *array, size_t index); /* returns 0 on fail */
AzureIoTClient 42:448eecc3676e 174 int json_array_get_boolean(const JSON_Array *array, size_t index); /* returns -1 on fail */
AzureIoTClient 42:448eecc3676e 175 size_t json_array_get_count (const JSON_Array *array);
AzureIoTClient 61:8b85a4e797cf 176 JSON_Value * json_array_get_wrapping_value(const JSON_Array *array);
AzureIoTClient 61:8b85a4e797cf 177
AzureIoTClient 42:448eecc3676e 178 /* Frees and removes value at given index, does nothing and returns JSONFailure if index doesn't exist.
AzureIoTClient 42:448eecc3676e 179 * Order of values in array may change during execution. */
AzureIoTClient 42:448eecc3676e 180 JSON_Status json_array_remove(JSON_Array *array, size_t i);
AzureIoTClient 42:448eecc3676e 181
AzureIoTClient 42:448eecc3676e 182 /* Frees and removes from array value at given index and replaces it with given one.
AzureIoTClient 42:448eecc3676e 183 * Does nothing and returns JSONFailure if index doesn't exist.
AzureIoTClient 42:448eecc3676e 184 * json_array_replace_value does not copy passed value so it shouldn't be freed afterwards. */
AzureIoTClient 42:448eecc3676e 185 JSON_Status json_array_replace_value(JSON_Array *array, size_t i, JSON_Value *value);
AzureIoTClient 42:448eecc3676e 186 JSON_Status json_array_replace_string(JSON_Array *array, size_t i, const char* string);
AzureIoTClient 42:448eecc3676e 187 JSON_Status json_array_replace_number(JSON_Array *array, size_t i, double number);
AzureIoTClient 42:448eecc3676e 188 JSON_Status json_array_replace_boolean(JSON_Array *array, size_t i, int boolean);
AzureIoTClient 42:448eecc3676e 189 JSON_Status json_array_replace_null(JSON_Array *array, size_t i);
AzureIoTClient 42:448eecc3676e 190
AzureIoTClient 42:448eecc3676e 191 /* Frees and removes all values from array */
AzureIoTClient 42:448eecc3676e 192 JSON_Status json_array_clear(JSON_Array *array);
AzureIoTClient 42:448eecc3676e 193
AzureIoTClient 42:448eecc3676e 194 /* Appends new value at the end of array.
AzureIoTClient 42:448eecc3676e 195 * json_array_append_value does not copy passed value so it shouldn't be freed afterwards. */
AzureIoTClient 42:448eecc3676e 196 JSON_Status json_array_append_value(JSON_Array *array, JSON_Value *value);
AzureIoTClient 42:448eecc3676e 197 JSON_Status json_array_append_string(JSON_Array *array, const char *string);
AzureIoTClient 42:448eecc3676e 198 JSON_Status json_array_append_number(JSON_Array *array, double number);
AzureIoTClient 42:448eecc3676e 199 JSON_Status json_array_append_boolean(JSON_Array *array, int boolean);
AzureIoTClient 42:448eecc3676e 200 JSON_Status json_array_append_null(JSON_Array *array);
AzureIoTClient 42:448eecc3676e 201
AzureIoTClient 42:448eecc3676e 202 /*
AzureIoTClient 42:448eecc3676e 203 *JSON Value
AzureIoTClient 42:448eecc3676e 204 */
AzureIoTClient 42:448eecc3676e 205 JSON_Value * json_value_init_object (void);
AzureIoTClient 42:448eecc3676e 206 JSON_Value * json_value_init_array (void);
AzureIoTClient 42:448eecc3676e 207 JSON_Value * json_value_init_string (const char *string); /* copies passed string */
AzureIoTClient 42:448eecc3676e 208 JSON_Value * json_value_init_number (double number);
AzureIoTClient 42:448eecc3676e 209 JSON_Value * json_value_init_boolean(int boolean);
AzureIoTClient 42:448eecc3676e 210 JSON_Value * json_value_init_null (void);
AzureIoTClient 42:448eecc3676e 211 JSON_Value * json_value_deep_copy (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 212 void json_value_free (JSON_Value *value);
AzureIoTClient 42:448eecc3676e 213
AzureIoTClient 42:448eecc3676e 214 JSON_Value_Type json_value_get_type (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 215 JSON_Object * json_value_get_object (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 216 JSON_Array * json_value_get_array (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 217 const char * json_value_get_string (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 218 double json_value_get_number (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 219 int json_value_get_boolean(const JSON_Value *value);
AzureIoTClient 61:8b85a4e797cf 220 JSON_Value * json_value_get_parent (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 221
AzureIoTClient 42:448eecc3676e 222 /* Same as above, but shorter */
AzureIoTClient 42:448eecc3676e 223 JSON_Value_Type json_type (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 224 JSON_Object * json_object (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 225 JSON_Array * json_array (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 226 const char * json_string (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 227 double json_number (const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 228 int json_boolean(const JSON_Value *value);
AzureIoTClient 42:448eecc3676e 229
AzureIoTClient 42:448eecc3676e 230 #ifdef __cplusplus
AzureIoTClient 42:448eecc3676e 231 }
AzureIoTClient 42:448eecc3676e 232 #endif
AzureIoTClient 42:448eecc3676e 233
AzureIoTClient 42:448eecc3676e 234 #endif