deblistparser.cc 27 KB

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