00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __XRD_CL_MESSAGE_UTILS_HH__
00026 #define __XRD_CL_MESSAGE_UTILS_HH__
00027
00028 #include "XrdCl/XrdClXRootDResponses.hh"
00029 #include "XrdCl/XrdClURL.hh"
00030 #include "XrdCl/XrdClMessage.hh"
00031 #include "XrdCl/XrdClUglyHacks.hh"
00032
00033 namespace XrdCl
00034 {
00035 class LocalFileHandler;
00036
00037
00039
00040 class SyncResponseHandler: public ResponseHandler
00041 {
00042 public:
00043
00045
00046 SyncResponseHandler():
00047 pStatus(0),
00048 pResponse(0),
00049 pCondVar(0) {}
00050
00051
00053
00054 virtual ~SyncResponseHandler()
00055 {
00056 }
00057
00058
00059
00061
00062 virtual void HandleResponse( XRootDStatus *status,
00063 AnyObject *response )
00064 {
00065 XrdSysCondVarHelper scopedLock(pCondVar);
00066 pStatus = status;
00067 pResponse = response;
00068 pCondVar.Broadcast();
00069 }
00070
00071
00073
00074 XRootDStatus *GetStatus()
00075 {
00076 return pStatus;
00077 }
00078
00079
00081
00082 AnyObject *GetResponse()
00083 {
00084 return pResponse;
00085 }
00086
00087
00089
00090 void WaitForResponse()
00091 {
00092 XrdSysCondVarHelper scopedLock(pCondVar);
00093 while (pStatus == 0) {
00094 pCondVar.Wait();
00095 }
00096 }
00097
00098 private:
00099 SyncResponseHandler(const SyncResponseHandler &other);
00100 SyncResponseHandler &operator = (const SyncResponseHandler &other);
00101
00102 XRootDStatus *pStatus;
00103 AnyObject *pResponse;
00104 XrdSysCondVar pCondVar;
00105 };
00106
00107
00108
00109
00110
00111 class NullResponseHandler: public XrdCl::ResponseHandler
00112 {
00113 public:
00114
00115
00116
00117 virtual void HandleResponseWithHosts( XrdCl::XRootDStatus *status,
00118 XrdCl::AnyObject *response,
00119 XrdCl::HostList *hostList )
00120 {
00121 delete this;
00122 }
00123 };
00124
00125
00126
00127
00128 struct MessageSendParams
00129 {
00130 MessageSendParams():
00131 timeout(0), expires(0), followRedirects(true), stateful(true),
00132 hostList(0), chunkList(0), redirectLimit(0) {}
00133 uint16_t timeout;
00134 time_t expires;
00135 HostInfo loadBalancer;
00136 bool followRedirects;
00137 bool stateful;
00138 HostList *hostList;
00139 ChunkList *chunkList;
00140 uint16_t redirectLimit;
00141 };
00142
00143 class MessageUtils
00144 {
00145 public:
00146
00148
00149 static XRootDStatus WaitForStatus( SyncResponseHandler *handler )
00150 {
00151 handler->WaitForResponse();
00152 XRootDStatus *status = handler->GetStatus();
00153 XRootDStatus ret( *status );
00154 delete status;
00155 return ret;
00156 }
00157
00158
00160
00161 template<class Type>
00162 static XrdCl::XRootDStatus WaitForResponse(
00163 SyncResponseHandler *handler,
00164 Type *&response )
00165 {
00166 handler->WaitForResponse();
00167
00168 AnyObject *resp = handler->GetResponse();
00169 XRootDStatus *status = handler->GetStatus();
00170 XRootDStatus ret( *status );
00171 delete status;
00172
00173 if( ret.IsOK() )
00174 {
00175 if( !resp )
00176 return XRootDStatus( stError, errInternal );
00177 resp->Get( response );
00178 resp->Set( (int *)0 );
00179 delete resp;
00180
00181 if( !response )
00182 return XRootDStatus( stError, errInternal );
00183 }
00184
00185 return ret;
00186 }
00187
00188
00190
00191 template<class Request>
00192 static void CreateRequest( Message *&msg,
00193 Request *&req,
00194 uint32_t payloadSize = 0 )
00195 {
00196 msg = new Message( sizeof(Request) + payloadSize );
00197 req = (Request*)msg->GetBuffer();
00198 msg->Zero();
00199 }
00200
00201
00203
00204 static Status SendMessage( const URL &url,
00205 Message *msg,
00206 ResponseHandler *handler,
00207 const MessageSendParams &sendParams,
00208 LocalFileHandler *lFileHandler );
00209
00210
00212
00213 static Status RedirectMessage( const URL &url,
00214 Message *msg,
00215 ResponseHandler *handler,
00216 MessageSendParams &sendParams,
00217 LocalFileHandler *lFileHandler );
00218
00219
00221
00222 static void ProcessSendParams( MessageSendParams &sendParams );
00223
00224
00234
00235 static void RewriteCGIAndPath( Message *msg,
00236 const URL::ParamsMap &newCgi,
00237 bool replace,
00238 const std::string &newPath );
00239
00240
00248
00249 static void MergeCGI( URL::ParamsMap &cgi1,
00250 const URL::ParamsMap &cgi2,
00251 bool replace );
00252 };
00253 }
00254
00255 #endif // __XRD_CL_MESSAGE_UTILS_HH__