diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2024-04-17 01:43:38 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2024-04-17 01:47:31 +0200 |
commit | 4c9103827465c09d9d3df088f9c73463908d0ba4 (patch) | |
tree | 369367dc10b19fc5cb1fcfdff77e93ccb5394203 | |
parent | 53126a0af9341d609247ef63b494c44b33a93baf (diff) |
Removed unmaintained C JSON dumper.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | examples/README.md | 4 | ||||
-rw-r--r-- | examples/c-json-stdout/c-json-stdout.c | 135 |
3 files changed, 2 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1039b05c3..4849403ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -380,10 +380,6 @@ if(BUILD_EXAMPLES) "${pkgcfg_lib_PCRE_pcre2-8}" "${pkgcfg_lib_MAXMINDDB_maxminddb}" "${GCRYPT_LIBRARY}" "${GCRYPT_ERROR_LIBRARY}" "${PCAP_LIBRARY}") - add_executable(nDPIsrvd-json-dump examples/c-json-stdout/c-json-stdout.c) - target_compile_definitions(nDPIsrvd-json-dump PRIVATE ${NDPID_DEFS}) - target_include_directories(nDPIsrvd-json-dump PRIVATE ${NDPID_DEPS_INC}) - add_executable(nDPIsrvd-analysed examples/c-analysed/c-analysed.c utils.c) target_compile_definitions(nDPIsrvd-analysed PRIVATE ${NDPID_DEFS}) target_include_directories(nDPIsrvd-analysed PRIVATE ${NDPID_DEPS_INC}) @@ -393,7 +389,7 @@ if(BUILD_EXAMPLES) target_include_directories(nDPIsrvd-simple PRIVATE ${NDPID_DEPS_INC}) if(ENABLE_COVERAGE) - add_dependencies(coverage nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-json-dump nDPIsrvd-simple) + add_dependencies(coverage nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-simple) endif() if(ENABLE_DBUS) @@ -420,7 +416,7 @@ if(BUILD_EXAMPLES) install(TARGETS nDPIsrvd-influxd DESTINATION bin) endif() - install(TARGETS nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-json-dump nDPIsrvd-simple DESTINATION bin) + install(TARGETS nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-simple DESTINATION bin) install(FILES examples/c-collectd/plugin_nDPIsrvd.conf examples/c-collectd/rrdgraph.sh DESTINATION share/nDPId/nDPIsrvd-collectd) install(DIRECTORY examples/c-collectd/www DESTINATION share/nDPId/nDPIsrvd-collectd) endif() diff --git a/examples/README.md b/examples/README.md index 59fea7187..52fd6e090 100644 --- a/examples/README.md +++ b/examples/README.md @@ -31,10 +31,6 @@ The results are sent to a specified InfluxDB endpoint. A notification daemon that sends information about suspicious flow events to DBUS. -## c-json-stdout - -Tiny nDPId json dumper. Does not provide any useful funcationality besides dumping parsed JSON objects. - ## c-simple Integration example that verifies flow timeouts on SIGUSR1. diff --git a/examples/c-json-stdout/c-json-stdout.c b/examples/c-json-stdout/c-json-stdout.c deleted file mode 100644 index 414ece44c..000000000 --- a/examples/c-json-stdout/c-json-stdout.c +++ /dev/null @@ -1,135 +0,0 @@ -#include <arpa/inet.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/socket.h> -#include <sys/types.h> -#include <unistd.h> - -#include "config.h" -#include "jsmn.h" - -static char serv_listen_addr[INET_ADDRSTRLEN] = DISTRIBUTOR_HOST; -static uint16_t serv_listen_port = DISTRIBUTOR_PORT; - -int main(void) -{ - int sockfd = socket(AF_INET, SOCK_STREAM, 0); - struct sockaddr_in remote_addr = {}; - socklen_t remote_addrlen = sizeof(remote_addr); - uint8_t buf[NETWORK_BUFFER_MAX_SIZE]; - size_t buf_used = 0; - size_t json_start = 0; - unsigned long long int json_bytes = 0; - jsmn_parser parser; - jsmntok_t tokens[128]; - - if (sockfd < 0) - { - perror("socket"); - return 1; - } - - remote_addr.sin_family = AF_INET; - if (inet_pton(AF_INET, &serv_listen_addr[0], &remote_addr.sin_addr) != 1) - { - perror("inet_pton"); - return 1; - } - remote_addr.sin_port = htons(serv_listen_port); - - if (connect(sockfd, (struct sockaddr *)&remote_addr, remote_addrlen) != 0) - { - perror("connect"); - return 1; - } - - while (1) - { - errno = 0; - ssize_t bytes_read = read(sockfd, buf + buf_used, sizeof(buf) - buf_used); - - if (bytes_read <= 0 || errno != 0) - { - fprintf(stderr, "Remote end disconnected.\n"); - break; - } - - buf_used += bytes_read; - while (buf_used >= NETWORK_BUFFER_LENGTH_DIGITS + 1) - { - if (buf[NETWORK_BUFFER_LENGTH_DIGITS] != '{') - { - fprintf(stderr, "BUG: JSON invalid opening character: '%c'\n", buf[NETWORK_BUFFER_LENGTH_DIGITS]); - exit(1); - } - - char * json_msg_start = NULL; - json_bytes = strtoull((char *)buf, &json_msg_start, 10); - json_bytes += (uint8_t *)json_msg_start - buf; - json_start = (uint8_t *)json_msg_start - buf; - - if (errno == ERANGE) - { - fprintf(stderr, "BUG: Size of JSON exceeds limit\n"); - exit(1); - } - if ((uint8_t *)json_msg_start == buf) - { - fprintf(stderr, "BUG: Missing size before JSON message: \"%.*s\"\n", NETWORK_BUFFER_LENGTH_DIGITS, buf); - exit(1); - } - if (json_bytes > sizeof(buf)) - { - fprintf(stderr, "BUG: JSON message too big: %llu > %zu\n", json_bytes, sizeof(buf)); - exit(1); - } - if (json_bytes > buf_used) - { - break; - } - - if (buf[json_bytes - 2] != '}' || buf[json_bytes - 1] != '\n') - { - fprintf(stderr, "BUG: Invalid JSON message: \"%.*s\"\n", (int)json_bytes, buf); - exit(1); - } - - int r; - jsmn_init(&parser); - r = jsmn_parse(&parser, - (char *)(buf + json_start), - json_bytes - json_start, - tokens, - sizeof(tokens) / sizeof(tokens[0])); - if (r < 1 || tokens[0].type != JSMN_OBJECT) - { - fprintf(stderr, "JSON parsing failed with return value %d at position %u\n", r, parser.pos); - fprintf(stderr, "JSON message: '%.*s'\n", (int)(json_bytes - json_start), (char *)(buf + json_start)); - exit(1); - } - - for (int i = 1; i < r; i++) - { - if (i % 2 == 1) - { -#ifdef JSMN_PARENT_LINKS - printf("[%d][%d]", i, tokens[i].parent); -#endif - printf("[%.*s : ", tokens[i].end - tokens[i].start, (char *)(buf + json_start) + tokens[i].start); - } - else - { - printf("%.*s] ", tokens[i].end - tokens[i].start, (char *)(buf + json_start) + tokens[i].start); - } - } - printf("EoF\n"); - - memmove(buf, buf + json_bytes, buf_used - json_bytes); - buf_used -= json_bytes; - } - } - - return 0; -} |