p3dMultifileReader.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Filename: p3dMultifileReader.h
  2. // Created by: drose (15Jun09)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef P3DMULTIFILEREADER_H
  15. #define P3DMULTIFILEREADER_H
  16. #include "p3d_plugin_common.h"
  17. #include "p3dInstanceManager.h" // for openssl
  18. #include "p3dPackage.h"
  19. ////////////////////////////////////////////////////////////////////
  20. // Class : P3DMultifileReader
  21. // Description : A way-simple implementation of Panda's multifile
  22. // reader. See panda/src/express/multifile.cxx for a
  23. // full description of the binary format. This
  24. // implementation doesn't support per-subfile
  25. // compression or encryption.
  26. ////////////////////////////////////////////////////////////////////
  27. class P3DMultifileReader {
  28. public:
  29. P3DMultifileReader();
  30. bool open_read(const string &pathname, const int &offset = 0);
  31. inline bool is_open() const;
  32. void close();
  33. bool extract_all(const string &to_dir, P3DPackage *package,
  34. P3DPackage::InstallStepThreaded *step);
  35. bool extract_one(ostream &out, const string &filename);
  36. class CertRecord {
  37. public:
  38. inline CertRecord(X509 *cert);
  39. inline CertRecord(const CertRecord &copy);
  40. inline ~CertRecord();
  41. X509 *_cert;
  42. };
  43. typedef vector<CertRecord> CertChain;
  44. int get_num_signatures() const;
  45. const CertChain &get_signature(int n) const;
  46. private:
  47. class Subfile;
  48. bool read_header(const string &pathname);
  49. bool read_index();
  50. bool extract_subfile(ostream &out, const Subfile &s);
  51. void check_signatures();
  52. inline unsigned int read_uint16();
  53. inline unsigned int read_uint32();
  54. enum SubfileFlags {
  55. SF_compressed = 0x0008,
  56. SF_encrypted = 0x0010,
  57. SF_signature = 0x0020,
  58. };
  59. class Subfile {
  60. public:
  61. inline size_t get_last_byte_pos() const;
  62. string _filename;
  63. size_t _index_start;
  64. size_t _index_length;
  65. size_t _data_start;
  66. size_t _data_length;
  67. size_t _timestamp;
  68. };
  69. ifstream _in;
  70. bool _is_open;
  71. int _read_offset;
  72. typedef vector<Subfile> Subfiles;
  73. Subfiles _subfiles;
  74. Subfiles _cert_special;
  75. size_t _last_data_byte;
  76. typedef vector<CertChain> Certificates;
  77. Certificates _signatures;
  78. static const char _header[];
  79. static const size_t _header_size;
  80. static const int _current_major_ver;
  81. static const int _current_minor_ver;
  82. };
  83. #include "p3dMultifileReader.I"
  84. #endif