Use latest Cygwin setup on AppVeyor
[cygwin-setup.git] / package_source.h
blobfae46f70cf45dc32ea964e1c54b09c6a0d138c7b
1 /*
2 * Copyright (c) 2001, Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #ifndef SETUP_PACKAGE_SOURCE_H
17 #define SETUP_PACKAGE_SOURCE_H
19 /* this is the parent class for all package source (not source code - installation
20 * source as in http/ftp/disk file) operations.
23 #include "sha2.h"
24 #include "strings.h"
25 #include "String++.h"
26 #include "csu_util/MD5Sum.h"
27 #include <vector>
29 class site
31 public:
32 site (const std::string& newkey);
33 ~site () {}
34 std::string key;
35 bool operator == (site const &rhs)
37 return casecompare(key, rhs.key) == 0;
41 class packagesource
43 public:
44 packagesource ():size (0), canonical (), shortname (), cached (), validated (false)
46 memset (sha512sum, 0, sizeof sha512sum);
47 sha512_isSet = false;
49 /* how big is the source file */
50 size_t size;
51 /* The canonical name - the complete path to the source file
52 * i.e. foo/bar/package-1.tar.bz2
54 const char *Canonical () const
56 if (!canonical.empty())
57 return canonical.c_str();
59 return NULL;
61 /* What is the cached filename, to prevent directory scanning during
62 install? Except in mirror mode, we never set this without
63 checking the size. The more expensive hash checking is reserved
64 for verifying the integrity of downloaded files and sources of
65 packages about to be installed. Set the 'validated' flag to
66 avoid checking the hash twice. */
67 char const *Cached () const
69 /* Pointer-coerce-to-boolean is used by many callers. */
70 if (cached.empty())
71 return NULL;
72 return cached.c_str();
74 /* sets the canonical path */
75 void set_canonical (char const *);
76 void set_cached (const std::string& );
77 unsigned char sha512sum[SHA512_DIGEST_LENGTH];
78 bool sha512_isSet;
79 MD5Sum md5;
80 /* The next two functions throw exceptions on failure. */
81 void check_size_and_cache (const std::string fullname);
82 void check_hash ();
83 typedef std::vector <site> sitestype;
84 sitestype sites;
86 private:
87 std::string canonical;
88 /* For progress reporting. */
89 std::string shortname;
90 std::string cached;
91 bool validated;
92 void check_sha512 (const std::string fullname) const;
93 void check_md5 (const std::string fullname) const;
96 #endif /* SETUP_PACKAGE_SOURCE_H */