]>
git.saurik.com Git - wxWidgets.git/blob - src/common/protocol.cpp
c535c79258285876f35f85fb93801b39105e5980
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()
83 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
84 #define PROTO_BSIZE 2048
86 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
90 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
91 if (sock
->LastError() != 0 || avail
== 0)
92 return wxPROTO_NETERR
;
94 memcpy(tmp_str
, tmp_buf
, avail
);
96 // Not implemented on all systems
97 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
99 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
106 return wxPROTO_PROTERR
;
110 result
= result
.Left(result
.Length()-1);
112 size
= ret
-tmp_str
+1;
113 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
114 return wxPROTO_NOERR
;
119 // ----------------------------------------------------------------------
121 // ----------------------------------------------------------------------
123 class wxProtocolModule
: public wxModule
{
124 DECLARE_DYNAMIC_CLASS(wxProtocolModule
)
126 wxProtocolModule() {}
131 #if !USE_SHARED_LIBRARY
132 IMPLEMENT_DYNAMIC_CLASS(wxProtocolModule
, wxModule
)
135 bool wxProtocolModule::OnInit()
140 wxURL::g_proxy
= NULL
;
141 // Initialize the proxy when HTTP_PROXY is defined
142 env_http_prox
= getenv("HTTP_PROXY");
144 wxURL::SetDefaultProxy(env_http_prox
);
150 void wxProtocolModule::OnExit()
154 delete wxURL::g_proxy
;
155 wxURL::g_proxy
= NULL
;