X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/29bc4c1c75d3d1ca4e6133a7685980483c34f58d..64680d3bf12db6599e93f950546e380e0bd5ddf4:/apt-pkg/deb/debsrcrecords.cc diff --git a/apt-pkg/deb/debsrcrecords.cc b/apt-pkg/deb/debsrcrecords.cc index 2f87c767b..c620c2298 100644 --- a/apt-pkg/deb/debsrcrecords.cc +++ b/apt-pkg/deb/debsrcrecords.cc @@ -9,15 +9,21 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include #include #include +#include +#include using std::max; /*}}}*/ +using std::string; + // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ // --------------------------------------------------------------------- /* This member parses the binaries field into a pair of class arrays and @@ -27,25 +33,32 @@ using std::max; used during scanning to find the right package */ const char **debSrcRecordParser::Binaries() { - // This should use Start/Stop too, it is supposed to be efficient after all. - string Bins = Sect.FindS("Binary"); - if (Bins.empty() == true || Bins.length() >= 102400) - return 0; - - if (Bins.length() >= BufSize) - { - delete [] Buffer; - // allocate new size based on buffer (but never smaller than 4000) - BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize)); - Buffer = new char[BufSize]; - } + const char *Start, *End; + if (Sect.Find("Binary", Start, End) == false) + return NULL; + for (; isspace(*Start) != 0; ++Start); + if (Start >= End) + return NULL; + + StaticBinList.clear(); + free(Buffer); + Buffer = strndup(Start, End - Start); - strcpy(Buffer,Bins.c_str()); - if (TokSplitString(',',Buffer,StaticBinList, - sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false) - return 0; + char* bin = Buffer; + do { + char* binStartNext = strchrnul(bin, ','); + char* binEnd = binStartNext - 1; + for (; isspace(*binEnd) != 0; --binEnd) + binEnd = '\0'; + StaticBinList.push_back(bin); + if (*binStartNext != ',') + break; + *binStartNext = '\0'; + for (bin = binStartNext + 1; isspace(*bin) != 0; ++bin); + } while (*bin != '\0'); + StaticBinList.push_back(NULL); - return (const char **)StaticBinList; + return (const char **) &StaticBinList[0]; } /*}}}*/ // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/ @@ -54,7 +67,8 @@ const char **debSrcRecordParser::Binaries() package/version records representing the build dependency. The returned array need not be freed and will be reused by the next call to this function */ -bool debSrcRecordParser::BuildDepends(vector &BuildDeps, bool ArchOnly) +bool debSrcRecordParser::BuildDepends(std::vector &BuildDeps, + bool const &ArchOnly, bool const &StripMultiArch) { unsigned int I; const char *Start, *Stop; @@ -77,7 +91,7 @@ bool debSrcRecordParser::BuildDepends(vector while (1) { Start = debListParser::ParseDepends(Start, Stop, - rec.Package,rec.Version,rec.Op,true); + rec.Package,rec.Version,rec.Op,true, StripMultiArch); if (Start == 0) return _error->Error("Problem parsing dependency: %s", fields[I]); @@ -98,58 +112,92 @@ bool debSrcRecordParser::BuildDepends(vector // --------------------------------------------------------------------- /* This parses the list of files and returns it, each file is required to have a complete source package */ -bool debSrcRecordParser::Files(vector &List) +bool debSrcRecordParser::Files(std::vector &List) { List.erase(List.begin(),List.end()); + + // FIXME: build string dynamically from + // Hashes::SupportedHashes + const char *hash_field[] = { "Checksums-Sha512", + "Checksums-Sha256", + "Checksums-Sha1", + "Files", // historic name + NULL, + }; + + // FIXME: use string from Hashes::SupportedHashes + // FIXME2: this is case senstivie + const char *hash_type[] = { "SHA512", + "SHA256", + "SHA1", + "MD5Sum", + NULL, + }; - string Files = Sect.FindS("Files"); - if (Files.empty() == true) - return false; - - // Stash the / terminated directory prefix - string Base = Sect.FindS("Directory"); - if (Base.empty() == false && Base[Base.length()-1] != '/') - Base += '/'; - - // Iterate over the entire list grabbing each triplet - const char *C = Files.c_str(); - while (*C != 0) - { - pkgSrcRecords::File F; - string Size; - - // Parse each of the elements - if (ParseQuoteWord(C,F.MD5Hash) == false || - ParseQuoteWord(C,Size) == false || - ParseQuoteWord(C,F.Path) == false) - return _error->Error("Error parsing file record"); - - // Parse the size and append the directory - F.Size = atoi(Size.c_str()); - F.Path = Base + F.Path; - - // Try to guess what sort of file it is we are getting. - string::size_type Pos = F.Path.length()-1; - while (1) - { - string::size_type Tmp = F.Path.rfind('.',Pos); - if (Tmp == string::npos) - break; - F.Type = string(F.Path,Tmp+1,Pos-Tmp); - - if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma") - { - Pos = Tmp-1; - continue; - } + for (int i=0; hash_field[i] != NULL; i++) + { + + string Files = Sect.FindS(hash_field[i]); + if (Files.empty() == true) + continue; + + // Stash the / terminated directory prefix + string Base = Sect.FindS("Directory"); + if (Base.empty() == false && Base[Base.length()-1] != '/') + Base += '/'; + + std::vector const compExts = APT::Configuration::getCompressorExtensions(); + + // Iterate over the entire list grabbing each triplet + const char *C = Files.c_str(); + while (*C != 0) + { + pkgSrcRecords::File F; + string Size; + + // Parse each of the elements + std::string RawHash; + if (ParseQuoteWord(C, RawHash) == false || + ParseQuoteWord(C, Size) == false || + ParseQuoteWord(C, F.Path) == false) + return _error->Error("Error parsing '%s' record", hash_field[i]); + // assign full hash string + F.Hash = HashString(hash_type[i], RawHash).toStr(); + + // Parse the size and append the directory + F.Size = atoi(Size.c_str()); + F.Path = Base + F.Path; + + // Try to guess what sort of file it is we are getting. + string::size_type Pos = F.Path.length()-1; + while (1) + { + string::size_type Tmp = F.Path.rfind('.',Pos); + if (Tmp == string::npos) + break; + if (F.Type == "tar") { + // source v3 has extension 'debian.tar.*' instead of 'diff.*' + if (string(F.Path, Tmp+1, Pos-Tmp) == "debian") + F.Type = "diff"; + break; + } + F.Type = string(F.Path,Tmp+1,Pos-Tmp); + + if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() || + F.Type == "tar") + { + Pos = Tmp-1; + continue; + } - break; - } + break; + } - List.push_back(F); + List.push_back(F); + } + break; } - - return true; + return (List.size() > 0); } /*}}}*/ // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/