include/GUI/HTTPClient.hpp

Go to the documentation of this file.
00001 #ifndef hpp_CPP_HTTPClient_CPP_hpp
00002 #define hpp_CPP_HTTPClient_CPP_hpp
00003 
00004 // We need the base GUI stuff
00005 #include "../../include/GUI/UZIBase.hpp"
00006 // We need the network stuff
00007 #include "../../include/Network/URLHandler.hpp"
00008 
00009 namespace UZI
00010 {
00015     class HTTPClient
00016     {
00017         // Type and enumerations
00018     public:
00020         enum State
00021         {
00022             Constructed     = 0,    
00023             Connected       = 1,    
00024             Prepared        = 2,    
00025             RequestEmitted  = 3,    
00026             FetchingResult  = 4,    
00027             HeaderReceived  = 5,    
00028             ResultFetched   = 6,    
00029             ResultParsed    = 7,    
00030             ErrorDetected   = 8,    
00031         };
00032 
00034         enum DocumentType
00035         {
00036             Unknown     =   0x00000000,     
00037             XML         =   0x00000001,     
00038             HTML        =   0x00000002,     
00039             JPEGImage   =   0x00000003,     
00040             PNGImage    =   0x00000004,     
00041             GIFImage    =   0x00000005,     
00042             Stylesheet  =   0x00000006,     
00043             ScriptFile  =   0x00000007,     
00044         };
00045 
00046         // We are currently using Juce as framework
00047         typedef juce::String        String;
00048         typedef juce::Socket        Socket;
00049         typedef juce::MemoryBlock   MemoryBlock;
00050 
00051         // Members
00052     private:
00054         Socket          clientSocket;
00056         Network::URL    url;
00058         int             portNumber;
00060         String          postData;
00061 
00063         State           state;
00064 
00066         String          communication;
00068         MemoryBlock     answer;
00069 
00070 
00071         // Interface
00072     public:    
00075         bool connectToServer();
00077         bool prepareHTTPHeaders();
00079         bool emitRequest();
00082         bool fetchResults(const int timeoutMs);
00085         bool parseResults();
00086         
00088         const unsigned int getDataSize() const;
00090         const void *  getDataPtr() const;
00092         const DocumentType getMimeType() const;
00093 
00095         inline const State getState() const { return state; }
00097         inline String      getHeaders() const { return communication; }
00099         void Mutate(const Network::URL & _URL, const int portNumber, const String & postData = String::empty);
00100 
00101         // Helpers
00102     private:
00104         void addHeader(const String & headerName, const String & headerValue);
00106         const String findHeaderValue(const String & headerName) const;
00107 
00108         // Construction / Destruction
00109     public:
00111         HTTPClient(const Network::URL & _URL = Network::URL(), const int _portNumber = 80, const String & _postData = String::empty) 
00112             : url(_URL), portNumber(_portNumber), postData(_postData), state(Constructed)
00113         {
00114         }
00115         ~HTTPClient() {}
00116 
00117     };
00118 
00119 
00120 }
00121 
00122 #endif

(C) An X-Ryl669 project 2007

This document describes Unlimited Zooming Interface source code. UZI stands for Unlimited Zooming Interface, and source code license is