// 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
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);
if (line.Length() == 0)
break;
+ printf("Header: %s\n", WXSTRINGCAST line);
int pos = line.Find(':');
if (pos == -1)
return FALSE;
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();
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();
break;
default:
m_error = wxPROTO_NOFILE;
+ RestoreState();
return FALSE;
}
- return ParseHeaders();
+ ret_value = ParseHeaders();
+ RestoreState();
+ return ret_value;
}
class wxHTTPStream : public wxSocketInputStream {
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(); }
};
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;
////////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "socket.h"
-// #pragma interface
-// #pragma implementation "socket.cpp"
#endif
#ifdef __MWERKS__
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;
}
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;
}
if (!peek) {
m_unrd_size -= size;
- if (!m_unrd_size) {
+ if (m_unrd_size == 0) {
free(m_unread);
m_unread = NULL;
}
}
m_url = url;
m_error = wxURL_NOERR;
+ ParseURL();
}
bool wxURL::ParseURL()