From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id ACF3D3858D38; Thu, 26 Jan 2023 18:59:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACF3D3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674759550; bh=VaHS8XzSEE9XbqNMXZ2UdC2CzLTZ1tVIk8dTQheZxpQ=; h=From:To:Subject:Date:From; b=f3EMMccwfchzlBu6bIMoNFMMcBdyOX00V1DLRyfSeCfY7yosUM+7sStvhTiv1J80O Fzx47g4RXz/kBpiPZX4rAAPXuow/PxO6wGr0FVEBE9azWP8hD9mJJZQXGPhrCvjr0U tFGIOrzbl6X9EaJYfZEHvakHjJlYSj1PNchQrDbU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: cygcheck: split out fetching data from cygwin.com X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: bf915420042eadf29622c9a7b7ab12221f238fe5 X-Git-Newrev: 28594480df73bbed642b4471445fa106ee387730 Message-Id: <20230126185910.ACF3D3858D38@sourceware.org> Date: Thu, 26 Jan 2023 18:59:10 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D28594480df7= 3bbed642b4471445fa106ee387730 commit 28594480df73bbed642b4471445fa106ee387730 Author: Corinna Vinschen AuthorDate: Thu Jan 26 19:58:24 2023 +0100 Commit: Corinna Vinschen CommitDate: Thu Jan 26 19:58:30 2023 +0100 Cygwin: cygcheck: split out fetching data from cygwin.com =20 In preparation of new functionality, split fetching data from cygwin.com out of the package_grep() function. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/utils/mingw/cygcheck.cc | 84 ++++++++++++++++++++++----------------= ---- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/winsup/utils/mingw/cygcheck.cc b/winsup/utils/mingw/cygcheck.cc index 69f75927fca7..ce97cfe3a862 100644 --- a/winsup/utils/mingw/cygcheck.cc +++ b/winsup/utils/mingw/cygcheck.cc @@ -2008,7 +2008,7 @@ check_keys () static const char safe_chars[] =3D "$-_.!*'(),"; =20 /* the URL to query. */ -static const char base_url[] =3D +static const char grep_base_url[] =3D "http://cygwin.com/cgi-bin2/package-grep.cgi?text=3D1&grep=3D"; =20 #ifdef __x86_64__ @@ -2018,34 +2018,13 @@ static const char base_url[] =3D #endif static const char *ARCH_str =3D ARCH_STR; =20 -/* Queries Cygwin web site for packages containing files matching a regexp. - Return value is 1 if there was a problem, otherwise 0. */ static int -package_grep (char *search) +fetch_url (const char *url, FILE *outstream) { - char buf[1024]; - - /* construct the actual URL by escaping */ - char *url =3D (char *) alloca (sizeof (base_url) + strlen (ARCH_str) - + strlen (search) * 3); - strcpy (url, base_url); - - char *dest; - for (dest =3D &url[sizeof (base_url) - 1]; *search; search++) - { - if (isalnum (*search) - || memchr (safe_chars, *search, sizeof (safe_chars) - 1)) - { - *dest++ =3D *search; - } - else - { - *dest++ =3D '%'; - sprintf (dest, "%02x", (unsigned char) *search); - dest +=3D 2; - } - } - strcpy (dest, ARCH_str); + DWORD rc =3D 0, rc_s =3D sizeof (DWORD); + HINTERNET hi =3D NULL, hurl =3D NULL; + char buf[4096]; + DWORD numread; =20 /* Connect to the net and open the URL. */ if (InternetAttemptConnect (0) !=3D ERROR_SUCCESS) @@ -2055,7 +2034,6 @@ package_grep (char *search) } =20 /* Initialize WinInet and attempt to fetch our URL. */ - HINTERNET hi =3D NULL, hurl =3D NULL; if (!(hi =3D InternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) return display_internet_error ("InternetOpen() failed", NULL); @@ -2065,34 +2043,62 @@ package_grep (char *search) "InternetOpenUrl() failed", hi, NULL); =20 /* Check the HTTP response code. */ - DWORD rc =3D 0, rc_s =3D sizeof (DWORD); if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMB= ER, (void *) &rc, &rc_s, NULL)) return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NUL= L); =20 - if (rc !=3D HTTP_STATUS_OK) - { - sprintf (buf, "error retrieving results from cygwin.com site, " - "HTTP status code %lu", rc); - return display_internet_error (buf, hurl, hi, NULL); - } - - /* Fetch result and print to stdout. */ - DWORD numread; + /* Fetch result and print to outstream. */ do { if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread)) return display_internet_error ("InternetReadFile failed", hurl, hi, NULL); if (numread) - fwrite ((void *) buf, (size_t) numread, 1, stdout); + fwrite ((void *) buf, (size_t) numread, 1, outstream); } while (numread); =20 + if (rc !=3D HTTP_STATUS_OK) + { + sprintf (buf, "error retrieving results from cygwin.com site, " + "HTTP status code %lu", rc); + return display_internet_error (buf, hurl, hi, NULL); + } + InternetCloseHandle (hurl); InternetCloseHandle (hi); return 0; } =20 +/* Queries Cygwin web site for packages containing files matching a regexp. + Return value is 1 if there was a problem, otherwise 0. */ +static int +package_grep (char *search) +{ + /* construct the actual URL by escaping */ + char *url =3D (char *) alloca (sizeof (grep_base_url) + strlen (ARCH_str) + + strlen (search) * 3); + strcpy (url, grep_base_url); + + char *dest; + for (dest =3D &url[sizeof (grep_base_url) - 1]; *search; search++) + { + if (isalnum (*search) + || memchr (safe_chars, *search, sizeof (safe_chars) - 1)) + { + *dest++ =3D *search; + } + else + { + *dest++ =3D '%'; + sprintf (dest, "%02x", (unsigned char) *search); + dest +=3D 2; + } + } + strcpy (dest, ARCH_str); + + return fetch_url (url, stdout); +} + static void __attribute__ ((__noreturn__)) usage (FILE * stream, int status) {