]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/protocol/protocol.h
Correct compilation conditions for wxURL::SetProxy.
[wxWidgets.git] / include / wx / protocol / protocol.h
... / ...
CommitLineData
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 licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_PROTOCOL_PROTOCOL_H
13#define _WX_PROTOCOL_PROTOCOL_H
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16#pragma interface
17#endif
18
19#include "wx/defs.h"
20
21#if wxUSE_PROTOCOL
22
23#include "wx/object.h"
24#include "wx/string.h"
25#include "wx/stream.h"
26
27#if wxUSE_SOCKETS
28 #include "wx/socket.h"
29#endif
30
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
34
35typedef enum
36{
37 wxPROTO_NOERR = 0,
38 wxPROTO_NETERR,
39 wxPROTO_PROTERR,
40 wxPROTO_CONNERR,
41 wxPROTO_INVVAL,
42 wxPROTO_NOHNDLR,
43 wxPROTO_NOFILE,
44 wxPROTO_ABRT,
45 wxPROTO_RCNCT,
46 wxPROTO_STREAMING
47} wxProtocolError;
48
49// ----------------------------------------------------------------------------
50// wxProtocol: abstract base class for all protocols
51// ----------------------------------------------------------------------------
52
53class WXDLLIMPEXP_NET wxProtocol
54#if wxUSE_SOCKETS
55 : public wxSocketClient
56#else
57 : public wxObject
58#endif
59{
60public:
61 wxProtocol();
62
63#if wxUSE_SOCKETS
64 bool Reconnect();
65 virtual bool Connect( const wxString& WXUNUSED(host) ) { return FALSE; }
66 virtual bool Connect( wxSockAddress& addr, bool WXUNUSED(wait) = TRUE) { return wxSocketClient::Connect(addr); }
67
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);
71
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
76
77 virtual bool Abort() = 0;
78 virtual wxInputStream *GetInputStream(const wxString& path) = 0;
79 virtual wxProtocolError GetError() = 0;
80 virtual wxString GetContentType() { return wxEmptyString; }
81 virtual void SetUser(const wxString& WXUNUSED(user)) {}
82 virtual void SetPassword(const wxString& WXUNUSED(passwd) ) {}
83
84private:
85 DECLARE_DYNAMIC_CLASS_NO_COPY(wxProtocol)
86};
87
88#if wxUSE_SOCKETS
89wxProtocolError WXDLLIMPEXP_NET GetLine(wxSocketBase *sock, wxString& result);
90#endif
91
92// ----------------------------------------------------------------------------
93// macros for protocol classes
94// ----------------------------------------------------------------------------
95
96#define DECLARE_PROTOCOL(class) \
97public: \
98 static wxProtoInfo g_proto_##class;
99
100#define IMPLEMENT_PROTOCOL(class, name, serv, host) \
101wxProtoInfo class::g_proto_##class(name, serv, host, CLASSINFO(class)); \
102bool wxProtocolUse##class = TRUE;
103
104#define USE_PROTOCOL(class) \
105 extern bool wxProtocolUse##class ; \
106 static struct wxProtocolUserFor##class \
107 { \
108 wxProtocolUserFor##class() { wxProtocolUse##class = TRUE; } \
109 } wxProtocolDoUse##class;
110
111class WXDLLIMPEXP_NET wxProtoInfo : public wxObject
112{
113public:
114 wxProtoInfo(const wxChar *name,
115 const wxChar *serv_name,
116 const bool need_host1,
117 wxClassInfo *info);
118
119protected:
120 wxProtoInfo *next;
121 wxString m_protoname;
122 wxString prefix;
123 wxString m_servname;
124 wxClassInfo *m_cinfo;
125 bool m_needhost;
126
127 friend class wxURL;
128
129 DECLARE_DYNAMIC_CLASS(wxProtoInfo)
130 DECLARE_NO_COPY_CLASS(wxProtoInfo)
131};
132
133#endif // wxUSE_PROTOCOL
134
135#endif // _WX_PROTOCOL_PROTOCOL_H