Skip to content

Commit b768bc4

Browse files
committed
add helpers to retrieve URI encoded data (likely binary) from json objects
1 parent 03acc60 commit b768bc4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

daemon/json-helpers.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ str *json_object_get_str(JsonObject* json, const char *key) {
4646
return out;
4747
}
4848

49+
str *json_object_get_str_uri_enc(JsonObject *json, const char *key) {
50+
str *strval = NULL;
51+
strval = json_object_get_str(json, key);
52+
if (!strval)
53+
return NULL;
54+
return str_uri_decode_len(strval->s, strval->len);
55+
}
56+
4957
str *json_array_get_str(JsonArray *json, unsigned idx) {
5058
const gchar *strval;
5159
str *out = NULL;

include/json-helpers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ str *json_reader_get_str(JsonReader *reader, const char *key);
2323
*/
2424
str *json_object_get_str(JsonObject *json, const char *key);
2525

26+
/**
27+
* Retrieve a string value from a JSON object, using the JsonObject API, according to a key, decoding the
28+
* URI encoded value. The resulting buffer might contain NULL values.
29+
* @param json glib JsonObject from which to get the string
30+
* @param key name of the string value to retrieve
31+
* @return `str` string created from the string value, or `NULL` if no such value was found,
32+
* the reader is in an error state or not pointing to a JSON object. Release using `free()`.
33+
*/
34+
str *json_object_get_str_uri_enc(JsonObject *json, const char *key);
35+
2636
/**
2737
* Retrieve a string value from a JSON list, using the JsonArray API, according to a key.
2838
* @param json glib JsonArray from which to get the string

0 commit comments

Comments
 (0)