]> cygwin.com Git - cygwin-apps/setup.git/blob - package_source.h
Prepare for changing from MD5 to SHA256 checksums.
[cygwin-apps/setup.git] / package_source.h
1 /*
2 * Copyright (c) 2001, Robert Collins.
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16 #ifndef SETUP_PACKAGE_SOURCE_H
17 #define SETUP_PACKAGE_SOURCE_H
18
19 /* this is the parent class for all package source (not source code - installation
20 * source as in http/ftp/disk file) operations.
21 */
22
23 /* required to parse this file */
24 #include "sha2.h"
25 #include "strings.h"
26 #include "String++.h"
27 #include "csu_util/MD5Sum.h"
28 #include <vector>
29
30 /* standard binary package metadata:
31 * Name (ie mutt
32 * Vendor Version (ie 2.5.1)
33 * Package Version (ie 16)
34 * Stability
35 * Files
36 */
37
38 /* For non installed files, this class can be populated via information about
39 * what is available on the net, or by parsing a specific package file.
40 * for installed packages, this class should represent what is currently installed,
41 * - updated by what net metadata has about it.
42 * i.e. the stability of this version will change simply because the net mirrors
43 * now consider it old.
44 */
45
46 class site
47 {
48 public:
49 site (const std::string& newkey);
50 ~site () {}
51 std::string key;
52 bool operator == (site const &rhs)
53 {
54 return casecompare(key, rhs.key) == 0;
55 }
56 };
57
58 class packagesource
59 {
60 public:
61 packagesource ():size (0), canonical (0), base (0), filename (0), cached (),
62 _installedSize (0)
63 {
64 memset (sha256sum, 0, sizeof sha256sum);
65 };
66 /* how big is the source file */
67 size_t size;
68 /* how much space do we need to install this ? */
69 virtual unsigned long installedSize () const
70 {
71 return _installedSize;
72 }
73 virtual void setInstalledSize (unsigned long size)
74 {
75 _installedSize = size;
76 }
77 /* The canonical name - the complete path to the source file
78 * i.e. foo/bar/package-1.tar.bz2
79 */
80 virtual const char *Canonical () const
81 {
82 return canonical;
83 };
84 /* The basename - without extention
85 * i.e. package-1
86 */
87 virtual const char *Base () const
88 {
89 return base;
90 };
91 /* The basename - with extention
92 * i.e. package-1.tar.bz2
93 */
94 virtual const char *Filename () const
95 {
96 return filename;
97 };
98 /* what is the cached filename, to prevent directory scanning during install */
99 virtual char const *Cached () const
100 {
101 /* Pointer-coerce-to-boolean is used by many callers. */
102 if (cached.empty())
103 return NULL;
104 return cached.c_str();
105 };
106 /* sets the canonical path, and parses and creates base and filename */
107 virtual void set_canonical (char const *);
108 virtual void set_cached (const std::string& );
109 unsigned char sha256sum[SHA256_DIGEST_LENGTH];
110 MD5Sum md5;
111 typedef std::vector <site> sitestype;
112 sitestype sites;
113
114 virtual ~ packagesource ()
115 {
116 if (canonical)
117 delete []canonical;
118 if (base)
119 delete []base;
120 if (filename)
121 delete []filename;
122 };
123
124 private:
125 char *canonical;
126 char *base;
127 char *filename;
128 std::string cached;
129 unsigned long _installedSize;
130 };
131
132 #endif /* SETUP_PACKAGE_SOURCE_H */
This page took 0.043043 seconds and 6 git commands to generate.