From 6687618b672d0ea19328179bb78d4b65425ef447 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Mon, 1 Jun 2026 10:57:31 -0600 Subject: [PATCH] misc: remove log-cf-common It was only used to http-log which is now removed. --- src/Makefile.am | 2 - src/log-cf-common.c | 230 -------------------------------------------- src/log-cf-common.h | 88 ----------------- src/output.c | 4 - 4 files changed, 324 deletions(-) delete mode 100644 src/log-cf-common.c delete mode 100644 src/log-cf-common.h diff --git a/src/Makefile.am b/src/Makefile.am index 0ed1409559..5cc7d7782d 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -337,7 +337,6 @@ noinst_HEADERS = \ ippair-storage.h \ ippair-timeout.h \ ippair.h \ - log-cf-common.h \ log-flush.h \ log-pcap.h \ log-stats.h \ @@ -911,7 +910,6 @@ libsuricata_c_a_SOURCES = \ ippair-storage.c \ ippair-timeout.c \ ippair.c \ - log-cf-common.c \ log-flush.c \ log-pcap.c \ log-stats.c \ diff --git a/src/log-cf-common.c b/src/log-cf-common.c deleted file mode 100644 index 98b6989c62..0000000000 --- a/src/log-cf-common.c +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright (C) 2007-2016 Open Information Security Foundation - * - * You can copy, redistribute or modify this Program under the terms of - * the GNU General Public License version 2 as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * \file - * - * \author Paulo Pacheco - * \author Victor Julien - * \author Ignacio Sanchez - * - * Common custom logging format - */ - -#include "log-cf-common.h" -#include "util-print.h" -#include "util-time.h" -#include "util-debug.h" - -/** - * \brief Creates a custom format node - * \retval LogCustomFormatNode * ptr if created - * \retval NULL if failed to allocate - */ -LogCustomFormatNode *LogCustomFormatNodeAlloc(void) -{ - LogCustomFormatNode * node = SCCalloc(1, sizeof(LogCustomFormatNode)); - if (unlikely(node == NULL)) { - SCLogError("Failed to alloc custom format node"); - return NULL; - } - return node; -} - -/** - * \brief Creates a custom format. - * \retval LogCustomFormat * ptr if created - * \retval NULL if failed to allocate - */ -LogCustomFormat *LogCustomFormatAlloc(void) -{ - LogCustomFormat * cf = SCCalloc(1, sizeof(LogCustomFormat)); - if (unlikely(cf == NULL)) { - SCLogError("Failed to alloc custom format"); - return NULL; - } - return cf; -} - -/** - * \brief Frees memory held by a custom format node - * \param LogCustomFormatNode * node - node to release - */ -void LogCustomFormatNodeFree(LogCustomFormatNode *node) -{ - if (node==NULL) - return; - - SCFree(node); -} - -/** - * \brief Frees memory held by a custom format - * \param LogCustomFormat * cf - format to release - */ -void LogCustomFormatFree(LogCustomFormat *cf) -{ - if (cf==NULL) - return; - - for (size_t i = 0; i < cf->cf_n; ++i) { - LogCustomFormatNodeFree(cf->cf_nodes[i]); - } - SCFree(cf); -} - -/** - * \brief Parses and saves format nodes for custom format - * \param LogCustomFormat * cf - custom format to build - * \param const char * format - string with format specification - */ -int LogCustomFormatParse(LogCustomFormat *cf, const char *format) -{ - const char *p, *np; - uint32_t n; - LogCustomFormatNode *node = NULL; - - if (cf==NULL) - return 0; - - if (format==NULL) - return 0; - - p=format; - - for (cf->cf_n = 0; cf->cf_n < LOG_MAXN_NODES-1 && p && *p != '\0';){ - - node = LogCustomFormatNodeAlloc(); - if (node == NULL) { - goto parsererror; - } - node->maxlen = 0; - - if (*p != '%'){ - /* Literal found in format string */ - node->type = LOG_CF_LITERAL; - np = strchr(p, '%'); - if (np == NULL){ - n = LOG_NODE_STRLEN-2; - np = NULL; /* End */ - }else{ - n = (uint32_t)(np - p); - } - strlcpy(node->data,p,n+1); - p = np; - } else { - /* Non Literal found in format string */ - p++; - if (*p == '[') { /* Check if maxlength has been specified (ie: [25]) */ - p++; - np = strchr(p, ']'); - if (np != NULL) { - if (np-p > 0 && np-p < 10){ - long maxlen = strtol(p,NULL,10); - if (maxlen > 0 && maxlen < LOG_NODE_MAXOUTPUTLEN) { - node->maxlen = (uint32_t) maxlen; - } - } else { - goto parsererror; - } - p = np + 1; - } else { - goto parsererror; - } - } - if (*p == '{') { /* Simple format char */ - np = strchr(p, '}'); - if (np != NULL && np-p > 1 && np-p < LOG_NODE_STRLEN-2) { - p++; - n = (uint32_t)(np - p); - strlcpy(node->data, p, n+1); - p = np; - } else { - goto parsererror; - } - p++; - } else { - node->data[0] = '\0'; - } - node->type = *p; - if (*p == '%'){ - node->type = LOG_CF_LITERAL; - strlcpy(node->data, "%", 2); - } - p++; - } - LogCustomFormatAddNode(cf, node); - } - return 1; - -parsererror: - LogCustomFormatNodeFree(node); - return 0; -} - -/** - * \brief Adds a node to custom format - * \param LogCustomFormat * cf - custom format - * \param LogCustomFormatNode * node - node to add - */ -void LogCustomFormatAddNode(LogCustomFormat *cf, LogCustomFormatNode *node) -{ - if (cf == NULL || node == NULL) - return; - - if (cf->cf_n == LOG_MAXN_NODES) { - SCLogWarning("Too many options for custom format"); - return; - } - -#ifdef DEBUG - SCLogDebug("%d-> n.type=[%d] n.maxlen=[%d] n.data=[%s]", - cf->cf_n, node->type, node->maxlen, node->data); -#endif - - cf->cf_nodes[cf->cf_n] = node; - cf->cf_n++; -} - -/** - * \brief Writes a timestamp with given format into a MemBuffer - * \param MemBuffer * buffer - where to write - * \param const char * fmt - format to be used write timestamp - * \param const struct timeveal *ts - the timestamp - * - */ -void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts) -{ - - time_t time = SCTIME_SECS(ts); - struct tm local_tm; - struct tm *timestamp = SCLocalTime(time, &local_tm); - char buf[128] = {0}; - const char * fmt_to_use = TIMESTAMP_DEFAULT_FORMAT; - - if (fmt && *fmt != '\0') { - fmt_to_use = fmt; - } - - CreateFormattedTimeString (timestamp, fmt_to_use, buf, sizeof(buf)); - PrintRawUriBuf((char *)buffer->buffer, &buffer->offset, - buffer->size, (uint8_t *)buf,strlen(buf)); -} - -void LogCustomFormatRegister(void) -{ -} diff --git a/src/log-cf-common.h b/src/log-cf-common.h deleted file mode 100644 index 078a5064e9..0000000000 --- a/src/log-cf-common.h +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2016 Open Information Security Foundation - * - * You can copy, redistribute or modify this Program under the terms of - * the GNU General Public License version 2 as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -/** - * \file - * - * \author Victor Julien - * \author Ignacio Sanchez - * \author Paulo Pacheco - * - * Common custom logging format - */ - -#ifndef SURICATA_LOG_CF_COMMON_H -#define SURICATA_LOG_CF_COMMON_H - -#define LOG_MAXN_NODES 64 -#define LOG_NODE_STRLEN 256 -#define LOG_NODE_MAXOUTPUTLEN 8192 - -#define TIMESTAMP_DEFAULT_FORMAT "%D-%H:%M:%S" - -/* Common format nodes */ -#define LOG_CF_NONE "-" -#define LOG_CF_LITERAL '%' -#define LOG_CF_TIMESTAMP 't' -#define LOG_CF_TIMESTAMP_U 'z' -#define LOG_CF_CLIENT_IP 'a' -#define LOG_CF_SERVER_IP 'A' -#define LOG_CF_CLIENT_PORT 'p' -#define LOG_CF_SERVER_PORT 'P' - -/* Line log common separators **/ -#define LOG_CF_STAR_SEPARATOR "[**]" -#define LOG_CF_SPACE_SEPARATOR " " -#define LOG_CF_UNKNOWN_VALUE "-" - -#define LOG_CF_WRITE_STAR_SEPARATOR(buffer) MemBufferWriteString(buffer, LOG_CF_STAR_SEPARATOR); - -#define LOG_CF_WRITE_SPACE_SEPARATOR(buffer) \ - MemBufferWriteString(buffer, LOG_CF_SPACE_SEPARATOR); - -#define LOG_CF_WRITE_UNKNOWN_VALUE(buffer) \ - MemBufferWriteString(buffer, LOG_CF_UNKNOWN_VALUE); - -/* Include */ -#include "suricata-common.h" -#include "util-buffer.h" - -typedef struct LogCustomFormatNode_ { - uint32_t type; /**< Node format type. ie: LOG_CF_LITERAL, ... */ - uint32_t maxlen; /**< Maximum length of the data */ - char data[LOG_NODE_STRLEN]; /**< optional data. ie: http header name */ -} LogCustomFormatNode; - - -typedef struct LogCustomFormat_ { - uint32_t cf_n; /**< Total number of custom string format nodes */ - LogCustomFormatNode *cf_nodes[LOG_MAXN_NODES]; /**< Custom format string nodes */ -} LogCustomFormat; - -LogCustomFormatNode * LogCustomFormatNodeAlloc(void); -LogCustomFormat * LogCustomFormatAlloc(void); - -void LogCustomFormatNodeFree(LogCustomFormatNode *node); -void LogCustomFormatFree(LogCustomFormat *cf); - -void LogCustomFormatAddNode(LogCustomFormat *cf, LogCustomFormatNode *node); -int LogCustomFormatParse(LogCustomFormat *cf, const char *format); - -void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts); -void LogCustomFormatRegister(void); - -#endif /* SURICATA_LOG_CF_COMMON_H */ diff --git a/src/output.c b/src/output.c index ed38790756..f3819390fa 100644 --- a/src/output.c +++ b/src/output.c @@ -49,7 +49,6 @@ #include "output-json-anomaly.h" #include "output-json-flow.h" #include "output-json-netflow.h" -#include "log-cf-common.h" #include "output-json-drop.h" #include "output-eve-stream.h" #include "output-json-http.h" @@ -1071,9 +1070,6 @@ static TxLogger JsonLoggerFromDir(uint8_t dir) */ void OutputRegisterLoggers(void) { - /* custom format log*/ - LogCustomFormatRegister(); - LuaLogRegister(); /* fast log */ AlertFastLogRegister();