3
3
** Purpose: Amalgamation of the SQLite3 Multiple Ciphers encryption extension for SQLite
4
4
** Author: Ulrich Telle
5
5
** Created: 2020-02-28
6
- ** Copyright: (c) 2006-2024 Ulrich Telle
6
+ ** Copyright: (c) 2006-2025 Ulrich Telle
7
7
** License: MIT
8
8
*/
9
9
37
37
#endif
38
38
#endif
39
39
40
- /*
41
- ** Define function for extra initialization and extra shutdown
42
- **
43
- ** The extra initialization function registers an extension function
44
- ** which will be automatically executed for each new database connection.
45
- **
46
- ** The extra shutdown function will be executed on the invocation of sqlite3_shutdown.
47
- ** All created multiple ciphers VFSs will be unregistered and destroyed.
48
- */
49
-
50
- #define SQLITE_EXTRA_INIT sqlite3mc_initialize
51
- #define SQLITE_EXTRA_SHUTDOWN sqlite3mc_shutdown
52
-
53
40
/*
54
41
** Declare all internal functions as 'static' unless told otherwise
55
42
*/
@@ -538,8 +525,6 @@ sqlite3mcRegisterCipher(const CipherDescriptor* desc, const CipherParams* params
538
525
if (!cipherParams )
539
526
return SQLITE_NOMEM ;
540
527
541
- sqlite3_mutex_enter (sqlite3_mutex_alloc (SQLITE_MUTEX_STATIC_MAIN ));
542
-
543
528
/* Check for */
544
529
if (globalCipherCount < CODEC_COUNT_MAX )
545
530
{
@@ -589,8 +574,6 @@ sqlite3mcRegisterCipher(const CipherDescriptor* desc, const CipherParams* params
589
574
rc = SQLITE_NOMEM ;
590
575
}
591
576
592
- sqlite3_mutex_leave (sqlite3_mutex_alloc (SQLITE_MUTEX_STATIC_MAIN ));
593
-
594
577
return rc ;
595
578
}
596
579
@@ -602,7 +585,10 @@ sqlite3mc_register_cipher(const CipherDescriptor* desc, const CipherParams* para
602
585
rc = sqlite3_initialize ();
603
586
if (rc ) return rc ;
604
587
#endif
605
- return sqlite3mcRegisterCipher (desc , params , makeDefault );
588
+ sqlite3_mutex_enter (sqlite3_mutex_alloc (SQLITE_MUTEX_STATIC_MAIN ));
589
+ rc = sqlite3mcRegisterCipher (desc , params , makeDefault );
590
+ sqlite3_mutex_leave (sqlite3_mutex_alloc (SQLITE_MUTEX_STATIC_MAIN ));
591
+ return rc ;
606
592
}
607
593
608
594
SQLITE_PRIVATE int
@@ -718,84 +704,92 @@ sqlite3mc_initialize(const char* arg)
718
704
{
719
705
rc = sqlite3mc_vfs_create (NULL , 1 );
720
706
}
707
+ return rc ;
708
+ }
709
+
710
+ SQLITE_PRIVATE int
711
+ sqlite3mc_builtin_extensions (sqlite3 * db )
712
+ {
713
+ char * errmsg = NULL ;
714
+ int rc = SQLITE_OK ;
721
715
722
716
/*
723
717
** Register Multi Cipher extension
724
718
*/
725
719
if (rc == SQLITE_OK )
726
720
{
727
- rc = sqlite3_auto_extension (( void ( * )( void )) mcRegisterCodecExtensions );
721
+ rc = mcRegisterCodecExtensions ( db , & errmsg , NULL );
728
722
}
729
723
#ifdef SQLITE_ENABLE_EXTFUNC
730
724
if (rc == SQLITE_OK )
731
725
{
732
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_extfunc_init );
726
+ rc = sqlite3_extfunc_init ( db , & errmsg , NULL );
733
727
}
734
728
#endif
735
729
#ifdef SQLITE_ENABLE_CSV
736
730
if (rc == SQLITE_OK )
737
731
{
738
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_csv_init );
732
+ rc = sqlite3_csv_init ( db , & errmsg , NULL );
739
733
}
740
734
#endif
741
735
#ifdef SQLITE_ENABLE_VSV
742
736
if (rc == SQLITE_OK )
743
737
{
744
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_vsv_init );
738
+ rc = sqlite3_vsv_init ( db , & errmsg , NULL );
745
739
}
746
740
#endif
747
741
#ifdef SQLITE_ENABLE_SHA3
748
742
if (rc == SQLITE_OK )
749
743
{
750
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_shathree_init );
744
+ rc = sqlite3_shathree_init ( db , & errmsg , NULL );
751
745
}
752
746
#endif
753
747
#ifdef SQLITE_ENABLE_CARRAY
754
748
if (rc == SQLITE_OK )
755
749
{
756
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_carray_init );
750
+ rc = sqlite3_carray_init ( db , & errmsg , NULL );
757
751
}
758
752
#endif
759
753
#ifdef SQLITE_ENABLE_FILEIO
760
754
if (rc == SQLITE_OK )
761
755
{
762
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_fileio_init );
756
+ rc = sqlite3_fileio_init ( db , & errmsg , NULL );
763
757
}
764
758
#endif
765
759
#ifdef SQLITE_ENABLE_SERIES
766
760
if (rc == SQLITE_OK )
767
761
{
768
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_series_init );
762
+ rc = sqlite3_series_init ( db , & errmsg , NULL );
769
763
}
770
764
#endif
771
765
#ifdef SQLITE_ENABLE_UUID
772
766
if (rc == SQLITE_OK )
773
767
{
774
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_uuid_init );
768
+ rc = sqlite3_uuid_init ( db , & errmsg , NULL );
775
769
}
776
770
#endif
777
771
#ifdef SQLITE_ENABLE_REGEXP
778
772
if (rc == SQLITE_OK )
779
773
{
780
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_regexp_init );
774
+ rc = sqlite3_regexp_init ( db , & errmsg , NULL );
781
775
}
782
776
#endif
783
777
#ifdef SQLITE_ENABLE_COMPRESS
784
778
if (rc == SQLITE_OK )
785
779
{
786
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_compress_init );
780
+ rc = sqlite3_compress_init ( db , & errmsg , NULL );
787
781
}
788
782
#endif
789
783
#ifdef SQLITE_ENABLE_SQLAR
790
784
if (rc == SQLITE_OK )
791
785
{
792
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_sqlar_init );
786
+ rc = sqlite3_sqlar_init ( db , & errmsg , NULL );
793
787
}
794
788
#endif
795
789
#ifdef SQLITE_ENABLE_ZIPFILE
796
790
if (rc == SQLITE_OK )
797
791
{
798
- rc = sqlite3_auto_extension (( void ( * )( void )) sqlite3_zipfile_init );
792
+ rc = sqlite3_zipfile_init ( db , & errmsg , NULL );
799
793
}
800
794
#endif
801
795
return rc ;
0 commit comments