/src/open5gs/lib/sbi/openapi/model/object.c
Line | Count | Source |
1 | | #include <stdlib.h> |
2 | | #include <string.h> |
3 | | #include <stdio.h> |
4 | | #include "object.h" |
5 | | |
6 | | OpenAPI_object_t *OpenAPI_object_create(void) |
7 | 272 | { |
8 | 272 | OpenAPI_object_t *object = ogs_calloc(1, sizeof(OpenAPI_object_t)); |
9 | | |
10 | 272 | return object; |
11 | 272 | } |
12 | | |
13 | | void OpenAPI_object_free(OpenAPI_object_t *object) |
14 | 272 | { |
15 | 272 | if (!object) { |
16 | 0 | return; |
17 | 0 | } |
18 | | |
19 | 272 | if (object->temporary) { |
20 | 272 | ogs_free(object->temporary); |
21 | 272 | object->temporary = NULL; |
22 | 272 | } |
23 | | |
24 | 272 | ogs_free (object); |
25 | 272 | } |
26 | | |
27 | | cJSON *OpenAPI_object_convertToJSON(OpenAPI_object_t *object) |
28 | 0 | { |
29 | 0 | if (!object) { |
30 | 0 | return NULL; |
31 | 0 | } |
32 | | |
33 | 0 | if (!object->temporary) { |
34 | 0 | return cJSON_Parse("{}"); |
35 | 0 | } |
36 | | |
37 | 0 | return cJSON_Parse(object->temporary); |
38 | 0 | } |
39 | | |
40 | | OpenAPI_object_t *OpenAPI_object_parseFromJSON(cJSON *json) |
41 | 272 | { |
42 | 272 | if (!json) { |
43 | 0 | goto end; |
44 | 0 | } |
45 | | |
46 | 272 | OpenAPI_object_t *object = OpenAPI_object_create(); |
47 | 272 | if (!object) { |
48 | 0 | goto end; |
49 | 0 | } |
50 | 272 | object->temporary = cJSON_Print(json); |
51 | 272 | return object; |
52 | | |
53 | 0 | end: |
54 | | return NULL; |
55 | 272 | } |