@@ -67,19 +67,13 @@ typedef struct {
67
67
void * provider_ctx ;
68
68
} cipher_ctx ;
69
69
70
- typedef struct {
71
- sqlite3_file * file ;
72
- char * filename ;
73
- } profile_ctx ;
74
-
75
70
static unsigned int default_flags = DEFAULT_CIPHER_FLAGS ;
76
71
static unsigned char hmac_salt_mask = HMAC_SALT_MASK ;
77
72
static int default_kdf_iter = PBKDF2_ITER ;
78
73
static int default_page_size = SQLITE_DEFAULT_PAGE_SIZE ;
79
74
static unsigned int sqlcipher_activate_count = 0 ;
80
75
static sqlite3_mutex * sqlcipher_provider_mutex = NULL ;
81
76
static sqlcipher_provider * default_provider = NULL ;
82
- static profile_ctx * profile = NULL ;
83
77
84
78
struct codec_ctx {
85
79
int kdf_salt_sz ;
@@ -1211,54 +1205,27 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz
1211
1205
}
1212
1206
1213
1207
int 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 ){
1240
1218
return SQLITE_ERROR ;
1241
1219
}
1242
1220
}
1243
- sqlite3_profile (db , sqlcipher_profile_callback , profile );
1221
+ sqlite3_profile (db , sqlcipher_profile_callback , f );
1244
1222
return SQLITE_OK ;
1245
1223
}
1246
1224
1247
1225
static 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 );
1262
1229
}
1263
1230
1264
1231
int sqlcipher_codec_fips_status (codec_ctx * ctx ) {
0 commit comments