diff options
author | 2023-12-18 14:18:25 +0000 | |
---|---|---|
committer | 2023-12-18 14:18:25 +0000 | |
commit | 8ebb7775a35b632d49a8f294d83ac786666631f3 (patch) | |
tree | 02ac5475274125170132b0a4d9f69bd67491a32c /internal/gtsmodel/headerfilter.go | |
parent | fix poll total vote double count (#2464) (diff) | |
download | gotosocial-8ebb7775a35b632d49a8f294d83ac786666631f3.tar.xz |
[feature] request blocking by http headers (#2409)
Diffstat (limited to 'internal/gtsmodel/headerfilter.go')
-rw-r--r-- | internal/gtsmodel/headerfilter.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/gtsmodel/headerfilter.go b/internal/gtsmodel/headerfilter.go new file mode 100644 index 000000000..d1fcb146e --- /dev/null +++ b/internal/gtsmodel/headerfilter.go @@ -0,0 +1,54 @@ +// GoToSocial +// Copyright (C) GoToSocial Authors admin@gotosocial.org +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +package gtsmodel + +import ( + "time" + "unsafe" +) + +func init() { + // Note that since all of the below calculations are + // constant, these should be optimized out of builds. + const filterSz = unsafe.Sizeof(HeaderFilter{}) + if unsafe.Sizeof(HeaderFilterAllow{}) != filterSz { + panic("HeaderFilterAllow{} needs to have the same in-memory size / layout as HeaderFilter{}") + } + if unsafe.Sizeof(HeaderFilterBlock{}) != filterSz { + panic("HeaderFilterBlock{} needs to have the same in-memory size / layout as HeaderFilter{}") + } +} + +// HeaderFilterAllow represents an allow HTTP header filter in the database. +type HeaderFilterAllow struct{ HeaderFilter } + +// HeaderFilterBlock represents a block HTTP header filter in the database. +type HeaderFilterBlock struct{ HeaderFilter } + +// HeaderFilter represents an HTTP request filter in +// the database, with a header to match against, value +// matching regex, and details about its creation. +type HeaderFilter struct { + ID string `bun:"type:CHAR(26),pk,nullzero,notnull,unique"` // ID of this item in the database + Header string `bun:",nullzero,notnull,unique:header_regex"` // Request header this filter pertains to + Regex string `bun:",nullzero,notnull,unique:header_regex"` // Request header value matching regular expression + AuthorID string `bun:"type:CHAR(26),nullzero,notnull"` // Account ID of the creator of this filter + Author *Account `bun:"-"` // Account corresponding to AuthorID + CreatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item created + UpdatedAt time.Time `bun:"type:timestamptz,nullzero,notnull,default:current_timestamp"` // when was item last updated +} |