ulxr_http_protocol.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                ulxr_http_prootocol.h  -  http prootocol
00003                              -------------------
00004     begin                : Mon May 3 2004
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_http_protocol.h 1014 2007-07-22 11:44:45Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 #ifndef ULXR_HTTP_PROTOCOL_H
00031 #define ULXR_HTTP_PROTOCOL_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
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,   // 7 chunk header of a chunked transfer
00372      ConnChunkBody,                          // 8 data chunk of a chunked transfer
00373      ConnChunkBodySkip,                      // 9 skip CRLF after chunk body
00374      ConnChunkTerminated                     // 10 all chunks and footer received
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&);  // empty!
00445 
00446  private:
00447 
00448    struct PImpl;
00449    PImpl *pimpl;
00450 };
00451 
00452 
00453 };  // namespace ulxr
00454 
00455 
00456 #endif // ULXR_HTTP_PROTOCOL_H

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1