From 9c2c258f2ba014b460b0b2c2381940da82535b06 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 23 Oct 2018 14:43:35 +0200 Subject: [PATCH] uricontent: move debug func into unittests Cleanup header, which lead to the app-layer-htp.h header needing to be added in a few other places. --- src/app-layer-detect-proto.c | 2 + src/detect-bypass.c | 2 + src/detect-filestore.c | 1 + src/detect-lua.c | 1 + src/detect-parse.c | 1 + src/detect-uricontent.c | 88 ++++++++++++++++++------------------ src/detect-uricontent.h | 5 -- 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index 326d76de19..b90266d787 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -1948,6 +1948,8 @@ void AppLayerRegisterExpectationProto(uint8_t proto, AppProto alproto) #ifdef UNITTESTS +#include "app-layer-htp.h" + static AppLayerProtoDetectCtx alpd_ctx_ut; void AppLayerProtoDetectUnittestCtxBackup(void) diff --git a/src/detect-bypass.c b/src/detect-bypass.c index f415d65299..cd672a9160 100644 --- a/src/detect-bypass.c +++ b/src/detect-bypass.c @@ -101,6 +101,8 @@ static int DetectBypassMatch(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, Pac } #ifdef UNITTESTS +#include "app-layer-htp.h" + static int callback_var = 0; static int BypassCallback(Packet *p) diff --git a/src/detect-filestore.c b/src/detect-filestore.c index 7edf8b7d01..221e8595d4 100644 --- a/src/detect-filestore.c +++ b/src/detect-filestore.c @@ -46,6 +46,7 @@ #include "app-layer.h" #include "app-layer-parser.h" +#include "app-layer-htp.h" #include "stream-tcp.h" diff --git a/src/detect-lua.c b/src/detect-lua.c index 487ade7f4e..eefc200788 100644 --- a/src/detect-lua.c +++ b/src/detect-lua.c @@ -49,6 +49,7 @@ #include "app-layer.h" #include "app-layer-parser.h" +#include "app-layer-htp.h" #include "stream-tcp.h" diff --git a/src/detect-parse.c b/src/detect-parse.c index 437e4dfecd..c2ab03586a 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -58,6 +58,7 @@ #include "app-layer.h" #include "app-layer-protos.h" #include "app-layer-parser.h" +#include "app-layer-htp.h" #include "util-classification-config.h" #include "util-unittest.h" diff --git a/src/detect-uricontent.c b/src/detect-uricontent.c index 4886bacccb..8663387832 100644 --- a/src/detect-uricontent.c +++ b/src/detect-uricontent.c @@ -97,50 +97,6 @@ void DetectUricontentFree(void *ptr) SCReturn; } -/** - * \brief Helper function to print a DetectContentData - */ -void DetectUricontentPrint(DetectContentData *cd) -{ - int i = 0; - if (cd == NULL) { - SCLogDebug("Detect UricontentData \"cd\" is NULL"); - return; - } - char *tmpstr = SCMalloc(sizeof(char) * cd->content_len + 1); - if (unlikely(tmpstr == NULL)) - return; - - if (tmpstr != NULL) { - for (i = 0; i < cd->content_len; i++) { - if (isprint(cd->content[i])) - tmpstr[i] = cd->content[i]; - else - tmpstr[i] = '.'; - } - tmpstr[i] = '\0'; - SCLogDebug("Uricontent: \"%s\"", tmpstr); - SCFree(tmpstr); - } else { - SCLogDebug("Uricontent: "); - for (i = 0; i < cd->content_len; i++) - SCLogDebug("%c", cd->content[i]); - } - - SCLogDebug("Uricontent_id: %"PRIu32, cd->id); - SCLogDebug("Uricontent_len: %"PRIu16, cd->content_len); - SCLogDebug("Depth: %"PRIu16, cd->depth); - SCLogDebug("Offset: %"PRIu16, cd->offset); - SCLogDebug("Within: %"PRIi32, cd->within); - SCLogDebug("Distance: %"PRIi32, cd->distance); - SCLogDebug("flags: %u ", cd->flags); - SCLogDebug("negated: %s ", - cd->flags & DETECT_CONTENT_NEGATED ? "true" : "false"); - SCLogDebug("relative match next: %s ", - cd->flags & DETECT_CONTENT_RELATIVE_NEXT ? "true" : "false"); - SCLogDebug("-----------"); -} - /** * \brief Creates a SigMatch for the uricontent keyword being sent as argument, * and appends it to the Signature(s). @@ -195,6 +151,50 @@ error: #include "detect-isdataat.h" #include "stream-tcp-reassemble.h" +/** + * \brief Helper function to print a DetectContentData + */ +static void DetectUricontentPrint(DetectContentData *cd) +{ + int i = 0; + if (cd == NULL) { + SCLogDebug("Detect UricontentData \"cd\" is NULL"); + return; + } + char *tmpstr = SCMalloc(sizeof(char) * cd->content_len + 1); + if (unlikely(tmpstr == NULL)) + return; + + if (tmpstr != NULL) { + for (i = 0; i < cd->content_len; i++) { + if (isprint(cd->content[i])) + tmpstr[i] = cd->content[i]; + else + tmpstr[i] = '.'; + } + tmpstr[i] = '\0'; + SCLogDebug("Uricontent: \"%s\"", tmpstr); + SCFree(tmpstr); + } else { + SCLogDebug("Uricontent: "); + for (i = 0; i < cd->content_len; i++) + SCLogDebug("%c", cd->content[i]); + } + + SCLogDebug("Uricontent_id: %"PRIu32, cd->id); + SCLogDebug("Uricontent_len: %"PRIu16, cd->content_len); + SCLogDebug("Depth: %"PRIu16, cd->depth); + SCLogDebug("Offset: %"PRIu16, cd->offset); + SCLogDebug("Within: %"PRIi32, cd->within); + SCLogDebug("Distance: %"PRIi32, cd->distance); + SCLogDebug("flags: %u ", cd->flags); + SCLogDebug("negated: %s ", + cd->flags & DETECT_CONTENT_NEGATED ? "true" : "false"); + SCLogDebug("relative match next: %s ", + cd->flags & DETECT_CONTENT_RELATIVE_NEXT ? "true" : "false"); + SCLogDebug("-----------"); +} + /** \test Test case where path traversal has been sent as a path string in the * HTTP URL and normalized path string is checked */ static int HTTPUriTest01(void) diff --git a/src/detect-uricontent.h b/src/detect-uricontent.h index 1729e58f3e..289afff33a 100644 --- a/src/detect-uricontent.h +++ b/src/detect-uricontent.h @@ -25,12 +25,7 @@ #ifndef __DETECT_URICONTENT_H__ #define __DETECT_URICONTENT_H__ -#include "detect-content.h" - -#include "app-layer-htp.h" - /* prototypes */ void DetectUricontentRegister (void); -void DetectUricontentPrint(DetectContentData *); #endif /* __DETECT_URICONTENT_H__ */