]>
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"
27 #include "wx/protocol/protocol.h"
29 #include "wx/module.h"
31 /////////////////////////////////////////////////////////////////
33 /////////////////////////////////////////////////////////////////
36 * --------------------------------------------------------------
37 * --------- wxProtoInfo CONSTRUCTOR ----------------------------
38 * --------------------------------------------------------------
41 wxProtoInfo::wxProtoInfo(const char *name
, const char *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()
131 wxURL::g_proxy
= new wxHTTP();
135 void wxProtocolModule::OnExit()
137 delete wxURL::g_proxy
;
138 wxURL::g_proxy
= NULL
;