]> git.giacomolli.uk - onechat/blob - socket.go
Order model and chat declarations
[onechat] / socket.go
1 package main
2
3 import (
4 "fmt"
5 )
6
7 const (
8 // socketFileName is the Unix socket of the daemon in the data
9 // directory.
10 socketFileName = "onechat.sock"
11
12 // socketRequestBytes is the most bytes of one request line of a client.
13 socketRequestBytes = 16 << 20
14
15 // socketPathBytes is the longest path of a Unix socket on Linux.
16 socketPathBytes = 107
17
18 // terminalSource is the source of the user messages from the clients of
19 // the socket.
20 terminalSource = "terminal"
21 )
22
23 // SocketRequest is one line from a client: "send" with the text of a user
24 // message, "interrupt", "stop" with the name of a subagent in Text, or
25 // "whatsapp" with the text after /whatsapp of a WhatsApp command, or "backup"
26 // with the absolute output path in Text. The backup answer is a "backup" event
27 // with the path and size, or an "error" event. An "image" request has an
28 // absolute Path and the caption in Text.
29 type SocketRequest struct {
30 Type string `json:"type"`
31 Text string `json:"text,omitempty"`
32 Path string `json:"path,omitempty"`
33 }
34
35 // checkSocketPath makes sure that path fits in the address of a Unix socket.
36 func checkSocketPath(path string) error {
37 if len(path) > socketPathBytes {
38 return fmt.Errorf("socket path %s is longer than %d bytes: set ONECHAT_DIR to a shorter path", path, socketPathBytes)
39 }
40
41 return nil
42 }