From: Jeff Lucovsky Date: Sun, 21 Jul 2019 16:36:10 +0000 (-0400) Subject: eve/ftp: Move "get next line" into app-layer-ftp.c X-Git-Tag: suricata-5.0.0-rc1~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3df2b3437c4cc58de4e67244ead074bbb933abe5;p=thirdparty%2Fsuricata.git eve/ftp: Move "get next line" into app-layer-ftp.c --- diff --git a/src/app-layer-ftp.c b/src/app-layer-ftp.c index 05a2bd65d5..a48facc150 100644 --- a/src/app-layer-ftp.c +++ b/src/app-layer-ftp.c @@ -1364,6 +1364,32 @@ void FTPAtExitPrintStats(void) #ifdef HAVE_LIBJANSSON +/* + * \brief Returns the ending offset of the next line from a multi-line buffer. + * + * "Buffer" refers to a FTP response in a single buffer containing multiple lines. + * Here, "next line" is defined as terminating on + * - Newline character + * - Null character + * + * \param buffer Contains zero or more characters. + * \param len Size, in bytes, of buffer. + * + * \retval Offset from the start of buffer indicating the where the + * next "line ends". The characters between the input buffer and this + * value comprise the line. + * + * NULL is found first or a newline isn't found, then + */ +uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len) +{ + if (!buffer || *buffer == '\0') + return UINT16_MAX; + + char *c = strchr(buffer, '\n'); + return c == NULL ? len : c - buffer + 1; +} + json_t *JsonFTPDataAddMetadata(const Flow *f) { const FtpDataState *ftp_state = NULL; diff --git a/src/app-layer-ftp.h b/src/app-layer-ftp.h index ec4a6ddd00..50b6082c9a 100644 --- a/src/app-layer-ftp.h +++ b/src/app-layer-ftp.h @@ -219,6 +219,7 @@ uint64_t FTPMemuseGlobalCounter(void); uint64_t FTPMemcapGlobalCounter(void); #ifdef HAVE_LIBJANSSON +uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len); json_t *JsonFTPDataAddMetadata(const Flow *f); #endif diff --git a/src/output-json-ftp.c b/src/output-json-ftp.c index 9f54c0e5e9..251d5f878d 100644 --- a/src/output-json-ftp.c +++ b/src/output-json-ftp.c @@ -62,31 +62,6 @@ typedef struct LogFTPLogThread_ { MemBuffer *buffer; } LogFTPLogThread; -/* - * \brief Returns the ending offset of the next line. - * - * Here, "next line" is defined as terminating on - * - Newline character - * - Null character - * - * \param buffer Contains zero or more characters. - * \param len Size, in bytes, of buffer. - * - * \retval Offset from the start of buffer indicating the where the - * next "line ends". The characters between the input buffer and this - * value comprise the line. - * - * NULL is found first or a newline isn't found, then - */ -static uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len) -{ - if (!buffer || *buffer == '\0') - return UINT16_MAX; - - char *c = strchr(buffer, '\n'); - return c == NULL ? len : c - buffer + 1; -} - static json_t *JsonFTPLogCommand(Flow *f, FTPTransaction *tx) { json_t *cjs = json_object();