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