]> git.saurik.com Git - wxWidgets.git/blame - include/wx/protocol/protocol.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / protocol / protocol.h
CommitLineData
f4ada568 1/////////////////////////////////////////////////////////////////////////////
8e907a13 2// Name: wx/protocol/protocol.h
f4ada568
GL
3// Purpose: Protocol base class
4// Author: Guilhem Lavaux
5// Modified by:
6// Created: 10/07/1997
f4ada568 7// Copyright: (c) 1997, 1998 Guilhem Lavaux
65571936 8// Licence: wxWindows licence
f4ada568 9/////////////////////////////////////////////////////////////////////////////
8e907a13 10
f4ada568
GL
11#ifndef _WX_PROTOCOL_PROTOCOL_H
12#define _WX_PROTOCOL_PROTOCOL_H
13
e3e717ec
VZ
14#include "wx/defs.h"
15
a5d46b73
VZ
16#if wxUSE_PROTOCOL
17
f4ada568
GL
18#include "wx/object.h"
19#include "wx/string.h"
20#include "wx/stream.h"
8a4df159
RR
21
22#if wxUSE_SOCKETS
8e907a13 23 #include "wx/socket.h"
8a4df159 24#endif
f4ada568 25
0576cd9e
VZ
26class WXDLLIMPEXP_FWD_NET wxProtocolLog;
27
8e907a13
VZ
28// ----------------------------------------------------------------------------
29// constants
30// ----------------------------------------------------------------------------
f4ada568 31
8e907a13
VZ
32typedef enum
33{
34 wxPROTO_NOERR = 0,
35 wxPROTO_NETERR,
36 wxPROTO_PROTERR,
37 wxPROTO_CONNERR,
38 wxPROTO_INVVAL,
39 wxPROTO_NOHNDLR,
40 wxPROTO_NOFILE,
41 wxPROTO_ABRT,
42 wxPROTO_RCNCT,
43 wxPROTO_STREAMING
44} wxProtocolError;
f4ada568 45
8e907a13
VZ
46// ----------------------------------------------------------------------------
47// wxProtocol: abstract base class for all protocols
48// ----------------------------------------------------------------------------
f4ada568 49
7c4728f6 50class WXDLLIMPEXP_NET wxProtocol
8a4df159 51#if wxUSE_SOCKETS
8e907a13 52 : public wxSocketClient
8a4df159 53#else
8e907a13 54 : public wxObject
8a4df159 55#endif
8e907a13 56{
f4ada568 57public:
8e907a13 58 wxProtocol();
0576cd9e 59 virtual ~wxProtocol();
f4ada568 60
8a4df159 61#if wxUSE_SOCKETS
8e907a13 62 bool Reconnect();
730b772b
FM
63 virtual bool Connect( const wxString& WXUNUSED(host) ) { return false; }
64 virtual bool Connect( const wxSockAddress& addr, bool WXUNUSED(wait) = true)
ddc7f0c9 65 { return wxSocketClient::Connect(addr); }
8e907a13
VZ
66
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);
70
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
f4ada568 75
8e907a13
VZ
76 virtual bool Abort() = 0;
77 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
730b772b
FM
78 virtual wxString GetContentType() const = 0;
79
80 // the error code
81 virtual wxProtocolError GetError() const { return m_lastError; }
82
83 void SetUser(const wxString& user) { m_username = user; }
84 void SetPassword(const wxString& passwd) { m_password = passwd; }
85
86 virtual void SetDefaultTimeout(wxUint32 Value);
87
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); }
92
93
0576cd9e
VZ
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
96 // responses
97
98 // set the logger, deleting the old one and taking ownership of this one
99 void SetLog(wxProtocolLog *log);
100
101 // return the current logger, may be NULL
102 wxProtocolLog *GetLog() const { return m_log; }
103
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()
107 {
108 wxProtocolLog * const log = m_log;
109 m_log = NULL;
110 return log;
111 }
112
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);
117
730b772b
FM
118protected:
119 // the timeout associated with the protocol:
120 wxUint32 m_uiDefaultTimeout;
121
122 wxString m_username;
123 wxString m_password;
124
125 // this must be always updated by the derived classes!
126 wxProtocolError m_lastError;
8e907a13
VZ
127
128private:
0576cd9e
VZ
129 wxProtocolLog *m_log;
130
fc7a2a60 131 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
f4ada568
GL
132};
133
8e907a13
VZ
134// ----------------------------------------------------------------------------
135// macros for protocol classes
136// ----------------------------------------------------------------------------
137
138#define DECLARE_PROTOCOL(class) \
139public: \
140 static wxProtoInfo g_proto_##class;
141
142#define IMPLEMENT_PROTOCOL(class, name, serv, host) \
b19b28c8 143wxProtoInfo class::g_proto_##class(name, serv, host, wxCLASSINFO(class)); \
8e6efd1f 144bool wxProtocolUse##class = true;
f92f546c
VS
145
146#define USE_PROTOCOL(class) \
147 extern bool wxProtocolUse##class ; \
148 static struct wxProtocolUserFor##class \
149 { \
8e6efd1f 150 wxProtocolUserFor##class() { wxProtocolUse##class = true; } \
f92f546c 151 } wxProtocolDoUse##class;
8e907a13 152
7c4728f6 153class WXDLLIMPEXP_NET wxProtoInfo : public wxObject
8e907a13
VZ
154{
155public:
156 wxProtoInfo(const wxChar *name,
157 const wxChar *serv_name,
158 const bool need_host1,
159 wxClassInfo *info);
160
161protected:
162 wxProtoInfo *next;
163 wxString m_protoname;
164 wxString prefix;
165 wxString m_servname;
166 wxClassInfo *m_cinfo;
167 bool m_needhost;
168
169 friend class wxURL;
170
171 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
c0c133e1 172 wxDECLARE_NO_COPY_CLASS(wxProtoInfo);
8e907a13
VZ
173};
174
a5d46b73
VZ
175#endif // wxUSE_PROTOCOL
176
e3e717ec 177#endif // _WX_PROTOCOL_PROTOCOL_H