summaryrefslogtreecommitdiffstats
path: root/libnetdata/buffer
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 12:07:37 +0000
commitb485aab7e71c1625cfc27e0f92c9509f42378458 (patch)
treeae9abe108601079d1679194de237c9a435ae5b55 /libnetdata/buffer
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-upstream.tar.xz
netdata-upstream.zip
Adding upstream version 1.45.3+dfsg.upstream/1.45.3+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--libnetdata/buffer/Makefile.am8
-rw-r--r--libnetdata/buffer/README.md20
-rw-r--r--libnetdata/buffered_reader/Makefile.am8
-rw-r--r--src/go/collectors/go.d.plugin/modules/docker_engine/testdata/non-docker-engine.txt (renamed from libnetdata/buffered_reader/README.md)0
-rw-r--r--src/libnetdata/buffer/buffer.c (renamed from libnetdata/buffer/buffer.c)35
-rw-r--r--src/libnetdata/buffer/buffer.h (renamed from libnetdata/buffer/buffer.h)91
-rw-r--r--src/libnetdata/buffered_reader/buffered_reader.c (renamed from libnetdata/buffered_reader/buffered_reader.c)0
-rw-r--r--src/libnetdata/buffered_reader/buffered_reader.h (renamed from libnetdata/buffered_reader/buffered_reader.h)0
8 files changed, 62 insertions, 100 deletions
diff --git a/libnetdata/buffer/Makefile.am b/libnetdata/buffer/Makefile.am
deleted file mode 100644
index 161784b8f..000000000
--- a/libnetdata/buffer/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-or-later
-
-AUTOMAKE_OPTIONS = subdir-objects
-MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
-
-dist_noinst_DATA = \
- README.md \
- $(NULL)
diff --git a/libnetdata/buffer/README.md b/libnetdata/buffer/README.md
deleted file mode 100644
index 2937ae141..000000000
--- a/libnetdata/buffer/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-<!--
-title: "BUFFER"
-custom_edit_url: https://github.com/netdata/netdata/edit/master/libnetdata/buffer/README.md
-sidebar_label: "BUFFER library"
-learn_status: "Published"
-learn_topic_type: "Tasks"
-learn_rel_path: "Developers/libnetdata"
--->
-
-# BUFFER
-
-`BUFFER` is a convenience library for working with strings in `C`.
-Mainly, `BUFFER`s eliminate the need for tracking the string length, thus providing
-a safe alternative for string operations.
-
-Also, they are super fast in printing and appending data to the string and its `buffer_strlen()`
-is just a lookup (it does not traverse the string).
-
-Netdata uses `BUFFER`s for preparing web responses and buffering data to be sent upstream or
-to external databases.
diff --git a/libnetdata/buffered_reader/Makefile.am b/libnetdata/buffered_reader/Makefile.am
deleted file mode 100644
index 161784b8f..000000000
--- a/libnetdata/buffered_reader/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-or-later
-
-AUTOMAKE_OPTIONS = subdir-objects
-MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
-
-dist_noinst_DATA = \
- README.md \
- $(NULL)
diff --git a/libnetdata/buffered_reader/README.md b/src/go/collectors/go.d.plugin/modules/docker_engine/testdata/non-docker-engine.txt
index e69de29bb..e69de29bb 100644
--- a/libnetdata/buffered_reader/README.md
+++ b/src/go/collectors/go.d.plugin/modules/docker_engine/testdata/non-docker-engine.txt
diff --git a/libnetdata/buffer/buffer.c b/src/libnetdata/buffer/buffer.c
index 64f9cce47..119216dd9 100644
--- a/libnetdata/buffer/buffer.c
+++ b/src/libnetdata/buffer/buffer.c
@@ -259,23 +259,23 @@ void buffer_free(BUFFER *b) {
void buffer_increase(BUFFER *b, size_t free_size_required) {
buffer_overflow_check(b);
- size_t left = b->size - b->len;
- if(left >= free_size_required) return;
+ size_t remaining = b->size - b->len;
+ if(remaining >= free_size_required) return;
- size_t wanted = free_size_required - left;
- size_t minimum = WEB_DATA_LENGTH_INCREASE_STEP;
- if(minimum > wanted) wanted = minimum;
+ size_t increase = free_size_required - remaining;
+ size_t minimum = 128;
+ if(minimum > increase) increase = minimum;
size_t optimal = (b->size > 5*1024*1024) ? b->size / 2 : b->size;
- if(optimal > wanted) wanted = optimal;
+ if(optimal > increase) increase = optimal;
- netdata_log_debug(D_WEB_BUFFER, "Increasing data buffer from size %zu to %zu.", b->size, b->size + wanted);
+ netdata_log_debug(D_WEB_BUFFER, "Increasing data buffer from size %zu to %zu.", b->size, b->size + increase);
- b->buffer = reallocz(b->buffer, b->size + wanted + sizeof(BUFFER_OVERFLOW_EOF) + 2);
- b->size += wanted;
+ b->buffer = reallocz(b->buffer, b->size + increase + sizeof(BUFFER_OVERFLOW_EOF) + 2);
+ b->size += increase;
if(b->statistics)
- __atomic_add_fetch(b->statistics, wanted, __ATOMIC_RELAXED);
+ __atomic_add_fetch(b->statistics, increase, __ATOMIC_RELAXED);
buffer_overflow_init(b);
buffer_overflow_check(b);
@@ -341,8 +341,10 @@ __attribute__((constructor)) void initialize_ascii_maps(void) {
base64_value_from_ascii[i] = 255;
}
- for(size_t i = 0; i < 16 ; i++)
- hex_value_from_ascii[(int)hex_digits[i]] = i;
+ for(size_t i = 0; i < 16 ; i++) {
+ hex_value_from_ascii[(int)toupper(hex_digits[i])] = i;
+ hex_value_from_ascii[(int)tolower(hex_digits[i])] = i;
+ }
for(size_t i = 0; i < 64 ; i++)
base64_value_from_ascii[(int)base64_digits[i]] = i;
@@ -492,12 +494,3 @@ int buffer_unittest(void) {
buffer_free(wb);
return errors;
}
-
-#ifdef ENABLE_H2O
-h2o_iovec_t buffer_to_h2o_iovec(BUFFER *wb) {
- h2o_iovec_t ret;
- ret.base = wb->buffer;
- ret.len = wb->len;
- return ret;
-}
-#endif
diff --git a/libnetdata/buffer/buffer.h b/src/libnetdata/buffer/buffer.h
index 88d3f0282..900907d49 100644
--- a/libnetdata/buffer/buffer.h
+++ b/src/libnetdata/buffer/buffer.h
@@ -6,12 +6,6 @@
#include "../string/utf8.h"
#include "../libnetdata.h"
-#ifdef ENABLE_H2O
-#include "h2o/memory.h"
-#endif
-
-#define WEB_DATA_LENGTH_INCREASE_STEP 1024
-
#define BUFFER_JSON_MAX_DEPTH 32 // max is 255
extern const char hex_digits[16];
@@ -38,37 +32,6 @@ typedef enum __attribute__ ((__packed__)) {
} BUFFER_OPTIONS;
typedef enum __attribute__ ((__packed__)) {
- CT_NONE = 0,
- CT_APPLICATION_JSON,
- CT_TEXT_PLAIN,
- CT_TEXT_HTML,
- CT_APPLICATION_X_JAVASCRIPT,
- CT_TEXT_CSS,
- CT_TEXT_XML,
- CT_APPLICATION_XML,
- CT_TEXT_XSL,
- CT_APPLICATION_OCTET_STREAM,
- CT_APPLICATION_X_FONT_TRUETYPE,
- CT_APPLICATION_X_FONT_OPENTYPE,
- CT_APPLICATION_FONT_WOFF,
- CT_APPLICATION_FONT_WOFF2,
- CT_APPLICATION_VND_MS_FONTOBJ,
- CT_IMAGE_SVG_XML,
- CT_IMAGE_PNG,
- CT_IMAGE_JPG,
- CT_IMAGE_GIF,
- CT_IMAGE_XICON,
- CT_IMAGE_ICNS,
- CT_IMAGE_BMP,
- CT_PROMETHEUS,
- CT_AUDIO_MPEG,
- CT_AUDIO_OGG,
- CT_VIDEO_MP4,
- CT_APPLICATION_PDF,
- CT_APPLICATION_ZIP,
-} HTTP_CONTENT_TYPE;
-
-typedef enum __attribute__ ((__packed__)) {
BUFFER_JSON_OPTIONS_DEFAULT = 0,
BUFFER_JSON_OPTIONS_MINIFY = (1 << 0),
BUFFER_JSON_OPTIONS_NEWLINE_ON_ARRAY_ITEMS = (1 << 1),
@@ -109,7 +72,7 @@ typedef struct web_buffer {
#define buffer_overflow_check(b)
#endif
-static inline void _buffer_overflow_check(BUFFER *b) {
+static inline void _buffer_overflow_check(BUFFER *b __maybe_unused) {
assert(b->len <= b->size &&
"BUFFER: length is above buffer size.");
@@ -150,10 +113,6 @@ void buffer_char_replace(BUFFER *wb, char from, char to);
void buffer_print_sn_flags(BUFFER *wb, SN_FLAGS flags, bool send_anomaly_bit);
-#ifdef ENABLE_H2O
-h2o_iovec_t buffer_to_h2o_iovec(BUFFER *wb);
-#endif
-
static inline void buffer_need_bytes(BUFFER *buffer, size_t needed_free_size) {
if(unlikely(buffer->len + needed_free_size >= buffer->size))
buffer_increase(buffer, needed_free_size + 1);
@@ -166,6 +125,9 @@ void buffer_json_finalize(BUFFER *wb);
static const char *buffer_tostring(BUFFER *wb)
{
+ if(unlikely(!wb))
+ return NULL;
+
buffer_need_bytes(wb, 1);
wb->buffer[wb->len] = '\0';
@@ -309,7 +271,8 @@ static inline void buffer_memcat(BUFFER *wb, const void *mem, size_t bytes) {
buffer_overflow_check(wb);
}
-static inline void buffer_json_strcat(BUFFER *wb, const char *txt) {
+static inline void buffer_json_strcat(BUFFER *wb, const char *txt)
+{
if(unlikely(!txt || !*txt)) return;
const unsigned char *t = (const unsigned char *)txt;
@@ -871,6 +834,26 @@ static inline void buffer_json_add_array_item_string(BUFFER *wb, const char *val
wb->json.stack[wb->json.depth].count++;
}
+static inline void buffer_json_add_array_item_uuid(BUFFER *wb, uuid_t *value) {
+ if(value && !uuid_is_null(*value)) {
+ char uuid[GUID_LEN + 1];
+ uuid_unparse_lower(*value, uuid);
+ buffer_json_add_array_item_string(wb, uuid);
+ }
+ else
+ buffer_json_add_array_item_string(wb, NULL);
+}
+
+static inline void buffer_json_add_array_item_uuid_compact(BUFFER *wb, uuid_t *value) {
+ if(value && !uuid_is_null(*value)) {
+ char uuid[GUID_LEN + 1];
+ uuid_unparse_lower_compact(*value, uuid);
+ buffer_json_add_array_item_string(wb, uuid);
+ }
+ else
+ buffer_json_add_array_item_string(wb, NULL);
+}
+
static inline void buffer_json_add_array_item_double(BUFFER *wb, NETDATA_DOUBLE value) {
buffer_print_json_comma_newline_spacing(wb);
@@ -1225,4 +1208,26 @@ buffer_rrdf_table_add_field(BUFFER *wb, size_t field_id, const char *key, const
buffer_json_object_close(wb);
}
+static inline void buffer_copy(BUFFER *dst, BUFFER *src) {
+ if(!src || !dst)
+ return;
+
+ buffer_contents_replace(dst, buffer_tostring(src), buffer_strlen(src));
+
+ dst->content_type = src->content_type;
+ dst->options = src->options;
+ dst->date = src->date;
+ dst->expires = src->expires;
+ dst->json = src->json;
+}
+
+static inline BUFFER *buffer_dup(BUFFER *src) {
+ if(!src)
+ return NULL;
+
+ BUFFER *dst = buffer_create(buffer_strlen(src) + 1, src->statistics);
+ buffer_copy(dst, src);
+ return dst;
+}
+
#endif /* NETDATA_WEB_BUFFER_H */
diff --git a/libnetdata/buffered_reader/buffered_reader.c b/src/libnetdata/buffered_reader/buffered_reader.c
index 7cd17abfe..7cd17abfe 100644
--- a/libnetdata/buffered_reader/buffered_reader.c
+++ b/src/libnetdata/buffered_reader/buffered_reader.c
diff --git a/libnetdata/buffered_reader/buffered_reader.h b/src/libnetdata/buffered_reader/buffered_reader.h
index 4db57cd29..4db57cd29 100644
--- a/libnetdata/buffered_reader/buffered_reader.h
+++ b/src/libnetdata/buffered_reader/buffered_reader.h