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 #ifndef ULXR_HTTP_PROTOCOL_H
00031 #define ULXR_HTTP_PROTOCOL_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #include <map>
00036 #include <vector>
00037
00038 #include <ulxmlrpcpp/ulxr_protocol.h>
00039
00040
00041 namespace ulxr {
00042
00043
00044 class TcpIpConnection;
00045 class ConnectorWrapperBase;
00046
00050 class ULXR_API_DECL0 HttpProtocol : public Protocol
00051 {
00052 public:
00053
00054 typedef std::map<CppString, CppString> header_property;
00055
00061 HttpProtocol(Connection *conn, const CppString &hostname, unsigned hostport);
00062
00066 HttpProtocol(TcpIpConnection *conn);
00067
00070 virtual ~HttpProtocol();
00071
00076 virtual bool responseStatus(CppString &phrase) const;
00077
00083 virtual void sendRpcCall(const MethodCall &call, const CppString &resource, bool wbxml);
00084
00089 virtual void sendRpcResponse(const MethodResponse &resp, bool wbxml);
00090
00096 virtual void resetConnection();
00097
00110 virtual State connectionMachine(char * &buffer, long &len);
00111
00114 virtual void setTransmitOnly();
00115
00119 virtual bool isTransmitOnly();
00120
00124 virtual CppString getProtocolName();
00125
00129 virtual bool hasBytesToRead() const;
00130
00137 virtual bool determineClosing(const CppString &http_ver);
00138
00141
00147 void sendNegativeResponse(int status, const CppString &phrase,
00148 const CppString &info = ULXR_PCHAR(""));
00149
00158 void sendRequestHeader(const CppString &method,
00159 const CppString &resource,
00160 const CppString &type, unsigned long len,
00161 bool wbxml_mode = false);
00162
00171 void sendResponseHeader(int code,
00172 const CppString &phrase,
00173 const CppString &type,
00174 unsigned long len,
00175 bool wbxml_mode = false);
00176
00181 CppString getUserAgent() const;
00182
00187 void setUserAgent(const CppString &ua);
00188
00193 virtual void rejectAuthentication(const CppString &realm);
00194
00201 virtual void setMessageAuthentication(const CppString &user, const CppString &pass);
00202
00209 virtual void setProxyAuthentication(const CppString &user, const CppString &pass);
00210
00217 CppString getHttpProperty (const CppString &name) const;
00218
00224 bool hasHttpProperty (const CppString &name) const;
00225
00229 static CppString getDateStr();
00230
00236 CppString getFirstHeaderLine() const;
00237
00242 virtual Protocol *detach();
00243
00246 void clearCookie();
00247
00251 bool hasCookie() const;
00252
00257 void setCookie(const CppString &cont);
00258
00262 CppString getCookie() const;
00263
00268 void setServerCookie(const CppString &cookie);
00269
00273 CppString getServerCookie() const;
00274
00278 bool hasServerCookie() const;
00279
00284 void setClientCookie(const CppString &cookie);
00285
00289 CppString getClientCookie() const;
00290
00294 bool hasClientCookie() const;
00295
00299 void setAcceptCookies(bool bAccept = true);
00300
00304 bool isAcceptCookies() const;
00305
00311 virtual void shutdown(int mode);
00312
00315 virtual void close();
00316
00320 void enableConnect(bool enable = true);
00321
00325 bool isConnectEnabled() const;
00326
00330 bool isConnected() const;
00331
00334 void doConnect();
00335
00341 void splitHeaderLine(CppString &head_version, unsigned &head_status, CppString &head_phrase);
00342
00347 void writeBody(const char *data, unsigned long len);
00348
00353 void writeChunk(const char *data, unsigned long len);
00354
00358 void setChunkedTransfer(bool chunked);
00359
00363 bool isChunkedTransfer() const;
00364
00365 protected:
00366
00369 typedef enum
00370 {
00371 ConnChunkHeader = Protocol::ConnLast,
00372 ConnChunkBody,
00373 ConnChunkBodySkip,
00374 ConnChunkTerminated
00375 }
00376 HttpState;
00377
00380 void tryConnect();
00381
00384 void awaitConnect();
00385
00390 bool hasClosingProperty();
00391
00394 void clearHttpInfo();
00395
00401 virtual bool getUserPass(CppString &user, CppString &pass) const;
00402
00408 void addOneTimeHttpField(const CppString &name, const CppString &value);
00409
00412 virtual void determineContentLength();
00413
00418 void parseHeaderLine();
00419
00422 bool checkContinue();
00423
00424 private:
00425
00428 void init ();
00429
00436 void machine_switchToBody(char * &buffer,
00437 long &len,
00438 char * &chunk_start,
00439 char * &chunk_cursor);
00440
00441 private:
00442
00443 HttpProtocol(const HttpProtocol&);
00444 HttpProtocol& operator=(const HttpProtocol&);
00445
00446 private:
00447
00448 struct PImpl;
00449 PImpl *pimpl;
00450 };
00451
00452
00453 };
00454
00455
00456 #endif // ULXR_HTTP_PROTOCOL_H