Back to index

lightning-sunbird  0.9+nobinonly
nsDateTimeHandler.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nspr.h"
00039 #include "nsDateTimeChannel.h"
00040 #include "nsDateTimeHandler.h"
00041 #include "nsIURL.h"
00042 #include "nsCRT.h"
00043 #include "nsIComponentManager.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsIInterfaceRequestor.h"
00046 #include "nsIInterfaceRequestorUtils.h"
00047 #include "nsIProgressEventSink.h"
00048 #include "nsNetCID.h"
00049 
00050 static NS_DEFINE_CID(kSimpleURICID,            NS_SIMPLEURI_CID);
00051 
00053 
00054 nsDateTimeHandler::nsDateTimeHandler() {
00055 }
00056 
00057 nsDateTimeHandler::~nsDateTimeHandler() {
00058 }
00059 
00060 NS_IMPL_ISUPPORTS2(nsDateTimeHandler,
00061                    nsIProtocolHandler,
00062                    nsIProxiedProtocolHandler)
00063 
00064 NS_METHOD
00065 nsDateTimeHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
00066 
00067     nsDateTimeHandler* ph = new nsDateTimeHandler();
00068     if (ph == nsnull)
00069         return NS_ERROR_OUT_OF_MEMORY;
00070     NS_ADDREF(ph);
00071     nsresult rv = ph->QueryInterface(aIID, aResult);
00072     NS_RELEASE(ph);
00073     return rv;
00074 }
00075     
00077 // nsIProtocolHandler methods:
00078 
00079 NS_IMETHODIMP
00080 nsDateTimeHandler::GetScheme(nsACString &result) {
00081     result = "datetime";
00082     return NS_OK;
00083 }
00084 
00085 NS_IMETHODIMP
00086 nsDateTimeHandler::GetDefaultPort(PRInt32 *result) {
00087     *result = DATETIME_PORT;
00088     return NS_OK;
00089 }
00090 
00091 NS_IMETHODIMP
00092 nsDateTimeHandler::GetProtocolFlags(PRUint32 *result) {
00093     *result = URI_NORELATIVE | URI_NOAUTH | ALLOWS_PROXY;
00094     return NS_OK;
00095 }
00096 
00097 NS_IMETHODIMP
00098 nsDateTimeHandler::NewURI(const nsACString &aSpec,
00099                           const char *aCharset, // ignore charset info
00100                           nsIURI *aBaseURI,
00101                           nsIURI **result) {
00102     nsresult rv;
00103 
00104     nsIURI* url;
00105     rv = CallCreateInstance(kSimpleURICID, &url);
00106     if (NS_FAILED(rv)) return rv;
00107 
00108     rv = url->SetSpec(aSpec);
00109     if (NS_FAILED(rv)) {
00110         NS_RELEASE(url);
00111         return rv;
00112     }
00113 
00114     *result = url;
00115     return rv;
00116 }
00117 
00118 NS_IMETHODIMP
00119 nsDateTimeHandler::NewChannel(nsIURI* url, nsIChannel* *result)
00120 {
00121     return NewProxiedChannel(url, nsnull, result);
00122 }
00123 
00124 NS_IMETHODIMP
00125 nsDateTimeHandler::NewProxiedChannel(nsIURI* url, nsIProxyInfo* proxyInfo,
00126                                      nsIChannel* *result)
00127 {
00128     NS_ENSURE_ARG_POINTER(url);
00129     nsresult rv;
00130     
00131     nsDateTimeChannel *chan = new nsDateTimeChannel();
00132     if (!chan)
00133         return NS_ERROR_OUT_OF_MEMORY;
00134     NS_ADDREF(chan);
00135 
00136     rv = chan->Init(url, proxyInfo);
00137     if (NS_FAILED(rv)) {
00138         NS_RELEASE(chan);
00139         return rv;
00140     }
00141 
00142     *result = chan;
00143     return NS_OK;
00144 }
00145 
00146 
00147 NS_IMETHODIMP 
00148 nsDateTimeHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
00149 {
00150     if (port == DATETIME_PORT)
00151         *_retval = PR_TRUE;
00152     else
00153         *_retval = PR_FALSE;
00154     return NS_OK;
00155 }