diff --git a/.gitignore b/.gitignore index 2443226..f68644e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ xcuserdata/* /sqlcipher.pc /sqlite3ext.h /libsqlcipher.la +/.DS_Store diff --git a/src/crypto.c b/src/crypto.c index e326840..b9fb815 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -89,6 +89,12 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef CODEC_TRACE(("sqlcipher_codec_pragma: entered db=%p iDb=%d pParse=%p zLeft=%s zRight=%s ctx=%p\n", db, iDb, pParse, zLeft, zRight, ctx)); + + if( sqlite3StrICmp(zLeft, "cipher_profile")== 0 && zRight ){ + char *profile_status = sqlite3_mprintf("%d", sqlcipher_cipher_profile(db, zRight)); + codec_vdbe_return_static_string(pParse, "cipher_profile", profile_status); + sqlite3_free(profile_status); + } else if( sqlite3StrICmp(zLeft, "cipher_add_random")==0 && zRight ){ if(ctx) { char *add_random_status = sqlite3_mprintf("%d", sqlcipher_codec_add_random(ctx, zRight, sqlite3Strlen30(zRight))); @@ -243,6 +249,7 @@ int sqlcipher_codec_pragma(sqlite3* db, int iDb, Parse *pParse, const char *zLef return 1; } + /* * sqlite3Codec can be called in multiple modes. * encrypt mode - expected to return a pointer to the diff --git a/src/crypto.h b/src/crypto.h index 7b76c08..dad6128 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -214,6 +214,8 @@ int sqlcipher_codec_ctx_get_flag(codec_ctx *ctx, unsigned int flag, int for_ctx) const char* sqlcipher_codec_get_cipher_provider(codec_ctx *ctx); int sqlcipher_codec_ctx_migrate(codec_ctx *ctx); int sqlcipher_codec_add_random(codec_ctx *ctx, const char *data, int random_sz); +int sqlcipher_cipher_profile(sqlite3 *db, const char *destination); +static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time); #endif #endif /* END SQLCIPHER */ diff --git a/src/crypto_impl.c b/src/crypto_impl.c index 2170f20..d84f22b 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -1146,6 +1146,30 @@ int sqlcipher_codec_add_random(codec_ctx *ctx, const char *zRight, int random_sz return SQLITE_ERROR; } +int sqlcipher_cipher_profile(sqlite3 *db, const char *destination){ + FILE *f; + if( strcmp(destination,"stdout")==0 ){ + f = stdout; + }else if( strcmp(destination, "stderr")==0 ){ + f = stderr; + }else if( strcmp(destination, "off")==0 ){ + f = 0; + }else{ + f = fopen(destination, "wb"); + if( f==0 ){ + return SQLITE_ERROR; + } + } + sqlite3_profile(db, sqlcipher_profile_callback, f); + return SQLITE_OK; +} + +static void sqlcipher_profile_callback(void *file, const char *sql, sqlite3_uint64 run_time){ + FILE *f = (FILE*)file; + double elapsed = run_time/1000000.0; + if( f ) fprintf(f, "Elapsed time:%.3f ms - %s\n", elapsed, sql); +} + #endif /* END SQLCIPHER */