Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
XrdProofConn.h
Go to the documentation of this file.
1 // @(#)root/proofd:$Id$
2 // Author: G. Ganis June 2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_XrdProofConn
13 #define ROOT_XrdProofConn
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // XrdProofConn //
18 // //
19 // Authors: G. Ganis, CERN, 2005 //
20 // //
21 // Low level handler of connections to xproofd. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #define DFLT_CONNECTMAXTRY 10
26 
27 #include "XrdSysToOuc.h"
28 #include "XProofProtocol.h"
29 #include "XProofProtUtils.h"
32 #ifndef __OUC_STRING_H__
33 #include "XrdOuc/XrdOucString.hh"
34 #endif
35 
36 #include <list>
37 
38 class XrdClientConnectionMgr;
39 class XrdClientMessage;
40 class XrdClientPhyConnection;
41 class XrdSysRecMutex;
42 class XrdSecProtocol;
43 class XrdSysPlugin;
44 
45 // Generic sender
46 typedef int (*XrdProofConnSender_t)(const char *, int, void *);
47 
48 class XrdProofConn : public XrdClientAbsUnsolMsgHandler {
49 
50 friend class TXSocket;
51 friend class TXUnixSocket;
52 friend class XrdProofPhyConn;
53 
54 public:
55 
56  enum ESrvType { kSTError = -1, kSTNone, kSTXProofd, kSTProofd };
57 
58 private:
59 
60  char fMode; // Type of client
61  bool fConnected;
62  int fLogConnID; // Logical connection ID of current object
63  kXR_unt16 fStreamid; // Streamid used for normal communications
64  int fRemoteProtocol; // Protocol of remote daemon
65  int fServerProto; // The server protocol
66  ESrvType fServerType; // Server type as returned by DoHandShake()
67  // (see enum ServerType)
68  short fSessionID; // proofsrv: remote ID of connected session
69  XrdOucString fUser; // Username used for login
70  XrdOucString fHost; // Remote host
71  int fPort; // Remote port
72  XrdOucString fLastErrMsg; // Msg describing last error
73  XErrorCode fLastErr; // Last error code
74  char fCapVer; // a version number (e.g. a protocol num)
75 
76  XrdOucString fLoginBuffer; // Buffer to be sent over at login
77 
78  XrdSysRecMutex *fMutex; // Lock SendRecv actions
79 
80  XrdSysRecMutex *fConnectInterruptMtx; // Protect access to fConnectInterrupt
81  bool fConnectInterrupt;
82 
83  XrdClientPhyConnection *fPhyConn; // underlying physical connection
84 
85  int fOpenSockFD; // Underlying socket descriptor
86 
87  XrdClientAbsUnsolMsgHandler *fUnsolMsgHandler; // Handler of unsolicited responses
88 
89  XrdProofConnSender_t fSender; // Generic message forwarder
90  void *fSenderArg; // Optional rgument for the message forwarder
91 
92  XrdClientUrlInfo fUrl; // Connection URL info object with
93 
94  static XrdClientConnectionMgr *fgConnMgr; //Connection Manager
95 
96  static int fgMaxTry; //max number of connection attempts
97  static int fgTimeWait; //Wait time between an attempt and the other
98 
99  static XrdSysPlugin *fgSecPlugin; // Sec library plugin
100  static void *fgSecGetProtocol; // Sec protocol getter
101 
102  XrdSecProtocol *Authenticate(char *plist, int lsiz);
103  bool CheckErrorStatus(XrdClientMessage *, int &, const char *, bool);
104  bool CheckResp(struct ServerResponseHeader *resp,
105  const char *met, bool);
106  virtual void Connect(int = -1);
107  void ReConnect();
108  virtual int TryConnect(int = -1);
109 
110  ESrvType DoHandShake(XrdClientPhyConnection *p = 0);
111  virtual bool GetAccessToSrv(XrdClientPhyConnection *p = 0);
112  virtual bool Init(const char *url = 0, int = -1);
113  bool Login();
114  bool MatchStreamID(struct ServerResponseHeader *resp);
115  XrdClientMessage *SendRecv(XPClientRequest *req,
116  const void *reqData, char **answData);
117 
118  void SetInterrupt();
119 
120  void SetConnectInterrupt();
121  bool ConnectInterrupt();
122 
123 public:
124  XrdProofConn(const char *url, char mode = 'M', int psid = -1, char ver = -1,
125  XrdClientAbsUnsolMsgHandler * uh = 0, const char *logbuf = 0);
126  virtual ~XrdProofConn();
127 
128  virtual void Close(const char *opt = "");
129 
130  int GetLogConnID() const { return fLogConnID; }
131  int GetLowSocket();
132  int GetOpenError() const { return (int)fLastErr; }
133  int GetServType() const { return (int)fServerType; }
134  short GetSessionID() const { return fSessionID; }
135  const char *GetUrl() { return (const char *) fUrl.GetUrl().c_str(); }
136  const char *GetLastErr() { return fLastErrMsg.c_str(); }
137 
138  bool IsValid() const;
139 
140  XReqErrorType LowWrite(XPClientRequest *, const void *, int);
141 
142  // Send, Recv interfaces
143  virtual int ReadRaw(void *buf, int len, XrdClientPhyConnection *p = 0);
144  virtual XrdClientMessage *ReadMsg();
145  XrdClientMessage *SendReq(XPClientRequest *req, const void *reqData,
146  char **answData, const char *CmdName,
147  bool notifyerr = 1);
148  virtual void SetAsync(XrdClientAbsUnsolMsgHandler *uh, XrdProofConnSender_t = 0, void * = 0);
149  void SetSID(kXR_char *sid);
150  virtual int WriteRaw(const void *buf, int len, XrdClientPhyConnection *p = 0);
151 
152  static void GetRetryParam(int &maxtry, int &timewait);
153  static void SetRetryParam(int maxtry = 5, int timewait = 2);
154 
155  virtual UnsolRespProcResult ProcessUnsolicitedMsg(XrdClientUnsolMsgSender *s,
156  XrdClientMessage *m);
157 };
158 
159 #endif