transport: pass correct channel
[abstract.git] / transport / sqlite / src / aaSqliteProtocolHandler.cpp
blobc46d88422997db06aa37c10d4b95a49d5ba8936d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2008-2010 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "aaSqliteProtocolHandler.h"
24 #include "nsStringAPI.h"
25 #include "nsCOMPtr.h"
26 #include "nsAutoPtr.h"
27 #include "nsIURI.h"
28 #include "nsIStandardURL.h"
29 #include "nsIScriptSecurityManager.h"
30 #include "nsNetCID.h"
31 #include "nsComponentManagerUtils.h"
32 #include "nsServiceManagerUtils.h"
34 #include "aaSqlitePump.h"
35 #include "aaSqliteChannel.h"
37 NS_IMPL_ISUPPORTS1(aaSqliteProtocolHandler, nsIProtocolHandler)
39 /* readonly attribute ACString scheme; */
40 NS_IMETHODIMP
41 aaSqliteProtocolHandler::GetScheme(nsACString & aScheme)
43 aScheme.AssignLiteral(AA_SQLITE_PROTOCOL);
44 return NS_OK;
47 /* readonly attribute long defaultPort; */
48 NS_IMETHODIMP
49 aaSqliteProtocolHandler::GetDefaultPort(PRInt32 *aDefaultPort)
51 NS_ENSURE_ARG_POINTER(aDefaultPort);
52 *aDefaultPort = -1;
53 return NS_OK;
56 /* readonly attribute unsigned long protocolFlags; */
57 NS_IMETHODIMP
58 aaSqliteProtocolHandler::GetProtocolFlags(PRUint32 *aProtocolFlags)
60 NS_ENSURE_ARG_POINTER(aProtocolFlags);
61 *aProtocolFlags = URI_STD | URI_IS_LOCAL_FILE;
62 return NS_OK;
65 /* nsIURI newURI (in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI); */
66 NS_IMETHODIMP
67 aaSqliteProtocolHandler::NewURI(const nsACString & aSpec,
68 const char *aOriginCharset, nsIURI *aBaseURI, nsIURI **_retval NS_OUTPARAM)
70 NS_ENSURE_ARG(!aSpec.IsEmpty());
71 NS_ENSURE_ARG_POINTER(_retval);
72 nsresult rv = NS_OK;
74 nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
75 NS_ENSURE_SUCCESS(rv, rv);
77 nsCOMPtr<nsIStandardURL> surl = do_QueryInterface(uri, &rv);
78 NS_ENSURE_SUCCESS(rv, rv);
80 rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec, aOriginCharset,
81 aBaseURI);
82 NS_ENSURE_SUCCESS(rv, rv);
84 rv = surl->SetMutable(PR_FALSE);
85 NS_ENSURE_SUCCESS(rv, rv);
86 NS_IF_ADDREF(*_retval = uri);
87 return NS_OK;
90 /* nsIChannel newChannel (in nsIURI aURI); */
91 NS_IMETHODIMP
92 aaSqliteProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval NS_OUTPARAM)
94 NS_ENSURE_ARG_POINTER(aURI);
95 NS_ENSURE_ARG_POINTER(_retval);
97 nsresult rv = NS_OK;
98 PRBool sqliteScheme = PR_FALSE;
99 rv = aURI->SchemeIs(AA_SQLITE_PROTOCOL, &sqliteScheme);
100 NS_ENSURE_SUCCESS(rv, rv);
101 NS_ENSURE_TRUE(sqliteScheme, NS_ERROR_FAILURE);
103 nsCOMPtr<nsIChannel> channel = new aaSqliteChannel(aURI);
104 NS_ENSURE_TRUE(channel, NS_ERROR_OUT_OF_MEMORY);
106 nsCOMPtr<nsIScriptSecurityManager> scrSecMngr =
107 do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
108 NS_ENSURE_SUCCESS(rv, rv);
110 nsCOMPtr<nsIPrincipal> owner;
111 rv = scrSecMngr->GetSystemPrincipal(getter_AddRefs(owner));
112 NS_ENSURE_SUCCESS(rv, rv);
114 rv = channel->SetOwner(owner);
115 NS_ENSURE_SUCCESS(rv, rv);
117 NS_IF_ADDREF(*_retval = channel);
119 return NS_OK;
122 /* boolean allowPort (in long port, in string scheme); */
123 NS_IMETHODIMP
124 aaSqliteProtocolHandler::AllowPort(PRInt32 port, const char *scheme,
125 PRBool *_retval NS_OUTPARAM)
127 return NS_ERROR_NOT_IMPLEMENTED;