Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

url.h

Go to the documentation of this file.
00001 // Copyright (C) 2001 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 
00041 #ifndef __CCXX_URL_H__
00042 #define __CCXX_URL_H__
00043 
00044 #ifndef __CCXX_SOCKET_H__
00045 #include <cc++/socket.h>
00046 #endif
00047 
00048 typedef enum
00049 {
00050         URL_SUCCESS = 0,
00051         URL_UNREACHABLE,
00052         URL_MISSING,
00053         URL_DENIED,
00054         URL_INVALID,
00055         URL_FORBIDDEN,
00056         URL_UNAUTHORIZED,
00057         URL_RELOCATED,
00058         URL_FAILURE,
00059         URL_TIMEOUT
00060 } urlerror_t;
00061 
00062 typedef enum
00063 {
00064         URL_ANONYMOUS_AUTH = 0,
00065         URL_BASIC_AUTH
00066 } urlauth_t;
00067 
00068 typedef enum
00069 {
00070         URL_BINARY_ENCODING = 0,
00071         URL_CHUNKED_ENCODING
00072 } urlencoding_t;
00073 
00074 typedef enum
00075 {
00076         HTTP_GET_METHOD,
00077         HTTP_PUT_METHOD,
00078         HTTP_POST_METHOD,
00079         FTP_GET_METHOD,
00080         FTP_PUT_METHOD,
00081         FILE_GET_METHOD,
00082         FILE_PUT_METHOD
00083 } urlmethod_t;
00084 
00085 typedef enum
00086 {
00087         HTTP_PROTOCOL_1_0,
00088         HTTP_PROTOCOL_1_1
00089 } urlprotocol_t;
00090 
00091 class __EXPORT URLStream;
00092 
00099 class URLStream : public TCPStream
00100 {
00101 private:
00102         const char *agent, *referer, *cookie, *pragma, *user, *password;
00103         InetHostAddress proxyHost, prevHost;
00104         tpport_t proxyPort, prevPort;
00105         InetHostAddress refhost;
00106         urlmethod_t urlmethod;
00107         urlencoding_t encoding;
00108         urlprotocol_t protocol;
00109         urlauth_t auth;
00110         timeout_t timeout;
00111         bool persistent;
00112         bool follow;
00113         unsigned chunk;
00114         char authbuf[128];
00115 
00116         urlerror_t getHTTPHeaders(char *buffer, unsigned bufsize);
00117 
00118 protected:
00119         urlerror_t sendHTTPHeader(const char *path, const char **vars, int bufsize);
00120         int underflow(void);
00121 
00128         virtual void httpHeader(const char *header, const char *value)
00129                 {return;};
00130 
00131 public:
00135         URLStream();
00136 
00144         URLStream &getline(char *buffer, size_t len);
00145 
00153         urlerror_t Get(const char *path, int buffer = 512);
00154 
00164         urlerror_t Submit(const char *path, const char **vars, int buffer = 512);
00165 
00174         urlerror_t Post(const char *path, const char **vars, int buffer = 512);
00175 
00183         urlerror_t Head(const char *path, int buffer = 512);
00184 
00188         void Close();
00189 
00195         void setReferer(const char *str);
00196 
00202         inline void setCookie(const char *str)
00203                 {cookie = str;};
00204 
00210         inline void setUser(const char *str)
00211                 {user = str;};
00212 
00218         inline void setPassword(const char *str)
00219                 {password = str;};
00220 
00226         void setAuthentication(urlauth_t a, const char *str = NULL);
00227 
00233         inline void setPragma(const char *str)
00234                 {pragma = str;};
00235 
00242         void setProxy(const char *host, tpport_t port);
00243 
00249         inline void setAgent(const char *str)
00250                 {agent = str;};
00251 
00257         inline urlmethod_t getMethod(void)
00258                 {return urlmethod;};
00259 
00266         inline void setTimeout(timeout_t to)
00267                 {timeout = to;};
00268 
00275         inline void setFollow(bool enable)
00276                 {follow = enable;};
00277 
00283         inline void setProtocol(urlprotocol_t pro)
00284                 {protocol = pro;};
00285 };
00286 
00287 extern __EXPORT char *urldecode(char *source, char *dest = NULL);
00288 extern __EXPORT char *urlencode(const char *source, char *dest, unsigned size);
00289 
00290 #ifdef  __CCXX_NAMESPACE_H__
00291 #undef  __CCXX_NAMESPACE_H__
00292 #include <cc++/namespace.h>
00293 #endif
00294 
00295 #endif
00296 

Generated at Wed Sep 5 11:25:19 2001 for CommonC++ by doxygen1.2.5 written by Dimitri van Heesch, © 1997-2001