deblistparser.cc 25 KB

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