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