delete from stringlist
authorVolker Birk <vb@pep-project.org>
Thu, 31 Mar 2016 14:01:45 +0200
changeset 523afaf34a57cc6
parent 520 e29a693d2748
child 524 465eaf414405
delete from stringlist
src/keymanagement.c
src/pgp_gpg.c
src/stringlist.c
src/stringlist.h
     1.1 --- a/src/keymanagement.c	Tue Mar 22 17:22:03 2016 +0100
     1.2 +++ b/src/keymanagement.c	Thu Mar 31 14:01:45 2016 +0200
     1.3 @@ -8,7 +8,6 @@
     1.4  
     1.5  #include "pEp_internal.h"
     1.6  #include "keymanagement.h"
     1.7 -#include "blacklist.h"
     1.8  
     1.9  #ifndef EMPTYSTR
    1.10  #define EMPTYSTR(STR) ((STR) == NULL || (STR)[0] == '\0')
     2.1 --- a/src/pgp_gpg.c	Tue Mar 22 17:22:03 2016 +0100
     2.2 +++ b/src/pgp_gpg.c	Thu Mar 31 14:01:45 2016 +0200
     2.3 @@ -1253,6 +1253,10 @@
     2.4      } while (gpgme_error != GPG_ERR_EOF);
     2.5  
     2.6      gpg.gpgme_op_keylist_end(session->ctx);
     2.7 +    if (_keylist->value == NULL) {
     2.8 +        free_stringlist(_keylist);
     2.9 +        _keylist = NULL;
    2.10 +    }
    2.11      *keylist = _keylist;
    2.12      return PEP_STATUS_OK;
    2.13  }
     3.1 --- a/src/stringlist.c	Tue Mar 22 17:22:03 2016 +0100
     3.2 +++ b/src/stringlist.c	Thu Mar 31 14:01:45 2016 +0200
     3.3 @@ -104,6 +104,39 @@
     3.4      return len;
     3.5  }
     3.6  
     3.7 +DYNAMIC_API stringlist_t *stringlist_delete(
     3.8 +        stringlist_t *stringlist,
     3.9 +        const char *value
    3.10 +    )
    3.11 +{
    3.12 +    assert(stringlist);
    3.13 +    assert(value);
    3.14 +
    3.15 +    if (stringlist->value == NULL) {
    3.16 +        free_stringlist(stringlist);
    3.17 +        return NULL;
    3.18 +    }
    3.19 +
    3.20 +    if (value == NULL)
    3.21 +        return stringlist;
    3.22 +
    3.23 +    stringlist_t *_sl;
    3.24 +    stringlist_t *last = NULL;
    3.25 +    for (_sl = stringlist; _sl && _sl->value; _sl = _sl->next) {
    3.26 +        if (strcmp(_sl->value, value) == 0) {
    3.27 +            if (last == NULL)
    3.28 +                stringlist = stringlist->next;
    3.29 +            else
    3.30 +                last->next = _sl->next;
    3.31 +            _sl->next = NULL;
    3.32 +            free_stringlist(_sl);
    3.33 +            break;
    3.34 +        }
    3.35 +        last = _sl;
    3.36 +    }
    3.37 +    return stringlist;
    3.38 +}
    3.39 +
    3.40  DYNAMIC_API void free_stringlist(stringlist_t *stringlist)
    3.41  {
    3.42      if (stringlist) {
     4.1 --- a/src/stringlist.h	Tue Mar 22 17:22:03 2016 +0100
     4.2 +++ b/src/stringlist.h	Thu Mar 31 14:01:45 2016 +0200
     4.3 @@ -88,6 +88,21 @@
     4.4  DYNAMIC_API int stringlist_length(const stringlist_t *stringlist);
     4.5  
     4.6  
     4.7 +// stringlist_delete() - delete entry from stringlist
     4.8 +//
     4.9 +//  parameters:
    4.10 +//      stringlist (in)     stringlist struct to delete from
    4.11 +//      value (in)          data to delete
    4.12 +//
    4.13 +//  return value:
    4.14 +//      modified stringlist
    4.15 +
    4.16 +DYNAMIC_API stringlist_t *stringlist_delete(
    4.17 +        stringlist_t *stringlist,
    4.18 +        const char *value
    4.19 +    );
    4.20 +
    4.21 +
    4.22  // free_stringlist() - free memory occupied by stringlist
    4.23  //
    4.24  //  parameters: