00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 00006 // 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_POST_MASTER_INTERFACES_HH__ 00026 #define __XRD_CL_POST_MASTER_INTERFACES_HH__ 00027 00028 #include "XrdCl/XrdClXRootDResponses.hh" 00029 00030 #include <stdint.h> 00031 #include <ctime> 00032 00033 #include "XrdCl/XrdClStatus.hh" 00034 #include "XrdCl/XrdClAnyObject.hh" 00035 #include "XrdCl/XrdClURL.hh" 00036 00037 class XrdNetAddr; 00038 00039 namespace XrdCl 00040 { 00041 class Channel; 00042 class Message; 00043 class URL; 00044 class Socket; 00045 00046 //---------------------------------------------------------------------------- 00048 //---------------------------------------------------------------------------- 00049 class MessageFilter 00050 { 00051 public: 00052 virtual ~MessageFilter() {} 00053 00054 //------------------------------------------------------------------------ 00057 //------------------------------------------------------------------------ 00058 virtual bool Filter( const Message *msg ) = 0; 00059 00060 //------------------------------------------------------------------------ 00064 //------------------------------------------------------------------------ 00065 virtual uint16_t GetSid() const = 0; 00066 }; 00067 00068 //---------------------------------------------------------------------------- 00070 //---------------------------------------------------------------------------- 00071 class IncomingMsgHandler 00072 { 00073 public: 00074 //------------------------------------------------------------------------ 00076 //------------------------------------------------------------------------ 00077 enum Action 00078 { 00079 Take = 0x0001, 00080 Ignore = 0x0002, 00081 RemoveHandler = 0x0004, 00082 00083 Raw = 0x0008, 00084 00085 00086 NoProcess = 0x0010 00087 00088 00089 }; 00090 00091 //------------------------------------------------------------------------ 00093 //------------------------------------------------------------------------ 00094 enum StreamEvent 00095 { 00096 Ready = 1, 00097 Broken = 2, 00098 Timeout = 3, 00099 FatalError = 4 00100 }; 00101 00102 //------------------------------------------------------------------------ 00104 //------------------------------------------------------------------------ 00105 00106 virtual ~IncomingMsgHandler() {} 00107 00108 //------------------------------------------------------------------------ 00114 //------------------------------------------------------------------------ 00115 virtual uint16_t Examine( Message *msg ) = 0; 00116 00117 //------------------------------------------------------------------------ 00121 //------------------------------------------------------------------------ 00122 virtual uint16_t GetSid() const = 0; 00123 00124 //------------------------------------------------------------------------ 00128 //------------------------------------------------------------------------ 00129 virtual void Process( Message *msg ) { (void)msg; }; 00130 00131 //------------------------------------------------------------------------ 00141 //------------------------------------------------------------------------ 00142 virtual Status ReadMessageBody( Message *msg, 00143 Socket *socket, 00144 uint32_t &bytesRead ) 00145 { 00146 (void)msg; (void)socket; (void)bytesRead; 00147 return Status( stOK, suDone ); 00148 }; 00149 00150 //------------------------------------------------------------------------ 00156 //------------------------------------------------------------------------ 00157 virtual uint8_t OnStreamEvent( StreamEvent event, 00158 XRootDStatus status ) 00159 { 00160 (void)event; (void)status; 00161 return 0; 00162 }; 00163 }; 00164 00165 //---------------------------------------------------------------------------- 00167 //---------------------------------------------------------------------------- 00168 class OutgoingMsgHandler 00169 { 00170 public: 00171 virtual ~OutgoingMsgHandler() {} 00172 00173 //------------------------------------------------------------------------ 00175 //------------------------------------------------------------------------ 00176 virtual void OnStatusReady( const Message *message, 00177 XRootDStatus status ) = 0; 00178 00179 //------------------------------------------------------------------------ 00186 //------------------------------------------------------------------------ 00187 virtual void OnReadyToSend( Message *msg ) 00188 { 00189 (void)msg; 00190 }; 00191 00192 //------------------------------------------------------------------------ 00196 //------------------------------------------------------------------------ 00197 virtual bool IsRaw() const { return false; } 00198 00199 //------------------------------------------------------------------------ 00208 //------------------------------------------------------------------------ 00209 virtual Status WriteMessageBody( Socket *socket, 00210 uint32_t &bytesWritten ) 00211 { 00212 (void)socket; (void)bytesWritten; 00213 return Status(); 00214 } 00215 }; 00216 00217 //---------------------------------------------------------------------------- 00219 //---------------------------------------------------------------------------- 00220 class ChannelEventHandler 00221 { 00222 public: 00223 //------------------------------------------------------------------------ 00225 //------------------------------------------------------------------------ 00226 enum ChannelEvent 00227 { 00228 StreamReady = 1, 00229 StreamBroken = 2, 00230 FatalError = 4 00231 }; 00232 00233 //------------------------------------------------------------------------ 00235 //------------------------------------------------------------------------ 00236 virtual ~ChannelEventHandler() {}; 00237 00238 //------------------------------------------------------------------------ 00246 //------------------------------------------------------------------------ 00247 virtual bool OnChannelEvent( ChannelEvent event, 00248 Status status ) = 0; 00249 }; 00250 00251 //---------------------------------------------------------------------------- 00253 //---------------------------------------------------------------------------- 00254 00255 struct HandShakeData 00256 { 00257 //-------------------------------------------------------------------------- 00259 //-------------------------------------------------------------------------- 00260 HandShakeData( const URL *addr, uint16_t subStream ): 00261 step(0), out(0), in(0), url(addr), subStreamId( subStream ), 00262 startTime( time(0) ), serverAddr(0) 00263 {} 00264 uint16_t step; 00265 Message *out; 00266 Message *in; 00267 const URL *url; 00268 uint16_t subStreamId; 00269 time_t startTime; 00270 const 00271 XrdNetAddr *serverAddr; 00272 std::string clientName; 00273 std::string streamName; 00274 }; 00275 00276 //---------------------------------------------------------------------------- 00279 //---------------------------------------------------------------------------- 00280 struct PathID 00281 { 00282 PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {} 00283 uint16_t up; 00284 uint16_t down; 00285 }; 00286 00287 //---------------------------------------------------------------------------- 00290 //---------------------------------------------------------------------------- 00291 struct TransportQuery 00292 { 00293 static const uint16_t Name = 1; 00294 static const uint16_t Auth = 2; 00295 }; 00296 00297 //---------------------------------------------------------------------------- 00299 //---------------------------------------------------------------------------- 00300 class TransportHandler 00301 { 00302 public: 00303 00304 //------------------------------------------------------------------------ 00306 //------------------------------------------------------------------------ 00307 enum StreamAction 00308 { 00309 NoAction = 0x0000, 00310 DigestMsg = 0x0001, 00311 00312 AbortStream = 0x0002, 00313 00314 00315 CloseStream = 0x0004, 00316 00317 ResumeStream = 0x0008, 00318 00319 HoldStream = 0x0010, 00320 RequestClose = 0x0020 00321 }; 00322 00323 00324 virtual ~TransportHandler() {} 00325 00326 //------------------------------------------------------------------------ 00337 //------------------------------------------------------------------------ 00338 virtual Status GetHeader( Message *message, Socket *socket ) = 0; 00339 00340 //------------------------------------------------------------------------ 00349 //------------------------------------------------------------------------ 00350 virtual Status GetBody( Message *message, Socket *socket ) = 0; 00351 00352 //------------------------------------------------------------------------ 00354 //------------------------------------------------------------------------ 00355 virtual void InitializeChannel( const URL &url, 00356 AnyObject &channelData ) = 0; 00357 00358 //------------------------------------------------------------------------ 00360 //------------------------------------------------------------------------ 00361 virtual void FinalizeChannel( AnyObject &channelData ) = 0; 00362 00363 //------------------------------------------------------------------------ 00365 //------------------------------------------------------------------------ 00366 virtual Status HandShake( HandShakeData *handShakeData, 00367 AnyObject &channelData ) = 0; 00368 00369 //------------------------------------------------------------------------ 00370 // @return true if handshake has been done and stream is connected, 00371 // false otherwise 00372 //------------------------------------------------------------------------ 00373 virtual bool HandShakeDone( HandShakeData *handShakeData, 00374 AnyObject &channelData ) = 0; 00375 00376 //------------------------------------------------------------------------ 00378 //------------------------------------------------------------------------ 00379 virtual bool IsStreamTTLElapsed( time_t inactiveTime, 00380 AnyObject &channelData ) = 0; 00381 00382 //------------------------------------------------------------------------ 00385 //------------------------------------------------------------------------ 00386 virtual Status IsStreamBroken( time_t inactiveTime, 00387 AnyObject &channelData ) = 0; 00388 00389 //------------------------------------------------------------------------ 00395 //------------------------------------------------------------------------ 00396 virtual PathID Multiplex( Message *msg, 00397 AnyObject &channelData, 00398 PathID *hint = 0 ) = 0; 00399 00400 //------------------------------------------------------------------------ 00406 //------------------------------------------------------------------------ 00407 virtual PathID MultiplexSubStream( Message *msg, 00408 AnyObject &channelData, 00409 PathID *hint = 0 ) = 0; 00410 00411 //------------------------------------------------------------------------ 00413 //------------------------------------------------------------------------ 00414 virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0; 00415 00416 //------------------------------------------------------------------------ 00418 //------------------------------------------------------------------------ 00419 virtual void Disconnect( AnyObject &channelData, 00420 uint16_t subStreamId ) = 0; 00421 00422 //------------------------------------------------------------------------ 00424 //------------------------------------------------------------------------ 00425 virtual Status Query( uint16_t query, 00426 AnyObject &result, 00427 AnyObject &channelData ) = 0; 00428 00429 //------------------------------------------------------------------------ 00431 //------------------------------------------------------------------------ 00432 virtual uint32_t MessageReceived( Message *msg, 00433 uint16_t subStream, 00434 AnyObject &channelData ) = 0; 00435 00436 //------------------------------------------------------------------------ 00438 //------------------------------------------------------------------------ 00439 virtual void MessageSent( Message *msg, 00440 uint16_t subStream, 00441 uint32_t bytesSent, 00442 AnyObject &channelData ) = 0; 00443 00444 //------------------------------------------------------------------------ 00446 //------------------------------------------------------------------------ 00447 virtual void WaitBeforeExit() = 0; 00448 00449 //------------------------------------------------------------------------ 00451 //------------------------------------------------------------------------ 00452 virtual bool NeedEncryption( HandShakeData *handShakeData, 00453 AnyObject &channelData ) = 0; 00454 00455 //------------------------------------------------------------------------ 00457 //------------------------------------------------------------------------ 00458 virtual Status GetSignature( Message *toSign, Message *&sign, 00459 AnyObject &channelData ) = 0; 00460 }; 00461 } 00462 00463 #endif // __XRD_CL_POST_MASTER_INTERFACES_HH__