diff options
Diffstat (limited to '')
-rw-r--r-- | libnetdata/parser/parser.h (renamed from parser/parser.h) | 76 |
1 files changed, 27 insertions, 49 deletions
diff --git a/parser/parser.h b/libnetdata/parser/parser.h index ad7488389..9e0d3480d 100644 --- a/parser/parser.h +++ b/libnetdata/parser/parser.h @@ -3,76 +3,56 @@ #ifndef NETDATA_INCREMENTAL_PARSER_H #define NETDATA_INCREMENTAL_PARSER_H 1 -#include "daemon/common.h" +#include "../libnetdata.h" -#define PARSER_MAX_CALLBACKS 20 -#define PARSER_MAX_RECOVER_KEYWORDS 128 #define WORKER_PARSER_FIRST_JOB 3 // this has to be in-sync with the same at receiver.c #define WORKER_RECEIVER_JOB_REPLICATION_COMPLETION (WORKER_PARSER_FIRST_JOB - 3) +#define PARSER_KEYWORDS_HASHTABLE_SIZE 73 // unittest finds this magic number +//#define parser_hash_function(s) djb2_hash32(s) +//#define parser_hash_function(s) fnv1_hash32(s) +//#define parser_hash_function(s) fnv1a_hash32(s) +//#define parser_hash_function(s) larson_hash32(s) +#define parser_hash_function(s) pluginsd_parser_hash32(s) + // PARSER return codes -typedef enum parser_rc { +typedef enum __attribute__ ((__packed__)) parser_rc { PARSER_RC_OK, // Callback was successful, go on PARSER_RC_STOP, // Callback says STOP PARSER_RC_ERROR // Callback failed (abort rest of callbacks) } PARSER_RC; -typedef enum parser_input_type { +typedef enum __attribute__ ((__packed__)) parser_input_type { PARSER_INPUT_SPLIT = (1 << 1), - PARSER_INPUT_KEEP_ORIGINAL = (1 << 2), - PARSER_INPUT_PROCESSED = (1 << 3), - PARSER_NO_PARSE_INIT = (1 << 4), - PARSER_NO_ACTION_INIT = (1 << 5), - PARSER_DEFER_UNTIL_KEYWORD = (1 << 6), + PARSER_DEFER_UNTIL_KEYWORD = (1 << 2), } PARSER_INPUT_TYPE; -#define PARSER_INPUT_FULL (PARSER_INPUT_SPLIT|PARSER_INPUT_ORIGINAL) - typedef PARSER_RC (*keyword_function)(char **words, size_t num_words, void *user_data); typedef struct parser_keyword { - size_t worker_job_id; - char *keyword; - uint32_t keyword_hash; - int func_no; - keyword_function func[PARSER_MAX_CALLBACKS+1]; - struct parser_keyword *next; + size_t worker_job_id; + char *keyword; + keyword_function func; } PARSER_KEYWORD; -typedef struct parser_data { - char *line; - struct parser_data *next; -} PARSER_DATA; - typedef struct parser { size_t worker_job_next_id; uint8_t version; // Parser version - RRDHOST *host; int fd; // Socket FILE *fp_input; // Input source e.g. stream FILE *fp_output; // Stream to send commands to plugin #ifdef ENABLE_HTTPS struct netdata_ssl *ssl_output; #endif - PARSER_DATA *data; // extra input - PARSER_KEYWORD *keyword; // List of parse keywords and functions - void *user; // User defined structure to hold extra state between calls + void *user; // User defined structure to hold extra state between calls uint32_t flags; size_t line; - char *(*read_function)(char *buffer, long unsigned int, void *input); - int (*eof_function)(void *input); - keyword_function unknown_function; - char buffer[PLUGINSD_LINE_MAX]; - char *recover_location[PARSER_MAX_RECOVER_KEYWORDS+1]; - char recover_input[PARSER_MAX_RECOVER_KEYWORDS]; -#ifdef ENABLE_HTTPS - int bytesleft; - char tmpbuffer[PLUGINSD_LINE_MAX]; - char *readfrom; -#endif + struct { + PARSER_KEYWORD *hashtable[PARSER_KEYWORDS_HASHTABLE_SIZE]; + } keywords; struct { const char *end_keyword; @@ -85,20 +65,13 @@ typedef struct parser { DICTIONARY *functions; usec_t smaller_timeout; } inflight; - } PARSER; -int find_first_keyword(const char *str, char *keyword, int max_size, int (*custom_isspace)(char)); - -PARSER *parser_init(RRDHOST *host, void *user, FILE *fp_input, FILE *fp_output, int fd, PARSER_INPUT_TYPE flags, void *ssl); -int parser_add_keyword(PARSER *working_parser, char *keyword, keyword_function func); -int parser_next(PARSER *working_parser); +PARSER *parser_init(void *user, FILE *fp_input, FILE *fp_output, int fd, PARSER_INPUT_TYPE flags, void *ssl); +void parser_add_keyword(PARSER *working_parser, char *keyword, keyword_function func); +int parser_next(PARSER *working_parser, char *buffer, size_t buffer_size); int parser_action(PARSER *working_parser, char *input); -int parser_push(PARSER *working_parser, char *line); void parser_destroy(PARSER *working_parser); -int parser_recover_input(PARSER *working_parser); - -size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp_plugin_input, FILE *fp_plugin_output, int trust_durations); PARSER_RC pluginsd_set(char **words, size_t num_words, void *user); PARSER_RC pluginsd_begin(char **words, size_t num_words, void *user); @@ -114,10 +87,15 @@ PARSER_RC pluginsd_overwrite(char **words, size_t num_words, void *user); PARSER_RC pluginsd_clabel_commit(char **words, size_t num_words, void *user); PARSER_RC pluginsd_clabel(char **words, size_t num_words, void *user); -PARSER_RC pluginsd_replay_rrdset_begin(char **words, size_t num_words, void *user); +PARSER_RC pluginsd_replay_begin(char **words, size_t num_words, void *user); PARSER_RC pluginsd_replay_rrddim_collection_state(char **words, size_t num_words, void *user); PARSER_RC pluginsd_replay_rrdset_collection_state(char **words, size_t num_words, void *user); PARSER_RC pluginsd_replay_set(char **words, size_t num_words, void *user); PARSER_RC pluginsd_replay_end(char **words, size_t num_words, void *user); +PARSER_RC pluginsd_begin_v2(char **words, size_t num_words, void *user); +PARSER_RC pluginsd_set_v2(char **words, size_t num_words, void *user); +PARSER_RC pluginsd_end_v2(char **words, size_t num_words, void *user); +void pluginsd_cleanup_v2(void *user); + #endif |