deblistparser.cc 27 KB

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