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
00038
00039
00040
00041 #ifndef __CCXX_URL_H__
00042 #define __CCXX_URL_H__
00043
00044 #ifndef __CCXX_SOCKET_H__
00045 #include <cc++/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_RELOCATED,
00058 URL_FAILURE,
00059 URL_TIMEOUT
00060 } urlerror_t;
00061
00062 typedef enum
00063 {
00064 URL_ANONYMOUS_AUTH = 0,
00065 URL_BASIC_AUTH
00066 } urlauth_t;
00067
00068 typedef enum
00069 {
00070 URL_BINARY_ENCODING = 0,
00071 URL_CHUNKED_ENCODING
00072 } urlencoding_t;
00073
00074 typedef enum
00075 {
00076 HTTP_GET_METHOD,
00077 HTTP_PUT_METHOD,
00078 HTTP_POST_METHOD,
00079 FTP_GET_METHOD,
00080 FTP_PUT_METHOD,
00081 FILE_GET_METHOD,
00082 FILE_PUT_METHOD
00083 } urlmethod_t;
00084
00085 typedef enum
00086 {
00087 HTTP_PROTOCOL_1_0,
00088 HTTP_PROTOCOL_1_1
00089 } urlprotocol_t;
00090
00091 class __EXPORT URLStream;
00092
00099 class URLStream : public TCPStream
00100 {
00101 private:
00102 const char *agent, *referer, *cookie, *pragma, *user, *password;
00103 InetHostAddress proxyHost, prevHost;
00104 tpport_t proxyPort, prevPort;
00105 InetHostAddress refhost;
00106 urlmethod_t urlmethod;
00107 urlencoding_t encoding;
00108 urlprotocol_t protocol;
00109 urlauth_t auth;
00110 timeout_t timeout;
00111 bool persistent;
00112 bool follow;
00113 unsigned chunk;
00114 char authbuf[128];
00115
00116 urlerror_t getHTTPHeaders(char *buffer, unsigned bufsize);
00117
00118 protected:
00119 urlerror_t sendHTTPHeader(const char *path, const char **vars, int bufsize);
00120 int underflow(void);
00121
00128 virtual void httpHeader(const char *header, const char *value)
00129 {return;};
00130
00131 public:
00135 URLStream();
00136
00144 URLStream &getline(char *buffer, size_t len);
00145
00153 urlerror_t Get(const char *path, int buffer = 512);
00154
00164 urlerror_t Submit(const char *path, const char **vars, int buffer = 512);
00165
00174 urlerror_t Post(const char *path, const char **vars, int buffer = 512);
00175
00183 urlerror_t Head(const char *path, int buffer = 512);
00184
00188 void Close();
00189
00195 void setReferer(const char *str);
00196
00202 inline void setCookie(const char *str)
00203 {cookie = str;};
00204
00210 inline void setUser(const char *str)
00211 {user = str;};
00212
00218 inline void setPassword(const char *str)
00219 {password = str;};
00220
00226 void setAuthentication(urlauth_t a, const char *str = NULL);
00227
00233 inline void setPragma(const char *str)
00234 {pragma = str;};
00235
00242 void setProxy(const char *host, tpport_t port);
00243
00249 inline void setAgent(const char *str)
00250 {agent = str;};
00251
00257 inline urlmethod_t getMethod(void)
00258 {return urlmethod;};
00259
00266 inline void setTimeout(timeout_t to)
00267 {timeout = to;};
00268
00275 inline void setFollow(bool enable)
00276 {follow = enable;};
00277
00283 inline void setProtocol(urlprotocol_t pro)
00284 {protocol = pro;};
00285 };
00286
00287 extern __EXPORT char *urldecode(char *source, char *dest = NULL);
00288 extern __EXPORT char *urlencode(const char *source, char *dest, unsigned size);
00289
00290 #ifdef __CCXX_NAMESPACE_H__
00291 #undef __CCXX_NAMESPACE_H__
00292 #include <cc++/namespace.h>
00293 #endif
00294
00295 #endif
00296