]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/protocol.h
1) wxHTML now outputs unrecognized entities verbosely
[wxWidgets.git] / include / wx / protocol / protocol.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/protocol.h
3 // Purpose: Protocol base class
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 10/07/1997
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROTOCOL_PROTOCOL_H
13 #define _WX_PROTOCOL_PROTOCOL_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "wx/defs.h"
20
21 #include "wx/object.h"
22 #include "wx/string.h"
23 #include "wx/stream.h"
24
25 #if wxUSE_SOCKETS
26 #include "wx/socket.h"
27 #endif
28
29 // ----------------------------------------------------------------------------
30 // constants
31 // ----------------------------------------------------------------------------
32
33 typedef enum
34 {
35 wxPROTO_NOERR = 0,
36 wxPROTO_NETERR,
37 wxPROTO_PROTERR,
38 wxPROTO_CONNERR,
39 wxPROTO_INVVAL,
40 wxPROTO_NOHNDLR,
41 wxPROTO_NOFILE,
42 wxPROTO_ABRT,
43 wxPROTO_RCNCT,
44 wxPROTO_STREAMING
45 } wxProtocolError;
46
47 // ----------------------------------------------------------------------------
48 // wxProtocol: abstract base class for all protocols
49 // ----------------------------------------------------------------------------
50
51 class WXDLLEXPORT wxProtocol
52 #if wxUSE_SOCKETS
53 : public wxSocketClient
54 #else
55 : public wxObject
56 #endif
57 {
58 public:
59 wxProtocol();
60
61 #if wxUSE_SOCKETS
62 bool Reconnect();
63 virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; }
64 virtual bool Connect( wxSockAddress& addr, bool WXUNUSED(wait) = TRUE) { return wxSocketClient::Connect(addr); }
65
66 // read a '\r\n' terminated line from the given socket and put it in
67 // result (without the terminators)
68 static wxProtocolError ReadLine(wxSocketBase *socket, wxString& result);
69
70 // read a line from this socket - this one can be overridden in the
71 // derived classes if different line termination convention is to be used
72 virtual wxProtocolError ReadLine(wxString& result);
73 #endif // wxUSE_SOCKETS
74
75 virtual bool Abort() = 0;
76 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
77 virtual wxProtocolError GetError() = 0;
78 virtual wxString GetContentType() { return wxEmptyString; }
79 virtual void SetUser(const wxString& WXUNUSED(user)) {}
80 virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
81
82 private:
83 DECLARE_ABSTRACT_CLASS(wxProtocol)
84 };
85
86 #if wxUSE_SOCKETS
87 wxProtocolError WXDLLEXPORT GetLine(wxSocketBase *sock, wxString& result);
88 #endif
89
90 // ----------------------------------------------------------------------------
91 // macros for protocol classes
92 // ----------------------------------------------------------------------------
93
94 #define DECLARE_PROTOCOL(class) \
95 public: \
96 static wxProtoInfo g_proto_##class;
97
98 #define IMPLEMENT_PROTOCOL(class, name, serv, host) \
99 wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
100 bool wxProtocolUse##class = TRUE;
101
102 #define USE_PROTOCOL(class) \
103 extern bool wxProtocolUse##class ; \
104 static struct wxProtocolUserFor##class \
105 { \
106 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
107 } wxProtocolDoUse##class;
108
109 class WXDLLEXPORT wxProtoInfo : public wxObject
110 {
111 public:
112 wxProtoInfo(const wxChar *name,
113 const wxChar *serv_name,
114 const bool need_host1,
115 wxClassInfo *info);
116
117 protected:
118 wxProtoInfo *next;
119 wxString m_protoname;
120 wxString prefix;
121 wxString m_servname;
122 wxClassInfo *m_cinfo;
123 bool m_needhost;
124
125 friend class wxURL;
126
127 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
128 };
129
130 #endif // _WX_PROTOCOL_PROTOCOL_H