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

url.h

Go to the documentation of this file.
00001 // Copyright (C) 2001-2005 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, you may use this file as part of a free software
00018 // library without restriction.  Specifically, if other files instantiate
00019 // templates or use macros or inline functions from this file, or you compile
00020 // this file and link it with other files to produce an executable, this
00021 // file does not by itself cause the resulting executable to be covered by
00022 // the GNU General Public License.  This exception does not however    
00023 // invalidate any other reasons why the executable file might be covered by
00024 // the GNU General Public License.    
00025 //
00026 // This exception applies only to the code released under the name GNU
00027 // Common C++.  If you copy code from other releases into a copy of GNU
00028 // Common C++, as the General Public License permits, the exception does
00029 // not apply to the code that you add in this way.  To avoid misleading
00030 // anyone as to the status of such modified files, you must delete
00031 // this exception notice from them.
00032 //
00033 // If you write modifications of your own for GNU Common C++, it is your choice
00034 // whether to permit this exception to apply to your modifications.
00035 // If you do not wish that, delete this exception notice.
00036 //
00037 
00043 #ifndef CCXX_URL_H_
00044 #define CCXX_URL_H_
00045 
00046 #ifndef CCXX_CONFIG_H_
00047 #include <cc++/config.h>
00048 #endif
00049 
00050 #ifndef CCXX_SOCKET_H_
00051 #include <cc++/socket.h>
00052 #endif
00053 
00054 #ifdef  CCXX_NAMESPACES
00055 namespace ost {
00056 #endif
00057 
00064 class __EXPORT URLStream : public TCPStream
00065 {
00066 public:
00070         typedef enum
00071         {
00072                 errSuccess = 0,
00073                 errUnreachable,
00074                 errMissing,
00075                 errDenied,
00076                 errInvalid,
00077                 errForbidden,
00078                 errUnauthorized,
00079                 errRelocated,
00080                 errFailure,
00081                 errTimeout,
00082                 errInterface
00083         } Error;
00084 
00088         typedef enum
00089         {
00090                 authAnonymous = 0,
00091                 authBasic
00092         } Authentication;
00093 
00097         typedef enum
00098         {
00099                 encodingBinary = 0,
00100                 encodingChunked
00101         } Encoding;
00102 
00106         typedef enum
00107         {
00108                 methodHttpGet,
00109                 methodHttpPut,
00110                 methodHttpPost,
00111                 methodFtpGet,
00112                 methodFtpPut,
00113                 methodFileGet,
00114                 methodFilePut
00115         } Method;
00116 
00120         typedef enum
00121         {
00122                 protocolHttp1_0,
00123                 protocolHttp1_1
00124         } Protocol;
00125 
00126 private:
00127         const char *agent, *referer, *cookie, *pragma, *user, *password;
00128         const char *proxyUser, *proxyPasswd;
00129         const char *localif;
00130         IPV4Host proxyHost;
00131 #ifdef  CCXX_IPV6
00132         IPV6Host v6proxyHost;
00133 #endif
00134         tpport_t proxyPort;
00135         Method urlmethod;
00136         Encoding encoding;
00137         Protocol protocol;
00138         Authentication auth;
00139         Authentication proxyAuth;
00140         timeout_t timeout;
00141         bool persistent;
00142         bool follow;
00143         unsigned chunk;
00144 
00145         Error getHTTPHeaders();
00146         URLStream(const URLStream& rhs);
00147 
00148 protected:
00149         ost::String m_host, m_address;
00150 
00151         Error sendHTTPHeader(const char *url, const char **vars, size_t bufsize);
00152         int underflow(void);
00153 
00154         virtual int aRead(char *buffer, size_t len, timeout_t timer);
00155 
00156         virtual int aWrite(char *buffer, size_t len, timeout_t timer);
00157 
00164         virtual void httpHeader(const char *header, const char *value);
00165 
00171         virtual char **extraHeader(void);
00172 
00173 public:
00179         URLStream(Family family = IPV4, timeout_t to = 0);
00180 
00188         URLStream &getline(char *buffer, size_t len);
00189 
00197         Error get(const char *url, size_t buffer = 512);
00198 
00207         Error get(size_t buffer = 512);         
00208 
00218         Error submit(const char *url, const char **vars, size_t buffer = 512);
00219 
00228         Error post(const char *url, const char **vars, size_t buffer = 512);
00229 
00237         Error head(const char *url, size_t buffer = 512);
00238 
00242         void close();
00243 
00249         void setReferer(const char *str);
00250 
00256         inline void setHost(const char *str)
00257                 {m_host = str;};
00258 
00264         inline void setAddress(const char *str)
00265                 {m_address = str;};
00266 
00272         inline void setCookie(const char *str)
00273                 {cookie = str;};
00274 
00280         inline void setUser(const char *str)
00281                 {user = str;};
00282 
00288         inline void setPassword(const char *str)
00289                 {password = str;};
00290 
00297         void setAuthentication(Authentication a, const char *str = NULL);
00298 
00304         inline void setProxyUser(const char *str)
00305                 {proxyUser = str;};
00306  
00312         inline void setProxyPassword(const char *str)
00313                 {proxyPasswd = str;};
00314  
00321         void setProxyAuthentication(Authentication a, const char *str = NULL);
00322 
00328         inline void setPragma(const char *str)
00329                 {pragma = str;};
00330 
00337         void setProxy(const char *host, tpport_t port);
00338 
00344         inline void setAgent(const char *str)
00345                 {agent = str;};
00346 
00352         inline Method getMethod(void)
00353                 {return urlmethod;};
00354 
00361         inline void setTimeout(timeout_t to)
00362                 {timeout = to;};
00363 
00370         inline void setFollow(bool enable)
00371                 {follow = enable;};
00372 
00378         inline void setProtocol(Protocol pro)
00379                 {protocol = pro;};
00385         inline void setLocalInterface(const char *intf) 
00386         {localif=intf;} 
00387 };
00388 
00394 __EXPORT char* urlDecode(char *source, char *dest = NULL);
00395 
00402 __EXPORT char* urlEncode(const char *source, char *dest, size_t size);
00403 
00414 __EXPORT char* b64Decode(char *src, char *dest = NULL);
00415 
00427 __EXPORT char* b64Encode(const char *source, char *dest, size_t size);
00428 
00440 __EXPORT size_t b64Encode(const unsigned char *src, size_t srcsize,
00441                char *dst, size_t dstsize);
00442 
00452 __EXPORT size_t b64Decode(const char *src,
00453                 unsigned char *dst, size_t dstsize);
00454 
00460 __EXPORT String b64Encode(const String& src);
00461 
00469 __EXPORT String b64Decode(const String& src);
00470 
00477 __EXPORT String b64Encode(const unsigned char *src, size_t srcsize);
00478 
00488 __EXPORT size_t b64Decode(const String& src,
00489                 unsigned char *dst, size_t dstsize);
00490 
00491 
00492 #ifdef  CCXX_NAMESPACES
00493 }
00494 #endif
00495 
00496 #endif
00497 

Generated on Tue Sep 13 02:19:09 2005 for Bayonne by  doxygen 1.4.4