Changes to enabled on-line compiler

Committer:
JMF
Date:
Wed May 30 20:59:51 2018 +0000
Revision:
0:082731ede69f
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:082731ede69f 1 /*
JMF 0:082731ede69f 2 * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
JMF 0:082731ede69f 3 *
JMF 0:082731ede69f 4 * Licensed under the Apache License, Version 2.0 (the "License").
JMF 0:082731ede69f 5 * You may not use this file except in compliance with the License.
JMF 0:082731ede69f 6 * A copy of the License is located at
JMF 0:082731ede69f 7 *
JMF 0:082731ede69f 8 * http://aws.amazon.com/apache2.0
JMF 0:082731ede69f 9 *
JMF 0:082731ede69f 10 * or in the "license" file accompanying this file. This file is distributed
JMF 0:082731ede69f 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
JMF 0:082731ede69f 12 * express or implied. See the License for the specific language governing
JMF 0:082731ede69f 13 * permissions and limitations under the License.
JMF 0:082731ede69f 14 */
JMF 0:082731ede69f 15
JMF 0:082731ede69f 16 /**
JMF 0:082731ede69f 17 * @file aws_json_utils.h
JMF 0:082731ede69f 18 * @brief Utilities for manipulating JSON
JMF 0:082731ede69f 19 *
JMF 0:082731ede69f 20 * json_utils provides JSON parsing utilities for use with the IoT SDK.
JMF 0:082731ede69f 21 * Underlying JSON parsing relies on the Jasmine JSON parser.
JMF 0:082731ede69f 22 *
JMF 0:082731ede69f 23 */
JMF 0:082731ede69f 24
JMF 0:082731ede69f 25 #ifndef AWS_IOT_SDK_SRC_JSON_UTILS_H_
JMF 0:082731ede69f 26 #define AWS_IOT_SDK_SRC_JSON_UTILS_H_
JMF 0:082731ede69f 27
JMF 0:082731ede69f 28 #ifdef __cplusplus
JMF 0:082731ede69f 29 extern "C" {
JMF 0:082731ede69f 30 #endif
JMF 0:082731ede69f 31
JMF 0:082731ede69f 32 #include <stdbool.h>
JMF 0:082731ede69f 33 #include <stdint.h>
JMF 0:082731ede69f 34
JMF 0:082731ede69f 35 #include "aws_iot_error.h"
JMF 0:082731ede69f 36 #include "jsmn.h"
JMF 0:082731ede69f 37
JMF 0:082731ede69f 38 // utility functions
JMF 0:082731ede69f 39 /**
JMF 0:082731ede69f 40 * @brief JSON Equality Check
JMF 0:082731ede69f 41 *
JMF 0:082731ede69f 42 * Given a token pointing to a particular JSON node and an
JMF 0:082731ede69f 43 * input string, check to see if the key is equal to the string.
JMF 0:082731ede69f 44 *
JMF 0:082731ede69f 45 * @param json json string
JMF 0:082731ede69f 46 * @param tok json token - pointer to key to test for equality
JMF 0:082731ede69f 47 * @param s input string for key to test equality
JMF 0:082731ede69f 48 *
JMF 0:082731ede69f 49 * @return 0 if equal, 1 otherwise
JMF 0:082731ede69f 50 */
JMF 0:082731ede69f 51 int8_t jsoneq(const char *json, jsmntok_t *tok, const char *s);
JMF 0:082731ede69f 52
JMF 0:082731ede69f 53 /**
JMF 0:082731ede69f 54 * @brief Parse a signed 32-bit integer value from a JSON node.
JMF 0:082731ede69f 55 *
JMF 0:082731ede69f 56 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 57 *
JMF 0:082731ede69f 58 * @param jsonString json string
JMF 0:082731ede69f 59 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 60 * @param i address of int32_t to be updated
JMF 0:082731ede69f 61 *
JMF 0:082731ede69f 62 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 63 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 64 */
JMF 0:082731ede69f 65 IoT_Error_t parseInteger32Value(int32_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 66
JMF 0:082731ede69f 67 /**
JMF 0:082731ede69f 68 * @brief Parse a signed 16-bit integer value from a JSON node.
JMF 0:082731ede69f 69 *
JMF 0:082731ede69f 70 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 71 *
JMF 0:082731ede69f 72 * @param jsonString json string
JMF 0:082731ede69f 73 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 74 * @param i address of int16_t to be updated
JMF 0:082731ede69f 75 *
JMF 0:082731ede69f 76 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 77 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 78 */
JMF 0:082731ede69f 79 IoT_Error_t parseInteger16Value(int16_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 80
JMF 0:082731ede69f 81 /**
JMF 0:082731ede69f 82 * @brief Parse a signed 8-bit integer value from a JSON node.
JMF 0:082731ede69f 83 *
JMF 0:082731ede69f 84 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 85 *
JMF 0:082731ede69f 86 * @param jsonString json string
JMF 0:082731ede69f 87 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 88 * @param i address of int8_t to be updated
JMF 0:082731ede69f 89 *
JMF 0:082731ede69f 90 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 91 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 92 */
JMF 0:082731ede69f 93 IoT_Error_t parseInteger8Value(int8_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 94
JMF 0:082731ede69f 95 /**
JMF 0:082731ede69f 96 * @brief Parse an unsigned 32-bit integer value from a JSON node.
JMF 0:082731ede69f 97 *
JMF 0:082731ede69f 98 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 99 *
JMF 0:082731ede69f 100 * @param jsonString json string
JMF 0:082731ede69f 101 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 102 * @param i address of uint32_t to be updated
JMF 0:082731ede69f 103 *
JMF 0:082731ede69f 104 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 105 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 106 */
JMF 0:082731ede69f 107 IoT_Error_t parseUnsignedInteger32Value(uint32_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 108
JMF 0:082731ede69f 109 /**
JMF 0:082731ede69f 110 * @brief Parse an unsigned 16-bit integer value from a JSON node.
JMF 0:082731ede69f 111 *
JMF 0:082731ede69f 112 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 113 *
JMF 0:082731ede69f 114 * @param jsonString json string
JMF 0:082731ede69f 115 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 116 * @param i address of uint16_t to be updated
JMF 0:082731ede69f 117 *
JMF 0:082731ede69f 118 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 119 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 120 */
JMF 0:082731ede69f 121 IoT_Error_t parseUnsignedInteger16Value(uint16_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 122
JMF 0:082731ede69f 123 /**
JMF 0:082731ede69f 124 * @brief Parse an unsigned 8-bit integer value from a JSON node.
JMF 0:082731ede69f 125 *
JMF 0:082731ede69f 126 * Given a JSON node parse the integer value from the value.
JMF 0:082731ede69f 127 *
JMF 0:082731ede69f 128 * @param jsonString json string
JMF 0:082731ede69f 129 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 130 * @param i address of uint8_t to be updated
JMF 0:082731ede69f 131 *
JMF 0:082731ede69f 132 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 133 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 134 */
JMF 0:082731ede69f 135 IoT_Error_t parseUnsignedInteger8Value(uint8_t *i, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 136
JMF 0:082731ede69f 137 /**
JMF 0:082731ede69f 138 * @brief Parse a float value from a JSON node.
JMF 0:082731ede69f 139 *
JMF 0:082731ede69f 140 * Given a JSON node parse the float value from the value.
JMF 0:082731ede69f 141 *
JMF 0:082731ede69f 142 * @param jsonString json string
JMF 0:082731ede69f 143 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 144 * @param f address of float to be updated
JMF 0:082731ede69f 145 *
JMF 0:082731ede69f 146 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 147 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 148 */
JMF 0:082731ede69f 149 IoT_Error_t parseFloatValue(float *f, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 150
JMF 0:082731ede69f 151 /**
JMF 0:082731ede69f 152 * @brief Parse a double value from a JSON node.
JMF 0:082731ede69f 153 *
JMF 0:082731ede69f 154 * Given a JSON node parse the double value from the value.
JMF 0:082731ede69f 155 *
JMF 0:082731ede69f 156 * @param jsonString json string
JMF 0:082731ede69f 157 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 158 * @param d address of double to be updated
JMF 0:082731ede69f 159 *
JMF 0:082731ede69f 160 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 161 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 162 */
JMF 0:082731ede69f 163 IoT_Error_t parseDoubleValue(double *d, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 164
JMF 0:082731ede69f 165 /**
JMF 0:082731ede69f 166 * @brief Parse a boolean value from a JSON node.
JMF 0:082731ede69f 167 *
JMF 0:082731ede69f 168 * Given a JSON node parse the boolean value from the value.
JMF 0:082731ede69f 169 *
JMF 0:082731ede69f 170 * @param jsonString json string
JMF 0:082731ede69f 171 * @param tok json token - pointer to JSON node
JMF 0:082731ede69f 172 * @param b address of boolean to be updated
JMF 0:082731ede69f 173 *
JMF 0:082731ede69f 174 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 175 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 176 */
JMF 0:082731ede69f 177 IoT_Error_t parseBooleanValue(bool *b, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 178
JMF 0:082731ede69f 179 /**
JMF 0:082731ede69f 180 * @brief Parse a string value from a JSON node.
JMF 0:082731ede69f 181 *
JMF 0:082731ede69f 182 * Given a JSON node parse the string value from the value.
JMF 0:082731ede69f 183 *
JMF 0:082731ede69f 184 * @param buf address of string to be updated
JMF 0:082731ede69f 185 * @param bufLen length of buf in bytes
JMF 0:082731ede69f 186 * @param jsonString json string
JMF 0:082731ede69f 187 * @param token json token - pointer to JSON node
JMF 0:082731ede69f 188 *
JMF 0:082731ede69f 189 * @return AWS_SUCCESS - success
JMF 0:082731ede69f 190 * @return JSON_PARSE_ERROR - error parsing value
JMF 0:082731ede69f 191 */
JMF 0:082731ede69f 192 IoT_Error_t parseStringValue(char *buf, size_t bufLen, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 193
JMF 0:082731ede69f 194 /**
JMF 0:082731ede69f 195 * @brief Find the JSON node associated with the given key in the given object.
JMF 0:082731ede69f 196 *
JMF 0:082731ede69f 197 * Given a JSON node parse the string value from the value.
JMF 0:082731ede69f 198 *
JMF 0:082731ede69f 199 * @param key json key
JMF 0:082731ede69f 200 * @param token json token - pointer to JSON node
JMF 0:082731ede69f 201 * @param jsonString json string
JMF 0:082731ede69f 202 *
JMF 0:082731ede69f 203 * @return pointer to found property value
JMF 0:082731ede69f 204 * @return NULL - not found
JMF 0:082731ede69f 205 */
JMF 0:082731ede69f 206 jsmntok_t *findToken(const char *key, const char *jsonString, jsmntok_t *token);
JMF 0:082731ede69f 207
JMF 0:082731ede69f 208 #ifdef __cplusplus
JMF 0:082731ede69f 209 }
JMF 0:082731ede69f 210 #endif
JMF 0:082731ede69f 211
JMF 0:082731ede69f 212 #endif /* AWS_IOT_SDK_SRC_JSON_UTILS_H_ */