X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/283965f0b33d0a7ea025afcc5a87fb162d3ea0a2..49746f2306b6eb7ef1c53e63287b3de237ad719e:/src/common/url.cpp diff --git a/src/common/url.cpp b/src/common/url.cpp index 7302b06585..15b9311839 100644 --- a/src/common/url.cpp +++ b/src/common/url.cpp @@ -30,7 +30,6 @@ #include #include -IMPLEMENT_CLASS(wxProtoInfo, wxObject) IMPLEMENT_CLASS(wxURL, wxURI) // Protocols list @@ -66,9 +65,15 @@ wxURL::wxURL(const wxString& url) : wxURI(url) ParseURL(); } -wxURL::wxURL(const wxURI& url) : wxURI(url) +wxURL::wxURL(const wxURI& uri) : wxURI(uri) { - Init(url.BuildURI()); + Init(uri.BuildURI()); + ParseURL(); +} + +wxURL::wxURL(const wxURL& url) : wxURI(url) +{ + Init(url.GetURL()); ParseURL(); } @@ -103,18 +108,39 @@ void wxURL::Init(const wxString& url) // Assignment // -------------------------------------------------------------- -wxURL& wxURL::operator = (const wxURI& url) +wxURL& wxURL::operator = (const wxString& url) { wxURI::operator = (url); - Init(url.BuildURI()); + Free(); + Init(url); ParseURL(); + return *this; } -wxURL& wxURL::operator = (const wxString& url) + +wxURL& wxURL::operator = (const wxURI& uri) { - wxURI::operator = (url); - Init(url); - ParseURL(); + if (&uri != this) + { + wxURI::operator = (uri); + Free(); + Init(uri.BuildURI()); + ParseURL(); + } + + return *this; +} + +wxURL& wxURL::operator = (const wxURL& url) +{ + if (&url != this) + { + wxURI::operator = (url); + Free(); + Init(url.GetURL()); + ParseURL(); + } + return *this; } @@ -167,6 +193,8 @@ bool wxURL::ParseURL() m_url = m_url + wxT("//") + m_server; // We initialize specific variables. + if (m_protocol) + m_protocol->Destroy(); m_protocol = m_proxy; // FIXME: we should clone the protocol } #endif // wxUSE_PROTOCOL_HTTP @@ -184,12 +212,17 @@ void wxURL::CleanData() #if wxUSE_PROTOCOL_HTTP if (!m_useProxy) #endif // wxUSE_PROTOCOL_HTTP + { if (m_protocol) + { // Need to safely delete the socket (pending events) m_protocol->Destroy(); + m_protocol = NULL; + } + } } -wxURL::~wxURL() +void wxURL::Free() { CleanData(); #if wxUSE_PROTOCOL_HTTP @@ -201,6 +234,11 @@ wxURL::~wxURL() #endif } +wxURL::~wxURL() +{ + Free(); +} + // -------------------------------------------------------------- // FetchProtocol // -------------------------------------------------------------- @@ -213,7 +251,7 @@ bool wxURL::FetchProtocol() { if (m_scheme == info->m_protoname) { - if (m_port.IsNull()) + if ( m_port.empty() ) m_port = info->m_servname; m_protoinfo = info; m_protocol = (wxProtocol *)m_protoinfo->m_cinfo->CreateObject(); @@ -327,8 +365,7 @@ void wxURL::SetDefaultProxy(const wxString& url_proxy) if ( ms_proxyDefault ) { ms_proxyDefault->Close(); - delete ms_proxyDefault; - ms_proxyDefault = NULL; + wxDELETE(ms_proxyDefault); } } else @@ -427,7 +464,7 @@ wxURLModule::wxURLModule() { // we must be cleaned up before wxSocketModule as otherwise deleting // ms_proxyDefault from our OnExit() won't work (and can actually crash) - AddDependency(wxClassInfo::FindClass(_T("wxSocketModule"))); + AddDependency(wxClassInfo::FindClass(wxT("wxSocketModule"))); } bool wxURLModule::OnInit() @@ -438,7 +475,7 @@ bool wxURLModule::OnInit() // down the program startup (especially if there is no DNS server // available, in which case it may take up to 1 minute) - if ( wxGetenv(_T("HTTP_PROXY")) ) + if ( wxGetenv(wxT("HTTP_PROXY")) ) { wxURL::ms_useDefaultProxy = true; } @@ -449,8 +486,7 @@ bool wxURLModule::OnInit() void wxURLModule::OnExit() { #if wxUSE_PROTOCOL_HTTP - delete wxURL::ms_proxyDefault; - wxURL::ms_proxyDefault = NULL; + wxDELETE(wxURL::ms_proxyDefault); #endif // wxUSE_PROTOCOL_HTTP }