1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 sts=2 expandtab
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is the
19 * Mozilla Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
24 * Shawn Wilsher <me@shawnwilsher.com> (Original author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsNullPrincipalURI.h"
41 #include "nsNetUtil.h"
45 ////////////////////////////////////////////////////////////////////////////////
46 //// nsNullPrincipalURI
48 nsNullPrincipalURI::nsNullPrincipalURI(const nsCString
&aSpec
)
50 PRInt32 dividerPosition
= aSpec
.FindChar(':');
51 NS_ASSERTION(dividerPosition
!= -1, "Malformed URI!");
53 PRInt32 n
= aSpec
.Left(mScheme
, dividerPosition
);
54 NS_ASSERTION(n
== dividerPosition
, "Storing the scheme failed!");
56 PRInt32 count
= aSpec
.Length() - dividerPosition
- 1;
57 n
= aSpec
.Mid(mPath
, dividerPosition
+ 1, count
);
58 NS_ASSERTION(n
== count
, "Storing the path failed!");
63 static NS_DEFINE_CID(kNullPrincipalURIImplementationCID
,
64 NS_NULLPRINCIPALURI_IMPLEMENTATION_CID
);
66 NS_IMPL_THREADSAFE_ADDREF(nsNullPrincipalURI
)
67 NS_IMPL_THREADSAFE_RELEASE(nsNullPrincipalURI
)
69 NS_INTERFACE_MAP_BEGIN(nsNullPrincipalURI
)
70 NS_INTERFACE_MAP_ENTRY(nsISupports
)
71 if (aIID
.Equals(kNullPrincipalURIImplementationCID
))
72 foundInterface
= static_cast<nsIURI
*>(this);
74 NS_INTERFACE_MAP_ENTRY(nsIURI
)
77 ////////////////////////////////////////////////////////////////////////////////
81 nsNullPrincipalURI::GetAsciiHost(nsACString
&_host
)
88 nsNullPrincipalURI::GetAsciiSpec(nsACString
&_spec
)
91 (void)GetSpec(buffer
);
92 NS_EscapeURL(buffer
, esc_OnlyNonASCII
| esc_AlwaysCopy
, _spec
);
97 nsNullPrincipalURI::GetHost(nsACString
&_host
)
104 nsNullPrincipalURI::SetHost(const nsACString
&aHost
)
106 return NS_ERROR_NOT_IMPLEMENTED
;
110 nsNullPrincipalURI::GetHostPort(nsACString
&_host
)
112 return NS_ERROR_NOT_IMPLEMENTED
;
116 nsNullPrincipalURI::SetHostPort(const nsACString
&aHost
)
118 return NS_ERROR_NOT_IMPLEMENTED
;
122 nsNullPrincipalURI::GetOriginCharset(nsACString
&_charset
)
129 nsNullPrincipalURI::GetPassword(nsACString
&_password
)
131 return NS_ERROR_NOT_IMPLEMENTED
;
135 nsNullPrincipalURI::SetPassword(const nsACString
&aPassword
)
137 return NS_ERROR_NOT_IMPLEMENTED
;
141 nsNullPrincipalURI::GetPath(nsACString
&_path
)
148 nsNullPrincipalURI::SetPath(const nsACString
&aPath
)
150 return NS_ERROR_NOT_IMPLEMENTED
;
154 nsNullPrincipalURI::GetPrePath(nsACString
&_prePath
)
156 _prePath
= mScheme
+ NS_LITERAL_CSTRING(":");
161 nsNullPrincipalURI::GetPort(PRInt32
*_port
)
163 return NS_ERROR_NOT_IMPLEMENTED
;
167 nsNullPrincipalURI::SetPort(PRInt32 aPort
)
169 return NS_ERROR_NOT_IMPLEMENTED
;
173 nsNullPrincipalURI::GetScheme(nsACString
&_scheme
)
180 nsNullPrincipalURI::SetScheme(const nsACString
&aScheme
)
182 return NS_ERROR_NOT_IMPLEMENTED
;
186 nsNullPrincipalURI::GetSpec(nsACString
&_spec
)
188 _spec
= mScheme
+ NS_LITERAL_CSTRING(":") + mPath
;
193 nsNullPrincipalURI::SetSpec(const nsACString
&aSpec
)
195 return NS_ERROR_NOT_IMPLEMENTED
;
199 nsNullPrincipalURI::GetUsername(nsACString
&_username
)
201 return NS_ERROR_NOT_IMPLEMENTED
;
205 nsNullPrincipalURI::SetUsername(const nsACString
&aUsername
)
207 return NS_ERROR_NOT_IMPLEMENTED
;
211 nsNullPrincipalURI::GetUserPass(nsACString
&_userPass
)
213 return NS_ERROR_NOT_IMPLEMENTED
;
217 nsNullPrincipalURI::SetUserPass(const nsACString
&aUserPass
)
219 return NS_ERROR_NOT_IMPLEMENTED
;
223 nsNullPrincipalURI::Clone(nsIURI
**_newURI
)
225 nsCOMPtr
<nsIURI
> uri
=
226 new nsNullPrincipalURI(mScheme
+ NS_LITERAL_CSTRING(":") + mPath
);
227 NS_ENSURE_TRUE(uri
, NS_ERROR_OUT_OF_MEMORY
);
233 nsNullPrincipalURI::Equals(nsIURI
*aOther
, PRBool
*_equals
)
236 nsNullPrincipalURI
*otherURI
;
237 nsresult rv
= aOther
->QueryInterface(kNullPrincipalURIImplementationCID
,
239 if (NS_SUCCEEDED(rv
)) {
240 *_equals
= (mScheme
== otherURI
->mScheme
&& mPath
== otherURI
->mPath
);
241 NS_RELEASE(otherURI
);
247 nsNullPrincipalURI::Resolve(const nsACString
&aRelativePath
,
248 nsACString
&_resolvedURI
)
250 _resolvedURI
= aRelativePath
;
255 nsNullPrincipalURI::SchemeIs(const char *aScheme
, PRBool
*_schemeIs
)
257 *_schemeIs
= (0 == nsCRT::strcasecmp(mScheme
.get(), aScheme
));