[balsa/port-to-pcre2: 35/36] gmime-gpgme-signature: Use a custom parser
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/port-to-pcre2: 35/36] gmime-gpgme-signature: Use a custom parser
- Date: Fri, 15 Jan 2021 22:21:17 +0000 (UTC)
commit 2e1cc20da31bce6ff608197490139df0db45b4dc
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Wed Dec 9 13:58:49 2020 -0500
gmime-gpgme-signature: Use a custom parser
instead of libbalsa_regex_split().
libbalsa/gmime-gpgme-signature.c | 40 ++++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/libbalsa/gmime-gpgme-signature.c b/libbalsa/gmime-gpgme-signature.c
index 659d2c2e6..3360cc6a2 100644
--- a/libbalsa/gmime-gpgme-signature.c
+++ b/libbalsa/gmime-gpgme-signature.c
@@ -342,6 +342,34 @@ hex_decode(const gchar *hexstr)
return result;
}
+/*
+ * Simple parser: split the subject at every unescaped '=' or ','
+ */
+static char **
+split_subject(const char *subject)
+{
+ GPtrArray *result = g_ptr_array_new();
+ const char *p = subject;
+ const char *start = subject;
+
+ while (*p != '\0') {
+ int c = *p++;
+
+ if (c == '\\') {
+ if (*p != '\0')
+ p++;
+ } else if (c == '=' || c == ',') {
+ g_ptr_array_add(result, g_strndup(start, (p - start) - 1));
+ start = p;
+ }
+ }
+
+ g_ptr_array_add(result, g_strndup(start, p - start));
+ g_ptr_array_add(result, NULL);
+
+ return (char **) g_ptr_array_free(result, FALSE);
+}
+
/** \brief Split a S/MIME certificate subject string into tokens
*
* \param subject certificate subject string
@@ -354,21 +382,13 @@ hex_decode(const gchar *hexstr)
*
* If the string starts with a '<', it contains an email address, and is returned untouched in the array.
*/
+
static gchar **
tokenize_subject(const gchar *subject,
gboolean unescape)
{
- static LibBalsaRegex *split_re = NULL;
- static volatile guint initialized = 0U;
gchar **result;
- /* create the reqular expression when called for teh first time */
- if (g_atomic_int_or(&initialized, 1U) == 0U) {
- /* split a DN string at unescaped ',' and '=' chars */
- split_re = libbalsa_regex_new("(?<!\\\\)[,=]", 0, NULL);
- g_assert(split_re != NULL);
- }
-
/* catch empty string */
if (subject == NULL) {
return NULL;
@@ -380,7 +400,7 @@ tokenize_subject(const gchar *subject,
result[0] = g_strdup(subject);
} else {
/* split into (oid, value) pairs */
- result = libbalsa_regex_split(split_re, subject, 0);
+ result = split_subject(subject);
if (result != NULL) {
gint n;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]