deblistparser.cc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: deblistparser.cc,v 1.29.2.5 2004/01/06 01:43:44 mdz Exp $
  4. /* ######################################################################
  5. Package Cache Generator - Generator for the cache structure.
  6. This builds the cache structure from the abstract package list parser.
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <config.h>
  11. #include <apt-pkg/deblistparser.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/configuration.h>
  14. #include <apt-pkg/cachefilter.h>
  15. #include <apt-pkg/aptconfiguration.h>
  16. #include <apt-pkg/strutl.h>
  17. #include <apt-pkg/fileutl.h>
  18. #include <apt-pkg/crc-16.h>
  19. #include <apt-pkg/md5.h>
  20. #include <apt-pkg/macros.h>
  21. #include <ctype.h>
  22. /*}}}*/
  23. using std::string;
  24. static debListParser::WordList PrioList[] = {
  25. {"required",pkgCache::State::Required},
  26. {"important",pkgCache::State::Important},
  27. {"standard",pkgCache::State::Standard},
  28. {"optional",pkgCache::State::Optional},
  29. {"extra",pkgCache::State::Extra},
  30. {}};
  31. // ListParser::debListParser - Constructor /*{{{*/
  32. // ---------------------------------------------------------------------
  33. /* Provide an architecture and only this one and "all" will be accepted
  34. in Step(), if no Architecture is given we will accept every arch
  35. we would accept in general with checkArchitecture() */
  36. debListParser::debListParser(FileFd *File, string const &Arch) : Tags(File),
  37. Arch(Arch) {
  38. if (Arch == "native")
  39. this->Arch = _config->Find("APT::Architecture");
  40. Architectures = APT::Configuration::getArchitectures();
  41. MultiArchEnabled = Architectures.size() > 1;
  42. }
  43. /*}}}*/
  44. // ListParser::UniqFindTagWrite - Find the tag and write a unq string /*{{{*/
  45. // ---------------------------------------------------------------------
  46. /* */
  47. unsigned long debListParser::UniqFindTagWrite(const char *Tag)
  48. {
  49. const char *Start;
  50. const char *Stop;
  51. if (Section.Find(Tag,Start,Stop) == false)
  52. return 0;
  53. return WriteUniqString(Start,Stop - Start);
  54. }
  55. /*}}}*/
  56. // ListParser::Package - Return the package name /*{{{*/
  57. // ---------------------------------------------------------------------
  58. /* This is to return the name of the package this section describes */
  59. string debListParser::Package() {
  60. string const Result = Section.FindS("Package");
  61. if(unlikely(Result.empty() == true))
  62. _error->Error("Encountered a section with no Package: header");
  63. return Result;
  64. }
  65. /*}}}*/
  66. // ListParser::Architecture - Return the package arch /*{{{*/
  67. // ---------------------------------------------------------------------
  68. /* This will return the Architecture of the package this section describes */
  69. string debListParser::Architecture() {
  70. return Section.FindS("Architecture");
  71. }
  72. /*}}}*/
  73. // ListParser::ArchitectureAll /*{{{*/
  74. // ---------------------------------------------------------------------
  75. /* */
  76. bool debListParser::ArchitectureAll() {
  77. return Section.FindS("Architecture") == "all";
  78. }
  79. /*}}}*/
  80. // ListParser::Version - Return the version string /*{{{*/
  81. // ---------------------------------------------------------------------
  82. /* This is to return the string describing the version in debian form,
  83. epoch:upstream-release. If this returns the blank string then the
  84. entry is assumed to only describe package properties */
  85. string debListParser::Version()
  86. {
  87. return Section.FindS("Version");
  88. }
  89. /*}}}*/
  90. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  91. // ---------------------------------------------------------------------
  92. /* */
  93. bool debListParser::NewVersion(pkgCache::VerIterator &Ver)
  94. {
  95. // Parse the section
  96. Ver->Section = UniqFindTagWrite("Section");
  97. // Parse multi-arch
  98. string const MultiArch = Section.FindS("Multi-Arch");
  99. if (MultiArch.empty() == true)
  100. Ver->MultiArch = pkgCache::Version::None;
  101. else if (MultiArch == "same") {
  102. // Parse multi-arch
  103. if (ArchitectureAll() == true)
  104. {
  105. /* Arch all packages can't be Multi-Arch: same */
  106. _error->Warning("Architecture: all package '%s' can't be Multi-Arch: same",
  107. Section.FindS("Package").c_str());
  108. Ver->MultiArch = pkgCache::Version::None;
  109. }
  110. else
  111. Ver->MultiArch = pkgCache::Version::Same;
  112. }
  113. else if (MultiArch == "foreign")
  114. Ver->MultiArch = pkgCache::Version::Foreign;
  115. else if (MultiArch == "allowed")
  116. Ver->MultiArch = pkgCache::Version::Allowed;
  117. else
  118. {
  119. _error->Warning("Unknown Multi-Arch type '%s' for package '%s'",
  120. MultiArch.c_str(), Section.FindS("Package").c_str());
  121. Ver->MultiArch = pkgCache::Version::None;
  122. }
  123. if (ArchitectureAll() == true)
  124. Ver->MultiArch |= pkgCache::Version::All;
  125. // Archive Size
  126. Ver->Size = Section.FindULL("Size");
  127. // Unpacked Size (in K)
  128. Ver->InstalledSize = Section.FindULL("Installed-Size");
  129. Ver->InstalledSize *= 1024;
  130. // Priority
  131. const char *Start;
  132. const char *Stop;
  133. if (Section.Find("Priority",Start,Stop) == true)
  134. {
  135. if (GrabWord(string(Start,Stop-Start),PrioList,Ver->Priority) == false)
  136. Ver->Priority = pkgCache::State::Extra;
  137. }
  138. if (ParseDepends(Ver,"Depends",pkgCache::Dep::Depends) == false)
  139. return false;
  140. if (ParseDepends(Ver,"Pre-Depends",pkgCache::Dep::PreDepends) == false)
  141. return false;
  142. if (ParseDepends(Ver,"Suggests",pkgCache::Dep::Suggests) == false)
  143. return false;
  144. if (ParseDepends(Ver,"Recommends",pkgCache::Dep::Recommends) == false)
  145. return false;
  146. if (ParseDepends(Ver,"Conflicts",pkgCache::Dep::Conflicts) == false)
  147. return false;
  148. if (ParseDepends(Ver,"Breaks",pkgCache::Dep::DpkgBreaks) == false)
  149. return false;
  150. if (ParseDepends(Ver,"Replaces",pkgCache::Dep::Replaces) == false)
  151. return false;
  152. if (ParseDepends(Ver,"Enhances",pkgCache::Dep::Enhances) == false)
  153. return false;
  154. // Obsolete.
  155. if (ParseDepends(Ver,"Optional",pkgCache::Dep::Suggests) == false)
  156. return false;
  157. if (ParseProvides(Ver) == false)
  158. return false;
  159. return true;
  160. }
  161. /*}}}*/
  162. // ListParser::Description - Return the description string /*{{{*/
  163. // ---------------------------------------------------------------------
  164. /* This is to return the string describing the package in debian
  165. form. If this returns the blank string then the entry is assumed to
  166. only describe package properties */
  167. string debListParser::Description()
  168. {
  169. string const lang = DescriptionLanguage();
  170. if (lang.empty())
  171. return Section.FindS("Description");
  172. else
  173. return Section.FindS(string("Description-").append(lang).c_str());
  174. }
  175. /*}}}*/
  176. // ListParser::DescriptionLanguage - Return the description lang string /*{{{*/
  177. // ---------------------------------------------------------------------
  178. /* This is to return the string describing the language of
  179. description. If this returns the blank string then the entry is
  180. assumed to describe original description. */
  181. string debListParser::DescriptionLanguage()
  182. {
  183. if (Section.FindS("Description").empty() == false)
  184. return "";
  185. std::vector<string> const lang = APT::Configuration::getLanguages(true);
  186. for (std::vector<string>::const_iterator l = lang.begin();
  187. l != lang.end(); ++l)
  188. if (Section.FindS(string("Description-").append(*l).c_str()).empty() == false)
  189. return *l;
  190. return "";
  191. }
  192. /*}}}*/
  193. // ListParser::Description - Return the description_md5 MD5SumValue /*{{{*/
  194. // ---------------------------------------------------------------------
  195. /* This is to return the md5 string to allow the check if it is the right
  196. description. If no Description-md5 is found in the section it will be
  197. calculated.
  198. */
  199. MD5SumValue debListParser::Description_md5()
  200. {
  201. string const value = Section.FindS("Description-md5");
  202. if (value.empty() == true)
  203. {
  204. std::string const desc = Description() + "\n";
  205. if (desc == "\n")
  206. return MD5SumValue();
  207. MD5Summation md5;
  208. md5.Add(desc.c_str());
  209. return md5.Result();
  210. }
  211. else if (likely(value.size() == 32))
  212. {
  213. if (likely(value.find_first_not_of("0123456789abcdefABCDEF") == string::npos))
  214. return MD5SumValue(value);
  215. _error->Error("Malformed Description-md5 line; includes invalid character '%s'", value.c_str());
  216. return MD5SumValue();
  217. }
  218. _error->Error("Malformed Description-md5 line; doesn't have the required length (32 != %d) '%s'", (int)value.size(), value.c_str());
  219. return MD5SumValue();
  220. }
  221. /*}}}*/
  222. // ListParser::UsePackage - Update a package structure /*{{{*/
  223. // ---------------------------------------------------------------------
  224. /* This is called to update the package with any new information
  225. that might be found in the section */
  226. bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
  227. pkgCache::VerIterator &Ver)
  228. {
  229. if (Pkg->Section == 0)
  230. Pkg->Section = UniqFindTagWrite("Section");
  231. string const static myArch = _config->Find("APT::Architecture");
  232. // Possible values are: "all", "native", "installed" and "none"
  233. // The "installed" mode is handled by ParseStatus(), See #544481 and friends.
  234. string const static essential = _config->Find("pkgCacheGen::Essential", "all");
  235. if (essential == "all" ||
  236. (essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()))
  237. if (Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
  238. return false;
  239. if (Section.FindFlag("Important",Pkg->Flags,pkgCache::Flag::Important) == false)
  240. return false;
  241. if (strcmp(Pkg.Name(),"apt") == 0)
  242. {
  243. if ((essential == "native" && Pkg->Arch != 0 && myArch == Pkg.Arch()) ||
  244. essential == "all")
  245. Pkg->Flags |= pkgCache::Flag::Essential | pkgCache::Flag::Important;
  246. else
  247. Pkg->Flags |= pkgCache::Flag::Important;
  248. }
  249. if (ParseStatus(Pkg,Ver) == false)
  250. return false;
  251. return true;
  252. }
  253. /*}}}*/
  254. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  255. // ---------------------------------------------------------------------
  256. /* */
  257. unsigned short debListParser::VersionHash()
  258. {
  259. const char *Sections[] ={"Installed-Size",
  260. "Depends",
  261. "Pre-Depends",
  262. // "Suggests",
  263. // "Recommends",
  264. "Conflicts",
  265. "Breaks",
  266. "Replaces",0};
  267. unsigned long Result = INIT_FCS;
  268. char S[1024];
  269. for (const char * const *I = Sections; *I != 0; ++I)
  270. {
  271. const char *Start;
  272. const char *End;
  273. if (Section.Find(*I,Start,End) == false || End - Start >= (signed)sizeof(S))
  274. continue;
  275. /* Strip out any spaces from the text, this undoes dpkgs reformatting
  276. of certain fields. dpkg also has the rather interesting notion of
  277. reformatting depends operators < -> <= */
  278. char *J = S;
  279. for (; Start != End; ++Start)
  280. {
  281. if (isspace(*Start) != 0)
  282. continue;
  283. *J++ = tolower_ascii(*Start);
  284. if ((*Start == '<' || *Start == '>') && Start[1] != *Start && Start[1] != '=')
  285. *J++ = '=';
  286. }
  287. Result = AddCRC16(Result,S,J - S);
  288. }
  289. return Result;
  290. }
  291. /*}}}*/
  292. // ListParser::ParseStatus - Parse the status field /*{{{*/
  293. // ---------------------------------------------------------------------
  294. /* Status lines are of the form,
  295. Status: want flag status
  296. want = unknown, install, hold, deinstall, purge
  297. flag = ok, reinstreq, hold, hold-reinstreq
  298. status = not-installed, unpacked, half-configured,
  299. half-installed, config-files, post-inst-failed,
  300. removal-failed, installed
  301. Some of the above are obsolete (I think?) flag = hold-* and
  302. status = post-inst-failed, removal-failed at least.
  303. */
  304. bool debListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  305. pkgCache::VerIterator &Ver)
  306. {
  307. const char *Start;
  308. const char *Stop;
  309. if (Section.Find("Status",Start,Stop) == false)
  310. return true;
  311. // UsePackage() is responsible for setting the flag in the default case
  312. bool const static essential = _config->Find("pkgCacheGen::Essential", "") == "installed";
  313. if (essential == true &&
  314. Section.FindFlag("Essential",Pkg->Flags,pkgCache::Flag::Essential) == false)
  315. return false;
  316. // Isolate the first word
  317. const char *I = Start;
  318. for(; I < Stop && *I != ' '; I++);
  319. if (I >= Stop || *I != ' ')
  320. return _error->Error("Malformed Status line");
  321. // Process the want field
  322. WordList WantList[] = {{"unknown",pkgCache::State::Unknown},
  323. {"install",pkgCache::State::Install},
  324. {"hold",pkgCache::State::Hold},
  325. {"deinstall",pkgCache::State::DeInstall},
  326. {"purge",pkgCache::State::Purge},
  327. {}};
  328. if (GrabWord(string(Start,I-Start),WantList,Pkg->SelectedState) == false)
  329. return _error->Error("Malformed 1st word in the Status line");
  330. // Isloate the next word
  331. I++;
  332. Start = I;
  333. for(; I < Stop && *I != ' '; I++);
  334. if (I >= Stop || *I != ' ')
  335. return _error->Error("Malformed status line, no 2nd word");
  336. // Process the flag field
  337. WordList FlagList[] = {{"ok",pkgCache::State::Ok},
  338. {"reinstreq",pkgCache::State::ReInstReq},
  339. {"hold",pkgCache::State::HoldInst},
  340. {"hold-reinstreq",pkgCache::State::HoldReInstReq},
  341. {}};
  342. if (GrabWord(string(Start,I-Start),FlagList,Pkg->InstState) == false)
  343. return _error->Error("Malformed 2nd word in the Status line");
  344. // Isloate the last word
  345. I++;
  346. Start = I;
  347. for(; I < Stop && *I != ' '; I++);
  348. if (I != Stop)
  349. return _error->Error("Malformed Status line, no 3rd word");
  350. // Process the flag field
  351. WordList StatusList[] = {{"not-installed",pkgCache::State::NotInstalled},
  352. {"unpacked",pkgCache::State::UnPacked},
  353. {"half-configured",pkgCache::State::HalfConfigured},
  354. {"installed",pkgCache::State::Installed},
  355. {"half-installed",pkgCache::State::HalfInstalled},
  356. {"config-files",pkgCache::State::ConfigFiles},
  357. {"triggers-awaited",pkgCache::State::TriggersAwaited},
  358. {"triggers-pending",pkgCache::State::TriggersPending},
  359. {"post-inst-failed",pkgCache::State::HalfConfigured},
  360. {"removal-failed",pkgCache::State::HalfInstalled},
  361. {}};
  362. if (GrabWord(string(Start,I-Start),StatusList,Pkg->CurrentState) == false)
  363. return _error->Error("Malformed 3rd word in the Status line");
  364. /* A Status line marks the package as indicating the current
  365. version as well. Only if it is actually installed.. Otherwise
  366. the interesting dpkg handling of the status file creates bogus
  367. entries. */
  368. if (!(Pkg->CurrentState == pkgCache::State::NotInstalled ||
  369. Pkg->CurrentState == pkgCache::State::ConfigFiles))
  370. {
  371. if (Ver.end() == true)
  372. _error->Warning("Encountered status field in a non-version description");
  373. else
  374. Pkg->CurrentVer = Ver.Index();
  375. }
  376. return true;
  377. }
  378. const char *debListParser::ConvertRelation(const char *I,unsigned int &Op)
  379. {
  380. // Determine the operator
  381. switch (*I)
  382. {
  383. case '<':
  384. I++;
  385. if (*I == '=')
  386. {
  387. I++;
  388. Op = pkgCache::Dep::LessEq;
  389. break;
  390. }
  391. if (*I == '<')
  392. {
  393. I++;
  394. Op = pkgCache::Dep::Less;
  395. break;
  396. }
  397. // < is the same as <= and << is really Cs < for some reason
  398. Op = pkgCache::Dep::LessEq;
  399. break;
  400. case '>':
  401. I++;
  402. if (*I == '=')
  403. {
  404. I++;
  405. Op = pkgCache::Dep::GreaterEq;
  406. break;
  407. }
  408. if (*I == '>')
  409. {
  410. I++;
  411. Op = pkgCache::Dep::Greater;
  412. break;
  413. }
  414. // > is the same as >= and >> is really Cs > for some reason
  415. Op = pkgCache::Dep::GreaterEq;
  416. break;
  417. case '=':
  418. Op = pkgCache::Dep::Equals;
  419. I++;
  420. break;
  421. // HACK around bad package definitions
  422. default:
  423. Op = pkgCache::Dep::Equals;
  424. break;
  425. }
  426. return I;
  427. }
  428. /*}}}*/
  429. // ListParser::ParseDepends - Parse a dependency element /*{{{*/
  430. // ---------------------------------------------------------------------
  431. /* This parses the dependency elements out of a standard string in place,
  432. bit by bit. */
  433. const char *debListParser::ParseDepends(const char *Start,const char *Stop,
  434. string &Package,string &Ver,
  435. unsigned int &Op, bool const &ParseArchFlags,
  436. bool const &StripMultiArch)
  437. {
  438. // Strip off leading space
  439. for (;Start != Stop && isspace(*Start) != 0; Start++);
  440. // Parse off the package name
  441. const char *I = Start;
  442. for (;I != Stop && isspace(*I) == 0 && *I != '(' && *I != ')' &&
  443. *I != ',' && *I != '|' && *I != '[' && *I != ']'; I++);
  444. // Malformed, no '('
  445. if (I != Stop && *I == ')')
  446. return 0;
  447. if (I == Start)
  448. return 0;
  449. // Stash the package name
  450. Package.assign(Start,I - Start);
  451. // We don't want to confuse library users which can't handle MultiArch
  452. string const arch = _config->Find("APT::Architecture");
  453. if (StripMultiArch == true) {
  454. size_t const found = Package.rfind(':');
  455. if (found != string::npos &&
  456. (strcmp(Package.c_str() + found, ":any") == 0 ||
  457. strcmp(Package.c_str() + found, ":native") == 0 ||
  458. strcmp(Package.c_str() + found + 1, arch.c_str()) == 0))
  459. Package = Package.substr(0,found);
  460. }
  461. // Skip white space to the '('
  462. for (;I != Stop && isspace(*I) != 0 ; I++);
  463. // Parse a version
  464. if (I != Stop && *I == '(')
  465. {
  466. // Skip the '('
  467. for (I++; I != Stop && isspace(*I) != 0 ; I++);
  468. if (I + 3 >= Stop)
  469. return 0;
  470. I = ConvertRelation(I,Op);
  471. // Skip whitespace
  472. for (;I != Stop && isspace(*I) != 0; I++);
  473. Start = I;
  474. I = (const char*) memchr(I, ')', Stop - I);
  475. if (I == NULL || Start == I)
  476. return 0;
  477. // Skip trailing whitespace
  478. const char *End = I;
  479. for (; End > Start && isspace(End[-1]); End--);
  480. Ver.assign(Start,End-Start);
  481. I++;
  482. }
  483. else
  484. {
  485. Ver.clear();
  486. Op = pkgCache::Dep::NoOp;
  487. }
  488. // Skip whitespace
  489. for (;I != Stop && isspace(*I) != 0; I++);
  490. if (ParseArchFlags == true)
  491. {
  492. APT::CacheFilter::PackageArchitectureMatchesSpecification matchesArch(arch, false);
  493. // Parse an architecture
  494. if (I != Stop && *I == '[')
  495. {
  496. ++I;
  497. // malformed
  498. if (unlikely(I == Stop))
  499. return 0;
  500. const char *End = I;
  501. bool Found = false;
  502. bool NegArch = false;
  503. while (I != Stop)
  504. {
  505. // look for whitespace or ending ']'
  506. for (;End != Stop && !isspace(*End) && *End != ']'; ++End);
  507. if (unlikely(End == Stop))
  508. return 0;
  509. if (*I == '!')
  510. {
  511. NegArch = true;
  512. ++I;
  513. }
  514. std::string arch(I, End);
  515. if (arch.empty() == false && matchesArch(arch.c_str()) == true)
  516. {
  517. Found = true;
  518. if (I[-1] != '!')
  519. NegArch = false;
  520. // we found a match, so fast-forward to the end of the wildcards
  521. for (; End != Stop && *End != ']'; ++End);
  522. }
  523. if (*End++ == ']') {
  524. I = End;
  525. break;
  526. }
  527. I = End;
  528. for (;I != Stop && isspace(*I) != 0; I++);
  529. }
  530. if (NegArch == true)
  531. Found = !Found;
  532. if (Found == false)
  533. Package = ""; /* not for this arch */
  534. }
  535. // Skip whitespace
  536. for (;I != Stop && isspace(*I) != 0; I++);
  537. }
  538. if (I != Stop && *I == '|')
  539. Op |= pkgCache::Dep::Or;
  540. if (I == Stop || *I == ',' || *I == '|')
  541. {
  542. if (I != Stop)
  543. for (I++; I != Stop && isspace(*I) != 0; I++);
  544. return I;
  545. }
  546. return 0;
  547. }
  548. /*}}}*/
  549. // ListParser::ParseDepends - Parse a dependency list /*{{{*/
  550. // ---------------------------------------------------------------------
  551. /* This is the higher level depends parser. It takes a tag and generates
  552. a complete depends tree for the given version. */
  553. bool debListParser::ParseDepends(pkgCache::VerIterator &Ver,
  554. const char *Tag,unsigned int Type)
  555. {
  556. const char *Start;
  557. const char *Stop;
  558. if (Section.Find(Tag,Start,Stop) == false)
  559. return true;
  560. string const pkgArch = Ver.Arch();
  561. while (1)
  562. {
  563. string Package;
  564. string Version;
  565. unsigned int Op;
  566. Start = ParseDepends(Start, Stop, Package, Version, Op, false, false);
  567. if (Start == 0)
  568. return _error->Error("Problem parsing dependency %s",Tag);
  569. size_t const found = Package.rfind(':');
  570. // If negative is unspecific it needs to apply on all architectures
  571. if (MultiArchEnabled == true && found == string::npos &&
  572. (Type == pkgCache::Dep::Conflicts ||
  573. Type == pkgCache::Dep::DpkgBreaks ||
  574. Type == pkgCache::Dep::Replaces))
  575. {
  576. for (std::vector<std::string>::const_iterator a = Architectures.begin();
  577. a != Architectures.end(); ++a)
  578. if (NewDepends(Ver,Package,*a,Version,Op,Type) == false)
  579. return false;
  580. if (NewDepends(Ver,Package,"none",Version,Op,Type) == false)
  581. return false;
  582. }
  583. else if (MultiArchEnabled == true && found != string::npos &&
  584. strcmp(Package.c_str() + found, ":any") != 0)
  585. {
  586. string Arch = Package.substr(found+1, string::npos);
  587. Package = Package.substr(0, found);
  588. // Such dependencies are not supposed to be accepted …
  589. // … but this is probably the best thing to do.
  590. if (Arch == "native")
  591. Arch = _config->Find("APT::Architecture");
  592. if (NewDepends(Ver,Package,Arch,Version,Op,Type) == false)
  593. return false;
  594. }
  595. else
  596. {
  597. if (NewDepends(Ver,Package,pkgArch,Version,Op,Type) == false)
  598. return false;
  599. if ((Type == pkgCache::Dep::Conflicts ||
  600. Type == pkgCache::Dep::DpkgBreaks ||
  601. Type == pkgCache::Dep::Replaces) &&
  602. NewDepends(Ver, Package,
  603. (pkgArch != "none") ? "none" : _config->Find("APT::Architecture"),
  604. Version,Op,Type) == false)
  605. return false;
  606. }
  607. if (Start == Stop)
  608. break;
  609. }
  610. return true;
  611. }
  612. /*}}}*/
  613. // ListParser::ParseProvides - Parse the provides list /*{{{*/
  614. // ---------------------------------------------------------------------
  615. /* */
  616. bool debListParser::ParseProvides(pkgCache::VerIterator &Ver)
  617. {
  618. const char *Start;
  619. const char *Stop;
  620. if (Section.Find("Provides",Start,Stop) == true)
  621. {
  622. string Package;
  623. string Version;
  624. string const Arch = Ver.Arch();
  625. unsigned int Op;
  626. while (1)
  627. {
  628. Start = ParseDepends(Start,Stop,Package,Version,Op);
  629. if (Start == 0)
  630. return _error->Error("Problem parsing Provides line");
  631. if (Op != pkgCache::Dep::NoOp) {
  632. _error->Warning("Ignoring Provides line with DepCompareOp for package %s", Package.c_str());
  633. } else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign) {
  634. if (NewProvidesAllArch(Ver, Package, Version) == false)
  635. return false;
  636. } else {
  637. if (NewProvides(Ver, Package, Arch, Version) == false)
  638. return false;
  639. }
  640. if (Start == Stop)
  641. break;
  642. }
  643. }
  644. if ((Ver->MultiArch & pkgCache::Version::Allowed) == pkgCache::Version::Allowed)
  645. {
  646. string const Package = string(Ver.ParentPkg().Name()).append(":").append("any");
  647. return NewProvidesAllArch(Ver, Package, Ver.VerStr());
  648. }
  649. else if ((Ver->MultiArch & pkgCache::Version::Foreign) == pkgCache::Version::Foreign)
  650. return NewProvidesAllArch(Ver, Ver.ParentPkg().Name(), Ver.VerStr());
  651. return true;
  652. }
  653. /*}}}*/
  654. // ListParser::NewProvides - add provides for all architectures /*{{{*/
  655. bool debListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, string const &Package,
  656. string const &Version) {
  657. for (std::vector<string>::const_iterator a = Architectures.begin();
  658. a != Architectures.end(); ++a)
  659. {
  660. if (NewProvides(Ver, Package, *a, Version) == false)
  661. return false;
  662. }
  663. return true;
  664. }
  665. /*}}}*/
  666. // ListParser::GrabWord - Matches a word and returns /*{{{*/
  667. // ---------------------------------------------------------------------
  668. /* Looks for a word in a list of words - for ParseStatus */
  669. bool debListParser::GrabWord(string Word,WordList *List,unsigned char &Out)
  670. {
  671. for (unsigned int C = 0; List[C].Str != 0; C++)
  672. {
  673. if (strcasecmp(Word.c_str(),List[C].Str) == 0)
  674. {
  675. Out = List[C].Val;
  676. return true;
  677. }
  678. }
  679. return false;
  680. }
  681. /*}}}*/
  682. // ListParser::Step - Move to the next section in the file /*{{{*/
  683. // ---------------------------------------------------------------------
  684. /* This has to be careful to only process the correct architecture */
  685. bool debListParser::Step()
  686. {
  687. iOffset = Tags.Offset();
  688. while (Tags.Step(Section) == true)
  689. {
  690. /* See if this is the correct Architecture, if it isn't then we
  691. drop the whole section. A missing arch tag only happens (in theory)
  692. inside the Status file, so that is a positive return */
  693. string const Architecture = Section.FindS("Architecture");
  694. if (Arch.empty() == true || Arch == "any" || MultiArchEnabled == false)
  695. {
  696. if (APT::Configuration::checkArchitecture(Architecture) == true)
  697. return true;
  698. /* parse version stanzas without an architecture only in the status file
  699. (and as misfortune bycatch flat-archives) */
  700. if ((Arch.empty() == true || Arch == "any") && Architecture.empty() == true)
  701. return true;
  702. }
  703. else
  704. {
  705. if (Architecture == Arch)
  706. return true;
  707. if (Architecture == "all" && Arch == _config->Find("APT::Architecture"))
  708. return true;
  709. }
  710. iOffset = Tags.Offset();
  711. }
  712. return false;
  713. }
  714. /*}}}*/
  715. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  716. // ---------------------------------------------------------------------
  717. /* */
  718. bool debListParser::LoadReleaseInfo(pkgCache::PkgFileIterator &FileI,
  719. FileFd &File, string component)
  720. {
  721. // apt-secure does no longer download individual (per-section) Release
  722. // file. to provide Component pinning we use the section name now
  723. map_ptrloc const storage = WriteUniqString(component);
  724. FileI->Component = storage;
  725. pkgTagFile TagFile(&File, File.Size());
  726. pkgTagSection Section;
  727. if (_error->PendingError() == true || TagFile.Step(Section) == false)
  728. return false;
  729. std::string data;
  730. #define APT_INRELEASE(TAG, STORE) \
  731. data = Section.FindS(TAG); \
  732. if (data.empty() == false) \
  733. { \
  734. map_ptrloc const storage = WriteUniqString(data); \
  735. STORE = storage; \
  736. }
  737. APT_INRELEASE("Suite", FileI->Archive)
  738. APT_INRELEASE("Component", FileI->Component)
  739. APT_INRELEASE("Version", FileI->Version)
  740. APT_INRELEASE("Origin", FileI->Origin)
  741. APT_INRELEASE("Codename", FileI->Codename)
  742. APT_INRELEASE("Label", FileI->Label)
  743. #undef APT_INRELEASE
  744. Section.FindFlag("NotAutomatic", FileI->Flags, pkgCache::Flag::NotAutomatic);
  745. Section.FindFlag("ButAutomaticUpgrades", FileI->Flags, pkgCache::Flag::ButAutomaticUpgrades);
  746. return !_error->PendingError();
  747. }
  748. /*}}}*/
  749. // ListParser::GetPrio - Convert the priority from a string /*{{{*/
  750. // ---------------------------------------------------------------------
  751. /* */
  752. unsigned char debListParser::GetPrio(string Str)
  753. {
  754. unsigned char Out;
  755. if (GrabWord(Str,PrioList,Out) == false)
  756. Out = pkgCache::State::Extra;
  757. return Out;
  758. }
  759. /*}}}*/