2004-07-10 15:04:33 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-26 03:31:24 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:14:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-03-29 06:11:48 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2001-09-26 03:31:24 +04:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-03-29 06:11:48 +04:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 03:31:24 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-07-09 04:20:57 +04:00
|
|
|
* Michiel van Leeuwen (mvl@exedo.nl)
|
2007-12-05 09:37:36 +03:00
|
|
|
* Daniel Witte (dwitte@stanford.edu)
|
2001-09-26 03:31:24 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:14:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 03:31:24 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:14:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-03-29 06:11:48 +04:00
|
|
|
*
|
2001-09-26 03:31:24 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2010-07-19 22:33:33 +04:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-12-12 22:36:00 +03:00
|
|
|
#include "mozilla/unused.h"
|
2001-03-29 06:11:48 +04:00
|
|
|
#include "nsPermissionManager.h"
|
2003-03-22 04:24:51 +03:00
|
|
|
#include "nsPermission.h"
|
2001-03-29 06:11:48 +04:00
|
|
|
#include "nsCRT.h"
|
2002-08-15 22:38:46 +04:00
|
|
|
#include "nsNetUtil.h"
|
2007-12-05 09:37:36 +03:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
2009-01-22 07:15:34 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2003-03-22 04:24:51 +03:00
|
|
|
#include "nsILineInputStream.h"
|
2007-12-05 09:37:36 +03:00
|
|
|
#include "nsIIDNService.h"
|
2003-03-22 04:24:51 +03:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "prprf.h"
|
2007-12-05 09:37:36 +03:00
|
|
|
#include "mozIStorageService.h"
|
|
|
|
#include "mozIStorageStatement.h"
|
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
#include "mozStorageHelper.h"
|
|
|
|
#include "mozStorageCID.h"
|
2010-07-15 18:04:25 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
static nsPermissionManager *gPermissionManager = nsnull;
|
|
|
|
|
|
|
|
using mozilla::dom::ContentParent;
|
2010-07-19 22:33:33 +04:00
|
|
|
using mozilla::dom::ContentChild;
|
2010-12-12 22:36:00 +03:00
|
|
|
using mozilla::unused; // ha!
|
2010-07-19 22:33:33 +04:00
|
|
|
|
2010-07-15 18:04:25 +04:00
|
|
|
static PRBool
|
|
|
|
IsChildProcess()
|
|
|
|
{
|
|
|
|
return XRE_GetProcessType() == GeckoProcessType_Content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns The child process object, or if we are not in the child
|
|
|
|
* process, nsnull.
|
|
|
|
*/
|
2010-07-19 22:33:33 +04:00
|
|
|
static ContentChild*
|
2010-07-15 18:04:25 +04:00
|
|
|
ChildProcess()
|
|
|
|
{
|
|
|
|
if (IsChildProcess()) {
|
2010-07-19 22:33:33 +04:00
|
|
|
ContentChild* cpc = ContentChild::GetSingleton();
|
2010-07-15 18:04:25 +04:00
|
|
|
if (!cpc)
|
|
|
|
NS_RUNTIMEABORT("Content Process is NULL!");
|
|
|
|
return cpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-10-09 22:07:38 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @returns The parent process object, or if we are not in the parent
|
|
|
|
* process, nsnull.
|
|
|
|
*/
|
|
|
|
static ContentParent*
|
|
|
|
ParentProcess()
|
|
|
|
{
|
|
|
|
if (!IsChildProcess()) {
|
|
|
|
ContentParent* cpc = ContentParent::GetSingleton();
|
|
|
|
if (!cpc)
|
|
|
|
NS_RUNTIMEABORT("Content Process is NULL!");
|
|
|
|
return cpc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-07-15 18:04:25 +04:00
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
#define ENSURE_NOT_CHILD_PROCESS_(onError) \
|
2010-07-15 18:04:25 +04:00
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (IsChildProcess()) { \
|
2010-10-09 22:07:38 +04:00
|
|
|
NS_ERROR("Cannot perform action in content process!"); \
|
|
|
|
onError \
|
2010-07-15 18:04:25 +04:00
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
#define ENSURE_NOT_CHILD_PROCESS \
|
|
|
|
ENSURE_NOT_CHILD_PROCESS_({ return NS_ERROR_NOT_AVAILABLE; })
|
|
|
|
|
|
|
|
#define ENSURE_NOT_CHILD_PROCESS_NORET \
|
|
|
|
ENSURE_NOT_CHILD_PROCESS_()
|
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 3
|
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
static PLArenaPool *gHostArena = nsnull;
|
|
|
|
|
|
|
|
// making sHostArena 512b for nice allocation
|
|
|
|
// growing is quite cheap
|
|
|
|
#define HOST_ARENA_SIZE 512
|
|
|
|
|
|
|
|
// equivalent to strdup() - does no error checking,
|
|
|
|
// we're assuming we're only called with a valid pointer
|
|
|
|
static char *
|
|
|
|
ArenaStrDup(const char* str, PLArenaPool* aArena)
|
|
|
|
{
|
|
|
|
void* mem;
|
|
|
|
const PRUint32 size = strlen(str) + 1;
|
|
|
|
PL_ARENA_ALLOCATE(mem, aArena, size);
|
|
|
|
if (mem)
|
|
|
|
memcpy(mem, str, size);
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<char*>(mem);
|
2003-04-23 03:33:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHostEntry::nsHostEntry(const char* aHost)
|
|
|
|
{
|
|
|
|
mHost = ArenaStrDup(aHost, gHostArena);
|
|
|
|
}
|
2001-10-19 06:28:06 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// XXX this can fail on OOM
|
2003-04-23 03:33:31 +04:00
|
|
|
nsHostEntry::nsHostEntry(const nsHostEntry& toCopy)
|
2007-12-05 09:37:36 +03:00
|
|
|
: mHost(toCopy.mHost)
|
|
|
|
, mPermissions(toCopy.mPermissions)
|
2003-04-23 03:33:31 +04:00
|
|
|
{
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2001-03-29 06:11:48 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-12-05 09:37:36 +03:00
|
|
|
// nsPermissionManager Implementation
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
static const char kPermissionsFileName[] = "permissions.sqlite";
|
2009-10-17 01:01:04 +04:00
|
|
|
#define HOSTS_SCHEMA_VERSION 2
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
static const char kHostpermFileName[] = "hostperm.1";
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
static const char kPermissionChangeNotification[] = PERM_CHANGE_NOTIFICATION;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS3(nsPermissionManager, nsIPermissionManager, nsIObserver, nsISupportsWeakReference)
|
2001-03-29 06:11:48 +04:00
|
|
|
|
|
|
|
nsPermissionManager::nsPermissionManager()
|
2007-12-05 09:37:36 +03:00
|
|
|
: mLargestID(0)
|
2010-10-09 22:07:38 +04:00
|
|
|
, mUpdateChildProcess(PR_FALSE)
|
2001-03-29 06:11:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
nsPermissionManager::~nsPermissionManager()
|
2001-03-29 06:11:48 +04:00
|
|
|
{
|
2003-03-22 04:24:51 +03:00
|
|
|
RemoveAllFromMemory();
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
// static
|
|
|
|
nsIPermissionManager*
|
|
|
|
nsPermissionManager::GetXPCOMSingleton()
|
|
|
|
{
|
2010-10-21 22:36:14 +04:00
|
|
|
return GetSingleton().get();
|
2010-10-09 22:07:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-10-21 22:36:14 +04:00
|
|
|
already_AddRefed<nsPermissionManager>
|
2010-10-09 22:07:38 +04:00
|
|
|
nsPermissionManager::GetSingleton()
|
|
|
|
{
|
|
|
|
if (gPermissionManager) {
|
|
|
|
NS_ADDREF(gPermissionManager);
|
|
|
|
return gPermissionManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new singleton nsPermissionManager.
|
|
|
|
// We AddRef only once since XPCOM has rules about the ordering of module
|
|
|
|
// teardowns - by the time our module destructor is called, it's too late to
|
|
|
|
// Release our members, since GC cycles have already been completed and
|
|
|
|
// would result in serious leaks.
|
|
|
|
// See bug 209571.
|
|
|
|
gPermissionManager = new nsPermissionManager();
|
|
|
|
if (gPermissionManager) {
|
|
|
|
NS_ADDREF(gPermissionManager);
|
|
|
|
if (NS_FAILED(gPermissionManager->Init())) {
|
|
|
|
NS_RELEASE(gPermissionManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gPermissionManager;
|
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult
|
|
|
|
nsPermissionManager::Init()
|
2001-03-29 06:11:48 +04:00
|
|
|
{
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
if (!mHostTable.Init()) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2010-12-25 10:31:01 +03:00
|
|
|
mObserverService = do_GetService("@mozilla.org/observer-service;1", &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mObserverService->AddObserver(this, "profile-before-change", PR_TRUE);
|
|
|
|
mObserverService->AddObserver(this, "profile-do-change", PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
if (IsChildProcess()) {
|
|
|
|
// Get the permissions from the parent process
|
2010-11-09 05:49:00 +03:00
|
|
|
InfallibleTArray<IPC::Permission> perms;
|
2010-10-09 22:07:38 +04:00
|
|
|
ChildProcess()->SendReadPermissions(&perms);
|
|
|
|
|
2010-12-12 22:36:00 +03:00
|
|
|
for (PRUint32 i = 0; i < perms.Length(); i++) {
|
2010-10-09 22:07:38 +04:00
|
|
|
const IPC::Permission &perm = perms[i];
|
|
|
|
AddInternal(perm.host, perm.type, perm.capability, 0, perm.expireType,
|
|
|
|
perm.expireTime, eNotify, eNoDBOperation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop here; we don't need the DB in the child process
|
2010-07-15 18:04:25 +04:00
|
|
|
return NS_OK;
|
2010-10-09 22:07:38 +04:00
|
|
|
}
|
2010-07-15 18:04:25 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// ignore failure here, since it's non-fatal (we can run fine without
|
|
|
|
// persistent storage - e.g. if there's no profile).
|
|
|
|
// XXX should we tell the user about this?
|
2009-04-18 10:42:09 +04:00
|
|
|
InitDB(PR_FALSE);
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult
|
2009-04-18 10:42:09 +04:00
|
|
|
nsPermissionManager::InitDB(PRBool aRemoveFile)
|
2007-12-05 09:37:36 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> permissionsFile;
|
|
|
|
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(permissionsFile));
|
|
|
|
if (!permissionsFile)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsresult rv = permissionsFile->AppendNative(NS_LITERAL_CSTRING(kPermissionsFileName));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-04-18 10:42:09 +04:00
|
|
|
if (aRemoveFile) {
|
|
|
|
PRBool exists = PR_FALSE;
|
|
|
|
rv = permissionsFile->Exists(&exists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (exists) {
|
|
|
|
rv = permissionsFile->Remove(PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsCOMPtr<mozIStorageService> storage = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID);
|
|
|
|
if (!storage)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// cache a connection to the hosts database
|
|
|
|
rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
|
2008-02-28 11:23:12 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool ready;
|
|
|
|
mDBConn->GetConnectionReady(&ready);
|
|
|
|
if (!ready) {
|
2007-12-05 09:37:36 +03:00
|
|
|
// delete and try again
|
|
|
|
rv = permissionsFile->Remove(PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = storage->OpenDatabase(permissionsFile, getter_AddRefs(mDBConn));
|
2008-02-28 11:23:12 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mDBConn->GetConnectionReady(&ready);
|
|
|
|
if (!ready)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-12-05 09:37:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool tableExists = PR_FALSE;
|
|
|
|
mDBConn->TableExists(NS_LITERAL_CSTRING("moz_hosts"), &tableExists);
|
|
|
|
if (!tableExists) {
|
2010-10-09 22:07:38 +04:00
|
|
|
rv = CreateTable();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// table already exists; check the schema version before reading
|
|
|
|
PRInt32 dbSchemaVersion;
|
|
|
|
rv = mDBConn->GetSchemaVersion(&dbSchemaVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
switch (dbSchemaVersion) {
|
|
|
|
// upgrading.
|
|
|
|
// every time you increment the database schema, you need to implement
|
|
|
|
// the upgrading code from the previous version to the new one.
|
|
|
|
// fall through to current version
|
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// previous non-expiry version of database. Upgrade it by adding the
|
|
|
|
// expiration columns
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"ALTER TABLE moz_hosts ADD expireType INTEGER"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"ALTER TABLE moz_hosts ADD expireTime INTEGER"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fall through to the next upgrade
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// current version.
|
|
|
|
case HOSTS_SCHEMA_VERSION:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
NS_WARNING("couldn't get schema version!");
|
|
|
|
|
|
|
|
// the table may be usable; someone might've just clobbered the schema
|
|
|
|
// version. we can treat this case like a downgrade using the codepath
|
|
|
|
// below, by verifying the columns we care about are all there. for now,
|
|
|
|
// re-set the schema version in the db, in case the checks succeed (if
|
|
|
|
// they don't, we're dropping the table anyway).
|
|
|
|
rv = mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// fall through to downgrade check
|
|
|
|
|
|
|
|
// downgrading.
|
|
|
|
// if columns have been added to the table, we can still use the ones we
|
|
|
|
// understand safely. if columns have been deleted or altered, just
|
|
|
|
// blow away the table and start from scratch! if you change the way
|
|
|
|
// a column is interpreted, make sure you also change its name so this
|
|
|
|
// check will catch it.
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// check if all the expected columns exist
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2009-10-17 01:01:04 +04:00
|
|
|
"SELECT host, type, permission, expireType, expireTime FROM moz_hosts"),
|
|
|
|
getter_AddRefs(stmt));
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// our columns aren't there - drop the table!
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DROP TABLE moz_hosts"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = CreateTable();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make operations on the table asynchronous, for performance
|
|
|
|
mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("PRAGMA synchronous = OFF"));
|
|
|
|
|
|
|
|
// cache frequently used statements (for insertion, deletion, and updating)
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"INSERT INTO moz_hosts "
|
2009-10-17 01:01:04 +04:00
|
|
|
"(id, host, type, permission, expireType, expireTime) "
|
|
|
|
"VALUES (?1, ?2, ?3, ?4, ?5, ?6)"), getter_AddRefs(mStmtInsert));
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_hosts "
|
|
|
|
"WHERE id = ?1"), getter_AddRefs(mStmtDelete));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_hosts "
|
2009-10-17 01:01:04 +04:00
|
|
|
"SET permission = ?2, expireType= ?3, expireTime = ?4 WHERE id = ?1"),
|
|
|
|
getter_AddRefs(mStmtUpdate));
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// check whether to import or just read in the db
|
|
|
|
if (tableExists)
|
|
|
|
return Read();
|
|
|
|
|
|
|
|
return Import();
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets the schema version and creates the moz_hosts table.
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::CreateTable()
|
|
|
|
{
|
|
|
|
// set the schema version, before creating the table
|
|
|
|
nsresult rv = mDBConn->SetSchemaVersion(HOSTS_SCHEMA_VERSION);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// create the table
|
2010-08-21 20:48:01 +04:00
|
|
|
// SQL also lives in automation.py.in. If you change this SQL change that
|
|
|
|
// one too.
|
2007-12-05 09:37:36 +03:00
|
|
|
return mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"CREATE TABLE moz_hosts ("
|
|
|
|
" id INTEGER PRIMARY KEY"
|
|
|
|
",host TEXT"
|
|
|
|
",type TEXT"
|
|
|
|
",permission INTEGER"
|
2009-10-17 01:01:04 +04:00
|
|
|
",expireType INTEGER"
|
|
|
|
",expireTime INTEGER"
|
2007-12-05 09:37:36 +03:00
|
|
|
")"));
|
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_IMETHODIMP
|
2003-07-09 04:20:57 +04:00
|
|
|
nsPermissionManager::Add(nsIURI *aURI,
|
|
|
|
const char *aType,
|
2009-10-17 01:01:04 +04:00
|
|
|
PRUint32 aPermission,
|
|
|
|
PRUint32 aExpireType,
|
|
|
|
PRInt64 aExpireTime)
|
2003-03-22 04:24:51 +03:00
|
|
|
{
|
2010-07-15 18:04:25 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2005-01-17 12:13:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2003-07-11 04:04:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
2009-10-17 01:01:04 +04:00
|
|
|
NS_ENSURE_TRUE(aExpireType == nsIPermissionManager::EXPIRE_NEVER ||
|
|
|
|
aExpireType == nsIPermissionManager::EXPIRE_TIME ||
|
|
|
|
aExpireType == nsIPermissionManager::EXPIRE_SESSION,
|
|
|
|
NS_ERROR_INVALID_ARG);
|
2005-01-17 12:13:27 +03:00
|
|
|
|
2001-03-29 06:11:48 +04:00
|
|
|
nsresult rv;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
// Skip addition if the permission is already expired.
|
|
|
|
if (aExpireType == nsIPermissionManager::EXPIRE_TIME &&
|
2009-10-17 03:16:31 +04:00
|
|
|
aExpireTime <= PR_Now() / 1000)
|
2009-10-17 01:01:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2003-11-06 23:21:05 +03:00
|
|
|
nsCAutoString host;
|
|
|
|
rv = GetHost(aURI, host);
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
return AddInternal(host, nsDependentCString(aType), aPermission, 0,
|
|
|
|
aExpireType, aExpireTime, eNotify, eWriteToDB);
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult
|
2003-04-23 03:33:31 +04:00
|
|
|
nsPermissionManager::AddInternal(const nsAFlatCString &aHost,
|
2007-12-05 09:37:36 +03:00
|
|
|
const nsAFlatCString &aType,
|
2003-10-22 10:53:19 +04:00
|
|
|
PRUint32 aPermission,
|
2007-12-05 09:37:36 +03:00
|
|
|
PRInt64 aID,
|
2009-10-17 01:01:04 +04:00
|
|
|
PRUint32 aExpireType,
|
|
|
|
PRInt64 aExpireTime,
|
2007-12-05 09:37:36 +03:00
|
|
|
NotifyOperationType aNotifyOperation,
|
|
|
|
DBOperationType aDBOperation)
|
2003-03-22 04:24:51 +03:00
|
|
|
{
|
2010-10-09 22:07:38 +04:00
|
|
|
if (!IsChildProcess()) {
|
|
|
|
// In the parent, send the update now, if the child is ready
|
|
|
|
if (mUpdateChildProcess) {
|
|
|
|
IPC::Permission permission((aHost),
|
|
|
|
(aType),
|
|
|
|
aPermission, aExpireType, aExpireTime);
|
2010-12-12 22:36:00 +03:00
|
|
|
unused << ParentProcess()->SendAddPermission(permission);
|
2010-10-09 22:07:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
if (!gHostArena) {
|
|
|
|
gHostArena = new PLArenaPool;
|
|
|
|
if (!gHostArena)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
PL_INIT_ARENA_POOL(gHostArena, "PermissionHostArena", HOST_ARENA_SIZE);
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// look up the type index
|
|
|
|
PRInt32 typeIndex = GetTypeIndex(aType.get(), PR_TRUE);
|
|
|
|
NS_ENSURE_TRUE(typeIndex != -1, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2003-10-22 10:53:19 +04:00
|
|
|
// When an entry already exists, PutEntry will return that, instead
|
2003-04-23 03:33:31 +04:00
|
|
|
// of adding a new one
|
|
|
|
nsHostEntry *entry = mHostTable.PutEntry(aHost.get());
|
|
|
|
if (!entry) return NS_ERROR_FAILURE;
|
2004-02-04 19:15:38 +03:00
|
|
|
if (!entry->GetKey()) {
|
|
|
|
mHostTable.RawRemoveEntry(entry);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// figure out the transaction type, and get any existing permission value
|
|
|
|
OperationType op;
|
|
|
|
PRInt32 index = entry->GetPermissionIndex(typeIndex);
|
|
|
|
if (index == -1) {
|
|
|
|
if (aPermission == nsIPermissionManager::UNKNOWN_ACTION)
|
|
|
|
op = eOperationNone;
|
|
|
|
else
|
|
|
|
op = eOperationAdding;
|
|
|
|
|
|
|
|
} else {
|
2009-10-17 01:01:04 +04:00
|
|
|
nsPermissionEntry oldPermissionEntry = entry->GetPermissions()[index];
|
|
|
|
|
|
|
|
// remove the permission if the permission is UNKNOWN, update the
|
|
|
|
// permission if its value or expire type have changed OR if the time has
|
|
|
|
// changed and the expire type is time, otherwise, don't modify. There's
|
|
|
|
// no need to modify a permission that doesn't expire with time when the
|
|
|
|
// only thing changed is the expire time.
|
|
|
|
if (aPermission == oldPermissionEntry.mPermission &&
|
|
|
|
aExpireType == oldPermissionEntry.mExpireType &&
|
|
|
|
(aExpireType != nsIPermissionManager::EXPIRE_TIME ||
|
|
|
|
aExpireTime == oldPermissionEntry.mExpireTime))
|
2007-12-05 09:37:36 +03:00
|
|
|
op = eOperationNone;
|
|
|
|
else if (aPermission == nsIPermissionManager::UNKNOWN_ACTION)
|
|
|
|
op = eOperationRemoving;
|
|
|
|
else
|
|
|
|
op = eOperationChanging;
|
2003-04-23 03:33:31 +04:00
|
|
|
}
|
2003-10-22 10:53:19 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// do the work for adding, deleting, or changing a permission:
|
|
|
|
// update the in-memory list, write to the db, and notify consumers.
|
|
|
|
PRInt64 id;
|
|
|
|
switch (op) {
|
|
|
|
case eOperationNone:
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
case eOperationAdding:
|
|
|
|
{
|
|
|
|
if (aDBOperation == eWriteToDB) {
|
|
|
|
// we'll be writing to the database - generate a known unique id
|
|
|
|
id = ++mLargestID;
|
|
|
|
} else {
|
|
|
|
// we're reading from the database - use the id already assigned
|
|
|
|
id = aID;
|
|
|
|
}
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
entry->GetPermissions().AppendElement(nsPermissionEntry(typeIndex, aPermission, id, aExpireType, aExpireTime));
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
if (aDBOperation == eWriteToDB && aExpireType != nsIPermissionManager::EXPIRE_SESSION)
|
|
|
|
UpdateDB(op, mStmtInsert, id, aHost, aType, aPermission, aExpireType, aExpireTime);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
if (aNotifyOperation == eNotify) {
|
2003-10-22 10:53:19 +04:00
|
|
|
NotifyObserversWithPermission(aHost,
|
2007-12-05 09:37:36 +03:00
|
|
|
mTypeArray[typeIndex],
|
2007-03-23 02:01:14 +03:00
|
|
|
aPermission,
|
2009-10-17 01:01:04 +04:00
|
|
|
aExpireType,
|
|
|
|
aExpireTime,
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_LITERAL_STRING("added").get());
|
2007-12-05 09:37:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eOperationRemoving:
|
|
|
|
{
|
2009-10-17 01:01:04 +04:00
|
|
|
nsPermissionEntry oldPermissionEntry = entry->GetPermissions()[index];
|
|
|
|
id = oldPermissionEntry.mID;
|
2007-12-05 09:37:36 +03:00
|
|
|
entry->GetPermissions().RemoveElementAt(index);
|
|
|
|
|
|
|
|
// If no more types are present, remove the entry
|
|
|
|
if (entry->GetPermissions().IsEmpty())
|
|
|
|
mHostTable.RawRemoveEntry(entry);
|
|
|
|
|
|
|
|
if (aDBOperation == eWriteToDB)
|
2009-10-17 01:01:04 +04:00
|
|
|
UpdateDB(op, mStmtDelete, id, EmptyCString(), EmptyCString(), 0,
|
|
|
|
nsIPermissionManager::EXPIRE_NEVER, 0);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
if (aNotifyOperation == eNotify) {
|
|
|
|
NotifyObserversWithPermission(aHost,
|
|
|
|
mTypeArray[typeIndex],
|
2009-10-17 01:01:04 +04:00
|
|
|
oldPermissionEntry.mPermission,
|
|
|
|
oldPermissionEntry.mExpireType,
|
|
|
|
oldPermissionEntry.mExpireTime,
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_LITERAL_STRING("deleted").get());
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eOperationChanging:
|
|
|
|
{
|
|
|
|
id = entry->GetPermissions()[index].mID;
|
|
|
|
entry->GetPermissions()[index].mPermission = aPermission;
|
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
if (aDBOperation == eWriteToDB && aExpireType != nsIPermissionManager::EXPIRE_SESSION)
|
|
|
|
UpdateDB(op, mStmtUpdate, id, EmptyCString(), EmptyCString(), aPermission, aExpireType, aExpireTime);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
if (aNotifyOperation == eNotify) {
|
2007-03-23 02:01:14 +03:00
|
|
|
NotifyObserversWithPermission(aHost,
|
2007-12-05 09:37:36 +03:00
|
|
|
mTypeArray[typeIndex],
|
2003-10-22 10:53:19 +04:00
|
|
|
aPermission,
|
2009-10-17 01:01:04 +04:00
|
|
|
aExpireType,
|
|
|
|
aExpireTime,
|
2003-10-22 10:53:19 +04:00
|
|
|
NS_LITERAL_STRING("changed").get());
|
2007-12-05 09:37:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2003-10-22 10:53:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-29 06:11:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPermissionManager::Remove(const nsACString &aHost,
|
2003-07-09 04:20:57 +04:00
|
|
|
const char *aType)
|
2003-03-22 04:24:51 +03:00
|
|
|
{
|
2010-07-15 18:04:25 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2003-07-11 04:04:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// AddInternal() handles removal, just let it do the work
|
|
|
|
return AddInternal(PromiseFlatCString(aHost),
|
|
|
|
nsDependentCString(aType),
|
|
|
|
nsIPermissionManager::UNKNOWN_ACTION,
|
|
|
|
0,
|
2009-10-17 01:01:04 +04:00
|
|
|
nsIPermissionManager::EXPIRE_NEVER,
|
|
|
|
0,
|
2007-12-05 09:37:36 +03:00
|
|
|
eNotify,
|
|
|
|
eWriteToDB);
|
2002-01-11 02:33:36 +03:00
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPermissionManager::RemoveAll()
|
2007-12-05 09:37:36 +03:00
|
|
|
{
|
2010-07-15 18:04:25 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult rv = RemoveAllInternal();
|
2007-03-23 02:01:14 +03:00
|
|
|
NotifyObservers(nsnull, NS_LITERAL_STRING("cleared").get());
|
2007-12-05 09:37:36 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::RemoveAllInternal()
|
|
|
|
{
|
|
|
|
RemoveAllFromMemory();
|
|
|
|
|
|
|
|
// clear the db
|
|
|
|
if (mDBConn) {
|
|
|
|
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("DELETE FROM moz_hosts"));
|
|
|
|
if (NS_FAILED(rv)) {
|
2009-04-18 10:42:09 +04:00
|
|
|
mStmtInsert = nsnull;
|
|
|
|
mStmtDelete = nsnull;
|
|
|
|
mStmtUpdate = nsnull;
|
|
|
|
mDBConn = nsnull;
|
|
|
|
rv = InitDB(PR_TRUE);
|
2007-12-05 09:37:36 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-29 06:11:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-20 18:24:36 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPermissionManager::TestExactPermission(nsIURI *aURI,
|
|
|
|
const char *aType,
|
|
|
|
PRUint32 *aPermission)
|
|
|
|
{
|
|
|
|
return CommonTestPermission(aURI, aType, aPermission, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_IMETHODIMP
|
2003-07-09 04:20:57 +04:00
|
|
|
nsPermissionManager::TestPermission(nsIURI *aURI,
|
|
|
|
const char *aType,
|
|
|
|
PRUint32 *aPermission)
|
2007-02-20 18:24:36 +03:00
|
|
|
{
|
|
|
|
return CommonTestPermission(aURI, aType, aPermission, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::CommonTestPermission(nsIURI *aURI,
|
|
|
|
const char *aType,
|
|
|
|
PRUint32 *aPermission,
|
|
|
|
PRBool aExactHostMatch)
|
2001-03-29 06:11:48 +04:00
|
|
|
{
|
2005-01-17 12:13:27 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2003-07-11 04:04:02 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
2003-03-22 04:24:51 +03:00
|
|
|
|
|
|
|
// set the default
|
|
|
|
*aPermission = nsIPermissionManager::UNKNOWN_ACTION;
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2003-11-06 23:21:05 +03:00
|
|
|
nsCAutoString host;
|
|
|
|
nsresult rv = GetHost(aURI, host);
|
2010-08-20 03:06:07 +04:00
|
|
|
// No host doesn't mean an error. Just return the default. Unless this is
|
|
|
|
// a file uri. In that case use a magic host.
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
PRBool isFile;
|
|
|
|
rv = aURI->SchemeIs("file", &isFile);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (isFile) {
|
|
|
|
host.AssignLiteral("<file>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2003-07-09 04:20:57 +04:00
|
|
|
PRInt32 typeIndex = GetTypeIndex(aType, PR_FALSE);
|
|
|
|
// If type == -1, the type isn't known,
|
|
|
|
// so just return NS_OK
|
|
|
|
if (typeIndex == -1) return NS_OK;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-02-20 18:24:36 +03:00
|
|
|
nsHostEntry *entry = GetHostEntry(host, typeIndex, aExactHostMatch);
|
2004-02-10 22:57:33 +03:00
|
|
|
if (entry)
|
2009-10-17 01:01:04 +04:00
|
|
|
*aPermission = entry->GetPermission(typeIndex).mPermission;
|
2004-02-10 22:57:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get hostentry for given host string and permission type.
|
|
|
|
// walk up the domain if needed.
|
|
|
|
// return null if nothing found.
|
2010-08-20 03:06:07 +04:00
|
|
|
// Also accepts host on the format "<foo>". This will perform an exact match
|
|
|
|
// lookup as the string doesn't contain any dots.
|
2004-02-10 22:57:33 +03:00
|
|
|
nsHostEntry *
|
|
|
|
nsPermissionManager::GetHostEntry(const nsAFlatCString &aHost,
|
2007-02-20 18:24:36 +03:00
|
|
|
PRUint32 aType,
|
|
|
|
PRBool aExactHostMatch)
|
2004-02-10 22:57:33 +03:00
|
|
|
{
|
2003-03-26 03:46:32 +03:00
|
|
|
PRUint32 offset = 0;
|
2004-02-10 22:57:33 +03:00
|
|
|
nsHostEntry *entry;
|
2009-10-17 01:01:04 +04:00
|
|
|
PRInt64 now = PR_Now() / 1000;
|
|
|
|
|
2003-03-26 03:46:32 +03:00
|
|
|
do {
|
2004-02-10 22:57:33 +03:00
|
|
|
entry = mHostTable.GetEntry(aHost.get() + offset);
|
2003-04-23 03:33:31 +04:00
|
|
|
if (entry) {
|
2009-10-17 01:01:04 +04:00
|
|
|
nsPermissionEntry permEntry = entry->GetPermission(aType);
|
|
|
|
|
|
|
|
// if the entry is expired, remove and keep looking for others.
|
|
|
|
if (permEntry.mExpireType == nsIPermissionManager::EXPIRE_TIME &&
|
2009-10-17 03:16:31 +04:00
|
|
|
permEntry.mExpireTime <= now)
|
2009-10-17 01:01:04 +04:00
|
|
|
Remove(aHost, mTypeArray[aType].get());
|
|
|
|
else if (permEntry.mPermission != nsIPermissionManager::UNKNOWN_ACTION)
|
2003-04-23 03:33:31 +04:00
|
|
|
break;
|
2004-02-10 22:57:33 +03:00
|
|
|
|
|
|
|
// reset entry, to be able to return null on failure
|
|
|
|
entry = nsnull;
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
2007-02-20 18:24:36 +03:00
|
|
|
if (aExactHostMatch)
|
|
|
|
break; // do not try super domains
|
|
|
|
|
2004-02-10 22:57:33 +03:00
|
|
|
offset = aHost.FindChar('.', offset) + 1;
|
2003-03-26 03:46:32 +03:00
|
|
|
|
2003-04-04 17:20:37 +04:00
|
|
|
// walk up the domaintree (we stop as soon as we find a match,
|
|
|
|
// which will be the most specific domain we have an entry for).
|
|
|
|
} while (offset > 0);
|
2004-02-10 22:57:33 +03:00
|
|
|
return entry;
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// helper struct for passing arguments into hash enumeration callback.
|
|
|
|
struct nsGetEnumeratorData
|
|
|
|
{
|
|
|
|
nsGetEnumeratorData(nsCOMArray<nsIPermission> *aArray, const nsTArray<nsCString> *aTypes)
|
|
|
|
: array(aArray)
|
|
|
|
, types(aTypes) {}
|
|
|
|
|
|
|
|
nsCOMArray<nsIPermission> *array;
|
|
|
|
const nsTArray<nsCString> *types;
|
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashOperator
|
2007-12-05 09:37:36 +03:00
|
|
|
AddPermissionsToList(nsHostEntry *entry, void *arg)
|
2003-04-23 03:33:31 +04:00
|
|
|
{
|
2007-12-05 09:37:36 +03:00
|
|
|
nsGetEnumeratorData *data = static_cast<nsGetEnumeratorData *>(arg);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < entry->GetPermissions().Length(); ++i) {
|
|
|
|
nsPermissionEntry &permEntry = entry->GetPermissions()[i];
|
|
|
|
|
|
|
|
nsPermission *perm = new nsPermission(entry->GetHost(),
|
|
|
|
data->types->ElementAt(permEntry.mType),
|
2009-10-17 01:01:04 +04:00
|
|
|
permEntry.mPermission,
|
|
|
|
permEntry.mExpireType,
|
|
|
|
permEntry.mExpireTime);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
data->array->AppendObject(perm);
|
|
|
|
}
|
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
NS_IMETHODIMP nsPermissionManager::GetEnumerator(nsISimpleEnumerator **aEnum)
|
|
|
|
{
|
2010-07-15 18:04:25 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// roll an nsCOMArray of all our permissions, then hand out an enumerator
|
|
|
|
nsCOMArray<nsIPermission> array;
|
|
|
|
nsGetEnumeratorData data(&array, &mTypeArray);
|
|
|
|
|
|
|
|
mHostTable.EnumerateEntries(AddPermissionsToList, &data);
|
|
|
|
|
|
|
|
return NS_NewArrayEnumerator(aEnum, array);
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
|
|
|
|
2001-10-20 00:52:59 +04:00
|
|
|
NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
|
2001-03-29 06:11:48 +04:00
|
|
|
{
|
2010-07-15 18:04:25 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2001-10-20 00:52:59 +04:00
|
|
|
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
|
2007-12-05 09:37:36 +03:00
|
|
|
// The profile is about to change,
|
|
|
|
// or is going away because the application is shutting down.
|
2004-03-12 21:02:38 +03:00
|
|
|
if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
|
2007-12-05 09:37:36 +03:00
|
|
|
// clear the permissions file
|
|
|
|
RemoveAllInternal();
|
2004-03-12 21:02:38 +03:00
|
|
|
} else {
|
2007-12-05 09:37:36 +03:00
|
|
|
RemoveAllFromMemory();
|
2004-03-12 21:02:38 +03:00
|
|
|
}
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
2001-10-20 00:52:59 +04:00
|
|
|
else if (!nsCRT::strcmp(aTopic, "profile-do-change")) {
|
2007-12-05 09:37:36 +03:00
|
|
|
// the profile has already changed; init the db from the new location
|
2009-04-18 10:42:09 +04:00
|
|
|
InitDB(PR_FALSE);
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
return NS_OK;
|
2001-03-29 06:11:48 +04:00
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//*** nsPermissionManager private methods
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::RemoveAllFromMemory()
|
|
|
|
{
|
2007-12-05 09:37:36 +03:00
|
|
|
mLargestID = 0;
|
|
|
|
mTypeArray.Clear();
|
2003-04-23 03:33:31 +04:00
|
|
|
mHostTable.Clear();
|
|
|
|
if (gHostArena) {
|
|
|
|
PL_FinishArenaPool(gHostArena);
|
|
|
|
delete gHostArena;
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
2003-04-23 03:33:31 +04:00
|
|
|
gHostArena = nsnull;
|
2003-03-22 04:24:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-09 04:20:57 +04:00
|
|
|
// Returns -1 on failure
|
|
|
|
PRInt32
|
|
|
|
nsPermissionManager::GetTypeIndex(const char *aType,
|
|
|
|
PRBool aAdd)
|
|
|
|
{
|
2007-12-05 09:37:36 +03:00
|
|
|
for (PRUint32 i = 0; i < mTypeArray.Length(); ++i)
|
|
|
|
if (mTypeArray[i].Equals(aType))
|
2003-07-09 04:20:57 +04:00
|
|
|
return i;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
if (!aAdd) {
|
2003-07-09 04:20:57 +04:00
|
|
|
// Not found, but that is ok - we were just looking.
|
|
|
|
return -1;
|
2007-12-05 09:37:36 +03:00
|
|
|
}
|
2003-07-09 04:20:57 +04:00
|
|
|
|
|
|
|
// This type was not registered before.
|
2007-12-05 09:37:36 +03:00
|
|
|
// append it to the array, without copy-constructing the string
|
|
|
|
nsCString *elem = mTypeArray.AppendElement();
|
|
|
|
if (!elem)
|
2003-07-09 04:20:57 +04:00
|
|
|
return -1;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
elem->Assign(aType);
|
|
|
|
return mTypeArray.Length() - 1;
|
2003-07-09 04:20:57 +04:00
|
|
|
}
|
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
// wrapper function for mangling (host,type,perm,expireType,expireTime)
|
|
|
|
// set into an nsIPermission.
|
2003-10-22 10:53:19 +04:00
|
|
|
void
|
|
|
|
nsPermissionManager::NotifyObserversWithPermission(const nsACString &aHost,
|
2007-12-05 09:37:36 +03:00
|
|
|
const nsCString &aType,
|
2003-10-22 10:53:19 +04:00
|
|
|
PRUint32 aPermission,
|
2009-10-17 01:01:04 +04:00
|
|
|
PRUint32 aExpireType,
|
|
|
|
PRInt64 aExpireTime,
|
2003-10-22 10:53:19 +04:00
|
|
|
const PRUnichar *aData)
|
2003-03-22 04:24:51 +03:00
|
|
|
{
|
2003-10-22 10:53:19 +04:00
|
|
|
nsCOMPtr<nsIPermission> permission =
|
2009-10-17 01:01:04 +04:00
|
|
|
new nsPermission(aHost, aType, aPermission, aExpireType, aExpireTime);
|
2003-10-22 10:53:19 +04:00
|
|
|
if (permission)
|
|
|
|
NotifyObservers(permission, aData);
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
|
|
|
|
2003-10-22 10:53:19 +04:00
|
|
|
// notify observers that the permission list changed. there are four possible
|
|
|
|
// values for aData:
|
|
|
|
// "deleted" means a permission was deleted. aPermission is the deleted permission.
|
|
|
|
// "added" means a permission was added. aPermission is the added permission.
|
|
|
|
// "changed" means a permission was altered. aPermission is the new permission.
|
|
|
|
// "cleared" means the entire permission list was cleared. aPermission is null.
|
|
|
|
void
|
|
|
|
nsPermissionManager::NotifyObservers(nsIPermission *aPermission,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
if (mObserverService)
|
|
|
|
mObserverService->NotifyObservers(aPermission,
|
|
|
|
kPermissionChangeNotification,
|
|
|
|
aData);
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::Read()
|
|
|
|
{
|
2010-10-09 22:07:38 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult rv;
|
2007-09-21 09:09:54 +04:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
// delete expired permissions before we read in the db
|
|
|
|
{
|
|
|
|
// this deletion has its own scope so the write lock is released when done.
|
|
|
|
nsCOMPtr<mozIStorageStatement> stmtDeleteExpired;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2009-10-17 03:16:31 +04:00
|
|
|
"DELETE FROM moz_hosts WHERE expireType = ?1 AND expireTime <= ?2"),
|
2009-10-17 01:01:04 +04:00
|
|
|
getter_AddRefs(stmtDeleteExpired));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = stmtDeleteExpired->BindInt32ByIndex(0, nsIPermissionManager::EXPIRE_TIME);
|
2009-10-17 01:01:04 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = stmtDeleteExpired->BindInt64ByIndex(1, PR_Now() / 1000);
|
2009-10-17 01:01:04 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResult;
|
|
|
|
rv = stmtDeleteExpired->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2009-10-17 01:01:04 +04:00
|
|
|
"SELECT id, host, type, permission, expireType, expireTime "
|
2007-12-05 09:37:36 +03:00
|
|
|
"FROM moz_hosts"), getter_AddRefs(stmt));
|
2007-09-21 09:09:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
PRInt64 id;
|
|
|
|
nsCAutoString host, type;
|
|
|
|
PRUint32 permission;
|
2009-10-17 01:01:04 +04:00
|
|
|
PRUint32 expireType;
|
|
|
|
PRInt64 expireTime;
|
2007-12-05 09:37:36 +03:00
|
|
|
PRBool hasResult;
|
|
|
|
while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
|
|
|
|
// explicitly set our entry id counter for use in AddInternal(),
|
|
|
|
// and keep track of the largest id so we know where to pick up.
|
|
|
|
id = stmt->AsInt64(0);
|
|
|
|
if (id > mLargestID)
|
|
|
|
mLargestID = id;
|
|
|
|
|
|
|
|
rv = stmt->GetUTF8String(1, host);
|
2004-02-08 16:04:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
rv = stmt->GetUTF8String(2, type);
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-04-11 19:09:51 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
permission = stmt->AsInt32(3);
|
2009-10-17 01:01:04 +04:00
|
|
|
expireType = stmt->AsInt32(4);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
// convert into PRInt64 value (milliseconds)
|
|
|
|
expireTime = stmt->AsInt64(5);
|
|
|
|
|
|
|
|
rv = AddInternal(host, type, permission, id, expireType, expireTime,
|
|
|
|
eDontNotify, eNoDBOperation);
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char kMatchTypeHost[] = "host";
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPermissionManager::Import()
|
|
|
|
{
|
2010-10-09 22:07:38 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> permissionsFile;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(permissionsFile));
|
2008-01-12 03:38:38 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
rv = permissionsFile->AppendNative(NS_LITERAL_CSTRING(kHostpermFileName));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> fileInputStream;
|
|
|
|
rv = NS_NewLocalFileInputStream(getter_AddRefs(fileInputStream),
|
|
|
|
permissionsFile);
|
2008-01-12 03:38:38 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(fileInputStream, &rv);
|
2004-02-08 16:04:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// start a transaction on the storage db, to optimize insertions.
|
|
|
|
// transaction will automically commit on completion
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_TRUE);
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
/* format is:
|
2004-02-08 16:04:13 +03:00
|
|
|
* matchtype \t type \t permission \t host
|
|
|
|
* Only "host" is supported for matchtype
|
|
|
|
* type is a string that identifies the type of permission (e.g. "cookie")
|
|
|
|
* permission is an integer between 1 and 15
|
2003-03-22 04:24:51 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
nsCAutoString buffer;
|
|
|
|
PRBool isMore = PR_TRUE;
|
2004-04-22 19:32:54 +04:00
|
|
|
while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) {
|
2003-03-22 04:24:51 +03:00
|
|
|
if (buffer.IsEmpty() || buffer.First() == '#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
nsTArray<nsCString> lineArray;
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// Split the line at tabs
|
2009-01-22 07:15:34 +03:00
|
|
|
ParseString(buffer, '\t', lineArray);
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2009-01-22 07:15:34 +03:00
|
|
|
if (lineArray[0].EqualsLiteral(kMatchTypeHost) &&
|
|
|
|
lineArray.Length() == 4) {
|
2007-12-05 09:37:36 +03:00
|
|
|
|
|
|
|
PRInt32 error;
|
2009-01-22 07:15:34 +03:00
|
|
|
PRUint32 permission = lineArray[2].ToInteger(&error);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (error)
|
2007-03-23 02:01:14 +03:00
|
|
|
continue;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// hosts might be encoded in UTF8; switch them to ACE to be consistent
|
2009-01-22 07:15:34 +03:00
|
|
|
if (!IsASCII(lineArray[3])) {
|
|
|
|
rv = NormalizeToACE(lineArray[3]);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv))
|
2007-03-23 02:01:14 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-10-17 01:01:04 +04:00
|
|
|
rv = AddInternal(lineArray[3], lineArray[1], permission, 0,
|
|
|
|
nsIPermissionManager::EXPIRE_NEVER, 0, eDontNotify, eWriteToDB);
|
2007-12-05 09:37:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// we're done importing - delete the old file
|
|
|
|
permissionsFile->Remove(PR_FALSE);
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult
|
|
|
|
nsPermissionManager::NormalizeToACE(nsCString &aHost)
|
2007-03-23 02:01:14 +03:00
|
|
|
{
|
2007-12-05 09:37:36 +03:00
|
|
|
// lazily init the IDN service
|
|
|
|
if (!mIDNService) {
|
|
|
|
nsresult rv;
|
|
|
|
mIDNService = do_GetService(NS_IDNSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2004-03-12 21:02:38 +03:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
return mIDNService->ConvertUTF8toACE(aHost, aHost);
|
2004-03-12 21:02:38 +03:00
|
|
|
}
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult
|
2007-12-05 09:37:36 +03:00
|
|
|
nsPermissionManager::GetHost(nsIURI *aURI, nsACString &aResult)
|
2003-03-22 04:24:51 +03:00
|
|
|
{
|
2007-12-05 09:37:36 +03:00
|
|
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
|
|
|
if (!innerURI) return NS_ERROR_FAILURE;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult rv = innerURI->GetAsciiHost(aResult);
|
2004-02-08 16:04:13 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv) || aResult.IsEmpty())
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
void
|
|
|
|
nsPermissionManager::UpdateDB(OperationType aOp,
|
|
|
|
mozIStorageStatement* aStmt,
|
|
|
|
PRInt64 aID,
|
|
|
|
const nsACString &aHost,
|
|
|
|
const nsACString &aType,
|
2009-10-17 01:01:04 +04:00
|
|
|
PRUint32 aPermission,
|
|
|
|
PRUint32 aExpireType,
|
|
|
|
PRInt64 aExpireTime)
|
2007-12-05 09:37:36 +03:00
|
|
|
{
|
2010-10-09 22:07:38 +04:00
|
|
|
ENSURE_NOT_CHILD_PROCESS_NORET;
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult rv;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// no statement is ok - just means we don't have a profile
|
|
|
|
if (!aStmt)
|
|
|
|
return;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
switch (aOp) {
|
|
|
|
case eOperationAdding:
|
|
|
|
{
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt64ByIndex(0, aID);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindUTF8StringByIndex(1, aHost);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindUTF8StringByIndex(2, aType);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt32ByIndex(3, aPermission);
|
2009-10-17 01:01:04 +04:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt32ByIndex(4, aExpireType);
|
2009-10-17 01:01:04 +04:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt64ByIndex(5, aExpireTime);
|
2007-12-05 09:37:36 +03:00
|
|
|
break;
|
2007-12-05 09:37:36 +03:00
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
case eOperationRemoving:
|
|
|
|
{
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt64ByIndex(0, aID);
|
2007-12-05 09:37:36 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
case eOperationChanging:
|
|
|
|
{
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt64ByIndex(0, aID);
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv)) break;
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt32ByIndex(1, aPermission);
|
2009-10-17 01:01:04 +04:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt32ByIndex(2, aExpireType);
|
2009-10-17 01:01:04 +04:00
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-03-31 21:19:31 +04:00
|
|
|
rv = aStmt->BindInt64ByIndex(3, aExpireTime);
|
2007-12-05 09:37:36 +03:00
|
|
|
break;
|
2004-07-20 02:00:03 +04:00
|
|
|
}
|
2004-07-17 00:08:08 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("need a valid operation in UpdateDB()!");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
break;
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2003-10-10 19:08:43 +04:00
|
|
|
}
|
2005-01-17 12:13:27 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRBool hasResult;
|
|
|
|
rv = aStmt->ExecuteStep(&hasResult);
|
|
|
|
aStmt->Reset();
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_WARNING("db change failed!");
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2007-12-05 09:37:36 +03:00
|
|
|
|