1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/protocol.h
3 // Purpose: Protocol base class
4 // Author: Guilhem Lavaux
7 // Copyright: (c) 1997, 1998 Guilhem Lavaux
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROTOCOL_PROTOCOL_H
12 #define _WX_PROTOCOL_PROTOCOL_H
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/stream.h"
23 #include "wx/socket.h"
26 class WXDLLIMPEXP_FWD_NET wxProtocolLog
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
47 // wxProtocol: abstract base class for all protocols
48 // ----------------------------------------------------------------------------
50 class WXDLLIMPEXP_NET wxProtocol
52 : public wxSocketClient
59 virtual ~wxProtocol();
63 virtual bool Connect( const wxString
& WXUNUSED(host
) ) { return false; }
64 virtual bool Connect( const wxSockAddress
& addr
, bool WXUNUSED(wait
) = true)
65 { return wxSocketClient::Connect(addr
); }
67 // read a '\r\n' terminated line from the given socket and put it in
68 // result (without the terminators)
69 static wxProtocolError
ReadLine(wxSocketBase
*socket
, wxString
& result
);
71 // read a line from this socket - this one can be overridden in the
72 // derived classes if different line termination convention is to be used
73 virtual wxProtocolError
ReadLine(wxString
& result
);
74 #endif // wxUSE_SOCKETS
76 virtual bool Abort() = 0;
77 virtual wxInputStream
*GetInputStream(const wxString
& path
) = 0;
78 virtual wxString
GetContentType() const = 0;
81 virtual wxProtocolError
GetError() const { return m_lastError
; }
83 void SetUser(const wxString
& user
) { m_username
= user
; }
84 void SetPassword(const wxString
& passwd
) { m_password
= passwd
; }
86 virtual void SetDefaultTimeout(wxUint32 Value
);
88 // override wxSocketBase::SetTimeout function to avoid that the internal
89 // m_uiDefaultTimeout goes out-of-sync:
90 virtual void SetTimeout(long seconds
)
91 { SetDefaultTimeout(seconds
); }
94 // logging support: each wxProtocol object may have the associated logger
95 // (by default there is none) which is used to log network requests and
98 // set the logger, deleting the old one and taking ownership of this one
99 void SetLog(wxProtocolLog
*log
);
101 // return the current logger, may be NULL
102 wxProtocolLog
*GetLog() const { return m_log
; }
104 // detach the existing logger without deleting it, the caller is
105 // responsible for deleting the returned pointer if it's non-NULL
106 wxProtocolLog
*DetachLog()
108 wxProtocolLog
* const log
= m_log
;
113 // these functions forward to the same functions with the same names in
114 // wxProtocolLog if we have a valid logger and do nothing otherwise
115 void LogRequest(const wxString
& str
);
116 void LogResponse(const wxString
& str
);
119 // the timeout associated with the protocol:
120 wxUint32 m_uiDefaultTimeout
;
125 // this must be always updated by the derived classes!
126 wxProtocolError m_lastError
;
129 wxProtocolLog
*m_log
;
131 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol
)
134 // ----------------------------------------------------------------------------
135 // macros for protocol classes
136 // ----------------------------------------------------------------------------
138 #define DECLARE_PROTOCOL(class) \
140 static wxProtoInfo g_proto_##class;
142 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
143 wxProtoInfo class::g_proto_##class(name, serv, host, wxCLASSINFO(class)); \
144 bool wxProtocolUse##class = true;
146 #define USE_PROTOCOL(class) \
147 extern bool wxProtocolUse##class ; \
148 static struct wxProtocolUserFor##class \
150 wxProtocolUserFor##class() { wxProtocolUse##class = true; } \
151 } wxProtocolDoUse##class;
153 class WXDLLIMPEXP_NET wxProtoInfo
: public wxObject
156 wxProtoInfo(const wxChar
*name
,
157 const wxChar
*serv_name
,
158 const bool need_host1
,
163 wxString m_protoname
;
166 wxClassInfo
*m_cinfo
;
171 DECLARE_DYNAMIC_CLASS(wxProtoInfo
)
172 wxDECLARE_NO_COPY_CLASS(wxProtoInfo
);
175 #endif // wxUSE_PROTOCOL
177 #endif // _WX_PROTOCOL_PROTOCOL_H