# HG changeset patch # User Andre Heinecke # Date 1396446444 0 # Node ID 881ce5126f07d21f99baa01872a153fbc0da9a7a # Parent f23e0ccd5d144bbd2d57c1dfe885d84d1eade7f9 Add helper function to get all certificates in a list diff -r f23e0ccd5d14 -r 881ce5126f07 common/listutil.c --- a/common/listutil.c Wed Apr 02 13:45:57 2014 +0000 +++ b/common/listutil.c Wed Apr 02 13:47:24 2014 +0000 @@ -9,6 +9,8 @@ #include #include +#include "strhelp.h" + #ifdef RELEASE #include "pubkey-release.h" #else @@ -232,22 +234,30 @@ return retval; } -char **get_certs_to_remove(const char *data, const size_t size) { +char ** +get_certs_from_list (char *data, const size_t size) +{ + char *cur = data; + char **retval = NULL; - /* TODO */ - if (!data || !size) { - printf ("Invalid call to get_certs_to_remove \n"); - return NULL; + if (!data || !size) + { + printf ("Invalid call to get_certs_to_remove \n"); + return NULL; } - return NULL; + + while (cur) + { + char *next = strchr(cur, '\n'); + if (strlen(cur) > 3 && (cur[0] == 'I' || cur[0] == 'R') && + next - cur > 4) + { + size_t len = (size_t) (next - cur - 4); + /* Remove I: or R: at the beginning and \r\n at the end */ + strv_append(&retval, cur + 2, len); + } + cur = next ? (next + 1) : NULL; + } + return retval; } -char **get_certs_to_install(const char *data, const size_t size) { - - /* TODO */ - if (!data || !size) { - printf ("Invalid call to get_certs_to_install \n"); - return NULL; - } - return NULL; -} diff -r f23e0ccd5d14 -r 881ce5126f07 common/listutil.h --- a/common/listutil.h Wed Apr 02 13:45:57 2014 +0000 +++ b/common/listutil.h Wed Apr 02 13:47:24 2014 +0000 @@ -59,9 +59,9 @@ */ int verify_list(const char *data, const size_t size); -/** @brief get a list of the certificates marked with I: +/** @brief get a list of the certificates marked with I: or R: * - * Get a list of certificates that should be installed by the + * Get a list of certificates that are contained in the * certificatelist pointed to by data. * On Success this function makes a copy of the certificates * and the certificates need to be freed by the caller. @@ -72,23 +72,7 @@ * @returns a newly allocated array of strings containing the encoded * certificates or NULL on error. * */ -char **get_certs_to_install(const char *data, const size_t size); - -/** @brief get a list of the certificates marked with R: - * - * Get a list of certificates that should be removed by the - * certificatelist pointed to by data. - * On Success this function makes a copy of the certificates - * and the certificates need to be freed by the caller. - * - * @param [in] data the certificatelist to parse - * @param [in] size the size of the certificatelist - * - * @returns a newly allocated array of strings containing the encoded - * certificates or NULL on error. - * */ -char **get_certs_to_remove(const char *data, const size_t size); - +char **get_certs_from_list (char *data, const size_t size); #ifdef __cplusplus }