X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/86470d432f52318dfaac17bfd6cf41e5123e82c9..6929fe3af8c307d7ff46e73a88edbedc39731d09:/src/common/url.cpp diff --git a/src/common/url.cpp b/src/common/url.cpp index b6b91694b1..46f40e2300 100644 --- a/src/common/url.cpp +++ b/src/common/url.cpp @@ -40,20 +40,27 @@ wxProtoInfo *wxURL::ms_protocols = NULL; // Enforce linking of protocol classes: USE_PROTOCOL(wxFileProto) -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP USE_PROTOCOL(wxHTTP) -USE_PROTOCOL(wxFTP) wxHTTP *wxURL::ms_proxyDefault = NULL; bool wxURL::ms_useDefaultProxy = false; #endif +#if wxUSE_PROTOCOL_FTP +USE_PROTOCOL(wxFTP) +#endif + // -------------------------------------------------------------- // // wxURL // // -------------------------------------------------------------- +// -------------------------------------------------------------- +// Construction +// -------------------------------------------------------------- + wxURL::wxURL(const wxString& url) : wxURI(url) { Init(url); @@ -66,21 +73,6 @@ wxURL::wxURL(const wxURI& url) : wxURI(url) ParseURL(); } -wxURL& wxURL::operator = (const wxURI& url) -{ - wxURI::operator = (url); - Init(url.BuildURI()); - ParseURL(); - return *this; -} -wxURL& wxURL::operator = (const wxString& url) -{ - wxURI::operator = (url); - Init(url); - ParseURL(); - return *this; -} - void wxURL::Init(const wxString& url) { m_protocol = NULL; @@ -90,7 +82,7 @@ void wxURL::Init(const wxString& url) m_nativeImp = CreateNativeImpObject(); #endif -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP if ( ms_useDefaultProxy && !ms_proxyDefault ) { SetDefaultProxy( wxGetenv(wxT("HTTP_PROXY")) ); @@ -104,9 +96,29 @@ void wxURL::Init(const wxString& url) m_useProxy = ms_proxyDefault != NULL; m_proxy = ms_proxyDefault; -#endif // wxUSE_SOCKETS +#endif // wxUSE_PROTOCOL_HTTP } + +// -------------------------------------------------------------- +// Assignment +// -------------------------------------------------------------- + +wxURL& wxURL::operator = (const wxURI& url) +{ + wxURI::operator = (url); + Init(url.BuildURI()); + ParseURL(); + return *this; +} +wxURL& wxURL::operator = (const wxString& url) +{ + wxURI::operator = (url); + Init(url); + ParseURL(); + return *this; +} + // -------------------------------------------------------------- // ParseURL // @@ -147,7 +159,7 @@ bool wxURL::ParseURL() } } -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP if (m_useProxy) { // destroy the previously created protocol as we'll be using m_proxy @@ -161,32 +173,39 @@ bool wxURL::ParseURL() // We initialize specific variables. m_protocol = m_proxy; // FIXME: we should clone the protocol } -#endif +#endif // wxUSE_PROTOCOL_HTTP m_error = wxURL_NOERR; return true; } +// -------------------------------------------------------------- +// Destruction/Cleanup +// -------------------------------------------------------------- + void wxURL::CleanData() { -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP if (!m_useProxy) -#endif +#endif // wxUSE_PROTOCOL_HTTP delete m_protocol; } wxURL::~wxURL() { CleanData(); -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP if (m_proxy && m_proxy != ms_proxyDefault) delete m_proxy; -#endif +#endif // wxUSE_PROTOCOL_HTTP #if wxUSE_URL_NATIVE delete m_nativeImp; #endif } +// -------------------------------------------------------------- +// FetchProtocol +// -------------------------------------------------------------- bool wxURL::FetchProtocol() { @@ -208,7 +227,7 @@ bool wxURL::FetchProtocol() } // -------------------------------------------------------------- -// --------- wxURL get ------------------------------------------ +// GetInputStream // -------------------------------------------------------------- wxInputStream *wxURL::GetInputStream() @@ -269,9 +288,24 @@ wxInputStream *wxURL::GetInputStream() #endif // When we use a proxy, we have to pass the whole URL to it. - wxInputStream *the_i_stream = - (m_useProxy) ? m_protocol->GetInputStream(m_url) : - m_protocol->GetInputStream(m_path); + wxInputStream *the_i_stream; + + if (!m_useProxy) + { + the_i_stream = m_protocol->GetInputStream(m_url); + } + else + { + wxString fullPath = m_path; + + if (HasQuery()) + fullPath += wxT("?") + m_query; + + if (HasFragment()) + fullPath += wxT("#") + m_fragment; + + the_i_stream = m_protocol->GetInputStream(fullPath); + } if (!the_i_stream) { @@ -282,7 +316,7 @@ wxInputStream *wxURL::GetInputStream() return the_i_stream; } -#if wxUSE_SOCKETS +#if wxUSE_PROTOCOL_HTTP void wxURL::SetDefaultProxy(const wxString& url_proxy) { if ( !url_proxy ) @@ -362,9 +396,11 @@ void wxURL::SetProxy(const wxString& url_proxy) ParseURL(); } } -#endif // wxUSE_SOCKETS +#endif // wxUSE_PROTOCOL_HTTP // ---------------------------------------------------------------------- +// wxURLModule +// // A module which deletes the default proxy if we created it // ---------------------------------------------------------------------- @@ -384,6 +420,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxURLModule, wxModule) bool wxURLModule::OnInit() { +#if wxUSE_PROTOCOL_HTTP // env var HTTP_PROXY contains the address of the default proxy to use if // set, but don't try to create this proxy right now because it will slow // down the program startup (especially if there is no DNS server @@ -393,14 +430,16 @@ bool wxURLModule::OnInit() { wxURL::ms_useDefaultProxy = true; } - +#endif // wxUSE_PROTOCOL_HTTP return true; } void wxURLModule::OnExit() { +#if wxUSE_PROTOCOL_HTTP delete wxURL::ms_proxyDefault; wxURL::ms_proxyDefault = NULL; +#endif // wxUSE_PROTOCOL_HTTP } #endif // wxUSE_SOCKETS