]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsrcrecords.cc
* apt-pkg/aptconfiguration.cc:
[apt.git] / apt-pkg / deb / debsrcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
4 /* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11 // Include Files /*{{{*/
12 #include <config.h>
13
14 #include <apt-pkg/deblistparser.h>
15 #include <apt-pkg/debsrcrecords.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/configuration.h>
19 #include <apt-pkg/aptconfiguration.h>
20
21 using std::max;
22 /*}}}*/
23
24 using std::string;
25
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
31 reused by the next Binaries function call. This function is commonly
32 used during scanning to find the right package */
33 const char **debSrcRecordParser::Binaries()
34 {
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);
45
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);
59
60 return (const char **) &StaticBinList[0];
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 */
69 bool debSrcRecordParser::BuildDepends(std::vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
70 bool const &ArchOnly, bool const &StripMultiArch)
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();
81
82 for (I = 0; I < 4; I++)
83 {
84 if (ArchOnly && (I == 1 || I == 3))
85 continue;
86
87 if (Sect.Find(fields[I], Start, Stop) == false)
88 continue;
89
90 while (1)
91 {
92 Start = debListParser::ParseDepends(Start, Stop,
93 rec.Package,rec.Version,rec.Op,true, StripMultiArch);
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 }
105 }
106
107 return true;
108 }
109 /*}}}*/
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 */
114 bool debSrcRecordParser::Files(std::vector<pkgSrcRecords::File> &List)
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
123 string Base = Sect.FindS("Directory");
124 if (Base.empty() == false && Base[Base.length()-1] != '/')
125 Base += '/';
126
127 std::vector<std::string> const compExts = APT::Configuration::getCompressorExtensions();
128
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;
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;
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 }
159 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
160
161 if (std::find(compExts.begin(), compExts.end(), std::string(".").append(F.Type)) != compExts.end() ||
162 F.Type == "tar")
163 {
164 Pos = Tmp-1;
165 continue;
166 }
167
168 break;
169 }
170
171 List.push_back(F);
172 }
173
174 return true;
175 }
176 /*}}}*/
177 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
178 // ---------------------------------------------------------------------
179 /* */
180 debSrcRecordParser::~debSrcRecordParser()
181 {
182 delete[] Buffer;
183 }
184 /*}}}*/