Back to index

nordugrid-arc-nox  1.1.0~rc6
PayloadHTTP.h
Go to the documentation of this file.
00001 #ifndef __ARC_PAYLOADHTTP_H__
00002 #define __ARC_PAYLOADHTTP_H__
00003 
00004 #include <string>
00005 #include <map>
00006 
00007 #ifdef HAVE_STDINT_H
00008 #include <stdint.h>
00009 #endif
00010 
00011 #include <arc/message/PayloadRaw.h>
00012 #include <arc/message/PayloadStream.h>
00013 
00014 #define HTTP_OK           (200)
00015 #define HTTP_BAD_REQUEST  (400)
00016 #define HTTP_NOT_FOUND    (404)
00017 #define HTTP_PARTIAL      (206)
00018 #define HTTP_RANGE_NOT_SATISFIABLE (416)
00019 #define HTTP_INTERNAL_ERR (500)
00020 
00021 namespace Arc {
00022 
00026 class PayloadHTTP: virtual public PayloadRaw, virtual public PayloadStreamInterface {
00027  protected:
00028   bool valid_;
00029   bool fetched_;                   
00034   PayloadStreamInterface* stream_; 
00035   bool stream_own_;                
00036   PayloadRawInterface* rbody_;     
00037   PayloadStreamInterface* sbody_;  
00038   bool body_own_;                  
00039   std::string uri_;                
00040   int version_major_;              
00041   int version_minor_;              
00042   std::string method_;             
00043   int code_;                       
00044   std::string reason_;             
00045   int64_t length_;                 
00046   //int offset_;                   /** Logical beginning of content computed from Content-Range */
00047   //int size_;                     /** Logical size of content obtained from Content-Range */
00048   bool chunked_;                   
00049   bool keep_alive_;                
00050   std::multimap<std::string,std::string> attributes_; /* All HTTP attributes */
00051   char tbuf_[1024];
00052   int tbuflen_;
00053   uint64_t stream_offset_;
00054   int64_t chunked_size_;
00055   uint64_t chunked_offset_;
00057   bool readline(std::string& line);
00059   bool read(char* buf,int64_t& size);
00061   bool parse_header(void);
00063   bool get_body(void);
00064  public:
00070   PayloadHTTP(PayloadStreamInterface& stream,bool own = false);
00071 
00074   PayloadHTTP(const std::string& method,const std::string& url,PayloadStreamInterface& stream);
00076   PayloadHTTP(const std::string& method,const std::string& url);
00077 
00080   PayloadHTTP(int code,const std::string& reason,PayloadStreamInterface& stream);
00082   PayloadHTTP(int code,const std::string& reason);
00083 
00084   virtual ~PayloadHTTP(void);
00085 
00086   virtual operator bool(void) { return valid_; };
00087   virtual bool operator!(void) { return !valid_; };
00088 
00091   virtual const std::string& Attribute(const std::string& name);
00093   virtual const std::multimap<std::string,std::string>& Attributes(void);
00095   virtual void Attribute(const std::string& name,const std::string& value);
00101   virtual bool Flush(void);
00102   virtual std::string Method() { return method_; };
00103   virtual std::string Endpoint() { return uri_; };
00104   virtual std::string Reason() { return reason_; };
00105   virtual int Code() { return code_; };
00106   virtual bool KeepAlive(void) { return keep_alive_; };
00107   virtual void KeepAlive(bool keep_alive) { keep_alive_=keep_alive; };
00112   virtual void Body(PayloadRawInterface& body,bool ownership = true);
00113   virtual void Body(PayloadStreamInterface& body,bool ownership = true);
00114 
00115   // PayloadRawInterface reimplemented methods
00116   virtual char operator[](PayloadRawInterface::Size_t pos) const;
00117   virtual char* Content(PayloadRawInterface::Size_t pos = -1);
00118   virtual PayloadRawInterface::Size_t Size(void) const;
00119   virtual char* Insert(PayloadRawInterface::Size_t pos = 0,PayloadRawInterface::Size_t size = 0);
00120   virtual char* Insert(const char* s,PayloadRawInterface::Size_t pos = 0,PayloadRawInterface::Size_t size = -1);
00121   virtual char* Buffer(unsigned int num = 0);
00122   virtual PayloadRawInterface::Size_t BufferSize(unsigned int num = 0) const;
00123   virtual PayloadRawInterface::Size_t BufferPos(unsigned int num = 0) const;
00124   virtual bool Truncate(PayloadRawInterface::Size_t size);
00125 
00126   // PayloadStreamInterface implemented methods
00127   virtual bool Get(char* buf,int& size);
00128   virtual bool Get(std::string& buf);
00129   virtual std::string Get(void);
00130   virtual bool Put(const char* buf,PayloadStreamInterface::Size_t size);
00131   virtual bool Put(const std::string& buf);
00132   virtual bool Put(const char* buf);
00133   virtual int Timeout(void) const;
00134   virtual void Timeout(int to);
00135   virtual PayloadStreamInterface::Size_t Pos(void) const;
00136   virtual PayloadStreamInterface::Size_t Limit(void) const;
00137 
00138 };
00139 
00140 } // namespace Arc
00141 
00142 #endif /* __ARC_PAYLOADHTTP_H__ */