XRootD
Loading...
Searching...
No Matches
XrdHttpExtHandler.cc
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of XrdHTTP: A pragmatic implementation of the
3// HTTP/WebDAV protocol for the Xrootd framework
4//
5// Copyright (c) 2017 by European Organization for Nuclear Research (CERN)
6// Author: Fabrizio Furano <furano@cern.ch>
7// File Date: May 2017
8//------------------------------------------------------------------------------
9// XRootD is free software: you can redistribute it and/or modify
10// it under the terms of the GNU Lesser General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// XRootD is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public License
20// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
21//------------------------------------------------------------------------------
22
23
24#include "Xrd/XrdLink.hh"
25#include "XrdHttpExtHandler.hh"
26#include "XrdHttpReq.hh"
27#include "XrdHttpProtocol.hh"
28#include "XrdOuc/XrdOucEnv.hh"
29
31int XrdHttpExtReq::SendSimpleResp(int code, const char* desc, const char* header_to_add, const char* body, long long int bodylen)
32{
33 if (!prot) return -1;
34
35 // @FIXME
36 // - need this to circumvent missing API calls and keep ABI compatibility
37 // - when large files are returned we cannot return them in a single buffer
38 // @TODO: for XRootD 5.0 this two hidden calls should just be added to the external handler API and the code here can be removed
39
40 if ( code == 0 ) {
41 return prot->StartSimpleResp(200, desc, header_to_add, bodylen, true);
42 }
43
44 if ( code == 1 ) {
45 return prot->SendData(body, bodylen);
46 }
47
48 return prot->SendSimpleResp(code, desc, header_to_add, body, bodylen, true);
49}
50
51int XrdHttpExtReq::StartChunkedResp(int code, const char *desc, const char *header_to_add)
52{
53 if (!prot) return -1;
54
55 return prot->StartChunkedResp(code, desc, header_to_add, -1, true);
56}
57
58int XrdHttpExtReq::ChunkResp(const char *body, long long bodylen)
59{
60 if (!prot) return -1;
61
62 return prot->ChunkResp(body, bodylen);
63}
64
65int XrdHttpExtReq::BuffgetData(int blen, char **data, bool wait) {
66
67 if (!prot) return -1;
68 int nb = prot->BuffgetData(blen, data, wait);
69
70 return nb;
71}
72
73void XrdHttpExtReq::GetClientID(std::string &clid)
74{
75 char buff[512];
76 prot->Link->Client(buff, sizeof(buff));
77 clid = buff;
78}
79
81{
82 return prot->SecEntity;
83}
84
85
87verb(req->requestverb), headers(req->allheaders) {
88 // Here we fill the request summary with all the fields we can
89 resource = req->resource.c_str();
90 int envlen = 0;
91
92 const char *p = nullptr;
93 if (req->opaque)
94 p = req->opaque->Env(envlen);
95 headers["xrd-http-query"] = p ? p:"";
96 p = req->resourceplusopaque.c_str();
97 headers["xrd-http-fullresource"] = p ? p:"";
98 headers["xrd-http-prot"] = prot->isHTTPS()?"https":"http";
99
100 // These fields usually identify the client that connected
101
102
103 if (prot->SecEntity.moninfo) {
104 clientdn = prot->SecEntity.moninfo;
105 trim(clientdn);
106 }
107 if (prot->SecEntity.host) {
108 clienthost = prot->SecEntity.host;
109 trim(clienthost);
110 }
111 if (prot->SecEntity.vorg) {
112 clientgroups = prot->SecEntity.vorg;
113 trim(clientgroups);
114 }
115
116 // Get the packet marking handle and the client scitag from the XrdHttp layer
117 pmark = prot->pmarkHandle;
118 mSciTag = req->mScitag;
119
120 tpcForwardCreds = prot->tpcForwardCreds;
121
122 length = req->length;
123}
A pragmatic implementation of the HTTP/DAV protocol for the Xrd framework.
Main request/response class, handling the logical status of the communication.
if(Avsz)
int ChunkResp(const char *body, long long bodylen)
Send a (potentially partial) body in a chunked response; invoking with NULL body.
XrdHttpExtReq(XrdHttpReq *req, XrdHttpProtocol *pr)
void GetClientID(std::string &clid)
std::map< std::string, std::string > & headers
std::string resource
int StartChunkedResp(int code, const char *desc, const char *header_to_add)
Starts a chunked response; body of request is sent over multiple parts using the SendChunkResp.
XrdNetPMark * pmark
int BuffgetData(int blen, char **data, bool wait)
Get a pointer to data read from the client, valid for up to blen bytes from the buffer....
const XrdSecEntity & GetSecEntity() const
int SendSimpleResp(int code, const char *desc, const char *header_to_add, const char *body, long long bodylen)
Sends a basic response. If the length is < 0 then it is calculated internally.
long long length
XrdOucString resource
The resource specified by the request, stripped of opaque data.
XrdOucEnv * opaque
The opaque data, after parsing.
XrdOucString resourceplusopaque
The resource specified by the request, including all the opaque data.
char * Env(int &envlen)
Definition XrdOucEnv.hh:48
const char * c_str() const