XRootD
Loading...
Searching...
No Matches
TPC::State Class Reference

#include <XrdTpcState.hh>

Collaboration diagram for TPC::State:

Public Member Functions

 State ()
 State (CURL *curl, bool tpcForwardCreds)
 State (off_t start_offset, Stream &stream, CURL *curl, bool push, bool tpcForwardCreds)
 ~State ()
int AvailableBuffers () const
bool BodyTransferInProgress () const
off_t BytesTransferred () const
void CopyHeaders (XrdHttpExtReq &req)
void DumpBuffers () const
StateDuplicate ()
bool Finalize ()
int Flush ()
std::string GetConnectionDescription ()
off_t GetContentLength () const
int GetErrorCode () const
std::string GetErrorMessage () const
CURLGetHandle () const
int GetStatusCode () const
void Move (State &other)
void ResetAfterRequest ()
void SetContentLength (const off_t content_length)
void SetErrorCode (int error_code)
void SetErrorMessage (const std::string &error_msg)
void SetTransferParameters (off_t offset, size_t size)

Detailed Description

Definition at line 21 of file XrdTpcState.hh.

Constructor & Destructor Documentation

◆ State() [1/3]

TPC::State::State ( )
inline

Definition at line 24 of file XrdTpcState.hh.

24 :
25 m_push(true),
26 m_recv_status_line(false),
27 m_recv_all_headers(false),
28 m_offset(0),
29 m_start_offset(0),
30 m_status_code(-1),
31 m_error_code(0),
32 m_content_length(-1),
33 m_stream(NULL),
34 m_curl(NULL),
35 m_headers(NULL),
36 m_is_transfer_state(true)
37 {}

Referenced by Duplicate(), and Move().

Here is the caller graph for this function:

◆ State() [2/3]

TPC::State::State ( CURL * curl,
bool tpcForwardCreds )
inline

Don't use that constructor if you want to do some transfers.

Parameters
curlthe curl handle

Definition at line 43 of file XrdTpcState.hh.

43 :
44 m_push(true),
45 m_recv_status_line(false),
46 m_recv_all_headers(false),
47 m_offset(0),
48 m_start_offset(0),
49 m_status_code(-1),
50 m_error_code(0),
51 m_content_length(-1),
52 m_stream(NULL),
53 m_curl(curl),
54 m_headers(NULL),
55 m_is_transfer_state(false),
56 tpcForwardCreds(tpcForwardCreds)
57 {
58 InstallHandlers(curl);
59 }

◆ State() [3/3]

TPC::State::State ( off_t start_offset,
Stream & stream,
CURL * curl,
bool push,
bool tpcForwardCreds )
inline

Definition at line 64 of file XrdTpcState.hh.

64 :
65 m_push(push),
66 m_recv_status_line(false),
67 m_recv_all_headers(false),
68 m_offset(0),
69 m_start_offset(start_offset),
70 m_status_code(-1),
71 m_error_code(0),
72 m_content_length(-1),
73 m_stream(&stream),
74 m_curl(curl),
75 m_headers(NULL),
76 m_is_transfer_state(true),
77 tpcForwardCreds(tpcForwardCreds)
78 {
79 InstallHandlers(curl);
80 }

◆ ~State()

State::~State ( )

Definition at line 18 of file XrdTpcState.cc.

18 {
19 if (m_headers) {
20 curl_slist_free_all(m_headers);
21 m_headers = NULL;
22 if (m_curl) {curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, m_headers);}
23 }
24}

Member Function Documentation

◆ AvailableBuffers()

int State::AvailableBuffers ( ) const

Definition at line 274 of file XrdTpcState.cc.

275{
276 return m_stream->AvailableBuffers();
277}

◆ BodyTransferInProgress()

bool TPC::State::BodyTransferInProgress ( ) const
inline

Definition at line 114 of file XrdTpcState.hh.

114{return m_offset && (m_offset != m_content_length);}

◆ BytesTransferred()

off_t TPC::State::BytesTransferred ( ) const
inline

Definition at line 88 of file XrdTpcState.hh.

88{return m_offset;}

