X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f985bd39a0605d8dea4b4b1abc717c5658209c6..26128999a7e2bc05024e09ba2658d4a6ab87accd:/src/common/http.cpp diff --git a/src/common/http.cpp b/src/common/http.cpp index 07ba17fa8b..9d08ee7d80 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -20,6 +20,8 @@ #pragma hdrstop #endif +#if wxUSE_SOCKETS + #ifndef WX_PRECOMP #endif @@ -88,7 +90,7 @@ wxString wxHTTP::GetHeader(const wxString& header) { wxNode *node = m_headers.Find(header); if (!node) - return (char *)NULL; + return wxEmptyString; return *((wxString *)node->Data()); } @@ -97,12 +99,14 @@ void wxHTTP::SendHeaders() { wxNode *head = m_headers.First(); - while (head) { + while (head) + { wxString *str = (wxString *)head->Data(); - char buf[100]; - sprintf(buf, "%s: %s\n\r", head->GetKeyString(), str->GetData()); - Write(buf, strlen(buf)); + wxString buf; + buf.Printf("%s: %s\n\r", head->GetKeyString(), str->GetData()); + + Write(buf, buf.Len()); head = head->Next(); } @@ -123,6 +127,7 @@ bool wxHTTP::ParseHeaders() if (line.Length() == 0) break; + printf("Header: %s\n", WXSTRINGCAST line); int pos = line.Find(':'); if (pos == -1) return FALSE; @@ -164,7 +169,7 @@ bool wxHTTP::Connect(const wxString& host) return TRUE; } -bool wxHTTP::Connect(wxSockAddress& addr) +bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait)) { struct sockaddr *raw_addr; size_t len; @@ -190,6 +195,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(); @@ -199,18 +208,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(); @@ -220,16 +233,22 @@ 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 { public: wxHTTP *m_http; + size_t m_httpsize; + wxHTTPStream(wxHTTP *http) : wxSocketInputStream(*http), m_http(http) {} + size_t StreamSize() const { return m_httpsize; } virtual ~wxHTTPStream(void) { m_http->Abort(); } }; @@ -253,5 +272,12 @@ wxInputStream *wxHTTP::GetInputStream(const wxString& path) if (!BuildRequest(path, wxHTTP_GET)) return NULL; + 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; } + +#endif + // wxUSE_SOCKETS