Google

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) 1999-2000 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 <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_FAILURE
00058 } urlerror_t;
00059 
00060 typedef enum
00061 {
00062         URL_ANONYMOUS_AUTH = 0,
00063         URL_BASIC_AUTH
00064 } urlauth_t;
00065 
00066 typedef enum
00067 {
00068         URL_BINARY_ENCODING = 0,
00069         URL_CHUNKED_ENCODING
00070 } urlencoding_t;
00071 
00072 typedef enum
00073 {
00074         HTTP_GET_METHOD,
00075         HTTP_PUT_METHOD,
00076         HTTP_POST_METHOD,
00077         FTP_GET_METHOD,
00078         FTP_PUT_METHOD,
00079         FILE_GET_METHOD,
00080         FILE_PUT_METHOD
00081 } urlmethod_t;
00082 
00083 class __EXPORT URLStream;
00084 
00091 class URLStream : public TCPStream
00092 {
00093 private:
00094         const char *agent, *referer, *cookie, *pragma, *user, *password;
00095         InetHostAddress proxyHost, prevHost;
00096         tpport_t proxyPort, prevPort;
00097         InetHostAddress refhost;
00098         urlmethod_t urlmethod;
00099         urlencoding_t encoding;
00100         urlauth_t auth;
00101         timeout_t timeout;
00102         bool persistent;
00103         unsigned chunk;
00104         char authbuf[128];
00105 
00106         urlerror_t getHTTPHeaders(char *buffer, unsigned bufsize);
00107 
00108 protected:
00109         urlerror_t sendHTTPHeader(const char *path, const char **vars, int bufsize);
00110         int underflow(void);
00111 
00118         virtual void httpHeader(const char *header, const char *value)
00119                 {return;};
00120 
00121 public:
00125         URLStream();
00126 
00134         URLStream &getline(char *buffer, size_t len);
00135 
00143         urlerror_t Get(const char *path, int buffer = 512);
00144 
00154         urlerror_t Submit(const char *path, const char **vars, int buffer = 512);
00155 
00164         urlerror_t Post(const char *path, const char **vars, int buffer = 512);
00165 
00173         urlerror_t Head(const char *path, int buffer = 512);
00174 
00178         void Close();
00179 
00185         void setReferer(const char *str);
00186 
00192         inline void setCookie(const char *str)
00193                 {cookie = str;};
00194 
00200         inline void setUser(const char *str)
00201                 {user = str;};
00202 
00208         inline void setPassword(const char *str)
00209                 {password = str;};
00210 
00216         void setAuthentication(urlauth_t a, const char *str = NULL);
00217 
00223         inline void setPragma(const char *str)
00224                 {pragma = str;};
00225 
00232         void setProxy(const char *host, tpport_t port);
00233 
00239         inline void setAgent(const char *str)
00240                 {agent = str;};
00241 
00247         inline urlmethod_t getMethod(void)
00248                 {return urlmethod;};
00249 
00256         inline void setTimeout(timeout_t to)
00257                 {timeout = to;};
00258 };
00259 
00260 extern __EXPORT char *urldecode(char *source, char *dest = NULL);
00261 extern __EXPORT char *urlencode(const char *source, char *dest, unsigned size);
00262 
00263 #ifdef  __CCXX_NAMESPACE_H__
00264 #undef  __CCXX_NAMESPACE_H__
00265 #include <cc++/namespace.h>
00266 #endif
00267 
00268 #endif
00269 

Generated at Fri Mar 23 10:47:54 2001 for CommonC++ by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000