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_PROTOCOL_H
00031 #define ULXR_PROTOCOL_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #include <vector>
00036
00037
00038 namespace ulxr {
00039
00040
00045 class MethodCall;
00046 class MethodResponse;
00047 class Connection;
00048
00052 class ULXR_API_DECL0 Protocol
00053 {
00054 public:
00055
00059 Protocol(Connection *conn);
00060
00063 virtual ~Protocol();
00064
00069 void writeRaw(char const *buff, long len);
00070
00076 long readRaw(char *buff, long len);
00077
00080 virtual void open();
00081
00087 bool accept(int timeout = 0) ;
00088
00092 bool isOpen() const;
00093
00100 virtual void shutdown(int mode) = 0;
00101
00104 virtual void close();
00105
00109 virtual bool hasBytesToRead() const = 0;
00110
00116 virtual void resetConnection();
00117
00123 virtual void sendRpcCall(const MethodCall &call, const CppString &resource, bool wbxml_mode);
00124
00129 virtual void sendRpcResponse(const MethodResponse &resp, bool wbxml_mode);
00130
00143 void setPersistent(bool pers);
00144
00148 bool isPersistent() const;
00149
00154 virtual bool responseStatus(CppString &phrase) const = 0;
00155
00158 typedef enum
00159 {
00160 ConnStart,
00161 ConnPendingCR,
00162 ConnPendingHeaderLine,
00163 ConnHeaderLine,
00164 ConnSwitchToBody,
00165 ConnBody,
00166 ConnError,
00167 ConnLast
00168 }
00169 State;
00170
00171
00184 virtual State connectionMachine(char * &buffer, long &len);
00185
00191 void addAuthentication(const CppString &user, const CppString &pass,
00192 const CppString &realm);
00193
00200 virtual void setMessageAuthentication(const CppString &user, const CppString &pass);
00201
00209 virtual bool checkAuthentication(const CppString &realm) const;
00210
00215 virtual void rejectAuthentication(const CppString &realm);
00216
00219 virtual void setTransmitOnly();
00220
00224 virtual bool isTransmitOnly();
00225
00229 Connection * getConnection() const;
00230
00235 virtual Protocol *detach() = 0;
00236
00237 protected:
00238
00243 void setConnection(Connection *conn);
00244
00248 void setConnectionState(State state);
00249
00253 State getConnectionState() const;
00254
00259 void setRemainingContentLength(long len);
00260
00268 long getRemainingContentLength() const;
00269
00274 long getContentLength() const;
00275
00279 void setContentLength(long len);
00280
00286 virtual bool getUserPass(CppString &user, CppString &pass) const;
00287
00290 virtual void determineContentLength() = 0;
00291
00295 virtual CppString getProtocolName() = 0;
00296
00297 private:
00298
00301 void init();
00302
00303 private:
00304
00305 struct AuthData;
00306 struct PImpl;
00307 PImpl *pimpl;
00308
00309 protected:
00310
00311 Protocol(const Protocol&);
00312
00313 private:
00314
00315 Protocol& operator=(const Protocol&);
00316 };
00317
00318
00319 }
00320
00321
00322 #endif // ULXR_PROTOCOL_H
00323