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