65 o <<
"WaitTask for: 0x" << handler->
GetRequest();
69 virtual time_t
Run( time_t now )
71 pHandler->WaitDone( now );
97 virtual void Run(
void *arg )
99 pHandler->HandleResponse();
111 const int sst = pSendingState.fetch_or( kSawResp );
113 if( !( sst & kSendDone ) && !( sst & kSawResp ) )
119 log->
Dump(
XRootDMsg,
"[%s] Message %s reply received before notification "
120 "that it was sent, assuming it was sent ok.",
131 if( pOksofarAsAnswer )
134 while( pResponse ) pCV.
Wait();
141 log->
Warning(
ExDbgMsg,
"[%s] MsgHandler is examining a response although "
142 "it already owns a response: %p (message: %s ).",
148 if( msg->GetSize() < 8 )
188 pBodyReader->SetDataLength( dlen );
245 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_oksofar response to request "
249 if( !pOksofarAsAnswer )
251 pPartialResps.emplace_back( std::move( pResponse ) );
262 pTimeoutFence.store(
true, std::memory_order_relaxed );
271 pTimeoutFence.store(
true, std::memory_order_relaxed );
280 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_status response to request "
299 pTimeoutFence.store(
true, std::memory_order_relaxed );
366 pPartialResps.push_back( std::move( pResponse ) );
379 pPageReader.reset(
new AsyncPageReader( *pChunkList, pCrc32cDigests ) );
380 pPageReader->SetRsp( rspst );
395 pResponse->GetCursor() )
434 int *qryResponse = 0;
436 qryResult.
Get( qryResponse );
437 pHosts->back().flags = *qryResponse;
delete qryResponse; qryResponse = 0;
439 qryResult.
Get( qryResponse );
440 pHosts->back().protocol = *qryResponse;
delete qryResponse;
464 pAggregatedWaitTime = 0;
473 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_ok response to request %s",
483 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_status response to request %s",
496 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_oksofar response to request %s",
509 char *errmsg =
new char[rsp->
hdr.
dlen-3]; errmsg[rsp->
hdr.
dlen-4] = 0;
510 memcpy( errmsg, rsp->
body.error.errmsg, rsp->
hdr.
dlen-4 );
511 log->
Dump(
XRootDMsg,
"[%s] Got a kXR_error response to request %s "
535 char *urlInfoBuff =
new char[rsp->
hdr.
dlen-3];
536 urlInfoBuff[rsp->
hdr.
dlen-4] = 0;
537 memcpy( urlInfoBuff, rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
538 std::string urlInfo = urlInfoBuff;
539 delete [] urlInfoBuff;
541 "message %s: %s, port %d", pUrl.
GetHostId().c_str(),
543 rsp->
body.redirect.port );
548 if( !pRedirectCounter )
551 "message %s, the last known error is: %s",
567 uint32_t flags = pHosts->back().flags;
568 if( !pHasLoadBalancer )
579 pLoadBalancer = pHosts->back();
580 log->
Dump(
XRootDMsg,
"[%s] Current server has been assigned "
581 "as a load-balancer for message %s",
584 HostList::iterator it;
585 for( it = pHosts->begin(); it != pHosts->end(); ++it )
586 it->loadBalancer =
false;
587 pHosts->back().loadBalancer =
true;
598 pEffectiveDataServerUrl =
new URL( pHosts->back().url );
603 std::vector<std::string> urlComponents;
607 std::ostringstream o;
609 o << urlComponents[0];
610 if( rsp->
body.redirect.port > 0 )
611 o <<
":" << rsp->
body.redirect.port <<
"/";
612 else if( rsp->
body.redirect.port < 0 )
627 std::string url( rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
633 std::string url( rsp->
body.redirect.host, rsp->
hdr.
dlen-4 );
635 pRedirectAsAnswer =
true;
639 URL newUrl =
URL( o.str() );
644 pUrl.
GetHostId().c_str(), urlInfo.c_str() );
661 std::ostringstream ossXrd;
664 for(URL::ParamsMap::const_iterator it = urlParams.begin();
665 it != urlParams.end(); ++it )
667 if( it->first.compare( 0, 4,
"xrd." ) &&
668 it->first.compare( 0, 6,
"xrdcl." ) )
671 ossXrd << it->first <<
'=' << it->second <<
'&';
674 std::string xrdCgi = ossXrd.str();
675 pRedirectUrl = newUrl.
GetURL();
678 if( urlComponents.size() > 1 )
681 pRedirectUrl += urlComponents[1];
682 std::ostringstream o;
683 o <<
"fake://fake:111//fake?";
684 o << urlComponents[1];
686 if( urlComponents.size() == 3 )
687 o <<
'?' << urlComponents[2];
693 pRedirectUrl += xrdCgi;
696 cgiURL =
URL( o.str() );
701 std::ostringstream o;
702 o <<
"fake://fake:111//fake?";
704 cgiURL =
URL( o.str() );
706 pRedirectUrl += xrdCgi;
716 pRedirectAsAnswer =
true;
718 if( pRedirectAsAnswer )
729 Status st = RewriteRequestRedirect( newUrl );
756 uint32_t waitSeconds = 0;
760 char *infoMsg =
new char[rsp->
hdr.
dlen-3];
762 memcpy( infoMsg, rsp->
body.wait.infomsg, rsp->
hdr.
dlen-4 );
763 log->
Dump(
XRootDMsg,
"[%s] Got kXR_wait response of %d seconds to "
764 "message %s: %s", pUrl.
GetHostId().c_str(),
768 waitSeconds = rsp->
body.wait.seconds;
772 log->
Dump(
XRootDMsg,
"[%s] Got kXR_wait response of 0 seconds to "
777 pAggregatedWaitTime += waitSeconds;
782 if( OmitWait( *pRequest, pLoadBalancer.
url ) )
786 if( pAggregatedWaitTime > maxWait )
798 Status st = RewriteRequestWait();
810 time_t resendTime = ::time(0)+waitSeconds;
812 if( resendTime < pExpiration )
814 log->
Debug(
ExDbgMsg,
"[%s] Scheduling WaitTask for MsgHandler: %p (message: %s ).",
819 taskMgr->
RegisterTask(
new WaitTask(
this ), resendTime );
823 log->
Debug(
XRootDMsg,
"[%s] Wait time is too long, timing out %s",
848 log->
Dump(
XRootDMsg,
"[%s] Got kXR_waitresp response of %d seconds to "
850 rsp->
body.waitresp.seconds,
860 log->
Dump(
XRootDMsg,
"[%s] Got unrecognized response %d to "
879 log->
Dump(
XRootDMsg,
"[%s] Stream event reported for msg %s",
885 if( pTimeoutFence.load( std::memory_order_relaxed ) )
888 HandleError( status );
897 uint32_t &bytesRead )
903 return pPageReader->Read( *socket, bytesRead );
905 return pBodyReader->Read( *socket, bytesRead );
917 const int sst = pSendingState.fetch_or( kSendDone );
919 if( sst & kFinalResp )
921 log->
Dump(
XRootDMsg,
"[%s] Got late notification that outgoing message %s was "
922 "sent, already have final response, queuing handler callback.",
930 log->
Dump(
XRootDMsg,
"[%s] Got late notification that message %s has "
931 "been successfully sent.",
941 log->
Dump(
XRootDMsg,
"[%s] Message %s has been successfully sent.",
951 log->
Error(
XRootDMsg,
"[%s] Impossible to send message %s. Trying to "
954 HandleError( status );
981 uint32_t &bytesWritten )
986 if( !pChunkList->empty() && !pCrc32cDigests.empty() )
996 int fLen = 0, lLen = 0;
1004 uint32_t digest = htonl( pCrc32cDigests[pPgWrtCurrentPageNb] );
1005 memcpy( pPgWrtCksumBuff.
GetBuffer(), &digest,
sizeof( uint32_t ) );
1008 uint32_t btsLeft = chunk.
length - pAsyncOffset;
1009 uint32_t pglen = ( pPgWrtCurrentPageNb == 0 ? fLen :
XrdSys::PageSize ) - pPgWrtCurrentPageOffset;
1010 if( pglen > btsLeft ) pglen = btsLeft;
1011 char* pgbuf =
static_cast<char*
>( chunk.
buffer ) + pAsyncOffset;
1013 while( btsLeft > 0 )
1016 while( pPgWrtCksumBuff.
GetCursor() <
sizeof( uint32_t ) )
1018 uint32_t dgstlen =
sizeof( uint32_t ) - pPgWrtCksumBuff.
GetCursor();
1021 Status st = socket->
Send( dgstbuf, dgstlen, btswrt );
1022 if( !st.
IsOK() )
return st;
1023 bytesWritten += btswrt;
1029 Status st = socket->
Send( pgbuf, pglen, btswrt );
1030 if( !st.
IsOK() )
return st;
1034 bytesWritten += btswrt;
1035 pAsyncOffset += btswrt;
1041 ++pPgWrtCurrentPageNb;
1042 if( pPgWrtCurrentPageNb < nbpgs )
1046 uint32_t digest = htonl( pCrc32cDigests[pPgWrtCurrentPageNb] );
1047 memcpy( pPgWrtCksumBuff.
GetBuffer(), &digest,
sizeof( uint32_t ) );
1051 if( pglen > btsLeft ) pglen = btsLeft;
1053 pPgWrtCurrentPageOffset = 0;
1057 pPgWrtCurrentPageOffset += btswrt;
1061 else if( !pChunkList->empty() )
1063 size_t size = pChunkList->size();
1064 for(
size_t i = pAsyncChunkIndex ; i < size; ++i )
1066 char *buffer = (
char*)(*pChunkList)[i].buffer;
1067 uint32_t size = (*pChunkList)[i].length;
1068 size_t leftToBeWritten = size - pAsyncOffset;
1070 while( leftToBeWritten )
1073 Status st = socket->
Send( buffer + pAsyncOffset, leftToBeWritten, btswrt );
1074 bytesWritten += btswrt;
1076 pAsyncOffset += btswrt;
1077 leftToBeWritten -= btswrt;
1097 log->
Debug(
XRootDMsg,
"[%s] Channel is encrypted: cannot use kernel buffer.",
1103 pChunkList->push_back(
ChunkInfo( 0, ret, ubuff ) );
1110 while( !pKBuff->
Empty() )
1114 bytesWritten += btswrt;
1118 log->
Debug(
XRootDMsg,
"[%s] Request %s payload (kernel buffer) transferred to socket.",
1139 pTimeoutFence.store(
false, std::memory_order_relaxed );
1145 void XRootDMsgHandler::HandleResponse()
1156 const int sst = pSendingState.fetch_or( kFinalResp );
1157 if( !( sst & kSendDone ) )
1165 XRootDStatus *status = ProcessStatus();
1166 AnyObject *response = 0;
1169 log->Debug(
ExDbgMsg,
"[%s] Calling MsgHandler: %p (message: %s ) "
1173 status->ToString().c_str() );
1175 if( status->IsOK() )
1177 Status st = ParseResponse( response );
1182 status =
new XRootDStatus( st );
1192 pRdirEntry->status = *status;
1193 pRedirectTraceBack.push_back( std::move( pRdirEntry ) );
1199 if( pSidMgr && finalrsp )
1202 if( status->IsOK() || !pMsgInFly ||
1207 HostList *hosts = pHosts.release();
1209 pHosts.reset(
new HostList( *hosts ) );
1226 pTimeoutFence.store(
false, std::memory_order_relaxed );
1235 XRootDStatus *XRootDMsgHandler::ProcessStatus()
1237 XRootDStatus *st =
new XRootDStatus( pStatus );
1242 if( !pStatus.
IsOK() && rsp )
1246 st->errNo = rsp->
body.error.errnum;
1249 std::string errmsg( rsp->
body.error.errmsg, rsp->
hdr.
dlen-5 );
1251 errmsg +=
" Last seen error: " + pLastError.
ToString();
1252 st->SetErrorMessage( errmsg );
1255 st->SetErrorMessage( pRedirectUrl );
1264 Status XRootDMsgHandler::ParseResponse( AnyObject *&response )
1278 log->Error(
XRootDMsg,
"Internal Error: unable to process redirect" );
1283 uint32_t length = 0;
1289 if( pPartialResps.empty() )
1291 buffer = rsp->
body.buffer.data;
1300 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1307 buff.Allocate( length );
1308 uint32_t offset = 0;
1309 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1312 buff.Append( part->
body.buffer.data, part->
hdr.
dlen, offset );
1315 buff.Append( rsp->
body.buffer.data, rsp->
hdr.
dlen, offset );
1316 buffer = buff.GetBuffer();
1347 AnyObject *obj =
new AnyObject();
1349 char *nullBuffer =
new char[length+1];
1350 nullBuffer[length] = 0;
1351 memcpy( nullBuffer, buffer, length );
1353 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1354 "LocateInfo: %s", pUrl.
GetHostId().c_str(),
1356 LocationInfo *data =
new LocationInfo();
1358 if( data->ParseServerResponse( nullBuffer ) ==
false )
1362 delete [] nullBuffer;
1365 delete [] nullBuffer;
1377 AnyObject *obj =
new AnyObject();
1384 StatInfoVFS *data =
new StatInfoVFS();
1386 char *nullBuffer =
new char[length+1];
1387 nullBuffer[length] = 0;
1388 memcpy( nullBuffer, buffer, length );
1390 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1391 "StatInfoVFS: %s", pUrl.
GetHostId().c_str(),
1394 if( data->ParseServerResponse( nullBuffer ) ==
false )
1398 delete [] nullBuffer;
1401 delete [] nullBuffer;
1410 StatInfo *data =
new StatInfo();
1412 char *nullBuffer =
new char[length+1];
1413 nullBuffer[length] = 0;
1414 memcpy( nullBuffer, buffer, length );
1416 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as StatInfo: "
1420 if( data->ParseServerResponse( nullBuffer ) ==
false )
1424 delete [] nullBuffer;
1427 delete [] nullBuffer;
1440 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as ProtocolInfo",
1446 log->Error(
XRootDMsg,
"[%s] Got invalid redirect response.",
1451 AnyObject *obj =
new AnyObject();
1452 ProtocolInfo *data =
new ProtocolInfo( rsp->
body.protocol.pval,
1453 rsp->
body.protocol.flags );
1464 AnyObject *obj =
new AnyObject();
1465 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as "
1466 "DirectoryList", pUrl.
GetHostId().c_str(),
1473 DirectoryList *data =
new DirectoryList();
1474 data->SetParentName( path );
1477 char *nullBuffer =
new char[length+1];
1478 nullBuffer[length] = 0;
1479 memcpy( nullBuffer, buffer, length );
1481 bool invalidrsp =
false;
1483 if( !pDirListStarted )
1486 pDirListStarted =
true;
1488 invalidrsp = !data->ParseServerResponse( pUrl.
GetHostId(), nullBuffer );
1491 invalidrsp = !data->ParseServerResponse( pUrl.
GetHostId(), nullBuffer, pDirListWithStat );
1497 delete [] nullBuffer;
1501 delete [] nullBuffer;
1512 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as OpenInfo",
1518 log->Error(
XRootDMsg,
"[%s] Got invalid open response.",
1523 AnyObject *obj =
new AnyObject();
1524 StatInfo *statInfo = 0;
1531 log->Dump(
XRootDMsg,
"[%s] Parsing StatInfo in response to %s",
1537 char *nullBuffer =
new char[rsp->
hdr.
dlen-11];
1538 nullBuffer[rsp->
hdr.
dlen-12] = 0;
1539 memcpy( nullBuffer, buffer+12, rsp->
hdr.
dlen-12 );
1541 statInfo =
new StatInfo();
1542 if( statInfo->ParseServerResponse( nullBuffer ) ==
false )
1547 delete [] nullBuffer;
1550 if( rsp->
hdr.
dlen < 12 || !statInfo )
1552 log->Error(
XRootDMsg,
"[%s] Unable to parse StatInfo in response "
1560 OpenInfo *data =
new OpenInfo( (uint8_t*)buffer,
1561 pResponse->GetSessionId(),
1573 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as ChunkInfo",
1577 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1583 if( pPartialResps[i]->GetSize() > 8 )
1590 if( pResponse->GetSize() > 8 )
1595 return pBodyReader->GetResponse( response );
1603 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as PageInfo",
1610 ChunkInfo chunk = pChunkList->front();
1611 bool sizeMismatch =
false;
1612 uint32_t currentOffset = 0;
1613 char *cursor = (
char*)chunk.buffer;
1614 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1624 if( currentOffset + datalen > chunk.length )
1626 sizeMismatch =
true;
1630 currentOffset += datalen;
1635 size_t datalen = rspst->
status.
bdy.
dlen - NbPgPerRsp( rspst->
info.pgread.offset,
1637 if( currentOffset + datalen <= chunk.length )
1638 currentOffset += datalen;
1640 sizeMismatch =
true;
1645 if( pChunkStatus.front().sizeError || sizeMismatch )
1647 log->Error(
XRootDMsg,
"[%s] Handling response to %s: user supplied "
1648 "buffer is too small for the received data.",
1654 AnyObject *obj =
new AnyObject();
1655 PageInfo *pgInfo =
new PageInfo( chunk.offset, currentOffset, chunk.buffer,
1656 std::move( pCrc32cDigests) );
1668 std::vector<std::tuple<uint64_t, uint32_t>> retries;
1675 retries.reserve( pgcnt );
1679 for(
size_t i = 0; i < pgcnt; ++i )
1682 if( i == 0 ) len = cse->
dlFirst;
1683 else if( i == pgcnt - 1 ) len = cse->
dlLast;
1684 retries.push_back( std::make_tuple( pgoffs[i], len ) );
1688 RetryInfo *info =
new RetryInfo( std::move( retries ) );
1689 AnyObject *obj =
new AnyObject();
1702 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %p as "
1703 "VectorReadInfo", pUrl.
GetHostId().c_str(),
1706 for( uint32_t i = 0; i < pPartialResps.size(); ++i )
1712 if( pPartialResps[i]->GetSize() > 8 )
1719 if( pResponse->GetSize() > 8 )
1724 return pBodyReader->GetResponse( response );
1732 int len = rsp->hdr.dlen;
1733 char* data = rsp->body.buffer.data;
1735 return ParseXAttrResponse( data, len, response );
1746 AnyObject *obj =
new AnyObject();
1747 log->Dump(
XRootDMsg,
"[%s] Parsing the response to %s as BinaryData",
1752 data->Allocate( length );
1753 data->Append( buffer, length );
1766 Status XRootDMsgHandler::ParseXAttrResponse(
char *data,
size_t len,
1767 AnyObject *&response )
1780 if( !( status = ReadFromBuffer( data, len, nerrs ) ).IsOK() )
1784 if( !( status = ReadFromBuffer( data, len, nattr ) ).IsOK() )
1787 std::vector<XAttrStatus> resp;
1789 for(
kXR_char i = 0; i < nattr; ++i )
1792 if( !( status = ReadFromBuffer( data, len, rc ) ).IsOK() )
1800 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1805 resp.push_back( XAttrStatus( name, st ) );
1812 response =
new AnyObject();
1813 response->Set(
new std::vector<XAttrStatus>( std::move( resp ) ) );
1823 if( !( status = ReadFromBuffer( data, len, nerrs ) ).IsOK() )
1827 if( !( status = ReadFromBuffer( data, len, nattr ) ).IsOK() )
1830 std::vector<XAttr> resp;
1831 resp.reserve( nattr );
1834 for(
kXR_char i = 0; i < nattr; ++i )
1837 if( !( status = ReadFromBuffer( data, len, rc ) ).IsOK() )
1845 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1850 resp.push_back( XAttr( name, st ) );
1854 for(
kXR_char i = 0; i < nattr; ++i )
1857 if( !( status = ReadFromBuffer( data, len, vlen ) ).IsOK() )
1859 vlen = ntohl( vlen );
1862 if( !( status = ReadFromBuffer( data, len, vlen, value ) ).IsOK() )
1865 resp[i].value.swap( value );
1872 response =
new AnyObject();
1873 response->Set(
new std::vector<XAttr>( std::move( resp ) ) );
1881 std::vector<XAttr> resp;
1886 if( !( status = ReadFromBuffer( data, len, name ) ).IsOK() )
1890 if( !( status = ReadFromBuffer( data, len, vlen ) ).IsOK() )
1892 vlen = ntohl( vlen );
1895 if( !( status = ReadFromBuffer( data, len, vlen, value ) ).IsOK() )
1898 resp.push_back( XAttr( name, value ) );
1902 response =
new AnyObject();
1903 response->Set(
new std::vector<XAttr>( std::move( resp ) ) );
1917 Status XRootDMsgHandler::RewriteRequestRedirect(
const URL &newUrl )
1925 std::string xrdCgi =
"";
1926 std::ostringstream ossXrd;
1927 for(URL::ParamsMap::const_iterator it = newCgi.begin(); it != newCgi.end(); ++it )
1929 if( it->first.compare( 0, 4,
"xrd." ) )
1931 ossXrd << it->first <<
'=' << it->second <<
'&';
1934 xrdCgi = ossXrd.str();
1944 std::string surl = newUrl.
GetURL();
1945 (surl.find(
'?') == std::string::npos) ? (surl +=
'?') :
1946 ((*surl.rbegin() !=
'&') ? (surl +=
'&') : (surl +=
""));
1950 std::string surlLog = surl;
1954 log->Error(
XRootDMsg,
"[%s] Failed to build redirection URL from data: %s",
1955 newUrl.GetHostId().c_str(), surl.c_str());
1972 Status XRootDMsgHandler::RewriteRequestWait()
2007 void XRootDMsgHandler::HandleError( XRootDStatus status )
2015 if( pSidMgr && pMsgInFly && (
2026 if( !noreplicas ) pLastError = status;
2029 log->Debug(
XRootDMsg,
"[%s] Handling error while processing %s: %s.",
2031 status.ToString().c_str() );
2037 if( status.IsFatal() && status.code ==
errTlsError && status.errNo == EAGAIN )
2039 if( pSslErrCnt < MaxSslErrRetry )
2059 if( RetriableErrorResponse( status ) )
2061 UpdateTriedCGI(status.errNo);
2063 SwitchOnRefreshFlag();
2084 log->Error(
XRootDMsg,
"[%s] Unable to get the response to request %s",
2106 if( !status.IsFatal() && IsRetriable() )
2108 log->Info(
XRootDMsg,
"[%s] Retrying request: %s.",
2133 if( pRdirEntry ) pRedirectTraceBack.push_back( std::move( pRdirEntry ) );
2134 pRdirEntry.reset(
new RedirectEntry( pUrl.
GetLocation(), url.GetLocation(), entryType ) );
2138 pHosts->push_back( url );
2150 pSidMgr->ReleaseSID( req->
streamid );
2157 if( !url.IsLocalFile() )
2160 Status st = pSidMgr->AllocateSID( req->
streamid );
2163 log->Error(
XRootDMsg,
"[%s] Impossible to send message %s.",
2175 log->Debug(
ExDbgMsg,
"[%s] Metaling redirection for MsgHandler: %p (message: %s ).",
2179 return pPostMaster->
Redirect( pUrl, pRequest,
this );
2183 HandleLocalRedirect( &pUrl );
2188 log->Debug(
ExDbgMsg,
"[%s] Retry at server MsgHandler: %p (message: %s ).",
2191 return pPostMaster->
Send( pUrl, pRequest,
this,
true, pExpiration );
2198 void XRootDMsgHandler::UpdateTriedCGI(uint32_t errNo)
2208 if( pEffectiveDataServerUrl )
2211 delete pEffectiveDataServerUrl;
2212 pEffectiveDataServerUrl = 0;
2223 {
if (errNo ==
kXR_NotFound) cgi[
"triedrc"] =
"enoent";
2224 else if (errNo ==
kXR_IOError) cgi[
"triedrc"] =
"ioerr";
2225 else if (errNo ==
kXR_FSError) cgi[
"triedrc"] =
"fserr";
2236 HostList::reverse_iterator it;
2237 for( it = pHosts->rbegin()+1; it != pHosts->rend(); ++it )
2239 if( it->loadBalancer )
2242 tried +=
"," + it->url.GetHostName();
2249 cgi[
"tried"] = tried;
2258 void XRootDMsgHandler::SwitchOnRefreshFlag()
2284 void XRootDMsgHandler::HandleRspOrQueue()
2295 const int sst = pSendingState.fetch_or( kFinalResp );
2296 if( !( sst & kSendDone ) )
2301 if( jobMgr->IsWorker() )
2306 log->Debug(
ExDbgMsg,
"[%s] Passing to the thread-pool MsgHandler: %p (message: %s ).",
2316 void XRootDMsgHandler::HandleLocalRedirect( URL *url )
2319 log->Debug(
ExDbgMsg,
"[%s] Handling local redirect - MsgHandler: %p (message: %s ).",
2323 if( !pLFileHandler )
2329 AnyObject *resp = 0;
2331 XRootDStatus st = pLFileHandler->
Open( url, pRequest, resp );
2349 bool XRootDMsgHandler::IsRetriable()
2353 if( value ==
"true" )
return true;
2366 "[%s] Not allowed to retry open request (OpenRecovery disabled): %s.",
2381 bool XRootDMsgHandler::OmitWait( Message &request,
const URL &url )
2384 if( !url.IsMetalink() )
2396 VirtualRedirector *redirector = registry.Get( url );
2400 if( redirector->Count( request ) > 1 )
2409 bool XRootDMsgHandler::RetriableErrorResponse(
const Status &status )
2437 bool ret = pNotAuthorizedCounter < limit;
2438 ++pNotAuthorizedCounter;
2443 "[%s] Reached limit of NotAuthorized retries!",
2464 void XRootDMsgHandler::DumpRedirectTraceBack()
2466 if( pRedirectTraceBack.empty() )
return;
2468 std::stringstream sstrm;
2470 sstrm <<
"Redirect trace-back:\n";
2474 auto itr = pRedirectTraceBack.begin();
2475 sstrm <<
'\t' << counter <<
". " << (*itr)->ToString() <<
'\n';
2481 for( ; itr != pRedirectTraceBack.end(); ++itr, ++prev, ++counter )
2482 sstrm <<
'\t' << counter <<
". "
2483 << (*itr)->ToString( (*prev)->status.IsOK() ) <<
'\n';
2488 bool warn = !pStatus.
IsOK() &&
2495 log->Warning(
XRootDMsg,
"%s", sstrm.str().c_str() );
2497 log->Debug(
XRootDMsg,
"%s", sstrm.str().c_str() );
2502 template<
typename T>
2503 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen, T& result )
2507 memcpy(&result, buffer,
sizeof(T));
2509 buffer +=
sizeof( T );
2510 buflen -=
sizeof( T );
2518 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen, std::string &result )
2525 if( !( status = ReadFromBuffer( buffer, buflen, c ) ).IsOK() )
2538 Status XRootDMsgHandler::ReadFromBuffer(
char *&buffer,
size_t &buflen,
2539 size_t size, std::string &result )
2545 result.append( buffer, size );
union ServerResponse::@0 body
struct ClientFattrRequest fattr
#define kXR_collapseRedir
ServerResponseStatus status
struct ClientDirlistRequest dirlist
static const int kXR_ckpXeq
struct ClientOpenRequest open
struct ServerResponseBody_Status bdy
struct ClientRequestHdr header
struct ClientChkPointRequest chkpoint
struct ServerResponseHeader hdr
union ServerResponseV2::@1 info
#define kXR_PROTOCOLVERSION
struct ClientStatRequest stat
struct ClientLocateRequest locate
std::string obfuscateAuth(const std::string &input)
void Get(Type &object)
Retrieve the object being held.
void AdvanceCursor(uint32_t delta)
Advance the cursor.
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
void SetCursor(uint32_t cursor)
Set the cursor.
uint32_t GetCursor() const
Get append cursor.
char * GetBufferAtCursor()
Get the buffer pointer at the append cursor.
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
static bool HasStatInfo(const char *data)
Returns true if data contain stat info.
bool GetString(const std::string &key, std::string &value)
bool GetInt(const std::string &key, int &value)
virtual void Run(void *arg)
The job logic.
HandleRspJob(XrdCl::XRootDMsgHandler *handler)
Interface for a job to be run by the job manager.
void SetHostList(const HostList &hostList)
XRootDStatus Open(const std::string &url, uint16_t flags, uint16_t mode, ResponseHandler *handler, uint16_t timeout=0)
void Error(uint64_t topic, const char *format,...)
Report an error.
void Warning(uint64_t topic, const char *format,...)
Report a warning.
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
void Debug(uint64_t topic, const char *format,...)
Print a debug message.
static void RewriteCGIAndPath(Message *msg, const URL::ParamsMap &newCgi, bool replace, const std::string &newPath)
Append cgi to the one already present in the message.
The message representation used throughout the system.
const std::string & GetObfuscatedDescription() const
Get the description of the message with authz parameter obfuscated.
uint64_t GetSessionId() const
Get the session ID the message is meant for.
@ More
there are more (non-raw) data to be read
@ Ignore
Ignore the message.
StreamEvent
Events that may have occurred to the stream.
@ Ready
The stream has become connected.
void CollapseRedirect(const URL &oldurl, const URL &newURL)
Collapse channel URL - replace the URL of the channel.
XRootDStatus Send(const URL &url, Message *msg, MsgHandler *handler, bool stateful, time_t expires)
TaskManager * GetTaskManager()
Get the task manager object user by the post master.
Status Redirect(const URL &url, Message *msg, MsgHandler *handler)
Status QueryTransport(const URL &url, uint16_t query, AnyObject &result)
JobManager * GetJobManager()
Get the job manager object user by the post master.
static RedirectorRegistry & Instance()
Returns reference to the single instance.
virtual void HandleResponseWithHosts(XRootDStatus *status, AnyObject *response, HostList *hostList)
static SIDMgrPool & Instance()
std::shared_ptr< SIDManager > GetSIDMgr(const URL &url)
virtual XRootDStatus Send(const char *buffer, size_t size, int &bytesWritten)
void RegisterTask(Task *task, time_t time, bool own=true)
Interface for a task to be run by the TaskManager.
virtual time_t Run(time_t now)=0
void SetName(const std::string &name)
Set name of the task.
std::string GetHostId() const
Get the host part of the URL (user:password@host:port)
bool IsMetalink() const
Is it a URL to a metalink.
const std::string & GetHostName() const
Get the name of the target host.
std::map< std::string, std::string > ParamsMap
bool FromString(const std::string &url)
Parse a string and fill the URL fields.
void SetPassword(const std::string &password)
Set the password.
const std::string & GetProtocol() const
Get the protocol.
void SetParams(const std::string ¶ms)
Set params.
std::string GetURL() const
Get the URL.
std::string GetLocation() const
Get location (protocol://host:port/path)
const std::string & GetUserName() const
Get the username.
const std::string & GetPassword() const
Get the password.
const ParamsMap & GetParams() const
Get the URL params.
void SetProtocol(const std::string &protocol)
Set protocol.
bool IsValid() const
Is the url valid.
void SetUserName(const std::string &userName)
Set the username.
static void splitString(Container &result, const std::string &input, const std::string &delimiter)
Split a string.
static bool CheckEC(const Message *req, const URL &url)
Check if this client can support given EC redirect.
Handle/Process/Forward XRootD messages.
const Message * GetRequest() const
Get the request pointer.
virtual uint16_t InspectStatusRsp() override
friend class HandleRspJob
virtual void OnStatusReady(const Message *message, XRootDStatus status) override
The requested action has been performed and the status is available.
virtual uint16_t Examine(std::shared_ptr< Message > &msg) override
void WaitDone(time_t now)
virtual void Process() override
Process the message if it was "taken" by the examine action.
virtual XRootDStatus ReadMessageBody(Message *msg, Socket *socket, uint32_t &bytesRead) override
XRootDStatus WriteMessageBody(Socket *socket, uint32_t &bytesWritten) override
virtual uint8_t OnStreamEvent(StreamEvent event, XRootDStatus status) override
virtual uint16_t GetSid() const override
virtual bool IsRaw() const override
Are we a raw writer or not?
const std::string & GetErrorMessage() const
Get error message.
static void SetDescription(Message *msg)
Get the description of a message.
static XRootDStatus UnMarshallBody(Message *msg, uint16_t reqType)
Unmarshall the body of the incoming message.
static XRootDStatus UnMarshallRequest(Message *msg)
static XRootDStatus UnMarshalStatusBody(Message &msg, uint16_t reqType)
Unmarshall the body of the status response.
static XRootDStatus MarshallRequest(Message *msg)
Marshal the outgoing message.
static int csNum(off_t offs, int count)
Compute the required size of a checksum vector based on offset & length.
const uint16_t errRedirectLimit
const int DefaultMaxMetalinkWait
const uint16_t errErrorResponse
const uint16_t errTlsError
const uint16_t errOperationExpired
const uint16_t stFatal
Fatal error, it's still an error.
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errNotFound
std::vector< HostInfo > HostList
const uint16_t errDataError
data is corrupted
const uint16_t errInternal
Internal error.
const uint16_t stOK
Everything went OK.
const uint16_t errInvalidResponse
const uint16_t errInvalidRedirectURL
const uint16_t errNotSupported
Buffer BinaryDataInfo
Binary buffer.
const uint16_t errOperationInterrupted
const uint16_t suContinue
const int DefaultNotAuthorizedRetryLimit
const uint16_t errRedirect
const uint16_t errAuthFailed
const uint16_t errInvalidMessage
none object for initializing empty Optional
static const int PageSize
ssize_t Move(KernelBuffer &kbuff, char *&ubuff)
Describe a data chunk for vector read.
void * buffer
length of the chunk
uint32_t length
offset in the file
Procedure execution status.
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
std::string ToString() const
Create a string representation.
static const uint16_t ServerFlags
returns server flags
static const uint16_t ProtocolVersion
returns the protocol version