]>
Commit | Line | Data |
---|---|---|
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> |
b0e1a43f | 18 | #include <apt-pkg/aptconfiguration.h> |
453b82a3 DK |
19 | #include <apt-pkg/srcrecords.h> |
20 | #include <apt-pkg/tagfile.h> | |
cb6a2b3e | 21 | #include <apt-pkg/hashes.h> |
4ab24e53 | 22 | |
453b82a3 DK |
23 | #include <ctype.h> |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | #include <algorithm> | |
27 | #include <string> | |
28 | #include <vector> | |
11e7af84 AL |
29 | /*}}}*/ |
30 | ||
453b82a3 | 31 | using std::max; |
8f3ba4e8 DK |
32 | using std::string; |
33 | ||
11e7af84 AL |
34 | // SrcRecordParser::Binaries - Return the binaries field /*{{{*/ |
35 | // --------------------------------------------------------------------- | |
36 | /* This member parses the binaries field into a pair of class arrays and | |
37 | returns a list of strings representing all of the components of the | |
38 | binaries field. The returned array need not be freed and will be | |
b2e465d6 AL |
39 | reused by the next Binaries function call. This function is commonly |
40 | used during scanning to find the right package */ | |
11e7af84 AL |
41 | const char **debSrcRecordParser::Binaries() |
42 | { | |
39fb1e24 DK |
43 | const char *Start, *End; |
44 | if (Sect.Find("Binary", Start, End) == false) | |
45 | return NULL; | |
46 | for (; isspace(*Start) != 0; ++Start); | |
47 | if (Start >= End) | |
48 | return NULL; | |
49 | ||
50 | StaticBinList.clear(); | |
51 | free(Buffer); | |
52 | Buffer = strndup(Start, End - Start); | |
c33b707e | 53 | |
39fb1e24 DK |
54 | char* bin = Buffer; |
55 | do { | |
56 | char* binStartNext = strchrnul(bin, ','); | |
57 | char* binEnd = binStartNext - 1; | |
58 | for (; isspace(*binEnd) != 0; --binEnd) | |
59 | binEnd = '\0'; | |
60 | StaticBinList.push_back(bin); | |
61 | if (*binStartNext != ',') | |
62 | break; | |
63 | *binStartNext = '\0'; | |
64 | for (bin = binStartNext + 1; isspace(*bin) != 0; ++bin); | |
65 | } while (*bin != '\0'); | |
66 | StaticBinList.push_back(NULL); | |
c33b707e | 67 | |
e788a834 | 68 | return &StaticBinList[0]; |
b2e465d6 AL |
69 | } |
70 | /*}}}*/ | |
71 | // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/ | |
72 | // --------------------------------------------------------------------- | |
73 | /* This member parses the build-depends information and returns a list of | |
74 | package/version records representing the build dependency. The returned | |
75 | array need not be freed and will be reused by the next call to this | |
76 | function */ | |
8f3ba4e8 | 77 | bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, |
41c81fd8 | 78 | bool const &ArchOnly, bool const &StripMultiArch) |
b2e465d6 AL |
79 | { |
80 | unsigned int I; | |
81 | const char *Start, *Stop; | |
82 | BuildDepRec rec; | |
83 | const char *fields[] = {"Build-Depends", | |
84 | "Build-Depends-Indep", | |
85 | "Build-Conflicts", | |
86 | "Build-Conflicts-Indep"}; | |
87 | ||
88 | BuildDeps.clear(); | |
11e7af84 | 89 | |
b2e465d6 | 90 | for (I = 0; I < 4; I++) |
11e7af84 | 91 | { |
45430cbf AL |
92 | if (ArchOnly && (I == 1 || I == 3)) |
93 | continue; | |
94 | ||
b2e465d6 AL |
95 | if (Sect.Find(fields[I], Start, Stop) == false) |
96 | continue; | |
11e7af84 | 97 | |
b2e465d6 AL |
98 | while (1) |
99 | { | |
100 | Start = debListParser::ParseDepends(Start, Stop, | |
565ded7b | 101 | rec.Package,rec.Version,rec.Op,true,StripMultiArch,true); |
b2e465d6 AL |
102 | |
103 | if (Start == 0) | |
104 | return _error->Error("Problem parsing dependency: %s", fields[I]); | |
105 | rec.Type = I; | |
106 | ||
107 | if (rec.Package != "") | |
108 | BuildDeps.push_back(rec); | |
109 | ||
110 | if (Start == Stop) | |
111 | break; | |
112 | } | |
11e7af84 AL |
113 | } |
114 | ||
b2e465d6 | 115 | return true; |
11e7af84 AL |
116 | } |
117 | /*}}}*/ | |
36f610f1 AL |
118 | // SrcRecordParser::Files - Return a list of files for this source /*{{{*/ |
119 | // --------------------------------------------------------------------- | |
120 | /* This parses the list of files and returns it, each file is required to have | |
121 | a complete source package */ | |
8f3ba4e8 | 122 | bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List) |
36f610f1 AL |
123 | { |
124 | List.erase(List.begin(),List.end()); | |
cb6a2b3e | 125 | |
3bbce699 MV |
126 | // map from the Hashsum field to the hashsum function, |
127 | // unfortunately this is not a 1:1 mapping from | |
128 | // Hashes::SupporedHashes as e.g. Files is a historic name for the md5 | |
129 | const std::pair<const char*, const char*> SourceHashFields[] = { | |
130 | std::make_pair( "Checksums-Sha512", "SHA512"), | |
131 | std::make_pair( "Checksums-Sha256", "SHA256"), | |
132 | std::make_pair( "Checksums-Sha1", "SHA1"), | |
133 | std::make_pair( "Files", "MD5Sum"), // historic Name | |
cb6a2b3e | 134 | }; |
36f610f1 | 135 | |
3bbce699 MV |
136 | for (unsigned int i=0; |
137 | i < sizeof(SourceHashFields)/sizeof(SourceHashFields[0]); | |
138 | i++) | |
cb6a2b3e | 139 | { |
3bbce699 | 140 | string Files = Sect.FindS(SourceHashFields[i].first); |
cb6a2b3e MV |
141 | if (Files.empty() == true) |
142 | continue; | |
143 | ||
144 | // Stash the / terminated directory prefix | |
145 | string Base = Sect.FindS("Directory"); | |
146 | if (Base.empty() == false && Base[Base.length()-1] != '/') | |
147 | Base += '/'; | |
148 | ||
149 | std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions(); | |
150 | ||
151 | // Iterate over the entire list grabbing each triplet | |
152 | const char *C = Files.c_str(); | |
153 | while (*C != 0) | |
154 | { | |
155 | pkgSrcRecords::File F; | |
156 | string Size; | |
157 | ||
158 | // Parse each of the elements | |
159 | std::string RawHash; | |
160 | if (ParseQuoteWord(C, RawHash) == false || | |
161 | ParseQuoteWord(C, Size) == false || | |
162 | ParseQuoteWord(C, F.Path) == false) | |
3bbce699 MV |
163 | return _error->Error("Error parsing '%s' record", |
164 | SourceHashFields[i].first); | |
cb6a2b3e | 165 | // assign full hash string |
3bbce699 | 166 | F.Hash = HashString(SourceHashFields[i].second, RawHash).toStr(); |
a1b5561a | 167 | // API compat hack |
38d2959f | 168 | if(strcmp(SourceHashFields[i].second, "MD5Sum") == 0) |
a1b5561a | 169 | F.MD5Hash = RawHash; |
cb6a2b3e MV |
170 | |
171 | // Parse the size and append the directory | |
172 | F.Size = atoi(Size.c_str()); | |
173 | F.Path = Base + F.Path; | |
174 | ||
175 | // Try to guess what sort of file it is we are getting. | |
176 | string::size_type Pos = F.Path.length()-1; | |
177 | while (1) | |
178 | { | |
179 | string::size_type Tmp = F.Path.rfind('.',Pos); | |
180 | if (Tmp == string::npos) | |
181 | break; | |
182 | if (F.Type == "tar") { | |
183 | // source v3 has extension 'debian.tar.*' instead of 'diff.*' | |
184 | if (string(F.Path, Tmp+1, Pos-Tmp) == "debian") | |
185 | F.Type = "diff"; | |
186 | break; | |
187 | } | |
188 | F.Type = string(F.Path,Tmp+1,Pos-Tmp); | |
189 | ||
190 | if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() || | |
191 | F.Type == "tar") | |
192 | { | |
193 | Pos = Tmp-1; | |
194 | continue; | |
195 | } | |
b2e465d6 | 196 | |
cb6a2b3e MV |
197 | break; |
198 | } | |
b2e465d6 | 199 | |
cb6a2b3e MV |
200 | List.push_back(F); |
201 | } | |
202 | break; | |
36f610f1 | 203 | } |
cb6a2b3e | 204 | return (List.size() > 0); |
36f610f1 AL |
205 | } |
206 | /*}}}*/ | |
7a9f09bd MV |
207 | // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/ |
208 | // --------------------------------------------------------------------- | |
209 | /* */ | |
210 | debSrcRecordParser::~debSrcRecordParser() | |
211 | { | |
212 | delete[] Buffer; | |
213 | } | |
214 | /*}}}*/ |