public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: cygcheck: split out fetching data from cygwin.com Date: Thu, 26 Jan 2023 18:59:10 +0000 (GMT) [thread overview] Message-ID: <20230126185910.ACF3D3858D38@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=28594480df73bbed642b4471445fa106ee387730 commit 28594480df73bbed642b4471445fa106ee387730 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Thu Jan 26 19:58:24 2023 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Thu Jan 26 19:58:30 2023 +0100 Cygwin: cygcheck: split out fetching data from cygwin.com In preparation of new functionality, split fetching data from cygwin.com out of the package_grep() function. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> 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[] = "$-_.!*'(),"; /* the URL to query. */ -static const char base_url[] = +static const char grep_base_url[] = "http://cygwin.com/cgi-bin2/package-grep.cgi?text=1&grep="; #ifdef __x86_64__ @@ -2018,34 +2018,13 @@ static const char base_url[] = #endif static const char *ARCH_str = ARCH_STR; -/* 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 = (char *) alloca (sizeof (base_url) + strlen (ARCH_str) - + strlen (search) * 3); - strcpy (url, base_url); - - char *dest; - for (dest = &url[sizeof (base_url) - 1]; *search; search++) - { - if (isalnum (*search) - || memchr (safe_chars, *search, sizeof (safe_chars) - 1)) - { - *dest++ = *search; - } - else - { - *dest++ = '%'; - sprintf (dest, "%02x", (unsigned char) *search); - dest += 2; - } - } - strcpy (dest, ARCH_str); + DWORD rc = 0, rc_s = sizeof (DWORD); + HINTERNET hi = NULL, hurl = NULL; + char buf[4096]; + DWORD numread; /* Connect to the net and open the URL. */ if (InternetAttemptConnect (0) != ERROR_SUCCESS) @@ -2055,7 +2034,6 @@ package_grep (char *search) } /* Initialize WinInet and attempt to fetch our URL. */ - HINTERNET hi = NULL, hurl = NULL; if (!(hi = 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); /* Check the HTTP response code. */ - DWORD rc = 0, rc_s = sizeof (DWORD); if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, (void *) &rc, &rc_s, NULL)) return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL); - if (rc != 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); + if (rc != 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; } +/* 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 = (char *) alloca (sizeof (grep_base_url) + strlen (ARCH_str) + + strlen (search) * 3); + strcpy (url, grep_base_url); + + char *dest; + for (dest = &url[sizeof (grep_base_url) - 1]; *search; search++) + { + if (isalnum (*search) + || memchr (safe_chars, *search, sizeof (safe_chars) - 1)) + { + *dest++ = *search; + } + else + { + *dest++ = '%'; + sprintf (dest, "%02x", (unsigned char) *search); + dest += 2; + } + } + strcpy (dest, ARCH_str); + + return fetch_url (url, stdout); +} + static void __attribute__ ((__noreturn__)) usage (FILE * stream, int status) {
reply other threads:[~2023-01-26 18:59 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230126185910.ACF3D3858D38@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).