◆ CopyHeaders()

void State::CopyHeaders ( XrdHttpExtReq & req)

Handle the 'Copy-Headers' feature

Definition at line 95 of file XrdTpcState.cc.

95 {
96 struct curl_slist *list = NULL;
97 for (std::map<std::string, std::string>::const_iterator hdr_iter = req.headers.begin();
98 hdr_iter != req.headers.end();
99 hdr_iter++) {
100 if (!strcasecmp(hdr_iter->first.c_str(),"copy-header")) {
101 list = curl_slist_append(list, hdr_iter->second.c_str());
102 m_headers_copy.emplace_back(hdr_iter->second);
103 }
104 // Note: len("TransferHeader") == 14
105 if (!strncasecmp(hdr_iter->first.c_str(),"transferheader",14)) {
106 std::stringstream ss;
107 ss << hdr_iter->first.substr(14) << ": " << hdr_iter->second;
108 list = curl_slist_append(list, ss.str().c_str());
109 m_headers_copy.emplace_back(ss.str());
110 }
111 }
112 if (list != NULL) {
113 curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, list);
114 m_headers = list;
115 }
116}
std::map< std::string, std::string > & headers

References XrdHttpExtReq::headers.

◆ DumpBuffers()

void State::DumpBuffers ( ) const

Definition at line 279 of file XrdTpcState.cc.

280{
281 m_stream->DumpBuffers();
282}

◆ Duplicate()

State * State::Duplicate ( )

Definition at line 242 of file XrdTpcState.cc.

242 {
243 CURL *curl = curl_easy_duphandle(m_curl);
244 if (!curl) {
245 throw std::runtime_error("Failed to duplicate existing curl handle.");
246 }
247
248 State *state = new State(0, *m_stream, curl, m_push, tpcForwardCreds);
249
250 if (m_headers) {
251 state->m_headers_copy.reserve(m_headers_copy.size());
252 for (std::vector<std::string>::const_iterator header_iter = m_headers_copy.begin();
253 header_iter != m_headers_copy.end();
254 header_iter++) {
255 state->m_headers = curl_slist_append(state->m_headers, header_iter->c_str());
256 state->m_headers_copy.push_back(*header_iter);
257 }
258 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);
259 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, state->m_headers);
260 }
261
262 return state;
263}
void CURL

References State().

Here is the call graph for this function:

◆ Finalize()

bool State::Finalize ( )

Definition at line 284 of file XrdTpcState.cc.

285{
286 if (!m_stream->Finalize()) {
287 m_error_buf = m_stream->GetErrorMessage();
288 m_error_code = 3;
289 return false;
290 }
291 return true;
292}

◆ Flush()

int State::Flush ( )

Definition at line 210 of file XrdTpcState.cc.

210 {
211 if (m_push) {
212 return 0;
213 }
214
215 ssize_t retval = m_stream->Write(m_start_offset + m_offset, 0, 0, true);
216 if (retval == SFS_ERROR) {
217 m_error_buf = m_stream->GetErrorMessage();
218 m_error_code = 2;
219 return -1;
220 }
221 m_offset += retval;
222 return retval;
223}
#define SFS_ERROR

References SFS_ERROR.

◆ GetConnectionDescription()

std::string State::GetConnectionDescription ( )

Definition at line 294 of file XrdTpcState.cc.

295{
296 // CURLINFO_PRIMARY_PORT is only defined for 7.21.0 or later; on older
297 // library versions, simply omit this information.
298#if LIBCURL_VERSION_NUM >= 0x071500
299 char *curl_ip = NULL;
300 CURLcode rc = curl_easy_getinfo(m_curl, CURLINFO_PRIMARY_IP, &curl_ip);
301 if ((rc != CURLE_OK) || !curl_ip) {
302 return "";
303 }
304 long curl_port = 0;
305 rc = curl_easy_getinfo(m_curl, CURLINFO_PRIMARY_PORT, &curl_port);
306 if ((rc != CURLE_OK) || !curl_port) {
307 return "";
308 }
309 std::stringstream ss;
310 // libcurl returns IPv6 addresses of the form:
311 // 2600:900:6:1301:5054:ff:fe0b:9cba:8000
312 // However the HTTP-TPC spec says to use the form
313 // [2600:900:6:1301:5054:ff:fe0b:9cba]:8000
314 // Hence, we add '[' and ']' whenever a ':' is seen.
315 if (NULL == strchr(curl_ip, ':'))
316 ss << "tcp:" << curl_ip << ":" << curl_port;
317 else
318 ss << "tcp:[" << curl_ip << "]:" << curl_port;
319 return ss.str();
320#else
321 return "";
322#endif
323}

