@@ -67,19 +67,13 @@ typedef struct {
6767 void * provider_ctx ;
6868} cipher_ctx ;
6969
70- typedef struct {
71- sqlite3_file * file ;
72- char * filename ;
73- } profile_ctx ;
74-
7570static unsigned int default_flags = DEFAULT_CIPHER_FLAGS ;
7671static unsigned char hmac_salt_mask = HMAC_SALT_MASK ;
7772static int default_kdf_iter = PBKDF2_ITER ;
7873static int default_page_size = SQLITE_DEFAULT_PAGE_SIZE ;
7974static unsigned int sqlcipher_activate_count = 0 ;
8075static sqlite3_mutex * sqlcipher_provider_mutex = NULL ;
8176static sqlcipher_provider * default_provider = NULL ;
82- static profile_ctx * profile = NULL ;
8377
8478struct codec_ctx {
8579 int kdf_salt_sz ;
@@ -1211,54 +1205,27 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz
12111205}
12121206
12131207int sqlcipher_cipher_profile (sqlite3 * db , const char * destination ){
1214- int rc ;
1215- sqlite3_vfs * pVfs ;
1216- if (profile == NULL ){
1217- profile = sqlcipher_malloc (sizeof (profile_ctx ));
1218- }
1219- if (strcmp (destination , "off" ) == 0 ){
1220- if (profile != NULL && profile -> filename != NULL ){
1221- if (strcmp (profile -> filename , "/dev/stdout" ) != 0 &&
1222- strcmp (profile -> filename , "/dev/stderr" ) != 0 ) {
1223- sqlite3OsCloseFree (profile -> file );
1224- }
1225- sqlcipher_free (profile , sizeof (profile ));
1226- profile = NULL ;
1227- }
1228- } else {
1229- if (strcmp (destination ,"stdout" )== 0 ){
1230- profile -> filename = "/dev/stdout" ;
1231- } else if (strcmp (destination , "stderr" )== 0 ){
1232- profile -> filename = "/dev/stderr" ;
1233- } else {
1234- profile -> filename = (char * )destination ;
1235- }
1236- pVfs = sqlite3_vfs_find (0 );
1237- rc = sqlite3OsOpenMalloc (pVfs , profile -> filename , & (profile -> file ),
1238- (SQLITE_OPEN_CREATE |SQLITE_OPEN_READWRITE ), 0 );
1239- if (rc ){
1208+ FILE * f ;
1209+ if ( strcmp (destination ,"stdout" )== 0 ){
1210+ f = stdout ;
1211+ }else if ( strcmp (destination , "stderr" )== 0 ){
1212+ f = stderr ;
1213+ }else if ( strcmp (destination , "off" )== 0 ){
1214+ f = 0 ;
1215+ }else {
1216+ f = fopen (destination , "wb" );
1217+ if ( f == 0 ){
12401218 return SQLITE_ERROR ;
12411219 }
12421220 }
1243- sqlite3_profile (db , sqlcipher_profile_callback , profile );
1221+ sqlite3_profile (db , sqlcipher_profile_callback , f );
12441222 return SQLITE_OK ;
12451223}
12461224
12471225static void sqlcipher_profile_callback (void * file , const char * sql , sqlite3_uint64 run_time ){
1248- i64 log_file_sz = 0 ;
1249- double elapsed = 0.0 ;
1250- char * log_message = 0 ;
1251- int log_message_sz = 0 ;
1252- profile_ctx * pro = (profile_ctx * )file ;
1253- CODEC_TRACE (("sqlcipher_profile_callback entered file:%p, sql:%s runtime:%llu\n" , file , sql , run_time ));
1254- if (pro != NULL && pro -> file != NULL ) {
1255- elapsed = run_time /1000000.0 ;
1256- log_message = sqlite3_mprintf ("Elapsed time:%.3f ms - %s\n" , elapsed , sql );
1257- log_message_sz = sqlite3Strlen30 (log_message );
1258- sqlite3OsFileSize (pro -> file , & log_file_sz );
1259- sqlite3OsWrite (pro -> file , log_message , log_message_sz , log_file_sz );
1260- sqlite3_free (log_message );
1261- }
1226+ FILE * f = (FILE * )file ;
1227+ double elapsed = run_time /1000000.0 ;
1228+ if ( f ) fprintf (f , "Elapsed time:%.3f ms - %s\n" , elapsed , sql );
12621229}
12631230
12641231int sqlcipher_codec_fips_status (codec_ctx * ctx ) {
0 commit comments