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: */
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"
26 #include "nsAutoPtr.h"
28 #include "nsIStandardURL.h"
30 #include "nsComponentManagerUtils.h"
32 #include "aaSqlitePump.h"
33 #include "aaSqliteChannel.h"
35 NS_IMPL_ISUPPORTS1(aaSqliteProtocolHandler
, nsIProtocolHandler
)
37 /* readonly attribute ACString scheme; */
39 aaSqliteProtocolHandler::GetScheme(nsACString
& aScheme
)
41 aScheme
.AssignLiteral(AA_SQLITE_PROTOCOL
);
45 /* readonly attribute long defaultPort; */
47 aaSqliteProtocolHandler::GetDefaultPort(PRInt32
*aDefaultPort
)
49 NS_ENSURE_ARG_POINTER(aDefaultPort
);
54 /* readonly attribute unsigned long protocolFlags; */
56 aaSqliteProtocolHandler::GetProtocolFlags(PRUint32
*aProtocolFlags
)
58 NS_ENSURE_ARG_POINTER(aProtocolFlags
);
59 *aProtocolFlags
= URI_STD
| URI_IS_LOCAL_FILE
;
63 /* nsIURI newURI (in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI); */
65 aaSqliteProtocolHandler::NewURI(const nsACString
& aSpec
,
66 const char *aOriginCharset
, nsIURI
*aBaseURI
, nsIURI
**_retval NS_OUTPARAM
)
68 NS_ENSURE_ARG(!aSpec
.IsEmpty());
69 NS_ENSURE_ARG_POINTER(_retval
);
72 nsCOMPtr
<nsIURI
> uri
= do_CreateInstance(NS_STANDARDURL_CONTRACTID
, &rv
);
73 NS_ENSURE_SUCCESS(rv
, rv
);
75 nsCOMPtr
<nsIStandardURL
> surl
= do_QueryInterface(uri
, &rv
);
76 NS_ENSURE_SUCCESS(rv
, rv
);
78 rv
= surl
->Init(nsIStandardURL::URLTYPE_STANDARD
, -1, aSpec
, aOriginCharset
,
80 NS_ENSURE_SUCCESS(rv
, rv
);
82 rv
= surl
->SetMutable(PR_FALSE
);
83 NS_ENSURE_SUCCESS(rv
, rv
);
84 NS_IF_ADDREF(*_retval
= uri
);
88 /* nsIChannel newChannel (in nsIURI aURI); */
90 aaSqliteProtocolHandler::NewChannel(nsIURI
*aURI
, nsIChannel
**_retval NS_OUTPARAM
)
92 NS_ENSURE_ARG_POINTER(aURI
);
93 NS_ENSURE_ARG_POINTER(_retval
);
96 PRBool sqliteScheme
= PR_FALSE
;
97 rv
= aURI
->SchemeIs(AA_SQLITE_PROTOCOL
, &sqliteScheme
);
98 NS_ENSURE_SUCCESS(rv
, rv
);
99 NS_ENSURE_TRUE(sqliteScheme
, NS_ERROR_FAILURE
);
101 nsCOMPtr
<nsIChannel
> channel
= new aaSqliteChannel(aURI
);
102 NS_ENSURE_TRUE(channel
, NS_ERROR_OUT_OF_MEMORY
);
104 NS_IF_ADDREF(*_retval
= channel
);
109 /* boolean allowPort (in long port, in string scheme); */
111 aaSqliteProtocolHandler::AllowPort(PRInt32 port
, const char *scheme
,
112 PRBool
*_retval NS_OUTPARAM
)
114 return NS_ERROR_NOT_IMPLEMENTED
;