[Pkg-gnupg-commit] [gpgme] 122/412: core: New functions to help parsing of status lines.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:30 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 a92946a8cacc44f655249d84b316deae59e62671
Author: Werner Koch <wk at gnupg.org>
Date:   Sat May 21 10:21:06 2016 +0200

    core: New functions to help parsing of status lines.
    
    * src/conversion.c (_gpgme_split_fields): New.
    (_gpgme_strtoul_field): New.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 src/conversion.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/util.h       |  9 +++++++++
 2 files changed, 56 insertions(+)

diff --git a/src/conversion.c b/src/conversion.c
index 0992225..c2b27a1 100644
--- a/src/conversion.c
+++ b/src/conversion.c
@@ -317,6 +317,53 @@ _gpgme_encode_percent_string (const char *src, char **destp, size_t len)
 }
 
 
+/* Split a string into space delimited fields and remove leading and
+ * trailing spaces from each field.  A pointer to the each field is
+ * stored in ARRAY.  Stop splitting at ARRAYSIZE fields.  The function
+ * modifies STRING.  The number of parsed fields is returned.
+ */
+int
+_gpgme_split_fields (char *string, char **array, int arraysize)
+{
+  int n = 0;
+  char *p, *pend;
+
+  for (p = string; *p == ' '; p++)
+    ;
+  do
+    {
+      if (n == arraysize)
+        break;
+      array[n++] = p;
+      pend = strchr (p, ' ');
+      if (!pend)
+        break;
+      *pend++ = 0;
+      for (p = pend; *p == ' '; p++)
+        ;
+    }
+  while (*p);
+
+  return n;
+}
+
+/* Convert the field STRING into an unsigned long value.  Check for
+ * trailing garbage.  */
+gpgme_error_t
+_gpgme_strtoul_field (const char *string, unsigned long *result)
+{
+  char *endp;
+
+  gpg_err_set_errno (0);
+  *result = strtoul (string, &endp, 0);
+  if (errno)
+    return gpg_error_from_syserror ();
+  if (endp == string || *endp)
+    return gpg_error (GPG_ERR_INV_VALUE);
+  return 0;
+}
+
+
 #ifdef HAVE_W32_SYSTEM
 static time_t
 _gpgme_timegm (struct tm *tm)
diff --git a/src/util.h b/src/util.h
index 365f1d8..9c62f57 100644
--- a/src/util.h
+++ b/src/util.h
@@ -124,6 +124,15 @@ gpgme_error_t _gpgme_decode_percent_string (const char *src, char **destp,
 gpgme_error_t _gpgme_encode_percent_string (const char *src, char **destp,
 					    size_t len);
 
+/* Split a string into space delimited fields and remove leading and
+ * trailing spaces from each field.  A pointer to the each field is
+ * stored in ARRAY.  Stop splitting at ARRAYSIZE fields.  The function
+ * modifies STRING.  The number of parsed fields is returned.  */
+int _gpgme_split_fields (char *string, char **array, int arraysize);
+
+/* Convert the field STRING into an unsigned long value.  Check for
+ * trailing garbage.  */
+gpgme_error_t _gpgme_strtoul_field (const char *string, unsigned long *result);
 
 /* Parse the string TIMESTAMP into a time_t.  The string may either be
    seconds since Epoch or in the ISO 8601 format like

-- 
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