diff options
author | Alfredo Cardigliano <cardigliano@ntop.org> | 2022-04-26 12:25:34 +0200 |
---|---|---|
committer | Alfredo Cardigliano <cardigliano@ntop.org> | 2022-04-26 12:25:34 +0200 |
commit | e8d81123cca48cf1d36fd2dbb33068878c5eb8fa (patch) | |
tree | 0cf63c114fa94297514f3e6cb5ae1a0eda35ce20 | |
parent | d5005f584c4baf67e084e3bc8b052ca27004550e (diff) |
Add ndpi_json_string_escape to the API
-rw-r--r-- | src/include/ndpi_api.h.in | 7 | ||||
-rw-r--r-- | src/lib/ndpi_serializer.c | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 38cd7edc1..9401731fa 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -1541,6 +1541,13 @@ extern "C" { int ndpi_deserialize_clone_item(ndpi_deserializer *deserializer, ndpi_serializer *serializer); int ndpi_deserialize_clone_all(ndpi_deserializer *deserializer, ndpi_serializer *serializer); + /* + * Escape a string to be suitable for a JSON value, adding double quotes, and terminating the string with a null byte. + * It is recommended to provide a destination buffer (dst) which is as large as double the source buffer (src) at least. + * Upon successful return, these functions return the number of characters printed (excluding the null byte used to terminate the string). + */ + int ndpi_json_string_escape(const char *src, int src_len, char *dst, int dst_max_len); + /* Data analysis */ struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len); void ndpi_init_data_analysis(struct ndpi_analyze_struct *s, u_int16_t _max_series_len); diff --git a/src/lib/ndpi_serializer.c b/src/lib/ndpi_serializer.c index b9294fa72..d560e5b9e 100644 --- a/src/lib/ndpi_serializer.c +++ b/src/lib/ndpi_serializer.c @@ -87,7 +87,7 @@ static int ndpi_is_number(const char *str, u_int32_t str_len) { * It is recommended to provide a destination buffer (dst) which is as large as double the source buffer (src) at least. * Upon successful return, these functions return the number of characters printed (excluding the null byte used to terminate the string). */ -static int ndpi_json_string_escape(const char *src, int src_len, char *dst, int dst_max_len) { +int ndpi_json_string_escape(const char *src, int src_len, char *dst, int dst_max_len) { char c = 0; int i, j = 0; |