Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   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_CONFIG_H__
00045 #include <cc++/config.h>
00046 #endif
00047 
00048 #ifndef __CCXX_SOCKET_H__
00049 #include <cc++/socket.h>
00050 #endif
00051 
00052 #ifdef  __NAMESPACES__
00053 namespace ost {
00054 #endif
00055 
00056 typedef enum
00057 {
00058         URL_SUCCESS = 0,
00059         URL_UNREACHABLE,
00060         URL_MISSING,
00061         URL_DENIED,
00062         URL_INVALID,
00063         URL_FORBIDDEN,
00064         URL_UNAUTHORIZED,
00065         URL_RELOCATED,
00066         URL_FAILURE,
00067         URL_TIMEOUT
00068 } urlerror_t;
00069 
00070 typedef enum
00071 {
00072         URL_ANONYMOUS_AUTH = 0,
00073         URL_BASIC_AUTH
00074 } urlauth_t;
00075 
00076 typedef enum
00077 {
00078         URL_BINARY_ENCODING = 0,
00079         URL_CHUNKED_ENCODING
00080 } urlencoding_t;
00081 
00082 typedef enum
00083 {
00084         HTTP_GET_METHOD,
00085         HTTP_PUT_METHOD,
00086         HTTP_POST_METHOD,
00087         FTP_GET_METHOD,
00088         FTP_PUT_METHOD,
00089         FILE_GET_METHOD,
00090         FILE_PUT_METHOD
00091 } urlmethod_t;
00092 
00093 typedef enum
00094 {
00095         HTTP_PROTOCOL_1_0,
00096         HTTP_PROTOCOL_1_1
00097 } urlprotocol_t;
00098 
00099 class CCXX_CLASS_EXPORT URLStream;
00100 
00107 class CCXX_CLASS_EXPORT URLStream : public TCPStream
00108 {
00109 private:
00110         const char *agent, *referer, *cookie, *pragma, *user, *password;
00111         InetHostAddress proxyHost, prevHost;
00112         tpport_t proxyPort, prevPort;
00113         InetHostAddress refhost;
00114         urlmethod_t urlmethod;
00115         urlencoding_t encoding;
00116         urlprotocol_t protocol;
00117         urlauth_t auth;
00118         timeout_t timeout;
00119         bool persistent;
00120         bool follow;
00121         unsigned chunk;
00122         char authbuf[128];
00123 
00124         urlerror_t getHTTPHeaders(char *buffer, unsigned bufsize);
00125 
00126 protected:
00127         urlerror_t sendHTTPHeader(const char *path, const char **vars, int bufsize);
00128         int underflow(void);
00129 
00136         virtual void httpHeader(const char *header, const char *value)
00137                 {return;};
00138 
00139 public:
00143         URLStream();
00144 
00152         URLStream &getline(char *buffer, size_t len);
00153 
00161         urlerror_t Get(const char *path, int buffer = 512);
00162 
00172         urlerror_t Submit(const char *path, const char **vars, int buffer = 512);
00173 
00182         urlerror_t Post(const char *path, const char **vars, int buffer = 512);
00183 
00191         urlerror_t Head(const char *path, int buffer = 512);
00192 
00196         void Close();
00197 
00203         void setReferer(const char *str);
00204 
00210         inline void setCookie(const char *str)
00211                 {cookie = str;};
00212 
00218         inline void setUser(const char *str)
00219                 {user = str;};
00220 
00226         inline void setPassword(const char *str)
00227                 {password = str;};
00228 
00234         void setAuthentication(urlauth_t a, const char *str = NULL);
00235 
00241         inline void setPragma(const char *str)
00242                 {pragma = str;};
00243 
00250         void setProxy(const char *host, tpport_t port);
00251 
00257         inline void setAgent(const char *str)
00258                 {agent = str;};
00259 
00265         inline urlmethod_t getMethod(void)
00266                 {return urlmethod;};
00267 
00274         inline void setTimeout(timeout_t to)
00275                 {timeout = to;};
00276 
00283         inline void setFollow(bool enable)
00284                 {follow = enable;};
00285 
00291         inline void setProtocol(urlprotocol_t pro)
00292                 {protocol = pro;};
00293 };
00294 
00295 extern CCXX_EXPORT(char*) urldecode(char *source, char *dest = NULL);
00296 extern CCXX_EXPORT(char*) urlencode(const char *source, char *dest, unsigned size);
00297 
00298 #ifdef  __NAMESPACES__
00299 };
00300 #endif
00301 
00302 #endif
00303 

Generated at Tue Nov 20 12:34:33 2001 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001