xrootd
XrdClXRootDMsgHandler.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_XROOTD_MSG_HANDLER_HH__
20 #define __XRD_CL_XROOTD_MSG_HANDLER_HH__
21 
24 #include "XrdCl/XrdClDefaultEnv.hh"
25 #include "XrdCl/XrdClMessage.hh"
26 
27 namespace XrdCl
28 {
29  class PostMaster;
30  class SIDManager;
31  class URL;
32 
33  //----------------------------------------------------------------------------
35  //----------------------------------------------------------------------------
37  public OutgoingMsgHandler
38  {
39  public:
40  //------------------------------------------------------------------------
49  //------------------------------------------------------------------------
51  ResponseHandler *respHandler,
52  const URL *url,
53  SIDManager *sidMgr ):
54  pRequest( msg ),
55  pResponse( 0 ),
56  pResponseHandler( respHandler ),
57  pUrl( *url ),
58  pSidMgr( sidMgr ),
59  pExpiration( 0 ),
60  pRedirectAsAnswer( false ),
61  pHosts( 0 ),
62  pHasLoadBalancer( false ),
63  pHasSessionId( false ),
64  pChunkList( 0 ),
65  pRedirectCounter( 0 )
66  {
68  if( msg->GetSessionId() )
69  pHasSessionId = true;
70  }
71 
72  //------------------------------------------------------------------------
74  //------------------------------------------------------------------------
76  {
77  if( !pHasSessionId )
78  delete pRequest;
79  delete pResponse;
80  std::vector<Message *>::iterator it;
81  for( it = pPartialResps.begin(); it != pPartialResps.end(); ++it )
82  delete *it;
83  }
84 
85  //------------------------------------------------------------------------
91  //------------------------------------------------------------------------
92  virtual uint8_t OnIncoming( Message *msg );
93 
94 
95  //------------------------------------------------------------------------
101  //------------------------------------------------------------------------
102  virtual uint8_t OnStreamEvent( StreamEvent event,
103  uint16_t streamNum,
104  Status status );
105 
106  //------------------------------------------------------------------------
108  //------------------------------------------------------------------------
109  virtual void OnStatusReady( const Message *message,
110  Status status );
111 
112  //------------------------------------------------------------------------
116  //------------------------------------------------------------------------
117  void WaitDone( time_t now );
118 
119  //------------------------------------------------------------------------
121  //------------------------------------------------------------------------
122  void SetExpiration( time_t expiration )
123  {
124  pExpiration = expiration;
125  }
126 
127  //------------------------------------------------------------------------
130  //------------------------------------------------------------------------
131  void SetRedirectAsAnswer( bool redirectAsAnswer )
132  {
133  pRedirectAsAnswer = redirectAsAnswer;
134  }
135 
136  //------------------------------------------------------------------------
138  //------------------------------------------------------------------------
139  const Message *GetRequest() const
140  {
141  return pRequest;
142  }
143 
144  //------------------------------------------------------------------------
146  //------------------------------------------------------------------------
147  void SetLoadBalancer( const HostInfo &loadBalancer )
148  {
149  if( !loadBalancer.url.IsValid() )
150  return;
151  pLoadBalancer = loadBalancer;
152  pHasLoadBalancer = true;
153  }
154 
155  //------------------------------------------------------------------------
157  //------------------------------------------------------------------------
158  void SetHostList( HostList *hostList )
159  {
160  delete pHosts;
161  pHosts = hostList;
162  }
163 
164  //------------------------------------------------------------------------
166  //------------------------------------------------------------------------
167  void SetChunkList( ChunkList *chunkList )
168  {
169  pChunkList = chunkList;
170  }
171 
172  //------------------------------------------------------------------------
174  //------------------------------------------------------------------------
175  void SetRedirectCounter( uint16_t redirectCounter )
176  {
177  pRedirectCounter = redirectCounter;
178  }
179 
180  private:
181  //------------------------------------------------------------------------
183  //------------------------------------------------------------------------
184  void HandleError( Status status, Message *msg = 0 );
185 
186  //------------------------------------------------------------------------
188  //------------------------------------------------------------------------
189  Status RetryAtServer( const URL &url );
190 
191  //------------------------------------------------------------------------
193  //------------------------------------------------------------------------
194  void HandleResponse();
195 
196  //------------------------------------------------------------------------
198  //------------------------------------------------------------------------
200 
201  //------------------------------------------------------------------------
204  //------------------------------------------------------------------------
205  Status ParseResponse( AnyObject *&response );
206 
207  //------------------------------------------------------------------------
210  //------------------------------------------------------------------------
212 
213  //------------------------------------------------------------------------
215  //------------------------------------------------------------------------
217 
218  //------------------------------------------------------------------------
220  //------------------------------------------------------------------------
222  ChunkList *list,
223  char *sourceBuffer,
224  uint32_t sourceBufferSize );
225 
226  //------------------------------------------------------------------------
228  //------------------------------------------------------------------------
229  void UpdateTriedCGI();
230 
231  //------------------------------------------------------------------------
233  //------------------------------------------------------------------------
234  void SwitchOnRefreshFlag();
235 
238  std::vector<Message *> pPartialResps;
244  time_t pExpiration;
250  std::string pRedirectCgi;
253  };
254 }
255 
256 #endif // __XRD_CL_XROOTD_MSG_HANDLER_HH__