Bug 559408: Turn arena pool macros into methods. (r=gal)
[mozilla-central.git] / caps / src / nsNullPrincipalURI.cpp
blob8dcfcf7e9bef9dfb9bd147a35535f09f109c2419
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
14 * License.
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.
23 * Contributor(s):
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"
42 #include "nsEscape.h"
43 #include "nsCRT.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!");
60 ToLowerCase(mScheme);
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);
73 else
74 NS_INTERFACE_MAP_ENTRY(nsIURI)
75 NS_INTERFACE_MAP_END
77 ////////////////////////////////////////////////////////////////////////////////
78 //// nsIURI
80 NS_IMETHODIMP
81 nsNullPrincipalURI::GetAsciiHost(nsACString &_host)
83 _host.Truncate();
84 return NS_OK;
87 NS_IMETHODIMP
88 nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec)
90 nsCAutoString buffer;
91 (void)GetSpec(buffer);
92 NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec);
93 return NS_OK;
96 NS_IMETHODIMP
97 nsNullPrincipalURI::GetHost(nsACString &_host)
99 _host.Truncate();
100 return NS_OK;
103 NS_IMETHODIMP
104 nsNullPrincipalURI::SetHost(const nsACString &aHost)
106 return NS_ERROR_NOT_IMPLEMENTED;
109 NS_IMETHODIMP
110 nsNullPrincipalURI::GetHostPort(nsACString &_host)
112 return NS_ERROR_NOT_IMPLEMENTED;
115 NS_IMETHODIMP
116 nsNullPrincipalURI::SetHostPort(const nsACString &aHost)
118 return NS_ERROR_NOT_IMPLEMENTED;
121 NS_IMETHODIMP
122 nsNullPrincipalURI::GetOriginCharset(nsACString &_charset)
124 _charset.Truncate();
125 return NS_OK;
128 NS_IMETHODIMP
129 nsNullPrincipalURI::GetPassword(nsACString &_password)
131 return NS_ERROR_NOT_IMPLEMENTED;
134 NS_IMETHODIMP
135 nsNullPrincipalURI::SetPassword(const nsACString &aPassword)
137 return NS_ERROR_NOT_IMPLEMENTED;
140 NS_IMETHODIMP
141 nsNullPrincipalURI::GetPath(nsACString &_path)
143 _path = mPath;
144 return NS_OK;
147 NS_IMETHODIMP
148 nsNullPrincipalURI::SetPath(const nsACString &aPath)
150 return NS_ERROR_NOT_IMPLEMENTED;
153 NS_IMETHODIMP
154 nsNullPrincipalURI::GetPrePath(nsACString &_prePath)
156 _prePath = mScheme + NS_LITERAL_CSTRING(":");
157 return NS_OK;
160 NS_IMETHODIMP
161 nsNullPrincipalURI::GetPort(PRInt32 *_port)
163 return NS_ERROR_NOT_IMPLEMENTED;
166 NS_IMETHODIMP
167 nsNullPrincipalURI::SetPort(PRInt32 aPort)
169 return NS_ERROR_NOT_IMPLEMENTED;
172 NS_IMETHODIMP
173 nsNullPrincipalURI::GetScheme(nsACString &_scheme)
175 _scheme = mScheme;
176 return NS_OK;
179 NS_IMETHODIMP
180 nsNullPrincipalURI::SetScheme(const nsACString &aScheme)
182 return NS_ERROR_NOT_IMPLEMENTED;
185 NS_IMETHODIMP
186 nsNullPrincipalURI::GetSpec(nsACString &_spec)
188 _spec = mScheme + NS_LITERAL_CSTRING(":") + mPath;
189 return NS_OK;
192 NS_IMETHODIMP
193 nsNullPrincipalURI::SetSpec(const nsACString &aSpec)
195 return NS_ERROR_NOT_IMPLEMENTED;
198 NS_IMETHODIMP
199 nsNullPrincipalURI::GetUsername(nsACString &_username)
201 return NS_ERROR_NOT_IMPLEMENTED;
204 NS_IMETHODIMP
205 nsNullPrincipalURI::SetUsername(const nsACString &aUsername)
207 return NS_ERROR_NOT_IMPLEMENTED;
210 NS_IMETHODIMP
211 nsNullPrincipalURI::GetUserPass(nsACString &_userPass)
213 return NS_ERROR_NOT_IMPLEMENTED;
216 NS_IMETHODIMP
217 nsNullPrincipalURI::SetUserPass(const nsACString &aUserPass)
219 return NS_ERROR_NOT_IMPLEMENTED;
222 NS_IMETHODIMP
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);
228 uri.forget(_newURI);
229 return NS_OK;
232 NS_IMETHODIMP
233 nsNullPrincipalURI::Equals(nsIURI *aOther, PRBool *_equals)
235 *_equals = PR_FALSE;
236 nsNullPrincipalURI *otherURI;
237 nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID,
238 (void **)&otherURI);
239 if (NS_SUCCEEDED(rv)) {
240 *_equals = (mScheme == otherURI->mScheme && mPath == otherURI->mPath);
241 NS_RELEASE(otherURI);
243 return NS_OK;
246 NS_IMETHODIMP
247 nsNullPrincipalURI::Resolve(const nsACString &aRelativePath,
248 nsACString &_resolvedURI)
250 _resolvedURI = aRelativePath;
251 return NS_OK;
254 NS_IMETHODIMP
255 nsNullPrincipalURI::SchemeIs(const char *aScheme, PRBool *_schemeIs)
257 *_schemeIs = (0 == nsCRT::strcasecmp(mScheme.get(), aScheme));
258 return NS_OK;