[almanah] Removed conditional encryption compilation
- From: Álvaro Peña <alvaropg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [almanah] Removed conditional encryption compilation
- Date: Fri, 28 Nov 2014 23:03:35 +0000 (UTC)
commit 3948c97db2dcf1fc1840fa20b41a1e9f33ccb534
Author: Álvaro Peña <alvaropg gmail com>
Date: Tue Nov 25 18:07:04 2014 +0100
Removed conditional encryption compilation
In order to remove the clutter in the SQLiteVFS and to simplify the
code, I have removed the conditional compilation about the encryption,
so gpgme it's a mess right now, also cryptui and gcr-base.
configure.ac | 116 ++++++++++++++------------------
src/Makefile.am | 10 +--
src/application.c | 9 ---
src/preferences-dialog.c | 14 ----
src/vfs.c | 170 +++++++++++++++++++---------------------------
5 files changed, 123 insertions(+), 196 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8df1b74..32bf6e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,21 +47,6 @@ fi
AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
-dnl Encryption support
-AC_ARG_ENABLE([encryption],
- AS_HELP_STRING([--enable-encryption],[enable database encryption support]),
- [case "${enableval}" in
- yes) encryption=true ;;
- no) encryption=false ;;
- *) AC_MSG_ERROR([bad value ${enableval} for --enable-encryption]) ;;
- esac],[encryption=true])
-
-if test $encryption = "true"; then
- AC_DEFINE([ENABLE_ENCRYPTION],[1],[Define if you want database encryption support])
-fi
-
-AM_CONDITIONAL([ENCRYPTION], [test x$encryption = xtrue])
-
dnl Spell checking
AC_ARG_ENABLE([spell-checking],
AS_HELP_STRING([--enable-spell-checking],[enable spell checking support]),
@@ -82,7 +67,56 @@ dnl Dependencies
dnl ***************************************************************************
dnl Required dependencies
-PKG_CHECK_MODULES(STANDARD, glib-2.0 gtk+-3.0 >= 3.6 gmodule-2.0 gthread-2.0 gio-2.0 >= 2.28.0 sqlite3 cairo
atk)
+PKG_CHECK_MODULES(STANDARD, glib-2.0
+ gtk+-3.0 >= 3.6
+ gmodule-2.0
+ gthread-2.0
+ gio-2.0 >= 2.28.0
+ sqlite3
+ cairo
+ atk
+ gcr-base-3
+ cryptui-0.0)
+
+dnl Check for GPGME, which doesn't provide a pkgconfig file
+dnl This code courtesy of seahorse
+min_gpgme_version=1.0.0
+AC_PATH_PROG(GPGME_CONFIG, gpgme-config, "failed")
+if test $GPGME_CONFIG != "failed" ; then
+ AC_MSG_CHECKING(for GPGME)
+ req_major=`echo $min_gpgme_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
+ req_minor=`echo $min_gpgme_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
+ req_micro=`echo $min_gpgme_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
+ gpgme_config_version=`$GPGME_CONFIG --version`
+ major=`echo $gpgme_config_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
+ minor=`echo $gpgme_config_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
+ micro=`echo $gpgme_config_version | \
+ sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
+
+ if test "$major" -eq "$req_major"; then
+ if test "$minor" -ge "$req_minor"; then
+ if test "$micro" -ge "$req_micro"; then
+ ok="yes"
+ fi
+ fi
+ fi
+fi
+
+AC_DEFINE_UNQUOTED([MIN_GPGME_VERSION],"${min_gpgme_version}",[The minimum required version of GPGME])
+
+if test $ok = "yes"; then
+ STANDARD_CFLAGS="$STANDARD_CFLAGS `$GPGME_CONFIG --cflags`"
+ STANDARD_LIBS="$STANDARD_LIBS `$GPGME_CONFIG --libs`"
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_ERROR(GPGME $min_gpgme_version or later needed)
+fi
+
AC_SUBST(STANDARD_CFLAGS)
AC_SUBST(STANDARD_LIBS)
@@ -104,56 +138,6 @@ if test $spell_checking = "true"; then
AC_SUBST(SPELL_CHECKING_LIBS)
fi
-dnl Encryption support
-if test $encryption = "true"; then
- PKG_CHECK_MODULES(ENCRYPTION, cryptui-0.0 gcr-base-3)
-
- dnl Check for GPGME, which doesn't provide a pkgconfig file
- dnl This code courtesy of seahorse
- min_gpgme_version=1.0.0
- AC_PATH_PROG(GPGME_CONFIG, gpgme-config, "failed")
- if test $GPGME_CONFIG != "failed" ; then
- AC_MSG_CHECKING(for GPGME)
- req_major=`echo $min_gpgme_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
- req_minor=`echo $min_gpgme_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
- req_micro=`echo $min_gpgme_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
- gpgme_config_version=`$GPGME_CONFIG --version`
- major=`echo $gpgme_config_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
- minor=`echo $gpgme_config_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
- micro=`echo $gpgme_config_version | \
- sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
-
- if test "$major" -eq "$req_major"; then
- if test "$minor" -ge "$req_minor"; then
- if test "$micro" -ge "$req_micro"; then
- ok="yes"
- fi
- fi
- fi
- fi
-
- AC_DEFINE_UNQUOTED([MIN_GPGME_VERSION],"${min_gpgme_version}",[The minimum required version of GPGME])
-
- if test $ok = "yes"; then
- ENCRYPTION_CFLAGS="$ENCRYPTION_CFLAGS `$GPGME_CONFIG --cflags`"
- ENCRYPTION_LIBS="$ENCRYPTION_LIBS `$GPGME_CONFIG --libs`"
- AC_MSG_RESULT(yes)
- else
- AC_MSG_ERROR(GPGME $min_gpgme_version or later needed)
- fi
-else
- ENCRYPTION_CFLAGS=""
- ENCRYPTION_LIBS=""
-fi
-
-AC_SUBST(ENCRYPTION_CFLAGS)
-AC_SUBST(ENCRYPTION_LIBS)
-
# Various required functions and headers
AC_CHECK_HEADERS([libintl.h])
AC_C_INLINE
diff --git a/src/Makefile.am b/src/Makefile.am
index dcf61d3..363c2e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,8 @@ almanah_SOURCES = \
storage-manager.h \
search-dialog.c \
search-dialog.h \
+ preferences-dialog.c \
+ preferences-dialog.h \
printing.c \
printing.h \
entry.c \
@@ -76,12 +78,6 @@ almanah_SOURCES += \
events/calendar-task.h
endif
-if ENCRYPTION
-almanah_SOURCES += \
- preferences-dialog.c \
- preferences-dialog.h
-endif
-
almanah_CPPFLAGS = \
-DPACKAGE_LOCALE_DIR=\""$(datadir)/locale"\" \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
@@ -93,7 +89,6 @@ almanah_CPPFLAGS = \
almanah_CFLAGS = \
$(STANDARD_CFLAGS) \
$(EVO_CFLAGS) \
- $(ENCRYPTION_CFLAGS) \
$(SPELL_CHECKING_CFLAGS) \
$(WARN_CFLAGS) \
$(AM_CFLAGS)
@@ -101,7 +96,6 @@ almanah_CFLAGS = \
almanah_LDADD = \
$(STANDARD_LIBS) \
$(EVO_LIBS) \
- $(ENCRYPTION_LIBS) \
$(SPELL_CHECKING_LIBS) \
$(AM_LDADD)
diff --git a/src/application.c b/src/application.c
index 33092f1..8ae28f4 100644
--- a/src/application.c
+++ b/src/application.c
@@ -435,13 +435,6 @@ almanah_application_init_actions (AlmanahApplication *self)
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
gtk_application_set_app_menu (GTK_APPLICATION (self), G_MENU_MODEL (gtk_builder_get_object (builder,
"almanah_app_menu")));
-#ifndef ENABLE_ENCRYPTION
-#ifndef ENABLE_SPELL_CHECKING
- /* Remove the "Preferences" entry from the menu */
- g_action_map_remove_action (G_ACTION_MAP (self), "preferences");
-#endif /* !ENABLE_SPELL_CHECKING */
-#endif /* !ENABLE_ENCRYPTION */
-
g_object_unref (builder);
}
@@ -463,7 +456,6 @@ action_search_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data
static void
action_preferences_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
{
-#if defined(ENABLE_ENCRYPTION) || defined(ENABLE_SPELL_CHECKING)
AlmanahApplication *application;
GSettings *settings;
AlmanahPreferencesDialog *dialog;
@@ -477,7 +469,6 @@ action_preferences_cb (GSimpleAction *action, GVariant *parameter, gpointer user
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
-#endif /* ENABLE_ENCRYPTION || ENABLE_SPELL_CHECKING */
}
static void
diff --git a/src/preferences-dialog.c b/src/preferences-dialog.c
index 11cdf33..3f9d912 100644
--- a/src/preferences-dialog.c
+++ b/src/preferences-dialog.c
@@ -22,13 +22,11 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
-#ifdef ENABLE_ENCRYPTION
#define LIBCRYPTUI_API_SUBJECT_TO_CHANGE
#include <cryptui-key-combo.h>
#include <cryptui-keyset.h>
#include <cryptui.h>
#include <atk/atk.h>
-#endif /* ENABLE_ENCRYPTION */
#include "preferences-dialog.h"
#include "interface.h"
@@ -37,19 +35,15 @@
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void almanah_preferences_dialog_dispose (GObject *object);
-#ifdef ENABLE_ENCRYPTION
static void pd_key_combo_changed_cb (GtkComboBox *combo_box, AlmanahPreferencesDialog *preferences_dialog);
static void pd_new_key_button_clicked_cb (GtkButton *button, AlmanahPreferencesDialog *preferences_dialog);
-#endif /* ENABLE_ENCRYPTION */
static void pd_response_cb (GtkDialog *dialog, gint response_id, AlmanahPreferencesDialog
*preferences_dialog);
struct _AlmanahPreferencesDialogPrivate {
GSettings *settings;
-#ifdef ENABLE_ENCRYPTION
CryptUIKeyset *keyset;
CryptUIKeyStore *key_store;
GtkComboBox *key_combo;
-#endif /* ENABLE_ENCRYPTION */
#ifdef ENABLE_SPELL_CHECKING
guint spell_checking_enabled_id;
GtkCheckButton *spell_checking_enabled_check_button;
@@ -98,7 +92,6 @@ almanah_preferences_dialog_dispose (GObject *object)
{
AlmanahPreferencesDialogPrivate *priv = ALMANAH_PREFERENCES_DIALOG (object)->priv;
-#ifdef ENABLE_ENCRYPTION
if (priv->keyset != NULL) {
g_object_unref (priv->keyset);
priv->keyset = NULL;
@@ -108,7 +101,6 @@ almanah_preferences_dialog_dispose (GObject *object)
g_object_unref (priv->key_store);
priv->key_store = NULL;
}
-#endif /* ENABLE_ENCRYPTION */
if (priv->settings != NULL)
g_object_unref (priv->settings);
@@ -163,11 +155,9 @@ almanah_preferences_dialog_new (GSettings *settings)
{
GtkBuilder *builder;
GtkTable *table;
-#ifdef ENABLE_ENCRYPTION
GtkWidget *label, *button;
AtkObject *a11y_label, *a11y_key_combo;
gchar *key;
-#endif /* ENABLE_ENCRYPTION */
AlmanahPreferencesDialog *preferences_dialog;
AlmanahPreferencesDialogPrivate *priv;
GError *error = NULL;
@@ -212,7 +202,6 @@ almanah_preferences_dialog_new (GSettings *settings)
priv->settings = g_object_ref (settings);
table = GTK_TABLE (gtk_builder_get_object (builder, "almanah_pd_table"));
-#ifdef ENABLE_ENCRYPTION
/* Grab our child widgets */
label = gtk_label_new (_("Encryption key: "));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
@@ -246,7 +235,6 @@ almanah_preferences_dialog_new (GSettings *settings)
button = gtk_button_new_with_mnemonic (_("New _Key"));
gtk_table_attach (table, button, 3, 4, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
g_signal_connect (button, "clicked", G_CALLBACK (pd_new_key_button_clicked_cb), preferences_dialog);
-#endif /* ENABLE_ENCRYPTION */
#ifdef ENABLE_SPELL_CHECKING
/* Set up the "Enable spell checking" check button */
@@ -261,7 +249,6 @@ almanah_preferences_dialog_new (GSettings *settings)
return preferences_dialog;
}
-#ifdef ENABLE_ENCRYPTION
static void
pd_key_combo_changed_cb (GtkComboBox *combo_box, AlmanahPreferencesDialog *preferences_dialog)
{
@@ -303,7 +290,6 @@ pd_new_key_button_clicked_cb (GtkButton *button, AlmanahPreferencesDialog *prefe
g_error_free (error);
}
}
-#endif /* ENABLE_ENCRYPTION */
static void
pd_response_cb (GtkDialog *dialog, gint response_id, AlmanahPreferencesDialog *preferences_dialog)
diff --git a/src/vfs.c b/src/vfs.c
index fd7a7bf..0fea3e4 100644
--- a/src/vfs.c
+++ b/src/vfs.c
@@ -36,19 +36,17 @@
#include <errno.h>
#include <fcntl.h>
+#define GCR_API_SUBJECT_TO_CHANGE
+#include <gcr/gcr-base.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
+#include <gpgme.h>
#include <config.h>
-#ifdef ENABLE_ENCRYPTION
-#define GCR_API_SUBJECT_TO_CHANGE
-#include <gcr/gcr-base.h>
-#include <gpgme.h>
#define ENCRYPTED_SUFFIX ".encrypted"
-#endif /* ENABLE_ENCRYPTION */
/*
** Size of the write buffer used by journal files in bytes.
@@ -78,20 +76,18 @@ struct _AlmanahSQLiteVFS
int nBuffer; /* Valid bytes of data in zBuffer */
sqlite3_int64 iBufferOfst; /* Offset in file of zBuffer[0] */
+ /* TODO: Unify in just one file */
gchar *plain_filename;
-#ifdef ENABLE_ENCRYPTION
gchar *encrypted_filename;
+
gboolean decrypted;
gpointer plain_buffer;
gsize plain_buffer_size; /* Reserved memory size */
goffset plain_offset;
gsize plain_size; /* Data size (plain_size <= plain_buffer_size) */
-#endif /* ENABLE_ENCRYPTION */
};
-#ifdef ENABLE_ENCRYPTION
-
typedef struct _CipherOperation CipherOperation;
typedef struct _GpgmeNpmClosure GpgmeNpmClosure;
@@ -465,8 +461,6 @@ get_encryption_key (void)
return encryption_key;
}
-#endif /* ENABLE_ENCRYPTION */
-
static gboolean
back_up_file (const gchar *filename)
{
@@ -513,7 +507,6 @@ demoDirectWrite (AlmanahSQLiteVFS *self, /* File handle */
off_t ofst;
size_t nWrite;
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted) {
if ((gsize) (offset + len) > self->plain_buffer_size) {
gsize new_size;
@@ -542,20 +535,19 @@ demoDirectWrite (AlmanahSQLiteVFS *self, /* File handle */
self->plain_size = MAX(self->plain_size, (gsize) (offset + len));
return SQLITE_OK;
- }
-#endif /* ENABLE_ENCRYPTION */
+ } else {
+ ofst = lseek (self->fd, offset, SEEK_SET);
+ if (ofst != offset) {
+ return SQLITE_IOERR_WRITE;
+ }
- ofst = lseek (self->fd, offset, SEEK_SET);
- if (ofst != offset) {
- return SQLITE_IOERR_WRITE;
- }
+ nWrite = write (self->fd, buffer, len);
+ if (nWrite != (size_t) len){
+ return SQLITE_IOERR_WRITE;
+ }
- nWrite = write (self->fd, buffer, len);
- if (nWrite != (size_t) len){
- return SQLITE_IOERR_WRITE;
+ return SQLITE_OK;
}
-
- return SQLITE_OK;
}
/*
@@ -566,16 +558,16 @@ demoDirectWrite (AlmanahSQLiteVFS *self, /* File handle */
static int
demoFlushBuffer (AlmanahSQLiteVFS *p)
{
-#ifdef ENABLE_ENCRYPTION
- if (p->decrypted)
- return SQLITE_OK;
-#endif /* ENABLE_ENCRYPTION */
int rc = SQLITE_OK;
+ if (p->decrypted)
+ return rc;
+
if (p->nBuffer) {
rc = demoDirectWrite(p, p->aBuffer, p->nBuffer, p->iBufferOfst);
p->nBuffer = 0;
}
+
return rc;
}
@@ -585,11 +577,10 @@ demoFlushBuffer (AlmanahSQLiteVFS *p)
static int
demoClose (sqlite3_file *pFile)
{
- int rc = SQLITE_OK;
AlmanahSQLiteVFS *self = (AlmanahSQLiteVFS*) pFile;
-#ifdef ENABLE_ENCRYPTION
gchar *encryption_key;
GError *child_error = NULL;
+ int rc;
/* TODO: This code is not completed */
@@ -600,7 +591,7 @@ demoClose (sqlite3_file *pFile)
encryption_key = get_encryption_key ();
if (encryption_key == NULL) {
/* TODO: No encryption key, so save in plain file from DB in memory,
- this happends when the user has changed from encrypted to no encrypted */
+ this happends when the user has changed from encrypted to non encrypted */
if (self->plain_buffer)
gcr_secure_memory_free (self->plain_buffer);
goto delete_encrypted_db;
@@ -616,21 +607,21 @@ demoClose (sqlite3_file *pFile)
if (encryption_key)
g_free (encryption_key);
- close_db:
-#endif /* ENABLE_ENCRYPTION */
+ return SQLITE_OK;
+ close_db:
rc = demoFlushBuffer (self);
+ if (rc != SQLITE_OK)
+ return rc;
sqlite3_free (self->aBuffer);
close (self->fd);
return SQLITE_OK;
-#ifdef ENABLE_ENCRYPTION
delete_encrypted_db:
/* Delete the old encrypted database and return */
g_unlink (self->encrypted_filename);
- return rc;
-#endif /* ENABLE_ENCRYPTION */
+ return SQLITE_OK;
}
/*
@@ -644,7 +635,6 @@ demoRead (sqlite3_file *pFile, void *buffer, int len, sqlite_int64 offset)
int nRead;
int rc;
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted) {
if ((gsize) (offset + len) > self->plain_size)
return SQLITE_IOERR_SHORT_READ;
@@ -653,7 +643,6 @@ demoRead (sqlite3_file *pFile, void *buffer, int len, sqlite_int64 offset)
return SQLITE_OK;
}
-#endif /* ENABLE_ENCRYPTION */
/* Flush any data in the write buffer to disk in case this operation
** is trying to read data the file-region currently cached in the buffer.
@@ -689,10 +678,8 @@ demoWrite (sqlite3_file *pFile, const void *buffer, int len, sqlite_int64 offse
{
AlmanahSQLiteVFS *self = (AlmanahSQLiteVFS*)pFile;
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted)
return demoDirectWrite (self, buffer, len, offset);
-#endif /* ENABLE_ENCRYPTION */
if (self->aBuffer) {
char *z = (char *)buffer; /* Pointer to remaining data to write */
@@ -727,11 +714,11 @@ demoWrite (sqlite3_file *pFile, const void *buffer, int len, sqlite_int64 offse
i += nCopy;
z += nCopy;
}
+
+ return SQLITE_OK;
} else {
return demoDirectWrite (self, buffer, len, offset);
}
-
- return SQLITE_OK;
}
/*
@@ -754,16 +741,14 @@ demoTruncate(sqlite3_file *pFile, sqlite_int64 size)
static int
demoSync (sqlite3_file *pFile, __attribute__ ((unused)) int flags)
{
+ int rc;
AlmanahSQLiteVFS *self = (AlmanahSQLiteVFS*) pFile;
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted)
return SQLITE_OK;
-#endif
- int rc;
rc = demoFlushBuffer (self);
- if (rc!=SQLITE_OK) {
+ if (rc != SQLITE_OK) {
return rc;
}
@@ -781,12 +766,10 @@ demoFileSize (sqlite3_file *pFile, sqlite_int64 *pSize)
int rc; /* Return code from fstat() call */
struct stat sStat; /* Output of fstat() call */
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted) {
*pSize = self->plain_size;
return SQLITE_OK;
}
-#endif
/* Flush the contents of the buffer to disk. As with the flush in the
** demoRead() method, it would be possible to avoid this and save a write
@@ -803,6 +786,7 @@ demoFileSize (sqlite3_file *pFile, sqlite_int64 *pSize)
return SQLITE_IOERR_FSTAT;
*pSize = sStat.st_size;
+
return SQLITE_OK;
}
@@ -872,10 +856,8 @@ demoOpen (__attribute__ ((unused)) sqlite3_vfs *pVfs, /* VFS */
AlmanahSQLiteVFS *self = (AlmanahSQLiteVFS*) pFile; /* Populate this structure */
int oflags = 0; /* flags to pass to open() call */
char *aBuf = NULL;
-#ifdef ENABLE_ENCRYPTION
struct stat encrypted_db_stat, plaintext_db_stat;
GError *child_error = NULL;
-#endif
if (zName == 0) {
return SQLITE_IOERR;
@@ -893,7 +875,6 @@ demoOpen (__attribute__ ((unused)) sqlite3_vfs *pVfs, /* VFS */
self->plain_filename = g_strdup (zName);
self->decrypted = FALSE;
-#ifdef ENABLE_ENCRYPTION
if (flags & SQLITE_OPEN_MAIN_DB) {
self->encrypted_filename = g_strdup_printf ("%s%s", self->plain_filename, ENCRYPTED_SUFFIX);
@@ -932,57 +913,46 @@ demoOpen (__attribute__ ((unused)) sqlite3_vfs *pVfs, /* VFS */
} else
self->decrypted = TRUE;
}
+ } else {
+ /* Make a backup of the plaintext database file */
+ if (back_up_file (self->plain_filename) != TRUE) {
+ /* Translators: the first parameter is a filename. */
+ g_warning (_("Error backing up file ‘%s’"), self->plain_filename);
+ g_clear_error (&child_error);
+ }
}
}
-#else
- if (flags & SQLITE_OPEN_MAIN_DB) {
- /* Make a backup of the plaintext database file */
- if (back_up_file (self->plain_filename) != TRUE) {
- /* Translators: the first parameter is a filename. */
- g_warning (_("Error backing up file ‘%s’"), self->priv->plain_filename);
- g_clear_error (&child_error);
- }
- }
- self->decrypted = FALSE;
-#endif /* ENABLE_ENCRYPTION */
-
-#ifdef ENABLE_ENCRYPTION
if (self->decrypted) {
sqlite3_free (aBuf);
*pOutFlags = 0;
} else {
-#endif /* ENABLE_ENCRYPTION */
-
- if (flags & SQLITE_OPEN_EXCLUSIVE) oflags |= O_EXCL;
- if (flags & SQLITE_OPEN_CREATE) oflags |= O_CREAT;
- if (flags & SQLITE_OPEN_READONLY) oflags |= O_RDONLY;
- if (flags & SQLITE_OPEN_READWRITE) oflags |= O_RDWR;
-
- self->fd = open (self->plain_filename, oflags, 0600);
- if (self->fd < 0) {
- sqlite3_free (aBuf);
- return SQLITE_CANTOPEN;
- }
-
- if (g_chmod (self->plain_filename, 0600) != 0 && errno != ENOENT) {
- g_critical (_("Error changing database file permissions: %s"), g_strerror (errno));
- sqlite3_free (aBuf);
- g_free (self->plain_filename);
- g_free (self->encrypted_filename);
- close (self->fd);
- return SQLITE_IOERR;
- }
+ if (flags & SQLITE_OPEN_EXCLUSIVE) oflags |= O_EXCL;
+ if (flags & SQLITE_OPEN_CREATE) oflags |= O_CREAT;
+ if (flags & SQLITE_OPEN_READONLY) oflags |= O_RDONLY;
+ if (flags & SQLITE_OPEN_READWRITE) oflags |= O_RDWR;
+
+ self->fd = open (self->plain_filename, oflags, 0600);
+ if (self->fd < 0) {
+ sqlite3_free (aBuf);
+ return SQLITE_CANTOPEN;
+ }
- self->aBuffer = aBuf;
+ if (g_chmod (self->plain_filename, 0600) != 0 && errno != ENOENT) {
+ g_critical (_("Error changing database file permissions: %s"), g_strerror (errno));
+ sqlite3_free (aBuf);
+ g_free (self->plain_filename);
+ g_free (self->encrypted_filename);
+ close (self->fd);
+ return SQLITE_IOERR;
+ }
- if (pOutFlags) {
- *pOutFlags = flags;
- }
+ self->aBuffer = aBuf;
-#ifdef ENABLE_ENCRYPTION
+ if (pOutFlags) {
+ *pOutFlags = flags;
+ }
}
-#endif /* ENABLE_ENCRYPTION */
self->base.pMethods = &demoio;
@@ -1045,16 +1015,17 @@ demoAccess (__attribute__ ((unused)) sqlite3_vfs *pVfs, const char *zPath, int f
int rc; /* access() return code */
int eAccess = F_OK; /* Second argument to access() */
- assert( flags==SQLITE_ACCESS_EXISTS /* access(zPath, F_OK) */
+ assert (flags==SQLITE_ACCESS_EXISTS /* access(zPath, F_OK) */
|| flags==SQLITE_ACCESS_READ /* access(zPath, R_OK) */
|| flags==SQLITE_ACCESS_READWRITE /* access(zPath, R_OK|W_OK) */
);
- if( flags==SQLITE_ACCESS_READWRITE ) eAccess = R_OK|W_OK;
- if( flags==SQLITE_ACCESS_READ ) eAccess = R_OK;
+ if (flags==SQLITE_ACCESS_READWRITE) eAccess = R_OK|W_OK;
+ if (flags==SQLITE_ACCESS_READ) eAccess = R_OK;
- rc = access(zPath, eAccess);
+ rc = access (zPath, eAccess);
*pResOut = (rc==0);
+
return SQLITE_OK;
}
@@ -1073,14 +1044,15 @@ static int
demoFullPathname (__attribute__ ((unused)) sqlite3_vfs *pVfs, const char *zPath, int nPathOut, char
*zPathOut)
{
char zDir[MAXPATHNAME+1];
- if( zPath[0]=='/' ){
+
+ if (zPath[0] == '/') {
zDir[0] = '\0';
- }else{
- getcwd(zDir, sizeof(zDir));
+ } else {
+ getcwd (zDir, sizeof (zDir));
}
zDir[MAXPATHNAME] = '\0';
- sqlite3_snprintf(nPathOut, zPathOut, "%s/%s", zDir, zPath);
+ sqlite3_snprintf (nPathOut, zPathOut, "%s/%s", zDir, zPath);
zPathOut[nPathOut-1] = '\0';
return SQLITE_OK;
@@ -1107,7 +1079,7 @@ demoDlOpen (__attribute__ ((unused)) sqlite3_vfs *pVfs, __attribute__ ((unused))
static void
demoDlError(__attribute__ ((unused)) sqlite3_vfs *pVfs, int nByte, char *zErrMsg)
{
- sqlite3_snprintf(nByte, zErrMsg, "Loadable extensions are not supported");
+ sqlite3_snprintf (nByte, zErrMsg, "Loadable extensions are not supported");
zErrMsg[nByte-1] = '\0';
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]