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.
 
 
 
 
 
 

180 lines
5.5 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: debrecords.cc,v 1.10 2001/03/13 06:51:46 jgg Exp $
  4. /* ######################################################################
  5. Debian Package Records - Parser for debian package records
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <apt-pkg/debrecords.h>
  10. #include <apt-pkg/strutl.h>
  11. #include <apt-pkg/error.h>
  12. #include <apt-pkg/aptconfiguration.h>
  13. #include <langinfo.h>
  14. /*}}}*/
  15. // RecordParser::debRecordParser - Constructor /*{{{*/
  16. // ---------------------------------------------------------------------
  17. /* */
  18. debRecordParser::debRecordParser(string FileName,pkgCache &Cache) :
  19. File(FileName,FileFd::ReadOnlyGzip),
  20. Tags(&File, std::max(Cache.Head().MaxVerFileSize,
  21. Cache.Head().MaxDescFileSize) + 200)
  22. {
  23. }
  24. /*}}}*/
  25. // RecordParser::Jump - Jump to a specific record /*{{{*/
  26. // ---------------------------------------------------------------------
  27. /* */
  28. bool debRecordParser::Jump(pkgCache::VerFileIterator const &Ver)
  29. {
  30. return Tags.Jump(Section,Ver->Offset);
  31. }
  32. bool debRecordParser::Jump(pkgCache::DescFileIterator const &Desc)
  33. {
  34. return Tags.Jump(Section,Desc->Offset);
  35. }
  36. /*}}}*/
  37. // RecordParser::FileName - Return the archive filename on the site /*{{{*/
  38. // ---------------------------------------------------------------------
  39. /* */
  40. string debRecordParser::FileName()
  41. {
  42. return Section.FindS("Filename");
  43. }
  44. /*}}}*/
  45. // RecordParser::Name - Return the package name /*{{{*/
  46. // ---------------------------------------------------------------------
  47. /* */
  48. string debRecordParser::Name()
  49. {
  50. return Section.FindS("Package");
  51. }
  52. /*}}}*/
  53. // RecordParser::Homepage - Return the package homepage /*{{{*/
  54. // ---------------------------------------------------------------------
  55. /* */
  56. string debRecordParser::Homepage()
  57. {
  58. return Section.FindS("Homepage");
  59. }
  60. /*}}}*/
  61. // RecordParser::MD5Hash - Return the archive hash /*{{{*/
  62. // ---------------------------------------------------------------------
  63. /* */
  64. string debRecordParser::MD5Hash()
  65. {
  66. return Section.FindS("MD5Sum");
  67. }
  68. /*}}}*/
  69. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  70. // ---------------------------------------------------------------------
  71. /* */
  72. string debRecordParser::SHA1Hash()
  73. {
  74. return Section.FindS("SHA1");
  75. }
  76. /*}}}*/
  77. // RecordParser::SHA1Hash - Return the archive hash /*{{{*/
  78. // ---------------------------------------------------------------------
  79. /* */
  80. string debRecordParser::SHA256Hash()
  81. {
  82. return Section.FindS("SHA256");
  83. }
  84. /*}}}*/
  85. // RecordParser::Maintainer - Return the maintainer email /*{{{*/
  86. // ---------------------------------------------------------------------
  87. /* */
  88. string debRecordParser::Maintainer()
  89. {
  90. return Section.FindS("Maintainer");
  91. }
  92. /*}}}*/
  93. // RecordParser::ShortDesc - Return a 1 line description /*{{{*/
  94. // ---------------------------------------------------------------------
  95. /* */
  96. string debRecordParser::ShortDesc()
  97. {
  98. string Res = LongDesc();
  99. string::size_type Pos = Res.find('\n');
  100. if (Pos == string::npos)
  101. return Res;
  102. return string(Res,0,Pos);
  103. }
  104. /*}}}*/
  105. // RecordParser::LongDesc - Return a longer description /*{{{*/
  106. // ---------------------------------------------------------------------
  107. /* */
  108. string debRecordParser::LongDesc()
  109. {
  110. string orig, dest;
  111. if (!Section.FindS("Description").empty())
  112. orig = Section.FindS("Description").c_str();
  113. else
  114. {
  115. vector<string> const lang = APT::Configuration::getLanguages();
  116. for (vector<string>::const_iterator l = lang.begin();
  117. orig.empty() && l != lang.end(); l++)
  118. orig = Section.FindS(string("Description-").append(*l).c_str());
  119. }
  120. char const * const codeset = nl_langinfo(CODESET);
  121. if (strcmp(codeset,"UTF-8") != 0) {
  122. UTF8ToCodeset(codeset, orig, &dest);
  123. orig = dest;
  124. }
  125. return orig;
  126. }
  127. /*}}}*/
  128. static const char *SourceVerSeparators = " ()";
  129. // RecordParser::SourcePkg - Return the source package name if any /*{{{*/
  130. // ---------------------------------------------------------------------
  131. /* */
  132. string debRecordParser::SourcePkg()
  133. {
  134. string Res = Section.FindS("Source");
  135. string::size_type Pos = Res.find_first_of(SourceVerSeparators);
  136. if (Pos == string::npos)
  137. return Res;
  138. return string(Res,0,Pos);
  139. }
  140. /*}}}*/
  141. // RecordParser::SourceVer - Return the source version number if present /*{{{*/
  142. // ---------------------------------------------------------------------
  143. /* */
  144. string debRecordParser::SourceVer()
  145. {
  146. string Pkg = Section.FindS("Source");
  147. string::size_type Pos = Pkg.find_first_of(SourceVerSeparators);
  148. if (Pos == string::npos)
  149. return "";
  150. string::size_type VerStart = Pkg.find_first_not_of(SourceVerSeparators, Pos);
  151. if(VerStart == string::npos)
  152. return "";
  153. string::size_type VerEnd = Pkg.find_first_of(SourceVerSeparators, VerStart);
  154. if(VerEnd == string::npos)
  155. // Corresponds to the case of, e.g., "foo (1.2" without a closing
  156. // paren. Be liberal and guess what it means.
  157. return string(Pkg, VerStart);
  158. else
  159. return string(Pkg, VerStart, VerEnd - VerStart);
  160. }
  161. /*}}}*/
  162. // RecordParser::GetRec - Return the whole record /*{{{*/
  163. // ---------------------------------------------------------------------
  164. /* */
  165. void debRecordParser::GetRec(const char *&Start,const char *&Stop)
  166. {
  167. Section.GetSection(Start,Stop);
  168. }
  169. /*}}}*/