test

Committer:
peyo
Date:
Wed Apr 12 14:09:46 2017 +0200
Revision:
1:3f75eb8d46f4
Parent:
0:cd5404401c2f
add main

Who changed what in which revision?

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