◆ GetContentLength()

off_t TPC::State::GetContentLength ( ) const
inline

Definition at line 92 of file XrdTpcState.hh.

92{return m_content_length;}

◆ GetErrorCode()

int TPC::State::GetErrorCode ( ) const
inline

Definition at line 94 of file XrdTpcState.hh.

94{return m_error_code;}

◆ GetErrorMessage()

std::string TPC::State::GetErrorMessage ( ) const
inline

Definition at line 100 of file XrdTpcState.hh.

100{return m_error_buf;}

◆ GetHandle()

CURL * TPC::State::GetHandle ( ) const
inline

Definition at line 106 of file XrdTpcState.hh.

106{return m_curl;}

◆ GetStatusCode()

int TPC::State::GetStatusCode ( ) const
inline

Definition at line 98 of file XrdTpcState.hh.

98{return m_status_code;}

◆ Move()

void State::Move ( State & other)

Definition at line 27 of file XrdTpcState.cc.

28{
29 m_push = other.m_push;
30 m_recv_status_line = other.m_recv_status_line;
31 m_recv_all_headers = other.m_recv_all_headers;
32 m_offset = other.m_offset;
33 m_start_offset = other.m_start_offset;
34 m_status_code = other.m_status_code;
35 m_content_length = other.m_content_length;
36 m_stream = other.m_stream;
37 m_curl = other.m_curl;
38 m_headers = other.m_headers;
39 m_headers_copy = other.m_headers_copy;
40 m_resp_protocol = other.m_resp_protocol;
41 m_is_transfer_state = other.m_is_transfer_state;
42 curl_easy_setopt(m_curl, CURLOPT_HEADERDATA, this);
43 if (m_is_transfer_state) {
44 if (m_push) {
45 curl_easy_setopt(m_curl, CURLOPT_READDATA, this);
46 } else {
47 curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, this);
48 }
49 }
50 tpcForwardCreds = other.tpcForwardCreds;
51 other.m_headers_copy.clear();
52 other.m_curl = NULL;
53 other.m_headers = NULL;
54 other.m_stream = NULL;
55}

References State().

Here is the call graph for this function:

◆ ResetAfterRequest()

void State::ResetAfterRequest ( )

Definition at line 118 of file XrdTpcState.cc.

118 {
119 m_offset = 0;
120 m_status_code = -1;
121 m_content_length = -1;
122 m_recv_all_headers = false;
123 m_recv_status_line = false;
124}

◆ SetContentLength()

void TPC::State::SetContentLength ( const off_t content_length)
inline

Definition at line 90 of file XrdTpcState.hh.

90{ m_content_length = content_length; }

◆ SetErrorCode()

void TPC::State::SetErrorCode ( int error_code)
inline

Definition at line 96 of file XrdTpcState.hh.

96{m_error_code = error_code;}

◆ SetErrorMessage()

void TPC::State::SetErrorMessage ( const std::string & error_msg)
inline

Definition at line 102 of file XrdTpcState.hh.

102{m_error_buf = error_msg;}

◆ SetTransferParameters()

void State::SetTransferParameters ( off_t offset,
size_t size )

Definition at line 265 of file XrdTpcState.cc.

265 {
266 m_start_offset = offset;
267 m_offset = 0;
268 m_content_length = size;
269 std::stringstream ss;
270 ss << offset << "-" << (offset+size-1);
271 curl_easy_setopt(m_curl, CURLOPT_RANGE, ss.str().c_str());
272}

The documentation for this class was generated from the following files: