Blame SOURCES/0002-split_on_separator-move-to-a-separate-file.patch

ecf709
From 4f98b36562fb02f95c9af7af6fde548334ce9c34 Mon Sep 17 00:00:00 2001
ecf709
From: Sumit Bose <sbose@redhat.com>
ecf709
Date: Wed, 8 Feb 2017 14:28:28 +0100
ecf709
Subject: [PATCH 02/15] split_on_separator: move to a separate file
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
To be able to include split_on_separator() without additional
ecf709
dependencies (only talloc), it is moved into a separate file.
ecf709
ecf709
Related to https://pagure.io/SSSD/sssd/issue/3050
ecf709
ecf709
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ecf709
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
ecf709
---
ecf709
 Makefile.am         |  30 ++++++++++---
ecf709
 src/util/util.c     |  93 ----------------------------------------
ecf709
 src/util/util_ext.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++
ecf709
 3 files changed, 144 insertions(+), 100 deletions(-)
ecf709
 create mode 100644 src/util/util_ext.c
ecf709
ecf709
diff --git a/Makefile.am b/Makefile.am
ecf709
index 45b04de2638a745a189c0b4e5794ccd29913b10d..6dae4f2dd7f2dee501add82c7ab4f15fcbcc59ac 100644
ecf709
--- a/Makefile.am
ecf709
+++ b/Makefile.am
ecf709
@@ -987,6 +987,7 @@ libsss_util_la_SOURCES = \
ecf709
     src/sbus/sssd_dbus_common_signals.c \
ecf709
     src/sbus/sssd_dbus_utils.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     src/util/memory.c \
ecf709
     src/util/safe-format-string.c \
ecf709
     src/util/server.c \
ecf709
@@ -2355,19 +2356,23 @@ test_authtok_SOURCES = \
ecf709
     src/tests/cmocka/test_authtok.c \
ecf709
     src/util/authtok.c \
ecf709
     src/util/authtok-utils.c \
ecf709
-    src/util/util.c
ecf709
+    src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
+    $(NULL)
ecf709
 test_authtok_CFLAGS = \
ecf709
     $(AM_CFLAGS) \
ecf709
     $(TALLOC_CFLAGS) \
ecf709
     $(POPT_CFLAGS) \
ecf709
-    $(DHASH_CFLAGS)
ecf709
+    $(DHASH_CFLAGS) \
ecf709
+    $(NULL)
ecf709
 test_authtok_LDADD = \
ecf709
     $(TALLOC_LIBS) \
ecf709
     $(CMOCKA_LIBS) \
ecf709
     $(DHASH_LIBS) \
ecf709
     $(POPT_LIBS) \
ecf709
     libsss_test_common.la \
ecf709
-    libsss_debug.la
ecf709
+    libsss_debug.la \
ecf709
+    $(NULL)
ecf709
 
ecf709
 sss_nss_idmap_tests_SOURCES = \
ecf709
     src/tests/cmocka/sss_nss_idmap-tests.c
ecf709
@@ -2839,6 +2844,7 @@ test_child_common_SOURCES = \
ecf709
     src/util/atomic_io.c \
ecf709
     src/util/util_errors.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     $(NULL)
ecf709
 test_child_common_CFLAGS = \
ecf709
     $(AM_CFLAGS) \
ecf709
@@ -3774,6 +3780,7 @@ krb5_child_SOURCES = \
ecf709
     src/util/authtok.c \
ecf709
     src/util/authtok-utils.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     src/util/signal.c \
ecf709
     src/util/strtonum.c \
ecf709
     src/util/become_user.c \
ecf709
@@ -3807,6 +3814,7 @@ ldap_child_SOURCES = \
ecf709
     src/util/authtok.c \
ecf709
     src/util/authtok-utils.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     src/util/signal.c \
ecf709
     src/util/become_user.c \
ecf709
     $(NULL)
