OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
8 #define CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 8 #define CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "core/fxcrt/fx_basic.h" | 15 #include "core/fxcrt/fx_basic.h" |
16 | 16 |
17 class CPDF_Array; | 17 class CPDF_Array; |
18 class CPDF_CryptoHandler; | 18 class CPDF_CryptoHandler; |
19 class CPDF_Dictionary; | 19 class CPDF_Dictionary; |
20 class CPDF_Document; | 20 class CPDF_Document; |
21 class CPDF_IndirectObjectHolder; | 21 class CPDF_IndirectObjectHolder; |
22 class CPDF_Object; | 22 class CPDF_Object; |
23 class CPDF_SecurityHandler; | 23 class CPDF_SecurityHandler; |
24 class CPDF_StreamAcc; | 24 class CPDF_StreamAcc; |
25 class CPDF_SyntaxParser; | 25 class CPDF_SyntaxParser; |
26 class IFX_FileRead; | 26 class IFX_SeekableReadStream; |
27 | 27 |
28 class CPDF_Parser { | 28 class CPDF_Parser { |
29 public: | 29 public: |
30 enum Error { | 30 enum Error { |
31 SUCCESS = 0, | 31 SUCCESS = 0, |
32 FILE_ERROR, | 32 FILE_ERROR, |
33 FORMAT_ERROR, | 33 FORMAT_ERROR, |
34 PASSWORD_ERROR, | 34 PASSWORD_ERROR, |
35 HANDLER_ERROR | 35 HANDLER_ERROR |
36 }; | 36 }; |
37 | 37 |
38 // A limit on the maximum object number in the xref table. Theoretical limits | 38 // A limit on the maximum object number in the xref table. Theoretical limits |
39 // are higher, but this may be large enough in practice. | 39 // are higher, but this may be large enough in practice. |
40 static const uint32_t kMaxObjectNumber = 1048576; | 40 static const uint32_t kMaxObjectNumber = 1048576; |
41 | 41 |
42 CPDF_Parser(); | 42 CPDF_Parser(); |
43 ~CPDF_Parser(); | 43 ~CPDF_Parser(); |
44 | 44 |
45 Error StartParse(IFX_FileRead* pFile, CPDF_Document* pDocument); | 45 Error StartParse(IFX_SeekableReadStream* pFile, CPDF_Document* pDocument); |
46 Error StartLinearizedParse(IFX_FileRead* pFile, CPDF_Document* pDocument); | 46 Error StartLinearizedParse(IFX_SeekableReadStream* pFile, |
| 47 CPDF_Document* pDocument); |
47 | 48 |
48 void SetPassword(const FX_CHAR* password) { m_Password = password; } | 49 void SetPassword(const FX_CHAR* password) { m_Password = password; } |
49 CFX_ByteString GetPassword() { return m_Password; } | 50 CFX_ByteString GetPassword() { return m_Password; } |
50 CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } | 51 CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } |
51 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } | 52 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } |
52 | 53 |
53 uint32_t GetPermissions() const; | 54 uint32_t GetPermissions() const; |
54 uint32_t GetRootObjNum(); | 55 uint32_t GetRootObjNum(); |
55 uint32_t GetInfoObjNum(); | 56 uint32_t GetInfoObjNum(); |
56 CPDF_Array* GetIDArray(); | 57 CPDF_Array* GetIDArray(); |
57 | 58 |
58 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } | 59 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } |
59 | 60 |
60 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList, | 61 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList, |
61 uint32_t objnum); | 62 uint32_t objnum); |
62 | 63 |
63 uint32_t GetLastObjNum() const; | 64 uint32_t GetLastObjNum() const; |
64 bool IsValidObjectNumber(uint32_t objnum) const; | 65 bool IsValidObjectNumber(uint32_t objnum) const; |
65 FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; | 66 FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; |
66 uint8_t GetObjectType(uint32_t objnum) const; | 67 uint8_t GetObjectType(uint32_t objnum) const; |
67 uint16_t GetObjectGenNum(uint32_t objnum) const; | 68 uint16_t GetObjectGenNum(uint32_t objnum) const; |
68 bool IsVersionUpdated() const { return m_bVersionUpdated; } | 69 bool IsVersionUpdated() const { return m_bVersionUpdated; } |
69 bool IsObjectFreeOrNull(uint32_t objnum) const; | 70 bool IsObjectFreeOrNull(uint32_t objnum) const; |
70 CPDF_CryptoHandler* GetCryptoHandler(); | 71 CPDF_CryptoHandler* GetCryptoHandler(); |
71 IFX_FileRead* GetFileAccess() const; | 72 IFX_SeekableReadStream* GetFileAccess() const; |
72 | 73 |
73 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; | 74 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; |
74 FX_FILESIZE GetObjectSize(uint32_t objnum) const; | 75 FX_FILESIZE GetObjectSize(uint32_t objnum) const; |
75 | 76 |
76 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); | 77 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); |
77 int GetFileVersion() const { return m_FileVersion; } | 78 int GetFileVersion() const { return m_FileVersion; } |
78 FX_BOOL IsXRefStream() const { return m_bXRefStream; } | 79 FX_BOOL IsXRefStream() const { return m_bXRefStream; } |
79 | 80 |
80 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, | 81 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, |
81 FX_FILESIZE pos, | 82 FX_FILESIZE pos, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); | 130 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); |
130 FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef); | 131 FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef); |
131 CPDF_Dictionary* LoadTrailerV4(); | 132 CPDF_Dictionary* LoadTrailerV4(); |
132 Error SetEncryptHandler(); | 133 Error SetEncryptHandler(); |
133 void ReleaseEncryptHandler(); | 134 void ReleaseEncryptHandler(); |
134 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 135 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
135 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 136 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
136 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); | 137 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); |
137 Error LoadLinearizedMainXRefTable(); | 138 Error LoadLinearizedMainXRefTable(); |
138 CPDF_StreamAcc* GetObjectStream(uint32_t number); | 139 CPDF_StreamAcc* GetObjectStream(uint32_t number); |
139 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, uint32_t offset); | 140 FX_BOOL IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, |
| 141 uint32_t offset); |
140 void SetEncryptDictionary(CPDF_Dictionary* pDict); | 142 void SetEncryptDictionary(CPDF_Dictionary* pDict); |
141 void ShrinkObjectMap(uint32_t size); | 143 void ShrinkObjectMap(uint32_t size); |
142 // A simple check whether the cross reference table matches with | 144 // A simple check whether the cross reference table matches with |
143 // the objects. | 145 // the objects. |
144 bool VerifyCrossRefV4(); | 146 bool VerifyCrossRefV4(); |
145 | 147 |
146 CPDF_Document* m_pDocument; // not owned | 148 CPDF_Document* m_pDocument; // not owned |
147 bool m_bHasParsed; | 149 bool m_bHasParsed; |
148 bool m_bOwnFileRead; | 150 bool m_bOwnFileRead; |
149 int m_FileVersion; | 151 int m_FileVersion; |
(...skipping 19 matching lines...) Expand all Loading... |
169 | 171 |
170 // Mapping of streams to their object caches. This is valid as long as the | 172 // Mapping of streams to their object caches. This is valid as long as the |
171 // streams in |m_ObjectStreamMap| are valid. | 173 // streams in |m_ObjectStreamMap| are valid. |
172 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; | 174 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; |
173 | 175 |
174 // All indirect object numbers that are being parsed. | 176 // All indirect object numbers that are being parsed. |
175 std::set<uint32_t> m_ParsingObjNums; | 177 std::set<uint32_t> m_ParsingObjNums; |
176 }; | 178 }; |
177 | 179 |
178 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 180 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
OLD | NEW |