]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debsrcrecords.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-pkg / deb / debsrcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
c33b707e 3// $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
11e7af84
AL
4/* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include <config.h>
13
b2e465d6 14#include <apt-pkg/deblistparser.h>
11e7af84
AL
15#include <apt-pkg/debsrcrecords.h>
16#include <apt-pkg/error.h>
36f610f1 17#include <apt-pkg/strutl.h>
b2e465d6 18#include <apt-pkg/configuration.h>
b0e1a43f 19#include <apt-pkg/aptconfiguration.h>
cb6a2b3e 20#include <apt-pkg/hashes.h>
4ab24e53
MV
21
22using std::max;
11e7af84
AL
23 /*}}}*/
24
8f3ba4e8
DK
25using std::string;
26
11e7af84
AL
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
b2e465d6
AL
32 reused by the next Binaries function call. This function is commonly
33 used during scanning to find the right package */
11e7af84
AL
34const char **debSrcRecordParser::Binaries()
35{
39fb1e24
DK
36 const char *Start, *End;
37 if (Sect.Find("Binary", Start, End) == false)
38 return NULL;
39 for (; isspace(*Start) != 0; ++Start);
40 if (Start >= End)
41 return NULL;
42
43 StaticBinList.clear();
44 free(Buffer);
45 Buffer = strndup(Start, End - Start);
c33b707e 46
39fb1e24
DK
47 char* bin = Buffer;
48 do {
49 char* binStartNext = strchrnul(bin, ',');
50 char* binEnd = binStartNext - 1;
51 for (; isspace(*binEnd) != 0; --binEnd)
52 binEnd = '\0';
53 StaticBinList.push_back(bin);
54 if (*binStartNext != ',')
55 break;
56 *binStartNext = '\0';
57 for (bin = binStartNext + 1; isspace(*bin) != 0; ++bin);
58 } while (*bin != '\0');
59 StaticBinList.push_back(NULL);
c33b707e 60
39fb1e24 61 return (const char **) &StaticBinList[0];
b2e465d6
AL
62}
63 /*}}}*/
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
69 function */
8f3ba4e8 70bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
41c81fd8 71 bool const &ArchOnly, bool const &StripMultiArch)
b2e465d6
AL
72{
73 unsigned int I;
74 const char *Start, *Stop;
75 BuildDepRec rec;
76 const char *fields[] = {"Build-Depends",
77 "Build-Depends-Indep",
78 "Build-Conflicts",
79 "Build-Conflicts-Indep"};
80
81 BuildDeps.clear();
11e7af84 82
b2e465d6 83 for (I = 0; I < 4; I++)
11e7af84 84 {
45430cbf
AL
85 if (ArchOnly && (I == 1 || I == 3))
86 continue;
87
b2e465d6
AL
88 if (Sect.Find(fields[I], Start, Stop) == false)
89 continue;
11e7af84 90
b2e465d6
AL
91 while (1)
92 {
93 Start = debListParser::ParseDepends(Start, Stop,
41c81fd8 94 rec.Package,rec.Version,rec.Op,true, StripMultiArch);
b2e465d6
AL
95
96 if (Start == 0)
97 return _error->Error("Problem parsing dependency: %s", fields[I]);
98 rec.Type = I;
99
100 if (rec.Package != "")
101 BuildDeps.push_back(rec);
102
103 if (Start == Stop)
104 break;
105 }
11e7af84
AL
106 }
107
b2e465d6 108 return true;
11e7af84
AL
109}
110 /*}}}*/
36f610f1
AL
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 */
8f3ba4e8 115bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
36f610f1
AL
116{
117 List.erase(List.begin(),List.end());
cb6a2b3e 118
3bbce699
MV
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
cb6a2b3e 127 };
36f610f1 128
3bbce699
MV
129 for (unsigned int i=0;
130 i < sizeof(SourceHashFields)/sizeof(SourceHashFields[0]);
131 i++)
cb6a2b3e 132 {
3bbce699 133 string Files = Sect.FindS(SourceHashFields[i].first);
cb6a2b3e
MV
134 if (Files.empty() == true)
135 continue;
136
137 // Stash the / terminated directory prefix
138 string Base = Sect.FindS("Directory");
139 if (Base.empty() == false && Base[Base.length()-1] != '/')
140 Base += '/';
141
142 std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
143
144 // Iterate over the entire list grabbing each triplet
145 const char *C = Files.c_str();
146 while (*C != 0)
147 {
148 pkgSrcRecords::File F;
149 string Size;
150
151 // Parse each of the elements
152 std::string RawHash;
153 if (ParseQuoteWord(C, RawHash) == false ||
154 ParseQuoteWord(C, Size) == false ||
155 ParseQuoteWord(C, F.Path) == false)
3bbce699
MV
156 return _error->Error("Error parsing '%s' record",
157 SourceHashFields[i].first);
cb6a2b3e 158 // assign full hash string
3bbce699 159 F.Hash = HashString(SourceHashFields[i].second, RawHash).toStr();
a1b5561a
MV
160 // API compat hack
161 if(SourceHashFields[i].second == "MD5Sum")
162 F.MD5Hash = RawHash;
cb6a2b3e
MV
163
164 // Parse the size and append the directory
165 F.Size = atoi(Size.c_str());
166 F.Path = Base + F.Path;
167
168 // Try to guess what sort of file it is we are getting.
169 string::size_type Pos = F.Path.length()-1;
170 while (1)
171 {
172 string::size_type Tmp = F.Path.rfind('.',Pos);
173 if (Tmp == string::npos)
174 break;
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")
178 F.Type = "diff";
179 break;
180 }
181 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
182
183 if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
184 F.Type == "tar")
185 {
186 Pos = Tmp-1;
187 continue;
188 }
b2e465d6 189
cb6a2b3e
MV
190 break;
191 }
b2e465d6 192
cb6a2b3e
MV
193 List.push_back(F);
194 }
195 break;
36f610f1 196 }
cb6a2b3e 197 return (List.size() > 0);
36f610f1
AL
198}
199 /*}}}*/
7a9f09bd
MV
200// SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
201// ---------------------------------------------------------------------
202/* */
203debSrcRecordParser::~debSrcRecordParser()
204{
205 delete[] Buffer;
206}
207 /*}}}*/