rename wxURI::GetUser to wxURI::GetUserInfo and add wxURI::GetUser and wxURI::GetPassword

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32492 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton 2005-02-28 20:01:44 +00:00
parent b9d6a5f3d8
commit 4860d40db4
4 changed files with 88 additions and 32 deletions

View File

@ -45,7 +45,7 @@ To obtain individual components you can use
one of the following methods
\helpref{GetScheme}{wxurigetscheme}\\
\helpref{GetUser}{wxurigetuser}\\
\helpref{GetUserInfo}{wxurigetuserinfo}\\
\helpref{GetServer}{wxurigetserver}\\
\helpref{GetPort}{wxurigetserver}\\
\helpref{GetPath}{wxurigetpath}\\
@ -60,7 +60,7 @@ Consider an undefined component equivilent to a
NULL C string.\\
\\
\helpref{HasScheme}{wxurihasscheme}\\
\helpref{HasUser}{wxurihasuser}\\
\helpref{HasUserInfo}{wxurihasuserinfo}\\
\helpref{HasServer}{wxurihasserver}\\
\helpref{HasPort}{wxurihasserver}\\
\helpref{HasPath}{wxurihaspath}\\
@ -156,6 +156,18 @@ wxURI::HostType:
\twocolitem{{\bf wxURI\_IPVFUTURE}}{Server is an IP address, but not versions 4 or 6}
\end{twocollist}
\membersection{wxURI::GetPassword}\label{wxurigetpassword}
\constfunc{const wxString&}{GetPassword}{\void}
Returns the password part of the userinfo component of
this URI. Note that this is explicitly depreciated by
RFC 1396 and should generally be avoided if possible.
\tt{http://<user>:<password>@mysite.com/mypath}
\membersection{wxURI::GetPath}\label{wxurigetpath}
\constfunc{const wxString&}{GetPath}{\void}
@ -229,12 +241,24 @@ server component.
\constfunc{const wxString&}{GetUser}{\void}
Returns the User component of the URI.
Returns the username part of the userinfo component of
this URI. Note that this is explicitly depreciated by
RFC 1396 and should generally be avoided if possible.
\tt{http://<user>:<password>@mysite.com/mypath}
\membersection{wxURI::GetUserInfo}\label{wxurigetuserinfo}
\constfunc{const wxString&}{GetUserInfo}{\void}
Returns the UserInfo component of the URI.
The component of a URI before the server component
that is postfixed by a '@' character.
\tt{http://<user>@mysite.com/mypath}
\tt{http://<userinfo>@mysite.com/mypath}
\membersection{wxURI::HasFragment}\label{wxurihasfragment}
@ -242,12 +266,14 @@ that is postfixed by a '@' character.
Returns \true if the Fragment component of the URI exists.
\membersection{wxURI::HasPath}\label{wxurihaspath}
\constfunc{bool}{HasPath}{\void}
Returns \true if the Path component of the URI exists.
\membersection{wxURI::HasPort}\label{wxurihasport}
\constfunc{bool}{HasPort}{\void}

View File

@ -32,7 +32,7 @@ enum wxURIHostType
enum wxURIFieldType
{
wxURI_SCHEME = 1,
wxURI_USER = 2,
wxURI_USERINFO = 2,
wxURI_SERVER = 4,
wxURI_PORT = 8,
wxURI_PATH = 16,
@ -64,7 +64,7 @@ public:
const wxChar* Create(const wxString& uri);
bool HasScheme() const { return (m_fields & wxURI_SCHEME) == wxURI_SCHEME; }
bool HasUser() const { return (m_fields & wxURI_USER) == wxURI_USER; }
bool HasUserInfo() const { return (m_fields & wxURI_USERINFO) == wxURI_USERINFO; }
bool HasServer() const { return (m_fields & wxURI_SERVER) == wxURI_SERVER; }
bool HasPort() const { return (m_fields & wxURI_PORT) == wxURI_PORT; }
bool HasPath() const { return (m_fields & wxURI_PATH) == wxURI_PATH; }
@ -76,10 +76,14 @@ public:
const wxString& GetQuery() const { return m_query; }
const wxString& GetFragment() const { return m_fragment; }
const wxString& GetPort() const { return m_port; }
const wxString& GetUser() const { return m_user; }
const wxString& GetUserInfo() const { return m_userinfo; }
const wxString& GetServer() const { return m_server; }
const wxURIHostType& GetHostType() const { return m_hostType; }
//Note that the following two get functions are explicitly depreciated by RFC 2396
wxString GetUser() const;
wxString GetPassword() const;
wxString BuildURI() const;
wxString BuildUnescapedURI() const;
@ -100,7 +104,7 @@ protected:
const wxChar* Parse (const wxChar* uri);
const wxChar* ParseAuthority (const wxChar* uri);
const wxChar* ParseScheme (const wxChar* uri);
const wxChar* ParseUser (const wxChar* uri);
const wxChar* ParseUserInfo (const wxChar* uri);
const wxChar* ParseServer (const wxChar* uri);
const wxChar* ParsePort (const wxChar* uri);
const wxChar* ParsePath (const wxChar* uri,
@ -137,7 +141,7 @@ protected:
wxString m_query;
wxString m_fragment;
wxString m_user;
wxString m_userinfo;
wxString m_server;
wxString m_port;

View File

@ -78,7 +78,7 @@ wxURI::~wxURI()
void wxURI::Clear()
{
m_scheme = m_user = m_server = m_port = m_path =
m_scheme = m_userinfo = m_server = m_port = m_path =
m_query = m_fragment = wxEmptyString;
m_hostType = wxURI_REGNAME;
@ -159,6 +159,32 @@ bool wxURI::IsEscape(const wxChar*& uri)
return false;
}
// ---------------------------------------------------------------------------
// GetUser
// GetPassword
//
// Gets the username and password via the old URL method.
// ---------------------------------------------------------------------------
wxString wxURI::GetUser() const
{
size_t dwPasswordPos = m_userinfo.find(':');
if (dwPasswordPos == wxString::npos)
dwPasswordPos = 0;
return m_userinfo(0, dwPasswordPos);
}
wxString wxURI::GetPassword() const
{
size_t dwPasswordPos = m_userinfo.find(':');
if (dwPasswordPos == wxString::npos)
return wxT("");
else
return m_userinfo(dwPasswordPos+1, m_userinfo.length() + 1);
}
// ---------------------------------------------------------------------------
// BuildURI
//
@ -180,8 +206,8 @@ wxString wxURI::BuildURI() const
{
ret += wxT("//");
if (HasUser())
ret = ret + m_user + wxT("@");
if (HasUserInfo())
ret = ret + m_userinfo + wxT("@");
ret += m_server;
@ -211,8 +237,8 @@ wxString wxURI::BuildUnescapedURI() const
{
ret += wxT("//");
if (HasUser())
ret = ret + wxURI::Unescape(m_user) + wxT("@");
if (HasUserInfo())
ret = ret + wxURI::Unescape(m_userinfo) + wxT("@");
if (m_hostType == wxURI_REGNAME)
ret += wxURI::Unescape(m_server);
@ -245,7 +271,7 @@ wxURI& wxURI::Assign(const wxURI& uri)
//ref over components
m_scheme = uri.m_scheme;
m_user = uri.m_user;
m_userinfo = uri.m_userinfo;
m_server = uri.m_server;
m_hostType = uri.m_hostType;
m_port = uri.m_port;
@ -284,12 +310,12 @@ bool wxURI::operator == (const wxURI& uri) const
if (HasServer())
{
if (HasUser())
if (HasUserInfo())
{
if (m_user != uri.m_user)
if (m_userinfo != uri.m_userinfo)
return false;
}
else if (uri.HasUser())
else if (uri.HasUserInfo())
return false;
if (m_server != uri.m_server ||
@ -416,7 +442,7 @@ const wxChar* wxURI::ParseAuthority(const wxChar* uri)
{
uri += 2;
uri = ParseUser(uri);
uri = ParseUserInfo(uri);
uri = ParseServer(uri);
return ParsePort(uri);
}
@ -424,7 +450,7 @@ const wxChar* wxURI::ParseAuthority(const wxChar* uri)
return uri;
}
const wxChar* wxURI::ParseUser(const wxChar* uri)
const wxChar* wxURI::ParseUserInfo(const wxChar* uri)
{
wxASSERT(uri != NULL);
@ -437,20 +463,20 @@ const wxChar* wxURI::ParseUser(const wxChar* uri)
{
if(IsUnreserved(*uri) || IsEscape(uri) ||
IsSubDelim(*uri) || *uri == wxT(':'))
m_user += *uri++;
m_userinfo += *uri++;
else
Escape(m_user, *uri++);
Escape(m_userinfo, *uri++);
}
if(*uri == wxT('@'))
{
//valid userinfo
m_fields |= wxURI_USER;
m_fields |= wxURI_USERINFO;
uricopy = ++uri;
}
else
m_user = wxEmptyString;
m_userinfo = wxEmptyString;
return uricopy;
}
@ -755,10 +781,10 @@ void wxURI::Resolve(const wxURI& base, int flags)
}
//No authority - inherit
if (base.HasUser())
if (base.HasUserInfo())
{
m_user = base.m_user;
m_fields |= wxURI_USER;
m_userinfo = base.m_userinfo;
m_fields |= wxURI_USERINFO;
}
m_server = base.m_server;

View File

@ -239,16 +239,16 @@ wxInputStream *wxURL::GetInputStream()
}
m_error = wxURL_NOERR;
if (HasUser())
if (HasUserInfo())
{
size_t dwPasswordPos = m_user.find(':');
size_t dwPasswordPos = m_userinfo.find(':');
if (dwPasswordPos == wxString::npos)
m_protocol->SetUser(m_user);
m_protocol->SetUser(m_userinfo);
else
{
m_protocol->SetUser(m_user(0, dwPasswordPos));
m_protocol->SetPassword(m_user(dwPasswordPos+1, m_user.length() + 1));
m_protocol->SetUser(m_userinfo(0, dwPasswordPos));
m_protocol->SetPassword(m_userinfo(dwPasswordPos+1, m_userinfo.length() + 1));
}
}