1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SEC_UTILS_JSON_H 17 #define SEC_UTILS_JSON_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 typedef void *JsonHandle; 27 28 JsonHandle CreateJson(const char *data); 29 void DestroyJson(JsonHandle handle); 30 31 int32_t GetJsonFieldInt(JsonHandle handle, const char *field); 32 uint32_t GetJsonFieldIntArray(JsonHandle handle, const char *field, int32_t *array, int32_t arrayLen); 33 const char *GetJsonFieldString(JsonHandle handle, const char *field); 34 JsonHandle GetJsonFieldJson(JsonHandle handle, const char *field); 35 36 JsonHandle GetJsonFieldJsonArray(JsonHandle handle, uint32_t num); 37 int32_t GetJsonFieldJsonArraySize(JsonHandle handle); 38 39 void AddFieldIntToJson(JsonHandle handle, const char *field, int32_t value); 40 void AddFieldIntArrayToJson(JsonHandle handle, const char *field, const int32_t *array, int32_t arrayLen); 41 void AddFieldBoolToJson(JsonHandle handle, const char *field, bool value); 42 void AddFieldStringToJson(JsonHandle handle, const char *field, const char *value); 43 void AddFieldJsonToJson(JsonHandle handle, const char *field, JsonHandle json); 44 45 char *ConvertJsonToString(JsonHandle handle); 46 47 bool CompareJsonData(JsonHandle handleA, JsonHandle handleB, bool caseSensitive); 48 49 #ifdef __cplusplus 50 } 51 #endif 52 53 #endif // SEC_UTILS_JSON_H