Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

url.h

Go to the documentation of this file.
00001 // Copyright (C) 2001-2002 Open Source Telecom Corporation.
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 // 
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 // 
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 // 
00017 // As a special exception to the GNU General Public License, permission is 
00018 // granted for additional uses of the text contained in its release 
00019 // of Common C++.
00020 // 
00021 // The exception is that, if you link the Common C++ library with other files
00022 // to produce an executable, this does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public License.
00024 // Your use of that executable is in no way restricted on account of
00025 // linking the Common C++ library code into it.
00026 //
00027 // This exception does not however invalidate any other reasons why
00028 // the executable file might be covered by the GNU General Public License.
00029 //
00030 // This exception applies only to the code released under the 
00031 // name Common C++.  If you copy code from other releases into a copy of
00032 // Common C++, as the General Public License permits, the exception does
00033 // not apply to the code that you add in this way.  To avoid misleading
00034 // anyone as to the status of such modified files, you must delete
00035 // this exception notice from them.
00036 // 
00037 // If you write modifications of your own for Common C++, it is your choice
00038 // whether to permit this exception to apply to your modifications.
00039 // If you do not wish that, delete this exception notice.
00040 
00046 #ifndef CCXX_URL_H_
00047 #define CCXX_URL_H_
00048 
00049 #ifndef CCXX_CONFIG_H_
00050 #include <cc++/config.h>
00051 #endif
00052 
00053 #ifndef CCXX_SOCKET_H_
00054 #include <cc++/socket.h>
00055 #endif
00056 
00057 #ifndef CCXX_URLSTRING_H_
00058 #include <cc++/urlstring.h>
00059 #endif
00060 
00061 #ifdef  CCXX_NAMESPACES
00062 namespace ost {
00063 #endif
00064 
00065 class CCXX_CLASS_EXPORT URLStream;
00066 
00073 class CCXX_CLASS_EXPORT URLStream : public TCPStream
00074 {
00075 public:
00079         typedef enum
00080         {
00081                 errSuccess = 0,
00082                 errUnreachable,
00083                 errMissing,
00084                 errDenied,
00085                 errInvalid,
00086                 errForbidden,
00087                 errUnauthorized,
00088                 errRelocated,
00089                 errFailure,
00090                 errTimeout
00091         } Error;
00092 
00096         typedef enum
00097         {
00098                 authAnonymous = 0,
00099                 authBasic
00100         } Authentication;
00101 
00105         typedef enum
00106         {
00107                 encodingBinary = 0,
00108                 encodingChunked
00109         } Encoding;
00110 
00114         typedef enum
00115         {
00116                 methodHttpGet,
00117                 methodHttpPut,
00118                 methodHttpPost,
00119                 methodFtpGet,
00120                 methodFtpPut,
00121                 methodFileGet,
00122                 methodFilePut
00123         } Method;
00124 
00128         typedef enum
00129         {
00130                 protocolHttp1_0,
00131                 protocolHttp1_1
00132         } Protocol;
00133 
00134 private:
00135         const char *agent, *referer, *cookie, *pragma, *user, *password;
00136         const char *localif;
00137         InetHostAddress proxyHost;
00138         tpport_t proxyPort;
00139         Method urlmethod;
00140         Encoding encoding;
00141         Protocol protocol;
00142         Authentication auth;
00143         timeout_t timeout;
00144         bool persistent;
00145         bool follow;
00146         unsigned chunk;
00147 
00148         Error getHTTPHeaders();
00149         URLStream(const URLStream& rhs);
00150 
00151 protected:
00152         Error sendHTTPHeader(const char *url, const char **vars, int bufsize);
00153         int underflow(void);
00154 
00155         virtual int aRead(char *buffer, size_t len, timeout_t timeout)
00156 #ifndef __MINGW32__
00157                 {return ::read(so, buffer, len);};
00158 #else
00159                 {return ::recv(so, buffer, len, 0); };
00160 #endif
00161 
00162         virtual int aWrite(char *buffer, size_t len, timeout_t timeout)
00163 #ifndef __MINGW32__
00164                 {return ::write(so, buffer, len);};
00165 #else
00166                 {return ::send(so, buffer, len, 0); };
00167 #endif
00168 
00175         virtual void httpHeader(const char *header, const char *value)
00176                 {return;};
00177 
00183         virtual char **extraHeader(void)
00184                 {return NULL;};
00185 
00186 public:
00192         URLStream(timeout_t to = 0);
00193 
00201         URLStream &getline(char *buffer, size_t len);
00202 
00210         Error get(const char *url, int buffer = 512);
00211 
00221         Error submit(const char *url, const char **vars, int buffer = 512);
00222 
00231         Error post(const char *url, const char **vars, int buffer = 512);
00232 
00240         Error head(const char *url, int buffer = 512);
00241 
00245         void close();
00246 
00252         void setReferer(const char *str);
00253 
00259         inline void setCookie(const char *str)
00260                 {cookie = str;};
00261 
00267         inline void setUser(const char *str)
00268                 {user = str;};
00269 
00275         inline void setPassword(const char *str)
00276                 {password = str;};
00277 
00284         void setAuthentication(Authentication a, const char *str = NULL);
00285 
00291         inline void setPragma(const char *str)
00292                 {pragma = str;};
00293 
00300         void setProxy(const char *host, tpport_t port);
00301 
00307         inline void setAgent(const char *str)
00308                 {agent = str;};
00309 
00315         inline Method getMethod(void)
00316                 {return urlmethod;};
00317 
00324         inline void setTimeout(timeout_t to)
00325                 {timeout = to;};
00326 
00333         inline void setFollow(bool enable)
00334                 {follow = enable;};
00335 
00341         inline void setProtocol(Protocol pro)
00342                 {protocol = pro;};
00348         inline void setLocalInterface(const char *intf) 
00349         {localif=intf;} 
00350 };
00351 
00352 #ifdef  CCXX_NAMESPACES
00353 };
00354 #endif
00355 
00356 #endif
00357 

Generated on Thu Sep 25 13:14:31 2003 for GNU CommonC++ by doxygen 1.3.3