Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / protocol / gopher / src / nsGopherHandler.cpp
blobf1d0c3292b8fb389b429d78186d60f28ba882ddb
2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is the Gopher protocol code.
19 * The Initial Developer of the Original Code is
20 * Bradley Baetz.
21 * Portions created by the Initial Developer are Copyright (C) 2000
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Bradley Baetz <bbaetz@student.usyd.edu.au>
26 * Darin Fisher <darin@meer.net>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include "nsGopherChannel.h"
43 #include "nsGopherHandler.h"
44 #include "nsIURL.h"
45 #include "nsIComponentManager.h"
46 #include "nsIServiceManager.h"
47 #include "nsIStandardURL.h"
48 #include "nsStandardURL.h"
50 //-----------------------------------------------------------------------------
52 NS_IMPL_THREADSAFE_ISUPPORTS2(nsGopherHandler,
53 nsIProxiedProtocolHandler,
54 nsIProtocolHandler)
56 //-----------------------------------------------------------------------------
58 NS_IMETHODIMP
59 nsGopherHandler::GetScheme(nsACString &result)
61 result.AssignLiteral("gopher");
62 return NS_OK;
65 NS_IMETHODIMP
66 nsGopherHandler::GetDefaultPort(PRInt32 *result)
68 *result = GOPHER_PORT;
69 return NS_OK;
72 NS_IMETHODIMP
73 nsGopherHandler::GetProtocolFlags(PRUint32 *result)
75 *result = URI_NORELATIVE | ALLOWS_PROXY | ALLOWS_PROXY_HTTP |
76 URI_LOADABLE_BY_ANYONE;
77 return NS_OK;
80 NS_IMETHODIMP
81 nsGopherHandler::NewURI(const nsACString &spec, const char *originCharset,
82 nsIURI *baseURI, nsIURI **result)
84 nsStandardURL *url = new nsStandardURL();
85 if (!url)
86 return NS_ERROR_OUT_OF_MEMORY;
87 NS_ADDREF(url);
89 nsresult rv = url->Init(nsIStandardURL::URLTYPE_STANDARD, GOPHER_PORT,
90 spec, originCharset, baseURI);
91 if (NS_FAILED(rv)) {
92 NS_RELEASE(url);
93 return rv;
96 *result = url; // no QI needed
97 return NS_OK;
100 NS_IMETHODIMP
101 nsGopherHandler::NewProxiedChannel(nsIURI *uri, nsIProxyInfo *proxyInfo,
102 nsIChannel **result)
104 NS_ENSURE_ARG_POINTER(uri);
105 nsGopherChannel *chan = new nsGopherChannel(uri, proxyInfo);
106 if (!chan)
107 return NS_ERROR_OUT_OF_MEMORY;
108 NS_ADDREF(chan);
110 nsresult rv = chan->Init();
111 if (NS_FAILED(rv)) {
112 NS_RELEASE(chan);
113 return rv;
116 *result = chan;
117 return NS_OK;
120 NS_IMETHODIMP
121 nsGopherHandler::NewChannel(nsIURI *uri, nsIChannel **result)
123 return NewProxiedChannel(uri, nsnull, result);
126 NS_IMETHODIMP
127 nsGopherHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *result)
129 *result = (port == GOPHER_PORT);
130 return NS_OK;