xrootd
Loading...
Searching...
No Matches
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"
33
34namespace XrdCl
35{
36 class LocalFileHandler;
37
38 class XAttr;
39
40 //----------------------------------------------------------------------------
42 //----------------------------------------------------------------------------
44 {
45 public:
46 //------------------------------------------------------------------------
48 //------------------------------------------------------------------------
50 pStatus(0),
51 pResponse(0),
52 pCondVar(0) {}
53
54 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
58 {
59 }
60
61
62 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
65 virtual void HandleResponse( XRootDStatus *status,
66 AnyObject *response )
67 {
68 XrdSysCondVarHelper scopedLock(pCondVar);
69 pStatus = status;
70 pResponse = response;
72 }
73
74 //------------------------------------------------------------------------
76 //------------------------------------------------------------------------
78 {
79 return pStatus;
80 }
81
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
86 {
87 return pResponse;
88 }
89
90 //------------------------------------------------------------------------
92 //------------------------------------------------------------------------
94 {
95 XrdSysCondVarHelper scopedLock(pCondVar);
96 while (pStatus == 0) {
97 pCondVar.Wait();
98 }
99 }
100
101 private:
104
108 };
109
110
111 //----------------------------------------------------------------------------
112 // We're not interested in the response just commit suicide
113 //----------------------------------------------------------------------------
115 {
116 public:
117 //------------------------------------------------------------------------
118 // Handle the response
119 //------------------------------------------------------------------------
121 XrdCl::AnyObject *response,
122 XrdCl::HostList *hostList )
123 {
124 delete this;
125 }
126 };
127
128 //----------------------------------------------------------------------------
129 // Sending parameters
130 //----------------------------------------------------------------------------
148
150 {
151 public:
152 //------------------------------------------------------------------------
154 //------------------------------------------------------------------------
156 {
157 handler->WaitForResponse();
158 XRootDStatus *status = handler->GetStatus();
159 XRootDStatus ret( *status );
160 delete status;
161 return ret;
162 }
163
164 //------------------------------------------------------------------------
166 //------------------------------------------------------------------------
167 template<class Type>
169 SyncResponseHandler *handler,
170 Type *&response )
171 {
172 handler->WaitForResponse();
173
174 AnyObject *resp = handler->GetResponse();
175 XRootDStatus *status = handler->GetStatus();
176 XRootDStatus ret( *status );
177 delete status;
178
179 if( ret.IsOK() )
180 {
181 if( !resp )
183 resp->Get( response );
184 resp->Set( (int *)0 );
185 delete resp;
186
187 if( !response )
189 }
190
191 return ret;
192 }
193
194 //------------------------------------------------------------------------
196 //------------------------------------------------------------------------
197 template<class Request>
198 static void CreateRequest( Message *&msg,
199 Request *&req,
200 uint32_t payloadSize = 0 )
201 {
202 msg = new Message( sizeof(Request) + payloadSize );
203 req = (Request*)msg->GetBuffer();
204 msg->Zero();
205 }
206
207 //------------------------------------------------------------------------
209 //------------------------------------------------------------------------
210 static XRootDStatus SendMessage( const URL &url,
211 Message *msg,
212 ResponseHandler *handler,
213 MessageSendParams &sendParams,
214 LocalFileHandler *lFileHandler );
215
216 //------------------------------------------------------------------------
218 //------------------------------------------------------------------------
219 static Status RedirectMessage( const URL &url,
220 Message *msg,
221 ResponseHandler *handler,
222 MessageSendParams &sendParams,
223 LocalFileHandler *lFileHandler );
224
225 //------------------------------------------------------------------------
227 //------------------------------------------------------------------------
228 static void ProcessSendParams( MessageSendParams &sendParams );
229
230 //------------------------------------------------------------------------
240 //------------------------------------------------------------------------
241 static void RewriteCGIAndPath( Message *msg,
242 const URL::ParamsMap &newCgi,
243 bool replace,
244 const std::string &newPath );
245
246 //------------------------------------------------------------------------
254 //------------------------------------------------------------------------
255 static void MergeCGI( URL::ParamsMap &cgi1,
256 const URL::ParamsMap &cgi2,
257 bool replace );
258
259 //------------------------------------------------------------------------
265 //------------------------------------------------------------------------
266 static Status CreateXAttrVec( const std::vector<xattr_t> &attrs,
267 std::vector<char> &avec );
268
269 //------------------------------------------------------------------------
274 //------------------------------------------------------------------------
275 static Status CreateXAttrVec( const std::vector<std::string> &attrs,
276 std::vector<char> &nvec );
277
278 //------------------------------------------------------------------------
284 //------------------------------------------------------------------------
285 template<typename T>
287 const std::vector<T> &vec,
288 const std::string &path = "" )
289 {
290 ClientRequestHdr *hdr = reinterpret_cast<ClientRequestHdr*>( msg->GetBuffer() );
291
292 std::vector<char> xattrvec;
293 Status st = MessageUtils::CreateXAttrVec( vec, xattrvec );
294 if( !st.IsOK() )
295 return st;
296
297 // update body size in the header
298 hdr->dlen = path.size() + 1;
299 hdr->dlen += xattrvec.size();
300
301 // append the body
302 size_t offset = sizeof( ClientRequestHdr );
303 msg->Append( path.c_str(), path.size() + 1, offset );
304 offset += path.size() + 1;
305 msg->Append( xattrvec.data(), xattrvec.size(), offset );
306
307 return Status();
308 }
309 };
310}
311
312#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
void Append(const char *buffer, uint32_t size)
Append data at the position pointed to by the append cursor.
Definition XrdClBuffer.hh:164
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
Definition XrdClBuffer.hh:72
Definition XrdClLocalFileHandler.hh:33
Definition XrdClMessageUtils.hh:150
static void RewriteCGIAndPath(Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath)
static void ProcessSendParams(MessageSendParams &sendParams)
Process sending params.
static Status CreateXAttrVec(const std::vector< std::string > &attrs, std::vector< char > &nvec)
static XRootDStatus SendMessage(const URL &url, Message *msg, ResponseHandler *handler, MessageSendParams &sendParams, LocalFileHandler *lFileHandler)
Send message.
static Status CreateXAttrBody(Message *msg, const std::vector< T > &vec, const std::string &path="")
Definition XrdClMessageUtils.hh:286
static void MergeCGI(URL::ParamsMap &cgi1, const URL::ParamsMap &cgi2, bool replace)
static Status CreateXAttrVec(const std::vector< xattr_t > &attrs, std::vector< char > &avec)
static XrdCl::XRootDStatus WaitForResponse(SyncResponseHandler *handler, Type *&response)
Wait for the response.
Definition XrdClMessageUtils.hh:168
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:198
static XRootDStatus WaitForStatus(SyncResponseHandler *handler)
Wait and return the status of the query.
Definition XrdClMessageUtils.hh:155
The message representation used throughout the system.
Definition XrdClMessage.hh:30
Definition XrdClMessageUtils.hh:115
virtual void HandleResponseWithHosts(XrdCl::XRootDStatus *status, XrdCl::AnyObject *response, XrdCl::HostList *hostList)
Definition XrdClMessageUtils.hh:120
Handle an async response.
Definition XrdClXRootDResponses.hh:1126
Synchronize the response.
Definition XrdClMessageUtils.hh:44
AnyObject * GetResponse()
Get the response.
Definition XrdClMessageUtils.hh:85
virtual void HandleResponse(XRootDStatus *status, AnyObject *response)
Handle the response.
Definition XrdClMessageUtils.hh:65
virtual ~SyncResponseHandler()
Destructor.
Definition XrdClMessageUtils.hh:57
AnyObject * pResponse
Definition XrdClMessageUtils.hh:106
XRootDStatus * GetStatus()
Get the status.
Definition XrdClMessageUtils.hh:77
SyncResponseHandler()
Constructor.
Definition XrdClMessageUtils.hh:49
XRootDStatus * pStatus
Definition XrdClMessageUtils.hh:105
XrdSysCondVar pCondVar
Definition XrdClMessageUtils.hh:107
void WaitForResponse()
Wait for the arrival of the response.
Definition XrdClMessageUtils.hh:93
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:219
Definition XrdSysPthread.hh:129
Definition XrdSysPthread.hh:79
void Broadcast()
Definition XrdSysPthread.hh:89
Definition XrdSysKernelBuffer.hh:46
Definition XrdClAction.hh:34
const uint16_t stError
An error occurred that could potentially be retried.
Definition XrdClStatus.hh:32
std::vector< HostInfo > HostList
Definition XrdClXRootDResponses.hh:1120
const uint16_t errInternal
Internal error.
Definition XrdClStatus.hh:56
std::vector< ChunkInfo > ChunkList
List of chunks.
Definition XrdClXRootDResponses.hh:1055
Definition XProtocol.hh:155
kXR_int32 dlen
Definition XProtocol.hh:159
Definition XrdClXRootDResponses.hh:1109
Definition XrdClMessageUtils.hh:132
HostList * hostList
Definition XrdClMessageUtils.hh:142
bool stateful
Definition XrdClMessageUtils.hh:141
std::vector< uint32_t > crc32cDigests
Definition XrdClMessageUtils.hh:146
XrdSys::KernelBuffer * kbuff
Definition XrdClMessageUtils.hh:145
uint16_t timeout
Definition XrdClMessageUtils.hh:136
HostInfo loadBalancer
Definition XrdClMessageUtils.hh:138
ChunkList * chunkList
Definition XrdClMessageUtils.hh:143
time_t expires
Definition XrdClMessageUtils.hh:137
uint16_t redirectLimit
Definition XrdClMessageUtils.hh:144
bool chunkedResponse
Definition XrdClMessageUtils.hh:140
MessageSendParams()
Definition XrdClMessageUtils.hh:133
bool followRedirects
Definition XrdClMessageUtils.hh:139
Procedure execution status.
Definition XrdClStatus.hh:115
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124