FreeRDP
Loading...
Searching...
No Matches
WinPR JSON wrapper

Wrapper around cJSON, JSONC or jansson libraries. More...

Typedefs

typedef void WINPR_JSON
 

Functions

WINPR_API int WINPR_JSON_version (char *buffer, size_t len)
 Get the library version string.
 
WINPR_API void WINPR_JSON_Delete (WINPR_JSON *item)
 Delete a WinPR JSON wrapper object.
 
WINPR_API WINPR_JSON * WINPR_JSON_Parse (const char *value)
 Parse a '\0' terminated JSON string.
 
WINPR_API WINPR_JSON * WINPR_JSON_ParseWithLength (const char *value, size_t buffer_length)
 Parse a JSON string.
 
WINPR_API WINPR_JSON * WINPR_JSON_ParseFromFile (const char *filename)
 Parse a JSON string read from a file filename.
 
WINPR_API WINPR_JSON * WINPR_JSON_ParseFromFileFP (FILE *fp)
 Parse a JSON string read from a FILE.
 
WINPR_API size_t WINPR_JSON_GetArraySize (const WINPR_JSON *array)
 Get the number of arrayitems from an array.
 
WINPR_API WINPR_JSON * WINPR_JSON_GetArrayItem (const WINPR_JSON *array, size_t index)
 Return a pointer to an item in the array.
 
WINPR_API WINPR_JSON * WINPR_JSON_GetObjectItem (const WINPR_JSON *object, const char *string)
 Return a pointer to an JSON object item.
 
WINPR_API WINPR_JSON * WINPR_JSON_GetObjectItemCaseSensitive (const WINPR_JSON *object, const char *string)
 Same as WINPR_JSON_GetObjectItem but with case sensitive matching.
 
WINPR_API BOOL WINPR_JSON_HasObjectItem (const WINPR_JSON *object, const char *string)
 Check if JSON has an object matching the name.
 
WINPR_API const char * WINPR_JSON_GetErrorPtr (void)
 Return an error string.
 
WINPR_API const char * WINPR_JSON_GetStringValue (WINPR_JSON *item)
 Return the String value of a JSON item.
 
WINPR_API double WINPR_JSON_GetNumberValue (const WINPR_JSON *item)
 Return the Number value of a JSON item.
 
WINPR_API BOOL WINPR_JSON_IsInvalid (const WINPR_JSON *item)
 Check if JSON item is valid.
 
WINPR_API BOOL WINPR_JSON_IsFalse (const WINPR_JSON *item)
 Check if JSON item is BOOL value False.
 
WINPR_API BOOL WINPR_JSON_IsTrue (const WINPR_JSON *item)
 Check if JSON item is BOOL value True.
 
WINPR_API BOOL WINPR_JSON_IsBool (const WINPR_JSON *item)
 Check if JSON item is of type BOOL.
 
WINPR_API BOOL WINPR_JSON_IsNull (const WINPR_JSON *item)
 Check if JSON item is Null.
 
WINPR_API BOOL WINPR_JSON_IsNumber (const WINPR_JSON *item)
 Check if JSON item is of type Number.
 
WINPR_API BOOL WINPR_JSON_IsString (const WINPR_JSON *item)
 Check if JSON item is of type String.
 
WINPR_API BOOL WINPR_JSON_IsArray (const WINPR_JSON *item)
 Check if JSON item is of type Array.
 
WINPR_API BOOL WINPR_JSON_IsObject (const WINPR_JSON *item)
 Check if JSON item is of type Object.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateNull (void)
 WINPR_JSON_CreateNull.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateTrue (void)
 WINPR_JSON_CreateTrue.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateFalse (void)
 WINPR_JSON_CreateFalse.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateBool (BOOL boolean)
 WINPR_JSON_CreateBool.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateNumber (double num)
 WINPR_JSON_CreateNumber.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateString (const char *string)
 WINPR_JSON_CreateString.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateArray (void)
 WINPR_JSON_CreateArray.
 
WINPR_API WINPR_JSON * WINPR_JSON_CreateObject (void)
 WINPR_JSON_CreateObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddNullToObject (WINPR_JSON *object, const char *name)
 WINPR_JSON_AddNullToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddTrueToObject (WINPR_JSON *object, const char *name)
 WINPR_JSON_AddTrueToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddFalseToObject (WINPR_JSON *object, const char *name)
 WINPR_JSON_AddFalseToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddBoolToObject (WINPR_JSON *object, const char *name, BOOL boolean)
 WINPR_JSON_AddBoolToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddNumberToObject (WINPR_JSON *object, const char *name, double number)
 WINPR_JSON_AddNumberToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddStringToObject (WINPR_JSON *object, const char *name, const char *string)
 WINPR_JSON_AddStringToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddObjectToObject (WINPR_JSON *object, const char *name)
 WINPR_JSON_AddObjectToObject.
 
WINPR_API WINPR_JSON * WINPR_JSON_AddArrayToObject (WINPR_JSON *object, const char *name)
 WINPR_JSON_AddArrayToObject.
 
WINPR_API BOOL WINPR_JSON_AddItemToArray (WINPR_JSON *array, WINPR_JSON *item)
 Add an item to an existing array.
 
WINPR_API char * WINPR_JSON_Print (WINPR_JSON *item)
 Serialize a JSON instance to string for minimal size without formatting see WINPR_JSON_PrintUnformatted.
 
WINPR_API char * WINPR_JSON_PrintUnformatted (WINPR_JSON *item)
 Serialize a JSON instance to string without formatting for human readable formatted output see WINPR_JSON_Print.
 

Detailed Description

Wrapper around cJSON, JSONC or jansson libraries.

FreeRDP: A Remote Desktop Protocol Implementation JSON parser wrapper

Copyright 2024 Armin Novak anova.nosp@m.k@th.nosp@m.incas.nosp@m.t.co.nosp@m.m Copyright 2024 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Since
version 3.6.0

Typedef Documentation

◆ WINPR_JSON

typedef void WINPR_JSON

Definition at line 39 of file json.h.

Function Documentation

◆ WINPR_JSON_AddArrayToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddArrayToObject ( WINPR_JSON *  object,
const char *  name 
)

WINPR_JSON_AddArrayToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 284 of file c-json.c.

285{
286 return cJSON_AddArrayToObject((cJSON*)object, name);
287}

◆ WINPR_JSON_AddBoolToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddBoolToObject ( WINPR_JSON *  object,
const char *  name,
BOOL  boolean 
)

WINPR_JSON_AddBoolToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 252 of file c-json.c.

253{
254 return cJSON_AddBoolToObject((cJSON*)object, name, boolean);
255}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_AddFalseToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddFalseToObject ( WINPR_JSON *  object,
const char *  name 
)

WINPR_JSON_AddFalseToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 247 of file c-json.c.

248{
249 return cJSON_AddFalseToObject((cJSON*)object, name);
250}

◆ WINPR_JSON_AddItemToArray()

WINPR_API BOOL WINPR_JSON_AddItemToArray ( WINPR_JSON *  array,
WINPR_JSON *  item 
)

Add an item to an existing array.

Parameters
arrayAn array to add to, must not be NULL
itemAn item to add, must not be NULL
Returns
TRUE for success, FALSE for failure
Since
version 3.7.0

Definition at line 272 of file c-json.c.

273{
274#if defined(USE_CJSON_COMPAT)
275 if ((array == NULL) || (item == NULL))
276 return FALSE;
277 cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
278 return TRUE;
279#else
280 return cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
281#endif
282}

◆ WINPR_JSON_AddNullToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddNullToObject ( WINPR_JSON *  object,
const char *  name 
)

WINPR_JSON_AddNullToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 237 of file c-json.c.

238{
239 return cJSON_AddNullToObject((cJSON*)object, name);
240}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_AddNumberToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddNumberToObject ( WINPR_JSON *  object,
const char *  name,
double  number 
)

WINPR_JSON_AddNumberToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 257 of file c-json.c.

258{
259 return cJSON_AddNumberToObject((cJSON*)object, name, number);
260}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_AddObjectToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddObjectToObject ( WINPR_JSON *  object,
const char *  name 
)

WINPR_JSON_AddObjectToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 267 of file c-json.c.

268{
269 return cJSON_AddObjectToObject((cJSON*)object, name);
270}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_AddStringToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddStringToObject ( WINPR_JSON *  object,
const char *  name,
const char *  string 
)

WINPR_JSON_AddStringToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 262 of file c-json.c.

263{
264 return cJSON_AddStringToObject((cJSON*)object, name, string);
265}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_AddTrueToObject()

WINPR_API WINPR_JSON * WINPR_JSON_AddTrueToObject ( WINPR_JSON *  object,
const char *  name 
)

WINPR_JSON_AddTrueToObject.

Parameters
objectThe JSON object the new item is added to
nameThe name of the object
Returns
the new JSON item added
Since
version 3.6.0

Definition at line 242 of file c-json.c.

243{
244 return cJSON_AddTrueToObject((cJSON*)object, name);
245}

◆ WINPR_JSON_CreateArray()

WINPR_API WINPR_JSON * WINPR_JSON_CreateArray ( void  )

WINPR_JSON_CreateArray.

Returns
a new JSON item of type array, empty
Since
version 3.6.0

Definition at line 227 of file c-json.c.

228{
229 return cJSON_CreateArray();
230}

◆ WINPR_JSON_CreateBool()

WINPR_API WINPR_JSON * WINPR_JSON_CreateBool ( BOOL  boolean)

WINPR_JSON_CreateBool.

Parameters
booleanthe value the JSON item should have
Returns
a new JSON item of type Bool
Since
version 3.6.0

Definition at line 212 of file c-json.c.

213{
214 return cJSON_CreateBool(boolean);
215}

◆ WINPR_JSON_CreateFalse()

WINPR_API WINPR_JSON * WINPR_JSON_CreateFalse ( void  )

WINPR_JSON_CreateFalse.

Returns
a new JSON item of type Bool and value False
Since
version 3.6.0

Definition at line 207 of file c-json.c.

208{
209 return cJSON_CreateFalse();
210}

◆ WINPR_JSON_CreateNull()

WINPR_API WINPR_JSON * WINPR_JSON_CreateNull ( void  )

WINPR_JSON_CreateNull.

Returns
a new JSON item of type and value Null
Since
version 3.6.0

Definition at line 197 of file c-json.c.

198{
199 return cJSON_CreateNull();
200}

◆ WINPR_JSON_CreateNumber()

WINPR_API WINPR_JSON * WINPR_JSON_CreateNumber ( double  num)

WINPR_JSON_CreateNumber.

Parameters
numthe number value of the new item
Returns
a new JSON item of type Number
Since
version 3.6.0

Definition at line 217 of file c-json.c.

218{
219 return cJSON_CreateNumber(num);
220}

◆ WINPR_JSON_CreateObject()

WINPR_API WINPR_JSON * WINPR_JSON_CreateObject ( void  )

WINPR_JSON_CreateObject.

Returns
a new JSON item of type Object
Since
version 3.6.0

Definition at line 232 of file c-json.c.

233{
234 return cJSON_CreateObject();
235}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_CreateString()

WINPR_API WINPR_JSON * WINPR_JSON_CreateString ( const char *  string)

WINPR_JSON_CreateString.

Parameters
stringThe string value of the new item
Returns
a new JSON item of type String
Since
version 3.6.0

Definition at line 222 of file c-json.c.

223{
224 return cJSON_CreateString(string);
225}

◆ WINPR_JSON_CreateTrue()

WINPR_API WINPR_JSON * WINPR_JSON_CreateTrue ( void  )

WINPR_JSON_CreateTrue.

Returns
a new JSON item of type Bool and value True
Since
version 3.6.0

Definition at line 202 of file c-json.c.

203{
204 return cJSON_CreateTrue();
205}

◆ WINPR_JSON_Delete()

WINPR_API void WINPR_JSON_Delete ( WINPR_JSON *  item)

Delete a WinPR JSON wrapper object.

Parameters
itemThe instance to delete
Since
version 3.6.0

Definition at line 103 of file c-json.c.

104{
105 cJSON_Delete((cJSON*)item);
106}

Referenced by freerdp_settings_deserialize(), and freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_GetArrayItem()

WINPR_API WINPR_JSON * WINPR_JSON_GetArrayItem ( const WINPR_JSON *  array,
size_t  index 
)

Return a pointer to an item in the array.

Parameters
arraythe JSON instance to query
indexThe index of the array item
Returns
A pointer to the array item or NULL if failed
Since
version 3.6.0

Definition at line 108 of file c-json.c.

109{
110 WINPR_ASSERT(index <= INT_MAX);
111 return cJSON_GetArrayItem((const cJSON*)array, (INT)index);
112}

