[Pkg-gnupg-commit] [gpgme] 283/412: core: Add gpgme_data_set_flag to add more meta data to data objects.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:27:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit 293d1736911fd5e77b8cec305168b35b2420c612
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Aug 12 15:21:16 2016 +0200

    core: Add gpgme_data_set_flag to add more meta data to data objects.
    
    * src/gpgme.h.in (gpgme_data_set_flag): New public function.
    * src/data.c (gpgme_data_set_flag): New.
    (_gpgme_data_get_size_hint): New.
    * src/data.h (strucy gpgme_data): Add field 'size_hint'.
    * src/gpgme.def, src/libgpgme.vers: Add new function.
    * src/conversion.c (_gpgme_string_to_off): New.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 NEWS              |  1 +
 src/conversion.c  | 19 +++++++++++++++++++
 src/data.c        | 30 ++++++++++++++++++++++++++++++
 src/data.h        |  6 ++++++
 src/gpgme.def     |  3 +++
 src/gpgme.h.in    |  4 ++++
 src/libgpgme.vers |  2 ++
 src/util.h        |  3 +++
 8 files changed, 68 insertions(+)

diff --git a/NEWS b/NEWS
index b3a250b..e47ec91 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 c2b27a1..3df8fe5 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 87b619e..6964246 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 3d404af..0a15b61 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 dfdb6c6..a15c35b 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 56d15f4..40f5442 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 873cb19..d29bc14 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 5a0f790..a3425f0 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list