1 /*
2 	This file is part of the metalink program
3 	Copyright (C) 2008  A. Bram Neijt <bneijt@gmail.com>
4 
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 
21 
22 
23 
24 #ifndef _MetalinkFile_HH_INCLUDED_
25 #define	_MetalinkFile_HH_INCLUDED_
26 
27 #include <string>
28 #include <vector>
29 #include <sstream>
30 
31 #include <utility>
32 
33 #include "../MirrorList/MirrorList.hh"
34 #include "../Hash/Hash.hh"
35 
36 
37 #include "../Globals/Globals.hh"
38 #include "../Preprocessor/foreach.hh"
39 namespace bneijt
40 {
41 /** The file segment of a metalink
42 */
43 class MetalinkFile: public std::string
44 {
45 		std::string d_filename;
46 		std::vector< std::pair<std::string, std::string> > d_paths;
47 		MirrorList const *d_ml;
48 		bool d_sizeSet;
49 		unsigned long long d_size;
50 		std::vector< std::pair<std::string, std::string> > d_vers;
51 		std::vector< std::string > d_verificationLines;
52 
53 	public:
54 
MetalinkFile(std::string const & filename,MirrorList const * ml)55 		MetalinkFile(std::string const &filename, MirrorList const *ml)
56 		:
57 			d_filename(filename),
58 			d_ml(ml),
59 			d_sizeSet(false),
60 			d_size(0)
61 		{}
62 
setSize(unsigned long long s)63 		void setSize(unsigned long long s)
64 		{
65 			d_size = s;
66 			d_sizeSet = true;
67 		}
size() const68 		std::string size() const
69 		{
70 			std::ostringstream s;
71 			s << d_size;
72 			return s.str();
73 		}
addVerification(std::string const & h)74 		void addVerification(std::string const &h)
75 		{
76 			d_verificationLines.push_back(h);
77 		}
78 
addVerification(std::string const & name,std::string const & value)79 		void addVerification(std::string const &name, std::string const &value)
80 		{
81 			d_vers.push_back(std::make_pair(name, value));
82 		}
83 
84 		///Add path and make sure to clean file from preprended slashes
85 		void addPath(std::string const &type, std::string const & file);
86 
87 		///Add path and make sure to clean file from preprended slashes
88 		void addPath(std::string const &type, std::string const &base, std::string const & file);
89 
90 		void finalize();
91 };
92 }
93 #endif
94 
95