debsrcrecords.cc 5.4 KB

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