http.hpp



The class "Http" public interface is:
  • Http(char* mhostname, char* mulr, int mport=80, char* mout_file=NULL, int mtimeout=-1) throw (Http_memory_error): build an object Http with all the connection's parameters.
  • get(): get the web document.
  • set_port(): set the server's port (80 by default).
  • set_hostname(): set the server's hostname.
  • set_url(): set the URL.
  • set_out_file(): set the output file.
  • set_timeout(): set the timeout (in seconds).
  • get_data(): returns a pointer to the web document.
  • get_data_size(): return the size (in bytes) of the web document.
  • get_header(): returns only the seb document's header.
  • get_status(): returns only the status line of the web document.

#ifndef HTTP_CPP_HD

#include "sockets.h"

#define BUFFER_INIT_SIZE 1000 // 10 ko

class Http_memory_error{};
class Http_invalid_args{};
class Http_write_failed{};
class Http_read_failed{};
class Http_timer_error{};
class Http_timeout_connect{};
class Http_timeout_read{};
class Http_connect_failed
{
        private: int error;

        public: Http_connect_failed(int err) { error = err; }
                        int get_error() { return error; }
};

class Http
{
        private:SOCK_IN server_address;
                        SOCK sock;
                        int port;
                        int timeout;
                        char* hostname;
                        char* url;
                        char* out_file;
                        char* buffer;
                        int buffer_size;
                        void re_alloc_buffer() throw (Http_memory_error);
                        void set_timer() throw (Http_timer_error);
                        void set_alarm();
                        void reset_alarm();

        public: Http();
                        Http(char* mhostname, char* mulr, int mport=80, char* mout_file=NULL, int mtimeout=-1) throw (Http_memory_error);
                        ~Http();
                        void get() throw (Http_memory_error, Http_invalid_args, Http_connect_failed, Http_write_failed, Http_read_failed, Http_timer_error, Http_timeout_connect, Http_timeout_read);
                        void set_port(int mport);
                        void set_hostname(const char *mhostname) throw (Http_memory_error);
                        void set_url (const char *mulr) throw (Http_memory_error);
                        void set_out_file (const char *mout_file) throw (Http_memory_error);
                        void set_timeout (const int);
                        inline char *get_data() { return buffer; }
                        inline int get_data_size() { return buffer_size; }
                        int get_header (char**);
                        int get_status (char**);
};

#define HTTP_CPP_HD
#endif