Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: core/include/fpdfapi/fpdf_parser.h

Issue 1774753002: Split CPDF_SyntaxParser into its own named .cpp/.h files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Copyright 2016. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 7 #ifndef CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 8 #define CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
9 9
10 #include <map> 10 #include <map>
(...skipping 10 matching lines...) Expand all
21 class CPDF_DocPageData; 21 class CPDF_DocPageData;
22 class CPDF_DocRenderData; 22 class CPDF_DocRenderData;
23 class CPDF_Font; 23 class CPDF_Font;
24 class CPDF_FontEncoding; 24 class CPDF_FontEncoding;
25 class CPDF_IccProfile; 25 class CPDF_IccProfile;
26 class CPDF_Image; 26 class CPDF_Image;
27 class CPDF_Object; 27 class CPDF_Object;
28 class CPDF_Parser; 28 class CPDF_Parser;
29 class CPDF_Pattern; 29 class CPDF_Pattern;
30 class CPDF_StandardSecurityHandler; 30 class CPDF_StandardSecurityHandler;
31 class CPDF_SyntaxParser;
31 class IPDF_SecurityHandler; 32 class IPDF_SecurityHandler;
32 33
33 #define FPDFPERM_PRINT 0x0004 34 #define FPDFPERM_PRINT 0x0004
34 #define FPDFPERM_MODIFY 0x0008 35 #define FPDFPERM_MODIFY 0x0008
35 #define FPDFPERM_EXTRACT 0x0010 36 #define FPDFPERM_EXTRACT 0x0010
36 #define FPDFPERM_ANNOT_FORM 0x0020 37 #define FPDFPERM_ANNOT_FORM 0x0020
37 #define FPDFPERM_FILL_FORM 0x0100 38 #define FPDFPERM_FILL_FORM 0x0100
38 #define FPDFPERM_EXTRACT_ACCESS 0x0200 39 #define FPDFPERM_EXTRACT_ACCESS 0x0200
39 #define FPDFPERM_ASSEMBLE 0x0400 40 #define FPDFPERM_ASSEMBLE 0x0400
40 #define FPDFPERM_PRINT_HIGH 0x0800 41 #define FPDFPERM_PRINT_HIGH 0x0800
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 FX_DWORD GetCurPos() const { return m_dwCurPos; } 225 FX_DWORD GetCurPos() const { return m_dwCurPos; }
225 226
226 private: 227 private:
227 void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize); 228 void ParseWord(const uint8_t*& pStart, FX_DWORD& dwSize);
228 229
229 const uint8_t* m_pData; 230 const uint8_t* m_pData;
230 FX_DWORD m_dwSize; 231 FX_DWORD m_dwSize;
231 FX_DWORD m_dwCurPos; 232 FX_DWORD m_dwCurPos;
232 }; 233 };
233 234
234 class CPDF_SyntaxParser {
235 public:
236 CPDF_SyntaxParser();
237 ~CPDF_SyntaxParser();
238
239 void InitParser(IFX_FileRead* pFileAccess, FX_DWORD HeaderOffset);
240
241 FX_FILESIZE SavePos() const { return m_Pos; }
242 void RestorePos(FX_FILESIZE pos) { m_Pos = pos; }
243
244 CPDF_Object* GetObject(CPDF_IndirectObjectHolder* pObjList,
245 FX_DWORD objnum,
246 FX_DWORD gennum,
247 FX_BOOL bDecrypt);
248 CPDF_Object* GetObjectByStrict(CPDF_IndirectObjectHolder* pObjList,
249 FX_DWORD objnum,
250 FX_DWORD gennum);
251 CFX_ByteString GetKeyword();
252
253 void ToNextLine();
254 void ToNextWord();
255
256 FX_BOOL SearchWord(const CFX_ByteStringC& word,
257 FX_BOOL bWholeWord,
258 FX_BOOL bForward,
259 FX_FILESIZE limit);
260 int SearchMultiWord(const CFX_ByteStringC& words,
261 FX_BOOL bWholeWord,
262 FX_FILESIZE limit);
263 FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit);
264
265 void SetEncrypt(std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler);
266
267 FX_BOOL ReadBlock(uint8_t* pBuf, FX_DWORD size);
268 FX_BOOL GetCharAt(FX_FILESIZE pos, uint8_t& ch);
269 CFX_ByteString GetNextWord(bool* bIsNumber);
270
271 private:
272 friend class CPDF_Parser;
273 friend class CPDF_DataAvail;
274 friend class fpdf_parser_parser_ReadHexString_Test;
275
276 static const int kParserMaxRecursionDepth = 64;
277 static int s_CurrentRecursionDepth;
278
279 uint32_t GetDirectNum();
280
281 FX_BOOL GetNextChar(uint8_t& ch);
282 FX_BOOL GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch);
283 void GetNextWordInternal(bool* bIsNumber);
284 bool IsWholeWord(FX_FILESIZE startpos,
285 FX_FILESIZE limit,
286 const CFX_ByteStringC& tag,
287 FX_BOOL checkKeyword);
288
289 CFX_ByteString ReadString();
290 CFX_ByteString ReadHexString();
291 unsigned int ReadEOLMarkers(FX_FILESIZE pos);
292 CPDF_Stream* ReadStream(CPDF_Dictionary* pDict,
293 FX_DWORD objnum,
294 FX_DWORD gennum);
295
296 FX_FILESIZE m_Pos;
297 int m_MetadataObjnum;
298 IFX_FileRead* m_pFileAccess;
299 FX_DWORD m_HeaderOffset;
300 FX_FILESIZE m_FileLen;
301 uint8_t* m_pFileBuf;
302 FX_DWORD m_BufSize;
303 FX_FILESIZE m_BufOffset;
304 std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
305 uint8_t m_WordBuffer[257];
306 FX_DWORD m_WordSize;
307 };
308
309 class CPDF_Parser { 235 class CPDF_Parser {
310 public: 236 public:
311 enum Error { 237 enum Error {
312 SUCCESS = 0, 238 SUCCESS = 0,
313 FILE_ERROR, 239 FILE_ERROR,
314 FORMAT_ERROR, 240 FORMAT_ERROR,
315 PASSWORD_ERROR, 241 PASSWORD_ERROR,
316 HANDLER_ERROR 242 HANDLER_ERROR
317 }; 243 };
318 244
319 CPDF_Parser(); 245 CPDF_Parser();
320 ~CPDF_Parser(); 246 ~CPDF_Parser();
321 247
322 Error StartParse(IFX_FileRead* pFile); 248 Error StartParse(IFX_FileRead* pFile);
323 FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE); 249 FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE);
324 250
325 void SetPassword(const FX_CHAR* password) { m_Password = password; } 251 void SetPassword(const FX_CHAR* password) { m_Password = password; }
326 CFX_ByteString GetPassword() { return m_Password; } 252 CFX_ByteString GetPassword() { return m_Password; }
327
328 CPDF_CryptoHandler* GetCryptoHandler() {
329 return m_Syntax.m_pCryptoHandler.get();
330 }
331
332 CPDF_Dictionary* GetTrailer() const { return m_pTrailer; } 253 CPDF_Dictionary* GetTrailer() const { return m_pTrailer; }
333 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } 254 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; }
334 CPDF_Document* GetDocument() const { return m_pDocument; } 255 CPDF_Document* GetDocument() const { return m_pDocument; }
335 256
336 FX_DWORD GetRootObjNum(); 257 FX_DWORD GetRootObjNum();
337 FX_DWORD GetInfoObjNum(); 258 FX_DWORD GetInfoObjNum();
338 CPDF_Array* GetIDArray(); 259 CPDF_Array* GetIDArray();
339 260
340 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } 261 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; }
341 262
342 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList, 263 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList,
343 FX_DWORD objnum); 264 FX_DWORD objnum);
344 265
345 FX_DWORD GetLastObjNum() const; 266 FX_DWORD GetLastObjNum() const;
346 bool IsValidObjectNumber(FX_DWORD objnum) const; 267 bool IsValidObjectNumber(FX_DWORD objnum) const;
347 FX_FILESIZE GetObjectPositionOrZero(FX_DWORD objnum) const; 268 FX_FILESIZE GetObjectPositionOrZero(FX_DWORD objnum) const;
348 uint8_t GetObjectType(FX_DWORD objnum) const; 269 uint8_t GetObjectType(FX_DWORD objnum) const;
349 uint16_t GetObjectGenNum(FX_DWORD objnum) const; 270 uint16_t GetObjectGenNum(FX_DWORD objnum) const;
350 bool IsVersionUpdated() const { return m_bVersionUpdated; } 271 bool IsVersionUpdated() const { return m_bVersionUpdated; }
351 bool IsObjectFreeOrNull(FX_DWORD objnum) const; 272 bool IsObjectFreeOrNull(FX_DWORD objnum) const;
352 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm); 273 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm);
274 CPDF_CryptoHandler* GetCryptoHandler();
275 IFX_FileRead* GetFileAccess() const;
353 276
354 FX_FILESIZE GetObjectOffset(FX_DWORD objnum) const; 277 FX_FILESIZE GetObjectOffset(FX_DWORD objnum) const;
355 FX_FILESIZE GetObjectSize(FX_DWORD objnum) const; 278 FX_FILESIZE GetObjectSize(FX_DWORD objnum) const;
356 279
357 void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size); 280 void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size);
358 IFX_FileRead* GetFileAccess() const { return m_Syntax.m_pFileAccess; }
359 int GetFileVersion() const { return m_FileVersion; } 281 int GetFileVersion() const { return m_FileVersion; }
360 FX_BOOL IsXRefStream() const { return m_bXRefStream; } 282 FX_BOOL IsXRefStream() const { return m_bXRefStream; }
361 283
362 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, 284 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList,
363 FX_FILESIZE pos, 285 FX_FILESIZE pos,
364 FX_DWORD objnum); 286 FX_DWORD objnum);
365 287
366 CPDF_Object* ParseIndirectObjectAtByStrict( 288 CPDF_Object* ParseIndirectObjectAtByStrict(
367 CPDF_IndirectObjectHolder* pObjList, 289 CPDF_IndirectObjectHolder* pObjList,
368 FX_FILESIZE pos, 290 FX_FILESIZE pos,
(...skipping 26 matching lines...) Expand all
395 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); 317 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
396 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount); 318 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
397 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); 319 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);
398 Error LoadLinearizedMainXRefTable(); 320 Error LoadLinearizedMainXRefTable();
399 CPDF_StreamAcc* GetObjectStream(FX_DWORD number); 321 CPDF_StreamAcc* GetObjectStream(FX_DWORD number);
400 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset); 322 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset);
401 void SetEncryptDictionary(CPDF_Dictionary* pDict); 323 void SetEncryptDictionary(CPDF_Dictionary* pDict);
402 void ShrinkObjectMap(FX_DWORD size); 324 void ShrinkObjectMap(FX_DWORD size);
403 325
404 CPDF_Document* m_pDocument; 326 CPDF_Document* m_pDocument;
405 CPDF_SyntaxParser m_Syntax; 327 std::unique_ptr<CPDF_SyntaxParser> m_pSyntax;
406 bool m_bOwnFileRead; 328 bool m_bOwnFileRead;
407 int m_FileVersion; 329 int m_FileVersion;
408 CPDF_Dictionary* m_pTrailer; 330 CPDF_Dictionary* m_pTrailer;
409 CPDF_Dictionary* m_pEncryptDict; 331 CPDF_Dictionary* m_pEncryptDict;
410 FX_FILESIZE m_LastXRefOffset; 332 FX_FILESIZE m_LastXRefOffset;
411 FX_BOOL m_bXRefStream; 333 FX_BOOL m_bXRefStream;
412 std::unique_ptr<IPDF_SecurityHandler> m_pSecurityHandler; 334 std::unique_ptr<IPDF_SecurityHandler> m_pSecurityHandler;
413 CFX_ByteString m_bsRecipient; 335 CFX_ByteString m_bsRecipient;
414 CFX_ByteString m_FilePath; 336 CFX_ByteString m_FilePath;
415 CFX_ByteString m_Password; 337 CFX_ByteString m_Password;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 FX_DWORD src_size, 772 FX_DWORD src_size,
851 const CPDF_Dictionary* pDict, 773 const CPDF_Dictionary* pDict,
852 uint8_t*& dest_buf, 774 uint8_t*& dest_buf,
853 FX_DWORD& dest_size, 775 FX_DWORD& dest_size,
854 CFX_ByteString& ImageEncoding, 776 CFX_ByteString& ImageEncoding,
855 CPDF_Dictionary*& pImageParms, 777 CPDF_Dictionary*& pImageParms,
856 FX_DWORD estimated_size, 778 FX_DWORD estimated_size,
857 FX_BOOL bImageAcc); 779 FX_BOOL bImageAcc);
858 780
859 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_ 781 #endif // CORE_INCLUDE_FPDFAPI_FPDF_PARSER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | core/src/fpdfapi/fpdf_parser/cpdf_syntax_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698