diff options
author | David Tardon <dtardon@redhat.com> | 2013-12-07 21:14:54 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-12-07 22:38:56 +0100 |
commit | b23561fd104a19146f3140fd3955a9d052fc7c0d (patch) | |
tree | 1fd42415a26f3cc6cabe947ea06e8d774384558d | |
parent | 191fe41ee330492dee54a71e27a2d92ad5231dda (diff) |
astyle
-rw-r--r-- | inc/libsdw/SDWDocument.h | 6 | ||||
-rw-r--r-- | src/conv/html/sdw2html.cpp | 134 | ||||
-rw-r--r-- | src/conv/raw/sdw2raw.cpp | 130 | ||||
-rw-r--r-- | src/conv/text/sdw2text.cpp | 142 | ||||
-rw-r--r-- | src/lib/SDWDocument.cpp | 58 | ||||
-rw-r--r-- | src/lib/SDWEncryption.cpp | 18 | ||||
-rw-r--r-- | src/lib/SDWEncryption.h | 21 | ||||
-rw-r--r-- | src/lib/SDWHeader.cpp | 106 | ||||
-rw-r--r-- | src/lib/SDWHeader.h | 48 | ||||
-rw-r--r-- | src/lib/SDWParser.cpp | 6 | ||||
-rw-r--r-- | src/lib/SDWParser.h | 40 | ||||
-rw-r--r-- | src/lib/libsdw_internal.cpp | 82 | ||||
-rw-r--r-- | src/lib/libsdw_internal.h | 8 |
13 files changed, 400 insertions, 399 deletions
diff --git a/inc/libsdw/SDWDocument.h b/inc/libsdw/SDWDocument.h index 5d5614f..dc327c1 100644 --- a/inc/libsdw/SDWDocument.h +++ b/inc/libsdw/SDWDocument.h @@ -44,9 +44,9 @@ StarWriter documents. class SDWDocument { public: - static SDWConfidence isFileFormatSupported(librevenge::RVNGInputStream *input, const char *password); - static bool verifyPassword(librevenge::RVNGInputStream *input, const char *password); - static bool parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *documentInterface, const char *password); + static SDWConfidence isFileFormatSupported(librevenge::RVNGInputStream *input, const char *password); + static bool verifyPassword(librevenge::RVNGInputStream *input, const char *password); + static bool parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *documentInterface, const char *password); }; } // namespace libsdw diff --git a/src/conv/html/sdw2html.cpp b/src/conv/html/sdw2html.cpp index 0be8e80..84089b4 100644 --- a/src/conv/html/sdw2html.cpp +++ b/src/conv/html/sdw2html.cpp @@ -39,19 +39,19 @@ namespace int printUsage() { - printf("Usage: sdw2html [OPTION] <StarOffice Document>\n"); - printf("\n"); - printf("Options:\n"); - printf("--help Shows this help message\n"); - printf("--password <password> Try to decrypt password protected document\n"); - printf("--version Output sdw2html version \n"); - return -1; + printf("Usage: sdw2html [OPTION] <StarOffice Document>\n"); + printf("\n"); + printf("Options:\n"); + printf("--help Shows this help message\n"); + printf("--password <password> Try to decrypt password protected document\n"); + printf("--version Output sdw2html version \n"); + return -1; } int printVersion() { - printf("sdw2html %s\n", VERSION); - return 0; + printf("sdw2html %s\n", VERSION); + return 0; } } // anonymous namespace @@ -60,64 +60,64 @@ using namespace libsdw; int main(int argc, char *argv[]) { - if (argc < 2) - return printUsage(); - - char *file = 0; - char *password = 0; - - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "--password")) - { - if (i < argc - 1) - password = argv[++i]; - } - else if (!strncmp(argv[i], "--password=", 11)) - password = &argv[i][11]; - else if (!strcmp(argv[i], "--version")) - return printVersion(); - else if (!file && strncmp(argv[i], "--", 2)) - file = argv[i]; - else - return printUsage(); - } - - if (!file) - return printUsage(); - - librevenge::RVNGFileStream input(file); - - SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); - if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) - { - fprintf(stderr, "ERROR: Unsupported file format!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) - { - fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) - { - fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); - return 1; - } - - librevenge::RVNGString output; - librevenge::RVNGHTMLTextGenerator documentGenerator(output); - if (!SDWDocument::parse(&input, &documentGenerator, password)) - return 1; - - if (output.empty()) - return 1; - - printf("%s", output.cstr()); - - return 0; + if (argc < 2) + return printUsage(); + + char *file = 0; + char *password = 0; + + for (int i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "--password")) + { + if (i < argc - 1) + password = argv[++i]; + } + else if (!strncmp(argv[i], "--password=", 11)) + password = &argv[i][11]; + else if (!strcmp(argv[i], "--version")) + return printVersion(); + else if (!file && strncmp(argv[i], "--", 2)) + file = argv[i]; + else + return printUsage(); + } + + if (!file) + return printUsage(); + + librevenge::RVNGFileStream input(file); + + SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); + if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) + { + fprintf(stderr, "ERROR: Unsupported file format!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) + { + fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) + { + fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); + return 1; + } + + librevenge::RVNGString output; + librevenge::RVNGHTMLTextGenerator documentGenerator(output); + if (!SDWDocument::parse(&input, &documentGenerator, password)) + return 1; + + if (output.empty()) + return 1; + + printf("%s", output.cstr()); + + return 0; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/conv/raw/sdw2raw.cpp b/src/conv/raw/sdw2raw.cpp index 51e988b..52eacb4 100644 --- a/src/conv/raw/sdw2raw.cpp +++ b/src/conv/raw/sdw2raw.cpp @@ -39,20 +39,20 @@ namespace int printUsage() { - printf("Usage: sdw2raw [OPTION] <StarOffice Document>\n"); - printf("\n"); - printf("Options:\n"); - printf("--callgraph Display the call graph nesting level\n"); - printf("--help Shows this help message\n"); - printf("--password <password> Try to decrypt password protected document\n"); - printf("--version Output sdw2raw version \n"); - return -1; + printf("Usage: sdw2raw [OPTION] <StarOffice Document>\n"); + printf("\n"); + printf("Options:\n"); + printf("--callgraph Display the call graph nesting level\n"); + printf("--help Shows this help message\n"); + printf("--password <password> Try to decrypt password protected document\n"); + printf("--version Output sdw2raw version \n"); + return -1; } int printVersion() { - printf("sdw2raw %s\n", VERSION); - return 0; + printf("sdw2raw %s\n", VERSION); + return 0; } } // anonymous namespace @@ -61,60 +61,60 @@ using namespace libsdw; int main(int argc, char *argv[]) { - bool printIndentLevel = false; - char *file = 0; - char *password = 0; - - if (argc < 2) - return printUsage(); - - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "--password")) - { - if (i < argc - 1) - password = argv[++i]; - } - else if (!strncmp(argv[i], "--password=", 11)) - password = &argv[i][11]; - else if (!strcmp(argv[i], "--callgraph")) - printIndentLevel = true; - else if (!strcmp(argv[i], "--version")) - return printVersion(); - else if (!file && strncmp(argv[i], "--", 2)) - file = argv[i]; - else - return printUsage(); - } - - if (!file) - return printUsage(); - - librevenge::RVNGFileStream input(file); - - SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); - if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) - { - fprintf(stderr, "ERROR: Unsupported file format!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) - { - fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) - { - fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); - return 1; - } - - librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel); - if (!SDWDocument::parse(&input, &documentGenerator, password)) - return 1; - - return 0; + bool printIndentLevel = false; + char *file = 0; + char *password = 0; + + if (argc < 2) + return printUsage(); + + for (int i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "--password")) + { + if (i < argc - 1) + password = argv[++i]; + } + else if (!strncmp(argv[i], "--password=", 11)) + password = &argv[i][11]; + else if (!strcmp(argv[i], "--callgraph")) + printIndentLevel = true; + else if (!strcmp(argv[i], "--version")) + return printVersion(); + else if (!file && strncmp(argv[i], "--", 2)) + file = argv[i]; + else + return printUsage(); + } + + if (!file) + return printUsage(); + + librevenge::RVNGFileStream input(file); + + SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); + if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) + { + fprintf(stderr, "ERROR: Unsupported file format!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) + { + fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) + { + fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); + return 1; + } + + librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel); + if (!SDWDocument::parse(&input, &documentGenerator, password)) + return 1; + + return 0; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/conv/text/sdw2text.cpp b/src/conv/text/sdw2text.cpp index f7b45b7..49cf0f5 100644 --- a/src/conv/text/sdw2text.cpp +++ b/src/conv/text/sdw2text.cpp @@ -39,20 +39,20 @@ namespace int printUsage() { - printf("Usage: sdw2text [OPTION] <StarOffice Document>\n"); - printf("\n"); - printf("Options:\n"); - printf("--info Display document metadata instead of the text\n"); - printf("--help Shows this help message\n"); - printf("--password <password> Try to decrypt password protected document\n"); - printf("--version Output sdw2text version\n"); - return -1; + printf("Usage: sdw2text [OPTION] <StarOffice Document>\n"); + printf("\n"); + printf("Options:\n"); + printf("--info Display document metadata instead of the text\n"); + printf("--help Shows this help message\n"); + printf("--password <password> Try to decrypt password protected document\n"); + printf("--version Output sdw2text version\n"); + return -1; } int printVersion() { - printf("sdw2text %s\n", VERSION); - return 0; + printf("sdw2text %s\n", VERSION); + return 0; } } // anonymous namespace @@ -61,66 +61,66 @@ using namespace libsdw; int main(int argc, char *argv[]) { - if (argc < 2) - return printUsage(); - - char *szInputFile = 0; - bool isInfo = false; - char *password = 0; - - for (int i = 1; i < argc; i++) - { - if (!strcmp(argv[i], "--password")) - { - if (i < argc - 1) - password = argv[++i]; - } - else if (!strncmp(argv[i], "--password=", 11)) - password = &argv[i][11]; - else if (!strcmp(argv[i], "--info")) - isInfo = true; - else if (!strcmp(argv[i], "--version")) - return printVersion(); - else if (!szInputFile && strncmp(argv[i], "--", 2)) - szInputFile = argv[i]; - else - return printUsage(); - } - - if (!szInputFile) - return printUsage(); - - librevenge::RVNGFileStream input(szInputFile); - - SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); - if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) - { - fprintf(stderr, "ERROR: Unsupported file format!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) - { - fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); - return 1; - } - - if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) - { - fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); - return 1; - } - - librevenge::RVNGString output; - librevenge::RVNGTextTextGenerator documentGenerator(output, isInfo); - if (!SDWDocument::parse(&input, &documentGenerator, password)) - return 1; - - if (output.empty()) - return 1; - - printf("%s", output.cstr()); - - return 0; + if (argc < 2) + return printUsage(); + + char *szInputFile = 0; + bool isInfo = false; + char *password = 0; + + for (int i = 1; i < argc; i++) + { + if (!strcmp(argv[i], "--password")) + { + if (i < argc - 1) + password = argv[++i]; + } + else if (!strncmp(argv[i], "--password=", 11)) + password = &argv[i][11]; + else if (!strcmp(argv[i], "--info")) + isInfo = true; + else if (!strcmp(argv[i], "--version")) + return printVersion(); + else if (!szInputFile && strncmp(argv[i], "--", 2)) + szInputFile = argv[i]; + else + return printUsage(); + } + + if (!szInputFile) + return printUsage(); + + librevenge::RVNGFileStream input(szInputFile); + + SDWConfidence confidence = SDWDocument::isFileFormatSupported(&input, password); + if (confidence != SDW_CONFIDENCE_EXCELLENT && confidence != SDW_CONFIDENCE_ENCRYPTION) + { + fprintf(stderr, "ERROR: Unsupported file format!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && !password) + { + fprintf(stderr, "ERROR: File is password protected! Use \"--password\" option!\n"); + return 1; + } + + if (confidence == SDW_CONFIDENCE_ENCRYPTION && password && (!SDWDocument::verifyPassword(&input, password))) + { + fprintf(stderr, "ERROR: The password does not match, or document is not encrypted!\n"); + return 1; + } + + librevenge::RVNGString output; + librevenge::RVNGTextTextGenerator documentGenerator(output, isInfo); + if (!SDWDocument::parse(&input, &documentGenerator, password)) + return 1; + + if (output.empty()) + return 1; + + printf("%s", output.cstr()); + + return 0; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/SDWDocument.cpp b/src/lib/SDWDocument.cpp index 911583f..f968343 100644 --- a/src/lib/SDWDocument.cpp +++ b/src/lib/SDWDocument.cpp @@ -51,22 +51,22 @@ the input stream can be parsed */ libsdw::SDWConfidence libsdw::SDWDocument::isFileFormatSupported(librevenge::RVNGInputStream *input, const char *password) { - SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); - if (!input->isStructured()) - return SDW_CONFIDENCE_NONE; - librevenge::RVNGInputStream *starWriterDocument = input->getSubStreamByName("StarWriterDocument"); - if (!starWriterDocument) - return SDW_CONFIDENCE_NONE; + SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); + if (!input->isStructured()) + return SDW_CONFIDENCE_NONE; + librevenge::RVNGInputStream *starWriterDocument = input->getSubStreamByName("StarWriterDocument"); + if (!starWriterDocument) + return SDW_CONFIDENCE_NONE; - SDWHeader header(starWriterDocument, password); - if (!header.isValid()) - { - delete starWriterDocument; - return SDW_CONFIDENCE_NONE; - } + SDWHeader header(starWriterDocument, password); + if (!header.isValid()) + { + delete starWriterDocument; + return SDW_CONFIDENCE_NONE; + } - delete starWriterDocument; - return SDW_CONFIDENCE_NONE; + delete starWriterDocument; + return SDW_CONFIDENCE_NONE; } /** @@ -77,12 +77,12 @@ Checks whether the given password was used to encrypt the document */ bool libsdw::SDWDocument::verifyPassword(librevenge::RVNGInputStream *input, const char *password) { - if (!password) - return false; - if (!input) - return false; + if (!password) + return false; + if (!input) + return false; - return false; + return false; } /** @@ -94,17 +94,17 @@ librevenge::RVNGTextInterface class implementation when needed. This is often co */ bool libsdw::SDWDocument::parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface * /* documentInterface */, const char *password) { - SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); - if (!input->isStructured()) - return false; - librevenge::RVNGInputStream *starWriterDocument = input->getSubStreamByName("StarWriterDocument"); - if (!starWriterDocument) - return false; - if (password && !verifyPassword(input, password)) - return false; + SDW_DEBUG_MSG(("SDWDocument::isFileFormatSupported()\n")); + if (!input->isStructured()) + return false; + librevenge::RVNGInputStream *starWriterDocument = input->getSubStreamByName("StarWriterDocument"); + if (!starWriterDocument) + return false; + if (password && !verifyPassword(input, password)) + return false; - delete starWriterDocument; - return false; + delete starWriterDocument; + return false; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/SDWEncryption.cpp b/src/lib/SDWEncryption.cpp index a09f00e..84ee16c 100644 --- a/src/lib/SDWEncryption.cpp +++ b/src/lib/SDWEncryption.cpp @@ -24,29 +24,29 @@ #include <string.h> libsdw::SDWEncryption::SDWEncryption(const char *password) : - m_buffer(NULL), - m_password(password) + m_buffer(NULL), + m_password(password) { } libsdw::SDWEncryption::~SDWEncryption() { - if (m_buffer) - delete [] m_buffer; + if (m_buffer) + delete [] m_buffer; } bool libsdw::SDWEncryption::verifyPassword(const uint8_t * /* filePass */, uint32_t /* date */, uint32_t /* time */) { - return false; + return false; } const unsigned char *libsdw::SDWEncryption::decrypt(const unsigned char *cryptBuffer, unsigned long numBytes) { - if (m_password.len() <= 0) - return cryptBuffer; - (void)numBytes; + if (m_password.len() <= 0) + return cryptBuffer; + (void)numBytes; - return 0; + return 0; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/SDWEncryption.h b/src/lib/SDWEncryption.h index a5723b9..f3375af 100644 --- a/src/lib/SDWEncryption.h +++ b/src/lib/SDWEncryption.h @@ -17,22 +17,23 @@ #include <librevenge-stream/librevenge-stream.h> #include "libsdw_internal.h" -namespace libsdw { +namespace libsdw +{ class SDWEncryption { public: - SDWEncryption(const char *password); - ~SDWEncryption(); - bool verifyPassword(const uint8_t *filePass, uint32_t date, uint32_t time); - const unsigned char *decrypt(const unsigned char *cryptBuffer, unsigned long numBytes); + SDWEncryption(const char *password); + ~SDWEncryption(); + bool verifyPassword(const uint8_t *filePass, uint32_t date, uint32_t time); + const unsigned char *decrypt(const unsigned char *cryptBuffer, unsigned long numBytes); private: - unsigned char *m_buffer; - librevenge::RVNGString m_password; - // Unimplemented to prevent compiler from creating crasher ones - SDWEncryption(const SDWEncryption &); - SDWEncryption &operator=(const SDWEncryption &); + unsigned char *m_buffer; + librevenge::RVNGString m_password; + // Unimplemented to prevent compiler from creating crasher ones + SDWEncryption(const SDWEncryption &); + SDWEncryption &operator=(const SDWEncryption &); }; } // namespace libsdw diff --git a/src/lib/SDWHeader.cpp b/src/lib/SDWHeader.cpp index ce49d17..a164b4d 100644 --- a/src/lib/SDWHeader.cpp +++ b/src/lib/SDWHeader.cpp @@ -18,11 +18,11 @@ #include <string.h> libsdw::SDWHeader::SDWHeader(librevenge::RVNGInputStream *input, const char *password) : - m_needsPassword(false), - m_validHeader(false), - m_encryption(0) + m_needsPassword(false), + m_validHeader(false), + m_encryption(0) { - m_validHeader = loadHeader(input, password); + m_validHeader = loadHeader(input, password); } libsdw::SDWHeader::~SDWHeader() @@ -31,60 +31,60 @@ libsdw::SDWHeader::~SDWHeader() bool libsdw::SDWHeader::loadHeader(librevenge::RVNGInputStream *input, const char *password) { - librevenge::RVNGString signature = readString(input); - SDW_DEBUG_MSG(("SDWHeader signature %s\n", signature.cstr())); - if (signature != "SW3HDR" && signature != "SW4HDR" && signature != "SW5HDR") - return false; + librevenge::RVNGString signature = readString(input); + SDW_DEBUG_MSG(("SDWHeader signature %s\n", signature.cstr())); + if (signature != "SW3HDR" && signature != "SW4HDR" && signature != "SW5HDR") + return false; - uint8_t cLen = readU8(input); - long oldOffset = input->tell(); + uint8_t cLen = readU8(input); + long oldOffset = input->tell(); - uint16_t version = readU16(input); - uint16_t fileFlags = readU16(input); - if (fileFlags & SWGF_BAD_FILE) // Error on write - return false; - if (fileFlags & SWGF_HAS_PASSWD) - m_needsPassword = true; - input->seek(4, librevenge::RVNG_SEEK_CUR); // int32_t docFlags = readS32(input); - input->seek(4, librevenge::RVNG_SEEK_CUR); // uint32_t recSzPos = readU32(input); - input->seek(6, librevenge::RVNG_SEEK_CUR); - input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t redlineMode = readU8(input); - uint8_t compatVer = readU8(input); - if (version >= SWG_MAJORVERSION_50 && compatVer > 0) - return false; + uint16_t version = readU16(input); + uint16_t fileFlags = readU16(input); + if (fileFlags & SWGF_BAD_FILE) // Error on write + return false; + if (fileFlags & SWGF_HAS_PASSWD) + m_needsPassword = true; + input->seek(4, librevenge::RVNG_SEEK_CUR); // int32_t docFlags = readS32(input); + input->seek(4, librevenge::RVNG_SEEK_CUR); // uint32_t recSzPos = readU32(input); + input->seek(6, librevenge::RVNG_SEEK_CUR); + input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t redlineMode = readU8(input); + uint8_t compatVer = readU8(input); + if (version >= SWG_MAJORVERSION_50 && compatVer > 0) + return false; - unsigned long numBytesRead(0L); - const uint8_t *passwd = input->read(16L, numBytesRead); - if (!passwd || numBytesRead != 16L) - return false; + unsigned long numBytesRead(0L); + const uint8_t *passwd = input->read(16L, numBytesRead); + if (!passwd || numBytesRead != 16L) + return false; - input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t charSet = readU8(input); - input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t gui = readU8(input); + input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t charSet = readU8(input); + input->seek(1, librevenge::RVNG_SEEK_CUR); // uint8_t gui = readU8(input); - uint32_t date = readU32(input); - uint32_t time = readU32(input); - - librevenge::RVNGString blockName; - if (fileFlags & SWGF_BLOCKNAME) - { - const uint8_t *buffer = input->read(64L, numBytesRead); - if (numBytesRead != 64L && buffer[63] != 0) - return false; - blockName.append((const char*)buffer); - SDW_DEBUG_MSG(("SDWHeader blockName \"%s\"\n", blockName.cstr())); - } + uint32_t date = readU32(input); + uint32_t time = readU32(input); - SDW_DEBUG_MSG(("SDWHeader finished construction\n")); - input->seek(oldOffset + cLen, librevenge::RVNG_SEEK_SET); - - if (m_needsPassword && password) - m_encryption = new SDWEncryption(password); - if (m_encryption && !m_encryption->verifyPassword(passwd, date, time)) - { - delete m_encryption; - m_encryption = 0; - return false; - } - return true; + librevenge::RVNGString blockName; + if (fileFlags & SWGF_BLOCKNAME) + { + const uint8_t *buffer = input->read(64L, numBytesRead); + if (numBytesRead != 64L && buffer[63] != 0) + return false; + blockName.append((const char *)buffer); + SDW_DEBUG_MSG(("SDWHeader blockName \"%s\"\n", blockName.cstr())); + } + + SDW_DEBUG_MSG(("SDWHeader finished construction\n")); + input->seek(oldOffset + cLen, librevenge::RVNG_SEEK_SET); + + if (m_needsPassword && password) + m_encryption = new SDWEncryption(password); + if (m_encryption && !m_encryption->verifyPassword(passwd, date, time)) + { + delete m_encryption; + m_encryption = 0; + return false; + } + return true; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/SDWHeader.h b/src/lib/SDWHeader.h index f3e2df4..4519f4d 100644 --- a/src/lib/SDWHeader.h +++ b/src/lib/SDWHeader.h @@ -25,35 +25,35 @@ class SDWEncryption; class SDWHeader { - // disable copying - SDWHeader(const SDWHeader &); - SDWHeader &operator=(const SDWHeader &); + // disable copying + SDWHeader(const SDWHeader &); + SDWHeader &operator=(const SDWHeader &); public: - SDWHeader(librevenge::RVNGInputStream *input, const char *password); - virtual ~SDWHeader(); - - bool isValid() - { - return m_validHeader; - } - - bool needsPassword() - { - return m_needsPassword; - } - - SDWEncryption *getEncryption() const - { - return m_encryption; - } + SDWHeader(librevenge::RVNGInputStream *input, const char *password); + virtual ~SDWHeader(); + + bool isValid() + { + return m_validHeader; + } + + bool needsPassword() + { + return m_needsPassword; + } + + SDWEncryption *getEncryption() const + { + return m_encryption; + } private: - bool m_needsPassword; - bool m_validHeader; - SDWEncryption *m_encryption; + bool m_needsPassword; + bool m_validHeader; + SDWEncryption *m_encryption; - bool loadHeader(librevenge::RVNGInputStream *input, const char *password); + bool loadHeader(librevenge::RVNGInputStream *input, const char *password); }; } // namespace libsdw diff --git a/src/lib/SDWParser.cpp b/src/lib/SDWParser.cpp index 8b2e6be..5d7cc13 100644 --- a/src/lib/SDWParser.cpp +++ b/src/lib/SDWParser.cpp @@ -26,9 +26,9 @@ #include "SDWParser.h" libsdw::SDWParser::SDWParser(librevenge::RVNGInputStream *input, SDWHeader *header, SDWEncryption *encryption) : - m_input(input), - m_header(header), - m_encryption(encryption) + m_input(input), + m_header(header), + m_encryption(encryption) { } diff --git a/src/lib/SDWParser.h b/src/lib/SDWParser.h index b74bb2b..877df3b 100644 --- a/src/lib/SDWParser.h +++ b/src/lib/SDWParser.h @@ -35,31 +35,31 @@ class SDWEncryption; class SDWParser { public: - SDWParser(librevenge::RVNGInputStream *input, SDWHeader *header, SDWEncryption *encryption); - virtual ~SDWParser(); + SDWParser(librevenge::RVNGInputStream *input, SDWHeader *header, SDWEncryption *encryption); + virtual ~SDWParser(); - virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0; + virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0; protected: - SDWHeader *getHeader() - { - return m_header; - } - librevenge::RVNGInputStream *getInput() - { - return m_input; - } - SDWEncryption *getEncryption() - { - return m_encryption; - } + SDWHeader *getHeader() + { + return m_header; + } + librevenge::RVNGInputStream *getInput() + { + return m_input; + } + SDWEncryption *getEncryption() + { + return m_encryption; + } private: - SDWParser(const SDWParser &); - SDWParser &operator=(const SDWParser &); - librevenge::RVNGInputStream *m_input; - SDWHeader *m_header; - SDWEncryption *m_encryption; + SDWParser(const SDWParser &); + SDWParser &operator=(const SDWParser &); + librevenge::RVNGInputStream *m_input; + SDWHeader *m_header; + SDWEncryption *m_encryption; }; } // namespace libsdw diff --git a/src/lib/libsdw_internal.cpp b/src/lib/libsdw_internal.cpp index 2c21f28..2875260 100644 --- a/src/lib/libsdw_internal.cpp +++ b/src/lib/libsdw_internal.cpp @@ -24,74 +24,74 @@ uint8_t libsdw::readU8(librevenge::RVNGInputStream *input) { - if (!input || input->isEnd()) - { - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); - } - unsigned long numBytesRead; - uint8_t const *p = input->read(sizeof(uint8_t), numBytesRead); + if (!input || input->isEnd()) + { + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); + } + unsigned long numBytesRead; + uint8_t const *p = input->read(sizeof(uint8_t), numBytesRead); - if (p && numBytesRead == sizeof(uint8_t)) - return *(uint8_t const *)(p); - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); + if (p && numBytesRead == sizeof(uint8_t)) + return *(uint8_t const *)(p); + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); } int8_t libsdw::readS8(librevenge::RVNGInputStream *input) { - return (int8_t)readU8(input); + return (int8_t)readU8(input); } uint16_t libsdw::readU16(librevenge::RVNGInputStream *input) { - if (!input || input->isEnd()) - { - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); - } - unsigned long numBytesRead; - uint8_t const *p = input->read(sizeof(uint16_t), numBytesRead); + if (!input || input->isEnd()) + { + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); + } + unsigned long numBytesRead; + uint8_t const *p = input->read(sizeof(uint16_t), numBytesRead); - if (p && numBytesRead == sizeof(uint16_t)) - return (uint16_t)((uint16_t)p[0]|((uint16_t)p[1]<<8)); - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); + if (p && numBytesRead == sizeof(uint16_t)) + return (uint16_t)((uint16_t)p[0]|((uint16_t)p[1]<<8)); + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); } int16_t libsdw::readS16(librevenge::RVNGInputStream *input) { - return (int16_t)readU16(input); + return (int16_t)readU16(input); } uint32_t libsdw::readU32(librevenge::RVNGInputStream *input) { - if (!input || input->isEnd()) - { - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); - } - unsigned long numBytesRead; - uint8_t const *p = input->read(sizeof(uint32_t), numBytesRead); + if (!input || input->isEnd()) + { + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); + } + unsigned long numBytesRead; + uint8_t const *p = input->read(sizeof(uint32_t), numBytesRead); - if (p && numBytesRead == sizeof(uint32_t)) - return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24); - SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); - throw EndOfStreamException(); + if (p && numBytesRead == sizeof(uint32_t)) + return (uint32_t)p[0]|((uint32_t)p[1]<<8)|((uint32_t)p[2]<<16)|((uint32_t)p[3]<<24); + SDW_DEBUG_MSG(("Throwing EndOfStreamException\n")); + throw EndOfStreamException(); } int32_t libsdw::readS32(librevenge::RVNGInputStream *input) { - return (int32_t)readU32(input); + return (int32_t)readU32(input); } librevenge::RVNGString libsdw::readString(librevenge::RVNGInputStream *input) { - librevenge::RVNGString text; - uint8_t c = 0; - while ( !input->isEnd() && (c = readU8(input)) ) - text.append((char)c); - return text; + librevenge::RVNGString text; + uint8_t c = 0; + while (!input->isEnd() && (c = readU8(input))) + text.append((char)c); + return text; } /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/libsdw_internal.h b/src/lib/libsdw_internal.h index 462dca3..679e74c 100644 --- a/src/lib/libsdw_internal.h +++ b/src/lib/libsdw_internal.h @@ -82,22 +82,22 @@ namespace libsdw // Various exceptions class EndOfStreamException { - // needless to say, we could flesh this class out a bit + // needless to say, we could flesh this class out a bit }; class FileException { - // needless to say, we could flesh this class out a bit + // needless to say, we could flesh this class out a bit }; class ParseException { - // needless to say, we could flesh this class out a bit + // needless to say, we could flesh this class out a bit }; class GenericException { - // needless to say, we could flesh this class out a bit + // needless to say, we could flesh this class out a bit }; } // namespace libsdw |