adding get_binary_path() to Message API
authorVolker Birk <vb@pep-project.org>
Wed, 16 Mar 2016 11:20:52 +0100
changeset 507288496838ffb
parent 506 66b92bca4133
child 508 a4710d4c678a
adding get_binary_path() to Message API
src/cryptotech.c
src/cryptotech.h
src/message_api.c
src/message_api.h
src/pgp_gpg.c
src/pgp_gpg.h
src/pgp_gpg_internal.h
     1.1 --- a/src/cryptotech.c	Fri Mar 11 16:14:55 2016 +0100
     1.2 +++ b/src/cryptotech.c	Wed Mar 16 11:20:52 2016 +0100
     1.3 @@ -45,6 +45,9 @@
     1.4          cryptotech[PEP_crypt_OpenPGP].renew_key = pgp_renew_key;
     1.5          cryptotech[PEP_crypt_OpenPGP].revoke_key = pgp_revoke_key;
     1.6          cryptotech[PEP_crypt_OpenPGP].key_expired = pgp_key_expired;
     1.7 +#ifdef PGP_BINARY_PATH
     1.8 +        cryptotech[PEP_crypt_OpenPGP].binary_path = PGP_BINARY_PATH;
     1.9 +#endif
    1.10      }
    1.11  
    1.12      session->cryptotech = cryptotech;
     2.1 --- a/src/cryptotech.h	Fri Mar 11 16:14:55 2016 +0100
     2.2 +++ b/src/cryptotech.h	Wed Mar 16 11:20:52 2016 +0100
     2.3 @@ -63,6 +63,8 @@
     2.4  typedef PEP_STATUS (*key_expired_t)(PEP_SESSION session, const char *fpr,
     2.5          bool *expired);
     2.6  
     2.7 +typedef PEP_STATUS (*binary_path_t)(const char **path);
     2.8 +
     2.9  typedef struct _PEP_cryptotech_t {
    2.10      uint8_t id;
    2.11      // the following are default values; comm_type may vary with key length or b0rken crypto
    2.12 @@ -82,6 +84,7 @@
    2.13      renew_key_t renew_key;
    2.14      revoke_key_t revoke_key;
    2.15      key_expired_t key_expired;
    2.16 +    binary_path_t binary_path;
    2.17  } PEP_cryptotech_t;
    2.18  
    2.19  extern PEP_cryptotech_t cryptotech[PEP_crypt__count];
     3.1 --- a/src/message_api.c	Fri Mar 11 16:14:55 2016 +0100
     3.2 +++ b/src/message_api.c	Wed Mar 16 11:20:52 2016 +0100
     3.3 @@ -1411,3 +1411,19 @@
     3.4      return status;
     3.5  }
     3.6  
     3.7 +DYNAMIC_API PEP_STATUS get_binary_path(PEP_cryptotech tech, const char **path)
     3.8 +{
     3.9 +    PEP_STATUS status = PEP_STATUS_OK;
    3.10 +
    3.11 +    assert(path);
    3.12 +    if (path == NULL)
    3.13 +        return PEP_ILLEGAL_VALUE;
    3.14 +
    3.15 +    if (cryptotech[tech].binary_path == NULL)
    3.16 +        *path = NULL;
    3.17 +    else
    3.18 +        status = cryptotech[tech].binary_path(path);
    3.19 +
    3.20 +    return status;
    3.21 +}
    3.22 +
     4.1 --- a/src/message_api.h	Fri Mar 11 16:14:55 2016 +0100
     4.2 +++ b/src/message_api.h	Wed Mar 16 11:20:52 2016 +0100
     4.3 @@ -134,6 +134,15 @@
     4.4      );
     4.5  
     4.6  
     4.7 +// get_binary_path() - retrieve path of cryptotech binary if available
     4.8 +//
     4.9 +//  parameters:
    4.10 +//      tech (in)           cryptotech to get the binary for
    4.11 +//      path (out)          path to cryptotech binary or NULL if not available
    4.12 +
    4.13 +DYNAMIC_API PEP_STATUS get_binary_path(PEP_cryptotech tech, const char **path);
    4.14 +
    4.15 +
    4.16  #ifdef __cplusplus
    4.17  }
    4.18  #endif
     5.1 --- a/src/pgp_gpg.c	Fri Mar 11 16:14:55 2016 +0100
     5.2 +++ b/src/pgp_gpg.c	Wed Mar 16 11:20:52 2016 +0100
     5.3 @@ -145,6 +145,11 @@
     5.4              = (gpgme_release_t) (intptr_t) dlsym(gpgme, "gpgme_release");
     5.5          assert(gpg.gpgme_release);
     5.6  
     5.7 +        gpg.gpgme_get_engine_info
     5.8 +            = (gpgme_get_engine_info_t) (intptr_t) dlsym(gpgme,
     5.9 +            "gpgme_get_engine_info");
    5.10 +        assert(gpg.gpgme_get_engine_info);
    5.11 +
    5.12          gpg.gpgme_set_protocol
    5.13              = (gpgme_set_protocol_t) (intptr_t) dlsym(gpgme,
    5.14              "gpgme_set_protocol");
    5.15 @@ -1716,3 +1721,22 @@
    5.16      return PEP_STATUS_OK;
    5.17  }
    5.18  
    5.19 +PEP_STATUS pgp_binary(const char **path)
    5.20 +{
    5.21 +    assert(path);
    5.22 +    if (path == NULL)
    5.23 +        return PEP_ILLEGAL_VALUE;
    5.24 +
    5.25 +    *path = NULL;
    5.26 +
    5.27 +    gpgme_engine_info_t info;
    5.28 +    int err = gpg.gpgme_get_engine_info(&info);
    5.29 +    assert(err == GPG_ERR_NO_ERROR);
    5.30 +    if (err != GPG_ERR_NO_ERROR)
    5.31 +        return PEP_OUT_OF_MEMORY;
    5.32 +
    5.33 +    *path = info->file_name;
    5.34 +
    5.35 +    return PEP_STATUS_OK;
    5.36 +}
    5.37 +
     6.1 --- a/src/pgp_gpg.h	Fri Mar 11 16:14:55 2016 +0100
     6.2 +++ b/src/pgp_gpg.h	Wed Mar 16 11:20:52 2016 +0100
     6.3 @@ -64,3 +64,6 @@
     6.4          bool *expired
     6.5      );
     6.6  
     6.7 +PEP_STATUS pgp_binary(const char **path);
     6.8 +#define PGP_BINARY_PATH pgp_binary
     6.9 +
     7.1 --- a/src/pgp_gpg_internal.h	Fri Mar 11 16:14:55 2016 +0100
     7.2 +++ b/src/pgp_gpg_internal.h	Wed Mar 16 11:20:52 2016 +0100
     7.3 @@ -5,6 +5,7 @@
     7.4  // init
     7.5  
     7.6  typedef const char * (*gpgme_check_version_t)(const char*);
     7.7 +typedef gpgme_error_t (*gpgme_get_engine_info_t)(gpgme_engine_info_t *INFO);
     7.8  typedef gpgme_error_t(*gpgme_set_locale_t)(gpgme_ctx_t CTX, int CATEGORY,
     7.9      const char *VALUE);
    7.10  typedef gpgme_error_t(*gpgme_new_t)(gpgme_ctx_t *CTX);
    7.11 @@ -76,6 +77,7 @@
    7.12  struct gpg_s {
    7.13      const char * version;
    7.14      gpgme_check_version_t gpgme_check;
    7.15 +    gpgme_get_engine_info_t gpgme_get_engine_info;
    7.16      gpgme_set_locale_t gpgme_set_locale;
    7.17      gpgme_new_t gpgme_new;
    7.18      gpgme_release_t gpgme_release;