00001
00007 #include <memory>
00008 #include <vector>
00009
00010
00011 class XrdSfsFile;
00012 class XrdHttpExtReq;
00013 typedef void CURL;
00014
00015 namespace TPC {
00016 class Stream;
00017
00018 class State {
00019 public:
00020
00021 State() :
00022 m_push(true),
00023 m_recv_status_line(false),
00024 m_recv_all_headers(false),
00025 m_offset(0),
00026 m_start_offset(0),
00027 m_status_code(-1),
00028 m_content_length(-1),
00029 m_stream(NULL),
00030 m_curl(NULL),
00031 m_headers(NULL)
00032 {}
00033
00034
00035
00036
00037 State (off_t start_offset, Stream &stream, CURL *curl, bool push) :
00038 m_push(push),
00039 m_recv_status_line(false),
00040 m_recv_all_headers(false),
00041 m_offset(0),
00042 m_start_offset(start_offset),
00043 m_status_code(-1),
00044 m_content_length(-1),
00045 m_stream(&stream),
00046 m_curl(curl),
00047 m_headers(NULL)
00048 {
00049 InstallHandlers(curl);
00050 }
00051
00052 ~State();
00053
00054 void SetTransferParameters(off_t offset, size_t size);
00055
00056 void CopyHeaders(XrdHttpExtReq &req);
00057
00058 off_t BytesTransferred() const {return m_offset;}
00059
00060 off_t GetContentLength() const {return m_content_length;}
00061
00062 int GetStatusCode() const {return m_status_code;}
00063
00064 std::string GetErrorMessage() const {return m_error_buf;}
00065
00066 void ResetAfterRequest();
00067
00068 CURL *GetHandle() const {return m_curl;}
00069
00070 int AvailableBuffers() const;
00071
00072 void DumpBuffers() const;
00073
00074
00075
00076 bool BodyTransferInProgress() const {return m_offset && (m_offset != m_content_length);}
00077
00078
00079
00080 State *Duplicate();
00081
00082
00083
00084 void Move (State &other);
00085
00086
00087
00088
00089
00090
00091
00092
00093 bool Finalize();
00094
00095
00096
00097
00098
00099 std::string GetConnectionDescription();
00100
00101 private:
00102 bool InstallHandlers(CURL *curl);
00103
00104 State(const State&);
00105
00106
00107
00108
00109 static size_t HeaderCB(char *buffer, size_t size, size_t nitems,
00110 void *userdata);
00111 int Header(const std::string &header);
00112 static size_t WriteCB(void *buffer, size_t size, size_t nitems, void *userdata);
00113 int Write(char *buffer, size_t size);
00114 static size_t ReadCB(void *buffer, size_t size, size_t nitems, void *userdata);
00115 int Read(char *buffer, size_t size);
00116
00117 bool m_push;
00118 bool m_recv_status_line;
00119 bool m_recv_all_headers;
00120 off_t m_offset;
00121 off_t m_start_offset;
00122 int m_status_code;
00123 off_t m_content_length;
00124 Stream *m_stream;
00125 CURL *m_curl;
00126 struct curl_slist *m_headers;
00127 std::vector<std::string> m_headers_copy;
00128 std::string m_resp_protocol;
00129 std::string m_error_buf;
00130 };
00131
00132 };