◆ WINPR_JSON_GetArraySize()

WINPR_API size_t WINPR_JSON_GetArraySize ( const WINPR_JSON *  array)

Get the number of arrayitems from an array.

Parameters
arraythe JSON instance to query
Returns
number of array items
Since
version 3.6.0

Definition at line 114 of file c-json.c.

115{
116 const int rc = cJSON_GetArraySize((const cJSON*)array);
117 if (rc <= 0)
118 return 0;
119 return (size_t)rc;
120}

◆ WINPR_JSON_GetErrorPtr()

WINPR_API const char * WINPR_JSON_GetErrorPtr ( void  )

Return an error string.

Returns
A string describing the last error that occurred or NULL
Since
version 3.6.0

Definition at line 137 of file c-json.c.

138{
139 return cJSON_GetErrorPtr();
140}

◆ WINPR_JSON_GetNumberValue()

WINPR_API double WINPR_JSON_GetNumberValue ( const WINPR_JSON *  item)

Return the Number value of a JSON item.

Parameters
itemthe JSON item to query
Returns
The Number value or NaN if failed
Since
version 3.6.0

Definition at line 147 of file c-json.c.

148{
149 return cJSON_GetNumberValue((const cJSON*)item);
150}

◆ WINPR_JSON_GetObjectItem()

WINPR_API WINPR_JSON * WINPR_JSON_GetObjectItem ( const WINPR_JSON *  object,
const char *  string 
)

Return a pointer to an JSON object item.

Parameters
objectthe JSON object
stringthe name of the object (case is ignored)
Returns
A pointer to the object identified by string or NULL
Since
version 3.6.0

Definition at line 122 of file c-json.c.

123{
124 return cJSON_GetObjectItem((const cJSON*)object, string);
125}

◆ WINPR_JSON_GetObjectItemCaseSensitive()

WINPR_API WINPR_JSON * WINPR_JSON_GetObjectItemCaseSensitive ( const WINPR_JSON *  object,
const char *  string 
)

Same as WINPR_JSON_GetObjectItem but with case sensitive matching.

Parameters
objectthe JSON instance to query
stringthe name of the object
Returns
A pointer to the object identified by string or NULL
Since
version 3.6.0

Definition at line 127 of file c-json.c.

128{
129 return cJSON_GetObjectItemCaseSensitive((const cJSON*)object, string);
130}

Referenced by freerdp_settings_deserialize().

Here is the caller graph for this function:

◆ WINPR_JSON_GetStringValue()

WINPR_API const char * WINPR_JSON_GetStringValue ( WINPR_JSON *  item)

Return the String value of a JSON item.

Parameters
itemthe JSON item to query
Returns
The string value or NULL if failed
Since
version 3.6.0

Definition at line 142 of file c-json.c.

143{
144 return cJSON_GetStringValue((cJSON*)item);
145}

Referenced by freerdp_settings_deserialize().

Here is the caller graph for this function:

◆ WINPR_JSON_HasObjectItem()

WINPR_API BOOL WINPR_JSON_HasObjectItem ( const WINPR_JSON *  object,
const char *  string 
)

Check if JSON has an object matching the name.

Parameters
objectthe JSON instance
stringthe name of the object
Returns
TRUE if found, FALSE otherwise
Since
version 3.6.0

Definition at line 132 of file c-json.c.

133{
134 return cJSON_HasObjectItem((const cJSON*)object, string);
135}

◆ WINPR_JSON_IsArray()

WINPR_API BOOL WINPR_JSON_IsArray ( const WINPR_JSON *  item)

Check if JSON item is of type Array.

Parameters
itemthe JSON item to query
Returns
TRUE if the type is Array, FALSE otherwise
Since
version 3.6.0

Definition at line 187 of file c-json.c.

188{
189 return cJSON_IsArray((const cJSON*)item);
190}

Referenced by WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsBool()

WINPR_API BOOL WINPR_JSON_IsBool ( const WINPR_JSON *  item)

Check if JSON item is of type BOOL.

Parameters
itemthe JSON item to query
Returns
TRUE if the type is BOOL, FALSE otherwise
Since
version 3.6.0

Definition at line 167 of file c-json.c.

168{
169 return cJSON_IsBool((const cJSON*)item);
170}

Referenced by freerdp_settings_deserialize(), WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsFalse()

