On Mon, Aug 07, 2017 at 06:18:34PM +0200, Pino Toscano wrote: > libsoup is used to check the validity of URLs in distributions in > osinfo-db; OTOH it supports only HTTP(S), so this limits the checks to > that protocol. > > To overcome this limitation, switch to libcurl: while it requires > slightly more code to do the same task, it provides a bit more > flexibility, and support for other protocols. No version check is > performed, since the APIs used are old enough. Regardless of this improvement, I would switch the few ftp URLs we have in libosinfo database to use https instead, I'll send a patch for that. Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx> Christophe > > Adapt also the README, and the packaging files. > --- > README | 2 +- > configure.ac | 12 +++--------- > libosinfo.spec.in | 2 +- > mingw-libosinfo.spec.in | 4 ++-- > tests/Makefile.am | 4 ++-- > tests/test-mediauris.c | 39 ++++++++++++++++++++++++--------------- > tests/test-treeuris.c | 39 ++++++++++++++++++++++++--------------- > 7 files changed, 57 insertions(+), 45 deletions(-) > > diff --git a/README b/README > index b2c54ae..1d1f47a 100644 > --- a/README > +++ b/README > @@ -21,7 +21,7 @@ Dependencies > - Required: > - gobject-2.0 > - gio-2.0 > - - libsoup-2.4 > + - libcurl > - libxml-2.0 > - libxslt-1.0 > > diff --git a/configure.ac b/configure.ac > index c10e9e7..7cdf091 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -40,10 +40,6 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) > GLIB_MINIMUM_VERSION="2.36" > GLIB_ENCODED_VERSION="GLIB_VERSION_2_36" > > -# Keep these two definitions in agreement. > -SOUP_MINIMUM_VERSION="2.42" > -SOUP_ENCODED_VERSION="SOUP_VERSION_2_42" > - > PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.6.0]) > PKG_CHECK_MODULES([LIBXSLT], [libxslt >= 1.0.0]) > > @@ -53,11 +49,9 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MAX_ALLOWED=$GLIB_ENCODED_VERSION" > AC_SUBST(GLIB_CFLAGS) > AC_SUBST(GLIB_LIBS) > > -PKG_CHECK_MODULES([SOUP], [libsoup-2.4 >= $SOUP_MINIMUM_VERSION]) > -SOUP_CFLAGS="$SOUP_CFLAGS -DSOUP_VERSION_MIN_REQUIRED=$SOUP_ENCODED_VERSION" > -SOUP_CFLAGS="$SOUP_CFLAGS -DSOUP_VERSION_MAX_ALLOWED=$SOUP_ENCODED_VERSION" > -AC_SUBST(SOUP_CFLAGS) > -AC_SUBST(SOUP_LIBS) > +PKG_CHECK_MODULES([CURL], [libcurl]) > +AC_SUBST(CURL_CFLAGS) > +AC_SUBST(CURL_LIBS) > > GTK_DOC_CHECK([1.10],[--flavour no-tmpl]) > > diff --git a/libosinfo.spec.in b/libosinfo.spec.in > index d553341..5a5e6f8 100644 > --- a/libosinfo.spec.in > +++ b/libosinfo.spec.in > @@ -16,7 +16,7 @@ BuildRequires: libxml2-devel >= 2.6.0 > BuildRequires: libxslt-devel >= 1.0.0 > BuildRequires: vala > BuildRequires: vala-tools > -BuildRequires: libsoup-devel > +BuildRequires: libcurl-devel > BuildRequires: /usr/bin/pod2man > BuildRequires: hwdata > BuildRequires: gobject-introspection-devel > diff --git a/mingw-libosinfo.spec.in b/mingw-libosinfo.spec.in > index bd58f25..0653282 100644 > --- a/mingw-libosinfo.spec.in > +++ b/mingw-libosinfo.spec.in > @@ -26,8 +26,8 @@ BuildRequires: mingw32-libxml2 > BuildRequires: mingw64-libxml2 > BuildRequires: mingw32-libxslt > BuildRequires: mingw64-libxslt > -BuildRequires: mingw32-libsoup > -BuildRequires: mingw64-libsoup > +BuildRequires: mingw32-libcurl > +BuildRequires: mingw64-libcurl > > BuildRequires: pkgconfig > > diff --git a/tests/Makefile.am b/tests/Makefile.am > index 9d10ee5..e3df06b 100644 > --- a/tests/Makefile.am > +++ b/tests/Makefile.am > @@ -25,7 +25,7 @@ COMMON_LDADD = \ > $(COVERAGE_LDFLAGS) \ > $(GLIB_LIBS) \ > $(GOBJECT_LIBS) \ > - $(SOUP_LIBS) \ > + $(CURL_LIBS) \ > $(CHECK_LIBS) \ > ../osinfo/libosinfo-1.0.la > COMMON_CFLAGS = \ > @@ -33,7 +33,7 @@ COMMON_CFLAGS = \ > $(COVERAGE_CFLAGS) \ > $(GLIB_CFLAGS) \ > $(GOBJECT_CFLAGS) \ > - $(SOUP_CFLAGS) \ > + $(CURL_CFLAGS) \ > -I$(top_srcdir) \ > -DSRCDIR="\"$(abs_top_srcdir)\"" \ > -DBUILDDIR="\"$(abs_top_builddir)\"" \ > diff --git a/tests/test-mediauris.c b/tests/test-mediauris.c > index 837197c..366136f 100644 > --- a/tests/test-mediauris.c > +++ b/tests/test-mediauris.c > @@ -25,9 +25,9 @@ > #include <stdlib.h> > #include <osinfo/osinfo.h> > #include <check.h> > -#include <libsoup/soup.h> > +#include <curl/curl.h> > > -static void test_media(OsinfoMediaList *medialist, GError **error, SoupSession *session) > +static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl) > { > GList *mediael = NULL, *tmp; > > @@ -35,8 +35,8 @@ static void test_media(OsinfoMediaList *medialist, GError **error, SoupSession * > while (tmp) { > OsinfoMedia *media = tmp->data; > const gchar *url = osinfo_media_get_url(media); > - SoupMessage *msg; > - guint status; > + CURLcode res; > + long response_code; > > if (url == NULL || g_str_equal(url, "") || > (!g_str_has_prefix(url, "http://") && !g_str_has_prefix(url, "https://"))) { > @@ -45,12 +45,14 @@ static void test_media(OsinfoMediaList *medialist, GError **error, SoupSession * > } > > g_print("%s\n", url); > - msg = soup_message_new("HEAD", url); > - status = soup_session_send_message(session, msg); > + curl_easy_setopt(curl, CURLOPT_URL, url); > + res = curl_easy_perform(curl); > + if (res != CURLE_OK) { > + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); > + } > > - fail_unless(SOUP_STATUS_IS_SUCCESSFUL(status), "Failed HEAD (code=%u) on %s", status, url); > + fail_unless(res == CURLE_OK, "Failed HEAD (res=%d, %s; code=%ld) on %s", res, curl_easy_strerror(res), response_code, url); > > - g_object_unref(msg); > tmp = tmp->next; > } > > @@ -59,7 +61,7 @@ static void test_media(OsinfoMediaList *medialist, GError **error, SoupSession * > > START_TEST(test_uris) > { > - SoupSession *session; > + CURL *curl; > OsinfoLoader *loader = osinfo_loader_new(); > OsinfoDb *db = osinfo_loader_get_db(loader); > GError *error = NULL; > @@ -67,15 +69,17 @@ START_TEST(test_uris) > GList *osel = NULL, *tmp; > const gchar *debugstr; > > - session = soup_session_new(); > + curl = curl_easy_init(); > + curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); > + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L); > + curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); > + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); > + curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); > > if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) { > - SoupLogger *logger; > int debug_level = atoi(debugstr); > > - logger = soup_logger_new(debug_level, -1); > - soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger)); > - g_object_unref(logger); > + curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L); > } > > fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); > @@ -90,7 +94,7 @@ START_TEST(test_uris) > OsinfoOs *os = tmp->data; > OsinfoMediaList *medialist = osinfo_os_get_media_list(os); > > - test_media(medialist, &error, session); > + test_media(medialist, &error, curl); > > fail_unless(error == NULL, error ? error->message : "none"); > > @@ -98,6 +102,8 @@ START_TEST(test_uris) > tmp = tmp->next; > } > > + curl_easy_cleanup(curl); > + > g_list_free(osel); > if (oslist) > g_object_unref(oslist); > @@ -133,6 +139,7 @@ int main(void) > return 77; /* Skip */ > > /* Upfront so we don't confuse valgrind */ > + curl_global_init(CURL_GLOBAL_ALL); > osinfo_entity_get_type(); > osinfo_db_get_type(); > osinfo_device_get_type(); > @@ -148,6 +155,8 @@ int main(void) > number_failed = srunner_ntests_failed(sr); > srunner_free(sr); > > + curl_global_cleanup(); > + > return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; > } > /* > diff --git a/tests/test-treeuris.c b/tests/test-treeuris.c > index 60692bc..defe3a7 100644 > --- a/tests/test-treeuris.c > +++ b/tests/test-treeuris.c > @@ -25,9 +25,9 @@ > #include <stdlib.h> > #include <osinfo/osinfo.h> > #include <check.h> > -#include <libsoup/soup.h> > +#include <curl/curl.h> > > -static void test_tree(OsinfoTreeList *treelist, GError **error, SoupSession *session) > +static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl) > { > GList *treeel = NULL, *tmp; > > @@ -35,8 +35,8 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, SoupSession *ses > while (tmp) { > OsinfoTree *tree = tmp->data; > const gchar *url = osinfo_tree_get_url(tree); > - SoupMessage *msg; > - guint status; > + CURLcode res; > + long response_code; > > if (url == NULL || g_str_equal(url, "")) { > tmp = tmp->next; > @@ -44,12 +44,14 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, SoupSession *ses > } > > g_print("%s\n", url); > - msg = soup_message_new("HEAD", url); > - status = soup_session_send_message(session, msg); > + curl_easy_setopt(curl, CURLOPT_URL, url); > + res = curl_easy_perform(curl); > + if (res != CURLE_OK) { > + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); > + } > > - fail_unless(SOUP_STATUS_IS_SUCCESSFUL(status), "Failed HEAD on %s", url); > + fail_unless(res == CURLE_OK, "Failed HEAD (res=%d, %s; code=%ld) on %s", res, curl_easy_strerror(res), response_code, url); > > - g_object_unref(msg); > tmp = tmp->next; > } > > @@ -58,7 +60,7 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, SoupSession *ses > > START_TEST(test_uris) > { > - SoupSession *session; > + CURL *curl; > OsinfoLoader *loader = osinfo_loader_new(); > OsinfoDb *db = osinfo_loader_get_db(loader); > GError *error = NULL; > @@ -66,15 +68,17 @@ START_TEST(test_uris) > GList *osel = NULL, *tmp; > const gchar *debugstr; > > - session = soup_session_new(); > + curl = curl_easy_init(); > + curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); > + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60L); > + curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L); > + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); > + curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); > > if ((debugstr = g_getenv("LIBOSINFO_TEST_DEBUG"))) { > - SoupLogger *logger; > int debug_level = atoi(debugstr); > > - logger = soup_logger_new(debug_level, -1); > - soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger)); > - g_object_unref(logger); > + curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L); > } > > fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); > @@ -89,7 +93,7 @@ START_TEST(test_uris) > OsinfoOs *os = tmp->data; > OsinfoTreeList *treelist = osinfo_os_get_tree_list(os); > > - test_tree(treelist, &error, session); > + test_tree(treelist, &error, curl); > > fail_unless(error == NULL, error ? error->message : "none"); > > @@ -97,6 +101,8 @@ START_TEST(test_uris) > tmp = tmp->next; > } > > + curl_easy_cleanup(curl); > + > g_list_free(osel); > if (oslist) > g_object_unref(oslist); > @@ -132,6 +138,7 @@ int main(void) > return 77; /* Skip */ > > /* Upfront so we don't confuse valgrind */ > + curl_global_init(CURL_GLOBAL_ALL); > osinfo_entity_get_type(); > osinfo_db_get_type(); > osinfo_device_get_type(); > @@ -147,6 +154,8 @@ int main(void) > number_failed = srunner_ntests_failed(sr); > srunner_free(sr); > > + curl_global_cleanup(); > + > return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; > } > /* > -- > 2.13.4 > > _______________________________________________ > Libosinfo mailing list > Libosinfo@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libosinfo _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo