[vlc-devel] [PATCH 01/10][RFC][WIP] keystore: add the possibility to delete credentials
Diogo Silva
dbtdsilva at gmail.com
Thu Aug 17 03:08:09 CEST 2017
---
include/vlc_keystore.h | 14 ++++++++++++++
src/libvlccore.sym | 1 +
src/misc/keystore.c | 34 ++++++++++++++++++++++++++++------
3 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/include/vlc_keystore.h b/include/vlc_keystore.h
index 0af15eb90e..5559a0d501 100644
--- a/include/vlc_keystore.h
+++ b/include/vlc_keystore.h
@@ -258,6 +258,20 @@ vlc_credential_store(vlc_credential *p_credential, vlc_object_t *p_parent);
#define vlc_credential_store(a, b) \
vlc_credential_store(a, VLC_OBJECT(b))
+/**
+ * Deletes the last credential returned by vlc_credential_get() if it was ever
+ * stored before.
+ *
+ * This function will delete the credential from the memory or permament
+ * keystore depending on its current location or even if it was ever stored.
+ *
+ * @return true if the credential was deleted, false otherwise
+ */
+VLC_API bool
+vlc_credential_delete(vlc_credential *p_credential, vlc_object_t *p_parent);
+#define vlc_credential_delete(a, b) \
+ vlc_credential_delete(a, VLC_OBJECT(b))
+
/**
* @}
* @defgroup keystore_implementation Implemented by keystore modules
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f9a82d7a51..ab9cb15890 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -533,6 +533,7 @@ vlc_credential_init
vlc_credential_clean
vlc_credential_get
vlc_credential_store
+vlc_credential_delete
vlc_dialog_display_error
vlc_dialog_display_error_va
vlc_dialog_display_progress
diff --git a/src/misc/keystore.c b/src/misc/keystore.c
index 02537f00a8..ba8224ed89 100644
--- a/src/misc/keystore.c
+++ b/src/misc/keystore.c
@@ -439,9 +439,6 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
case GET_FROM_MEMORY_KEYSTORE:
{
- if (!psz_dialog_title || !psz_dialog_fmt)
- return false;
-
vlc_keystore *p_keystore = get_memory_keystore(p_parent);
if (p_keystore != NULL)
credential_find_keystore(p_credential, p_keystore);
@@ -450,9 +447,6 @@ vlc_credential_get(vlc_credential *p_credential, vlc_object_t *p_parent,
}
case GET_FROM_KEYSTORE:
- if (!psz_dialog_title || !psz_dialog_fmt)
- return false;
-
if (p_credential->p_keystore == NULL)
p_credential->p_keystore = vlc_keystore_create(p_parent);
if (p_credential->p_keystore != NULL)
@@ -583,3 +577,31 @@ vlc_credential_store(vlc_credential *p_credential, vlc_object_t *p_parent)
free(psz_path);
return b_ret;
}
+
+#undef vlc_credential_delete
+bool
+vlc_credential_delete(vlc_credential *p_credential, vlc_object_t *p_parent)
+{
+ if (!is_credential_valid(p_credential))
+ return false;
+
+ bool deleted_entries = false;
+ vlc_keystore *mem_keystore = get_memory_keystore(p_parent);
+ for (unsigned int i = 0; i < p_credential->i_entries_count; i++)
+ {
+ const char * const * ppsz_values =
+ (const char *const*) p_credential->p_entries[i].ppsz_values;
+
+ // Find the possible entries in the memory keystore and delete
+ if (mem_keystore != NULL &&
+ vlc_keystore_remove(mem_keystore, ppsz_values) > 0)
+ deleted_entries = true;
+
+ // Find the possible entries in the permanent keystore and delete
+ if (p_credential->p_keystore != NULL &&
+ vlc_keystore_remove(p_credential->p_keystore, ppsz_values) > 0)
+ deleted_entries = true;
+ }
+ // Only returns true if at least one entry was deleted
+ return deleted_entries;
+}
\ No newline at end of file
--
2.14.1
More information about the vlc-devel
mailing list