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 std::string GetErrorMessage() const {return m_error_buf;}
00066
00067 void ResetAfterRequest();
00068
00069 CURL *GetHandle() const {return m_curl;}
00070
00071 int AvailableBuffers() const;
00072
00073 void DumpBuffers() const;
00074
00075
00076
00077 bool BodyTransferInProgress() const {return m_offset && (m_offset != m_content_length);}
00078
00079
00080
00081 State *Duplicate();
00082
00083
00084
00085 void Move (State &other);
00086
00087
00088
00089
00090
00091
00092
00093
00094 bool Finalize();
00095
00096
00097
00098
00099
00100 std::string GetConnectionDescription();
00101
00102 private:
00103 bool InstallHandlers(CURL *curl);
00104
00105 State(const State&);
00106
00107
00108
00109
00110 static size_t HeaderCB(char *buffer, size_t size, size_t nitems,
00111 void *userdata);
00112 int Header(const std::string &header);
00113 static size_t WriteCB(void *buffer, size_t size, size_t nitems, void *userdata);
00114 int Write(char *buffer, size_t size);
00115 static size_t ReadCB(void *buffer, size_t size, size_t nitems, void *userdata);
00116 int Read(char *buffer, size_t size);
00117
00118 bool m_push;
00119 bool m_recv_status_line;
00120 bool m_recv_all_headers;
00121 off_t m_offset;
00122 off_t m_start_offset;
00123 int m_status_code;
00124 off_t m_content_length;
00125 Stream *m_stream;
00126 CURL *m_curl;
00127 struct curl_slist *m_headers;
00128 std::vector<std::string> m_headers_copy;
00129 std::string m_resp_protocol;
00130 std::string m_error_buf;
00131 };
00132
00133 };