]>
git.saurik.com Git - wxWidgets.git/blob - src/common/protocol.cpp
1f5fb7adfd5af6e2d230cdbe849ff984148bf5dc
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"
25 #include "wx/protocol/protocol.h"
27 #include "wx/module.h"
31 /////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////
36 * --------------------------------------------------------------
37 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
38 * --------------------------------------------------------------
41 wxProtoInfo::wxProtoInfo(const wxChar
*name
, const wxChar
*serv
,
42 const bool need_host1
, wxClassInfo
*info
)
47 m_needhost
= need_host1
;
48 next
= wxURL::g_protocols
;
49 wxURL::g_protocols
= this;
52 /////////////////////////////////////////////////////////////////
53 // wxProtocol ///////////////////////////////////////////////////
54 /////////////////////////////////////////////////////////////////
56 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
58 wxProtocol::wxProtocol()
63 bool wxProtocol::Reconnect()
78 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
79 #define PROTO_BSIZE 2048
81 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
85 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
86 if (sock
->LastError() != 0 || avail
== 0)
87 return wxPROTO_NETERR
;
89 memcpy(tmp_str
, tmp_buf
, avail
);
91 // Not implemented on all systems
92 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
94 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
101 return wxPROTO_PROTERR
;
105 result
= result
.Left(result
.Length()-1);
107 size
= ret
-tmp_str
+1;
108 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
109 return wxPROTO_NOERR
;
113 // ----------------------------------------------------------------------
115 // ----------------------------------------------------------------------
117 class wxProtocolModule
: public wxModule
{
118 DECLARE_DYNAMIC_CLASS(wxProtocolModule
)
120 wxProtocolModule() {}
125 #if !USE_SHARED_LIBRARY
126 IMPLEMENT_DYNAMIC_CLASS(wxProtocolModule
, wxModule
)
129 bool wxProtocolModule::OnInit()
133 wxURL::g_proxy
= NULL
;
134 // Initialize the proxy when HTTP_PROXY is defined
135 env_http_prox
= getenv("HTTP_PROXY");
137 wxURL::SetDefaultProxy(env_http_prox
);
142 void wxProtocolModule::OnExit()
145 delete wxURL::g_proxy
;
146 wxURL::g_proxy
= NULL
;