deblistparser.cc 26 KB

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