Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:52

0001 #ifndef __XrdProtocol_H__
0002 #define __XrdProtocol_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d P r o t o c o l . h h                         */
0006 /*                                                                            */
0007 /*(c) 2004-18 By the Board of Trustees of the Leland Stanford, Jr., University*/
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 #include "Xrd/XrdJob.hh"
0033  
0034 /******************************************************************************/
0035 /*                    X r d P r o t o c o l _ C o n f i g                     */
0036 /******************************************************************************/
0037   
0038 // The following class is passed to the XrdgetProtocol() and XrdgetProtocolPort()
0039 // functions to properly configure the protocol. This object is not stable and 
0040 // the protocol must copy out any values it desires to keep. It may copy the 
0041 // whole object using the supplied copy constructor.
0042 
0043 class XrdSysError;
0044 union XrdNetSockAddr;
0045 class XrdOucEnv;
0046 class XrdOucString;
0047 class XrdBuffManager;
0048 class XrdInet;
0049 class XrdScheduler;
0050 class XrdStats;
0051 class XrdTlsContext;
0052 
0053 struct sockaddr;
0054 
0055 class XrdProtocol_Config
0056 {
0057 public:
0058 
0059 // The following pointers may be copied; they are stable.
0060 //
0061 XrdSysError    *eDest;       // Stable -> Error Message/Logging Handler
0062 XrdInet        *NetTCP;      // Stable -> Network Object    (@ XrdgetProtocol)
0063 XrdBuffManager *BPool;       // Stable -> Buffer Pool Manager
0064 XrdScheduler   *Sched;       // Stable -> System Scheduler
0065 XrdStats       *Stats;       // Stable -> System Statistics (@ XrdgetProtocol)
0066 XrdOucEnv      *theEnv;      // Stable -> Additional environmental information
0067 void           *rsvd0;
0068 
0069 // The following information must be duplicated; it is unstable.
0070 //
0071 char            *ConfigFN;     // -> Configuration file
0072 int              Format;       // Binary format of this server
0073 int              Port;         // Port number
0074 int              WSize;        // Window size for Port
0075 int              rsvd1;
0076 const char      *AdmPath;      // Admin path
0077 int              AdmMode;      // Admin path mode
0078 int              xrdFlags;
0079 static const int admPSet    = 0x00000001;  // The adminppath was set via cli
0080 
0081 const char      *myInst;       // Instance name
0082 const char      *myName;       // Host name
0083 const char      *myProg;       // Program name
0084 union {
0085 const
0086 XrdNetSockAddr  *urAddr;       // Host Address (the actual structure/union)
0087 const
0088 struct sockaddr *myAddr;       // Host address
0089       };
0090 int              ConnMax;      // Max connections
0091 int              readWait;     // Max milliseconds to wait for data
0092 int              idleWait;     // Max milliseconds connection may be idle
0093 int              argc;         // Number of arguments
0094 char           **argv;         // Argument array (prescreened)
0095 char             DebugON;      // True if started with -d option
0096 char             rsvd3[7];
0097 int              hailWait;     // Max milliseconds to wait for data after accept
0098 int              tlsPort;      // Default TLS port (0 if not specified)
0099 XrdTlsContext   *tlsCtx;       // Stable -> TLS Context (0 if not initialized)
0100 XrdOucString    *totalCF;      // Stable -> total config after full init
0101 
0102                  XrdProtocol_Config(XrdProtocol_Config &rhs) =delete;
0103                  XrdProtocol_Config() : rsvd0(0), rsvd1(0)
0104                                         {memset(rsvd3, 0, sizeof(rsvd3));}
0105                 ~XrdProtocol_Config() {}
0106 };
0107 
0108 /******************************************************************************/
0109 /*                           X r d P r o t o c o l                            */
0110 /******************************************************************************/
0111 
0112 // This class is used by the Link object to process the input stream on a link.
0113 // At least one protocol object exists per Link object. Specific protocols are 
0114 // derived from this pure abstract class since a link can use one of several 
0115 // protocols. Indeed, startup and shutdown are handled by specialized protocols.
0116 
0117 // System configuration obtains an instance of a protocol by calling
0118 // XrdgetProtocol(), which must exist in the shared library.
0119 // This instance is used as the base pointer for Alloc(), Configure(), and
0120 // Match(). Unfortuantely, they cannot be static given the silly C++ rules.
0121 
0122 class XrdLink;
0123   
0124 class XrdProtocol : public XrdJob
0125 {
0126 public:
0127 
0128 // Match()     is invoked when a new link is created and we are trying
0129 //             to determine if this protocol can handle the link. It must
0130 //             return a protocol object if it can and NULL (0), otherwise.
0131 //
0132 virtual XrdProtocol  *Match(XrdLink *lp) = 0;
0133 
0134 // Process()   is invoked when a link has data waiting to be read
0135 //
0136 virtual int           Process(XrdLink *lp) = 0;
0137 
0138 // Recycle()   is invoked when this object is no longer needed. The method is
0139 //             passed the number of seconds the protocol was connected to the
0140 //             link and the reason for the disconnection, if any.
0141 //
0142 virtual void          Recycle(XrdLink *lp=0,int consec=0,const char *reason=0)=0;
0143 
0144 // Stats()     is invoked when we need statistics about all instances of the
0145 //             protocol. If a buffer is supplied, it must return a null 
0146 //             terminated string in the supplied buffer and the return value
0147 //             is the number of bytes placed in the buffer defined by C99 for 
0148 //             snprintf(). If no buffer is supplied, the method should return
0149 //             the maximum number of characters that could have been returned.
0150 //             Regardless of the buffer value, if do_sync is true, the method
0151 //             should include any local statistics in the global data (if any)
0152 //             prior to performing any action.
0153 //
0154 virtual int           Stats(char *buff, int blen, int do_sync=0) = 0;
0155 
0156             XrdProtocol(const char *jname): XrdJob(jname) {}
0157 virtual    ~XrdProtocol() {}
0158 };
0159 
0160 /******************************************************************************/
0161 /*                        X r d g e t P r o t o c o l                         */
0162 /******************************************************************************/
0163   
0164 /* This extern "C" function must be defined in the shared library plug-in
0165    implementing your protocol. It is called to obtain an instance of your
0166    protocol. This allows protocols to live outside of the protocol driver
0167    (i.e., to be loaded at run-time). The call is made after the call to
0168    XrdgetProtocolPort() to determine the port to be used (see below) which
0169    allows e network object (NetTCP) to be proerly defined and it's pointer
0170    is passed in the XrdProtocol_Config object for your use.
0171 
0172    Required return values:
0173    Success: Pointer to XrdProtocol object.
0174    Failure: Null pointer (i.e. 0) which causes the program to exit.
0175 
0176 extern "C"  // This is in a comment!
0177 {
0178        XrdProtocol *XrdgetProtocol(const char *protocol_name, char *parms,
0179                                    XrdProtocol_Config *pi) {....}
0180 }
0181 */
0182   
0183 /******************************************************************************/
0184 /*                    X r d g e t P r o t o c o l P o r t                     */
0185 /******************************************************************************/
0186   
0187 /* This extern "C" function must be defined for statically linked protocols
0188    but is optional for protocols defined as a shared library plug-in if the
0189    rules determining which port number to use is sufficient for your protocol.
0190    The function is called to obtain the actual port number to be used by the
0191    the protocol. The default port number is noted in XrdProtocol_Config Port.
0192    Initially, it has one of the fllowing values:
0193    <0 -> No port was specified.
0194    =0 -> An erbitrary port will be assigned.
0195    >0 -> This port number was specified.
0196 
0197    XrdgetProtoclPort() must return:
0198    <0 -> Failure is indicated and we terminate
0199    =0 -> Use an arbitrary port (even if this equals Port)
0200    >0 -> The returned port number must be used (even if it equals Port)
0201 
0202    When we finally call XrdgetProtocol(), the actual port number is indicated
0203    in Port and the network object is defined in NetTCP and bound to the port.
0204 
0205    Final Caveats: 1.  The network object (NetTCP) is not defined until
0206                       XrdgetProtocol() is called.
0207 
0208                   2.  The statistics object (Stats) is not defined until
0209                       XrdgetProtocol() is called.
0210 
0211                   3.  When the protocol is loaded from a shared library, you need
0212                       need not define XrdgetProtocolPort() if the standard port
0213                       determination scheme is sufficient.
0214 
0215 extern "C"  // This is in a comment!
0216 {
0217        int XrdgetProtocolPort(const char *protocol_name, char *parms,
0218                               XrdProtocol_Config *pi) {....}
0219 }
0220 */
0221 #endif