* Big memory bug fixed in socket/getline fixed.
* Added two missing "virtual" in stream.h (Sorry, you'll have to rebuild all) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ed175610f0
commit
41895a05ea
@ -150,7 +150,7 @@ class WXDLLEXPORT wxInputStream: public wxStreamBase {
|
||||
// IO functions
|
||||
virtual char Peek();
|
||||
char GetC();
|
||||
wxInputStream& Read(void *buffer, size_t size);
|
||||
virtual wxInputStream& Read(void *buffer, size_t size);
|
||||
wxInputStream& Read(wxOutputStream& stream_out);
|
||||
|
||||
// Position functions
|
||||
@ -191,7 +191,7 @@ class WXDLLEXPORT wxOutputStream: public wxStreamBase {
|
||||
wxOutputStream(wxStreamBuffer *sbuf);
|
||||
virtual ~wxOutputStream();
|
||||
|
||||
wxOutputStream& Write(const void *buffer, size_t size);
|
||||
virtual wxOutputStream& Write(const void *buffer, size_t size);
|
||||
wxOutputStream& Write(wxInputStream& stream_in);
|
||||
|
||||
off_t SeekO(off_t pos, wxSeekMode mode = wxFromStart);
|
||||
|
@ -125,6 +125,7 @@ bool wxHTTP::ParseHeaders()
|
||||
if (line.Length() == 0)
|
||||
break;
|
||||
|
||||
printf("Header: %s\n", WXSTRINGCAST line);
|
||||
int pos = line.Find(':');
|
||||
if (pos == -1)
|
||||
return FALSE;
|
||||
@ -192,6 +193,10 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SaveState();
|
||||
Notify(FALSE);
|
||||
SetFlags(WAITALL);
|
||||
|
||||
sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path);
|
||||
Write(buf, strlen(buf));
|
||||
SendHeaders();
|
||||
@ -201,18 +206,22 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
wxString tmp_str;
|
||||
|
||||
m_error = GetLine(this, tmp_str);
|
||||
if (m_error != wxPROTO_NOERR)
|
||||
if (m_error != wxPROTO_NOERR) {
|
||||
RestoreState();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!tmp_str.Contains("HTTP/")) {
|
||||
// TODO: support HTTP v0.9 which can have no header.
|
||||
SetHeader("Content-Length", "-1");
|
||||
SetHeader("Content-Type", "none/none");
|
||||
RestoreState();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxStringTokenizer token(tmp_str,' ');
|
||||
wxString tmp_str2;
|
||||
bool ret_value;
|
||||
|
||||
token.NextToken();
|
||||
tmp_str2 = token.NextToken();
|
||||
@ -222,10 +231,13 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
|
||||
break;
|
||||
default:
|
||||
m_error = wxPROTO_NOFILE;
|
||||
RestoreState();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ParseHeaders();
|
||||
ret_value = ParseHeaders();
|
||||
RestoreState();
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
class wxHTTPStream : public wxSocketInputStream {
|
||||
@ -234,7 +246,7 @@ public:
|
||||
size_t m_httpsize;
|
||||
|
||||
wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {}
|
||||
size_t StreamSize() { return m_httpsize; }
|
||||
size_t StreamSize() const { return m_httpsize; }
|
||||
virtual ~wxHTTPStream(void) { m_http->Abort(); }
|
||||
};
|
||||
|
||||
@ -258,7 +270,8 @@ wxInputStream *wxHTTP::GetInputStream(const wxString& path)
|
||||
if (!BuildRequest(path, wxHTTP_GET))
|
||||
return NULL;
|
||||
|
||||
if (GetHeader("Content-Length").IsEmpty())
|
||||
printf("Len = %s\n", WXSTRINGCAST GetHeader("Content-Length"));
|
||||
if (!GetHeader("Content-Length").IsEmpty())
|
||||
inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length"));
|
||||
|
||||
return inp_stream;
|
||||
|
@ -11,8 +11,6 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "socket.h"
|
||||
// #pragma interface
|
||||
// #pragma implementation "socket.cpp"
|
||||
#endif
|
||||
|
||||
#ifdef __MWERKS__
|
||||
@ -357,31 +355,40 @@ bool wxSocketBase::Close()
|
||||
|
||||
wxSocketBase& wxSocketBase::Read(char* buffer, size_t nbytes)
|
||||
{
|
||||
m_lcount = GetPushback(buffer, nbytes, FALSE);
|
||||
nbytes -= m_lcount;
|
||||
size_t count;
|
||||
|
||||
count = GetPushback(buffer, nbytes, FALSE);
|
||||
nbytes -= count;
|
||||
buffer += count;
|
||||
|
||||
// If we have got the whole needed buffer or if we don't want to
|
||||
// wait then it returns immediately.
|
||||
if (!nbytes || (m_lcount && !(m_flags & WAITALL)) )
|
||||
return *this;
|
||||
|
||||
m_lcount = 0;
|
||||
WantBuffer(buffer, nbytes, EVT_READ);
|
||||
m_lcount += count;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
wxSocketBase& wxSocketBase::Peek(char* buffer, size_t nbytes)
|
||||
{
|
||||
size_t nbytes_old = nbytes;
|
||||
size_t count;
|
||||
|
||||
nbytes -= GetPushback(buffer, nbytes, TRUE);
|
||||
if (!nbytes)
|
||||
count = GetPushback(buffer, nbytes, TRUE);
|
||||
if (nbytes-count == 0)
|
||||
{
|
||||
m_lcount = nbytes_old;
|
||||
m_lcount = nbytes;
|
||||
return *this;
|
||||
}
|
||||
buffer += count;
|
||||
nbytes -= count;
|
||||
|
||||
m_lcount = 0;
|
||||
WantBuffer(buffer, nbytes, EVT_PEEK);
|
||||
m_lcount += count;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -1127,9 +1134,10 @@ void wxSocketBase::CreatePushbackBefore(const char *buffer, size_t size)
|
||||
curr_pos = new_buf + size;
|
||||
|
||||
memcpy(new_buf, buffer, size);
|
||||
memcpy(curr_pos, m_unread, m_unrd_size);
|
||||
|
||||
free(m_unread);
|
||||
if (m_unrd_size != 0) {
|
||||
memcpy(curr_pos, m_unread, m_unrd_size);
|
||||
free(m_unread);
|
||||
}
|
||||
m_unread = new_buf;
|
||||
m_unrd_size += size;
|
||||
}
|
||||
@ -1145,7 +1153,7 @@ size_t wxSocketBase::GetPushback(char *buffer, size_t size, bool peek)
|
||||
|
||||
if (!peek) {
|
||||
m_unrd_size -= size;
|
||||
if (!m_unrd_size) {
|
||||
if (m_unrd_size == 0) {
|
||||
free(m_unread);
|
||||
m_unread = NULL;
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ wxURL::wxURL(const wxString& url)
|
||||
}
|
||||
m_url = url;
|
||||
m_error = wxURL_NOERR;
|
||||
ParseURL();
|
||||
}
|
||||
|
||||
bool wxURL::ParseURL()
|
||||
|
Loading…
Reference in New Issue
Block a user