ecf709
@@ -3827,6 +3835,7 @@ selinux_child_SOURCES = \
ecf709
     src/util/sss_semanage.c \
ecf709
     src/util/atomic_io.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     $(NULL)
ecf709
 selinux_child_CFLAGS = \
ecf709
     $(AM_CFLAGS) \
ecf709
@@ -3845,6 +3854,7 @@ gpo_child_SOURCES = \
ecf709
     src/providers/ad/ad_gpo_child.c \
ecf709
     src/util/atomic_io.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     src/util/signal.c
ecf709
 gpo_child_CFLAGS = \
ecf709
     $(AM_CFLAGS) \
ecf709
@@ -3876,6 +3886,7 @@ p11_child_SOURCES = \
ecf709
     src/p11_child/p11_child_nss.c \
ecf709
     src/util/atomic_io.c \
ecf709
     src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
     $(NULL)
ecf709
 p11_child_CFLAGS = \
ecf709
     $(AM_CFLAGS) \
ecf709
@@ -3893,16 +3904,21 @@ p11_child_LDADD = \
ecf709
 
ecf709
 memberof_la_SOURCES = \
ecf709
     src/ldb_modules/memberof.c \
ecf709
-    src/util/util.c
ecf709
+    src/util/util.c \
ecf709
+    src/util/util_ext.c \
ecf709
+    $(NULL)
ecf709
 memberof_la_CFLAGS = \
ecf709
-    $(AM_CFLAGS)
ecf709
+    $(AM_CFLAGS) \
ecf709
+    $(NULL)
ecf709
 memberof_la_LIBADD = \
ecf709
     libsss_debug.la \
ecf709
     $(LDB_LIBS) \
ecf709
-    $(DHASH_LIBS)
ecf709
+    $(DHASH_LIBS) \
ecf709
+    $(NULL)
ecf709
 memberof_la_LDFLAGS = \
ecf709
     -avoid-version \
ecf709
-    -module
ecf709
+    -module \
ecf709
+    $(NULL)
ecf709
 
ecf709
 if BUILD_KRB5_LOCATOR_PLUGIN
ecf709
 sssd_krb5_locator_plugin_la_SOURCES = \
ecf709
diff --git a/src/util/util.c b/src/util/util.c
ecf709
index a528f0c0249c33bfc3d3275250e74d5edcef2e6f..9d6202f695d516f20d648621da81a2d5e746daa5 100644
ecf709
--- a/src/util/util.c
ecf709
+++ b/src/util/util.c
ecf709
@@ -35,99 +35,6 @@
ecf709
 int socket_activated = 0;
ecf709
 int dbus_activated = 0;
ecf709
 
