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 #ifndef INCL_ABSTRACT_HTTP_CONNECTION
00037 #define INCL_ABSTRACT_HTTP_CONNECTION
00038
00040 #include "base/globalsdef.h"
00041 #include "base/fscapi.h"
00042 #include "base/constants.h"
00043 #include "http/constants.h"
00044 #include "http/HttpAuthentication.h"
00045 #include "http/Proxy.h"
00046 #include "base/Log.h"
00047 #include "base/util/StringBuffer.h"
00048 #include "base/util/StringMap.h"
00049 #include "inputStream/InputStream.h"
00050 #include "inputStream/OutputStream.h"
00051
00052 BEGIN_FUNAMBOL_NAMESPACE
00053
00054
00055
00056 #define HTTP_HEADER_USER_AGENT "User-Agent"
00057 #define HTTP_HEADER_ACCEPT "Accept"
00058 #define HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
00059 #define HTTP_HEADER_CONTENT_TYPE "Content-Type"
00060 #define HTTP_HEADER_CONTENT_LENGTH "Content-Length"
00061 #define HTTP_HEADER_UNCOMPRESSED_CONTENT_LENGTH "Uncompressed-Content-Length"
00062 #define HTTP_HEADER_SET_COOKIE "Set-Cookie"
00063 #define HTTP_HEADER_AUTHORIZATION "Authorization"
00064 #define HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
00065 #define HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
00066
00067
00068
00069 #define HTTP_HEADER_X_FUNAMBOL_DEVICE_ID "x-funambol-syncdeviceid"
00070 #define HTTP_HEADER_X_FUNAMBOL_FILE_SIZE "x-funambol-file-size"
00071 #define HTTP_HEADER_X_FUNAMBOL_LUID "x-funambol-luid"
00072
00073
00074
00075 #define DEFAULT_REQUEST_MAX_CHUNK_SIZE 50000
00076
00077
00094 class AbstractHttpConnection {
00095
00096 public:
00097
00099 enum RequestMethod {
00100 MethodGet,
00101 MethodPost,
00102 MethodPut,
00103 MethodHead
00104 };
00105
00106 enum ConnectionStatus {
00107 StatusNoError = 0,
00108 StatusCancelledByUser = -1,
00109 StatusInternalError = -2,
00110 StatusReadingError = -3,
00111 StatusWritingError = -4,
00112 StatusInvalidParam = -5
00113 };
00114
00116 AbstractHttpConnection(const char* ua) : userAgent(ua) {
00117 method = MethodPost;
00118 auth = NULL;
00119 chunkSize = DEFAULT_REQUEST_MAX_CHUNK_SIZE;
00120 SSLVerifyServer = true;
00121 SSLVerifyHost = true;
00122 compression_enabled = false;
00123 keepalive = false;
00124 }
00125
00126 virtual ~AbstractHttpConnection() {}
00127
00128
00134 virtual int open(const URL& url, RequestMethod method = MethodPost) = 0;
00135
00141 virtual int close() = 0;
00142
00147 void setRequestMethod(RequestMethod method) {
00148 this->method = method;
00149 }
00150
00151
00162 virtual int request(InputStream& data, OutputStream& response) = 0;
00163
00164
00176 virtual void setRequestHeader(const char* key, const char* value) {
00177 requestHeaders.put(key, value);
00178 }
00179
00180
00187 virtual StringBuffer getResponseHeader(const char* key) {
00188 return responseHeaders[key];
00189 }
00190
00196 virtual void setAuthentication(HttpAuthentication *auth) {
00197 this->auth = auth;
00198 }
00199
00200
00202 void setChunkSize(const int size) { chunkSize = size; }
00203 int getChunkSize() { return chunkSize; }
00204
00211 virtual void setURL(const URL& newURL) { url = newURL; }
00212
00216 virtual const URL& getURL() const { return url; }
00217
00223 virtual void setTimeout(unsigned int t) { timeout = t; }
00224
00228 virtual unsigned int getTimeout() const { return timeout; }
00229
00237 virtual bool getSSLVerifyServer() const { return SSLVerifyServer; }
00238 virtual void setSSLVerifyServer(bool value) { SSLVerifyServer = value; }
00239
00247 virtual bool getSSLVerifyHost() const { return SSLVerifyHost; }
00248 virtual void setSSLVerifyHost(bool value) { SSLVerifyHost = value; }
00249
00253 virtual bool getCompression() const { return compression_enabled; }
00254 virtual void setCompression(bool value) { compression_enabled = value; }
00255
00260 virtual void setKeepAlive(bool val) { keepalive = val; }
00261
00262 protected:
00263
00264 URL url;
00265
00266 RequestMethod method;
00267
00269 StringMap requestHeaders;
00270
00272 StringMap responseHeaders;
00273
00275 HttpAuthentication* auth;
00276
00278 int chunkSize;
00279
00280 Proxy proxy;
00281
00282 unsigned int timeout;
00283
00284 StringBuffer userAgent;
00285
00286
00287 StringBuffer SSLServerCertificates;
00288 bool SSLVerifyServer;
00289 bool SSLVerifyHost;
00290 bool compression_enabled;
00291
00294 bool keepalive;
00295 };
00296
00297 END_FUNAMBOL_NAMESPACE
00298
00300 #endif
00301