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
00046 #ifndef CCXX_URL_H_
00047 #define CCXX_URL_H_
00048
00049 #ifndef CCXX_CONFIG_H_
00050 #include <cc++/config.h>
00051 #endif
00052
00053 #ifndef CCXX_SOCKET_H_
00054 #include <cc++/socket.h>
00055 #endif
00056
00057 #ifndef CCXX_URLSTRING_H_
00058 #include <cc++/urlstring.h>
00059 #endif
00060
00061 #ifdef CCXX_NAMESPACES
00062 namespace ost {
00063 #endif
00064
00065 class CCXX_CLASS_EXPORT URLStream;
00066
00073 class CCXX_CLASS_EXPORT URLStream : public TCPStream
00074 {
00075 public:
00079 typedef enum
00080 {
00081 errSuccess = 0,
00082 errUnreachable,
00083 errMissing,
00084 errDenied,
00085 errInvalid,
00086 errForbidden,
00087 errUnauthorized,
00088 errRelocated,
00089 errFailure,
00090 errTimeout
00091 } Error;
00092
00096 typedef enum
00097 {
00098 authAnonymous = 0,
00099 authBasic
00100 } Authentication;
00101
00105 typedef enum
00106 {
00107 encodingBinary = 0,
00108 encodingChunked
00109 } Encoding;
00110
00114 typedef enum
00115 {
00116 methodHttpGet,
00117 methodHttpPut,
00118 methodHttpPost,
00119 methodFtpGet,
00120 methodFtpPut,
00121 methodFileGet,
00122 methodFilePut
00123 } Method;
00124
00128 typedef enum
00129 {
00130 protocolHttp1_0,
00131 protocolHttp1_1
00132 } Protocol;
00133
00134 private:
00135 const char *agent, *referer, *cookie, *pragma, *user, *password;
00136 const char *localif;
00137 InetHostAddress proxyHost;
00138 tpport_t proxyPort;
00139 Method urlmethod;
00140 Encoding encoding;
00141 Protocol protocol;
00142 Authentication auth;
00143 timeout_t timeout;
00144 bool persistent;
00145 bool follow;
00146 unsigned chunk;
00147
00148 Error getHTTPHeaders();
00149 URLStream(const URLStream& rhs);
00150
00151 protected:
00152 Error sendHTTPHeader(const char *url, const char **vars, int bufsize);
00153 int underflow(void);
00154
00155 virtual int aRead(char *buffer, size_t len, timeout_t timeout)
00156 #ifndef __MINGW32__
00157 {return ::read(so, buffer, len);};
00158 #else
00159 {return ::recv(so, buffer, len, 0); };
00160 #endif
00161
00162 virtual int aWrite(char *buffer, size_t len, timeout_t timeout)
00163 #ifndef __MINGW32__
00164 {return ::write(so, buffer, len);};
00165 #else
00166 {return ::send(so, buffer, len, 0); };
00167 #endif
00168
00175 virtual void httpHeader(const char *header, const char *value)
00176 {return;};
00177
00183 virtual char **extraHeader(void)
00184 {return NULL;};
00185
00186 public:
00192 URLStream(timeout_t to = 0);
00193
00201 URLStream &getline(char *buffer, size_t len);
00202
00210 Error get(const char *url, int buffer = 512);
00211
00221 Error submit(const char *url, const char **vars, int buffer = 512);
00222
00231 Error post(const char *url, const char **vars, int buffer = 512);
00232
00240 Error head(const char *url, int buffer = 512);
00241
00245 void close();
00246
00252 void setReferer(const char *str);
00253
00259 inline void setCookie(const char *str)
00260 {cookie = str;};
00261
00267 inline void setUser(const char *str)
00268 {user = str;};
00269
00275 inline void setPassword(const char *str)
00276 {password = str;};
00277
00284 void setAuthentication(Authentication a, const char *str = NULL);
00285
00291 inline void setPragma(const char *str)
00292 {pragma = str;};
00293
00300 void setProxy(const char *host, tpport_t port);
00301
00307 inline void setAgent(const char *str)
00308 {agent = str;};
00309
00315 inline Method getMethod(void)
00316 {return urlmethod;};
00317
00324 inline void setTimeout(timeout_t to)
00325 {timeout = to;};
00326
00333 inline void setFollow(bool enable)
00334 {follow = enable;};
00335
00341 inline void setProtocol(Protocol pro)
00342 {protocol = pro;};
00348 inline void setLocalInterface(const char *intf)
00349 {localif=intf;}
00350 };
00351
00352 #ifdef CCXX_NAMESPACES
00353 };
00354 #endif
00355
00356 #endif
00357