WINPR_API BOOL WINPR_JSON_IsFalse ( const WINPR_JSON *  item)

Check if JSON item is BOOL value False.

Parameters
itemthe JSON item to query
Returns
TRUE if False, FALSE otherwise
Since
version 3.6.0

Definition at line 157 of file c-json.c.

158{
159 return cJSON_IsFalse((const cJSON*)item);
160}

◆ WINPR_JSON_IsInvalid()

WINPR_API BOOL WINPR_JSON_IsInvalid ( const WINPR_JSON *  item)

Check if JSON item is valid.

Parameters
itemthe JSON item to query
Returns
TRUE if valid, FALSE otherwise
Since
version 3.6.0

Definition at line 152 of file c-json.c.

153{
154 return cJSON_IsInvalid((const cJSON*)item);
155}

References WINPR_JSON_IsArray(), WINPR_JSON_IsBool(), WINPR_JSON_IsNull(), WINPR_JSON_IsNumber(), WINPR_JSON_IsObject(), and WINPR_JSON_IsString().

Here is the call graph for this function:

◆ WINPR_JSON_IsNull()

WINPR_API BOOL WINPR_JSON_IsNull ( const WINPR_JSON *  item)

Check if JSON item is Null.

Parameters
itemthe JSON item to query
Returns
TRUE if it is Null, FALSE otherwise
Since
version 3.6.0

Definition at line 172 of file c-json.c.

173{
174 return cJSON_IsNull((const cJSON*)item);
175}

Referenced by freerdp_settings_deserialize(), WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsNumber()

WINPR_API BOOL WINPR_JSON_IsNumber ( const WINPR_JSON *  item)

Check if JSON item is of type Number.

Parameters
itemthe JSON item to query
Returns
TRUE if the type is Number, FALSE otherwise
Since
version 3.6.0

Definition at line 177 of file c-json.c.

178{
179 return cJSON_IsNumber((const cJSON*)item);
180}

Referenced by WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsObject()

WINPR_API BOOL WINPR_JSON_IsObject ( const WINPR_JSON *  item)

Check if JSON item is of type Object.

Parameters
itemthe JSON item to query
Returns
TRUE if the type is Object, FALSE otherwise
Since
version 3.6.0

Definition at line 192 of file c-json.c.

193{
194 return cJSON_IsObject((const cJSON*)item);
195}

Referenced by WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsString()

WINPR_API BOOL WINPR_JSON_IsString ( const WINPR_JSON *  item)

Check if JSON item is of type String.

Parameters
itemthe JSON item to query
Returns
TRUE if the type is String, FALSE otherwise
Since
version 3.6.0

Definition at line 182 of file c-json.c.

183{
184 return cJSON_IsString((const cJSON*)item);
185}

Referenced by freerdp_settings_deserialize(), WINPR_JSON_IsInvalid(), and WINPR_JSON_IsInvalid().

Here is the caller graph for this function:

◆ WINPR_JSON_IsTrue()

WINPR_API BOOL WINPR_JSON_IsTrue ( const WINPR_JSON *  item)

Check if JSON item is BOOL value True.

Parameters
itemthe JSON item to query
Returns
TRUE if True, FALSE otherwise
Since
version 3.6.0

Definition at line 162 of file c-json.c.

163{
164 return cJSON_IsTrue((const cJSON*)item);
165}

Referenced by freerdp_settings_deserialize().

Here is the caller graph for this function:

◆ WINPR_JSON_Parse()

WINPR_API WINPR_JSON * WINPR_JSON_Parse ( const char *  value)

Parse a '\0' terminated JSON string.

Parameters
valueA '\0' terminated JSON string
Returns
A WinPR JSON wrapper object holding the parsed string or NULL if failed
Since
version 3.6.0

Definition at line 93 of file c-json.c.

94{
95 return cJSON_Parse(value);
96}

◆ WINPR_JSON_ParseFromFile()

WINPR_API WINPR_JSON * WINPR_JSON_ParseFromFile ( const char *  filename)

Parse a JSON string read from a file filename.

Parameters
filenamethe name of the file to read from
Returns
A WinPR JSON wrapper object holding the parsed string or NULL if failed
Since
version 3.16.0

FreeRDP: A Remote Desktop Protocol Implementation JSON parser wrapper

Copyright 2024 Armin Novak anova.nosp@m.k@th.nosp@m.incas.nosp@m.t.co.nosp@m.m Copyright 2024 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 27 of file json.c.

