]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsrcrecords.cc
* remove all the remaining #pragma implementation
[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 <apt-pkg/deblistparser.h>
13 #include <apt-pkg/debsrcrecords.h>
14 #include <apt-pkg/error.h>
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/configuration.h>
17 /*}}}*/
18
19 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
20 // ---------------------------------------------------------------------
21 /* This member parses the binaries field into a pair of class arrays and
22 returns a list of strings representing all of the components of the
23 binaries field. The returned array need not be freed and will be
24 reused by the next Binaries function call. This function is commonly
25 used during scanning to find the right package */
26 const char **debSrcRecordParser::Binaries()
27 {
28 // This should use Start/Stop too, it is supposed to be efficient after all.
29 string Bins = Sect.FindS("Binary");
30 if (Bins.empty() == true || Bins.length() >= 102400)
31 return 0;
32
33 // Workaround for #236688. Only allocate a new buffer if the field
34 // is large, to avoid a performance penalty
35 char *BigBuf = NULL;
36 char *Buf;
37 if (Bins.length() > sizeof(Buffer))
38 {
39 BigBuf = new char[Bins.length()];
40 Buf = BigBuf;
41 }
42 else
43 {
44 Buf = Buffer;
45 }
46
47 strcpy(Buf,Bins.c_str());
48 if (TokSplitString(',',Buf,StaticBinList,
49 sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
50 {
51 if (BigBuf != NULL)
52 delete BigBuf;
53 return 0;
54 }
55
56 if (BigBuf != NULL)
57 delete BigBuf;
58 return (const char **)StaticBinList;
59 }
60 /*}}}*/
61 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
62 // ---------------------------------------------------------------------
63 /* This member parses the build-depends information and returns a list of
64 package/version records representing the build dependency. The returned
65 array need not be freed and will be reused by the next call to this
66 function */
67 bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool ArchOnly)
68 {
69 unsigned int I;
70 const char *Start, *Stop;
71 BuildDepRec rec;
72 const char *fields[] = {"Build-Depends",
73 "Build-Depends-Indep",
74 "Build-Conflicts",
75 "Build-Conflicts-Indep"};
76
77 BuildDeps.clear();
78
79 for (I = 0; I < 4; I++)
80 {
81 if (ArchOnly && (I == 1 || I == 3))
82 continue;
83
84 if (Sect.Find(fields[I], Start, Stop) == false)
85 continue;
86
87 while (1)
88 {
89 Start = debListParser::ParseDepends(Start, Stop,
90 rec.Package,rec.Version,rec.Op,true);
91
92 if (Start == 0)
93 return _error->Error("Problem parsing dependency: %s", fields[I]);
94 rec.Type = I;
95
96 if (rec.Package != "")
97 BuildDeps.push_back(rec);
98
99 if (Start == Stop)
100 break;
101 }
102 }
103
104 return true;
105 }
106 /*}}}*/
107 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
108 // ---------------------------------------------------------------------
109 /* This parses the list of files and returns it, each file is required to have
110 a complete source package */
111 bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
112 {
113 List.erase(List.begin(),List.end());
114
115 string Files = Sect.FindS("Files");
116 if (Files.empty() == true)
117 return false;
118
119 // Stash the / terminated directory prefix
120 string Base = Sect.FindS("Directory");
121 if (Base.empty() == false && Base[Base.length()-1] != '/')
122 Base += '/';
123
124 // Iterate over the entire list grabbing each triplet
125 const char *C = Files.c_str();
126 while (*C != 0)
127 {
128 pkgSrcRecords::File F;
129 string Size;
130
131 // Parse each of the elements
132 if (ParseQuoteWord(C,F.MD5Hash) == false ||
133 ParseQuoteWord(C,Size) == false ||
134 ParseQuoteWord(C,F.Path) == false)
135 return _error->Error("Error parsing file record");
136
137 // Parse the size and append the directory
138 F.Size = atoi(Size.c_str());
139 F.Path = Base + F.Path;
140
141 // Try to guess what sort of file it is we are getting.
142 string::size_type Pos = F.Path.length()-1;
143 while (1)
144 {
145 string::size_type Tmp = F.Path.rfind('.',Pos);
146 if (Tmp == string::npos)
147 break;
148 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
149
150 if (F.Type == "gz" || F.Type == "bz2")
151 {
152 Pos = Tmp-1;
153 continue;
154 }
155
156 break;
157 }
158
159 List.push_back(F);
160 }
161
162 return true;
163 }
164 /*}}}*/