]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: protocol.cpp | |
3 | // Purpose: Implement protocol base class | |
4 | // Author: Guilhem Lavaux | |
5 | // Modified by: | |
6 | // Created: 07/07/1997 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1997, 1998 Guilhem Lavaux | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "protocol.h" | |
14 | #endif | |
15 | ||
fcc6dddd JS |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
f4ada568 GL |
24 | #include <wx/wx.h> |
25 | #endif | |
26 | ||
27 | #include "wx/protocol/protocol.h" | |
28 | #include "wx/url.h" | |
29 | ||
f4ada568 GL |
30 | ///////////////////////////////////////////////////////////////// |
31 | // wxProtoInfo | |
32 | ///////////////////////////////////////////////////////////////// | |
33 | ||
34 | /* | |
35 | * -------------------------------------------------------------- | |
36 | * --------- wxProtoInfo CONSTRUCTOR ---------------------------- | |
37 | * -------------------------------------------------------------- | |
38 | */ | |
39 | ||
40 | wxProtoInfo::wxProtoInfo(const char *name, const char *serv, | |
41 | const bool need_host1, wxClassInfo *info) | |
42 | { | |
43 | m_protoname = name; | |
44 | m_servname = serv; | |
45 | m_cinfo = info; | |
46 | m_needhost = need_host1; | |
47 | next = wxURL::g_protocols; | |
48 | wxURL::g_protocols = this; | |
49 | } | |
50 | ||
51 | ///////////////////////////////////////////////////////////////// | |
52 | // wxProtocol /////////////////////////////////////////////////// | |
53 | ///////////////////////////////////////////////////////////////// | |
54 | ||
55 | IMPLEMENT_ABSTRACT_CLASS(wxProtocol, wxSocketClient) | |
56 | ||
57 | wxProtocol::wxProtocol() | |
58 | : wxSocketClient() | |
59 | { | |
60 | } | |
61 | ||
62 | bool wxProtocol::Reconnect() | |
63 | { | |
64 | wxIPV4address addr; | |
65 | ||
66 | if (!GetPeer(addr)) { | |
67 | Close(); | |
68 | return FALSE; | |
69 | } | |
70 | if (!Close()) | |
71 | return FALSE; | |
72 | if (!Connect(addr)) | |
73 | return FALSE; | |
74 | return TRUE; | |
75 | } | |
76 | ||
77 | wxProtocolError GetLine(wxSocketBase *sock, wxString& result) { | |
78 | #define PROTO_BSIZE 2048 | |
79 | size_t avail, size; | |
80 | char tmp_buf[PROTO_BSIZE], tmp_str[PROTO_BSIZE]; | |
81 | char *ret; | |
82 | bool found; | |
83 | ||
84 | avail = sock->Read(tmp_buf, PROTO_BSIZE).LastCount(); | |
85 | if (sock->LastError() != 0 || avail == 0) | |
86 | return wxPROTO_NETERR; | |
87 | ||
88 | memcpy(tmp_str, tmp_buf, avail); | |
89 | ||
90 | // Not implemented on all systems | |
91 | // ret = (char *)memccpy(tmp_str, tmp_buf, '\n', avail); | |
92 | found = FALSE; | |
93 | for (ret=tmp_str;ret < (tmp_str+avail); ret++) | |
94 | if (*ret == '\n') { | |
95 | found = TRUE; | |
96 | break; | |
97 | } | |
98 | ||
99 | if (!found) | |
100 | return wxPROTO_PROTERR; | |
101 | *ret = 0; | |
102 | ||
103 | result = tmp_str; | |
104 | result = result.Left(result.Length()-1); | |
105 | ||
106 | size = ret-tmp_str+1; | |
107 | sock->CreatePushbackBefore(&tmp_buf[size], avail-size); | |
108 | return wxPROTO_NOERR; | |
109 | #undef PROTO_BSIZE | |
110 | } |