This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH setup 07/10] Fold build(Install|Source)(MD5|SHA512) into buildPackage(Install|Source)


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 <vector>
 #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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]