]>
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"
25 #include "wx/protocol/protocol.h"
27 #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 /////////////////////////////////////////////////////////////////
54 IMPLEMENT_ABSTRACT_CLASS(wxProtocol
, wxSocketClient
)
56 wxProtocol::wxProtocol()
61 bool wxProtocol::Reconnect()
76 wxProtocolError
GetLine(wxSocketBase
*sock
, wxString
& result
) {
77 #define PROTO_BSIZE 2048
79 char tmp_buf
[PROTO_BSIZE
], tmp_str
[PROTO_BSIZE
];
83 avail
= sock
->Read(tmp_buf
, PROTO_BSIZE
).LastCount();
84 if (sock
->LastError() != 0 || avail
== 0)
85 return wxPROTO_NETERR
;
87 memcpy(tmp_str
, tmp_buf
, avail
);
89 // Not implemented on all systems
90 // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail);
92 for (ret
=tmp_str
;ret
< (tmp_str
+avail
); ret
++)
99 return wxPROTO_PROTERR
;
103 result
= result
.Left(result
.Length()-1);
105 size
= ret
-tmp_str
+1;
106 sock
->CreatePushbackBefore(&tmp_buf
[size
], avail
-size
);
107 return wxPROTO_NOERR
;
111 // ----------------------------------------------------------------------
113 // ----------------------------------------------------------------------
115 class wxProtocolModule
: public wxModule
{
116 DECLARE_DYNAMIC_CLASS(wxProtocolModule
)
118 wxProtocolModule() {}
123 #if !USE_SHARED_LIBRARY
124 IMPLEMENT_DYNAMIC_CLASS(wxProtocolModule
, wxModule
)
127 bool wxProtocolModule::OnInit()
129 wxURL::g_proxy
= new wxHTTP();
133 void wxProtocolModule::OnExit()
135 delete wxURL::g_proxy
;
136 wxURL::g_proxy
= NULL
;