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