ecf709
-int split_on_separator(TALLOC_CTX *mem_ctx, const char *str,
ecf709
-                       const char sep, bool trim, bool skip_empty,
ecf709
-                       char ***_list, int *size)
ecf709
-{
ecf709
-    int ret;
ecf709
-    const char *substr_end = str;
ecf709
-    const char *substr_begin = str;
ecf709
-    const char *sep_pos = NULL;
ecf709
-    size_t substr_len;
ecf709
-    char **list = NULL;
ecf709
-    int num_strings = 0;
ecf709
-    TALLOC_CTX *tmp_ctx = NULL;
ecf709
-
ecf709
-    if (str == NULL || *str == '\0' || _list == NULL) {
ecf709
-        return EINVAL;
ecf709
-    }
ecf709
-
ecf709
-    tmp_ctx = talloc_new(NULL);
ecf709
-    if (tmp_ctx == NULL) {
ecf709
-        return ENOMEM;
ecf709
-    }
ecf709
-
ecf709
-    do {
ecf709
-        substr_len = 0;
ecf709
-
ecf709
-        /* If this is not the first substring, then move from the separator. */
ecf709
-        if (sep_pos != NULL) {
ecf709
-            substr_end = sep_pos + 1;
ecf709
-            substr_begin = sep_pos + 1;
ecf709
-        }
ecf709
-
ecf709
-        /* Find end of the first substring */
ecf709
-        while (*substr_end != sep && *substr_end != '\0') {
ecf709
-            substr_end++;
ecf709
-            substr_len++;
ecf709
-        }
ecf709
-
ecf709
-        sep_pos = substr_end;
ecf709
-
ecf709
-        if (trim) {
ecf709
-            /* Trim leading whitespace */
ecf709
-            while (isspace(*substr_begin) && substr_begin < substr_end) {
ecf709
-                substr_begin++;
ecf709
-                substr_len--;
ecf709
-            }
ecf709
-
ecf709
-            /* Trim trailing whitespace */
ecf709
-            while (substr_end - 1 > substr_begin && isspace(*(substr_end-1))) {
ecf709
-                substr_end--;
ecf709
-                substr_len--;
ecf709
-            }
ecf709
-        }
ecf709
-
ecf709
-        /* Copy the substring to the output list of strings */
ecf709
-        if (skip_empty == false || substr_len > 0) {
ecf709
-            list = talloc_realloc(tmp_ctx, list, char*, num_strings + 2);
ecf709
-            if (list == NULL) {
ecf709
-                ret = ENOMEM;
ecf709
-                goto done;
ecf709
-            }
ecf709
-
ecf709
-            /* empty string is stored for substr_len == 0 */
ecf709
-            list[num_strings] = talloc_strndup(list, substr_begin, substr_len);
ecf709
-            if (list[num_strings] == NULL) {
ecf709
-                ret = ENOMEM;
ecf709
-                goto done;
ecf709
-            }
ecf709
-            num_strings++;
ecf709
-        }
ecf709
-
ecf709
-    } while (*sep_pos != '\0');
ecf709
-
ecf709
-    if (list == NULL) {
ecf709
-        /* No allocations were done, make space for the NULL */
ecf709
-        list = talloc(tmp_ctx, char *);
ecf709
-        if (list == NULL) {
ecf709
-            ret = ENOMEM;
ecf709
-            goto done;
ecf709
-        }
ecf709
-    }
ecf709
-    list[num_strings] = NULL;
ecf709
-
ecf709
-    if (size) {
ecf709
-        *size = num_strings;
ecf709
-    }
ecf709
-
ecf709
-    *_list = talloc_steal(mem_ctx, list);
ecf709
-    ret = EOK;
ecf709
-done:
ecf709
-    talloc_free(tmp_ctx);
ecf709
-    return ret;
ecf709
-}
ecf709
-
ecf709
 static void free_args(char **args)
