27#include "XrdNet/XrdNetAddr.hh"
45#include "XrdOuc/XrdOucErrInfo.hh"
46#include "XrdOuc/XrdOucString.hh"
47#include "XrdSec/XrdSecInterface.hh"
48#include "XrdSys/XrdSysLogger.hh"
49#include "XrdSys/XrdSysPlatform.hh"
53#if (defined(SUNCC) || defined(SUN))
54#include <sys/isa_defs.h>
55#if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
56#undef _FILE_OFFSET_BITS
57#define _FILE_OFFSET_BITS 32
58#undef _LARGEFILE_SOURCE
64#if !defined(__APPLE__)
74# include <sys/socket.h>
97#define URLTAG "["<<fUrl.Host<<":"<<fUrl.Port<<"]"
114 : fMode(
m), fConnected(0), fLogConnID(-1), fStreamid(0), fRemoteProtocol(-1),
115 fServerProto(-1), fServerType(
kSTNone), fSessionID(
psid), fPort(-1),
117 fConnectInterruptMtx(0), fConnectInterrupt(0), fPhyConn(0),
118 fOpenSockFD(-1), fUnsolMsgHandler(
uh), fSender(0), fSenderArg(0)
129 TRACE(
XERR,
"XrdProofConn: severe error occurred while opening a"
130 " connection" <<
" to server "<<
URLTAG);
166 TRACE(
XERR,
"error initializing connection manager");
175 if (
fUser.length() <= 0) {
219 TRACE(
ALL,
"got an interrupt while connecting - aborting attempts");
245 msg.erase(
msg.rfind(
":"));
258 TRACE(
DBG,
"connection successfully created");
271 const char *
cdef = (
fUrl.
Host ==
"lite") ?
" (or \"\": check 'Proof.LocalDefault')" :
"";
273 const char *
cses = (
fUrl.
Host ==
"lite") ?
"PROOF-Lite" :
"PoD";
274 TRACE(
ALL,
"connection attempt to server \""<<
fUrl.
Host<<
"\" failed. We are going to retry after some sleep,");
275 TRACE(
ALL,
"but if you intended to start a "<<
cses<<
" session instead, please note that you must");
334 TRACE(
DBG,
"server does not support reconnections (protocol: %d" <<
363 for (; i <
naddr; i++ ) {
377 if (
aNA.Format(
ha, 256) <= 0) {
431 bool closephys = (opt[0] ==
'P') ? 1 : 0;
455 XPDLOC(
ALL,
"Conn::ProcessUnsolicitedMsg")
457 TRACE(
DBG,
"processing unsolicited response");
459 if (!
m ||
m->IsError()) {
460 TRACE(
XERR,
"Got empty or error unsolicited message");
464 if ((
len =
m->DataLen()) < (
int)
sizeof(kXR_int32)) {
465 TRACE(
XERR,
"empty or bad-formed message - ignoring");
473 void *
pdata = (
void *)((
char *)(
m->GetData()) +
sizeof(kXR_int32));
481 if (opt == 0 || opt == 1 || opt == 2) {
483 pdata = (
void *)((
char *)
pdata +
sizeof(kXR_int32));
484 len -=
sizeof(kXR_int32);
600 TRACE(
DBG,
"dumping read data ...");
601 for (
int jj = 0;
jj <
xmsg->DataLen();
jj++) {
613 TRACE(
XERR,
"status in reply is unknown ["<<
615 "] (server "<<
URLTAG<<
") - Abort");
676 TRACE(
XERR,
"max number of retries reached - Abort");
683 TRACE(
XERR,
"not connected: nothing to do");
703 TRACE(
XERR,
"max number of retries reached - Abort");
738 " did not return OK replying to last request");
747 " - protocol error");
855 if (
mex->DataLen() > 4) {
857 " secs); message: "<<(
const char*)
body_wait->infomsg);
870 TRACE(
XERR,
"after: "<<
CmdName<<
": server reply not recognized - protocol error");
904 dum[0] = (kXR_int32)
htonl(0);
905 dum[1] = (kXR_int32)
htonl(2034);
936 if (phyconn && phyconn->
IsValid()) {
951 if (phyconn && phyconn->
IsValid()) {
996 dum[0] = (kXR_int32)
htonl(4);
997 dum[1] = (kXR_int32)
htonl(2012);
1014 TRACE(
ALL,
"-----------------------");
1015 TRACE(
ALL,
"TimeOut condition reached reading from remote server.");
1016 TRACE(
ALL,
"This may indicate that the server is a 'proofd', version <= 12");
1017 TRACE(
ALL,
"Retry commenting the 'Plugin.TSlave' line in system.rootrc or adding");
1018 TRACE(
ALL,
"Plugin.TSlave: ^xpd TSlave Proof \"TSlave(const char *,const char"
1019 " *,int,const char *, TProof *,ESlaveType,const char *,const char *)\"");
1020 TRACE(
ALL,
"to your $HOME/.rootrc .");
1021 TRACE(
ALL,
"-----------------------");
1054 }
else if (
type == 8) {
1095 if (
ug.length() > 8) {
1105 }
else if (
ug.length() >= 0) {
1107 if (
ug.length() < 8)
reqhdr.login.username[
ug.length()] =
'\0';
1114 const void *buf = (
const void *)(
fLoginBuffer.c_str());
1132 XrdOucString
usr((
const char *)&
reqhdr.login.username[0], 8);
1161 &
pltmp,
"XrdProofConn::Login", 0);
1169 if (
len >= (
int)
sizeof(kXR_int32)) {
1174 pltmp = (
char *)((
char *)
pltmp +
sizeof(kXR_int32));
1175 len -=
sizeof(kXR_int32);
1186 s =
new char [
strlen(
"XrdSecDEBUG")+20];
1191 s =
new char [
strlen(
"XrdSecUSER")+
fUser.length()+2];
1195 s =
new char [
strlen(
"XrdSecHOST")+
fHost.length()+2];
1204 netrc +=
"/.rootnetrc";
1207 if (
netrc.length() > 0) {
1208 s =
new char [
strlen(
"XrdSecNETRC")+
netrc.length()+2];
1217 TRACE(
DBG,
"server requires authentication");
1280 if (XrdSysDNS::getHostAddr((
char *)
fUrl.
HostAddr.c_str(),
1300 TRACE(
XERR,
"unable to allocate buffer for parameters");
1315#if !defined(ROOT_XrdNoUtils)
1326 TRACE(
XERR,
"unable to load XrdSecGetProtocol()");
1336 XrdOucString
protname = protocol->Entity.prot;
1346 fLastErrMsg +=
"cannot obtain credentials for protocol: ";
1376 dlen = (
xrsp) ?
xrsp->DataLen() : 0;
1377 TRACE(
HDBG,
"server reply: status: "<<status<<
" dlen: "<<dlen);
1391 TRACE(
XERR,
"cannot obtain credentials");
1408 }
else if (status !=
kXR_ok) {
1432 TRACE(
XERR,
"unable to get protocol object.");
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define TRACE(Flag, Args)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
R__EXTERN C unsigned int sleep(unsigned int seconds)
#define NAME_CONNECTTIMEOUT
#define TXSOCK_ERR_TIMEOUT
#define NAME_FIRSTCONNECTMAXCNT
XrdSecProtocol *(* secGetProt_t)(const char *, const struct sockaddr &, const XrdSecParameters &, XrdOucErrInfo *)
int(* XrdProofConnSender_t)(const char *, int, void *)
#define XrdSysMutexHelper
int ReadRaw(void *buffer, int BufferLength, int substreamid=-1, int *usedsubstreamid=0)
int WriteRaw(const void *buffer, int BufferLength, int substreamid=0)
ERemoteServerType fServerType
void SetLogged(ELoginState status)
void SetSecProtocol(XrdSecProtocol *sp)
void TakeUrl(XrdOucString url)
ESrvType DoHandShake(XrdClientPhyConnection *p=0)
Performs initial hand-shake with the server in order to understand which kind of server is there at t...
virtual int TryConnect(int=-1)
Connect to remote server.
static void GetRetryParam(int &maxtry, int &timewait)
Retrieve current values of the retry control parameters, numer of retries and wait time between attem...
XrdClientPhyConnection * fPhyConn
XrdClientMessage * SendReq(XPClientRequest *req, const void *reqData, char **answData, const char *CmdName, bool notifyerr=1)
SendReq tries to send a single command for a number of times.
static void * fgSecGetProtocol
virtual bool Init(const char *url=0, int=-1)
Initialization.
XrdSecProtocol * Authenticate(char *plist, int lsiz)
Negotiate authentication with the remote server.
bool ConnectInterrupt()
Check if interrupted during connect.
bool CheckErrorStatus(XrdClientMessage *, int &, const char *, bool)
Check error status.
virtual void SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t=0, void *=0)
Set handler of unsolicited responses.
XrdProofConnSender_t fSender
virtual bool GetAccessToSrv(XrdClientPhyConnection *p=0)
Gets access to the connected server.
bool MatchStreamID(struct ServerResponseHeader *resp)
Check stream ID matching.
XrdOucRecMutex * fConnectInterruptMtx
XrdClientAbsUnsolMsgHandler * fUnsolMsgHandler
virtual UnsolRespProcResult ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *s, XrdClientMessage *m)
We are here if an unsolicited response comes from a logical conn The response comes in the form of an...
bool IsValid() const
Test validity of this connection.
virtual int WriteRaw(const void *buf, int len, XrdClientPhyConnection *p=0)
Low level write call.
bool CheckResp(struct ServerResponseHeader *resp, const char *met, bool)
Checks if the server's response is ours.
virtual void Close(const char *opt="")
Close connection.
XrdClientMessage * SendRecv(XPClientRequest *req, const void *reqData, char **answData)
SendRecv sends a command to the server and to get a response.
static XrdClientConnectionMgr * fgConnMgr
virtual ~XrdProofConn()
Destructor.
virtual XrdClientMessage * ReadMsg()
Pickup message from the queue.
void SetSID(kXR_char *sid)
Set our stream id, to match against that one in the server's response.
XReqErrorType LowWrite(XPClientRequest *, const void *, int)
Send request to server (NB: req is marshalled at this point, so we need also the plain reqDataLen)
const char * GetLastErr()
virtual void Connect(int=-1)
Run the connection attempts: the result is stored in fConnected.
XrdOucString fLoginBuffer
static XrdOucPlugin * fgSecPlugin
int GetLowSocket()
Return the socket descriptor of the underlying connection.
XrdProofConn(const char *url, char mode='M', int psid=-1, char ver=-1, XrdClientAbsUnsolMsgHandler *uh=0, const char *logbuf=0)
Constructor.
bool Login()
This method perform the loggin-in into the server just after the hand-shake.
void ReConnect()
Perform a reconnection attempt when a connection is not valid any more.
static void SetRetryParam(int maxtry=5, int timewait=2)
Change values of the retry control parameters, numer of retries and wait time between attempts (in se...
virtual int ReadRaw(void *buf, int len, XrdClientPhyConnection *p=0)
Low level receive call.
void SetInterrupt()
Interrupt the underlying socket.
void SetConnectInterrupt()
Interrupt connection attempts.
void smartPrintClientHeader(XPClientRequest *hdr)
char * convertRespStatusToChar(kXR_int16 status)
void ServerInitHandShake2HostFmt(struct ServerInitHandShake *srh)
void smartPrintServerHeader(struct ServerResponseHeader *hdr)
int clientMarshall(XPClientRequest *str)
This function applies the network byte order on those parts of the 16-bytes buffer,...
struct ClientRequestHdr header
struct XPClientSendRcvRequest sendrcv