diff --git a/NEWS b/NEWS index b3a250b5..e47ec91a 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ Noteworthy changes in version 1.7.0 (unreleased) [C25/A14/R_] gpgme_pubkey_algo_string NEW. GPGME_PK_EDDSA NEW. gpgme_set_ctx_flag NEW. + gpgme_data_set_flag NEW. gpgme_signature_t EXTENDED: New field tofu. gpgme_subkey_t EXTENDED: New field keygrip. gpgme_tofu_policy_t NEW. diff --git a/src/conversion.c b/src/conversion.c index c2b27a16..3df8fe59 100644 --- a/src/conversion.c +++ b/src/conversion.c @@ -364,6 +364,25 @@ _gpgme_strtoul_field (const char *string, unsigned long *result) } +/* Convert STRING into an offset value. Note that this functions only + * allows for a base-10 length. This function is similar to atoi() + * and thus there is no error checking. */ +gpgme_off_t +_gpgme_string_to_off (const char *string) +{ + gpgme_off_t value = 0; + + while (*string == ' ' || *string == '\t') + string++; + for (; *string >= '0' && *string <= '9'; string++) + { + value *= 10; + value += atoi_1 (string); + } + return value; +} + + #ifdef HAVE_W32_SYSTEM static time_t _gpgme_timegm (struct tm *tm) diff --git a/src/data.c b/src/data.c index 87b619e4..6964246a 100644 --- a/src/data.c +++ b/src/data.c @@ -243,6 +243,28 @@ gpgme_data_get_file_name (gpgme_data_t dh) return dh->file_name; } + +/* Set a flag for the data object DH. See the manual for details. */ +gpg_error_t +gpgme_data_set_flag (gpgme_data_t dh, const char *name, const char *value) +{ + TRACE_BEG2 (DEBUG_DATA, "gpgme_data_set_flag", dh, + "%s=%s", name, value); + + if (!dh) + return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE)); + + if (!strcmp (name, "size-hint")) + { + dh->size_hint= value? _gpgme_string_to_off (value) : 0; + } + else + return gpg_error (GPG_ERR_UNKNOWN_NAME); + + return 0; +} + + /* Functions to support the wait interface. */ @@ -334,3 +356,11 @@ _gpgme_data_get_fd (gpgme_data_t dh) return -1; return (*dh->cbs->get_fd) (dh); } + + +/* Get the size-hint value for DH or 0 if not available. */ +gpgme_off_t +_gpgme_data_get_size_hint (gpgme_data_t dh) +{ + return dh ? dh->size_hint : 0; +} diff --git a/src/data.h b/src/data.h index 3d404af8..0a15b613 100644 --- a/src/data.h +++ b/src/data.h @@ -89,6 +89,9 @@ struct gpgme_data /* File name of the data object. */ char *file_name; + /* Hint on the to be expected toatl size of the data. */ + gpgme_off_t size_hint; + union { /* For gpgme_data_new_from_fd. */ @@ -134,4 +137,7 @@ void _gpgme_data_release (gpgme_data_t dh); return -1. */ int _gpgme_data_get_fd (gpgme_data_t dh); +/* Get the size-hint value for DH or 0 if not available. */ +gpgme_off_t _gpgme_data_get_size_hint (gpgme_data_t dh); + #endif /* DATA_H */ diff --git a/src/gpgme.def b/src/gpgme.def index dfdb6c66..a15c35b5 100644 --- a/src/gpgme.def +++ b/src/gpgme.def @@ -226,5 +226,8 @@ EXPORTS gpgme_pubkey_algo_string @169 gpgme_set_ctx_flag @170 + + gpgme_data_set_flag @171 + ; END diff --git a/src/gpgme.h.in b/src/gpgme.h.in index 56d15f4f..40f54426 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -1282,6 +1282,10 @@ char *gpgme_data_get_file_name (gpgme_data_t dh); gpgme_error_t gpgme_data_set_file_name (gpgme_data_t dh, const char *file_name); +/* Set a flag for the data object DH. See the manual for details. */ +gpg_error_t gpgme_data_set_flag (gpgme_data_t dh, + const char *name, const char *value); + /* Try to identify the type of the data in DH. */ gpgme_data_type_t gpgme_data_identify (gpgme_data_t dh, int reserved); diff --git a/src/libgpgme.vers b/src/libgpgme.vers index 873cb190..d29bc147 100644 --- a/src/libgpgme.vers +++ b/src/libgpgme.vers @@ -230,6 +230,8 @@ GPGME_1.0 { gpgme_err_code_from_syserror; gpgme_err_set_errno; + gpgme_data_set_flag; + local: *; diff --git a/src/util.h b/src/util.h index 5a0f7906..a3425f09 100644 --- a/src/util.h +++ b/src/util.h @@ -134,6 +134,9 @@ int _gpgme_split_fields (char *string, char **array, int arraysize); * trailing garbage. */ gpgme_error_t _gpgme_strtoul_field (const char *string, unsigned long *result); +/* Convert STRING into an offset value similar to atoi(). */ +gpgme_off_t _gpgme_string_to_off (const char *string); + /* Parse the string TIMESTAMP into a time_t. The string may either be seconds since Epoch or in the ISO 8601 format like "20390815T143012". Returns 0 for an empty string or seconds since