From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-042.btinternet.com (mailomta14-re.btinternet.com [213.120.69.107]) by sourceware.org (Postfix) with ESMTPS id 54E723858D33 for ; Fri, 8 Mar 2024 18:35:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54E723858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 54E723858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.107 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922930; cv=none; b=S2R/m92USOGmTA1jK+MW3yrlCYTN6F4KZ1MPQxaCXHPCpq3JWmKf+dXMaqs28KUFl0qwCsxYvjCtKN10uNpjJlNsb88gpuYuW0/ero6ebjCEV807GotpVV0TMIDH+uOpClnsrBGxI3DE51N2X5xDohiuZBTc6rt7cL65W3lfnog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922930; c=relaxed/simple; bh=ytmxVx4YnNSs7mEC8nB34EYSV7Gk7zlFDKvKcUTG6cA=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=qTj+WxqT1OzOS9woudTccGBXNlo59ekZ0HUj4fgoZWXGyGWwZcyK7VGcpo+EVBFH9jgyLmBb27zIcUJsd3+dn/IvwuPcpt2KejO0hGjm+S5dSsONhXpYInDICHcLMtzd9hu91y1E5tT9MeA/TQy8/amR0W6voCjW7KgpKUcA4Jg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-042.btinternet.com with ESMTP id <20240308183525.LJYR4314.re-prd-fep-042.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:35:25 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB06532 X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepudeuudffgfeigedtueegieelfeelvdelgedutefgveegvddtteevgeeiffeujeegnecuffhomhgrihhnpehgnhhurdhorhhgpdhsohhurhgtvgifrghrvgdrohhrghdprhgvughhrghtrdgtohhmpdgtohhmrdhnvghtnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhr rghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhinhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB06532; Fri, 8 Mar 2024 18:35:25 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 04/16] Split out site into SiteSettings and SitePage Date: Fri, 8 Mar 2024 18:34:23 +0000 Message-ID: <20240308183440.4263-5-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Again, this will ultimately make it possible to specify, or store and retrieve from settings a site, without having a GUI. --- Makefile.am | 6 +- SiteSetting.cc | 193 +++++++++++++++++++++++++++++++++++++ site.h => SiteSetting.h | 57 +++-------- site.cc => gui/SitePage.cc | 169 +------------------------------- gui/SitePage.h | 45 +++++++++ ini.cc | 2 +- main.cc | 3 +- threebar.cc | 2 +- 8 files changed, 264 insertions(+), 213 deletions(-) create mode 100644 SiteSetting.cc rename site.h => SiteSetting.h (74%) rename site.cc => gui/SitePage.cc (77%) create mode 100644 gui/SitePage.h diff --git a/Makefile.am b/Makefile.am index 82efbd8..f753961 100644 --- a/Makefile.am +++ b/Makefile.am @@ -266,8 +266,10 @@ endif setup_version.c \ sha2.h \ sha2.c \ - site.cc \ - site.h \ + gui/SitePage.cc \ + gui/SitePage.h \ + SiteSetting.cc \ + SiteSetting.h \ source.cc \ source.h \ SourceSetting.cc \ diff --git a/SiteSetting.cc b/SiteSetting.cc new file mode 100644 index 0000000..be5f5d8 --- /dev/null +++ b/SiteSetting.cc @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2000, Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by DJ Delorie + * + */ + +#include "io_stream.h" +#include "SiteSetting.h" +#include "UserSettings.h" +#include "getopt++/StringArrayOption.h" +#include "getopt++/BoolOption.h" +#include "resource.h" + +#include +#include +#include +#include + +StringArrayOption SiteOption('s', "site", IDS_HELPTEXT_SITE); +extern BoolOption UnsupportedOption; + +/* Selected sites */ +SiteList site_list; + +/* Fresh mirrors + selected sites */ +SiteList all_site_list; + +SiteSetting::SiteSetting (): saved (false) +{ + std::vector SiteOptionStrings = SiteOption; + if (SiteOptionStrings.size()) + { + for (std::vector::const_iterator n = SiteOptionStrings.begin (); + n != SiteOptionStrings.end (); ++n) + registerSavedSite (n->c_str ()); + } + else + getSavedSites (); +} + +const char * +SiteSetting::lastMirrorKey () +{ + if (UnsupportedOption) + return "last-mirror-unsupported"; + + return "last-mirror"; +} + +void +SiteSetting::save() +{ + io_stream *f = UserSettings::instance().open (lastMirrorKey ()); + if (f) + { + for (SiteList::const_iterator n = site_list.begin (); + n != site_list.end (); ++n) + *f << n->url; + delete f; + } + saved = true; +} + +SiteSetting::~SiteSetting () +{ + if (!saved) + save (); +} + +/* List of machines that should not be used by default when saved + in "last-mirror". */ +#define NOSAVE1 "ftp://sourceware.org/" +#define NOSAVE1_LEN (sizeof (NOSAVE2) - 1) +#define NOSAVE2 "ftp://sources.redhat.com/" +#define NOSAVE2_LEN (sizeof (NOSAVE1) - 1) +#define NOSAVE3 "ftp://gcc.gnu.org/" +#define NOSAVE3_LEN (sizeof (NOSAVE3) - 1) + +void +SiteSetting::registerSavedSite (const char * site) +{ + site_list_type tempSite(site, "", "", "", false); + + /* Don't default to certain machines if they suffer from bandwidth + limitations. */ + if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0 + || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0 + || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0) + return; + + site_list_insert (all_site_list, tempSite); + site_list.push_back (tempSite); +} + +void +SiteSetting::getSavedSites () +{ + const char *buf = UserSettings::instance().get (lastMirrorKey ()); + if (!buf) + return; + char *fg_ret = strdup (buf); + for (char *site = strtok (fg_ret, "\n"); site; site = strtok (NULL, "\n")) + registerSavedSite (site); + free (fg_ret); +} + +site_list_type::site_list_type (const std::string &_url, + const std::string &_servername, + const std::string &_area, + const std::string &_location, + bool _from_mirrors_lst, + bool _noshow /* default: false */) +{ + url = _url; + servername = _servername; + area = _area; + location = _location; + from_mirrors_lst = _from_mirrors_lst; + noshow = _noshow; + + /* Canonicalize URL to ensure it ends with a '/' */ + if (url.at(url.length()-1) != '/') + url.append("/"); + + /* displayed_url is protocol and site name part of url */ + std::string::size_type path_offset = url.find ("/", url.find ("//") + 2); + displayed_url = url.substr(0, path_offset); + + /* the sorting key is hostname components in reverse order (to sort by country code) + plus the url (to ensure uniqueness) */ + key = std::string(); + std::string::size_type last_idx = displayed_url.length () - 1; + std::string::size_type idx = url.find_last_of("./", last_idx); + if (last_idx - idx == 3) + { + /* Sort non-country TLDs (.com, .net, ...) together. */ + key += " "; + } + do + { + key += url.substr(idx + 1, last_idx - idx); + key += " "; + last_idx = idx - 1; + idx = url.find_last_of("./", last_idx); + if (idx == std::string::npos) + idx = 0; + } while (idx > 0); + key += url; +} + +bool +site_list_type::operator == (site_list_type const &rhs) const +{ + return stricmp (key.c_str(), rhs.key.c_str()) == 0; +} + +bool +site_list_type::operator < (site_list_type const &rhs) const +{ + return stricmp (key.c_str(), rhs.key.c_str()) < 0; +} + +/* + A SiteList is maintained as an in-order std::vector of site_list_type, by + replacing it with a new object with the new item inserted in the correct + place. + + Yes, we could just use an ordered container, instead. +*/ +void +site_list_insert(SiteList &site_list, site_list_type newsite) +{ + SiteList::iterator i = find (site_list.begin(), site_list.end(), newsite); + if (i == site_list.end()) + { + SiteList result; + merge (site_list.begin(), site_list.end(), + &newsite, &newsite + 1, + inserter (result, result.begin())); + site_list = result; + } + else + *i = newsite; +} diff --git a/site.h b/SiteSetting.h similarity index 74% rename from site.h rename to SiteSetting.h index 6ec7cf3..0582a2e 100644 --- a/site.h +++ b/SiteSetting.h @@ -13,44 +13,30 @@ * */ -#ifndef SETUP_SITE_H -#define SETUP_SITE_H +#ifndef SETUP_SITESETTING_H +#define SETUP_SITESETTING_H -#include #include -#include "proppage.h" - -class SitePage : public PropertyPage +class SiteSetting { -public: - SitePage (); - virtual ~ SitePage () - { - }; - - bool Create (); - - virtual void OnInit (); - virtual void OnActivate (); - virtual long OnNext (); - virtual long OnBack (); - virtual long OnUnattended (); - - virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code); - - void PopulateListBox(); - void CheckControlsAndDisableAccordingly () const; + public: + SiteSetting (); + void save (); + ~SiteSetting (); + private: + bool saved; + void getSavedSites(); + void registerSavedSite(char const *); + const char *lastMirrorKey(); }; -void do_download_site_info (HINSTANCE h, HWND owner); - class site_list_type { public: site_list_type () : url (), displayed_url (), key () {}; site_list_type (const std::string& , const std::string& , - const std::string& , const std::string&, bool, bool); + const std::string& , const std::string&, bool, bool = false); ~site_list_type () {}; std::string url; // provided by mirrors.lst but not used @@ -74,22 +60,11 @@ public: typedef std::vector SiteList; +void site_list_insert(SiteList &site_list, site_list_type newsite); + /* user chosen sites */ extern SiteList site_list; /* potential sites */ extern SiteList all_site_list; -class SiteSetting -{ - public: - SiteSetting (); - void save (); - ~SiteSetting (); - private: - bool saved; - void getSavedSites(); - void registerSavedSite(char const *); - const char *lastMirrorKey(); -}; - -#endif /* SETUP_SITE_H */ +#endif /* SETUP_SITESETTING_H */ diff --git a/site.cc b/gui/SitePage.cc similarity index 77% rename from site.cc rename to gui/SitePage.cc index 569235a..69bac1d 100644 --- a/site.cc +++ b/gui/SitePage.cc @@ -19,7 +19,6 @@ #include #include -#include "site.h" #include "win32.h" #include #include @@ -32,7 +31,7 @@ #include "msg.h" #include "LogSingleton.h" #include "io_stream.h" -#include "site.h" +#include "gui/SitePage.h" #include "propsheet.h" @@ -71,19 +70,14 @@ SitePage::SitePage () sizeProcessor.AddControlInfo (SiteControlsInfo); } -#include "getopt++/StringArrayOption.h" #include "getopt++/BoolOption.h" #include "UserSettings.h" +#include "SiteSetting.h" bool cache_is_usable; bool cache_needs_writing; std::string cache_warn_urls; -/* Selected sites */ -SiteList site_list; - -/* Fresh mirrors + selected sites */ -SiteList all_site_list; /* Previously fresh + cached before */ SiteList cached_site_list; @@ -91,131 +85,9 @@ SiteList cached_site_list; /* Stale selected sites to warn about and add to cache */ SiteList dropped_site_list; -StringArrayOption SiteOption('s', "site", IDS_HELPTEXT_SITE); BoolOption OnlySiteOption(false, 'O', "only-site", IDS_HELPTEXT_ONLY_SITE); extern BoolOption UnsupportedOption; -SiteSetting::SiteSetting (): saved (false) -{ - std::vector SiteOptionStrings = SiteOption; - if (SiteOptionStrings.size()) - { - for (std::vector::const_iterator n = SiteOptionStrings.begin (); - n != SiteOptionStrings.end (); ++n) - registerSavedSite (n->c_str ()); - } - else - getSavedSites (); -} - -const char * -SiteSetting::lastMirrorKey () -{ - if (UnsupportedOption) - return "last-mirror-unsupported"; - - return "last-mirror"; -} - -void -SiteSetting::save() -{ - io_stream *f = UserSettings::instance().open (lastMirrorKey ()); - if (f) - { - for (SiteList::const_iterator n = site_list.begin (); - n != site_list.end (); ++n) - *f << n->url; - delete f; - } - saved = true; -} - -SiteSetting::~SiteSetting () -{ - if (!saved) - save (); -} - -site_list_type::site_list_type (const std::string &_url, - const std::string &_servername, - const std::string &_area, - const std::string &_location, - bool _from_mirrors_lst, - bool _noshow = false) -{ - url = _url; - servername = _servername; - area = _area; - location = _location; - from_mirrors_lst = _from_mirrors_lst; - noshow = _noshow; - - /* Canonicalize URL to ensure it ends with a '/' */ - if (url.at(url.length()-1) != '/') - url.append("/"); - - /* displayed_url is protocol and site name part of url */ - std::string::size_type path_offset = url.find ("/", url.find ("//") + 2); - displayed_url = url.substr(0, path_offset); - - /* the sorting key is hostname components in reverse order (to sort by country code) - plus the url (to ensure uniqueness) */ - key = std::string(); - std::string::size_type last_idx = displayed_url.length () - 1; - std::string::size_type idx = url.find_last_of("./", last_idx); - if (last_idx - idx == 3) - { - /* Sort non-country TLDs (.com, .net, ...) together. */ - key += " "; - } - do - { - key += url.substr(idx + 1, last_idx - idx); - key += " "; - last_idx = idx - 1; - idx = url.find_last_of("./", last_idx); - if (idx == std::string::npos) - idx = 0; - } while (idx > 0); - key += url; -} - -bool -site_list_type::operator == (site_list_type const &rhs) const -{ - return stricmp (key.c_str(), rhs.key.c_str()) == 0; -} - -bool -site_list_type::operator < (site_list_type const &rhs) const -{ - return stricmp (key.c_str(), rhs.key.c_str()) < 0; -} - -/* - A SiteList is maintained as an in-order std::vector of site_list_type, by - replacing it with a new object with the new item inserted in the correct - place. - - Yes, we could just use an ordered container, instead. -*/ -static void -site_list_insert(SiteList &site_list, site_list_type newsite) -{ - SiteList::iterator i = find (site_list.begin(), site_list.end(), newsite); - if (i == site_list.end()) - { - SiteList result; - merge (site_list.begin(), site_list.end(), - &newsite, &newsite + 1, - inserter (result, result.begin())); - site_list = result; - } - else - *i = newsite; -} - static void save_dialog (HWND h) { @@ -381,43 +253,6 @@ get_site_list (HINSTANCE h, HWND owner) return 0; } -/* List of machines that should not be used by default when saved - in "last-mirror". */ -#define NOSAVE1 "ftp://sourceware.org/" -#define NOSAVE1_LEN (sizeof (NOSAVE2) - 1) -#define NOSAVE2 "ftp://sources.redhat.com/" -#define NOSAVE2_LEN (sizeof (NOSAVE1) - 1) -#define NOSAVE3 "ftp://gcc.gnu.org/" -#define NOSAVE3_LEN (sizeof (NOSAVE3) - 1) - -void -SiteSetting::registerSavedSite (const char * site) -{ - site_list_type tempSite(site, "", "", "", false); - - /* Don't default to certain machines if they suffer from bandwidth - limitations. */ - if (strnicmp (site, NOSAVE1, NOSAVE1_LEN) == 0 - || strnicmp (site, NOSAVE2, NOSAVE2_LEN) == 0 - || strnicmp (site, NOSAVE3, NOSAVE3_LEN) == 0) - return; - - site_list_insert (all_site_list, tempSite); - site_list.push_back (tempSite); -} - -void -SiteSetting::getSavedSites () -{ - const char *buf = UserSettings::instance().get (lastMirrorKey ()); - if (!buf) - return; - char *fg_ret = strdup (buf); - for (char *site = strtok (fg_ret, "\n"); site; site = strtok (NULL, "\n")) - registerSavedSite (site); - free (fg_ret); -} - static DWORD WINAPI do_download_site_info_thread (void *p) { diff --git a/gui/SitePage.h b/gui/SitePage.h new file mode 100644 index 0000000..1208338 --- /dev/null +++ b/gui/SitePage.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2001, Robert Collins. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + * Written by Robert Collins + * + */ + +#ifndef SETUP_SITE_H +#define SETUP_SITE_H + +#include "proppage.h" + +class SitePage : public PropertyPage +{ +public: + SitePage (); + virtual ~ SitePage () + { + }; + + bool Create (); + + virtual void OnInit (); + virtual void OnActivate (); + virtual long OnNext (); + virtual long OnBack (); + virtual long OnUnattended (); + + virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code); + + void PopulateListBox(); + void CheckControlsAndDisableAccordingly () const; +}; + +void do_download_site_info (HINSTANCE h, HWND owner); + +#endif /* SETUP_SITE_H */ diff --git a/ini.cc b/ini.cc index 95c9964..3d3cbde 100644 --- a/ini.cc +++ b/ini.cc @@ -36,7 +36,7 @@ #include "geturl.h" #include "dialog.h" #include "mount.h" -#include "site.h" +#include "SiteSetting.h" #include "find.h" #include "IniParseFeedback.h" diff --git a/main.cc b/main.cc index cf9e323..2ce3b30 100644 --- a/main.cc +++ b/main.cc @@ -53,7 +53,7 @@ #include "root.h" #include "localdir.h" #include "net.h" -#include "site.h" +#include "gui/SitePage.h" #include "choose.h" #include "prereq.h" #include "confirm.h" @@ -74,6 +74,7 @@ #include "SourceSetting.h" #include "ConnectionSetting.h" #include "KeysSetting.h" +#include "SiteSetting.h" #include #include diff --git a/threebar.cc b/threebar.cc index bc356c0..16430bb 100644 --- a/threebar.cc +++ b/threebar.cc @@ -23,7 +23,7 @@ #include "resource.h" #include "dialog.h" -#include "site.h" +#include "gui/SitePage.h" #include "propsheet.h" #include "threebar.h" -- 2.43.0