Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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 #ifndef CCXX_MIME_H_
00055 #include <cc++/mime.h>
00056 #endif
00057 
00058 #ifdef  CCXX_NAMESPACES
00059 namespace ost {
00060 #endif
00061 
00068 class __EXPORT URLStream : public TCPStream
00069 {
00070 public:
00074         typedef enum
00075         {
00076                 errSuccess = 0,
00077                 errUnreachable,
00078                 errMissing,
00079                 errDenied,
00080                 errInvalid,
00081                 errForbidden,
00082                 errUnauthorized,
00083                 errRelocated,
00084                 errFailure,
00085                 errTimeout,
00086                 errInterface
00087         } Error;
00088 
00092         typedef enum
00093         {
00094                 authAnonymous = 0,
00095                 authBasic
00096         } Authentication;
00097 
00101         typedef enum
00102         {
00103                 encodingBinary = 0,
00104                 encodingChunked
00105         } Encoding;
00106 
00110         typedef enum
00111         {
00112                 methodHttpGet,
00113                 methodHttpPut,
00114                 methodHttpPost,
00115                 methodHttpPostMultipart,
00116                 methodFtpGet,
00117                 methodFtpPut,
00118                 methodFileGet,
00119                 methodFilePut
00120         } Method;
00121 
00125         typedef enum
00126         {
00127                 protocolHttp1_0,
00128                 protocolHttp1_1
00129         } Protocol;
00130 
00131 private:
00132         const char *agent, *referer, *cookie, *pragma, *user, *password;
00133         const char *proxyUser, *proxyPasswd;
00134         const char *localif;
00135         IPV4Host proxyHost;
00136 #ifdef  CCXX_IPV6
00137         IPV6Host v6proxyHost;
00138 #endif
00139         tpport_t proxyPort;
00140         Method urlmethod;
00141         Encoding encoding;
00142         Protocol protocol;
00143         Authentication auth;
00144         Authentication proxyAuth;
00145         timeout_t timeout;
00146         bool persistent;
00147         bool follow;
00148         unsigned chunk;
00149 
00150         Error getHTTPHeaders();
00151         URLStream(const URLStream& rhs);
00152 
00153 protected:
00154         ost::String m_host, m_address;
00155 
00164         Error sendHTTPHeader(const char *url, const char **vars, size_t bufsize);
00165 
00171         int underflow(void);
00172 
00181         virtual int aRead(char *buffer, size_t len, timeout_t timer);
00182 
00191         virtual int aWrite(char *buffer, size_t len, timeout_t timer);
00192 
00199         virtual void httpHeader(const char *header, const char *value);
00200 
00206         virtual char **extraHeader(void);
00207 
00208 public:
00215         URLStream(Family family = IPV4, timeout_t timer = 0);
00216 
00224         URLStream &getline(char *buffer, size_t len);
00225 
00233         Error get(const char *url, size_t buffer = 512);
00234 
00243         Error get(size_t buffer = 512);         
00244 
00254         Error submit(const char *url, const char **vars, size_t buffer = 512);
00255 
00264         Error post(const char *url, const char **vars, size_t buffer = 512);
00265 
00274         Error post(const char *url, MIMEMultipartForm &form, size_t buffer = 512);
00275 
00283         Error head(const char *url, size_t buffer = 512);
00284 
00288         void close();
00289 
00295         void setReferer(const char *str);
00296 
00302         inline void setHost(const char *str)
00303                 {m_host = str;};
00304 
00310         inline void setAddress(const char *str)
00311                 {m_address = str;};
00312 
00318         inline void setCookie(const char *str)
00319                 {cookie = str;};
00320 
00326         inline void setUser(const char *str)
00327                 {user = str;};
00328 
00334         inline void setPassword(const char *str)
00335                 {password = str;};
00336 
00343         void setAuthentication(Authentication a, const char *str = NULL);
00344 
00350         inline void setProxyUser(const char *str)
00351                 {proxyUser = str;};
00352  
00358         inline void setProxyPassword(const char *str)
00359                 {proxyPasswd = str;};
00360  
00367         void setProxyAuthentication(Authentication a, const char *str = NULL);
00368 
00374         inline void setPragma(const char *str)
00375                 {pragma = str;};
00376 
00383         void setProxy(const char *host, tpport_t port);
00384 
00390         inline void setAgent(const char *str)
00391                 {agent = str;};
00392 
00398         inline Method getMethod(void)
00399                 {return urlmethod;};
00400 
00407         inline void setTimeout(timeout_t to)
00408                 {timeout = to;};
00409 
00416         inline void setFollow(bool enable)
00417                 {follow = enable;};
00418 
00424         inline void setProtocol(Protocol pro)
00425                 {protocol = pro;};
00431         inline void setLocalInterface(const char *intf) 
00432         {localif=intf;} 
00433 };
00434 
00440 __EXPORT char* urlDecode(char *source, char *dest = NULL);
00441 
00448 __EXPORT char* urlEncode(const char *source, char *dest, size_t size);
00449 
00460 __EXPORT char* b64Decode(char *src, char *dest = NULL);
00461 
00473 __EXPORT char* b64Encode(const char *source, char *dest, size_t size);
00474 
00486 __EXPORT size_t b64Encode(const unsigned char *src, size_t srcsize,
00487                char *dst, size_t dstsize);
00488 
00498 __EXPORT size_t b64Decode(const char *src,
00499                 unsigned char *dst, size_t dstsize);
00500 
00506 __EXPORT String b64Encode(const String& src);
00507 
00515 __EXPORT String b64Decode(const String& src);
00516 
00523 __EXPORT String b64Encode(const unsigned char *src, size_t srcsize);
00524 
00534 __EXPORT size_t b64Decode(const String& src,
00535                 unsigned char *dst, size_t dstsize);
00536 
00537 
00538 #ifdef  CCXX_NAMESPACES
00539 }
00540 #endif
00541 
00542 #endif
00543 

Generated on Mon Feb 6 17:50:13 2006 for GNU CommonC++ by  doxygen 1.4.4