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 *DslmJsonHandle; 27 28 DslmJsonHandle DslmCreateJson(const char *data); 29 void DslmDestroyJson(DslmJsonHandle handle); 30 31 int32_t DslmGetJsonFieldInt(DslmJsonHandle handle, const char *field); 32 uint32_t DslmGetJsonFieldIntArray(DslmJsonHandle handle, const char *field, int32_t *array, int32_t arrayLen); 33 const char *DslmGetJsonFieldString(DslmJsonHandle handle, const char *field); 34 DslmJsonHandle DslmGetJsonFieldJson(DslmJsonHandle handle, const char *field); 35 36 DslmJsonHandle DslmGetJsonFieldJsonArray(DslmJsonHandle handle, uint32_t num); 37 int32_t DslmGetJsonFieldJsonArraySize(DslmJsonHandle handle); 38 39 void DslmAddFieldIntToJson(DslmJsonHandle handle, const char *field, int32_t value); 40 void DslmAddFieldIntArrayToJson(DslmJsonHandle handle, const char *field, const int32_t *array, int32_t arrayLen); 41 void DslmAddFieldBoolToJson(DslmJsonHandle handle, const char *field, bool value); 42 void DslmAddFieldStringToJson(DslmJsonHandle handle, const char *field, const char *value); 43 void DslmAddFieldJsonToJson(DslmJsonHandle handle, const char *field, DslmJsonHandle json); 44 45 char *DslmConvertJsonToString(DslmJsonHandle handle); 46 47 bool DslmCompareJsonData(DslmJsonHandle handleA, DslmJsonHandle handleB, bool caseSensitive); 48 49 #ifdef __cplusplus 50 } 51 #endif 52 53 #endif // SEC_UTILS_JSON_H