1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/protocol.h
3 // Purpose: Protocol base class
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROTOCOL_PROTOCOL_H
13 #define _WX_PROTOCOL_PROTOCOL_H
19 #include "wx/object.h"
20 #include "wx/string.h"
21 #include "wx/stream.h"
24 #include "wx/socket.h"
27 class WXDLLIMPEXP_FWD_NET wxProtocolLog
;
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
48 // wxProtocol: abstract base class for all protocols
49 // ----------------------------------------------------------------------------
51 class WXDLLIMPEXP_NET wxProtocol
53 : public wxSocketClient
60 virtual ~wxProtocol();
64 virtual bool Connect( const wxString
& WXUNUSED(host
) ) { return false; }
65 virtual bool Connect( const wxSockAddress
& addr
, bool WXUNUSED(wait
) = true)
66 { return wxSocketClient::Connect(addr
); }
68 // read a '\r\n' terminated line from the given socket and put it in
69 // result (without the terminators)
70 static wxProtocolError
ReadLine(wxSocketBase
*socket
, wxString
& result
);
72 // read a line from this socket - this one can be overridden in the
73 // derived classes if different line termination convention is to be used
74 virtual wxProtocolError
ReadLine(wxString
& result
);
75 #endif // wxUSE_SOCKETS
77 virtual bool Abort() = 0;
78 virtual wxInputStream
*GetInputStream(const wxString
& path
) = 0;
79 virtual wxString
GetContentType() const = 0;
82 virtual wxProtocolError
GetError() const { return m_lastError
; }
84 void SetUser(const wxString
& user
) { m_username
= user
; }
85 void SetPassword(const wxString
& passwd
) { m_password
= passwd
; }
87 virtual void SetDefaultTimeout(wxUint32 Value
);
89 // override wxSocketBase::SetTimeout function to avoid that the internal
90 // m_uiDefaultTimeout goes out-of-sync:
91 virtual void SetTimeout(long seconds
)
92 { SetDefaultTimeout(seconds
); }
95 // logging support: each wxProtocol object may have the associated logger
96 // (by default there is none) which is used to log network requests and
99 // set the logger, deleting the old one and taking ownership of this one
100 void SetLog(wxProtocolLog
*log
);
102 // return the current logger, may be NULL
103 wxProtocolLog
*GetLog() const { return m_log
; }
105 // detach the existing logger without deleting it, the caller is
106 // responsible for deleting the returned pointer if it's non-NULL
107 wxProtocolLog
*DetachLog()
109 wxProtocolLog
* const log
= m_log
;
114 // these functions forward to the same functions with the same names in
115 // wxProtocolLog if we have a valid logger and do nothing otherwise
116 void LogRequest(const wxString
& str
);
117 void LogResponse(const wxString
& str
);
120 // the timeout associated with the protocol:
121 wxUint32 m_uiDefaultTimeout
;
126 // this must be always updated by the derived classes!
127 wxProtocolError m_lastError
;
130 wxProtocolLog
*m_log
;
132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol
)
135 // ----------------------------------------------------------------------------
136 // macros for protocol classes
137 // ----------------------------------------------------------------------------
139 #define DECLARE_PROTOCOL(class) \
141 static wxProtoInfo g_proto_##class;
143 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
144 wxProtoInfo class::g_proto_##class(name, serv, host, wxCLASSINFO(class)); \
145 bool wxProtocolUse##class = true;
147 #define USE_PROTOCOL(class) \
148 extern bool wxProtocolUse##class ; \
149 static struct wxProtocolUserFor##class \
151 wxProtocolUserFor##class() { wxProtocolUse##class = true; } \
152 } wxProtocolDoUse##class;
154 class WXDLLIMPEXP_NET wxProtoInfo
: public wxObject
157 wxProtoInfo(const wxChar
*name
,
158 const wxChar
*serv_name
,
159 const bool need_host1
,
164 wxString m_protoname
;
167 wxClassInfo
*m_cinfo
;
172 DECLARE_DYNAMIC_CLASS(wxProtoInfo
)
173 wxDECLARE_NO_COPY_CLASS(wxProtoInfo
);
176 #endif // wxUSE_PROTOCOL
178 #endif // _WX_PROTOCOL_PROTOCOL_H