From 9f25d7d347c461254bb2f29ebf86ca49a898783d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 21 May 2018 10:24:37 +0200 Subject: core: use function string_split to split list items --- src/core/wee-url.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/core/wee-url.c b/src/core/wee-url.c index 6c41bc5b0..bd3ce68c5 100644 --- a/src/core/wee-url.c +++ b/src/core/wee-url.c @@ -940,12 +940,11 @@ weeurl_option_map_cb (void *data, const void *key, const void *value) { CURL *curl; - int index, index_constant, rc; + int i, index, index_constant, rc, num_items; long long_value; long long long_long_value; struct curl_slist *slist; - char *list_copy, *list_entry_walker; - const char *list_entry_start; + char **items; /* make C compiler happy */ (void) hashtable; @@ -1015,27 +1014,18 @@ weeurl_option_map_cb (void *data, } break; case URL_TYPE_LIST: - slist = NULL; - list_copy = malloc (strlen ((const char *)value) + 1); - if (list_copy) + items = string_split (value, "\n", 0, 0, &num_items); + if (items) { - strcpy (list_copy, (const char *)value); - list_entry_start = list_copy; - list_entry_walker = list_copy; - while (*list_entry_walker) + slist = NULL; + for (i = 0; i < num_items; i++) { - if (*list_entry_walker == '\n') - { - *list_entry_walker = '\0'; - slist = curl_slist_append (slist, list_entry_start); - list_entry_start = list_entry_walker + 1; - } - ++list_entry_walker; + slist = curl_slist_append (slist, items[i]); } - slist = curl_slist_append (slist, list_entry_start); - free (list_copy); - curl_easy_setopt (curl, url_options[index].option, + curl_easy_setopt (curl, + url_options[index].option, slist); + string_free_split (items); } break; } -- cgit v1.2.3