From: Richard W.M. Jones <"Richard W.M. Jones "> Date: Thu, 13 Nov 2008 17:25:18 +0000 (+0000) Subject: Added https test program. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=9bd22d3923c4be0e2f371260a2991fb723a2e86a;p=fedora-mingw.git Added https test program. --- diff --git a/.hgignore b/.hgignore index 22548f6..add1d0e 100644 --- a/.hgignore +++ b/.hgignore @@ -17,6 +17,8 @@ cairo/svgspacewar cairo/svgspacewar.exe cairomm/cairomm-1.6.2.tar.gz curl/curl-7.18.2.tar.bz2 +curl/test1 +curl/*.exe expat/expat-2.0.1.tar.gz fontconfig/fontconfig-2.6.0.tar.gz freetype/freetype-2.3.7.tar.bz2 diff --git a/curl/Makefile b/curl/Makefile new file mode 100644 index 0000000..1bdb7e3 --- /dev/null +++ b/curl/Makefile @@ -0,0 +1,18 @@ +# Build some libcurl test programs under Wine. + +CFLAGS = -g `pkg-config --cflags libcurl` +LIBS = `pkg-config --libs libcurl` + +MINGW32_LIBDIR = /usr/i686-pc-mingw32/sys-root/mingw/lib + +all: test1 test1.exe + +test1: test1.c + gcc $(CFLAGS) $< $(LIBS) -o $@ + +test1.exe: test1.c + export PKG_CONFIG_PATH=$(MINGW32_LIBDIR)/pkgconfig; \ + i686-pc-mingw32-gcc $(CFLAGS) $< $(LIBS) -o $@ + +clean: + rm -f test1 *.exe *~ diff --git a/curl/mingw32-curl.spec b/curl/mingw32-curl.spec index ece71f6..94ccb8c 100644 --- a/curl/mingw32-curl.spec +++ b/curl/mingw32-curl.spec @@ -6,7 +6,7 @@ Name: mingw32-curl Version: 7.18.2 -Release: 1%{?dist} +Release: 2%{?dist} Summary: MinGW Windows port of curl and libcurl License: MIT @@ -27,7 +27,7 @@ Patch5: curl-7.18.2-nss-thread-safety.patch # MinGW-specific patches. Patch1000: mingw-curl-7.18.2-getaddrinfo.patch -BuildRequires: mingw32-filesystem >= 34 +BuildRequires: mingw32-filesystem >= 35 BuildRequires: mingw32-gcc BuildRequires: mingw32-binutils BuildRequires: pkgconfig @@ -120,5 +120,8 @@ rm -rf $RPM_BUILD_ROOT %changelog +* Thu Nov 13 2008 Richard W.M. Jones - 7.18.2-2 +- Requires mingw32-filesystem >= 35. + * Thu Nov 13 2008 Richard W.M. Jones - 7.18.2-1 - Initial RPM release. diff --git a/curl/test1.c b/curl/test1.c new file mode 100644 index 0000000..bb44050 --- /dev/null +++ b/curl/test1.c @@ -0,0 +1,99 @@ +/* Test using curl to fetch pages, look at headers, cookies. */ + +#include +#include + +#include + +static const char *url = "https://fedoraproject.org/wiki/MinGW"; + +static int bytes_received = 0; + +static size_t +write_fn (void *ptr, size_t size, size_t nmemb, void *stream) +{ + int bytes = size * nmemb; + bytes_received += bytes; + return bytes; +} + +static size_t +header_fn (void *ptr, size_t size, size_t nmemb, void *stream) +{ + int bytes = size * nmemb; + int i; + + /* Note that we are called once for each header, but the + * header data is not NUL-terminated. However we expect each + * header is terminated by \r\n. Hence: + */ + for (i = 0; i < bytes; ++i) + putchar (((char *)ptr)[i]); + + return bytes; +} + +int +main () +{ + CURLcode r; + CURL *curl; + long code; + + r = curl_global_init (CURL_GLOBAL_ALL); + if (r != 0) { + fprintf (stderr, "curl_global_init failed with code %d\n", r); + exit (1); + } + + curl = curl_easy_init (); + if (curl == NULL) { + fprintf (stderr, "curl_easy_init failed\n"); + exit (1); + } + + r = curl_easy_setopt (curl, CURLOPT_URL, url); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_setopt CURLOPT_URL failed with code %d\n", r); + exit (1); + } + + r = curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_fn); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_setopt CURLOPT_WRITEFUNCTION failed with code %d\n", r); + exit (1); + } + + r = curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, header_fn); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_setopt CURLOPT_HEADERFUNCTION failed with code %d\n", r); + exit (1); + } + + /* This enables cookie handling in libcurl: */ + r = curl_easy_setopt (curl, CURLOPT_COOKIEFILE, ""); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_setopt CURLOPT_COOKIEFILE failed with code %d\n", r); + exit (1); + } + + /* Fetch the page. */ + printf ("fetching %s ...\n", url); + r = curl_easy_perform (curl); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_perform failed with code %d\n", r); + exit (1); + } + printf ("... ok, bytes received in body was %d\n", bytes_received); + + r = curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code); + if (r != CURLE_OK) { + fprintf (stderr, "curl_easy_getinfo CURLINFO_RESPONSE_CODE failed with code %d\n", r); + exit (1); + } + printf ("HTTP response code: %d\n", (int) code); + + curl_easy_cleanup (curl); + curl_global_cleanup (); + exit (0); +}