From 01ea74f8a894803d845751f20decb58bdc54d061 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 5 Sep 2024 17:00:37 +0200 Subject: [PATCH 1/5] pre-commit: Add spicy-format This excludes the larger protocol analyzers. These should be formatted during the 7.2 cycle, shortly before 8.0. --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3336960177..e5638912cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,3 +32,10 @@ repos: hooks: - id: typos exclude: '^(.typos.toml|src/SmithWaterman.cc|testing/.*|auxil/.*|scripts/base/frameworks/files/magic/.*|CHANGES)$' + +- repo: https://github.com/bbannier/spicy-format + rev: v0.15.0 + hooks: + - id: spicy-format + # TODO: Reformat existing large analyzers just before 8.0. + exclude: '(^testing/.*)|(protocol/ldap/.*)|(protocol/quic/.*)|(protocol/websocket/.*)' From cde566277977aa101221c7833dfb2d5aa3718a6a Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 5 Sep 2024 17:01:26 +0200 Subject: [PATCH 2/5] scripts/spicy: Reformat with spicy-format --- scripts/spicy/zeek.spicy | 1 - scripts/spicy/zeek_file.spicy | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/spicy/zeek.spicy b/scripts/spicy/zeek.spicy index cc24f96117..ceaf5ca3b1 100644 --- a/scripts/spicy/zeek.spicy +++ b/scripts/spicy/zeek.spicy @@ -507,4 +507,3 @@ public function vector_size(id: string): uint64 &cxxname="zeek::spicy::rt::vecto ## ## v: opaque handle to the Zeek vector, as returned by other functions public function vector_size(v: ZeekVector): uint64 &cxxname="zeek::spicy::rt::vector_size"; - diff --git a/scripts/spicy/zeek_file.spicy b/scripts/spicy/zeek_file.spicy index 71082f9be9..c355a9a4cb 100644 --- a/scripts/spicy/zeek_file.spicy +++ b/scripts/spicy/zeek_file.spicy @@ -16,15 +16,19 @@ import zeek; ## size: Total number of bytes the file contains, if known; will be passed on to Zeek public type File = unit(mime_type: optional = Null, size: optional = Null) { on %init { - self.fid = zeek::file_begin(mime_type); + self.fid = zeek::file_begin(mime_type); - if ( size ) - zeek::file_set_size(*size, self.fid); + if (size) + zeek::file_set_size(*size, self.fid); } - : bytes &chunked &eod { zeek::file_data_in($$, self.fid); } + : bytes &chunked &eod { + zeek::file_data_in($$, self.fid); + } - on %finally { zeek::file_end(self.fid); } + on %finally { + zeek::file_end(self.fid); + } ## Zeek-side file ID var fid: string; From dae4b1fcd9ee1347f4e87a8c5f05f1f3357ad60b Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 5 Sep 2024 17:02:05 +0200 Subject: [PATCH 3/5] analyzer/finger: Reformat with spicy-format --- src/analyzer/protocol/finger/finger.spicy | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/analyzer/protocol/finger/finger.spicy b/src/analyzer/protocol/finger/finger.spicy index 0d6a8da54e..1e2e4dce06 100644 --- a/src/analyzer/protocol/finger/finger.spicy +++ b/src/analyzer/protocol/finger/finger.spicy @@ -8,13 +8,15 @@ module Finger; import spicy; const OptionalWhiteSpace = /[ \t]*/; -const NewLine = /\r?\n/; +const NewLine = /\r?\n/; -public type Request = unit { +public type Request = unit { : OptionalWhiteSpace; switch { - -> : /\/W/ { self.whois = True; } + -> : /\/W/ { + self.whois = True; + } -> : void; }; @@ -24,12 +26,12 @@ public type Request = unit { # We require valid UTF-8 to weed out binary data. self.user = self.arg[0].decode(); - if ( |self.arg[1]| > 0 ) + if (|self.arg[1]| > 0) self.host = self.arg[1].decode(); } - on %done { - if ( |self.arg[0]| > 0 || self.whois ) + on %done { + if (|self.arg[0]| > 0 || self.whois) spicy::accept_input(); } @@ -43,12 +45,12 @@ type ReplyLine = unit { : NewLine; on %done { - if ( |self.data| > 10 ) + if (|self.data| > 10) # Require some non-trivial output to accept. spicy::accept_input(); } }; -public type Reply = unit { +public type Reply = unit { : ReplyLine[]; }; From 526c903c0174069d466e491b451b284a1bf16c30 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 5 Sep 2024 17:02:21 +0200 Subject: [PATCH 4/5] analyzer/syslog: Reformat with spicy-format --- src/analyzer/protocol/syslog/syslog.spicy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyzer/protocol/syslog/syslog.spicy b/src/analyzer/protocol/syslog/syslog.spicy index ba8c8a77aa..67271a6d41 100644 --- a/src/analyzer/protocol/syslog/syslog.spicy +++ b/src/analyzer/protocol/syslog/syslog.spicy @@ -15,7 +15,7 @@ public type Message = unit { on %done { spicy::accept_input(); - if ( self?.prio ) { + if (self?.prio) { self.severity = (self.prio.value & 0x07); self.facility = (self.prio.value & 0x03f8) >> 3; } From f35835c8f9bc4c4e1c342d638ab504c413af6fef Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 5 Sep 2024 17:53:09 +0200 Subject: [PATCH 5/5] testing/external: Update private baselines --- testing/external/commit-hash.zeek-testing-private | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/external/commit-hash.zeek-testing-private b/testing/external/commit-hash.zeek-testing-private index 9d834eb6e3..cc9b7785c9 100644 --- a/testing/external/commit-hash.zeek-testing-private +++ b/testing/external/commit-hash.zeek-testing-private @@ -1 +1 @@ -e051f29d1f03f2264b8cf1ff5ed9bfba9d326c45 +d3d50408e762ba06fcae0694e09ab59248ff5308