00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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