xrootd
XrdClMessageUtils.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #ifndef __XRD_CL_MESSAGE_UTILS_HH__
26 #define __XRD_CL_MESSAGE_UTILS_HH__
27 
29 #include "XrdCl/XrdClURL.hh"
30 #include "XrdCl/XrdClMessage.hh"
31 #include "XrdCl/XrdClUglyHacks.hh"
32 
33 namespace XrdCl
34 {
35  class LocalFileHandler;
36 
37  //----------------------------------------------------------------------------
39  //----------------------------------------------------------------------------
41  {
42  public:
43  //------------------------------------------------------------------------
45  //------------------------------------------------------------------------
47  pStatus(0),
48  pResponse(0),
49  pCondVar(0) {}
50 
51  //------------------------------------------------------------------------
53  //------------------------------------------------------------------------
55  {
56  }
57 
58 
59  //------------------------------------------------------------------------
61  //------------------------------------------------------------------------
62  virtual void HandleResponse( XRootDStatus *status,
63  AnyObject *response )
64  {
65  XrdSysCondVarHelper scopedLock(pCondVar);
66  pStatus = status;
67  pResponse = response;
69  }
70 
71  //------------------------------------------------------------------------
73  //------------------------------------------------------------------------
75  {
76  return pStatus;
77  }
78 
79  //------------------------------------------------------------------------
81  //------------------------------------------------------------------------
83  {
84  return pResponse;
85  }
86 
87  //------------------------------------------------------------------------
89  //------------------------------------------------------------------------
91  {
92  XrdSysCondVarHelper scopedLock(pCondVar);
93  while (pStatus == 0) {
94  pCondVar.Wait();
95  }
96  }
97 
98  private:
101 
105  };
106 
107 
108  //----------------------------------------------------------------------------
109  // We're not interested in the response just commit suicide
110  //----------------------------------------------------------------------------
112  {
113  public:
114  //------------------------------------------------------------------------
115  // Handle the response
116  //------------------------------------------------------------------------
118  XrdCl::AnyObject *response,
119  XrdCl::HostList *hostList )
120  {
121  delete this;
122  }
123  };
124 
125  //----------------------------------------------------------------------------
126  // Sending parameters
127  //----------------------------------------------------------------------------
129  {
131  timeout(0), expires(0), followRedirects(true), chunkedResponse(false),
132  stateful(true), hostList(0), chunkList(0), redirectLimit(0) {}
133  uint16_t timeout;
134  time_t expires;
138  bool stateful;
141  uint16_t redirectLimit;
142  };
143 
145  {
146  public:
147  //------------------------------------------------------------------------
149  //------------------------------------------------------------------------
151  {
152  handler->WaitForResponse();
153  XRootDStatus *status = handler->GetStatus();
154  XRootDStatus ret( *status );
155  delete status;
156  return ret;
157  }
158 
159  //------------------------------------------------------------------------
161  //------------------------------------------------------------------------
162  template<class Type>
164  SyncResponseHandler *handler,
165  Type *&response )
166  {
167  handler->WaitForResponse();
168 
169  AnyObject *resp = handler->GetResponse();
170  XRootDStatus *status = handler->GetStatus();
171  XRootDStatus ret( *status );
172  delete status;
173 
174  if( ret.IsOK() )
175  {
176  if( !resp )
177  return XRootDStatus( stError, errInternal );
178  resp->Get( response );
179  resp->Set( (int *)0 );
180  delete resp;
181 
182  if( !response )
183  return XRootDStatus( stError, errInternal );
184  }
185 
186  return ret;
187  }
188 
189  //------------------------------------------------------------------------
191  //------------------------------------------------------------------------
192  template<class Request>
193  static void CreateRequest( Message *&msg,
194  Request *&req,
195  uint32_t payloadSize = 0 )
196  {
197  msg = new Message( sizeof(Request) + payloadSize );
198  req = (Request*)msg->GetBuffer();
199  msg->Zero();
200  }
201 
202  //------------------------------------------------------------------------
204  //------------------------------------------------------------------------
205  static Status SendMessage( const URL &url,
206  Message *msg,
207  ResponseHandler *handler,
208  const MessageSendParams &sendParams,
209  LocalFileHandler *lFileHandler );
210 
211  //------------------------------------------------------------------------
213  //------------------------------------------------------------------------
214  static Status RedirectMessage( const URL &url,
215  Message *msg,
216  ResponseHandler *handler,
217  MessageSendParams &sendParams,
218  LocalFileHandler *lFileHandler );
219 
220  //------------------------------------------------------------------------
222  //------------------------------------------------------------------------
223  static void ProcessSendParams( MessageSendParams &sendParams );
224 
225  //------------------------------------------------------------------------
235  //------------------------------------------------------------------------
236  static void RewriteCGIAndPath( Message *msg,
237  const URL::ParamsMap &newCgi,
238  bool replace,
239  const std::string &newPath );
240 
241  //------------------------------------------------------------------------
249  //------------------------------------------------------------------------
250  static void MergeCGI( URL::ParamsMap &cgi1,
251  const URL::ParamsMap &cgi2,
252  bool replace );
253  };
254 }
255 
256 #endif // __XRD_CL_MESSAGE_UTILS_HH__
XrdCl::MessageSendParams::timeout
uint16_t timeout
Definition: XrdClMessageUtils.hh:133
XrdCl::MessageSendParams
Definition: XrdClMessageUtils.hh:128
XrdClXRootDResponses.hh
XrdCl::ResponseHandler
Handle an async response.
Definition: XrdClXRootDResponses.hh:854
XrdCl::SyncResponseHandler::WaitForResponse
void WaitForResponse()
Wait for the arrival of the response.
Definition: XrdClMessageUtils.hh:90
XrdCl::SyncResponseHandler::pResponse
AnyObject * pResponse
Definition: XrdClMessageUtils.hh:103
XrdCl::SyncResponseHandler::pStatus
XRootDStatus * pStatus
Definition: XrdClMessageUtils.hh:102
XrdCl::LocalFileHandler
Definition: XrdClLocalFileHandler.hh:32
XrdSysCondVarHelper
Definition: XrdSysPthread.hh:129
XrdClMessage.hh
XrdCl::Buffer::GetBuffer
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
XrdCl::MessageSendParams::followRedirects
bool followRedirects
Definition: XrdClMessageUtils.hh:136
XrdCl::AnyObject::Get
void Get(Type &object)
Retrieve the object being held.
Definition: XrdClAnyObject.hh:78
XrdCl::MessageSendParams::expires
time_t expires
Definition: XrdClMessageUtils.hh:134
XrdCl::AnyObject::Set
void Set(Type object, bool own=true)
Definition: XrdClAnyObject.hh:59
XrdCl::errInternal
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:55
XrdCl::SyncResponseHandler
Synchronize the response.
Definition: XrdClMessageUtils.hh:40
XrdCl::Message
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
XrdCl::MessageSendParams::loadBalancer
HostInfo loadBalancer
Definition: XrdClMessageUtils.hh:135
XrdCl::MessageSendParams::redirectLimit
uint16_t redirectLimit
Definition: XrdClMessageUtils.hh:141
XrdSysCondVar::Broadcast
void Broadcast()
Definition: XrdSysPthread.hh:89
XrdCl::MessageUtils::ProcessSendParams
static void ProcessSendParams(MessageSendParams &sendParams)
Process sending params.
XrdCl::XRootDStatus
Request status.
Definition: XrdClXRootDResponses.hh:212
XrdCl::MessageUtils::WaitForStatus
static XRootDStatus WaitForStatus(SyncResponseHandler *handler)
Wait and return the status of the query.
Definition: XrdClMessageUtils.hh:150
XrdCl::MessageUtils::RedirectMessage
static Status RedirectMessage(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Redirect message.
XrdSysCondVar
Definition: XrdSysPthread.hh:78
XrdCl::ChunkList
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:784
XrdCl::URL::ParamsMap
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
XrdCl::MessageUtils::RewriteCGIAndPath
static void RewriteCGIAndPath(Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath)
XrdCl::MessageUtils::MergeCGI
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
XrdCl::MessageUtils
Definition: XrdClMessageUtils.hh:144
XrdCl::MessageUtils::CreateRequest
static void CreateRequest(Message *&msg, Request *&req, uint32_t payloadSize=0)
Create a message.
Definition: XrdClMessageUtils.hh:193
XrdCl::MessageSendParams::chunkList
ChunkList * chunkList
Definition: XrdClMessageUtils.hh:140
XrdCl::MessageSendParams::stateful
bool stateful
Definition: XrdClMessageUtils.hh:138
XrdCl::MessageSendParams::hostList
HostList * hostList
Definition: XrdClMessageUtils.hh:139
XrdCl::SyncResponseHandler::pCondVar
XrdSysCondVar pCondVar
Definition: XrdClMessageUtils.hh:104
XrdSysCondVar::Wait
int Wait()
XrdCl::SyncResponseHandler::GetStatus
XRootDStatus * GetStatus()
Get the status.
Definition: XrdClMessageUtils.hh:74
XrdCl::SyncResponseHandler::HandleResponse
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
Handle the response.
Definition: XrdClMessageUtils.hh:62
XrdCl::NullResponseHandler
Definition: XrdClMessageUtils.hh:111
XrdCl
Definition: XrdClAnyObject.hh:25
XrdCl::MessageSendParams::chunkedResponse
bool chunkedResponse
Definition: XrdClMessageUtils.hh:137
XrdCl::HostList
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:849
XrdCl::SyncResponseHandler::~SyncResponseHandler
virtual ~SyncResponseHandler()
Destructor.
Definition: XrdClMessageUtils.hh:54
XrdCl::MessageSendParams::MessageSendParams
MessageSendParams()
Definition: XrdClMessageUtils.hh:130
XrdClUglyHacks.hh
XrdCl::stError
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
XrdCl::MessageUtils::WaitForResponse
static XrdCl::XRootDStatus WaitForResponse(SyncResponseHandler *handler, Type *&response)
Wait for the response.
Definition: XrdClMessageUtils.hh:163
XrdCl::HostInfo
Definition: XrdClXRootDResponses.hh:837
XrdClURL.hh
XrdCl::MessageUtils::SendMessage
static Status SendMessage(const URL &url, Message *msg, ResponseHandler *handler, const MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Send message.
XrdCl::Status
Procedure execution status.
Definition: XrdClStatus.hh:109
XrdCl::URL
URL representation.
Definition: XrdClURL.hh:30
XrdCl::SyncResponseHandler::SyncResponseHandler
SyncResponseHandler()
Constructor.
Definition: XrdClMessageUtils.hh:46
XrdCl::Buffer::Zero
void Zero()
Zero.
Definition: XrdClBuffer.hh:124
XrdCl::SyncResponseHandler::operator=
SyncResponseHandler & operator=(const SyncResponseHandler &other)
XrdCl::NullResponseHandler::HandleResponseWithHosts
virtual void HandleResponseWithHosts(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response, XrdCl::HostList *hostList)
Definition: XrdClMessageUtils.hh:117
XrdCl::AnyObject
Definition: XrdClAnyObject.hh:32
XrdCl::SyncResponseHandler::GetResponse
AnyObject * GetResponse()
Get the response.
Definition: XrdClMessageUtils.hh:82