Back to index

lightning-sunbird  0.9+nobinonly
DotNETNetworking.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Roy Yokoyama <yokoyama@netscape.com> (original author)
00024  *   Johnny Stenback <jst@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #using <mscorlib.dll>
00041 
00042 #include "nsISupports.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsIURI.h"
00045 #include "nsNetUtil.h"
00046 #include "DotNETNetworking.h"
00047 
00048 using namespace Mozilla::Embedding::Networking;
00049 
00050 URI::URI(nsIURI *aURI)
00051   : mURI(aURI)
00052 {
00053   NS_IF_ADDREF(mURI);
00054 }
00055 
00056 URI::URI(String *aSpec)
00057   : mURI(nsnull)
00058 {
00059   nsCAutoString spec;
00060   CopyString(aSpec, spec);
00061 
00062   nsCOMPtr<nsIURI> uri;
00063   nsresult rv = NS_NewURI(getter_AddRefs(uri), spec.get());
00064   ThrowIfFailed(rv);
00065 
00066   mURI = uri.get();
00067   NS_IF_ADDREF(mURI);
00068 }
00069 
00070 URI::~URI()
00071 {
00072   NS_IF_RELEASE(mURI);
00073 }
00074 
00075 Object *
00076 URI::Clone()
00077 {
00078   nsCOMPtr<nsIURI> uriClone;
00079 
00080   if (mURI) {
00081     nsresult rv = mURI->Clone(getter_AddRefs(uriClone));
00082     ThrowIfFailed(rv);
00083   }
00084 
00085   return new URI(uriClone);
00086 }
00087 
00088 void
00089 URI::Dispose()
00090 {
00091   NS_IF_RELEASE(mURI);
00092 
00093   GC::SuppressFinalize(this);
00094 }
00095 
00096 String *
00097 URI::get_Spec()
00098 {
00099   nsCAutoString spec;
00100   nsresult rv = mURI->GetSpec(spec);
00101   ThrowIfFailed(rv);
00102 
00103   return CopyString(spec);
00104 }
00105 
00106 void
00107 URI::set_Spec(String *aSpec)
00108 {
00109   nsCAutoString spec;
00110   CopyString(aSpec, spec);
00111 
00112   nsresult rv = mURI->SetSpec(spec);
00113   ThrowIfFailed(rv);
00114 }
00115 
00116 String *
00117 URI::get_PrePath()
00118 {
00119   nsCAutoString prePath;
00120   nsresult rv = mURI->GetPrePath(prePath);
00121   ThrowIfFailed(rv);
00122 
00123   return CopyString(prePath);
00124 }
00125 
00126 String *
00127 URI::get_Scheme()
00128 {
00129   nsCAutoString scheme;
00130   nsresult rv = mURI->GetScheme(scheme);
00131   ThrowIfFailed(rv);
00132 
00133   return CopyString(scheme);
00134 }
00135 
00136 void
00137 URI::set_Scheme(String *aScheme)
00138 {
00139   nsCAutoString scheme;
00140   CopyString(aScheme, scheme);
00141 
00142   nsresult rv = mURI->SetScheme(scheme);
00143   ThrowIfFailed(rv);
00144 }
00145 
00146 String *
00147 URI::get_UserPass()
00148 {
00149   nsCAutoString userPass;
00150   nsresult rv = mURI->GetUserPass(userPass);
00151   ThrowIfFailed(rv);
00152 
00153   return CopyString(userPass);
00154 }
00155 
00156 void
00157 URI::set_UserPass(String *aUserPass)
00158 {
00159   nsCAutoString userPass;
00160   CopyString(aUserPass, userPass);
00161 
00162   nsresult rv = mURI->SetUserPass(userPass);
00163   ThrowIfFailed(rv);
00164 }
00165 
00166 String *
00167 URI::get_Username()
00168 {
00169   nsCAutoString username;
00170   nsresult rv = mURI->GetUsername(username);
00171   ThrowIfFailed(rv);
00172 
00173   return CopyString(username);
00174 }
00175 
00176 void
00177 URI::set_Username(String *aUsername)
00178 {
00179   nsCAutoString username;
00180   CopyString(aUsername, username);
00181 
00182   nsresult rv = mURI->SetUsername(username);
00183   ThrowIfFailed(rv);
00184 }
00185 
00186 String *
00187 URI::get_Password()
00188 {
00189   nsCAutoString password;
00190   nsresult rv = mURI->GetPassword(password);
00191   ThrowIfFailed(rv);
00192 
00193   return CopyString(password);
00194 }
00195 
00196 void
00197 URI::set_Password(String *aPassword)
00198 {
00199   nsCAutoString password;
00200   CopyString(aPassword, password);
00201 
00202   nsresult rv = mURI->SetPassword(password);
00203   ThrowIfFailed(rv);
00204 }
00205 
00206 String *
00207 URI::get_HostPort()
00208 {
00209   nsCAutoString hostPort;
00210   nsresult rv = mURI->GetHostPort(hostPort);
00211   ThrowIfFailed(rv);
00212 
00213   return CopyString(hostPort);
00214 }
00215 
00216 void
00217 URI::set_HostPort(String *aHostPort)
00218 {
00219   nsCAutoString hostPort;
00220   CopyString(aHostPort, hostPort);
00221 
00222   nsresult rv = mURI->SetHostPort(hostPort);
00223   ThrowIfFailed(rv);
00224 }
00225 
00226 String *
00227 URI::get_Host()
00228 {
00229   nsCAutoString host;
00230   nsresult rv = mURI->GetHost(host);
00231   ThrowIfFailed(rv);
00232 
00233   return CopyString(host);
00234 }
00235 
00236 void
00237 URI::set_Host(String *aHost)
00238 {
00239   nsCAutoString host;
00240   CopyString(aHost, host);
00241 
00242   nsresult rv = mURI->SetHost(host);
00243   ThrowIfFailed(rv);
00244 }
00245 
00246 Int32
00247 URI::get_Port()
00248 {
00249   PRInt32 port;
00250   nsresult rv = mURI->GetPort(&port);
00251   ThrowIfFailed(rv);
00252 
00253   return port;
00254 }
00255 
00256 void
00257 URI::set_Port(Int32 aPort)
00258 {
00259   nsresult rv = mURI->SetPort(aPort);
00260   ThrowIfFailed(rv);
00261 }
00262 
00263 String *
00264 URI::get_Path()
00265 {
00266   nsCAutoString path;
00267   nsresult rv = mURI->GetPath(path);
00268   ThrowIfFailed(rv);
00269 
00270   return CopyString(path);
00271 }
00272 
00273 void
00274 URI::set_Path(String *aPath)
00275 {
00276   nsCAutoString path;
00277   CopyString(aPath, path);
00278 
00279   nsresult rv = mURI->SetPath(path);
00280   ThrowIfFailed(rv);
00281 }
00282 
00283 bool
00284 URI::Equals(URI *aOther)
00285 {
00286   if (!mURI) {
00287     if (!aOther || !aOther->mURI) {
00288       return true;
00289     }
00290 
00291     return false;
00292   }
00293 
00294   PRBool equals;
00295   nsresult rv = mURI->Equals(aOther->mURI, &equals);
00296   ThrowIfFailed(rv);
00297 
00298   return equals;
00299 }
00300 
00301 bool
00302 URI::SchemeIs(String *aScheme)
00303 {
00304   nsCAutoString scheme;
00305   CopyString(aScheme, scheme);
00306 
00307   PRBool isScheme = PR_FALSE;
00308 
00309   nsresult rv = mURI->SchemeIs(scheme.get(), &isScheme);
00310   ThrowIfFailed(rv);
00311 
00312   return isScheme;
00313 }
00314 
00315 String *
00316 URI::Resolve(String *aRelativePath)
00317 {
00318   nsCAutoString relativePath, resolvedPath;
00319   CopyString(aRelativePath, relativePath);
00320 
00321   nsresult rv = mURI->Resolve(relativePath, resolvedPath);
00322   ThrowIfFailed(rv);
00323 
00324   return CopyString(resolvedPath);
00325 }
00326 
00327 String *
00328 URI::get_AsciiSpec()
00329 {
00330   nsCAutoString asciiSpec;
00331   nsresult rv = mURI->GetAsciiSpec(asciiSpec);
00332   ThrowIfFailed(rv);
00333 
00334   return CopyString(asciiSpec);
00335 }
00336 
00337 String *
00338 URI::get_AsciiHost()
00339 {
00340   nsCAutoString asciiHost;
00341   nsresult rv = mURI->GetAsciiHost(asciiHost);
00342   ThrowIfFailed(rv);
00343 
00344   return CopyString(asciiHost);
00345 }
00346 
00347 String *
00348 URI::get_OriginCharset()
00349 {
00350   nsCAutoString originalCharset;
00351   nsresult rv = mURI->GetOriginCharset(originalCharset);
00352   ThrowIfFailed(rv);
00353 
00354   return CopyString(originalCharset);
00355 }