video_filter: ripple: fix YUV10/RGB black pixel
[vlc.git] / modules / keystore / memory.c
blob527433db9ae9c30aaa412e9f137c99b0d26f891b
1 /*****************************************************************************
2 * memory.c: Memory keystore
3 *****************************************************************************
4 * Copyright © 2015-2016 VLC authors, VideoLAN and VideoLabs
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <stdio.h>
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_keystore.h>
30 #include <vlc_strings.h>
32 #include <assert.h>
34 #include "list_util.h"
36 static int Open(vlc_object_t *);
37 static void Close(vlc_object_t *);
39 vlc_module_begin()
40 set_shortname(N_("Memory keystore"))
41 set_description(N_("Secrets are stored in memory"))
42 set_category(CAT_ADVANCED)
43 set_subcategory(SUBCAT_ADVANCED_MISC)
44 set_capability("keystore", 0)
45 set_callbacks(Open, Close)
46 add_shortcut("memory")
47 vlc_module_end ()
49 struct vlc_keystore_sys
51 struct ks_list list;
52 vlc_mutex_t lock;
55 static int
56 Store(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX],
57 const uint8_t *p_secret, size_t i_secret_len, const char *psz_label)
59 (void) psz_label;
60 vlc_keystore_sys *p_sys = p_keystore->p_sys;
61 struct ks_list *p_list = &p_sys->list;
62 vlc_keystore_entry *p_entry;
63 int i_ret = VLC_EGENERIC;
65 vlc_mutex_lock(&p_sys->lock);
66 p_entry = ks_list_find_entry(p_list, ppsz_values, NULL);
67 if (p_entry)
68 vlc_keystore_release_entry(p_entry);
69 else
71 p_entry = ks_list_new_entry(p_list);
72 if (!p_entry)
73 goto end;
75 if (ks_values_copy((const char **)p_entry->ppsz_values, ppsz_values))
76 goto end;
78 if (vlc_keystore_entry_set_secret(p_entry, p_secret, i_secret_len))
79 goto end;
81 i_ret = VLC_SUCCESS;
82 end:
83 vlc_mutex_unlock(&p_sys->lock);
84 return i_ret;
87 static unsigned int
88 Find(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX],
89 vlc_keystore_entry **pp_entries)
91 vlc_keystore_sys *p_sys = p_keystore->p_sys;
92 struct ks_list *p_list = &p_sys->list;
93 struct ks_list out_list = { 0 };
94 vlc_keystore_entry *p_entry;
95 unsigned i_index = 0;
97 vlc_mutex_lock(&p_sys->lock);
98 while ((p_entry = ks_list_find_entry(p_list, ppsz_values, &i_index)))
100 vlc_keystore_entry *p_out_entry = ks_list_new_entry(&out_list);
102 if (!p_out_entry
103 || ks_values_copy((const char **)p_out_entry->ppsz_values,
104 (const char *const*)p_entry->ppsz_values))
106 ks_list_free(&out_list);
107 break;
110 if (vlc_keystore_entry_set_secret(p_out_entry, p_entry->p_secret,
111 p_entry->i_secret_len))
113 ks_list_free(&out_list);
114 break;
117 vlc_mutex_unlock(&p_sys->lock);
119 *pp_entries = out_list.p_entries;
121 return out_list.i_count;
124 static unsigned int
125 Remove(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX])
127 vlc_keystore_sys *p_sys = p_keystore->p_sys;
128 struct ks_list *p_list = &p_sys->list;
129 vlc_keystore_entry *p_entry;
130 unsigned i_index = 0, i_count = 0;
132 vlc_mutex_lock(&p_sys->lock);
133 while ((p_entry = ks_list_find_entry(p_list, ppsz_values, &i_index)))
135 vlc_keystore_release_entry(p_entry);
136 i_count++;
138 vlc_mutex_unlock(&p_sys->lock);
140 return i_count;
143 static void
144 Close(vlc_object_t *p_this)
146 vlc_keystore *p_keystore = (vlc_keystore *)p_this;
147 vlc_keystore_sys *p_sys = p_keystore->p_sys;
149 ks_list_free(&p_sys->list);
150 vlc_mutex_destroy(&p_keystore->p_sys->lock);
151 free(p_sys);
154 static int
155 Open(vlc_object_t *p_this)
157 vlc_keystore *p_keystore = (vlc_keystore *)p_this;
158 p_keystore->p_sys = calloc(1, sizeof(vlc_keystore_sys));
159 if (!p_keystore->p_sys)
160 return VLC_EGENERIC;
162 vlc_mutex_init(&p_keystore->p_sys->lock);
163 p_keystore->pf_store = Store;
164 p_keystore->pf_find = Find;
165 p_keystore->pf_remove = Remove;
167 return VLC_SUCCESS;