+// RPC primitives for safcm: message and additional types
+
+// Copyright (C) 2021 Simon Ruderich
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package safcm
+
+import (
+ "encoding/gob"
+ "io/fs"
+)
+
+// Messages
+
+type Msg interface {
+ msg() // unused, only to implement interface
+}
+
+type MsgLog struct {
+ Level LogLevel
+ Text string
+}
+
+type MsgInfoReq struct {
+ LogLevel LogLevel
+
+ DetectGroups []string
+}
+type MsgInfoResp struct {
+ Goos string
+ Goarch string
+
+ Output []string
+ Error string
+}
+
+type MsgSyncReq struct {
+ DryRun bool
+ Groups []string // for commands
+
+ Files map[string]*File
+ Packages []string
+ Services []string
+ Commands []string
+}
+type MsgSyncResp struct {
+ FileChanges []FileChange
+ PackageChanges []PackageChange
+ ServiceChanges []ServiceChange
+ CommandChanges []CommandChange
+
+ Error string
+}
+
+type MsgQuitReq struct {
+}
+type MsgQuitResp struct {
+}
+
+func (MsgLog) msg() {}
+func (MsgInfoReq) msg() {}
+func (MsgInfoResp) msg() {}
+func (MsgSyncReq) msg() {}
+func (MsgSyncResp) msg() {}
+func (MsgQuitReq) msg() {}
+func (MsgQuitResp) msg() {}
+
+func init() {
+ // Necessary to receive "into" an interface type
+ gob.Register(MsgLog{})
+ gob.Register(MsgInfoReq{})
+ gob.Register(MsgInfoResp{})
+ gob.Register(MsgSyncReq{})
+ gob.Register(MsgSyncResp{})
+ gob.Register(MsgQuitReq{})
+ gob.Register(MsgQuitResp{})
+}
+
+// Types used in messages
+
+type File struct {
+ OrigGroup string // group which provided this file
+
+ Path string
+
+ Mode fs.FileMode
+ User string
+ Uid int //lint:ignore ST1003 UID is too ugly
+ Group string
+ Gid int //lint:ignore ST1003 GID is too ugly
+
+ Data []byte
+
+ TriggerCommands []string
+}
+
+type FileChange struct {
+ Path string
+ Created bool
+ Old FileChangeInfo
+ New FileChangeInfo
+ DataDiff string
+}
+type FileChangeInfo struct {
+ Mode fs.FileMode
+ User string
+ Uid int //lint:ignore ST1003 UID is too ugly
+ Group string
+ Gid int //lint:ignore ST1003 GID is too ugly
+}
+
+type PackageChange struct {
+ Name string
+}
+
+type ServiceChange struct {
+ Name string
+ Started bool
+ Enabled bool
+}
+
+type CommandChange struct {
+ Command string
+ Trigger string // path which triggered this command (optional)
+ Output string // stdout and stderr combined
+ Error string
+}