1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
4 /* ######################################################################
6 Debian Source Package Records - Parser implementation for Debian style
9 ##################################################################### */
11 // Include Files /*{{{*/
14 #include <apt-pkg/deblistparser.h>
15 #include <apt-pkg/debsrcrecords.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/configuration.h>
19 #include <apt-pkg/aptconfiguration.h>
20 #include <apt-pkg/hashes.h>
27 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
28 // ---------------------------------------------------------------------
29 /* This member parses the binaries field into a pair of class arrays and
30 returns a list of strings representing all of the components of the
31 binaries field. The returned array need not be freed and will be
32 reused by the next Binaries function call. This function is commonly
33 used during scanning to find the right package */
34 const char **debSrcRecordParser::Binaries()
36 const char *Start
, *End
;
37 if (Sect
.Find("Binary", Start
, End
) == false)
39 for (; isspace(*Start
) != 0; ++Start
);
43 StaticBinList
.clear();
45 Buffer
= strndup(Start
, End
- Start
);
49 char* binStartNext
= strchrnul(bin
, ',');
50 char* binEnd
= binStartNext
- 1;
51 for (; isspace(*binEnd
) != 0; --binEnd
)
53 StaticBinList
.push_back(bin
);
54 if (*binStartNext
!= ',')
57 for (bin
= binStartNext
+ 1; isspace(*bin
) != 0; ++bin
);
58 } while (*bin
!= '\0');
59 StaticBinList
.push_back(NULL
);
61 return (const char **) &StaticBinList
[0];
64 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
65 // ---------------------------------------------------------------------
66 /* This member parses the build-depends information and returns a list of
67 package/version records representing the build dependency. The returned
68 array need not be freed and will be reused by the next call to this
70 bool debSrcRecordParser::BuildDepends(std::vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
71 bool const &ArchOnly
, bool const &StripMultiArch
)
74 const char *Start
, *Stop
;
76 const char *fields
[] = {"Build-Depends",
77 "Build-Depends-Indep",
79 "Build-Conflicts-Indep"};
83 for (I
= 0; I
< 4; I
++)
85 if (ArchOnly
&& (I
== 1 || I
== 3))
88 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
93 Start
= debListParser::ParseDepends(Start
, Stop
,
94 rec
.Package
,rec
.Version
,rec
.Op
,true, StripMultiArch
);
97 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
100 if (rec
.Package
!= "")
101 BuildDeps
.push_back(rec
);
111 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This parses the list of files and returns it, each file is required to have
114 a complete source package */
115 bool debSrcRecordParser::Files(std::vector
<pkgSrcRecords::File
> &List
)
117 List
.erase(List
.begin(),List
.end());
119 // map from the Hashsum field to the hashsum function,
120 // unfortunately this is not a 1:1 mapping from
121 // Hashes::SupporedHashes as e.g. Files is a historic name for the md5
122 const std::pair
<const char*, const char*> SourceHashFields
[] = {
123 std::make_pair( "Checksums-Sha512", "SHA512"),
124 std::make_pair( "Checksums-Sha256", "SHA256"),
125 std::make_pair( "Checksums-Sha1", "SHA1"),
126 std::make_pair( "Files", "MD5Sum"), // historic Name
129 for (unsigned int i
=0;
130 i
< sizeof(SourceHashFields
)/sizeof(SourceHashFields
[0]);
133 string Files
= Sect
.FindS(SourceHashFields
[i
].first
);
134 if (Files
.empty() == true)
137 // Stash the / terminated directory prefix
138 string Base
= Sect
.FindS("Directory");
139 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
142 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
144 // Iterate over the entire list grabbing each triplet
145 const char *C
= Files
.c_str();
148 pkgSrcRecords::File F
;
151 // Parse each of the elements
153 if (ParseQuoteWord(C
, RawHash
) == false ||
154 ParseQuoteWord(C
, Size
) == false ||
155 ParseQuoteWord(C
, F
.Path
) == false)
156 return _error
->Error("Error parsing '%s' record",
157 SourceHashFields
[i
].first
);
158 // assign full hash string
159 F
.Hash
= HashString(SourceHashFields
[i
].second
, RawHash
).toStr();
161 if(SourceHashFields
[i
].second
== "MD5Sum")
164 // Parse the size and append the directory
165 F
.Size
= atoi(Size
.c_str());
166 F
.Path
= Base
+ F
.Path
;
168 // Try to guess what sort of file it is we are getting.
169 string::size_type Pos
= F
.Path
.length()-1;
172 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
173 if (Tmp
== string::npos
)
175 if (F
.Type
== "tar") {
176 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
177 if (string(F
.Path
, Tmp
+1, Pos
-Tmp
) == "debian")
181 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
183 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
197 return (List
.size() > 0);
200 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
201 // ---------------------------------------------------------------------
203 debSrcRecordParser::~debSrcRecordParser()