/
default_handler.go
133 lines (112 loc) · 5.81 KB
/
default_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright ©2018 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xrootd // import "go-hep.org/x/hep/xrootd"
import (
"go-hep.org/x/hep/xrootd/xrdproto"
"go-hep.org/x/hep/xrootd/xrdproto/dirlist"
"go-hep.org/x/hep/xrootd/xrdproto/handshake"
"go-hep.org/x/hep/xrootd/xrdproto/login"
"go-hep.org/x/hep/xrootd/xrdproto/mkdir"
"go-hep.org/x/hep/xrootd/xrdproto/mv"
"go-hep.org/x/hep/xrootd/xrdproto/open"
"go-hep.org/x/hep/xrootd/xrdproto/ping"
"go-hep.org/x/hep/xrootd/xrdproto/protocol"
"go-hep.org/x/hep/xrootd/xrdproto/read"
"go-hep.org/x/hep/xrootd/xrdproto/rm"
"go-hep.org/x/hep/xrootd/xrdproto/rmdir"
"go-hep.org/x/hep/xrootd/xrdproto/stat"
"go-hep.org/x/hep/xrootd/xrdproto/sync"
"go-hep.org/x/hep/xrootd/xrdproto/truncate"
"go-hep.org/x/hep/xrootd/xrdproto/write"
"go-hep.org/x/hep/xrootd/xrdproto/xrdclose"
)
// defaultHandler implements Handler with some general functionality added.
// Any unimplemented request returns InvalidRequest error.
type defaultHandler struct {
}
// Default returns the defaultHandler implementing Handler with some general functionality added.
// Any unimplemented request returns InvalidRequest error.
func Default() Handler {
return &defaultHandler{}
}
// Login implements Handler.Login.
func (h *defaultHandler) Login(sessionID [16]byte, request *login.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
return &login.Response{SessionID: sessionID}, xrdproto.Ok
}
// Protocol implements Handler.Protocol.
func (h *defaultHandler) Protocol(sessionID [16]byte, request *protocol.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := &protocol.Response{BinaryProtocolVersion: 0x310, Flags: protocol.IsServer}
return resp, xrdproto.Ok
}
// Ping implements Handler.Ping.
func (h *defaultHandler) Ping(sessionID [16]byte, request *ping.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
return nil, xrdproto.Ok
}
// Dirlist implements Handler.Dirlist.
func (h *defaultHandler) Dirlist(sessionID [16]byte, request *dirlist.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Dirlist request is not implemented"}
return resp, xrdproto.Error
}
// Handshake implements Handler.Handshake.
func (*defaultHandler) Handshake() (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := handshake.Response{ProtocolVersion: 0x310, ServerType: xrdproto.DataServer}
return &resp, xrdproto.Ok
}
// CloseSession implements Handler.CloseSession.
func (h *defaultHandler) CloseSession(sessionID [16]byte) error { return nil }
// Open implements Handler.Open.
func (h *defaultHandler) Open(sessionID [16]byte, request *open.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Open request is not implemented"}
return resp, xrdproto.Error
}
// Close implements Handler.Close.
func (h *defaultHandler) Close(sessionID [16]byte, request *xrdclose.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Close request is not implemented"}
return resp, xrdproto.Error
}
// Read implements Handler.Read.
func (h *defaultHandler) Read(sessionID [16]byte, request *read.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Read request is not implemented"}
return resp, xrdproto.Error
}
// Write implements Handler.Write.
func (h *defaultHandler) Write(sessionID [16]byte, request *write.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Write request is not implemented"}
return resp, xrdproto.Error
}
// Stat implements Handler.Stat.
func (h *defaultHandler) Stat(sessionID [16]byte, request *stat.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Stat request is not implemented"}
return resp, xrdproto.Error
}
// Sync implements Handler.Sync.
func (h *defaultHandler) Sync(sessionID [16]byte, request *sync.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Sync request is not implemented"}
return resp, xrdproto.Error
}
// Truncate implements Handler.Truncate.
func (h *defaultHandler) Truncate(sessionID [16]byte, request *truncate.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Truncate request is not implemented"}
return resp, xrdproto.Error
}
// Rename implements Handler.Rename.
func (h *defaultHandler) Rename(sessionID [16]byte, request *mv.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Rename request is not implemented"}
return resp, xrdproto.Error
}
// Mkdir implements Handler.Mkdir.
func (h *defaultHandler) Mkdir(sessionID [16]byte, request *mkdir.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Mkdir request is not implemented"}
return resp, xrdproto.Error
}
// Remove implements Handler.Remove.
func (h *defaultHandler) Remove(sessionID [16]byte, request *rm.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "Remove request is not implemented"}
return resp, xrdproto.Error
}
// RemoveDir implements Handler.RemoveDir.
func (h *defaultHandler) RemoveDir(sessionID [16]byte, request *rmdir.Request) (xrdproto.Marshaler, xrdproto.ResponseStatus) {
resp := xrdproto.ServerError{Code: xrdproto.InvalidRequest, Message: "RemoveDir request is not implemented"}
return resp, xrdproto.Error
}