You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

840 lines
27 KiB

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