1 /*****************************************************************************
2 * list_util.c: list helper used by memory and file_crypt keystores
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 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_keystore.h>
28 #include "list_util.h"
31 ks_list_free(struct ks_list
*p_list
)
33 vlc_keystore_release_entries(p_list
->p_entries
, p_list
->i_count
);
34 p_list
->p_entries
= NULL
;
40 ks_values_copy(const char * ppsz_dst
[KEY_MAX
],
41 const char *const ppsz_src
[KEY_MAX
])
43 for (unsigned int i
= 0; i
< KEY_MAX
; ++i
)
47 ppsz_dst
[i
] = strdup(ppsz_src
[i
]);
56 ks_list_new_entry(struct ks_list
*p_list
)
58 if (p_list
->i_count
+ 1 > p_list
->i_max
)
61 vlc_keystore_entry
*p_entries
= realloc(p_list
->p_entries
, p_list
->i_max
62 * sizeof(*p_list
->p_entries
));
68 p_list
->p_entries
= p_entries
;
70 vlc_keystore_entry
*p_entry
= &p_list
->p_entries
[p_list
->i_count
];
71 p_entry
->p_secret
= NULL
;
72 VLC_KEYSTORE_VALUES_INIT(p_entry
->ppsz_values
);
79 ks_list_find_entry(struct ks_list
*p_list
, const char *const ppsz_values
[KEY_MAX
],
80 unsigned *p_start_index
)
82 for (unsigned int i
= p_start_index
? *p_start_index
: 0;
83 i
< p_list
->i_count
; ++i
)
85 vlc_keystore_entry
*p_entry
= &p_list
->p_entries
[i
];
86 if (!p_entry
->p_secret
)
90 for (unsigned int j
= 0; j
< KEY_MAX
; ++j
)
92 const char *psz_value1
= ppsz_values
[j
];
93 const char *psz_value2
= p_entry
->ppsz_values
[j
];
97 if (!psz_value2
|| strcmp(psz_value1
, psz_value2
))
103 *p_start_index
= i
+ 1;