From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57119 invoked by alias); 23 May 2017 16:47:42 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 57047 invoked by uid 89); 23 May 2017 16:47:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: rgout0805.bt.lon5.cpcloud.co.uk Received: from rgout0805.bt.lon5.cpcloud.co.uk (HELO rgout0805.bt.lon5.cpcloud.co.uk) (65.20.0.152) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 May 2017 16:47:40 +0000 X-OWM-Source-IP: 86.164.192.158 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-Junkmail-Premium-Raw: score=7/50,refid=2.7.2:2017.5.23.161815:17:7.944,ip=,rules=__HAS_FROM, __TO_MALFORMED_2, __TO_NO_NAME, __HAS_CC_HDR, __CC_NAME, __CC_NAME_DIFF_FROM_ACC, __HAS_MSGID, __SANE_MSGID, __HAS_X_MAILER, __IN_REP_TO, __REFERENCES, __FROM_DOMAIN_IN_ANY_CC1, __STOCK_PHRASE_7, __OEM_PRICE, __FRAUD_MONEY_CURRENCY_DOLLAR, BODY_SIZE_6000_6999, __MIME_TEXT_P1, __MIME_TEXT_ONLY, HTML_00_01, HTML_00_10, __FRAUD_MONEY_CURRENCY, IN_REP_TO, MSG_THREAD, __FROM_DOMAIN_IN_RCPT, __CC_REAL_NAMES, MULTIPLE_REAL_RCPTS, LEGITIMATE_SIGNS, NO_URI_FOUND, NO_CTA_URI_FOUND, __MIME_TEXT_P, REFERENCES, NO_URI_HTTPS, BODY_SIZE_7000_LESS Received: from localhost.localdomain (86.164.192.158) by rgout08.bt.lon5.cpcloud.co.uk (9.0.019.13-1) (authenticated as jonturney@btinternet.com) id 58BFF08008A2692E; Tue, 23 May 2017 17:47:21 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 07/10] Fold build(Install|Source)(MD5|SHA512) into buildPackage(Install|Source) Date: Tue, 23 May 2017 16:47:00 -0000 Message-Id: <20170523164558.50320-8-jon.turney@dronecode.org.uk> In-Reply-To: <20170523164558.50320-1-jon.turney@dronecode.org.uk> References: <20170523164558.50320-1-jon.turney@dronecode.org.uk> X-SW-Source: 2017-05/txt/msg00135.txt.bz2 Fold build(Install|Source)(MD5|SHA512) into buildPackage(Install|Source), so the (pathname, size, hash) information from an install: or source: line is all processed together. --- IniDBBuilderPackage.cc | 76 ++++++++++++++++++++++++++++---------------------- IniDBBuilderPackage.h | 20 +++++++++---- iniparse.yy | 16 +++-------- 3 files changed, 60 insertions(+), 52 deletions(-) diff --git a/IniDBBuilderPackage.cc b/IniDBBuilderPackage.cc index c90bfe3..ad1cc88 100644 --- a/IniDBBuilderPackage.cc +++ b/IniDBBuilderPackage.cc @@ -120,15 +120,37 @@ IniDBBuilderPackage::buildPackageLDesc (const std::string& theDesc) void IniDBBuilderPackage::buildPackageInstall (const std::string& path, - const std::string& size) + const std::string& size, + char *hash, + hashType type) { process_src (*cbpv.source(), path); setSourceSize (*cbpv.source(), size); + + switch (type) { + case hashType::sha512: + if (hash && !cbpv.source()->sha512_isSet) + { + memcpy (cbpv.source()->sha512sum, hash, sizeof(cbpv.source()->sha512sum)); + cbpv.source()->sha512_isSet = true; + } + break; + + case hashType::md5: + if (hash && !cbpv.source()->md5.isSet()) + cbpv.source()->md5.set((unsigned char *)hash); + break; + + case hashType::none: + break; + } } void IniDBBuilderPackage::buildPackageSource (const std::string& path, - const std::string& size) + const std::string& size, + char *hash, + hashType type) { packagedb db; /* get an appropriate metadata */ @@ -168,6 +190,24 @@ IniDBBuilderPackage::buildPackageSource (const std::string& path, spec.setVersion (cbpv.Canonical_version()); setSourceSize (*cspv.source(), size); + + switch (type) { + case hashType::sha512: + if (hash && !cspv.source()->sha512_isSet) + { + memcpy (cspv.source()->sha512sum, hash, sizeof(cspv.source()->sha512sum)); + cspv.source()->sha512_isSet = true; + } + break; + + case hashType::md5: + if (hash && !cspv.source()->md5.isSet()) + cspv.source()->md5.set((unsigned char *)hash); + break; + + case hashType::none: + break; + } } void @@ -200,38 +240,6 @@ IniDBBuilderPackage::buildBeginDepends () } void -IniDBBuilderPackage::buildInstallSHA512 (unsigned char const *sha512) -{ - if (sha512 && !cbpv.source()->sha512_isSet) { - memcpy (cbpv.source()->sha512sum, sha512, sizeof cbpv.source()->sha512sum); - cbpv.source()->sha512_isSet = true; - } -} - -void -IniDBBuilderPackage::buildSourceSHA512 (unsigned char const *sha512) -{ - if (sha512 && !cspv.source()->sha512_isSet) { - memcpy (cspv.source()->sha512sum, sha512, sizeof cspv.source()->sha512sum); - cspv.source()->sha512_isSet = true; - } -} - -void -IniDBBuilderPackage::buildInstallMD5 (unsigned char const *md5) -{ - if (md5 && !cbpv.source()->md5.isSet()) - cbpv.source()->md5.set(md5); -} - -void -IniDBBuilderPackage::buildSourceMD5 (unsigned char const *md5) -{ - if (md5 && !cspv.source()->md5.isSet()) - cspv.source()->md5.set(md5); -} - -void IniDBBuilderPackage::buildBeginBuildDepends () { #if DEBUG diff --git a/IniDBBuilderPackage.h b/IniDBBuilderPackage.h index 1dab41b..766a5ef 100644 --- a/IniDBBuilderPackage.h +++ b/IniDBBuilderPackage.h @@ -18,10 +18,13 @@ #include #include "package_version.h" + class IniParseFeedback; class packagesource; class packagemeta; +enum class hashType { none, md5, sha512 }; + class IniDBBuilderPackage { public: @@ -34,16 +37,21 @@ public: void buildPackageVersion (const std::string& ); void buildPackageSDesc (const std::string& ); void buildPackageLDesc (const std::string& ); - void buildPackageInstall (const std::string&, const std::string&); - void buildPackageSource (const std::string&, const std::string&); + void buildPackageInstall (const std::string&, const std::string&, + char *, hashType); + void buildPackageSource (const std::string&, const std::string&, + char *, hashType); + + // helpers for ScanFindVisitor + void buildPackageInstall (const std::string& path, const std::string& size) + { buildPackageInstall(path, size, NULL, hashType::none); } + void buildPackageSource (const std::string& path, const std::string& size) + { buildPackageSource(path, size, NULL, hashType::none); } + void buildPackageTrust (int); void buildPackageCategory (const std::string& ); void buildBeginDepends (); - void buildInstallSHA512 (unsigned char const[64]); - void buildSourceSHA512 (unsigned char const[64]); - void buildInstallMD5 (unsigned char const[16]); - void buildSourceMD5 (unsigned char const[16]); void buildBeginBuildDepends (); void buildMessage (const std::string&, const std::string&); void buildSourceName (const std::string& ); diff --git a/iniparse.yy b/iniparse.yy index 98b51bb..d768400 100644 --- a/iniparse.yy +++ b/iniparse.yy @@ -96,8 +96,10 @@ singleitem /* non-empty */ | T_OTHER NL { iniBuilder->buildPackageTrust (TRUST_OTHER); } | SOURCEPACKAGE source NL | CATEGORY categories NL - | INSTALL STRING STRING { iniBuilder->buildPackageInstall ($2, $3);} installchksum NL - | SOURCE STRING STRING sourcechksum NL {iniBuilder->buildPackageSource ($2, $3);} + | INSTALL STRING STRING MD5 NL { iniBuilder->buildPackageInstall ($2, $3, $4, hashType::md5); } + | INSTALL STRING STRING SHA512 NL { iniBuilder->buildPackageInstall ($2, $3, $4, hashType::sha512); } + | SOURCE STRING STRING MD5 NL {iniBuilder->buildPackageSource ($2, $3, $4, hashType::md5); } + | SOURCE STRING STRING SHA512 NL {iniBuilder->buildPackageSource ($2, $3, $4, hashType::sha512); } | DEPENDS { iniBuilder->buildBeginDepends(); } versionedpackagelist NL | REQUIRES { iniBuilder->buildBeginDepends(); } versionedpackagelistsp NL | BUILDDEPENDS { iniBuilder->buildBeginBuildDepends(); } versionedpackagelist NL @@ -112,16 +114,6 @@ categories: /* empty */ | categories STRING { iniBuilder->buildPackageCategory ($2); } ; -installchksum /* non-empty */ - : MD5 { iniBuilder->buildInstallMD5 ((unsigned char *)$1);} - | SHA512 { iniBuilder->buildInstallSHA512 ((unsigned char *)$1);} - ; - -sourcechksum /* non-empty */ - : MD5 { iniBuilder->buildSourceMD5 ((unsigned char *)$1); } - | SHA512 { iniBuilder->buildSourceSHA512 ((unsigned char *)$1); } - ; - source /* non-empty */ : STRING { iniBuilder->buildSourceName ($1); } versioninfo ; -- 2.12.3