sqlite3: Enabling option to disable filesystem locking (POSIX advisory locks)

When sqlite database is expected to be stored on a NFS disk (e.g., a
home directory and ~/.ndnx/ndnsec-public-info.db is on NFS mount),
default POSIX advisory filesystem locks may not work properly, since
some NFS implementation do not support them.  This commit allows
specification of ``--without-sqlite-locking`` to use alternative
"dotfile" sqlite locking mechanism.

Change-Id: Iddee82c6ca7839f993147547f61c440184689043
diff --git a/src/security/sec-public-info-sqlite3.cpp b/src/security/sec-public-info-sqlite3.cpp
index 7e6f4c8..43dc641 100644
--- a/src/security/sec-public-info-sqlite3.cpp
+++ b/src/security/sec-public-info-sqlite3.cpp
@@ -88,9 +88,16 @@
 {
   boost::filesystem::path identityDir = boost::filesystem::path(getenv("HOME")) / ".ndnx";
   boost::filesystem::create_directories (identityDir);
-  
-  int res = sqlite3_open((identityDir / "ndnsec-public-info.db").c_str(), &m_database);
 
+  /// @todo Add define for windows/unix in wscript. The following may completely fail on windows
+  int res = sqlite3_open_v2((identityDir / "ndnsec-public-info.db").c_str(), &m_database,
+                            SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
+#ifdef DISABLE_SQLITE3_FS_LOCKING
+                            "unix-dotfile"
+#else
+                            0
+#endif
+                            );
   if (res != SQLITE_OK)
     throw Error("identity DB cannot be opened/created");
   
diff --git a/wscript b/wscript
index 682df49..079ceeb 100644
--- a/wscript
+++ b/wscript
@@ -24,6 +24,9 @@
     opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
                    help='''Do not build tools''')
 
+    opt.add_option('--without-sqlite-locking', action='store_false', default=True, dest='with_sqlite_locking',
+                   help='''Disable filesystem locking in sqlite3 database (use unix-dot locking mechanism instead). '''
+                   '''This option may be necessary if home directory is hosted on NFS.''')
 
 def configure(conf):
     conf.load("compiler_c compiler_cxx boost gnu_dirs c_osx openssl cryptopp")
@@ -105,6 +108,9 @@
     conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD', mandatory=False)
     conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
 
+    if not conf.options.with_sqlite_locking:
+        conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
+    
     conf.write_config_header('src/ndn-cpp-config.h', define_prefix='NDN_CPP_')
 
 def build (bld):