go-hep.org/x/hep@v0.38.1/xrootd/default_handler.go (about)

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