debrecords.cc 5.3 KB

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