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