templates: clang format cleanups

Cleanup the trivial clang-formatting issues in templates.  Length of
protocol names may require clang-format after new protocol generation.
pull/8251/head
Jason Ish 3 years ago committed by Victor Julien
parent 712d80107f
commit 05e16820de

@ -120,7 +120,7 @@ def patch_app_layer_protos_c(protoname):
for i, line in enumerate(inlines): for i, line in enumerate(inlines):
if line.find("case ALPROTO_TEMPLATE:") > -1: if line.find("case ALPROTO_TEMPLATE:") > -1:
# Duplicate the section starting an this line and # Duplicate the section starting at this line and
# including the following 2 lines. # including the following 2 lines.
for j in range(i, i + 3): for j in range(i, i + 3):
temp = inlines[j] temp = inlines[j]
@ -129,9 +129,13 @@ def patch_app_layer_protos_c(protoname):
output.write(temp) output.write(temp)
if line.find("return ALPROTO_TEMPLATE;") > -1: if line.find("return ALPROTO_TEMPLATE;") > -1:
output.write( # Duplicate the section starting at this line and
line.replace("TEMPLATE", protoname.upper()).replace( # including the following line.
"template", protoname.lower())) for j in range(i, i + 2):
temp = inlines[j]
temp = temp.replace("TEMPLATE", protoname.upper())
temp = temp.replace("template", protoname.lower())
output.write(temp)
output.write(line) output.write(line)
open(filename, "w").write(output.getvalue()) open(filename, "w").write(output.getvalue())

@ -190,8 +190,10 @@ AppProto StringToAppProto(const char *proto_name)
return ALPROTO_PGSQL; return ALPROTO_PGSQL;
if (strcmp(proto_name, "telnet") == 0) if (strcmp(proto_name, "telnet") == 0)
return ALPROTO_TELNET; return ALPROTO_TELNET;
if (strcmp(proto_name,"template")==0) return ALPROTO_TEMPLATE; if (strcmp(proto_name, "template") == 0)
if (strcmp(proto_name,"template-rust")==0) return ALPROTO_TEMPLATE_RUST; return ALPROTO_TEMPLATE;
if (strcmp(proto_name, "template-rust") == 0)
return ALPROTO_TEMPLATE_RUST;
if (strcmp(proto_name,"rdp")==0) return ALPROTO_RDP; if (strcmp(proto_name,"rdp")==0) return ALPROTO_RDP;
if (strcmp(proto_name,"http2")==0) return ALPROTO_HTTP2; if (strcmp(proto_name,"http2")==0) return ALPROTO_HTTP2;
if (strcmp(proto_name, "bittorrent-dht") == 0) if (strcmp(proto_name, "bittorrent-dht") == 0)

@ -41,9 +41,7 @@
#include "detect-engine-build.h" #include "detect-engine-build.h"
#include "rust.h" #include "rust.h"
static int DetectTemplateRustBufferSetup(DetectEngineCtx *, Signature *, const char *);
static int DetectTemplateRustBufferSetup(DetectEngineCtx *, Signature *,
const char *);
static uint8_t DetectEngineInspectTemplateRustBuffer(DetectEngineCtx *de_ctx, static uint8_t DetectEngineInspectTemplateRustBuffer(DetectEngineCtx *de_ctx,
DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine,
const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id); const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
@ -82,8 +80,7 @@ void DetectTemplateRustBufferRegister(void)
SCLogNotice("Template application layer detect registered."); SCLogNotice("Template application layer detect registered.");
} }
static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s, static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
const char *str)
{ {
s->init_data->list = g_template_rust_id; s->init_data->list = g_template_rust_id;
@ -157,26 +154,24 @@ static int DetectTemplateRustBufferTest(void)
FAIL_IF_NULL(de_ctx); FAIL_IF_NULL(de_ctx);
/* This rule should match. */ /* This rule should match. */
s = DetectEngineAppendSig(de_ctx, s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
"alert tcp any any -> any any (" "msg:\"TEMPLATE Test Rule\"; "
"msg:\"TEMPLATE Test Rule\"; " "template_rust_buffer; content:\"World!\"; "
"template_rust_buffer; content:\"World!\"; " "sid:1; rev:1;)");
"sid:1; rev:1;)");
FAIL_IF_NULL(s); FAIL_IF_NULL(s);
/* This rule should not match. */ /* This rule should not match. */
s = DetectEngineAppendSig(de_ctx, s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
"alert tcp any any -> any any (" "msg:\"TEMPLATE Test Rule\"; "
"msg:\"TEMPLATE Test Rule\"; " "template_rust_buffer; content:\"W0rld!\"; "
"template_rust_buffer; content:\"W0rld!\"; " "sid:2; rev:1;)");
"sid:2; rev:1;)");
FAIL_IF_NULL(s); FAIL_IF_NULL(s);
SigGroupBuild(de_ctx); SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx); DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);
AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, AppLayerParserParse(
STREAM_TOSERVER, request, sizeof(request)); NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, STREAM_TOSERVER, request, sizeof(request));
/* Check that we have app-layer state. */ /* Check that we have app-layer state. */
FAIL_IF_NULL(f.alstate); FAIL_IF_NULL(f.alstate);

@ -24,7 +24,6 @@
#ifndef __DETECT_TEMPLATE_RUST_BUFFER_H__ #ifndef __DETECT_TEMPLATE_RUST_BUFFER_H__
#define __DETECT_TEMPLATE_RUST_BUFFER_H__ #define __DETECT_TEMPLATE_RUST_BUFFER_H__
void DetectTemplateRustBufferRegister(void); void DetectTemplateRustBufferRegister(void);
#endif /* __DETECT_TEMPLATE_RUST_BUFFER_H__ */ #endif /* __DETECT_TEMPLATE_RUST_BUFFER_H__ */

@ -53,7 +53,7 @@
#include "rust.h" #include "rust.h"
typedef struct LogTemplateFileCtx_ { typedef struct LogTemplateFileCtx_ {
uint32_t flags; uint32_t flags;
OutputJsonCtx *eve_ctx; OutputJsonCtx *eve_ctx;
} LogTemplateFileCtx; } LogTemplateFileCtx;
@ -62,8 +62,8 @@ typedef struct LogTemplateLogThread_ {
OutputJsonThreadCtx *ctx; OutputJsonThreadCtx *ctx;
} LogTemplateLogThread; } LogTemplateLogThread;
static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id) void *state, void *tx, uint64_t tx_id)
{ {
SCLogNotice("JsonTemplateLogger"); SCLogNotice("JsonTemplateLogger");
LogTemplateLogThread *thread = thread_data; LogTemplateLogThread *thread = thread_data;
@ -97,8 +97,7 @@ static void OutputTemplateLogDeInitCtxSub(OutputCtx *output_ctx)
SCFree(output_ctx); SCFree(output_ctx);
} }
static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
OutputCtx *parent_ctx)
{ {
OutputInitResult result = { NULL, false }; OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data; OutputJsonCtx *ajt = parent_ctx->data;

Loading…
Cancel
Save