0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-05-03 00:40:12 +00:00
netdata_netdata/libnetdata/buffer/buffer.h
Costa Tsaousis 8fbf817ef8
modularized all source code ()
* modularized all external plugins

* added README.md in plugins

* fixed title

* fixed typo

* relative link to external plugins

* external plugins configuration README

* added plugins link

* remove plugins link

* plugin names are links

* added links to external plugins

* removed unecessary spacing

* list to table

* added language

* fixed typo

* list to table on internal plugins

* added more documentation to internal plugins

* moved python, node, and bash code and configs into the external plugins

* added statsd README

* fix bug with corrupting config.h every 2nd compilation

* moved all config files together with their code

* more documentation

* diskspace info

* fixed broken links in apps.plugin

* added backends docs

* updated plugins readme

* move nc-backend.sh to backends

* created daemon directory

* moved all code outside src/

* fixed readme identation

* renamed plugins.d.plugin to plugins.d

* updated readme

* removed linux- from linux plugins

* updated readme

* updated readme

* updated readme

* updated readme

* updated readme

* updated readme

* fixed README.md links

* fixed netdata tree links

* updated codacy, codeclimate and lgtm excluded paths

* update CMakeLists.txt

* updated automake options at top directory

* libnetdata slit into directories

* updated READMEs

* updated READMEs

* updated ARL docs

* updated ARL docs

* moved /plugins to /collectors

* moved all external plugins outside plugins.d

* updated codacy, codeclimate, lgtm

* updated README

* updated url

* updated readme

* updated readme

* updated readme

* updated readme

* moved api and web into webserver

* web/api web/gui web/server

* modularized webserver

* removed web/gui/version.txt
2018-10-15 23:16:42 +03:00

85 lines
3.5 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef NETDATA_WEB_BUFFER_H
#define NETDATA_WEB_BUFFER_H 1
#include "../libnetdata.h"
#define WEB_DATA_LENGTH_INCREASE_STEP 1024
typedef struct web_buffer {
size_t size; // allocation size of buffer, in bytes
size_t len; // current data length in buffer, in bytes
char *buffer; // the buffer itself
uint8_t contenttype; // the content type of the data in the buffer
uint8_t options; // options related to the content
time_t date; // the timestamp this content has been generated
time_t expires; // the timestamp this content expires
} BUFFER;
// options
#define WB_CONTENT_CACHEABLE 1
#define WB_CONTENT_NO_CACHEABLE 2
// content-types
#define CT_APPLICATION_JSON 1
#define CT_TEXT_PLAIN 2
#define CT_TEXT_HTML 3
#define CT_APPLICATION_X_JAVASCRIPT 4
#define CT_TEXT_CSS 5
#define CT_TEXT_XML 6
#define CT_APPLICATION_XML 7
#define CT_TEXT_XSL 8
#define CT_APPLICATION_OCTET_STREAM 9
#define CT_APPLICATION_X_FONT_TRUETYPE 10
#define CT_APPLICATION_X_FONT_OPENTYPE 11
#define CT_APPLICATION_FONT_WOFF 12
#define CT_APPLICATION_FONT_WOFF2 13
#define CT_APPLICATION_VND_MS_FONTOBJ 14
#define CT_IMAGE_SVG_XML 15
#define CT_IMAGE_PNG 16
#define CT_IMAGE_JPG 17
#define CT_IMAGE_GIF 18
#define CT_IMAGE_XICON 19
#define CT_IMAGE_ICNS 20
#define CT_IMAGE_BMP 21
#define CT_PROMETHEUS 22
#define buffer_cacheable(wb) do { (wb)->options |= WB_CONTENT_CACHEABLE; if((wb)->options & WB_CONTENT_NO_CACHEABLE) (wb)->options &= ~WB_CONTENT_NO_CACHEABLE; } while(0)
#define buffer_no_cacheable(wb) do { (wb)->options |= WB_CONTENT_NO_CACHEABLE; if((wb)->options & WB_CONTENT_CACHEABLE) (wb)->options &= ~WB_CONTENT_CACHEABLE; (wb)->expires = 0; } while(0)
#define buffer_strlen(wb) ((wb)->len)
extern const char *buffer_tostring(BUFFER *wb);
#define buffer_flush(wb) wb->buffer[(wb)->len = 0] = '\0'
extern void buffer_reset(BUFFER *wb);
extern void buffer_strcat(BUFFER *wb, const char *txt);
extern void buffer_rrd_value(BUFFER *wb, calculated_number value);
extern void buffer_date(BUFFER *wb, int year, int month, int day, int hours, int minutes, int seconds);
extern void buffer_jsdate(BUFFER *wb, int year, int month, int day, int hours, int minutes, int seconds);
extern BUFFER *buffer_create(size_t size);
extern void buffer_free(BUFFER *b);
extern void buffer_increase(BUFFER *b, size_t free_size_required);
extern void buffer_snprintf(BUFFER *wb, size_t len, const char *fmt, ...) PRINTFLIKE(3, 4);
extern void buffer_vsprintf(BUFFER *wb, const char *fmt, va_list args);
extern void buffer_sprintf(BUFFER *wb, const char *fmt, ...) PRINTFLIKE(2,3);
extern void buffer_strcat_htmlescape(BUFFER *wb, const char *txt);
extern void buffer_char_replace(BUFFER *wb, char from, char to);
extern char *print_number_lu_r(char *str, unsigned long uvalue);
extern char *print_number_llu_r(char *str, unsigned long long uvalue);
extern char *print_number_llu_r_smart(char *str, unsigned long long uvalue);
extern void buffer_print_llu(BUFFER *wb, unsigned long long uvalue);
static inline void buffer_need_bytes(BUFFER *buffer, size_t needed_free_size) {
if(unlikely(buffer->size - buffer->len < needed_free_size))
buffer_increase(buffer, needed_free_size);
}
#endif /* NETDATA_WEB_BUFFER_H */