]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
templates: clang format cleanups
authorJason Ish <jason.ish@oisf.net>
Thu, 17 Nov 2022 16:00:19 +0000 (10:00 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:09:10 +0000 (14:09 +0100)
Cleanup the trivial clang-formatting issues in templates.  Length of
protocol names may require clang-format after new protocol generation.

scripts/setup-app-layer.py
src/app-layer-protos.c
src/detect-template-rust-buffer.c
src/detect-template-rust-buffer.h
src/output-json-template-rust.c

index 92abb9da459a83d967425ca5e7d318477019a4c8..920ddf796053af8415ca7532ca7ab56c56197160 100755 (executable)
@@ -120,7 +120,7 @@ def patch_app_layer_protos_c(protoname):
     for i, line in enumerate(inlines):
 
         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.
             for j in range(i, i + 3):
                 temp = inlines[j]
@@ -129,9 +129,13 @@ def patch_app_layer_protos_c(protoname):
                 output.write(temp)
 
         if line.find("return ALPROTO_TEMPLATE;") > -1:
-            output.write(
-                line.replace("TEMPLATE", protoname.upper()).replace(
-                    "template", protoname.lower()))
+            # Duplicate the section starting at this line and
+            # including the following line.
+            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)
     open(filename, "w").write(output.getvalue())
index d18d2f699098fc15e14495e1bf08cafdf7c41d6d..39e9e7f437a2aa097560be2572f29e8fd3ee0d85 100644 (file)
@@ -190,8 +190,10 @@ AppProto StringToAppProto(const char *proto_name)
         return ALPROTO_PGSQL;
     if (strcmp(proto_name, "telnet") == 0)
         return ALPROTO_TELNET;
-    if (strcmp(proto_name,"template")==0) return ALPROTO_TEMPLATE;
-    if (strcmp(proto_name,"template-rust")==0) return ALPROTO_TEMPLATE_RUST;
+    if (strcmp(proto_name, "template") == 0)
+        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,"http2")==0) return ALPROTO_HTTP2;
     if (strcmp(proto_name, "bittorrent-dht") == 0)
index a3185ddda4e102c24be744acb01457c2dceaaf5e..917f8a1ce23ed43a07d940632ed381c490ef0de9 100644 (file)
@@ -41,9 +41,7 @@
 #include "detect-engine-build.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,
         DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine,
         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.");
 }
 
-static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s,
-    const char *str)
+static int DetectTemplateRustBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
 {
     s->init_data->list = g_template_rust_id;
 
@@ -157,26 +154,24 @@ static int DetectTemplateRustBufferTest(void)
     FAIL_IF_NULL(de_ctx);
 
     /* This rule should match. */
-    s = DetectEngineAppendSig(de_ctx,
-        "alert tcp any any -> any any ("
-        "msg:\"TEMPLATE Test Rule\"; "
-        "template_rust_buffer; content:\"World!\"; "
-        "sid:1; rev:1;)");
+    s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
+                                      "msg:\"TEMPLATE Test Rule\"; "
+                                      "template_rust_buffer; content:\"World!\"; "
+                                      "sid:1; rev:1;)");
     FAIL_IF_NULL(s);
 
     /* This rule should not match. */
-    s = DetectEngineAppendSig(de_ctx,
-        "alert tcp any any -> any any ("
-        "msg:\"TEMPLATE Test Rule\"; "
-        "template_rust_buffer; content:\"W0rld!\"; "
-        "sid:2; rev:1;)");
+    s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any ("
+                                      "msg:\"TEMPLATE Test Rule\"; "
+                                      "template_rust_buffer; content:\"W0rld!\"; "
+                                      "sid:2; rev:1;)");
     FAIL_IF_NULL(s);
 
     SigGroupBuild(de_ctx);
     DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);
 
-    AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST,
-                        STREAM_TOSERVER, request, sizeof(request));
+    AppLayerParserParse(
+            NULL, alp_tctx, &f, ALPROTO_TEMPLATE_RUST, STREAM_TOSERVER, request, sizeof(request));
 
     /* Check that we have app-layer state. */
     FAIL_IF_NULL(f.alstate);
index 8778a6efe6274228efe9cbd0546514b1b8ca4c25..5e24a97f19dc3ac586d0d8603dedb2f4d23d0a29 100644 (file)
@@ -24,7 +24,6 @@
 #ifndef __DETECT_TEMPLATE_RUST_BUFFER_H__
 #define __DETECT_TEMPLATE_RUST_BUFFER_H__
 
-
 void DetectTemplateRustBufferRegister(void);
 
 #endif /* __DETECT_TEMPLATE_RUST_BUFFER_H__ */
index 83aed08a84d79df05b8b30cdaf76c96e44710d7f..1d7f5da241d7d8cc3ff04244dc7121467e97235c 100644 (file)
@@ -53,7 +53,7 @@
 #include "rust.h"
 
 typedef struct LogTemplateFileCtx_ {
-    uint32_t    flags;
+    uint32_t flags;
     OutputJsonCtx *eve_ctx;
 } LogTemplateFileCtx;
 
@@ -62,8 +62,8 @@ typedef struct LogTemplateLogThread_ {
     OutputJsonThreadCtx *ctx;
 } LogTemplateLogThread;
 
-static int JsonTemplateLogger(ThreadVars *tv, void *thread_data,
-    const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
+static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
+        void *state, void *tx, uint64_t tx_id)
 {
     SCLogNotice("JsonTemplateLogger");
     LogTemplateLogThread *thread = thread_data;
@@ -97,8 +97,7 @@ static void OutputTemplateLogDeInitCtxSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf,
-    OutputCtx *parent_ctx)
+static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
     OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;