Commit Graph

15 Commits

Author SHA1 Message Date
Julian Bouzas
10f85549a4 spa-json: make sure we only add encoded string data
The spa_json_encode_string() API does not add a null terminator character. We
need to use the return value to know the size of the encoded string when adding
it to the builder.
2023-01-04 10:07:36 -05:00
Julian Bouzas
55691a0d81 spa-json: always advance to the end of the nested array/object
Fixes size issue with nested objects when they are the last property value of
the parent object.
2022-08-28 10:50:25 -04:00
George Kiagiadakis
11902666f9 wp_spa_json_to_string: add since marker 2022-06-27 17:28:36 +03:00
Julian Bouzas
b6e8e7e064 spa-json: encode string in wp_spa_json_new_string() 2022-06-27 10:07:16 +00:00
Julian Bouzas
0996f5a5ca spa-json: add wp_spa_json_to_string() API
Since the string length returned by wp_spa_pod_get_data() does not always match
the size of the actual json object because it is stored in contiguous memory, we
cannot always rely on that API to get the json string data.

The new wp_spa_pod_to_string() always allocates a new string with the same
length as the json size, guaranteeing that the string returned always represents
the json object, regardless of whether it is nested or not. It is always
recommented to use wp_spa_pod_to_string() unless you know what you are doing.
2022-06-27 10:07:16 +00:00
Julian Bouzas
a19c7f3d2f spa-json: only add the json data represented by its size
The data pointer of a WpSpaJson object can be bigger than the actual WpSpaJson
size. For example, this happens when iterating an array: instead of
re-allocating the nested data into a new region of memory, the iterator uses
the same region of memory as the parent, and just sets the pointer data and size
to the correct location when creating the nested WpSpaJson object.

This patch makes sure only the data represented by the size is added into the
builder when adding a json object, fixing issues that were happening before when
adding nested objects directly from a second WpSpaJson object.
2022-06-27 10:07:16 +00:00
Julian Bouzas
e9be326954 spa-json: add _new_from_stringn() API 2022-03-24 04:35:12 -04:00
Julian Bouzas
a68a7cec0e spa-json: allow parsing unquoted keys when getting object properties
Unquoted strings are used in wireplumber and pipewire configuration files.
2022-03-24 07:21:25 +00:00
George Kiagiadakis
8d4fe81ebd spa-json: allocate enough space for parsing strings without looping
The string size is always less or equal to the size of the token (len),
so by allocating len+1 bytes we have enough space to write the whole
token and the null byte, if needed.
2022-03-16 21:11:09 +02:00
Ashok Sidipotu
2248b8ec1f spa-json: Parse unquoted string literals
- pipewire supports parsing unquoted strings and they are used
  extensively in JSON .conf files.
- Extend this support into wireplumber, as it wants to use the pipewire
  like syntax in its JSON .conf files.
2022-03-16 20:51:49 +02:00
Julian Bouzas
2a6902a634 spa-json: fix format and remove unneded WP_API 2022-02-15 16:19:47 -05:00
Julian Bouzas
e429db7e8c spa-json: fix va_list APIs for different architectures
The va_list type might not always be a pointer in some architectures, so we
cannot guarantee it will be modified after using it for a second time in another
function. This fixes the issue by using macros so args does not get copied, and
always gets modified when using it more than once.
2022-02-09 07:59:59 -05:00
Julian Bouzas
585ad72c7c spa-json: add null character when finishing building json 2022-02-01 16:07:12 +00:00
Julian Bouzas
46ab414a04 spa-json: fix coverity scan issues 2022-01-25 21:18:16 -05:00
Julian Bouzas
4c1574117a spa-json: add new WpSpaJson API 2022-01-25 07:20:35 -05:00