summaryrefslogtreecommitdiff
path: root/finger
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
commit23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 (patch)
treeec8113d3aa2379e3ca9cb3c6e13a5531895ea8c0 /finger
parent57a31a9b2cd549174d839b9b91b47db337f174cc (diff)
move common types to an internal package
This helps avoid import cycles.
Diffstat (limited to 'finger')
-rw-r--r--finger/client.go8
-rw-r--r--finger/request.go6
-rw-r--r--finger/response.go10
-rw-r--r--finger/serve.go8
-rw-r--r--finger/system.go6
5 files changed, 19 insertions, 19 deletions
diff --git a/finger/client.go b/finger/client.go
index 8ebf3ca..75a382f 100644
--- a/finger/client.go
+++ b/finger/client.go
@@ -7,7 +7,7 @@ import (
"net"
"strings"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// Client is used for sending finger requests and reading responses.
@@ -18,7 +18,7 @@ import (
type Client struct{}
// RoundTrip sends a single finger request and returns its response.
-func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) {
+func (c Client) RoundTrip(request *types.Request) (*types.Response, error) {
if request.Scheme != "finger" && request.Scheme != "" {
return nil, errors.New("non-finger protocols not supported")
}
@@ -46,11 +46,11 @@ func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) {
return nil, err
}
- return &sr.Response{Body: bytes.NewBuffer(response)}, nil
+ return &types.Response{Body: bytes.NewBuffer(response)}, nil
}
// Fetch resolves a finger query.
-func (c Client) Fetch(query string) (*sr.Response, error) {
+func (c Client) Fetch(query string) (*types.Response, error) {
req, err := ParseRequest(bytes.NewBufferString(query + "\r\n"))
if err != nil {
return nil, err
diff --git a/finger/request.go b/finger/request.go
index a18ff7e..b0ef102 100644
--- a/finger/request.go
+++ b/finger/request.go
@@ -7,7 +7,7 @@ import (
"net/url"
"strings"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// ForwardingDenied is returned in response to requests for forwarding service.
@@ -47,7 +47,7 @@ var InvalidFingerQuery = errors.New("Invalid finger query.")
// In accordance with the recommendation of RFC 1288 section 3.2.1
// (https://datatracker.ietf.org/doc/html/rfc1288#section-3.2.1), any queries which
// include a jump-host (user@host1@host2) are rejected with the ForwardingDenied error.
-func ParseRequest(rdr io.Reader) (*sr.Request, error) {
+func ParseRequest(rdr io.Reader) (*types.Request, error) {
line, err := bufio.NewReader(rdr).ReadString('\n')
if err != nil {
return nil, err
@@ -66,7 +66,7 @@ func ParseRequest(rdr io.Reader) (*sr.Request, error) {
return nil, ForwardingDenied
}
- return &sr.Request{URL: &url.URL{
+ return &types.Request{URL: &url.URL{
Scheme: "finger",
Host: hostname,
Path: "/" + username,
diff --git a/finger/response.go b/finger/response.go
index 8612f45..db2dfb0 100644
--- a/finger/response.go
+++ b/finger/response.go
@@ -5,18 +5,18 @@ import (
"io"
"strings"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// Error produces a finger Response containing the error message and Status 1.
-func Error(msg string) *sr.Response {
+func Error(msg string) *types.Response {
if !strings.HasSuffix(msg, "\r\n") {
msg += "\r\n"
}
- return &sr.Response{Body: bytes.NewBufferString(msg), Status: 1}
+ return &types.Response{Body: bytes.NewBufferString(msg), Status: 1}
}
// Success produces a finger response with a Status of 0.
-func Success(body io.Reader) *sr.Response {
- return &sr.Response{Body: body}
+func Success(body io.Reader) *types.Response {
+ return &types.Response{Body: body}
}
diff --git a/finger/serve.go b/finger/serve.go
index 6456763..ff842e1 100644
--- a/finger/serve.go
+++ b/finger/serve.go
@@ -6,14 +6,14 @@ import (
"io"
"net"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
"tildegit.org/tjp/sliderule/internal"
"tildegit.org/tjp/sliderule/logging"
)
type fingerServer struct {
internal.Server
- handler sr.Handler
+ handler types.Handler
}
func (fs fingerServer) Protocol() string { return "FINGER" }
@@ -24,9 +24,9 @@ func NewServer(
hostname string,
network string,
address string,
- handler sr.Handler,
+ handler types.Handler,
errLog logging.Logger,
-) (sr.Server, error) {
+) (types.Server, error) {
fs := &fingerServer{handler: handler}
hostname = internal.JoinDefaultPort(hostname, "79")
diff --git a/finger/system.go b/finger/system.go
index aa2cc84..30ee1e8 100644
--- a/finger/system.go
+++ b/finger/system.go
@@ -6,15 +6,15 @@ import (
"errors"
"os/exec"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// ListingDenied is returned to reject online user listing requests.
var ListingDenied = errors.New("Finger online user list denied.")
// SystemFinger handles finger requests by invoking the finger(1) command-line utility.
-func SystemFinger(allowListings bool) sr.Handler {
- return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
+func SystemFinger(allowListings bool) types.Handler {
+ return types.HandlerFunc(func(ctx context.Context, request *types.Request) *types.Response {
fingerPath, err := exec.LookPath("finger")
if err != nil {
_ = request.Server.LogError(