ecf709
 {
ecf709
     int i;
ecf709
diff --git a/src/util/util_ext.c b/src/util/util_ext.c
ecf709
new file mode 100644
ecf709
index 0000000000000000000000000000000000000000..fceb8c873a26471d476b39d5d4e567c445ed8d0b
ecf709
--- /dev/null
ecf709
+++ b/src/util/util_ext.c
ecf709
@@ -0,0 +1,121 @@
ecf709
+/*
ecf709
+   SSSD helper calls - can be used by libraries for external use as well
ecf709
+
ecf709
+    Authors:
ecf709
+        Simo Sorce <ssorce@redhat.com>
ecf709
+
ecf709
+    Copyright (C) 2017 Red Hat
ecf709
+
ecf709
+    This program is free software; you can redistribute it and/or modify
ecf709
+    it under the terms of the GNU General Public License as published by
ecf709
+    the Free Software Foundation; either version 3 of the License, or
ecf709
+    (at your option) any later version.
ecf709
+
ecf709
+    This program is distributed in the hope that it will be useful,
ecf709
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
ecf709
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ecf709
+    GNU General Public License for more details.
ecf709
+
ecf709
+    You should have received a copy of the GNU General Public License
ecf709
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
ecf709
+*/
ecf709
+
ecf709
+#include <talloc.h>
ecf709
+#include <stdbool.h>
ecf709
+#include <errno.h>
ecf709
+#include <ctype.h>
ecf709
+
ecf709
+#define EOK 0
ecf709
+
ecf709
+int split_on_separator(TALLOC_CTX *mem_ctx, const char *str,
ecf709
+                       const char sep, bool trim, bool skip_empty,
ecf709
+                       char ***_list, int *size)
ecf709
+{
ecf709
+    int ret;
ecf709
+    const char *substr_end = str;
ecf709
+    const char *substr_begin = str;
ecf709
+    const char *sep_pos = NULL;
ecf709
+    size_t substr_len;
ecf709
+    char **list = NULL;
ecf709
+    int num_strings = 0;
ecf709
+    TALLOC_CTX *tmp_ctx = NULL;
ecf709
+
ecf709
+    if (str == NULL || *str == '\0' || _list == NULL) {
ecf709
+        return EINVAL;
ecf709
+    }
ecf709
+
ecf709
+    tmp_ctx = talloc_new(NULL);
ecf709
+    if (tmp_ctx == NULL) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    do {
ecf709
+        substr_len = 0;
ecf709
+
ecf709
+        /* If this is not the first substring, then move from the separator. */
ecf709
+        if (sep_pos != NULL) {
ecf709
+            substr_end = sep_pos + 1;
ecf709
+            substr_begin = sep_pos + 1;
ecf709
+        }
ecf709
+
ecf709
+        /* Find end of the first substring */
ecf709
+        while (*substr_end != sep && *substr_end != '\0') {
ecf709
+            substr_end++;
ecf709
+            substr_len++;
ecf709
+        }
ecf709
+
ecf709
+        sep_pos = substr_end;
ecf709
+
ecf709
+        if (trim) {
ecf709
+            /* Trim leading whitespace */
ecf709
+            while (isspace(*substr_begin) && substr_begin < substr_end) {
ecf709
+                substr_begin++;
ecf709
+                substr_len--;
ecf709
+            }
ecf709
+
ecf709
+            /* Trim trailing whitespace */
ecf709
+            while (substr_end - 1 > substr_begin && isspace(*(substr_end-1))) {
ecf709
+                substr_end--;
ecf709
+                substr_len--;
ecf709
+            }
ecf709
+        }
ecf709
+
ecf709
+        /* Copy the substring to the output list of strings */
ecf709
+        if (skip_empty == false || substr_len > 0) {
ecf709
+            list = talloc_realloc(tmp_ctx, list, char*, num_strings + 2);
ecf709
+            if (list == NULL) {
ecf709
+                ret = ENOMEM;
ecf709
+                goto done;
ecf709
+            }
ecf709
+
ecf709
+            /* empty string is stored for substr_len == 0 */
ecf709
+            list[num_strings] = talloc_strndup(list, substr_begin, substr_len);
ecf709
+            if (list[num_strings] == NULL) {
ecf709
+                ret = ENOMEM;
ecf709
+                goto done;
ecf709
+            }
ecf709
+            num_strings++;
ecf709
+        }
ecf709
+
ecf709
+    } while (*sep_pos != '\0');
ecf709
+
ecf709
+    if (list == NULL) {
ecf709
+        /* No allocations were done, make space for the NULL */
ecf709
+        list = talloc(tmp_ctx, char *);
ecf709
+        if (list == NULL) {
ecf709
+            ret = ENOMEM;
ecf709
+            goto done;
ecf709
+        }
ecf709
+    }
ecf709
+    list[num_strings] = NULL;
ecf709
+
ecf709
+    if (size) {
ecf709
+        *size = num_strings;
ecf709
+    }
ecf709
+
ecf709
+    *_list = talloc_steal(mem_ctx, list);
ecf709
+    ret = EOK;
ecf709
+done:
ecf709
+    talloc_free(tmp_ctx);
ecf709
+    return ret;
ecf709
+}
ecf709
-- 
ecf709
2.9.3
ecf709