]>
git.saurik.com Git - wxWidgets.git/blob - src/common/protocol.cpp
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"
29 #include "wx/protocol/protocol.h"
31 #include "wx/module.h"
33 /////////////////////////////////////////////////////////////////
35 /////////////////////////////////////////////////////////////////
38 * --------------------------------------------------------------
39 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
40 * --------------------------------------------------------------
43 wxProtoInfo::wxProtoInfo(const char *name
, const char *serv
,
44 const bool need_host1
, wxClassInfo
*info
)
49 m_needhost
= need_host1
;
50 next
= wxURL::g_protocols
;
51 wxURL::g_protocols
= this;
54 /////////////////////////////////////////////////////////////////
55 // wxProtocol ///////////////////////////////////////////////////
56 /////////////////////////////////////////////////////////////////
58 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
60 wxProtocol::wxProtocol()
65 bool wxProtocol::Reconnect()
80 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
81 #define PROTO_BSIZE 2048
83 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
87 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
88 if (sock
->LastError() != 0 || avail
== 0)
89 return wxPROTO_NETERR
;
91 memcpy(tmp_str
, tmp_buf
, avail
);
93 // Not implemented on all systems
94 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
96 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
103 return wxPROTO_PROTERR
;
107 result
= result
.Left(result
.Length()-1);
109 size
= ret
-tmp_str
+1;
110 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
111 return wxPROTO_NOERR
;
115 // ----------------------------------------------------------------------
117 // ----------------------------------------------------------------------
119 class wxProtocolModule
: public wxModule
{
120 DECLARE_DYNAMIC_CLASS(wxProtocolModule
)
122 wxProtocolModule() {}
127 #if !USE_SHARED_LIBRARY
128 IMPLEMENT_DYNAMIC_CLASS(wxProtocolModule
, wxModule
)
131 bool wxProtocolModule::OnInit()
133 wxURL::g_proxy
= new wxHTTP();
137 void wxProtocolModule::OnExit()
139 delete wxURL::g_proxy
;
140 wxURL::g_proxy
= NULL
;