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

171 lines
5.2 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
  4. /* ######################################################################
  5. Debian Source Package Records - Parser implementation for Debian style
  6. source indexes
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include <apt-pkg/deblistparser.h>
  11. #include <apt-pkg/debsrcrecords.h>
  12. #include <apt-pkg/error.h>
  13. #include <apt-pkg/strutl.h>
  14. #include <apt-pkg/configuration.h>
  15. using std::max;
  16. /*}}}*/
  17. // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
  18. // ---------------------------------------------------------------------
  19. /* This member parses the binaries field into a pair of class arrays and
  20. returns a list of strings representing all of the components of the
  21. binaries field. The returned array need not be freed and will be
  22. reused by the next Binaries function call. This function is commonly
  23. used during scanning to find the right package */
  24. const char **debSrcRecordParser::Binaries()
  25. {
  26. // This should use Start/Stop too, it is supposed to be efficient after all.
  27. string Bins = Sect.FindS("Binary");
  28. if (Bins.empty() == true || Bins.length() >= 102400)
  29. return 0;
  30. if (Bins.length() >= BufSize)
  31. {
  32. delete [] Buffer;
  33. // allocate new size based on buffer (but never smaller than 4000)
  34. BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
  35. Buffer = new char[BufSize];
  36. }
  37. strcpy(Buffer,Bins.c_str());
  38. if (TokSplitString(',',Buffer,StaticBinList,
  39. sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
  40. return 0;
  41. return (const char **)StaticBinList;
  42. }
  43. /*}}}*/
  44. // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
  45. // ---------------------------------------------------------------------
  46. /* This member parses the build-depends information and returns a list of
  47. package/version records representing the build dependency. The returned
  48. array need not be freed and will be reused by the next call to this
  49. function */
  50. bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps,
  51. bool const &ArchOnly, bool const &StripMultiArch)
  52. {
  53. unsigned int I;
  54. const char *Start, *Stop;
  55. BuildDepRec rec;
  56. const char *fields[] = {"Build-Depends",
  57. "Build-Depends-Indep",
  58. "Build-Conflicts",
  59. "Build-Conflicts-Indep"};
  60. BuildDeps.clear();
  61. for (I = 0; I < 4; I++)
  62. {
  63. if (ArchOnly && (I == 1 || I == 3))
  64. continue;
  65. if (Sect.Find(fields[I], Start, Stop) == false)
  66. continue;
  67. while (1)
  68. {
  69. Start = debListParser::ParseDepends(Start, Stop,
  70. rec.Package,rec.Version,rec.Op,true, StripMultiArch);
  71. if (Start == 0)
  72. return _error->Error("Problem parsing dependency: %s", fields[I]);
  73. rec.Type = I;
  74. if (rec.Package != "")
  75. BuildDeps.push_back(rec);
  76. if (Start == Stop)
  77. break;
  78. }
  79. }
  80. return true;
  81. }
  82. /*}}}*/
  83. // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
  84. // ---------------------------------------------------------------------
  85. /* This parses the list of files and returns it, each file is required to have
  86. a complete source package */
  87. bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
  88. {
  89. List.erase(List.begin(),List.end());
  90. string Files = Sect.FindS("Files");
  91. if (Files.empty() == true)
  92. return false;
  93. // Stash the / terminated directory prefix
  94. string Base = Sect.FindS("Directory");
  95. if (Base.empty() == false && Base[Base.length()-1] != '/')
  96. Base += '/';
  97. // Iterate over the entire list grabbing each triplet
  98. const char *C = Files.c_str();
  99. while (*C != 0)
  100. {
  101. pkgSrcRecords::File F;
  102. string Size;
  103. // Parse each of the elements
  104. if (ParseQuoteWord(C,F.MD5Hash) == false ||
  105. ParseQuoteWord(C,Size) == false ||
  106. ParseQuoteWord(C,F.Path) == false)
  107. return _error->Error("Error parsing file record");
  108. // Parse the size and append the directory
  109. F.Size = atoi(Size.c_str());
  110. F.Path = Base + F.Path;
  111. // Try to guess what sort of file it is we are getting.
  112. string::size_type Pos = F.Path.length()-1;
  113. while (1)
  114. {
  115. string::size_type Tmp = F.Path.rfind('.',Pos);
  116. if (Tmp == string::npos)
  117. break;
  118. if (F.Type == "tar") {
  119. // source v3 has extension 'debian.tar.*' instead of 'diff.*'
  120. if (string(F.Path, Tmp+1, Pos-Tmp) == "debian")
  121. F.Type = "diff";
  122. break;
  123. }
  124. F.Type = string(F.Path,Tmp+1,Pos-Tmp);
  125. if (F.Type == "gz" || F.Type == "bz2" || F.Type == "lzma" ||
  126. F.Type == "xz" || F.Type == "tar")
  127. {
  128. Pos = Tmp-1;
  129. continue;
  130. }
  131. break;
  132. }
  133. List.push_back(F);
  134. }
  135. return true;
  136. }
  137. /*}}}*/
  138. // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
  139. // ---------------------------------------------------------------------
  140. /* */
  141. debSrcRecordParser::~debSrcRecordParser()
  142. {
  143. delete[] Buffer;
  144. }
  145. /*}}}*/