Back to index

lightning-sunbird  0.9+nobinonly
nsFingerHandler.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Brian Ryner.
00020  * Portions created by the Initial Developer are Copyright (C) 2000
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Brian Ryner <bryner@brianryner.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 #include "nspr.h"
00041 #include "nsFingerChannel.h"
00042 #include "nsFingerHandler.h"
00043 #include "nsIURL.h"
00044 #include "nsCRT.h"
00045 #include "nsIComponentManager.h"
00046 #include "nsIServiceManager.h"
00047 #include "nsIInterfaceRequestor.h"
00048 #include "nsIInterfaceRequestorUtils.h"
00049 #include "nsIProgressEventSink.h"
00050 #include "nsNetCID.h"
00051 
00052 static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
00053 
00055 
00056 nsFingerHandler::nsFingerHandler() {
00057 }
00058 
00059 nsFingerHandler::~nsFingerHandler() {
00060 }
00061 
00062 NS_IMPL_ISUPPORTS2(nsFingerHandler,
00063                    nsIProtocolHandler,
00064                    nsIProxiedProtocolHandler)
00065 
00066 NS_METHOD
00067 nsFingerHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
00068 
00069     nsFingerHandler* ph = new nsFingerHandler();
00070     if (ph == nsnull)
00071         return NS_ERROR_OUT_OF_MEMORY;
00072     NS_ADDREF(ph);
00073     nsresult rv = ph->QueryInterface(aIID, aResult);
00074     NS_RELEASE(ph);
00075     return rv;
00076 }
00077     
00079 // nsIProtocolHandler methods:
00080 
00081 NS_IMETHODIMP
00082 nsFingerHandler::GetScheme(nsACString &result) {
00083     result = "finger";
00084     return NS_OK;
00085 }
00086 
00087 NS_IMETHODIMP
00088 nsFingerHandler::GetDefaultPort(PRInt32 *result) {
00089     *result = FINGER_PORT;
00090     return NS_OK;
00091 }
00092 
00093 NS_IMETHODIMP
00094 nsFingerHandler::GetProtocolFlags(PRUint32 *result) {
00095     *result = URI_NORELATIVE | URI_NOAUTH | ALLOWS_PROXY;
00096     return NS_OK;
00097 }
00098 
00099 NS_IMETHODIMP
00100 nsFingerHandler::NewURI(const nsACString &aSpec,
00101                         const char *aCharset, // ignore charset info
00102                         nsIURI *aBaseURI,
00103                         nsIURI **result) {
00104     nsresult rv;
00105 
00106     nsIURI* url;
00107     rv = CallCreateInstance(kSimpleURICID, &url);
00108     if (NS_FAILED(rv)) return rv;
00109 
00110     rv = url->SetSpec(aSpec);
00111     if (NS_FAILED(rv)) {
00112         NS_RELEASE(url);
00113         return rv;
00114     }
00115 
00116     *result = url;
00117     return rv;
00118 }
00119 
00120 NS_IMETHODIMP
00121 nsFingerHandler::NewChannel(nsIURI* url, nsIChannel* *result)
00122 {
00123     return NewProxiedChannel(url, nsnull, result);
00124 }
00125 
00126 NS_IMETHODIMP
00127 nsFingerHandler::NewProxiedChannel(nsIURI* url, nsIProxyInfo* proxyInfo,
00128                                    nsIChannel* *result)
00129 {
00130     NS_ENSURE_ARG_POINTER(url);
00131     nsresult rv;
00132     
00133     nsFingerChannel *chan = new nsFingerChannel();
00134     if (!chan)
00135         return NS_ERROR_OUT_OF_MEMORY;
00136     NS_ADDREF(chan);
00137 
00138     rv = chan->Init(url, proxyInfo);
00139     if (NS_FAILED(rv)) {
00140         NS_RELEASE(chan);
00141         return rv;
00142     }
00143 
00144     *result = chan;
00145     return NS_OK;
00146 }
00147 
00148 NS_IMETHODIMP 
00149 nsFingerHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
00150 {
00151     if (port == FINGER_PORT)
00152         *_retval = PR_TRUE;
00153     else
00154         *_retval = PR_FALSE;
00155     return NS_OK;
00156 }