Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

CascadeHTTPClient.h

Go to the documentation of this file.
00001 //
00002 // CascadeHTTPClient.h - header file for class CascadeHTTPClient
00003 //
00004 // Copyright (c) 2003, Roku, LLC.  All rights reserved.
00005 //
00008 
00009 #ifndef _ROKU_INCLUDE_CASCADE_NET_CASCADEHTTPCLIENT_H
00010 #define _ROKU_INCLUDE_CASCADE_NET_CASCADEHTTPCLIENT_H
00011 
00012 #include <cascade/CascadeObject.h>
00013 #include <cascade/util/CascadeString.h>
00014 
00015 // ISSUE: Some people like to #define identifiers that are all caps, so
00016 // if you have function calls in a public API that are all caps, they might
00017 // collide with clients' macros / definitions.
00018 
00019 #ifdef GET
00020 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (GET)" )
00021 #undef GET
00022 #endif
00023 
00024 #ifdef HEAD
00025 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (HEAD)" )
00026 #undef HEAD
00027 #endif
00028 
00029 #ifdef POST
00030 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (POST)" )
00031 #undef POST
00032 #endif
00033 
00034 #ifdef PUT
00035 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (PUT)" )
00036 #undef PUT
00037 #endif
00038 
00039 #ifdef DELETE
00040 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (DELETE)" )
00041 #undef DELETE
00042 #endif
00043 
00044 #ifdef TRACE
00045 #pragma message ( "warning: CascadeHTTPClient API masking macro definition (TRACE)" )
00046 #undef TRACE
00047 #endif
00048 
00066 class CascadeHTTPClient : public CascadeObject
00067 {
00068 public:
00069         CascadeHTTPClient(const char * pURL);
00074 
00075         CascadeHTTPClient();
00081 
00082         virtual ~CascadeHTTPClient();
00089 
00090 public:
00091         /* CONFIGURATION METHODS */
00092 
00093         virtual void SetURL(const char * pURL);
00104         virtual bool GetURL(CascadeString &url) const;
00108         
00109         virtual void SetHostname(const char * pHostname);
00115         virtual bool GetHostname(CascadeString &hostname) const;
00121 
00122         virtual void SetPort(u16 nPort);
00128         virtual u16 GetPort() const;
00134 
00135         virtual void SetPath(const char * pPath);
00141         virtual bool GetPath(CascadeString &path) const;
00149 
00150         virtual bool GetPathQuery(CascadeString &pathnquery) const;
00156 
00157         virtual void SetFragment(const char * pFragment);
00163         virtual bool GetFragment(CascadeString &fragment) const;
00170 
00171         virtual void SetQueryValue(const char * pQuery, const char * pQueryValue); 
00173         virtual bool GetQueryValue(const char * pQuery, CascadeString &value) const;
00175 
00176         virtual void SetUsername(const char * pUsername);
00182         virtual bool GetUsername(CascadeString &username) const;
00186 
00187         virtual void SetPassword(const char * pPassword);
00193         virtual bool GetPassword(CascadeString &password) const;
00197 
00198 
00199         virtual void SetKeepAlive(bool bKeepAlive); 
00201         virtual bool GetKeepAlive() const;
00203 
00204         void UserAgent (const char *user_agent); 
00206         const char *UserAgent () const; 
00208 
00209         virtual void SetHTTPVersion(const char * pHTTPVersion); 
00211         virtual bool GetHTTPVersion(CascadeString &version) const;
00213 
00214         virtual void SetPeerHTTPVersion(const char * pPeerHTTPVersion); 
00216         virtual bool GetPeerHTTPVersion(CascadeString &version) const;
00218 
00219         /*HTML doesn't specify a line length limit or a limit to the number of
00220 header lines.  The CascadeHTTPClient class buffers header lines to
00221 give users an easy interface to the header content if they are
00222 interested.  MaxLineLength and MaxHeaderLines puts limits on the size
00223 of header data that the CascadeHTTPClient actually remembers, which
00224 protects a process from unruly servers.  This is in common with
00225 several different HTTP APIs that are out there.
00226 
00227 If a server produces lines that exceed the MaxLineLength or
00228 MaxHeaderLines, the CascadeHTTPClient fills up its storage and drops
00229 the rest on the floor (or overwrites previously stored header lines
00230 --- I haven't decided which behavior is best).  The COMMAND methods
00231 will return an error code to indicate when this happens.  No part of
00232 the HTTP entity body is ever dropped, only parts of header lines.*/
00233         virtual void SetMaxLineLength(u32 nMaxLineLength); 
00235         virtual u32 GetMaxLineLength() const;
00237 
00238         virtual void SetMaxHeaderLines(u32 nMaxHeaderLines); 
00240         virtual u32 GetMaxHeaderLines() const;
00242 
00243         virtual void SetRequestHeader(const char * pHeaderKey, const char * pHeaderValue); 
00245         virtual bool GetRequestHeader(const char * pHeaderKey, CascadeString &header) const;
00247 
00248         virtual void SetByteRange(u64 nRangeStart, u64 nRangeStop);
00249         // convience for setting range header info
00250         // Set nRangeStop to zero to request end of document.
00251         virtual void GetByteRange(u64 & nRangeStartToSet, u64 & nRangeStopToSet) const;
00252         // get the range info
00253         // NOTE: NOT IMPLEMENTED!!!
00254 
00255         /* COMMAND METHODS */
00256         /* in blocking mode, all commands result in at least HTTP header download */
00257 
00258         u32 GET ();     
00260         u32 GET (const char *path); 
00262 
00263         u32 HEAD ();    
00265         u32 HEAD (const char *path); 
00267 
00268         u32 POST (const char *buf, u32 len); 
00270         u32 POST (const char *path, const char *buf, u32 len); 
00272 
00273         u32 PUT (const char *buf, u32 len); 
00275         u32 PUT (const char *path, const char *buf, u32 len); 
00277 
00278         u32 DELETE ();  
00280         u32 DELETE (const char *path); 
00282 
00283         u32 TRACE ();   
00285         u32 TRACE (const char *path); 
00287 
00288         /* RESPONSE METHODS */
00289         /* In blocking mode, the header and response code info will be valid AFTER the COMMAND returns. */
00290 
00291         virtual bool GetResponseCode(CascadeString &code) const;
00293         virtual bool GetResponseText(CascadeString &text) const;
00295         virtual u32 GetResponseCodeInt () const;
00297 
00298         /* trailer key/value pairs only populated and valid after read() returns end-of-file */
00299         virtual bool GetResponseHeader(CascadeString &header) const;
00301         virtual bool GetResponseHeaderAt(u32 nIndex, CascadeString &header) const;
00303         virtual bool GetResponseHeaderKey(u32 nIndex, CascadeString &key) const;
00305         virtual bool GetResponseHeaderValue(const char * pResponseHeaderKey, CascadeString &value) const;
00307 
00308         virtual u32 ReadBytes(char * pBuff, u32 nBytes); 
00310 
00311         /* Note about Blocking and Non-Blocking modes:
00312            There are four places where we can potentially block in this class:
00313            ::GET       calls connect(), send(), and recv()
00314            ::ReadBytes calls recv()
00315            The blocking mode of each of these three different system calls can
00316            be independently controlled by giving them non-zero timeouts.
00317           
00318            The default timeout for connect is zero, which means it will block forever.
00319            if you give it a non-zero timeout using ::SetConnectTimeout(), the call to
00320            connect() will only block for as long (in microseconds) as that timeout.
00321 
00322            The same holds for setting the send and receive timeouts with
00323            ::SetSendTimeout() and ::SetReceiveTimeout() respectively.
00324          */
00325 
00326         virtual bool SetConnectTimeout(u32 nTimeoutMicroseconds);
00328         virtual bool SetSendTimeout(u32 nTimeoutMicroseconds);
00330         virtual bool SetReceiveTimeout(u32 nTimeoutMicroseconds);
00332         virtual u32 GetConnectTimeout() const;
00334         virtual u32 GetSendTimeout() const;
00336         virtual u32 GetReceiveTimeout() const;
00338 
00339         virtual bool SetAutoRedirectLimit(int this_many_times);
00341 
00342         static void URLEncodeString (const CascadeString input, CascadeString &output);
00344 
00345         static bool ErrorString (const u32 get_retval, CascadeString &error_string);
00347 
00348 private:
00349         class PrivateMembers;
00350         PrivateMembers *m_private;
00351 };
00352 
00353 #endif // #ifndef _ROKU_INCLUDE_CASCADE_NET_CASCADEHTTPCLIENT_H
00354 
00356 //  LOG
00358 //  12-Feb-04   dwuertele   this is how we shall support HTTP
00359 //  01-Jun-05   dsletten    unify line endings (VDSP confused by mixed-type)
00360 //                          changed Get / SetByteRange params to u64s
00361 

Generated on Sun Jul 24 14:27:17 2005 for Cascade Library by  doxygen 1.4.1