39 #include "XrdVersion.hh"
46 char *XrdProtLoad::ProtName[ProtoMax] = {0};
48 int XrdProtLoad::ProtoCnt = 0;
57 portMap(
int pnum,
int pidx,
bool istls)
58 : port(pnum), protIdx(pidx), protTLS(istls) {}
62 std::vector<portMap> portVec;
66 const char *TraceID =
"ProtLoad";
88 for (
int i = 0; i < (int)portVec.size(); i++)
89 {
if (myPort == portVec[i].port)
90 {
if (portVec[i].protTLS) hastls =
true;
91 else myProt[j++] = portVec[i].protIdx;
99 for (
int i = 0; i < (int)portVec.size(); i++)
100 {
if (myPort == portVec[i].port && portVec[i].protTLS)
101 myProt[j++] = portVec[i].protIdx;
124 TRACE(
DEBUG,
"getting protocol object " <<pname);
129 {
Log.
Emsg(
"Protocol",
"Too many protocols have been defined.");
135 xp = getProtocol(lname, pname, parms, pi);
136 if (!xp) {
Log.
Emsg(
"Protocol",
"Protocol", pname,
"could not be loaded");
142 ProtName[ProtoCnt] = strdup(pname);
143 Protocol[ProtoCnt] = xp;
148 Port(ProtoCnt, port, istls);
163 port = getProtocolPort(lname, pname, parms, pi);
167 TRACE(
DEBUG,
"protocol " <<pname <<
" wants to use port " <<port);
171 if (port < 0)
Log.
Emsg(
"Protocol",
"Protocol", pname,
172 "port number could not be determined");
180 if (protIdx > 0 && protIdx <= ProtoCnt && port > 0)
181 {portMap pMap(port, protIdx-1, isTLS);
182 portVec.push_back(pMap);
183 TRACE(
DEBUG,
"enabling " <<(isTLS ?
"tls port " :
"port ") <<port
184 <<
" for protocol " <<ProtName[protIdx-1]);
187 snprintf(buff,
sizeof(buff),
"prot=%d port=%d;", protIdx, port);
188 Log.
Emsg(
"Protocol",
"Invalid Port() parms:", buff,
"port not mapped!");
199 signed char *pVec = myProt;
207 {lp->
setEtext(
"TLS negotiation failed.");
211 if ((pp = Protocol[i]->
Match(lp)))
break;
219 if (!pp) {lp->
setEtext(
"matching protocol not found");
return -1;}
228 TRACE(
DEBUG,
"matched port " <<myPort <<
" protocol " <<ProtName[i]);
249 Log.
Emsg(
"Protocol", lp->
ID,
"terminated", reason);
258 int i, k, totlen = 0;
260 for (i = 0; i < ProtoCnt && (blen > 0 || !buff); i++)
261 {k = Protocol[i]->
Stats(buff, blen, do_sync);
262 totlen += k; buff += k; blen -= k;
278 XrdProtocol *XrdProtLoad::getProtocol(
const char *lname,
284 const char *xname = (lname ? lname :
"");
294 for (i = 0; i < libcnt; i++)
if (!strcmp(xname, liblist[i]))
break;
296 {
Log.
Emsg(
"Protocol", pname,
"was lost during loading", lname);
302 if (!(epvoid = libhndl[i]->Resolve(
"XrdgetProtocol")))
return 0;
304 return ep(pname, parms, pi);
314 int XrdProtLoad::getProtocolPort(
const char *lname,
320 const char *xname = (lname ? lname :
"");
331 for (i = 0; i < libcnt; i++)
if (!strcmp(xname, liblist[i]))
break;
334 {
Log.
Emsg(
"Protocol",
"Too many protocols have been defined.");
339 liblist[i] = strdup(xname);
345 if (!(epvoid = libhndl[i]->Resolve(
"XrdgetProtocolPort", 2)))
346 return (pi->
Port < 0 ? 0 : pi->
Port);
348 return ep(pname, parms, pi);
XrdProtocol * XrdgetProtocol(const char *pname, char *parms, XrdProtocol_Config *pi)
int XrdgetProtocolPort(const char *pname, char *parms, XrdProtocol_Config *pi)
XrdProtocol * setProtocol(XrdProtocol *pp, bool runit=false, bool push=false)
int setEtext(const char *text)
bool setTLS(bool enable, XrdTlsContext *ctx=0)
Enable or disable TLS on the link.
char * ID
Pointer to the client's link identity.
void setProtName(const char *name)
void Recycle(XrdLink *lp, int ctime, const char *txt)
XrdProtocol * Match(XrdLink *)
static int Statistics(char *buff, int blen, int do_sync=0)
static int Port(const char *lname, const char *pname, char *parms, XrdProtocol_Config *pi)
static int Load(const char *lname, const char *pname, char *parms, XrdProtocol_Config *pi, bool istls)
static const int ProtoMax
virtual int Stats(char *buff, int blen, int do_sync=0)=0
virtual int Process(XrdLink *lp)=0
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdVERSIONINFODEF(myVersion, cmsclient, XrdVNUMBER, XrdVERSION)