]>
git.saurik.com Git - wxWidgets.git/blob - src/common/protocol.cpp
875ad85af0bc02e7a45c44170415a8b7a9b1cf95
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implement protocol base class
4 // Author: Guilhem Lavaux
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "protocol.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/protocol/protocol.h"
25 #include "wx/module.h"
29 /////////////////////////////////////////////////////////////////
31 /////////////////////////////////////////////////////////////////
34 * --------------------------------------------------------------
35 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
36 * --------------------------------------------------------------
39 wxProtoInfo::wxProtoInfo(const wxChar
*name
, const wxChar
*serv
,
40 const bool need_host1
, wxClassInfo
*info
)
45 m_needhost
= need_host1
;
46 next
= wxURL::g_protocols
;
47 wxURL::g_protocols
= this;
50 /////////////////////////////////////////////////////////////////
51 // wxProtocol ///////////////////////////////////////////////////
52 /////////////////////////////////////////////////////////////////
55 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
57 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxObject
)
60 wxProtocol::wxProtocol()
68 bool wxProtocol::Reconnect()
85 // ----------------------------------------------------------------------------
86 // Read a line from socket
87 // ----------------------------------------------------------------------------
89 // TODO ReadLine() should use buffers private to wxProtocol for efficiency!
92 wxProtocolError
wxProtocol::ReadLine(wxSocketBase
*socket
, wxString
& result
)
95 char ch
, chLast
= '\0';
96 while ( !socket
->Read(&ch
, sizeof(ch
)).Error() )
101 // remember it, if the following is '\n', we're done
106 // only ends line if the previous character was '\r'
107 if ( chLast
== '\r' )
110 return wxPROTO_NOERR
;
126 return wxPROTO_NETERR
;
129 wxProtocolError
wxProtocol::ReadLine(wxString
& result
)
131 return ReadLine(this, result
);
134 // old function which only chops '\n' and not '\r\n'
135 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
136 #define PROTO_BSIZE 2048
138 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
142 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
143 if (sock
->Error() || avail
== 0)
144 return wxPROTO_NETERR
;
146 memcpy(tmp_str
, tmp_buf
, avail
);
148 // Not implemented on all systems
149 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
151 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
158 return wxPROTO_PROTERR
;
162 result
= result
.Left(result
.Length()-1);
164 size
= ret
-tmp_str
+1;
165 sock
->Unread(&tmp_buf
[size
], avail
-size
);
166 return wxPROTO_NOERR
;
171 // ----------------------------------------------------------------------
173 // ----------------------------------------------------------------------
175 class wxProtocolModule
: public wxModule
{
176 DECLARE_DYNAMIC_CLASS(wxProtocolModule
)
178 wxProtocolModule() {}
183 IMPLEMENT_DYNAMIC_CLASS(wxProtocolModule
, wxModule
)
185 bool wxProtocolModule::OnInit()
190 wxURL::g_proxy
= NULL
;
191 // Initialize the proxy when HTTP_PROXY is defined
192 env_http_prox
= getenv("HTTP_PROXY");
194 wxURL::SetDefaultProxy(env_http_prox
);
200 void wxProtocolModule::OnExit()
204 delete wxURL::g_proxy
;
205 wxURL::g_proxy
= NULL
;