diff options
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/cdromutl.cc | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/cdromutl.h | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/cmndline.cc | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/cmndline.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.cc | 8 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/crc-16.cc | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/crc-16.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/error.cc | 8 | ||||
-rw-r--r-- | apt-pkg/contrib/error.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 6 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.h | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.cc | 88 | ||||
-rw-r--r-- | apt-pkg/contrib/hashes.h | 34 | ||||
-rw-r--r-- | apt-pkg/contrib/md5.cc | 5 | ||||
-rw-r--r-- | apt-pkg/contrib/md5.h | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.cc | 10 | ||||
-rw-r--r-- | apt-pkg/contrib/mmap.h | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.cc | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/progress.h | 3 | ||||
-rw-r--r-- | apt-pkg/contrib/sha1.cc | 4 | ||||
-rw-r--r-- | apt-pkg/contrib/sha1.h | 5 | ||||
-rw-r--r-- | apt-pkg/contrib/sha256.cc | 6 | ||||
-rw-r--r-- | apt-pkg/contrib/sha256.h | 6 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 48 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 8 |
26 files changed, 194 insertions, 95 deletions
diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index ab170ec5a..6f00e1451 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -10,9 +10,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/cdromutl.h" -#endif #include <apt-pkg/cdromutl.h> #include <apt-pkg/error.h> #include <apt-pkg/md5.h> diff --git a/apt-pkg/contrib/cdromutl.h b/apt-pkg/contrib/cdromutl.h index 3180a03c7..f24bb8c70 100644 --- a/apt-pkg/contrib/cdromutl.h +++ b/apt-pkg/contrib/cdromutl.h @@ -8,18 +8,15 @@ ##################################################################### */ /*}}}*/ #ifndef PKGLIB_CDROMUTL_H -#define PKGLIB_ACQUIRE_METHOD_H +#define PKGLIB_CDROMUTL_H #include <string> using std::string; -#ifdef __GNUG__ -#pragma interface "apt-pkg/cdromutl.h" -#endif - bool MountCdrom(string Path); bool UnmountCdrom(string Path); bool IdentCdrom(string CD,string &Res,unsigned int Version = 2); +bool IsMounted(string &Path); #endif diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc index 2b3d7dc96..54c91d67d 100644 --- a/apt-pkg/contrib/cmndline.cc +++ b/apt-pkg/contrib/cmndline.cc @@ -11,9 +11,6 @@ ##################################################################### */ /*}}}*/ // Include files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/cmndline.h" -#endif #include <apt-pkg/cmndline.h> #include <apt-pkg/error.h> #include <apt-pkg/strutl.h> diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h index 8f461296f..fad6d1da9 100644 --- a/apt-pkg/contrib/cmndline.h +++ b/apt-pkg/contrib/cmndline.h @@ -44,9 +44,7 @@ #ifndef PKGLIB_CMNDLINE_H #define PKGLIB_CMNDLINE_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/cmndline.h" -#endif + #include <apt-pkg/configuration.h> diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 14a000fa5..3109fd7a5 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -15,9 +15,6 @@ ##################################################################### */ /*}}}*/ // Include files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/configuration.h" -#endif #include <apt-pkg/configuration.h> #include <apt-pkg/error.h> #include <apt-pkg/strutl.h> @@ -425,6 +422,7 @@ bool Configuration::ExistsAny(const char *Name) const string key = Name; if (key.size() > 2 && key.end()[-2] == '/') + { if (key.find_first_of("fdbi",key.size()-1) < key.size()) { key.resize(key.size() - 2); @@ -435,7 +433,7 @@ bool Configuration::ExistsAny(const char *Name) const { _error->Warning(_("Unrecognized type abbreviation: '%c'"), key.end()[-3]); } - + } return Exists(Name); } /*}}}*/ @@ -509,7 +507,7 @@ bool ReadConfigFile(Configuration &Conf,const string &FName,bool AsSectional, CurLine++; // This should be made to work instead, but this is better than looping if (F.fail() && !F.eof()) - return _error->Error(_("Line %d too long (max %d)"), CurLine, sizeof(Buffer)); + return _error->Error(_("Line %d too long (max %u)"), CurLine, sizeof(Buffer)); _strtabexpand(Buffer,sizeof(Buffer)); _strstrip(Buffer); diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index 0d4078dab..2534692a3 100644 --- a/apt-pkg/contrib/configuration.h +++ b/apt-pkg/contrib/configuration.h @@ -28,9 +28,7 @@ #ifndef PKGLIB_CONFIGURATION_H #define PKGLIB_CONFIGURATION_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/configuration.h" -#endif + #include <string> #include <iostream> diff --git a/apt-pkg/contrib/crc-16.cc b/apt-pkg/contrib/crc-16.cc index 52a551802..b300ed67e 100644 --- a/apt-pkg/contrib/crc-16.cc +++ b/apt-pkg/contrib/crc-16.cc @@ -15,10 +15,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/crc-16.h" -#endif - #include <apt-pkg/crc-16.h> /*}}}*/ diff --git a/apt-pkg/contrib/crc-16.h b/apt-pkg/contrib/crc-16.h index 757104c54..f30678bac 100644 --- a/apt-pkg/contrib/crc-16.h +++ b/apt-pkg/contrib/crc-16.h @@ -10,10 +10,6 @@ #ifndef APTPKG_CRC16_H #define APTPKG_CRC16_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/crc-16.h" -#endif - #define INIT_FCS 0xffff unsigned short AddCRC16(unsigned short fcs, void const *buf, unsigned long len); diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc index 5fe9bdfce..db8c53c36 100644 --- a/apt-pkg/contrib/error.cc +++ b/apt-pkg/contrib/error.cc @@ -14,19 +14,17 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/error.h" -#endif - #include <apt-pkg/error.h> #include <iostream> #include <errno.h> #include <stdio.h> -#include <string> #include <stdarg.h> #include <unistd.h> +#include <string> +#include <cstring> + #include "config.h" /*}}}*/ diff --git a/apt-pkg/contrib/error.h b/apt-pkg/contrib/error.h index a5fc1a223..a3be6a575 100644 --- a/apt-pkg/contrib/error.h +++ b/apt-pkg/contrib/error.h @@ -40,9 +40,7 @@ #ifndef PKGLIB_ERROR_H #define PKGLIB_ERROR_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/error.h" -#endif + #ifdef __GNUG__ // Methods have a hidden this parameter that is visible to this attribute diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 9fd71728e..9e13b4f60 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -14,9 +14,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/fileutl.h" -#endif #include <apt-pkg/fileutl.h> #include <apt-pkg/error.h> #include <apt-pkg/sptr.h> @@ -24,6 +21,9 @@ #include <apti18n.h> +#include <cstdlib> +#include <cstring> + #include <iostream> #include <unistd.h> #include <fcntl.h> diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h index 041aa3309..48bd95537 100644 --- a/apt-pkg/contrib/fileutl.h +++ b/apt-pkg/contrib/fileutl.h @@ -21,9 +21,6 @@ #ifndef PKGLIB_FILEUTL_H #define PKGLIB_FILEUTL_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/fileutl.h" -#endif #include <string> diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc index 9b22a90d3..fcc2f887c 100644 --- a/apt-pkg/contrib/hashes.cc +++ b/apt-pkg/contrib/hashes.cc @@ -11,16 +11,96 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/hashes.h" -#endif - #include <apt-pkg/hashes.h> +#include <apt-pkg/fileutl.h> +#include <apt-pkg/configuration.h> #include <unistd.h> #include <system.h> +#include <string> +#include <iostream> /*}}}*/ +const char* HashString::_SupportedHashes[] = +{ + "SHA256", "SHA1", "MD5Sum", NULL +}; + +HashString::HashString() +{ +} + +HashString::HashString(string Type, string Hash) : Type(Type), Hash(Hash) +{ +} + +HashString::HashString(string StringedHash) +{ + // legacy: md5sum without "MD5Sum:" prefix + if (StringedHash.find(":") == string::npos && StringedHash.size() == 32) + { + Type = "MD5Sum"; + Hash = StringedHash; + return; + } + string::size_type pos = StringedHash.find(":"); + Type = StringedHash.substr(0,pos); + Hash = StringedHash.substr(pos+1, StringedHash.size() - pos); + + if(_config->FindB("Debug::Hashes",false) == true) + std::clog << "HashString(string): " << Type << " : " << Hash << std::endl; +} + + +bool HashString::VerifyFile(string filename) const +{ + FileFd fd; + MD5Summation MD5; + SHA1Summation SHA1; + SHA256Summation SHA256; + string fileHash; + + FileFd Fd(filename, FileFd::ReadOnly); + if(Type == "MD5Sum") + { + MD5.AddFD(Fd.Fd(), Fd.Size()); + fileHash = (string)MD5.Result(); + } + else if (Type == "SHA1") + { + SHA1.AddFD(Fd.Fd(), Fd.Size()); + fileHash = (string)SHA1.Result(); + } + else if (Type == "SHA256") + { + SHA256.AddFD(Fd.Fd(), Fd.Size()); + fileHash = (string)SHA256.Result(); + } + Fd.Close(); + + if(_config->FindB("Debug::Hashes",false) == true) + std::clog << "HashString::VerifyFile: got: " << fileHash << " expected: " << toStr() << std::endl; + + return (fileHash == Hash); +} + +const char** HashString::SupportedHashes() +{ + return _SupportedHashes; +} + +bool HashString::empty() const +{ + return (Type.empty() || Hash.empty()); +} + + +string HashString::toStr() const +{ + return Type+string(":")+Hash; +} + + // Hashes::AddFD - Add the contents of the FD /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h index eefa7bf41..264f7fe90 100644 --- a/apt-pkg/contrib/hashes.h +++ b/apt-pkg/contrib/hashes.h @@ -13,17 +13,45 @@ #ifndef APTPKG_HASHES_H #define APTPKG_HASHES_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/hashes.h" -#endif #include <apt-pkg/md5.h> #include <apt-pkg/sha1.h> #include <apt-pkg/sha256.h> #include <algorithm> +#include <vector> +#include <cstring> using std::min; +using std::vector; + +// helper class that contains hash function name +// and hash +class HashString +{ + protected: + string Type; + string Hash; + static const char * _SupportedHashes[10]; + + public: + HashString(string Type, string Hash); + HashString(string StringedHashString); // init from str as "type:hash" + HashString(); + + // get hash type used + string HashType() { return Type; }; + + // verify the given filename against the currently loaded hash + bool VerifyFile(string filename) const; + + // helper + string toStr() const; // convert to str as "type:hash" + bool empty() const; + + // return the list of hashes we support + static const char** SupportedHashes(); +}; class Hashes { diff --git a/apt-pkg/contrib/md5.cc b/apt-pkg/contrib/md5.cc index fded5c864..a095f8f0f 100644 --- a/apt-pkg/contrib/md5.cc +++ b/apt-pkg/contrib/md5.cc @@ -35,10 +35,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/md5.h" -#endif - #include <apt-pkg/md5.h> #include <apt-pkg/strutl.h> @@ -48,6 +44,7 @@ #include <inttypes.h> #include <config.h> #include <system.h> + /*}}}*/ // byteSwap - Swap bytes in a buffer /*{{{*/ diff --git a/apt-pkg/contrib/md5.h b/apt-pkg/contrib/md5.h index e280d714e..96c8975b4 100644 --- a/apt-pkg/contrib/md5.h +++ b/apt-pkg/contrib/md5.h @@ -23,11 +23,9 @@ #ifndef APTPKG_MD5_H #define APTPKG_MD5_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/md5.h" -#endif #include <string> +#include <cstring> #include <algorithm> #include <stdint.h> diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index e395e6cc7..abcae46fe 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -21,10 +21,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/mmap.h" -#endif - #define _BSD_SOURCE #include <apt-pkg/mmap.h> #include <apt-pkg/error.h> @@ -35,6 +31,8 @@ #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> + +#include <cstring> /*}}}*/ // MMap::MMap - Constructor /*{{{*/ @@ -119,7 +117,7 @@ bool MMap::Sync() #ifdef _POSIX_SYNCHRONIZED_IO if ((Flags & ReadOnly) != ReadOnly) - if (msync((char *)Base,iSize,MS_SYNC) != 0) + if (msync((char *)Base,iSize,MS_SYNC) < 0) return _error->Errno("msync","Unable to write mmap"); #endif return true; @@ -136,7 +134,7 @@ bool MMap::Sync(unsigned long Start,unsigned long Stop) #ifdef _POSIX_SYNCHRONIZED_IO unsigned long PSize = sysconf(_SC_PAGESIZE); if ((Flags & ReadOnly) != ReadOnly) - if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) != 0) + if (msync((char *)Base+(int)(Start/PSize)*PSize,Stop - Start,MS_SYNC) < 0) return _error->Errno("msync","Unable to write mmap"); #endif return true; diff --git a/apt-pkg/contrib/mmap.h b/apt-pkg/contrib/mmap.h index e329b167a..19cf7582d 100644 --- a/apt-pkg/contrib/mmap.h +++ b/apt-pkg/contrib/mmap.h @@ -25,9 +25,6 @@ #ifndef PKGLIB_MMAP_H #define PKGLIB_MMAP_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/mmap.h" -#endif #include <string> #include <apt-pkg/fileutl.h> diff --git a/apt-pkg/contrib/progress.cc b/apt-pkg/contrib/progress.cc index cb272e389..cffdddc4f 100644 --- a/apt-pkg/contrib/progress.cc +++ b/apt-pkg/contrib/progress.cc @@ -8,9 +8,6 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/progress.h" -#endif #include <apt-pkg/progress.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> @@ -19,6 +16,7 @@ #include <iostream> #include <stdio.h> +#include <cstring> /*}}}*/ using namespace std; @@ -115,6 +113,8 @@ bool OpProgress::CheckChange(float Interval) if ((int)LastPercent == (int)Percent) return false; + + LastPercent = Percent; if (Interval == 0) return false; @@ -126,7 +126,6 @@ bool OpProgress::CheckChange(float Interval) if (Diff < Interval) return false; LastTime = Now; - LastPercent = Percent; return true; } /*}}}*/ diff --git a/apt-pkg/contrib/progress.h b/apt-pkg/contrib/progress.h index 20caf4cdf..7dd004f7e 100644 --- a/apt-pkg/contrib/progress.h +++ b/apt-pkg/contrib/progress.h @@ -21,9 +21,6 @@ #ifndef PKGLIB_PROGRESS_H #define PKGLIB_PROGRESS_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/progress.h" -#endif #include <string> #include <sys/time.h> diff --git a/apt-pkg/contrib/sha1.cc b/apt-pkg/contrib/sha1.cc index 72eafd4ca..b70f31dc6 100644 --- a/apt-pkg/contrib/sha1.cc +++ b/apt-pkg/contrib/sha1.cc @@ -29,10 +29,6 @@ */ /*}}} */ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/sha1.h" -#endif - #include <apt-pkg/sha1.h> #include <apt-pkg/strutl.h> diff --git a/apt-pkg/contrib/sha1.h b/apt-pkg/contrib/sha1.h index db8ca7893..8ddd889f1 100644 --- a/apt-pkg/contrib/sha1.h +++ b/apt-pkg/contrib/sha1.h @@ -14,11 +14,8 @@ #ifndef APTPKG_SHA1_H #define APTPKG_SHA1_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/sha1.h" -#endif - #include <string> +#include <cstring> #include <algorithm> using std::string; diff --git a/apt-pkg/contrib/sha256.cc b/apt-pkg/contrib/sha256.cc index b75ce8a84..ecda3d8e8 100644 --- a/apt-pkg/contrib/sha256.cc +++ b/apt-pkg/contrib/sha256.cc @@ -18,6 +18,12 @@ * any later version. * */ + +#ifdef __GNUG__ +#pragma implementation "apt-pkg/sha256.h" +#endif + + #define SHA256_DIGEST_SIZE 32 #define SHA256_HMAC_BLOCK_SIZE 64 diff --git a/apt-pkg/contrib/sha256.h b/apt-pkg/contrib/sha256.h index 9e88f5ece..1951f053b 100644 --- a/apt-pkg/contrib/sha256.h +++ b/apt-pkg/contrib/sha256.h @@ -14,13 +14,9 @@ #ifndef APTPKG_SHA256_H #define APTPKG_SHA256_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/sha256.h" -#endif - #include <string> +#include <cstring> #include <algorithm> -#include <stdint.h> using std::string; using std::min; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index d96155917..006452af4 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -15,10 +15,6 @@ ##################################################################### */ /*}}}*/ // Includes /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/strutl.h" -#endif - #include <apt-pkg/strutl.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/error.h> @@ -28,16 +24,60 @@ #include <ctype.h> #include <string.h> #include <stdio.h> +#include <algorithm> #include <unistd.h> #include <regex.h> #include <errno.h> #include <stdarg.h> +#include <iconv.h> #include "config.h" using namespace std; /*}}}*/ +// UTF8ToCodeset - Convert some UTF-8 string for some codeset /*{{{*/ +// --------------------------------------------------------------------- +/* This is handy to use before display some information for enduser */ +bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) +{ + iconv_t cd; + const char *inbuf; + char *inptr, *outbuf, *outptr; + size_t insize, outsize; + + cd = iconv_open(codeset, "UTF-8"); + if (cd == (iconv_t)(-1)) { + // Something went wrong + if (errno == EINVAL) + _error->Error("conversion from 'UTF-8' to '%s' not available", + codeset); + else + perror("iconv_open"); + + // Clean the destination string + *dest = ""; + + return false; + } + + insize = outsize = orig.size(); + inbuf = orig.data(); + inptr = (char *)inbuf; + outbuf = new char[insize+1]; + outptr = outbuf; + + iconv(cd, &inptr, &insize, &outptr, &outsize); + *outptr = '\0'; + + *dest = outbuf; + delete[] outbuf; + + iconv_close(cd); + + return true; +} + /*}}}*/ // strstrip - Remove white space from the front and back of a string /*{{{*/ // --------------------------------------------------------------------- /* This is handy to use when parsing a file. It also removes \n's left diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 6ec2b7811..53146ced7 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -16,12 +16,11 @@ #ifndef STRUTL_H #define STRUTL_H -#ifdef __GNUG__ -#pragma interface "apt-pkg/strutl.h" -#endif + #include <stdlib.h> #include <string> +#include <cstring> #include <vector> #include <iostream> #include <time.h> @@ -38,7 +37,8 @@ using std::ostream; #define APT_FORMAT2 #define APT_FORMAT3 #endif - + +bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest); char *_strstrip(char *String); char *_strtabexpand(char *String,size_t Len); bool ParseQuoteWord(const char *&String,string &Res); |