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"
32
33namespace 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;
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 )
178 resp->Get( response );
179 resp->Set( (int *)0 );
180 delete resp;
181
182 if( !response )
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__
Definition: XrdClAnyObject.hh:33
void Set(Type object, bool own=true)
Definition: XrdClAnyObject.hh:59
void Get(Type &object)
Retrieve the object being held.
Definition: XrdClAnyObject.hh:78
void Zero()
Zero.
Definition: XrdClBuffer.hh:124
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition: XrdClBuffer.hh:72
Definition: XrdClLocalFileHandler.hh:33
Definition: XrdClMessageUtils.hh:145
static void RewriteCGIAndPath(Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath)
static void ProcessSendParams(MessageSendParams &sendParams)
Process sending params.
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
static XrdCl::XRootDStatus WaitForResponse(SyncResponseHandler *handler, Type *&response)
Wait for the response.
Definition: XrdClMessageUtils.hh:163
static Status SendMessage(const URL &url, Message *msg, ResponseHandler *handler, const MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Send message.
static Status RedirectMessage(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Redirect message.
static void CreateRequest(Message *&msg, Request *&req, uint32_t payloadSize=0)
Create a message.
Definition: XrdClMessageUtils.hh:193
static XRootDStatus WaitForStatus(SyncResponseHandler *handler)
Wait and return the status of the query.
Definition: XrdClMessageUtils.hh:150
The message representation used throughout the system.
Definition: XrdClMessage.hh:30
Definition: XrdClMessageUtils.hh:112
virtual void HandleResponseWithHosts(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response, XrdCl::HostList *hostList)
Definition: XrdClMessageUtils.hh:117
Handle an async response.
Definition: XrdClXRootDResponses.hh:855
Synchronize the response.
Definition: XrdClMessageUtils.hh:41
AnyObject * GetResponse()
Get the response.
Definition: XrdClMessageUtils.hh:82
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
Handle the response.
Definition: XrdClMessageUtils.hh:62
virtual ~SyncResponseHandler()
Destructor.
Definition: XrdClMessageUtils.hh:54
AnyObject * pResponse
Definition: XrdClMessageUtils.hh:103
XRootDStatus * GetStatus()
Get the status.
Definition: XrdClMessageUtils.hh:74
SyncResponseHandler()
Constructor.
Definition: XrdClMessageUtils.hh:46
XRootDStatus * pStatus
Definition: XrdClMessageUtils.hh:102
XrdSysCondVar pCondVar
Definition: XrdClMessageUtils.hh:104
void WaitForResponse()
Wait for the arrival of the response.
Definition: XrdClMessageUtils.hh:90
SyncResponseHandler(const SyncResponseHandler &other)
SyncResponseHandler & operator=(const SyncResponseHandler &other)
URL representation.
Definition: XrdClURL.hh:31
std::map< std::string, std::string > ParamsMap
Definition: XrdClURL.hh:33
Request status.
Definition: XrdClXRootDResponses.hh:213
Definition: XrdSysPthread.hh:130
Definition: XrdSysPthread.hh:79
void Broadcast()
Definition: XrdSysPthread.hh:89
Definition: XrdClAnyObject.hh:26
const uint16_t stError
An error occurred that could potentially be retried.
Definition: XrdClStatus.hh:32
std::vector< HostInfo > HostList
Definition: XrdClXRootDResponses.hh:849
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:55
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition: XrdClXRootDResponses.hh:784
Definition: XrdClXRootDResponses.hh:838
Definition: XrdClMessageUtils.hh:129
HostList * hostList
Definition: XrdClMessageUtils.hh:139
bool stateful
Definition: XrdClMessageUtils.hh:138
uint16_t timeout
Definition: XrdClMessageUtils.hh:133
HostInfo loadBalancer
Definition: XrdClMessageUtils.hh:135
ChunkList * chunkList
Definition: XrdClMessageUtils.hh:140
time_t expires
Definition: XrdClMessageUtils.hh:134
uint16_t redirectLimit
Definition: XrdClMessageUtils.hh:141
bool chunkedResponse
Definition: XrdClMessageUtils.hh:137
MessageSendParams()
Definition: XrdClMessageUtils.hh:130
bool followRedirects
Definition: XrdClMessageUtils.hh:136
Procedure execution status.
Definition: XrdClStatus.hh:110
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:119