/** @brief Path to zrtp cache file (set if you use built-in realization) */
zrtp_string256_t def_cache_path;
+
+ /**
+ * @brief Flush the cache automatically
+ * Set to 1 if you want libzrtp to flush the cache to the persistent storage
+ * right after it is modified. If cache_auto_store is 0, libzrtp will flush
+ * the cache on going down only and the app is responsible for storing the
+ * cache in unexpected situations. Enabled by default.
+ *
+ * @sa zrtp_def_cache_store()
+ */
+ unsigned cache_auto_store;
} zrtp_config_t;
/**
ZSTR_SET_EMPTY(config->def_cache_path);
zrtp_zstrncpyc(ZSTR_GV(config->def_cache_path), "./zrtp_def_cache_path.dat", 25);
+ config->cache_auto_store = 1; /* cache auto flushing should be enabled by default */
+
#if (defined(ZRTP_USE_BUILTIN_CACHE) && (ZRTP_USE_BUILTIN_CACHE == 1))
config->cb.cache_cb.on_init = zrtp_def_cache_init;
config->cb.cache_cb.on_down = zrtp_def_cache_down;
ZSTR_SET_EMPTY(new_zrtp->def_cache_path);
zrtp_zstrcpy(ZSTR_GV(new_zrtp->def_cache_path), ZSTR_GV(config->def_cache_path));
zrtp_memcpy(&new_zrtp->cb, &config->cb, sizeof(zrtp_callback_t));
+ new_zrtp->cache_auto_store = config->cache_auto_store;
ZSTR_SET_EMPTY(new_zrtp->client_id);
zrtp_memset(new_zrtp->client_id.buffer, ' ', sizeof(zrtp_client_id_t));
if (inited) {
mlist_t *node = NULL, *tmp = NULL;
- zrtp_cache_user_down();
+ /* If automatic cache flushing enabled we don't need to store it in a disk as it should be already in sync. */
+ if (!zrtp->cache_auto_store)
+ zrtp_cache_user_down();
mlist_for_each_safe(node, tmp, &cache_head) {
zrtp_sys_free(mlist_get_struct(zrtp_cache_elem_t, _mlist, node));
}
zrtp_mutex_unlock(def_cache_protector);
+ if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
+
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
}
} while (0);
zrtp_mutex_unlock(def_cache_protector);
+ if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
+
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
}
}
zrtp_mutex_unlock(def_cache_protector);
+ if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
+
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
}
} while (0);
zrtp_mutex_unlock(def_cache_protector);
+ if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
+
return s;
}
}
zrtp_mutex_unlock(def_cache_protector);
+ if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
+
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
}