Commit 6a285161 authored by Mickaël Turnel's avatar Mickaël Turnel

Zrtp cache access thread safe

restricted do regular zrtp operations and getPeerStatus

To be completed for lime v1 access

(cherry picked from commit 1a0d5bad)

# Conflicts:
#	coreapi/linphonecore.c
parent 77ee43db
......@@ -6657,7 +6657,8 @@ void linphone_core_set_zrtp_secrets_file(LinphoneCore *lc, const char* file){
char *bkpFile = reinterpret_cast<char *>(bctbx_malloc(strlen(file)+6));
sprintf(bkpFile,"%s.bkp", file);
char *selfURI = linphone_address_as_string_uri_only(linphone_proxy_config_get_identity_address(proxy));
if ((ret = ms_zrtp_cache_migration((void *)cacheXml, linphone_core_get_zrtp_cache_db(lc), selfURI)) == 0) {
zrtpCacheAccess zrtpCacheInfo = linphone_core_get_zrtp_cache_access(lc);
if ((ret = ms_zrtp_cache_migration((void *)cacheXml, zrtpCacheInfo.db, selfURI)) == 0) {
ms_message("LIME/ZRTP cache migration successfull, obsolete xml file kept as backup in %s", bkpFile);
} else {
ms_error("LIME/ZRTP cache migration failed(returned -%x), start with a fresh cache, old one kept as backup in %s", -ret, bkpFile);
......@@ -6695,13 +6696,30 @@ const char *linphone_core_get_zrtp_secrets_file(LinphoneCore *lc){
return lc->zrtp_secrets_cache;
}
zrtpCacheAccess linphone_core_get_zrtp_cache_access(LinphoneCore *lc){
zrtpCacheAccess ret;
#ifdef SQLITE_STORAGE_ENABLED
ret.db = (void *)lc->zrtp_cache_db;
ret.dbMutex = &(lc->zrtp_cache_db_mutex);
#else /* SQITE_STORAGE_ENABLED */
ret.db = NULL;
ret.dbMutex = NULL;
#endif /* SQLITE_STORAGE_ENABLED */
return ret;
}
void *linphone_core_get_zrtp_cache_db(LinphoneCore *lc){
return (void *)lc->zrtp_cache_db;
#ifdef SQLITE_STORAGE_ENABLED
return (void *)lc->zrtp_cache_db
#else /* SQLITE_STORAGE_ENABLED */
return NULL;
#endif /* SQLITE_STORAGE_ENABLED */
}
static void linphone_core_zrtp_cache_close(LinphoneCore *lc) {
if (lc->zrtp_cache_db) {
sqlite3_close(lc->zrtp_cache_db);
bctbx_mutex_destroy(&(lc->zrtp_cache_db_mutex));
lc->zrtp_cache_db = NULL;
}
}
......@@ -6716,6 +6734,8 @@ void linphone_core_zrtp_cache_db_init(LinphoneCore *lc, const char *fileName) {
linphone_core_zrtp_cache_close(lc);
bctbx_mutex_init(&(lc->zrtp_cache_db_mutex), NULL);
ret = _linphone_sqlite3_open(fileName, &db);
if (ret != SQLITE_OK) {
errmsg = sqlite3_errmsg(db);
......@@ -6727,7 +6747,7 @@ void linphone_core_zrtp_cache_db_init(LinphoneCore *lc, const char *fileName) {
goto end;
}
ret = ms_zrtp_initCache((void *)db); /* this may perform an update, check return value */
ret = ms_zrtp_initCache((void *)db, &(lc->zrtp_cache_db_mutex)); /* this may perform an update, check return value */
if (ret == MSZRTP_CACHE_SETUP || ret == MSZRTP_CACHE_UPDATE) {
/* After updating schema, database need to be closed/reopenned */
......
......@@ -829,6 +829,7 @@ namespace LinphonePrivate {
#define LINPHONE_CORE_STRUCT_FIELDS \
LINPHONE_CORE_STRUCT_BASE_FIELDS \
sqlite3 *zrtp_cache_db; \
bctbx_mutex_t zrtp_cache_db_mutex; \
sqlite3 *logs_db; \
sqlite3 *friends_db; \
bool_t debug_storage;
......
......@@ -4265,7 +4265,22 @@ LINPHONE_PUBLIC const char *linphone_core_get_zrtp_secrets_file(LinphoneCore *lc
* @return An sqlite3 pointer cast to a void one or NULL if cache is not available(not enabled at compile or access failed)
* @ingroup initializing
*/
LINPHONE_PUBLIC void *linphone_core_get_zrtp_cache_db(LinphoneCore *lc);
LINPHONE_PUBLIC LINPHONE_DEPRECATED void *linphone_core_get_zrtp_cache_db(LinphoneCore *lc);
struct _zrtpCacheAccess{
void *db; /**< points to the zrtp cache sqlite database, is cast into a void * to support cacheless build */
bctbx_mutex_t *dbMutex; /**< the mutex used to prevent conflicting access to the database */
};
typedef struct _zrtpCacheAccess zrtpCacheAccess;
/**
* Get a pointer to a structure holding pointers to access zrtp/lime cache.
* The structure will hold a sqlite db pointer and a bctoolbox mutex pointer
*
* @param[in] lc #LinphoneCore object.
* @return a structure holding db pointer(NULL is cache is not available by built or runtime error) and the mutex associated to it
*/
LINPHONE_PUBLIC zrtpCacheAccess linphone_core_get_zrtp_cache_access(LinphoneCore *lc);
/**
* Set the path to the directory storing the user's x509 certificates (used by dtls)
......
......@@ -2440,10 +2440,14 @@ void MediaSessionPrivate::initializeAudioStream () {
char *selfUri = ms_strdup_printf("%s:%s@%s" , linphone_address_get_scheme(selfAddr)
, linphone_address_get_username(selfAddr)
, linphone_address_get_domain(selfAddr));
MSZrtpParams params;
zrtpCacheAccess zrtpCacheInfo = linphone_core_get_zrtp_cache_access(q->getCore()->getCCore());
memset(&params, 0, sizeof(MSZrtpParams));
/* media encryption of current params will be set later when zrtp is activated */
params.zidCacheDB = linphone_core_get_zrtp_cache_db(q->getCore()->getCCore());
params.zidCacheDB = zrtpCacheInfo.db;
params.zidCacheDBMutex = zrtpCacheInfo.dbMutex;
params.peerUri = peerUri;
params.selfUri = selfUri;
/* Get key lifespan from config file, default is 0:forever valid */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment