~ubuntu-branches/ubuntu/saucy/libwpd/saucy

« back to all changes in this revision

Viewing changes to src/lib/WPDocument.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20111129233113-xdtwca9h0y6wdxst
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2003 William Lachance (wrlach@gmail.com)
3
4
 * Copyright (C) 2003-2004 Marc Maurer (uwog@uwog.net)
86
87
                {
87
88
                        switch (header->getFileType())
88
89
                        {
89
 
                                case 0x0a: // WordPerfect File
90
 
                                        switch (header->getMajorVersion())
91
 
                                        {
92
 
                                                case 0x00: // WP5
93
 
                                                case 0x02: // WP6+
94
 
                                                        confidence = WPD_CONFIDENCE_EXCELLENT;
95
 
                                                        break;
96
 
                                                default:
97
 
                                                        // unhandled file format
98
 
                                                        confidence = WPD_CONFIDENCE_NONE;
99
 
                                                        break;
100
 
                                        }
101
 
                                        break;
102
 
                                case 0x2c: // WP Mac File
103
 
                                        switch (header->getMajorVersion())
104
 
                                        {
105
 
                                                case 0x02: // WP Mac 2.x
106
 
                                                case 0x03: // WP Mac 3.0-3.5
107
 
                                                case 0x04: // WP Mac 3.5e
108
 
                                                        confidence = WPD_CONFIDENCE_EXCELLENT;
109
 
                                                        break;
110
 
                                                default:
111
 
                                                        // unhandled file format
112
 
                                                        confidence = WPD_CONFIDENCE_NONE;
113
 
                                                        break;
114
 
                                        }
115
 
                                        break;
116
 
                                default:
117
 
                                        // unhandled file type
118
 
                                        confidence = WPD_CONFIDENCE_NONE;
119
 
                                        break;
 
90
                        case 0x0a: // WordPerfect File
 
91
                                switch (header->getMajorVersion())
 
92
                                {
 
93
                                case 0x00: // WP5
 
94
                                case 0x02: // WP6+
 
95
                                        confidence = WPD_CONFIDENCE_EXCELLENT;
 
96
                                        break;
 
97
                                default:
 
98
                                        // unhandled file format
 
99
                                        confidence = WPD_CONFIDENCE_NONE;
 
100
                                        break;
 
101
                                }
 
102
                                break;
 
103
                        case 0x2c: // WP Mac File
 
104
                                switch (header->getMajorVersion())
 
105
                                {
 
106
                                case 0x02: // WP Mac 2.x
 
107
                                case 0x03: // WP Mac 3.0-3.5
 
108
                                case 0x04: // WP Mac 3.5e
 
109
                                        confidence = WPD_CONFIDENCE_EXCELLENT;
 
110
                                        break;
 
111
                                default:
 
112
                                        // unhandled file format
 
113
                                        confidence = WPD_CONFIDENCE_NONE;
 
114
                                        break;
 
115
                                }
 
116
                                break;
 
117
                        default:
 
118
                                // unhandled file type
 
119
                                confidence = WPD_CONFIDENCE_NONE;
 
120
                                break;
120
121
                        }
121
122
                        if (header->getDocumentEncryption())
122
123
                        {
129
130
                }
130
131
                else
131
132
                        confidence = WP1Heuristics::isWP1FileFormat(input, 0);
132
 
                        if (confidence != WPD_CONFIDENCE_EXCELLENT && confidence != WPD_CONFIDENCE_SUPPORTED_ENCRYPTION)
133
 
                                confidence = LIBWPD_MAX(confidence, WP42Heuristics::isWP42FileFormat(input, 0));
134
 
                        
 
133
                if (confidence != WPD_CONFIDENCE_EXCELLENT && confidence != WPD_CONFIDENCE_SUPPORTED_ENCRYPTION)
 
134
                        confidence = LIBWPD_MAX(confidence, WP42Heuristics::isWP42FileFormat(input, 0));
 
135
 
135
136
 
136
137
                // dispose of the reference to the ole input stream, if we allocated one
137
138
                if (document && isDocumentOLE)
215
216
                }
216
217
                else
217
218
                        passwordMatch = WP1Heuristics::verifyPassword(input, password);
218
 
                        if (passwordMatch == WPD_PASSWORD_MATCH_NONE)
219
 
                                passwordMatch = LIBWPD_MAX(passwordMatch, WP42Heuristics::verifyPassword(input, password));
220
 
                        
 
219
                if (passwordMatch == WPD_PASSWORD_MATCH_NONE)
 
220
                        passwordMatch = LIBWPD_MAX(passwordMatch, WP42Heuristics::verifyPassword(input, password));
 
221
 
221
222
 
222
223
                // dispose of the reference to the ole input stream, if we allocated one
223
224
                if (document && isDocumentOLE)
262
263
{
263
264
        if (!input)
264
265
                return WPD_FILE_ACCESS_ERROR;
265
 
                
 
266
 
266
267
        if (password && verifyPassword(input, password) != WPD_PASSWORD_MATCH_OK)
267
268
                return WPD_PASSWORD_MISSMATCH_ERROR;
268
 
                
 
269
 
269
270
        input->seek(0, WPX_SEEK_SET);
270
271
 
271
272
        WPXParser *parser = 0;
299
300
                {
300
301
                        switch (header->getFileType())
301
302
                        {
302
 
                                case 0x0a: // WordPerfect File
303
 
                                        switch (header->getMajorVersion())
304
 
                                        {
305
 
                                                case 0x00: // WP5
306
 
                                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP5 parser.\n"));
307
 
                                                        if (encryption)
308
 
                                                        {
309
 
                                                                delete encryption;
310
 
                                                                encryption = new WPXEncryption(password, 16);
311
 
                                                        }
312
 
                                                        parser = new WP5Parser(document, header, encryption);
313
 
                                                        parser->parse(documentInterface);
314
 
                                                        break;
315
 
                                                case 0x02: // WP6
316
 
                                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP6 parser.\n"));
317
 
                                                        if (encryption)
318
 
                                                        {
319
 
                                                                delete encryption;
320
 
                                                                encryption = 0;
321
 
                                                                throw UnsupportedEncryptionException();
322
 
                                                        }
323
 
                                                        parser = new WP6Parser(document, header, encryption);
324
 
                                                        parser->parse(documentInterface);
325
 
                                                        break;
326
 
                                                default:
327
 
                                                        // unhandled file format
328
 
                                                        WPD_DEBUG_MSG(("WordPerfect: Unsupported file format.\n"));
329
 
                                                        break;
330
 
                                        }
331
 
                                        break;
332
 
                                case 0x2c: // WP Mac File
333
 
                                        switch (header->getMajorVersion())
334
 
                                        {
335
 
                                                case 0x02: // WP Mac 2.x
336
 
                                                case 0x03: // WP Mac 3.0-3.5
337
 
                                                case 0x04: // WP Mac 3.5e
338
 
                                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP3 parser.\n"));
339
 
                                                        if (encryption)
340
 
                                                        {
341
 
                                                                delete encryption;
342
 
                                                                encryption = new WPXEncryption(password, header->getDocumentOffset());
343
 
                                                        }
344
 
                                                        parser = new WP3Parser(document, header, encryption);
345
 
                                                        parser->parse(documentInterface);
346
 
                                                        break;
347
 
                                                default:
348
 
                                                        // unhandled file format
349
 
                                                        WPD_DEBUG_MSG(("WordPerfect: Unsupported file format.\n"));
350
 
                                                        break;
351
 
                                        }
352
 
                                        break;
353
 
                                default:
354
 
                                        // unhandled file format
355
 
                                        WPD_DEBUG_MSG(("WordPerfect: Unsupported file type.\n"));
356
 
                                        break;
 
303
                        case 0x0a: // WordPerfect File
 
304
                                switch (header->getMajorVersion())
 
305
                                {
 
306
                                case 0x00: // WP5
 
307
                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP5 parser.\n"));
 
308
                                        if (encryption)
 
309
                                        {
 
310
                                                delete encryption;
 
311
                                                encryption = new WPXEncryption(password, 16);
 
312
                                        }
 
313
                                        parser = new WP5Parser(document, header, encryption);
 
314
                                        parser->parse(documentInterface);
 
315
                                        break;
 
316
                                case 0x02: // WP6
 
317
                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP6 parser.\n"));
 
318
                                        if (encryption)
 
319
                                        {
 
320
                                                delete encryption;
 
321
                                                encryption = 0;
 
322
                                                throw UnsupportedEncryptionException();
 
323
                                        }
 
324
                                        parser = new WP6Parser(document, header, encryption);
 
325
                                        parser->parse(documentInterface);
 
326
                                        break;
 
327
                                default:
 
328
                                        // unhandled file format
 
329
                                        WPD_DEBUG_MSG(("WordPerfect: Unsupported file format.\n"));
 
330
                                        break;
 
331
                                }
 
332
                                break;
 
333
                        case 0x2c: // WP Mac File
 
334
                                switch (header->getMajorVersion())
 
335
                                {
 
336
                                case 0x02: // WP Mac 2.x
 
337
                                case 0x03: // WP Mac 3.0-3.5
 
338
                                case 0x04: // WP Mac 3.5e
 
339
                                        WPD_DEBUG_MSG(("WordPerfect: Using the WP3 parser.\n"));
 
340
                                        if (encryption)
 
341
                                        {
 
342
                                                delete encryption;
 
343
                                                encryption = new WPXEncryption(password, header->getDocumentOffset());
 
344
                                        }
 
345
                                        parser = new WP3Parser(document, header, encryption);
 
346
                                        parser->parse(documentInterface);
 
347
                                        break;
 
348
                                default:
 
349
                                        // unhandled file format
 
350
                                        WPD_DEBUG_MSG(("WordPerfect: Unsupported file format.\n"));
 
351
                                        break;
 
352
                                }
 
353
                                break;
 
354
                        default:
 
355
                                // unhandled file format
 
356
                                WPD_DEBUG_MSG(("WordPerfect: Unsupported file type.\n"));
 
357
                                break;
357
358
                        }
358
359
                        DELETEP(parser);
359
360
                        DELETEP(header);
415
416
        catch (...)
416
417
        {
417
418
                WPD_DEBUG_MSG(("Unknown Exception trapped\n"));
418
 
                error = WPD_UNKNOWN_ERROR; 
 
419
                error = WPD_UNKNOWN_ERROR;
419
420
        }
420
421
 
421
422
        DELETEP(parser);
428
429
WPDResult WPDocument::parseSubDocument(WPXInputStream *input, WPXDocumentInterface *documentInterface, WPDFileFormat fileFormat)
429
430
{
430
431
        WPXParser *parser = 0;
431
 
        
 
432
 
432
433
        WPDResult error = WPD_OK;
433
434
 
434
435
        try
435
436
        {
436
 
                
 
437
 
437
438
                switch (fileFormat)
438
439
                {
439
440
                case WPD_FILE_FORMAT_WP6:
456
457
                        DELETEP(parser);
457
458
                        return WPD_UNKNOWN_ERROR;
458
459
                }
459
 
                
 
460
 
460
461
                if (parser)
461
462
                        parser->parseSubDocument(documentInterface);
462
463
        }
478
479
        catch (...)
479
480
        {
480
481
                WPD_DEBUG_MSG(("Unknown Exception trapped\n"));
481
 
                error = WPD_UNKNOWN_ERROR; 
 
482
                error = WPD_UNKNOWN_ERROR;
482
483
        }
483
484
        DELETEP(parser);
484
485
        return error;
485
486
}
 
487
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */