debsrcrecords.cc 4.9 KB

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