28{
29 FILE* fp = winpr_fopen(filename, "r");
30 if (!fp)
31 return NULL;
32 WINPR_JSON* json = WINPR_JSON_ParseFromFileFP(fp);
33 (void)fclose(fp);
34 return json;
35}
WINPR_JSON * WINPR_JSON_ParseFromFileFP(FILE *fp)
Parse a JSON string read from a FILE.
Definition json.c:37

References WINPR_JSON_ParseFromFileFP().

Here is the call graph for this function:

◆ WINPR_JSON_ParseFromFileFP()

WINPR_API WINPR_JSON * WINPR_JSON_ParseFromFileFP ( FILE *  fp)

Parse a JSON string read from a FILE.

Parameters
fpa FILE pointer to read from.
Returns
A WinPR JSON wrapper object holding the parsed string or NULL if failed
Since
version 3.16.0

Definition at line 37 of file json.c.

38{
39 if (!fp)
40 return NULL;
41
42 if (fseek(fp, 0, SEEK_END) != 0)
43 return NULL;
44
45 const INT64 size = _ftelli64(fp);
46 if (size < 0)
47 return NULL;
48
49 if (fseek(fp, 0, SEEK_SET) != 0)
50 return NULL;
51
52 const size_t usize = WINPR_ASSERTING_INT_CAST(size_t, size);
53 char* str = calloc(usize + 1, sizeof(char));
54 if (!str)
55 return NULL;
56
57 WINPR_JSON* json = NULL;
58 const size_t s = fread(str, sizeof(char), usize, fp);
59 if (s == usize)
60 json = WINPR_JSON_ParseWithLength(str, usize);
61 free(str);
62 return json;
63}
WINPR_API WINPR_JSON * WINPR_JSON_ParseWithLength(const char *value, size_t buffer_length)
Parse a JSON string.
Definition c-json.c:98

References WINPR_JSON_ParseWithLength().

Referenced by WINPR_JSON_ParseFromFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WINPR_JSON_ParseWithLength()

WINPR_API WINPR_JSON * WINPR_JSON_ParseWithLength ( const char *  value,
size_t  buffer_length 
)

Parse a JSON string.

Parameters
valueA JSON string
buffer_lengthThe length in bytes of the JSON string
Returns
A WinPR JSON wrapper object holding the parsed string or NULL if failed
Since
version 3.6.0

Definition at line 98 of file c-json.c.

99{
100 return cJSON_ParseWithLength(value, buffer_length);
101}

Referenced by freerdp_settings_deserialize(), and WINPR_JSON_ParseFromFileFP().

Here is the caller graph for this function:

◆ WINPR_JSON_Print()

WINPR_API char * WINPR_JSON_Print ( WINPR_JSON *  item)

Serialize a JSON instance to string for minimal size without formatting see WINPR_JSON_PrintUnformatted.

Parameters
itemThe JSON instance to serialize
Returns
A string representation of the JSON instance or NULL
Since
version 3.6.0

Definition at line 289 of file c-json.c.

290{
291 return cJSON_Print((const cJSON*)item);
292}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_PrintUnformatted()

WINPR_API char * WINPR_JSON_PrintUnformatted ( WINPR_JSON *  item)

Serialize a JSON instance to string without formatting for human readable formatted output see WINPR_JSON_Print.

Parameters
itemThe JSON instance to serialize
Returns
A string representation of the JSON instance or NULL
Since
version 3.6.0

Definition at line 294 of file c-json.c.

295{
296 return cJSON_PrintUnformatted((const cJSON*)item);
297}

Referenced by freerdp_settings_serialize().

Here is the caller graph for this function:

◆ WINPR_JSON_version()

WINPR_API int WINPR_JSON_version ( char *  buffer,
size_t  len 
)

Get the library version string.

Parameters
buffera string buffer to hold the version string
lenthe length of the buffer
Returns
length of the version string in bytes or negative for error
Since
version 3.6.0

FreeRDP: A Remote Desktop Protocol Implementation JSON parser wrapper

Copyright 2024 Armin Novak anova.nosp@m.k@th.nosp@m.incas.nosp@m.t.co.nosp@m.m Copyright 2024 Thincast Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 88 of file c-json.c.

89{
90 return _snprintf(buffer, len, "cJSON %s", cJSON_Version());
91}