From 7e265b05f440ed81b80f2de496c9d13221a69fe0 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 10 Dec 2013 08:52:51 +0100 Subject: [PATCH] Simplified types for better readability. Use appropriate types (size_t, byte_t...). Minor warning fixes. --- src/address.cpp | 8 +- src/addressList.cpp | 10 +- src/base.cpp | 7 +- src/body.cpp | 64 ++-- src/bodyPart.cpp | 13 +- src/charset.cpp | 6 +- src/charsetConverter_iconv.cpp | 82 +++-- src/charsetConverter_icu.cpp | 14 +- src/charsetConverter_idna.cpp | 8 +- src/component.cpp | 51 ++- src/constants.cpp | 270 +++++++------- src/contentDisposition.cpp | 6 +- src/dateTime.cpp | 14 +- src/disposition.cpp | 24 +- src/emailAddress.cpp | 18 +- src/emptyContentHandler.cpp | 4 +- src/encoding.cpp | 10 +- src/fileAttachment.cpp | 4 +- src/generationContext.cpp | 4 +- src/header.cpp | 10 +- src/headerField.cpp | 22 +- src/headerFieldValue.cpp | 2 +- src/mailbox.cpp | 16 +- src/mailboxField.cpp | 4 +- src/mailboxGroup.cpp | 16 +- src/mailboxList.cpp | 8 +- src/mediaType.cpp | 14 +- src/message.cpp | 4 +- src/messageId.cpp | 26 +- src/messageIdSequence.cpp | 10 +- src/net/fetchAttributes.cpp | 1 + src/net/imap/IMAPConnection.cpp | 10 +- src/net/imap/IMAPFolder.cpp | 18 +- src/net/imap/IMAPFolderStatus.cpp | 36 +- src/net/imap/IMAPMessage.cpp | 39 +- src/net/imap/IMAPMessagePart.cpp | 2 +- .../imap/IMAPMessagePartContentHandler.cpp | 4 +- src/net/imap/IMAPUtils.cpp | 10 +- .../maildir/format/courierMaildirFormat.cpp | 2 +- src/net/maildir/format/kmailMaildirFormat.cpp | 7 +- src/net/maildir/maildirFolder.cpp | 14 +- src/net/maildir/maildirMessage.cpp | 53 ++- src/net/maildir/maildirMessagePart.cpp | 10 +- src/net/maildir/maildirStore.cpp | 2 +- src/net/maildir/maildirUtils.cpp | 8 +- src/net/messageSet.cpp | 12 +- src/net/pop3/POP3Connection.cpp | 6 +- src/net/pop3/POP3Folder.cpp | 18 +- src/net/pop3/POP3Message.cpp | 19 +- src/net/pop3/POP3Response.cpp | 22 +- src/net/sendmail/sendmailTransport.cpp | 6 +- .../smtp/SMTPChunkingOutputStreamAdapter.cpp | 16 +- src/net/smtp/SMTPCommand.cpp | 4 +- src/net/smtp/SMTPConnection.cpp | 6 +- src/net/smtp/SMTPResponse.cpp | 4 +- src/net/smtp/SMTPTransport.cpp | 6 +- src/net/tls/gnutls/TLSSocket_GnuTLS.cpp | 40 +- src/net/tls/openssl/TLSSocket_OpenSSL.cpp | 36 +- src/parameter.cpp | 32 +- src/parameterizedHeaderField.cpp | 36 +- src/path.cpp | 14 +- src/platforms/posix/posixChildProcess.cpp | 30 +- src/platforms/posix/posixFile.cpp | 27 +- src/platforms/posix/posixHandler.cpp | 2 +- src/platforms/posix/posixSocket.cpp | 24 +- src/platforms/windows/windowsFile.cpp | 18 +- src/platforms/windows/windowsHandler.cpp | 2 +- src/platforms/windows/windowsSocket.cpp | 20 +- src/propertySet.cpp | 2 +- src/relay.cpp | 14 +- .../cert/gnutls/X509Certificate_GnuTLS.cpp | 6 +- .../cert/openssl/X509Certificate_OpenSSL.cpp | 14 +- src/security/digest/md5/md5MessageDigest.cpp | 19 +- src/security/digest/messageDigest.cpp | 4 +- .../digest/sha1/sha1MessageDigest.cpp | 10 +- src/security/sasl/SASLContext.cpp | 4 +- src/security/sasl/SASLSession.cpp | 4 +- src/security/sasl/SASLSocket.cpp | 50 +-- src/security/sasl/builtinSASLMechanism.cpp | 12 +- src/streamContentHandler.cpp | 10 +- src/stringContentHandler.cpp | 12 +- src/text.cpp | 18 +- src/utility/encoder/b64Encoder.cpp | 70 ++-- src/utility/encoder/noopEncoder.cpp | 12 +- src/utility/encoder/qpEncoder.cpp | 76 ++-- src/utility/encoder/uuEncoder.cpp | 91 +++-- src/utility/filteredStream.cpp | 66 ++-- src/utility/inputStreamAdapter.cpp | 12 +- src/utility/inputStreamByteBufferAdapter.cpp | 16 +- src/utility/inputStreamSocketAdapter.cpp | 10 +- src/utility/inputStreamStringAdapter.cpp | 16 +- src/utility/inputStreamStringProxyAdapter.cpp | 14 +- src/utility/outputStream.cpp | 12 + src/utility/outputStreamAdapter.cpp | 6 +- src/utility/outputStreamByteArrayAdapter.cpp | 3 +- src/utility/outputStreamSocketAdapter.cpp | 6 +- src/utility/outputStreamStringAdapter.cpp | 7 +- src/utility/parserInputStreamAdapter.cpp | 40 +- src/utility/progressListener.cpp | 8 +- src/utility/random.cpp | 4 +- .../seekableInputStreamRegionAdapter.cpp | 18 +- src/utility/stream.cpp | 5 +- src/utility/streamUtils.cpp | 34 +- src/utility/stringProxy.cpp | 22 +- src/utility/stringUtils.cpp | 26 +- src/utility/url.cpp | 20 +- src/utility/urlUtils.cpp | 6 +- src/word.cpp | 44 +-- src/wordEncoder.cpp | 28 +- tests/net/smtp/SMTPTransportTestUtils.hpp | 24 +- .../charsetFilteredOutputStreamTest.cpp | 6 +- tests/parser/charsetTestSuites.hpp | 2 +- tests/parser/messageTest.cpp | 4 +- tests/testRunner.cpp | 4 +- tests/testUtils.cpp | 32 +- tests/testUtils.hpp | 17 +- tests/utility/filteredStreamTest.cpp | 14 +- .../outputStreamByteArrayAdapterTest.cpp | 2 +- .../utility/outputStreamSocketAdapterTest.cpp | 2 +- .../utility/outputStreamStringAdapterTest.cpp | 10 +- .../seekableInputStreamRegionAdapterTest.cpp | 29 +- tests/utility/stringProxyTest.cpp | 32 +- tests/utility/stringUtilsTest.cpp | 43 ++- vmime/address.hpp | 4 +- vmime/addressList.hpp | 10 +- vmime/base.hpp | 10 +- vmime/body.hpp | 20 +- vmime/bodyPart.hpp | 12 +- vmime/charset.hpp | 10 +- vmime/charsetConverter_iconv.hpp | 11 +- vmime/charsetConverter_icu.hpp | 5 +- vmime/component.hpp | 68 ++-- vmime/constants.hpp | 272 +++++++------- vmime/contentDisposition.hpp | 10 +- vmime/contentHandler.hpp | 4 +- vmime/dateTime.hpp | 10 +- vmime/disposition.hpp | 10 +- vmime/emailAddress.hpp | 10 +- vmime/emptyContentHandler.hpp | 4 +- vmime/encoding.hpp | 10 +- vmime/fileAttachment.hpp | 6 +- vmime/generationContext.hpp | 6 +- vmime/header.hpp | 12 +- vmime/headerField.hpp | 18 +- vmime/headerFieldValue.hpp | 2 +- vmime/mailbox.hpp | 10 +- vmime/mailboxField.hpp | 4 +- vmime/mailboxGroup.hpp | 10 +- vmime/mailboxList.hpp | 10 +- vmime/mediaType.hpp | 10 +- vmime/message.hpp | 4 +- vmime/messageId.hpp | 16 +- vmime/messageIdSequence.hpp | 10 +- vmime/net/folder.hpp | 2 +- vmime/net/imap/IMAPConnection.hpp | 2 +- vmime/net/imap/IMAPFolder.hpp | 2 +- vmime/net/imap/IMAPMessage.hpp | 26 +- vmime/net/imap/IMAPMessagePart.hpp | 4 +- .../imap/IMAPMessagePartContentHandler.hpp | 4 +- vmime/net/imap/IMAPParser.hpp | 348 +++++++++--------- vmime/net/maildir/maildirFolder.hpp | 4 +- vmime/net/maildir/maildirMessage.hpp | 10 +- vmime/net/maildir/maildirMessagePart.hpp | 20 +- vmime/net/message.hpp | 15 +- vmime/net/pop3/POP3Folder.hpp | 2 +- vmime/net/pop3/POP3Message.hpp | 18 +- vmime/net/pop3/POP3Response.hpp | 4 +- vmime/net/sendmail/sendmailTransport.hpp | 4 +- .../smtp/SMTPChunkingOutputStreamAdapter.hpp | 13 +- vmime/net/smtp/SMTPCommand.hpp | 4 +- vmime/net/smtp/SMTPTransport.hpp | 4 +- vmime/net/socket.hpp | 28 +- vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp | 11 +- vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp | 11 +- vmime/net/transport.hpp | 2 +- vmime/parameter.hpp | 10 +- vmime/parameterizedHeaderField.hpp | 10 +- vmime/path.hpp | 10 +- vmime/platforms/posix/posixFile.hpp | 13 +- vmime/platforms/posix/posixSocket.hpp | 11 +- vmime/platforms/windows/windowsFile.hpp | 13 +- vmime/platforms/windows/windowsSocket.hpp | 8 +- vmime/relay.hpp | 10 +- .../security/digest/md5/md5MessageDigest.hpp | 12 +- vmime/security/digest/messageDigest.hpp | 14 +- .../digest/sha1/sha1MessageDigest.hpp | 10 +- vmime/security/sasl/SASLContext.hpp | 4 +- vmime/security/sasl/SASLMechanism.hpp | 12 +- vmime/security/sasl/SASLSession.hpp | 4 +- vmime/security/sasl/SASLSocket.hpp | 15 +- vmime/security/sasl/builtinSASLMechanism.hpp | 12 +- vmime/streamContentHandler.hpp | 10 +- vmime/stringContentHandler.hpp | 8 +- vmime/text.hpp | 12 +- vmime/types.hpp | 5 +- vmime/utility/encoder/b64Encoder.hpp | 8 +- vmime/utility/encoder/encoder.hpp | 8 +- vmime/utility/encoder/noopEncoder.hpp | 8 +- vmime/utility/encoder/qpEncoder.hpp | 8 +- vmime/utility/encoder/uuEncoder.hpp | 8 +- vmime/utility/filteredStream.hpp | 82 +++-- vmime/utility/inputStream.hpp | 4 +- vmime/utility/inputStreamAdapter.hpp | 8 +- .../utility/inputStreamByteBufferAdapter.hpp | 14 +- vmime/utility/inputStreamSocketAdapter.hpp | 6 +- vmime/utility/inputStreamStringAdapter.hpp | 16 +- .../utility/inputStreamStringProxyAdapter.hpp | 10 +- vmime/utility/outputStream.hpp | 37 +- vmime/utility/outputStreamAdapter.hpp | 5 +- .../utility/outputStreamByteArrayAdapter.hpp | 5 +- vmime/utility/outputStreamSocketAdapter.hpp | 7 +- vmime/utility/outputStreamStringAdapter.hpp | 6 +- vmime/utility/parserInputStreamAdapter.hpp | 45 +-- vmime/utility/progressListener.hpp | 19 +- vmime/utility/random.hpp | 2 +- vmime/utility/seekableInputStream.hpp | 4 +- .../seekableInputStreamRegionAdapter.hpp | 16 +- vmime/utility/stream.hpp | 14 +- vmime/utility/streamUtils.hpp | 10 +- vmime/utility/stringProxy.hpp | 24 +- vmime/utility/stringUtils.hpp | 32 +- vmime/word.hpp | 26 +- vmime/wordEncoder.hpp | 6 +- 223 files changed, 2245 insertions(+), 1969 deletions(-) diff --git a/src/address.cpp b/src/address.cpp index 08a478ec..c6fa74f1 100644 --- a/src/address.cpp +++ b/src/address.cpp @@ -67,8 +67,8 @@ address-list = (address *("," address)) / obs-addr-list */ shared_ptr
address::parseNext - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition, bool *isLastAddressOfGroup) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition, bool *isLastAddressOfGroup) { bool escaped = false; bool quoted = false; @@ -81,12 +81,12 @@ shared_ptr
address::parseNext if (isLastAddressOfGroup) *isLastAddressOfGroup = false; - string::size_type pos = position; + size_t pos = position; while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; - const string::size_type start = pos; + const size_t start = pos; while (!stop && pos < end) { diff --git a/src/addressList.cpp b/src/addressList.cpp index 15b9227b..5c7d34ac 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -51,12 +51,12 @@ addressList::~addressList() void addressList::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { removeAllAddresses(); - string::size_type pos = position; + size_t pos = position; while (pos < end) { @@ -75,9 +75,9 @@ void addressList::parseImpl void addressList::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - string::size_type pos = curLinePos; + size_t pos = curLinePos; generationContext tmpCtx(ctx); tmpCtx.setMaxLineLength(tmpCtx.getMaxLineLength() - 2); diff --git a/src/base.cpp b/src/base.cpp index f7985376..9f9a87be 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -86,7 +86,7 @@ const string libapi() { return (VMIME_API); } // New line sequence to be used when folding header fields. const string NEW_LINE_SEQUENCE = "\r\n "; -const string::size_type NEW_LINE_SEQUENCE_LENGTH = 1; // space +const size_t NEW_LINE_SEQUENCE_LENGTH = 1; // space /** The CR-LF sequence. */ @@ -110,10 +110,13 @@ nullPtrType null; // Line length limits namespace lineLengthLimits { - const string::size_type infinite = std::numeric_limits ::max(); + const size_t infinite = std::numeric_limits ::max(); } +const size_t npos = std::numeric_limits ::max(); + + #ifndef VMIME_BUILDING_DOC diff --git a/src/body.cpp b/src/body.cpp index d24d800e..8f5401cf 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -55,30 +55,30 @@ body::~body() // static -utility::stream::size_type body::findNextBoundaryPosition +size_t body::findNextBoundaryPosition (shared_ptr parser, const string& boundary, - const utility::stream::size_type position, const utility::stream::size_type end, - utility::stream::size_type* boundaryStart, utility::stream::size_type* boundaryEnd) + const size_t position, const size_t end, + size_t* boundaryStart, size_t* boundaryEnd) { - utility::stream::size_type pos = position; + size_t pos = position; - while (pos != utility::stream::npos && pos < end) + while (pos != npos && pos < end) { pos = parser->findNext(boundary, pos); - if (pos == utility::stream::npos) + if (pos == npos) break; // not found if (pos != 0) { // Skip transport padding bytes (SPACE or HTAB), if any - utility::stream::size_type advance = 0; + size_t advance = 0; while (pos != 0) { parser->seek(pos - advance - 1); - const utility::stream::value_type c = parser->peekByte(); + const byte_t c = parser->peekByte(); if (c == ' ' || c == '\t') ++advance; @@ -96,7 +96,7 @@ utility::stream::size_type body::findNextBoundaryPosition { parser->seek(pos + boundary.length()); - const utility::stream::value_type next = parser->peekByte(); + const byte_t next = parser->peekByte(); // Boundary should be followed by a new line or a dash if (next == '\r' || next == '\n' || next == '-') @@ -130,9 +130,7 @@ utility::stream::size_type body::findNextBoundaryPosition void body::parseImpl (const parsingContext& /* ctx */, shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition) + const size_t position, const size_t end, size_t* newPosition) { removeAllParts(); @@ -174,7 +172,7 @@ void body::parseImpl { // No "boundary" parameter specified: we can try to // guess it by scanning the body contents... - utility::stream::size_type pos = position; + size_t pos = position; parser->seek(pos); @@ -186,23 +184,23 @@ void body::parseImpl { pos = parser->findNext("\n--", position); - if ((pos != utility::stream::npos) && (pos + 3 < end)) + if ((pos != npos) && (pos + 3 < end)) pos += 3; // skip \n-- } - if ((pos != utility::stream::npos) && (pos < end)) + if ((pos != npos) && (pos < end)) { parser->seek(pos); // Read some bytes after boundary separator - utility::stream::value_type buffer[256]; - const utility::stream::size_type bufferLen = + byte_t buffer[256]; + const size_t bufferLen = parser->read(buffer, std::min(end - pos, sizeof(buffer) / sizeof(buffer[0]))); buffer[sizeof(buffer) / sizeof(buffer[0]) - 1] = '\0'; // Skip transport padding bytes (SPACE or HTAB), if any - utility::stream::size_type boundarySkip = 0; + size_t boundarySkip = 0; while (boundarySkip < bufferLen && parserHelpers::isSpace(buffer[boundarySkip])) ++boundarySkip; @@ -210,10 +208,10 @@ void body::parseImpl // Extract boundary from buffer (stop at first CR or LF). // We have to stop after a reasonnably long boundary length (100) // not to take the whole body contents for a boundary... - string::value_type boundaryBytes[100]; - string::size_type boundaryLen = 0; + byte_t boundaryBytes[100]; + size_t boundaryLen = 0; - for (string::value_type c = buffer[boundarySkip] ; + for (byte_t c = buffer[boundarySkip] ; boundaryLen < bufferLen && boundaryLen < 100 && !(c == '\r' || c == '\n') ; ++boundaryLen, c = buffer[boundarySkip + boundaryLen]) { @@ -244,18 +242,18 @@ void body::parseImpl // This is a multi-part body if (isMultipart && !boundary.empty()) { - utility::stream::size_type partStart = position; - utility::stream::size_type pos = position; + size_t partStart = position; + size_t pos = position; bool lastPart = false; // Find the first boundary - utility::stream::size_type boundaryStart, boundaryEnd; + size_t boundaryStart, boundaryEnd; pos = findNextBoundaryPosition(parser, boundary, pos, end, &boundaryStart, &boundaryEnd); - for (int index = 0 ; !lastPart && (pos != utility::stream::npos) && (pos < end) ; ++index) + for (int index = 0 ; !lastPart && (pos != npos) && (pos < end) ; ++index) { - utility::stream::size_type partEnd = boundaryStart; + size_t partEnd = boundaryStart; // Check whether it is the last part (boundary terminated by "--") parser->seek(boundaryEnd); @@ -321,7 +319,7 @@ void body::parseImpl m_contents = make_shared (); // Last part was not found: recover from missing boundary - if (!lastPart && pos == utility::stream::npos) + if (!lastPart && pos == npos) { shared_ptr part = m_part->createChildPart(); @@ -364,7 +362,7 @@ void body::parseImpl } // Extract the (encoded) contents - const utility::stream::size_type length = end - position; + const size_t length = end - position; shared_ptr contentStream = make_shared @@ -416,7 +414,7 @@ text body::getActualEpilogText(const generationContext& ctx) const void body::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type /* curLinePos */, string::size_type* newLinePos) const + const size_t /* curLinePos */, size_t* newLinePos) const { // MIME-Multipart if (getPartCount() != 0) @@ -500,12 +498,12 @@ void body::generateImpl } -utility::stream::size_type body::getGeneratedSize(const generationContext& ctx) +size_t body::getGeneratedSize(const generationContext& ctx) { // MIME-Multipart if (getPartCount() != 0) { - utility::stream::size_type size = 0; + size_t size = 0; // Size of parts and boundaries for (size_t p = 0 ; p < getPartCount() ; ++p) @@ -588,7 +586,7 @@ const string body::generateRandomBoundaryString() this document.) */ - string::value_type boundary[2 + 48 + 1] = { 0 }; + char boundary[2 + 48 + 1] = { 0 }; boundary[0] = '='; boundary[1] = '_'; @@ -622,7 +620,7 @@ bool body::isValidBoundary(const string& boundary) if (boundary.length() > 0 && boundary.length() < 70) { - const string::value_type last = *(end - 1); + const char last = *(end - 1); if (!(last == ' ' || last == '\t' || last == '\n')) { diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp index be5b8e3a..12896f84 100644 --- a/src/bodyPart.cpp +++ b/src/bodyPart.cpp @@ -38,14 +38,11 @@ bodyPart::bodyPart() void bodyPart::parseImpl - (const parsingContext& ctx, - shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition) + (const parsingContext& ctx, shared_ptr parser, + const size_t position, const size_t end, size_t* newPosition) { // Parse the headers - string::size_type pos = position; + size_t pos = position; m_header->parse(ctx, parser, pos, end, &pos); // Parse the body contents @@ -60,7 +57,7 @@ void bodyPart::parseImpl void bodyPart::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type /* curLinePos */, string::size_type* newLinePos) const + const size_t /* curLinePos */, size_t* newLinePos) const { m_header->generate(ctx, os); @@ -73,7 +70,7 @@ void bodyPart::generateImpl } -utility::stream::size_type bodyPart::getGeneratedSize(const generationContext& ctx) +size_t bodyPart::getGeneratedSize(const generationContext& ctx) { return m_header->getGeneratedSize(ctx) + 2 /* CRLF */ + m_body->getGeneratedSize(ctx); } diff --git a/src/charset.cpp b/src/charset.cpp index 03c7b6a9..22bff301 100644 --- a/src/charset.cpp +++ b/src/charset.cpp @@ -58,8 +58,8 @@ charset::charset(const char* name) void charset::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_name = utility::stringUtils::trim (string(buffer.begin() + position, buffer.begin() + end)); @@ -77,7 +77,7 @@ void charset::parseImpl void charset::generateImpl (const generationContext& /* ctx */, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { os << m_name; diff --git a/src/charsetConverter_iconv.cpp b/src/charsetConverter_iconv.cpp index 0efa8445..75d7b170 100644 --- a/src/charsetConverter_iconv.cpp +++ b/src/charsetConverter_iconv.cpp @@ -44,11 +44,15 @@ extern "C" // HACK: prototypes may differ depending on the compiler and/or system (the // second parameter may or may not be 'const'). This relies on the compiler // for choosing the right type. - class ICONV_HACK + + class ICONV_IN_TYPE { public: - ICONV_HACK(const char** ptr) : m_ptr(ptr) { } + ICONV_IN_TYPE(const char** ptr) : m_ptr(ptr) { } + + ICONV_IN_TYPE(const vmime::byte_t** ptr) + : m_ptr(reinterpret_cast (ptr)) { } operator const char**() { return m_ptr; } operator char**() { return const_cast (m_ptr); } @@ -58,6 +62,22 @@ extern "C" const char** m_ptr; }; + class ICONV_OUT_TYPE + { + public: + + ICONV_OUT_TYPE(char** ptr) : m_ptr(ptr) { } + + ICONV_OUT_TYPE(vmime::byte_t** ptr) + : m_ptr(reinterpret_cast (ptr)) { } + + operator char**() { return m_ptr; } + + private: + + char** m_ptr; + }; + #endif // VMIME_BUILDING_DOC } @@ -69,14 +89,14 @@ void outputInvalidChar(OUTPUT_CLASS& out, ICONV_DESC cd, const vmime::charsetConverterOptions& opts = vmime::charsetConverterOptions()) { const char* invalidCharIn = opts.invalidSequence.c_str(); - size_t invalidCharInLen = opts.invalidSequence.length(); + vmime::size_t invalidCharInLen = opts.invalidSequence.length(); - char invalidCharOutBuffer[16]; - char* invalidCharOutPtr = invalidCharOutBuffer; - size_t invalidCharOutLen = 16; + vmime::byte_t invalidCharOutBuffer[16]; + vmime::byte_t* invalidCharOutPtr = invalidCharOutBuffer; + vmime::size_t invalidCharOutLen = 16; - if (iconv(cd, ICONV_HACK(&invalidCharIn), &invalidCharInLen, - &invalidCharOutPtr, &invalidCharOutLen) != static_cast (-1)) + if (iconv(cd, ICONV_IN_TYPE(&invalidCharIn), &invalidCharInLen, + ICONV_OUT_TYPE(&invalidCharOutPtr), &invalidCharOutLen) != static_cast (-1)) { out.write(invalidCharOutBuffer, 16 - invalidCharOutLen); } @@ -134,8 +154,8 @@ void charsetConverter_iconv::convert(utility::inputStream& in, utility::outputSt const iconv_t cd = *static_cast (m_desc); - char inBuffer[32768]; - char outBuffer[32768]; + byte_t inBuffer[32768]; + byte_t outBuffer[32768]; size_t inPos = 0; bool prevIsInvalid = false; @@ -147,13 +167,13 @@ void charsetConverter_iconv::convert(utility::inputStream& in, utility::outputSt size_t inLength = static_cast (in.read(inBuffer + inPos, sizeof(inBuffer) - inPos) + inPos); size_t outLength = sizeof(outBuffer); - const char* inPtr = breakAfterNext ? NULL : inBuffer; + const byte_t* inPtr = breakAfterNext ? NULL : inBuffer; size_t *ptrLength = breakAfterNext ? NULL : &inLength; - char* outPtr = outBuffer; + byte_t* outPtr = outBuffer; // Convert input bytes - if (iconv(cd, ICONV_HACK(&inPtr), ptrLength, - &outPtr, &outLength) == static_cast (-1)) + if (iconv(cd, ICONV_IN_TYPE(&inPtr), ptrLength, + ICONV_OUT_TYPE(&outPtr), &outLength) == static_cast (-1)) { // Illegal input sequence or input sequence has no equivalent // sequence in the destination charset. @@ -167,7 +187,7 @@ void charsetConverter_iconv::convert(utility::inputStream& in, utility::outputSt outputInvalidChar(out, cd, m_options); // Skip a byte and leave unconverted bytes in the input buffer - std::copy(const_cast (inPtr + 1), inBuffer + sizeof(inBuffer), inBuffer); + std::copy(const_cast (inPtr + 1), inBuffer + sizeof(inBuffer), inBuffer); inPos = inLength - 1; } else @@ -176,7 +196,7 @@ void charsetConverter_iconv::convert(utility::inputStream& in, utility::outputSt out.write(outBuffer, sizeof(outBuffer) - outLength); // Leave unconverted bytes in the input buffer - std::copy(const_cast (inPtr), inBuffer + sizeof(inBuffer), inBuffer); + std::copy(const_cast (inPtr), inBuffer + sizeof(inBuffer), inBuffer); inPos = inLength; if (errno != E2BIG) @@ -271,16 +291,16 @@ outputStream& charsetFilteredOutputStream_iconv::getNextOutputStream() } -void charsetFilteredOutputStream_iconv::write - (const value_type* const data, const size_type count) +void charsetFilteredOutputStream_iconv::writeImpl + (const byte_t* const data, const size_t count) { if (m_desc == NULL) throw exceptions::charset_conv_error("Cannot initialize converter."); const iconv_t cd = *static_cast (m_desc); - const value_type* curData = data; - size_type curDataLen = count; + const byte_t* curData = data; + size_t curDataLen = count; // If there is some unconverted bytes left, add more data from this // chunk to see if it can now be converted. @@ -303,7 +323,7 @@ void charsetFilteredOutputStream_iconv::write } // Get more data - const size_type remaining = + const size_t remaining = std::min(curDataLen, sizeof(m_unconvBuffer) - m_unconvCount); std::copy(curData, curData + remaining, m_unconvBuffer + m_unconvCount); @@ -316,14 +336,15 @@ void charsetFilteredOutputStream_iconv::write return; // no more data // Try a conversion - const char* inPtr = m_unconvBuffer; + const byte_t* inPtr = m_unconvBuffer; size_t inLength = m_unconvCount; - char* outPtr = m_outputBuffer; + byte_t* outPtr = m_outputBuffer; size_t outLength = sizeof(m_outputBuffer); const size_t inLength0 = inLength; - if (iconv(cd, ICONV_HACK(&inPtr), &inLength, &outPtr, &outLength) == static_cast (-1)) + if (iconv(cd, ICONV_IN_TYPE(&inPtr), &inLength, + ICONV_OUT_TYPE(&outPtr), &outLength) == static_cast (-1)) { const size_t inputConverted = inLength0 - inLength; @@ -350,14 +371,15 @@ void charsetFilteredOutputStream_iconv::write return; // no more data // Now, convert the current data buffer - const char* inPtr = curData; + const byte_t* inPtr = curData; size_t inLength = std::min(curDataLen, sizeof(m_outputBuffer) / MAX_CHARACTER_WIDTH); - char* outPtr = m_outputBuffer; + byte_t* outPtr = m_outputBuffer; size_t outLength = sizeof(m_outputBuffer); const size_t inLength0 = inLength; - if (iconv(cd, ICONV_HACK(&inPtr), &inLength, &outPtr, &outLength) == static_cast (-1)) + if (iconv(cd, ICONV_IN_TYPE(&inPtr), &inLength, + ICONV_OUT_TYPE(&outPtr), &outLength) == static_cast (-1)) { // Write successfully converted bytes m_stream.write(m_outputBuffer, sizeof(m_outputBuffer) - outLength); @@ -403,14 +425,14 @@ void charsetFilteredOutputStream_iconv::flush() while (m_unconvCount != 0) { // Try a conversion - const char* inPtr = m_unconvBuffer + offset; + const byte_t* inPtr = m_unconvBuffer + offset; size_t inLength = m_unconvCount; - char* outPtr = m_outputBuffer; + byte_t* outPtr = m_outputBuffer; size_t outLength = sizeof(m_outputBuffer); const size_t inLength0 = inLength; - if (iconv(cd, ICONV_HACK(&inPtr), &inLength, &outPtr, &outLength) == static_cast (-1)) + if (iconv(cd, ICONV_IN_TYPE(&inPtr), &inLength, ICONV_OUT_TYPE(&outPtr), &outLength) == static_cast (-1)) { const size_t inputConverted = inLength0 - inLength; diff --git a/src/charsetConverter_icu.cpp b/src/charsetConverter_icu.cpp index d967790e..3374d448 100644 --- a/src/charsetConverter_icu.cpp +++ b/src/charsetConverter_icu.cpp @@ -96,7 +96,7 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre UErrorCode err = U_ZERO_ERROR; // From buffers - char cpInBuffer[16]; // stream data put here + byte_t cpInBuffer[16]; // stream data put here size_t outSize = ucnv_getMinCharSize(m_from) * sizeof(cpInBuffer) * sizeof(UChar); UChar* uOutBuffer = new UChar[outSize]; // Unicode chars end up here @@ -120,10 +120,10 @@ void charsetConverter_icu::convert(utility::inputStream& in, utility::outputStre while (!in.eof()) { // Read input data into buffer - size_t inLength = static_cast(in.read(cpInBuffer, sizeof(cpInBuffer))); + size_t inLength = in.read(cpInBuffer, sizeof(cpInBuffer)); // Beginning of read data - const char* source = &cpInBuffer[0]; + const char* source = reinterpret_cast (&cpInBuffer[0]); const char* sourceLimit = source + inLength; // end + 1 UBool flush = in.eof(); // is this last run? @@ -250,8 +250,8 @@ outputStream& charsetFilteredOutputStream_icu::getNextOutputStream() } -void charsetFilteredOutputStream_icu::write - (const value_type* const data, const size_type count) +void charsetFilteredOutputStream_icu::writeImpl + (const byte_t* const data, const size_t count) { if (m_from == NULL || m_to == NULL) throw exceptions::charset_conv_error("Cannot initialize converters."); @@ -264,8 +264,8 @@ void charsetFilteredOutputStream_icu::write // Conversion loop UErrorCode toErr = U_ZERO_ERROR; - const char* uniSource = data; - const char* uniSourceLimit = data + count; + const char* uniSource = reinterpret_cast (data); + const char* uniSourceLimit = uniSource + count; do { diff --git a/src/charsetConverter_idna.cpp b/src/charsetConverter_idna.cpp index a6b339b6..aea6eca7 100644 --- a/src/charsetConverter_idna.cpp +++ b/src/charsetConverter_idna.cpp @@ -95,8 +95,8 @@ void charsetConverter_idna::convert(const string& in, string& out) string inUTF8; charset::convert(in, inUTF8, m_source, vmime::charsets::UTF_8); - const string::value_type* ch = inUTF8.c_str(); - const string::value_type* end = inUTF8.c_str() + inUTF8.length(); + const char* ch = inUTF8.c_str(); + const char* end = inUTF8.c_str() + inUTF8.length(); std::vector unichars; unichars.reserve(inUTF8.length()); @@ -139,8 +139,8 @@ void charsetConverter_idna::convert(const string& in, string& out) if (status == punycode_success) { - std::vector outUTF8Bytes(outputLen * 4); - string::value_type* p = &outUTF8Bytes[0]; + std::vector outUTF8Bytes(outputLen * 4); + char* p = &outUTF8Bytes[0]; for (std::vector ::const_iterator it = output.begin() ; it != output.begin() + outputLen ; ++it) diff --git a/src/component.cpp b/src/component.cpp index cb013899..46ff4036 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -47,15 +47,15 @@ component::~component() void component::parse - (shared_ptr inputStream, const utility::stream::size_type length) + (shared_ptr inputStream, const size_t length) { parse(inputStream, 0, length, NULL); } void component::parse - (shared_ptr inputStream, const utility::stream::size_type position, - const utility::stream::size_type end, utility::stream::size_type* newPosition) + (shared_ptr inputStream, const size_t position, + const size_t end, size_t* newPosition) { parse(parsingContext::getDefaultContext(), inputStream, position, end, newPosition); } @@ -63,8 +63,8 @@ void component::parse void component::parse (const parsingContext& ctx, - shared_ptr inputStream, const utility::stream::size_type position, - const utility::stream::size_type end, utility::stream::size_type* newPosition) + shared_ptr inputStream, const size_t position, + const size_t end, size_t* newPosition) { m_parsedOffset = m_parsedLength = 0; @@ -109,8 +109,8 @@ void component::parse(const parsingContext& ctx, const string& buffer) void component::parse - (const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_parsedOffset = m_parsedLength = 0; @@ -120,8 +120,8 @@ void component::parse void component::parse (const parsingContext& ctx, - const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_parsedOffset = m_parsedLength = 0; @@ -129,7 +129,7 @@ void component::parse } -void component::offsetParsedBounds(const utility::stream::size_type offset) +void component::offsetParsedBounds(const size_t offset) { // Offset parsed bounds of this component if (m_parsedLength != 0) @@ -145,8 +145,7 @@ void component::offsetParsedBounds(const utility::stream::size_type offset) void component::parseImpl (const parsingContext& ctx, shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, utility::stream::size_type* newPosition) + const size_t position, const size_t end, size_t* newPosition) { // This is the default implementation for parsing from an input stream: // actually, we extract the substring and use the "parse from string" implementation @@ -163,8 +162,8 @@ void component::parseImpl void component::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { // This is the default implementation for parsing from a string: // actually, we encapsulate the string buffer in an input stream, then use @@ -179,8 +178,8 @@ void component::parseImpl } -const string component::generate(const string::size_type maxLineLength, - const string::size_type curLinePos) const +const string component::generate + (const size_t maxLineLength, const size_t curLinePos) const { std::ostringstream oss; utility::outputStreamAdapter adapter(oss); @@ -195,9 +194,7 @@ const string component::generate(const string::size_type maxLineLength, void component::generate - (utility::outputStream& os, - const string::size_type curLinePos, - string::size_type* newLinePos) const + (utility::outputStream& os, const size_t curLinePos, size_t* newLinePos) const { generateImpl(generationContext::getDefaultContext(), os, curLinePos, newLinePos); @@ -205,38 +202,36 @@ void component::generate void component::generate - (const generationContext& ctx, - utility::outputStream& outputStream, - const string::size_type curLinePos, - string::size_type* newLinePos) const + (const generationContext& ctx, utility::outputStream& outputStream, + const size_t curLinePos, size_t* newLinePos) const { generateImpl(ctx, outputStream, curLinePos, newLinePos); } -string::size_type component::getParsedOffset() const +size_t component::getParsedOffset() const { return (m_parsedOffset); } -string::size_type component::getParsedLength() const +size_t component::getParsedLength() const { return (m_parsedLength); } -void component::setParsedBounds(const string::size_type start, const string::size_type end) +void component::setParsedBounds(const size_t start, const size_t end) { m_parsedOffset = start; m_parsedLength = end - start; } -utility::stream::size_type component::getGeneratedSize(const generationContext& ctx) +size_t component::getGeneratedSize(const generationContext& ctx) { std::vector > children = getChildComponents(); - utility::stream::size_type totalSize = 0; + size_t totalSize = 0; for (std::vector >::iterator it = children.begin() ; it != children.end() ; ++it) totalSize += (*it)->getGeneratedSize(ctx); diff --git a/src/constants.cpp b/src/constants.cpp index 551d0a18..3b0a54c0 100644 --- a/src/constants.cpp +++ b/src/constants.cpp @@ -32,205 +32,205 @@ namespace vmime namespace mediaTypes { // Types - const string::value_type* const TEXT = "text"; - const string::value_type* const MULTIPART = "multipart"; - const string::value_type* const MESSAGE = "message"; - const string::value_type* const APPLICATION = "application"; - const string::value_type* const IMAGE = "image"; - const string::value_type* const AUDIO = "audio"; - const string::value_type* const VIDEO = "video"; + const char* const TEXT = "text"; + const char* const MULTIPART = "multipart"; + const char* const MESSAGE = "message"; + const char* const APPLICATION = "application"; + const char* const IMAGE = "image"; + const char* const AUDIO = "audio"; + const char* const VIDEO = "video"; // Sub-types - const string::value_type* const TEXT_PLAIN = "plain"; - const string::value_type* const TEXT_HTML = "html"; - const string::value_type* const TEXT_RICHTEXT = "richtext"; - const string::value_type* const TEXT_ENRICHED = "enriched"; - const string::value_type* const TEXT_RFC822_HEADERS = "rfc822-headers"; // RFC-1892 - const string::value_type* const TEXT_DIRECTORY = "directory"; // RFC-2426 + const char* const TEXT_PLAIN = "plain"; + const char* const TEXT_HTML = "html"; + const char* const TEXT_RICHTEXT = "richtext"; + const char* const TEXT_ENRICHED = "enriched"; + const char* const TEXT_RFC822_HEADERS = "rfc822-headers"; // RFC-1892 + const char* const TEXT_DIRECTORY = "directory"; // RFC-2426 - const string::value_type* const MULTIPART_MIXED = "mixed"; - const string::value_type* const MULTIPART_RELATED = "related"; - const string::value_type* const MULTIPART_ALTERNATIVE = "alternative"; - const string::value_type* const MULTIPART_PARALLEL = "parallel"; - const string::value_type* const MULTIPART_DIGEST = "digest"; - const string::value_type* const MULTIPART_REPORT = "report"; // RFC-1892 + const char* const MULTIPART_MIXED = "mixed"; + const char* const MULTIPART_RELATED = "related"; + const char* const MULTIPART_ALTERNATIVE = "alternative"; + const char* const MULTIPART_PARALLEL = "parallel"; + const char* const MULTIPART_DIGEST = "digest"; + const char* const MULTIPART_REPORT = "report"; // RFC-1892 - const string::value_type* const MESSAGE_RFC822 = "rfc822"; - const string::value_type* const MESSAGE_PARTIAL = "partial"; - const string::value_type* const MESSAGE_EXTERNAL_BODY = "external-body"; - const string::value_type* const MESSAGE_DISPOSITION_NOTIFICATION = "disposition-notification"; + const char* const MESSAGE_RFC822 = "rfc822"; + const char* const MESSAGE_PARTIAL = "partial"; + const char* const MESSAGE_EXTERNAL_BODY = "external-body"; + const char* const MESSAGE_DISPOSITION_NOTIFICATION = "disposition-notification"; - const string::value_type* const APPLICATION_OCTET_STREAM = "octet-stream"; + const char* const APPLICATION_OCTET_STREAM = "octet-stream"; - const string::value_type* const IMAGE_JPEG = "jpeg"; - const string::value_type* const IMAGE_GIF = "gif"; + const char* const IMAGE_JPEG = "jpeg"; + const char* const IMAGE_GIF = "gif"; - const string::value_type* const AUDIO_BASIC = "basic"; + const char* const AUDIO_BASIC = "basic"; - const string::value_type* const VIDEO_MPEG = "mpeg"; + const char* const VIDEO_MPEG = "mpeg"; } // Encoding types namespace encodingTypes { - const string::value_type* const SEVEN_BIT = "7bit"; - const string::value_type* const EIGHT_BIT = "8bit"; - const string::value_type* const BASE64 = "base64"; - const string::value_type* const QUOTED_PRINTABLE = "quoted-printable"; - const string::value_type* const BINARY = "binary"; - const string::value_type* const UUENCODE = "uuencode"; + const char* const SEVEN_BIT = "7bit"; + const char* const EIGHT_BIT = "8bit"; + const char* const BASE64 = "base64"; + const char* const QUOTED_PRINTABLE = "quoted-printable"; + const char* const BINARY = "binary"; + const char* const UUENCODE = "uuencode"; } // Content disposition types namespace contentDispositionTypes { - const string::value_type* const INLINE = "inline"; - const string::value_type* const ATTACHMENT = "attachment"; + const char* const INLINE = "inline"; + const char* const ATTACHMENT = "attachment"; } // Charsets namespace charsets { - const string::value_type* const ISO8859_1 = "iso-8859-1"; - const string::value_type* const ISO8859_2 = "iso-8859-2"; - const string::value_type* const ISO8859_3 = "iso-8859-3"; - const string::value_type* const ISO8859_4 = "iso-8859-4"; - const string::value_type* const ISO8859_5 = "iso-8859-5"; - const string::value_type* const ISO8859_6 = "iso-8859-6"; - const string::value_type* const ISO8859_7 = "iso-8859-7"; - const string::value_type* const ISO8859_8 = "iso-8859-8"; - const string::value_type* const ISO8859_9 = "iso-8859-9"; - const string::value_type* const ISO8859_10 = "iso-8859-10"; - const string::value_type* const ISO8859_13 = "iso-8859-13"; - const string::value_type* const ISO8859_14 = "iso-8859-14"; - const string::value_type* const ISO8859_15 = "iso-8859-15"; - const string::value_type* const ISO8859_16 = "iso-8859-16"; + const char* const ISO8859_1 = "iso-8859-1"; + const char* const ISO8859_2 = "iso-8859-2"; + const char* const ISO8859_3 = "iso-8859-3"; + const char* const ISO8859_4 = "iso-8859-4"; + const char* const ISO8859_5 = "iso-8859-5"; + const char* const ISO8859_6 = "iso-8859-6"; + const char* const ISO8859_7 = "iso-8859-7"; + const char* const ISO8859_8 = "iso-8859-8"; + const char* const ISO8859_9 = "iso-8859-9"; + const char* const ISO8859_10 = "iso-8859-10"; + const char* const ISO8859_13 = "iso-8859-13"; + const char* const ISO8859_14 = "iso-8859-14"; + const char* const ISO8859_15 = "iso-8859-15"; + const char* const ISO8859_16 = "iso-8859-16"; - const string::value_type* const CP_437 = "cp437"; - const string::value_type* const CP_737 = "cp737"; - const string::value_type* const CP_775 = "cp775"; - const string::value_type* const CP_850 = "cp850"; - const string::value_type* const CP_852 = "cp852"; - const string::value_type* const CP_853 = "cp853"; - const string::value_type* const CP_855 = "cp855"; - const string::value_type* const CP_857 = "cp857"; - const string::value_type* const CP_858 = "cp858"; - const string::value_type* const CP_860 = "cp860"; - const string::value_type* const CP_861 = "cp861"; - const string::value_type* const CP_862 = "cp862"; - const string::value_type* const CP_863 = "cp863"; - const string::value_type* const CP_864 = "cp864"; - const string::value_type* const CP_865 = "cp865"; - const string::value_type* const CP_866 = "cp866"; - const string::value_type* const CP_869 = "cp869"; - const string::value_type* const CP_874 = "cp874"; - const string::value_type* const CP_1125 = "cp1125"; - const string::value_type* const CP_1250 = "cp1250"; - const string::value_type* const CP_1251 = "cp1251"; - const string::value_type* const CP_1252 = "cp1252"; - const string::value_type* const CP_1253 = "cp1253"; - const string::value_type* const CP_1254 = "cp1254"; - const string::value_type* const CP_1255 = "cp1255"; - const string::value_type* const CP_1256 = "cp1256"; - const string::value_type* const CP_1257 = "cp1257"; + const char* const CP_437 = "cp437"; + const char* const CP_737 = "cp737"; + const char* const CP_775 = "cp775"; + const char* const CP_850 = "cp850"; + const char* const CP_852 = "cp852"; + const char* const CP_853 = "cp853"; + const char* const CP_855 = "cp855"; + const char* const CP_857 = "cp857"; + const char* const CP_858 = "cp858"; + const char* const CP_860 = "cp860"; + const char* const CP_861 = "cp861"; + const char* const CP_862 = "cp862"; + const char* const CP_863 = "cp863"; + const char* const CP_864 = "cp864"; + const char* const CP_865 = "cp865"; + const char* const CP_866 = "cp866"; + const char* const CP_869 = "cp869"; + const char* const CP_874 = "cp874"; + const char* const CP_1125 = "cp1125"; + const char* const CP_1250 = "cp1250"; + const char* const CP_1251 = "cp1251"; + const char* const CP_1252 = "cp1252"; + const char* const CP_1253 = "cp1253"; + const char* const CP_1254 = "cp1254"; + const char* const CP_1255 = "cp1255"; + const char* const CP_1256 = "cp1256"; + const char* const CP_1257 = "cp1257"; - const string::value_type* const US_ASCII = "us-ascii"; + const char* const US_ASCII = "us-ascii"; - const string::value_type* const UTF_7 = "utf-7"; - const string::value_type* const UTF_8 = "utf-8"; - const string::value_type* const UTF_16 = "utf-16"; - const string::value_type* const UTF_32 = "utf-32"; + const char* const UTF_7 = "utf-7"; + const char* const UTF_8 = "utf-8"; + const char* const UTF_16 = "utf-16"; + const char* const UTF_32 = "utf-32"; - const string::value_type* const WINDOWS_1250 = "windows-1250"; - const string::value_type* const WINDOWS_1251 = "windows-1251"; - const string::value_type* const WINDOWS_1252 = "windows-1252"; - const string::value_type* const WINDOWS_1253 = "windows-1253"; - const string::value_type* const WINDOWS_1254 = "windows-1254"; - const string::value_type* const WINDOWS_1255 = "windows-1255"; - const string::value_type* const WINDOWS_1256 = "windows-1256"; - const string::value_type* const WINDOWS_1257 = "windows-1257"; - const string::value_type* const WINDOWS_1258 = "windows-1258"; + const char* const WINDOWS_1250 = "windows-1250"; + const char* const WINDOWS_1251 = "windows-1251"; + const char* const WINDOWS_1252 = "windows-1252"; + const char* const WINDOWS_1253 = "windows-1253"; + const char* const WINDOWS_1254 = "windows-1254"; + const char* const WINDOWS_1255 = "windows-1255"; + const char* const WINDOWS_1256 = "windows-1256"; + const char* const WINDOWS_1257 = "windows-1257"; + const char* const WINDOWS_1258 = "windows-1258"; - const string::value_type* const IDNA = "idna"; + const char* const IDNA = "idna"; } // Fields namespace fields { - const string::value_type* const RECEIVED = "Received"; - const string::value_type* const FROM = "From"; - const string::value_type* const SENDER = "Sender"; - const string::value_type* const REPLY_TO = "Reply-To"; - const string::value_type* const TO = "To"; - const string::value_type* const CC = "Cc"; - const string::value_type* const BCC = "Bcc"; - const string::value_type* const DATE = "Date"; - const string::value_type* const SUBJECT = "Subject"; - const string::value_type* const ORGANIZATION = "Organization"; - const string::value_type* const USER_AGENT = "User-Agent"; - const string::value_type* const DELIVERED_TO = "Delivered-To"; - const string::value_type* const RETURN_PATH = "Return-Path"; - const string::value_type* const MIME_VERSION = "Mime-Version"; - const string::value_type* const MESSAGE_ID = "Message-Id"; - const string::value_type* const CONTENT_TYPE = "Content-Type"; - const string::value_type* const CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; - const string::value_type* const CONTENT_DESCRIPTION = "Content-Description"; - const string::value_type* const CONTENT_DISPOSITION = "Content-Disposition"; - const string::value_type* const CONTENT_ID = "Content-Id"; - const string::value_type* const CONTENT_LOCATION = "Content-Location"; - const string::value_type* const IN_REPLY_TO = "In-Reply-To"; - const string::value_type* const REFERENCES = "References"; + const char* const RECEIVED = "Received"; + const char* const FROM = "From"; + const char* const SENDER = "Sender"; + const char* const REPLY_TO = "Reply-To"; + const char* const TO = "To"; + const char* const CC = "Cc"; + const char* const BCC = "Bcc"; + const char* const DATE = "Date"; + const char* const SUBJECT = "Subject"; + const char* const ORGANIZATION = "Organization"; + const char* const USER_AGENT = "User-Agent"; + const char* const DELIVERED_TO = "Delivered-To"; + const char* const RETURN_PATH = "Return-Path"; + const char* const MIME_VERSION = "Mime-Version"; + const char* const MESSAGE_ID = "Message-Id"; + const char* const CONTENT_TYPE = "Content-Type"; + const char* const CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding"; + const char* const CONTENT_DESCRIPTION = "Content-Description"; + const char* const CONTENT_DISPOSITION = "Content-Disposition"; + const char* const CONTENT_ID = "Content-Id"; + const char* const CONTENT_LOCATION = "Content-Location"; + const char* const IN_REPLY_TO = "In-Reply-To"; + const char* const REFERENCES = "References"; - const string::value_type* const X_MAILER = "X-Mailer"; - const string::value_type* const X_PRIORITY = "X-Priority"; + const char* const X_MAILER = "X-Mailer"; + const char* const X_PRIORITY = "X-Priority"; // RFC-3798: Message Disposition - const string::value_type* const ORIGINAL_MESSAGE_ID = "Original-Message-ID"; - const string::value_type* const DISPOSITION_NOTIFICATION_TO = "Disposition-Notification-To"; - const string::value_type* const DISPOSITION_NOTIFICATION_OPTIONS = "Disposition-Notification-Options"; - const string::value_type* const DISPOSITION = "Disposition"; - const string::value_type* const FAILURE = "Failure"; - const string::value_type* const ERROR = "Error"; - const string::value_type* const WARNING = "Warning"; - const string::value_type* const ORIGINAL_RECIPIENT = "Original-Recipient"; - const string::value_type* const FINAL_RECIPIENT = "Final-Recipient"; - const string::value_type* const REPORTING_UA = "Reporting-UA"; - const string::value_type* const MDN_GATEWAY = "MDN-Gateway"; + const char* const ORIGINAL_MESSAGE_ID = "Original-Message-ID"; + const char* const DISPOSITION_NOTIFICATION_TO = "Disposition-Notification-To"; + const char* const DISPOSITION_NOTIFICATION_OPTIONS = "Disposition-Notification-Options"; + const char* const DISPOSITION = "Disposition"; + const char* const FAILURE = "Failure"; + const char* const ERROR = "Error"; + const char* const WARNING = "Warning"; + const char* const ORIGINAL_RECIPIENT = "Original-Recipient"; + const char* const FINAL_RECIPIENT = "Final-Recipient"; + const char* const REPORTING_UA = "Reporting-UA"; + const char* const MDN_GATEWAY = "MDN-Gateway"; } // Constants for disposition action modes (RFC-3978). namespace dispositionActionModes { - const string::value_type* const MANUAL = "manual"; - const string::value_type* const AUTOMATIC = "automatic"; + const char* const MANUAL = "manual"; + const char* const AUTOMATIC = "automatic"; } // Constants for disposition sending modes (RFC-3798). namespace dispositionSendingModes { - const string::value_type* const SENT_MANUALLY = "MDN-sent-manually"; - const string::value_type* const SENT_AUTOMATICALLY ="MDN-sent-automatically"; + const char* const SENT_MANUALLY = "MDN-sent-manually"; + const char* const SENT_AUTOMATICALLY ="MDN-sent-automatically"; } // Constants for disposition types (RFC-3798). namespace dispositionTypes { - const string::value_type* const DISPLAYED = "displayed"; - const string::value_type* const DELETED = "deleted"; + const char* const DISPLAYED = "displayed"; + const char* const DELETED = "deleted"; } // Constants for disposition modifiers (RFC-3798). namespace dispositionModifiers { - const string::value_type* const ERROR = "error"; + const char* const ERROR = "error"; } diff --git a/src/contentDisposition.cpp b/src/contentDisposition.cpp index aa9b4fe3..3cf92e27 100644 --- a/src/contentDisposition.cpp +++ b/src/contentDisposition.cpp @@ -48,8 +48,8 @@ contentDisposition::contentDisposition(const contentDisposition& type) void contentDisposition::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_name = utility::stringUtils::trim(utility::stringUtils::toLower (string(buffer.begin() + position, buffer.begin() + end))); @@ -63,7 +63,7 @@ void contentDisposition::parseImpl void contentDisposition::generateImpl (const generationContext& /* ctx */, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { os << m_name; diff --git a/src/dateTime.cpp b/src/dateTime.cpp index 2c045e6d..eca8e785 100644 --- a/src/dateTime.cpp +++ b/src/dateTime.cpp @@ -69,11 +69,11 @@ zone = "UT" / "GMT" ; Universal Time void datetime::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* p = buffer.data() + position; + const char* const pend = buffer.data() + end; + const char* p = buffer.data() + position; // Parse the date and time value while (p < pend && parserHelpers::isSpace(*p)) ++p; @@ -592,11 +592,11 @@ void datetime::parseImpl void datetime::generateImpl (const generationContext& /* ctx */, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - static const string::value_type* dayNames[] = + static const char* dayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; - static const string::value_type* monthNames[] = + static const char* monthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; diff --git a/src/disposition.cpp b/src/disposition.cpp index 08e34afc..352d3251 100644 --- a/src/disposition.cpp +++ b/src/disposition.cpp @@ -172,22 +172,22 @@ const std::vector disposition::getModifierList() const void disposition::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { // disposition-mode ";" disposition-type // [ "/" disposition-modifier *( "," disposition-modifier ) ] // // disposition-mode = action-mode "/" sending-mode - string::size_type pos = position; + size_t pos = position; while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; // -- disposition-mode - const string::size_type modeStart = pos; - string::size_type modeEnd = pos; + const size_t modeStart = pos; + size_t modeEnd = pos; while (pos < end && buffer[pos] != ';') { @@ -199,7 +199,7 @@ void disposition::parseImpl --modeEnd; const string mode = string(buffer.begin() + modeStart, buffer.begin() + modeEnd); - const string::size_type slash = mode.find('/'); + const size_t slash = mode.find('/'); if (slash != string::npos) { @@ -222,8 +222,8 @@ void disposition::parseImpl ++pos; // -- disposition-type - const string::size_type typeStart = pos; - string::size_type typeEnd = pos; + const size_t typeStart = pos; + size_t typeEnd = pos; while (pos < end && buffer[pos] != '/') { @@ -248,8 +248,8 @@ void disposition::parseImpl while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; - const string::size_type modifierStart = pos; - string::size_type modifierEnd = pos; + const size_t modifierStart = pos; + size_t modifierEnd = pos; while (pos < end && buffer[pos] != ',') { @@ -279,9 +279,9 @@ void disposition::parseImpl void disposition::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - string::size_type pos = curLinePos; + size_t pos = curLinePos; const string actionMode = (m_actionMode.empty() ? "automatic-action" : m_actionMode); const string sendingMode = (m_sendingMode.empty() ? "MDN-sent-automatically" : m_sendingMode); diff --git a/src/emailAddress.cpp b/src/emailAddress.cpp index eb76e16d..e185b17b 100644 --- a/src/emailAddress.cpp +++ b/src/emailAddress.cpp @@ -72,12 +72,12 @@ emailAddress::emailAddress(const word& localName, const word& domainName) void emailAddress::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; enum ParserStates { @@ -104,7 +104,7 @@ void emailAddress::parseImpl while (p < pend && !stop) { - const string::value_type c = *p; + const char c = *p; if ((localPart.str().length() + domainPart.str().length()) >= 256) { @@ -371,9 +371,9 @@ void emailAddress::parseImpl static const string domainNameToIDNA(const string& domainName) { std::ostringstream idnaDomain; - string::size_type p = 0; + size_t p = 0; - for (string::size_type n = domainName.find('.', p) ; + for (size_t n = domainName.find('.', p) ; (n = domainName.find('.', p)) != string::npos ; p = n + 1) { string idnaPart; @@ -398,7 +398,7 @@ static const string domainNameToIDNA(const string& domainName) void emailAddress::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { string localPart, domainPart; diff --git a/src/emptyContentHandler.cpp b/src/emptyContentHandler.cpp index f6cdee95..e0f191f3 100644 --- a/src/emptyContentHandler.cpp +++ b/src/emptyContentHandler.cpp @@ -40,7 +40,7 @@ shared_ptr emptyContentHandler::clone() const void emptyContentHandler::generate(utility::outputStream& /* os */, const vmime::encoding& /* enc */, - const string::size_type /* maxLineLength */) const + const size_t /* maxLineLength */) const { // Nothing to do. } @@ -72,7 +72,7 @@ void emptyContentHandler::extractRaw(utility::outputStream& /* os */, } -string::size_type emptyContentHandler::getLength() const +size_t emptyContentHandler::getLength() const { return (0); } diff --git a/src/encoding.cpp b/src/encoding.cpp index 317d441f..26922395 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -62,8 +62,8 @@ encoding::encoding(const encoding& enc) void encoding::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_usage = USAGE_UNKNOWN; @@ -83,7 +83,7 @@ void encoding::parseImpl void encoding::generateImpl (const generationContext& /* ctx */, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { os << m_name; @@ -146,8 +146,8 @@ const encoding encoding::decideImpl // "lineLengthLimits::convenient" characters (7-bit requires that) string::const_iterator p = begin; - const string::size_type maxLen = lineLengthLimits::convenient; - string::size_type len = 0; + const size_t maxLen = lineLengthLimits::convenient; + size_t len = 0; for ( ; p != end && len <= maxLen ; ) { diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp index 1db1a1a8..25a97fcc 100644 --- a/src/fileAttachment.cpp +++ b/src/fileAttachment.cpp @@ -212,8 +212,8 @@ const datetime& fileAttachment::fileInfo::getReadDate() const { return (*m_readD void fileAttachment::fileInfo::setReadDate(const datetime& date) { if (m_readDate) { *m_readDate = date; } else { m_readDate = new datetime(date); } } bool fileAttachment::fileInfo::hasSize() const { return (m_size != NULL); } -utility::stream::size_type fileAttachment::fileInfo::getSize() const { return (*m_size); } -void fileAttachment::fileInfo::setSize(const utility::stream::size_type size) { if (m_size) { *m_size = size; } else { m_size = new utility::stream::size_type(size); } } +size_t fileAttachment::fileInfo::getSize() const { return (*m_size); } +void fileAttachment::fileInfo::setSize(const size_t size) { if (m_size) { *m_size = size; } else { m_size = new size_t(size); } } } // vmime diff --git a/src/generationContext.cpp b/src/generationContext.cpp index 0f19e623..e9662883 100644 --- a/src/generationContext.cpp +++ b/src/generationContext.cpp @@ -53,13 +53,13 @@ generationContext& generationContext::getDefaultContext() } -string::size_type generationContext::getMaxLineLength() const +size_t generationContext::getMaxLineLength() const { return m_maxLineLength; } -void generationContext::setMaxLineLength(const string::size_type maxLineLength) +void generationContext::setMaxLineLength(const size_t maxLineLength) { m_maxLineLength = maxLineLength; } diff --git a/src/header.cpp b/src/header.cpp index 2dc07b8f..34b5fa6e 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -63,10 +63,10 @@ field-body-contents = */ void header::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - string::size_type pos = position; + size_t pos = position; removeAllFields(); @@ -87,7 +87,7 @@ void header::parseImpl void header::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type /* curLinePos */, string::size_type* newLinePos) const + const size_t /* curLinePos */, size_t* newLinePos) const { // Generate the fields for (std::vector >::const_iterator it = m_fields.begin() ; @@ -102,7 +102,7 @@ void header::generateImpl } -utility::stream::size_type header::getGeneratedSize(const generationContext& ctx) +size_t header::getGeneratedSize(const generationContext& ctx) { return component::getGeneratedSize(ctx) + 2 * m_fields.size() /* CRLF */; } diff --git a/src/headerField.cpp b/src/headerField.cpp index c6baa32e..f4c6187e 100644 --- a/src/headerField.cpp +++ b/src/headerField.cpp @@ -76,10 +76,10 @@ headerField& headerField::operator=(const headerField& other) shared_ptr headerField::parseNext - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - string::size_type pos = position; + size_t pos = position; while (pos < end) { @@ -106,12 +106,12 @@ shared_ptr headerField::parseNext // This line may be a field description if (!parserHelpers::isSpace(c)) { - const string::size_type nameStart = pos; // remember the start position of the line + const size_t nameStart = pos; // remember the start position of the line while (pos < end && (buffer[pos] != ':' && !parserHelpers::isSpace(buffer[pos]))) ++pos; - const string::size_type nameEnd = pos; + const size_t nameEnd = pos; while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) ++pos; @@ -141,8 +141,8 @@ shared_ptr headerField::parseNext while (pos < end && (buffer[pos] == ' ' || buffer[pos] == '\t')) ++pos; - const string::size_type contentsStart = pos; - string::size_type contentsEnd = 0; + const size_t contentsStart = pos; + size_t contentsEnd = 0; // Extract the field value while (pos < end) @@ -280,8 +280,8 @@ shared_ptr headerField::parseNext void headerField::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_value->parse(ctx, buffer, position, end, newPosition); } @@ -289,7 +289,7 @@ void headerField::parseImpl void headerField::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { os << m_name + ": "; @@ -297,7 +297,7 @@ void headerField::generateImpl } -utility::stream::size_type headerField::getGeneratedSize(const generationContext& ctx) +size_t headerField::getGeneratedSize(const generationContext& ctx) { return m_name.length() + 2 /* ": " */ + m_value->getGeneratedSize(ctx); } diff --git a/src/headerFieldValue.cpp b/src/headerFieldValue.cpp index 19daf9f2..a93e0061 100644 --- a/src/headerFieldValue.cpp +++ b/src/headerFieldValue.cpp @@ -30,7 +30,7 @@ namespace vmime { -utility::stream::size_type headerFieldValue::getGeneratedSize(const generationContext& ctx) +size_t headerFieldValue::getGeneratedSize(const generationContext& ctx) { std::ostringstream oss; utility::outputStreamAdapter osa(oss); diff --git a/src/mailbox.cpp b/src/mailbox.cpp index a38aada0..7c6d5e3b 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -67,12 +67,12 @@ angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr */ void mailbox::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; // Ignore blank spaces at the beginning while (p < pend && parserHelpers::isSpace(*p)) ++p; @@ -333,7 +333,7 @@ void mailbox::parseImpl void mailbox::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { string generatedEmail; utility::outputStreamStringAdapter generatedEmailStream(generatedEmail); @@ -341,7 +341,7 @@ void mailbox::generateImpl if (m_name.isEmpty()) { - string::size_type pos = curLinePos; + size_t pos = curLinePos; // No display name is specified, only email address. if (curLinePos + generatedEmail.length() > ctx.getMaxLineLength()) @@ -404,7 +404,7 @@ void mailbox::generateImpl } } - string::size_type pos = curLinePos; + size_t pos = curLinePos; m_name.encodeAndFold(ctx, os, pos, &pos, text::QUOTE_IF_POSSIBLE | (forceEncode ? text::FORCE_ENCODING : 0)); diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp index 7d138f3e..29fe9d33 100644 --- a/src/mailboxField.cpp +++ b/src/mailboxField.cpp @@ -44,8 +44,8 @@ mailboxField::mailboxField(const mailboxField&) void mailboxField::parse - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { shared_ptr mbox = make_shared (); diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp index 0245affb..5e8d6b1b 100644 --- a/src/mailboxGroup.cpp +++ b/src/mailboxGroup.cpp @@ -55,12 +55,12 @@ mailboxGroup::~mailboxGroup() void mailboxGroup::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; while (p < pend && parserHelpers::isSpace(*p)) ++p; @@ -77,7 +77,7 @@ void mailboxGroup::parseImpl ++p; - string::size_type pos = position + (p - pstart); + size_t pos = position + (p - pstart); bool isLastAddressOfGroup = false; while (pos < end && !isLastAddressOfGroup) @@ -115,7 +115,7 @@ void mailboxGroup::parseImpl void mailboxGroup::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { // We have to encode the name: // - if it contains characters in a charset different from "US-ASCII", @@ -157,7 +157,7 @@ void mailboxGroup::generateImpl } } - string::size_type pos = curLinePos; + size_t pos = curLinePos; generationContext tmpCtx(ctx); tmpCtx.setMaxLineLength(ctx.getMaxLineLength() - 2); diff --git a/src/mailboxList.cpp b/src/mailboxList.cpp index 7d6674fc..b356a1e7 100644 --- a/src/mailboxList.cpp +++ b/src/mailboxList.cpp @@ -177,12 +177,12 @@ const std::vector > mailboxList::getChildComponents() void mailboxList::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_list.removeAllAddresses(); - string::size_type pos = position; + size_t pos = position; while (pos < end) { @@ -214,7 +214,7 @@ void mailboxList::parseImpl void mailboxList::generateImpl(const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { m_list.generate(ctx, os, curLinePos, newLinePos); } diff --git a/src/mediaType.cpp b/src/mediaType.cpp index 2f9ca6b1..60486da7 100644 --- a/src/mediaType.cpp +++ b/src/mediaType.cpp @@ -49,15 +49,15 @@ mediaType::mediaType(const string& type, const string& subType) void mediaType::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; // Extract the type - const string::size_type typeStart = position; + const size_t typeStart = position; while (p < pend && *p != '/') ++p; @@ -85,7 +85,7 @@ void mediaType::parseImpl void mediaType::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { const string value = m_type + "/" + m_subType; diff --git a/src/message.cpp b/src/message.cpp index 75016c36..76735496 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -37,8 +37,8 @@ message::message() } -const string message::generate(const string::size_type maxLineLength, - const string::size_type curLinePos) const +const string message::generate + (const size_t maxLineLength, const size_t curLinePos) const { return bodyPart::generate(maxLineLength, curLinePos); } diff --git a/src/messageId.cpp b/src/messageId.cpp index d981f061..edc4d1fb 100644 --- a/src/messageId.cpp +++ b/src/messageId.cpp @@ -62,12 +62,12 @@ messageId::messageId(const string& left, const string& right) */ void messageId::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; m_left.clear(); m_right.clear(); @@ -117,7 +117,7 @@ void messageId::parseImpl if (p < pend) { // Extract left part - const string::size_type leftStart = position + (p - pstart); + const size_t leftStart = position + (p - pstart); while (p < pend && *p != '@' && *p != '>') ++p; @@ -130,7 +130,7 @@ void messageId::parseImpl ++p; // Extract right part - const string::size_type rightStart = position + (p - pstart); + const size_t rightStart = position + (p - pstart); while (p < pend && *p != '>' && (hasBrackets || !parserHelpers::isSpace(*p))) ++p; @@ -147,17 +147,17 @@ void messageId::parseImpl shared_ptr messageId::parseNext - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - string::size_type pos = position; + size_t pos = position; while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; if (pos != end) { - const string::size_type begin = pos; + const size_t begin = pos; while (pos < end && !parserHelpers::isSpace(buffer[pos])) ++pos; @@ -189,9 +189,9 @@ const string messageId::getId() const void messageId::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - string::size_type pos = curLinePos; + size_t pos = curLinePos; if (curLinePos + m_left.length() + m_right.length() + 3 > ctx.getMaxLineLength()) { diff --git a/src/messageIdSequence.cpp b/src/messageIdSequence.cpp index bfd0c30f..23b12773 100644 --- a/src/messageIdSequence.cpp +++ b/src/messageIdSequence.cpp @@ -85,12 +85,12 @@ const std::vector > messageIdSequence::getChildComponent void messageIdSequence::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { removeAllMessageIds(); - string::size_type pos = position; + size_t pos = position; while (pos < end) { @@ -109,9 +109,9 @@ void messageIdSequence::parseImpl void messageIdSequence::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - string::size_type pos = curLinePos; + size_t pos = curLinePos; if (!m_list.empty()) { diff --git a/src/net/fetchAttributes.cpp b/src/net/fetchAttributes.cpp index b98e573f..85a41b8c 100644 --- a/src/net/fetchAttributes.cpp +++ b/src/net/fetchAttributes.cpp @@ -51,6 +51,7 @@ fetchAttributes::fetchAttributes(const int attribs) fetchAttributes::fetchAttributes(const fetchAttributes& attribs) + : object() { m_predefinedAttribs = attribs.m_predefinedAttribs; m_headers = attribs.m_headers; diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp index 0dba1ecc..234c2b6a 100644 --- a/src/net/imap/IMAPConnection.cpp +++ b/src/net/imap/IMAPConnection.cpp @@ -394,10 +394,10 @@ void IMAPConnection::authenticateSASL() } byte_t* challenge = 0; - long challengeLen = 0; + size_t challengeLen = 0; byte_t* resp = 0; - long respLen = 0; + size_t respLen = 0; try { @@ -530,7 +530,7 @@ bool IMAPConnection::hasCapability(const string& capa) const string normCapa = utility::stringUtils::toUpper(capa); - for (unsigned int i = 0, n = m_capabilities.size() ; i < n ; ++i) + for (size_t i = 0, n = m_capabilities.size() ; i < n ; ++i) { if (m_capabilities[i] == normCapa) return true; @@ -566,7 +566,7 @@ bool IMAPConnection::processCapabilityResponseData(const IMAPParser::response* r const std::vector & respDataList = resp->continue_req_or_response_data(); - for (unsigned int i = 0 ; i < respDataList.size() ; ++i) + for (size_t i = 0 ; i < respDataList.size() ; ++i) { if (respDataList[i]->response_data() == NULL) continue; @@ -739,7 +739,7 @@ void IMAPConnection::send(bool tag, const string& what, bool end) } -void IMAPConnection::sendRaw(const char* buffer, const int count) +void IMAPConnection::sendRaw(const byte_t* buffer, const size_t count) { m_socket->sendRaw(buffer, count); } diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp index 06d331df..fb98887c 100644 --- a/src/net/imap/IMAPFolder.cpp +++ b/src/net/imap/IMAPFolder.cpp @@ -791,8 +791,8 @@ void IMAPFolder::fetchMessages(std::vector >& msg, const f const std::vector & respDataList = resp->continue_req_or_response_data(); - const int total = msg.size(); - int current = 0; + const size_t total = msg.size(); + size_t current = 0; if (progress) progress->start(total); @@ -1005,7 +1005,7 @@ void IMAPFolder::addMessage(shared_ptr msg, const int flags, } -void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int flags, +void IMAPFolder::addMessage(utility::inputStream& is, const size_t size, const int flags, vmime::datetime* date, utility::progressListener* progress) { shared_ptr store = m_store.lock(); @@ -1064,22 +1064,22 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int } // Send message data - const int total = size; - int current = 0; + const size_t total = size; + size_t current = 0; if (progress) progress->start(total); - const socket::size_type blockSize = std::min(is.getBlockSize(), + const size_t blockSize = std::min(is.getBlockSize(), static_cast (m_connection->getSocket()->getBlockSize())); - std::vector vbuffer(blockSize); - char* buffer = &vbuffer.front(); + std::vector vbuffer(blockSize); + byte_t* buffer = &vbuffer.front(); while (!is.eof()) { // Read some data from the input stream - const int read = is.read(buffer, sizeof(buffer)); + const size_t read = is.read(buffer, sizeof(buffer)); current += read; // Put read data into socket output stream diff --git a/src/net/imap/IMAPFolderStatus.cpp b/src/net/imap/IMAPFolderStatus.cpp index 25c88b02..c78a40f3 100644 --- a/src/net/imap/IMAPFolderStatus.cpp +++ b/src/net/imap/IMAPFolderStatus.cpp @@ -115,7 +115,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) { case IMAPParser::status_att_val::MESSAGES: { - const unsigned int count = (*jt)->value_as_number()->value(); + const unsigned int count = + static_cast ((*jt)->value_as_number()->value()); if (m_count != count) { @@ -127,7 +128,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } case IMAPParser::status_att_val::UNSEEN: { - const unsigned int unseen = (*jt)->value_as_number()->value(); + const unsigned int unseen = + static_cast ((*jt)->value_as_number()->value()); if (m_unseen != unseen) { @@ -139,7 +141,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } case IMAPParser::status_att_val::RECENT: { - const unsigned int recent = (*jt)->value_as_number()->value(); + const unsigned int recent = + static_cast ((*jt)->value_as_number()->value()); if (m_recent != recent) { @@ -151,7 +154,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } case IMAPParser::status_att_val::UIDNEXT: { - const vmime_uint32 uidNext = (*jt)->value_as_number()->value(); + const vmime_uint32 uidNext = + static_cast ((*jt)->value_as_number()->value()); if (m_uidNext != uidNext) { @@ -163,7 +167,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } case IMAPParser::status_att_val::UIDVALIDITY: { - const vmime_uint32 uidValidity = (*jt)->value_as_number()->value(); + const vmime_uint32 uidValidity = + static_cast ((*jt)->value_as_number()->value()); if (m_uidValidity != uidValidity) { @@ -175,7 +180,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } case IMAPParser::status_att_val::HIGHESTMODSEQ: { - const vmime_uint64 highestModSeq = (*jt)->value_as_mod_sequence_value()->value(); + const vmime_uint64 highestModSeq = + static_cast ((*jt)->value_as_mod_sequence_value()->value()); if (m_highestModSeq != highestModSeq) { @@ -191,7 +197,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } else if (resp->type() == IMAPParser::mailbox_data::EXISTS) { - const unsigned int count = resp->number()->value(); + const unsigned int count = + static_cast (resp->number()->value()); if (m_count != count) { @@ -201,7 +208,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::mailbox_data* resp) } else if (resp->type() == IMAPParser::mailbox_data::RECENT) { - const unsigned int recent = resp->number()->value(); + const unsigned int recent = + static_cast (resp->number()->value()); if (m_recent != recent) { @@ -222,7 +230,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::resp_text_code* resp { case IMAPParser::resp_text_code::UIDVALIDITY: { - const vmime_uint32 uidValidity = resp->nz_number()->value(); + const vmime_uint32 uidValidity = + static_cast (resp->nz_number()->value()); if (m_uidValidity != uidValidity) { @@ -234,7 +243,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::resp_text_code* resp } case IMAPParser::resp_text_code::UIDNEXT: { - const vmime_uint32 uidNext = resp->nz_number()->value(); + const vmime_uint32 uidNext = + static_cast (resp->nz_number()->value()); if (m_uidNext != uidNext) { @@ -246,7 +256,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::resp_text_code* resp } case IMAPParser::resp_text_code::UNSEEN: { - const unsigned int unseen = resp->nz_number()->value(); + const unsigned int unseen = + static_cast (resp->nz_number()->value()); if (m_unseen != unseen) { @@ -258,7 +269,8 @@ bool IMAPFolderStatus::updateFromResponse(const IMAPParser::resp_text_code* resp } case IMAPParser::resp_text_code::HIGHESTMODSEQ: { - const vmime_uint64 highestModSeq = resp->mod_sequence_value()->value(); + const vmime_uint64 highestModSeq = + static_cast (resp->mod_sequence_value()->value()); if (m_highestModSeq != highestModSeq) { diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp index ae51bfe8..c11aafc2 100644 --- a/src/net/imap/IMAPMessage.cpp +++ b/src/net/imap/IMAPMessage.cpp @@ -98,7 +98,7 @@ private: IMAPMessage::IMAPMessage(shared_ptr folder, const int num) - : m_folder(folder), m_num(num), m_size(-1), m_flags(FLAG_UNDEFINED), + : m_folder(folder), m_num(num), m_size(-1U), m_flags(FLAG_UNDEFINED), m_expunged(false), m_modseq(0), m_structure(null) { folder->registerMessage(this); @@ -146,9 +146,9 @@ vmime_uint64 IMAPMessage::getModSequence() const } -int IMAPMessage::getSize() const +size_t IMAPMessage::getSize() const { - if (m_size == -1) + if (m_size == -1U) throw exceptions::unfetched_object(); return (m_size); @@ -197,28 +197,36 @@ shared_ptr IMAPMessage::getHeader() const } -void IMAPMessage::extract(utility::outputStream& os, utility::progressListener* progress, - const int start, const int length, const bool peek) const +void IMAPMessage::extract + (utility::outputStream& os, + utility::progressListener* progress, + const size_t start, const size_t length, + const bool peek) const { shared_ptr folder = m_folder.lock(); if (!folder) throw exceptions::folder_not_found(); - extractImpl(null, os, progress, start, length, EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0)); + extractImpl(null, os, progress, start, length, + EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0)); } void IMAPMessage::extractPart - (shared_ptr p, utility::outputStream& os, utility::progressListener* progress, - const int start, const int length, const bool peek) const + (shared_ptr p, + utility::outputStream& os, + utility::progressListener* progress, + const size_t start, const size_t length, + const bool peek) const { shared_ptr folder = m_folder.lock(); if (!folder) throw exceptions::folder_not_found(); - extractImpl(p, os, progress, start, length, EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0)); + extractImpl(p, os, progress, start, length, + EXTRACT_HEADER | EXTRACT_BODY | (peek ? EXTRACT_PEEK : 0)); } @@ -253,9 +261,12 @@ void IMAPMessage::fetchPartHeaderForStructure(shared_ptr str) } -void IMAPMessage::extractImpl(shared_ptr p, utility::outputStream& os, - utility::progressListener* progress, const int start, - const int length, const int extractFlags) const +void IMAPMessage::extractImpl + (shared_ptr p, + utility::outputStream& os, + utility::progressListener* progress, + const size_t start, const size_t length, + const int extractFlags) const { shared_ptr folder = m_folder.lock(); @@ -340,7 +351,7 @@ void IMAPMessage::extractImpl(shared_ptr p, utility::outputS command << "]"; - if (start != 0 || length != -1) + if (start != 0 || length != static_cast (-1)) command << "<" << start << "." << length << ">"; // Send the request @@ -473,7 +484,7 @@ int IMAPMessage::processFetchResponse } case IMAPParser::msg_att_item::RFC822_SIZE: { - m_size = (*it)->number()->value(); + m_size = static_cast ((*it)->number()->value()); break; } case IMAPParser::msg_att_item::BODY_SECTION: diff --git a/src/net/imap/IMAPMessagePart.cpp b/src/net/imap/IMAPMessagePart.cpp index 153470cf..eed885dc 100644 --- a/src/net/imap/IMAPMessagePart.cpp +++ b/src/net/imap/IMAPMessagePart.cpp @@ -104,7 +104,7 @@ const mediaType& IMAPMessagePart::getType() const } -int IMAPMessagePart::getSize() const +size_t IMAPMessagePart::getSize() const { return m_size; } diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp index 7112e3d2..1f53f082 100644 --- a/src/net/imap/IMAPMessagePartContentHandler.cpp +++ b/src/net/imap/IMAPMessagePartContentHandler.cpp @@ -59,7 +59,7 @@ shared_ptr IMAPMessagePartContentHandler::clone() const void IMAPMessagePartContentHandler::generate - (utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength) const + (utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength) const { shared_ptr msg = constCast (m_message.lock()); shared_ptr part = constCast (m_part.lock()); @@ -165,7 +165,7 @@ void IMAPMessagePartContentHandler::extractRaw } -string::size_type IMAPMessagePartContentHandler::getLength() const +size_t IMAPMessagePartContentHandler::getLength() const { return m_part.lock()->getSize(); } diff --git a/src/net/imap/IMAPUtils.cpp b/src/net/imap/IMAPUtils.cpp index bf310414..ff81ce71 100644 --- a/src/net/imap/IMAPUtils.cpp +++ b/src/net/imap/IMAPUtils.cpp @@ -190,9 +190,9 @@ const string IMAPUtils::toModifiedUTF7 int b = 0, k = 0; bool base64 = false; - string::size_type remaining = cvt.length(); + size_t remaining = cvt.length(); - for (string::size_type i = 0, len = cvt.length() ; i < len ; ) + for (size_t i = 0, len = cvt.length() ; i < len ; ) { const unsigned char c = cvt[i]; @@ -206,7 +206,7 @@ const string IMAPUtils::toModifiedUTF7 continue; } - string::size_type n = 0; + size_t n = 0; int ch = 0; if (c < 0x80) @@ -232,7 +232,7 @@ const string IMAPUtils::toModifiedUTF7 ++i; --remaining; - for (string::size_type j = 0 ; j < n ; j++) + for (size_t j = 0 ; j < n ; j++) { if ((cvt[i + j] & 0xc0) != 0x80) return ""; // error @@ -280,7 +280,7 @@ const string IMAPUtils::toModifiedUTF7 base64 = false; } - out += static_cast (ch); + out += static_cast (ch); if (ch == '&') out += '-'; diff --git a/src/net/maildir/format/courierMaildirFormat.cpp b/src/net/maildir/format/courierMaildirFormat.cpp index a948de3e..6d460d5e 100644 --- a/src/net/maildir/format/courierMaildirFormat.cpp +++ b/src/net/maildir/format/courierMaildirFormat.cpp @@ -242,7 +242,7 @@ const std::vector courierMaildirFormat::listFolders const string dir = dirs[i].substr(1) + "."; folder::path path; - for (string::size_type pos = dir.find("."), prev = 0 ; + for (size_t pos = dir.find("."), prev = 0 ; pos != string::npos ; prev = pos + 1, pos = dir.find(".", pos + 1)) { const string comp = dir.substr(prev, pos - prev); diff --git a/src/net/maildir/format/kmailMaildirFormat.cpp b/src/net/maildir/format/kmailMaildirFormat.cpp index 70c9b909..975752a5 100644 --- a/src/net/maildir/format/kmailMaildirFormat.cpp +++ b/src/net/maildir/format/kmailMaildirFormat.cpp @@ -118,11 +118,12 @@ const utility::file::path kmailMaildirFormat::folderPathToFileSystemPath // Root path utility::file::path fsPath = getContext()->getStore()->getFileSystemPath(); - const int count = (type == CONTAINER_DIRECTORY - ? path.getSize() : path.getSize() - 1); + const size_t pathSize = path.getSize(); + const size_t count = (type == CONTAINER_DIRECTORY + ? pathSize : (pathSize >= 1 ? pathSize - 1 : 0)); // Parent folders - for (int i = 0 ; i < count ; ++i) + for (size_t i = 0 ; i < count ; ++i) { utility::file::path::component comp(path[i]); diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp index f476d98a..660178ff 100644 --- a/src/net/maildir/maildirFolder.cpp +++ b/src/net/maildir/maildirFolder.cpp @@ -719,7 +719,7 @@ void maildirFolder::addMessage(shared_ptr msg, const int flags, } -void maildirFolder::addMessage(utility::inputStream& is, const int size, +void maildirFolder::addMessage(utility::inputStream& is, const size_t size, const int flags, vmime::datetime* /* date */, utility::progressListener* progress) { shared_ptr store = m_store.lock(); @@ -816,7 +816,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size, void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath, const utility::file::path& dstDirPath, const utility::file::path::component& filename, - utility::inputStream& is, const utility::stream::size_type size, + utility::inputStream& is, const size_t size, utility::progressListener* progress) { shared_ptr fsf = platform::getHandler()->getFileSystemFactory(); @@ -834,12 +834,12 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath, shared_ptr fw = file->getFileWriter(); shared_ptr os = fw->getOutputStream(); - utility::stream::value_type buffer[65536]; - utility::stream::size_type total = 0; + byte_t buffer[65536]; + size_t total = 0; while (!is.eof()) { - const utility::stream::size_type read = is.read(buffer, sizeof(buffer)); + const size_t read = is.read(buffer, sizeof(buffer)); if (read != 0) { @@ -1185,8 +1185,8 @@ void maildirFolder::fetchMessages(std::vector >& msg, else if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - const int total = msg.size(); - int current = 0; + const size_t total = msg.size(); + size_t current = 0; if (progress) progress->start(total); diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp index 88d743b2..a14f067e 100644 --- a/src/net/maildir/maildirMessage.cpp +++ b/src/net/maildir/maildirMessage.cpp @@ -40,6 +40,7 @@ #include "vmime/platform.hpp" #include "vmime/utility/outputStreamAdapter.hpp" +#include "vmime/utility/stringUtils.hpp" namespace vmime { @@ -82,9 +83,9 @@ const message::uid maildirMessage::getUID() const } -int maildirMessage::getSize() const +size_t maildirMessage::getSize() const { - if (m_size == -1) + if (m_size == static_cast (-1)) throw exceptions::unfetched_object(); return (m_size); @@ -145,16 +146,16 @@ void maildirMessage::setFlags(const int flags, const int mode) void maildirMessage::extract(utility::outputStream& os, - utility::progressListener* progress, const int start, - const int length, const bool peek) const + utility::progressListener* progress, const size_t start, + const size_t length, const bool peek) const { extractImpl(os, progress, 0, m_size, start, length, peek); } void maildirMessage::extractPart(shared_ptr p, utility::outputStream& os, - utility::progressListener* progress, const int start, - const int length, const bool peek) const + utility::progressListener* progress, const size_t start, + const size_t length, const bool peek) const { shared_ptr mp = dynamicCast (p); @@ -164,7 +165,7 @@ void maildirMessage::extractPart(shared_ptr p, utility::outp void maildirMessage::extractImpl(utility::outputStream& os, utility::progressListener* progress, - const int start, const int length, const int partialStart, const int partialLength, + const size_t start, const size_t length, const size_t partialStart, const size_t partialLength, const bool /* peek */) const { shared_ptr folder = m_folder.lock(); @@ -179,20 +180,19 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progressLis is->skip(start + partialStart); - utility::stream::value_type buffer[8192]; - utility::stream::size_type remaining = (partialLength == -1 ? length - : std::min(partialLength, length)); + byte_t buffer[8192]; + size_t remaining = (partialLength == static_cast (-1) + ? length : std::min(partialLength, length)); - const int total = remaining; - int current = 0; + const size_t total = remaining; + size_t current = 0; if (progress) progress->start(total); while (!is->eof() && remaining > 0) { - const utility::stream::size_type read = - is->read(buffer, std::min(remaining, sizeof(buffer))); + const size_t read = is->read(buffer, std::min(remaining, sizeof(buffer))); remaining -= read; current += read; @@ -226,20 +226,19 @@ void maildirMessage::fetchPartHeader(shared_ptr p) is->skip(mp->getHeaderParsedOffset()); - utility::stream::value_type buffer[1024]; - utility::stream::size_type remaining = mp->getHeaderParsedLength(); + byte_t buffer[1024]; + size_t remaining = mp->getHeaderParsedLength(); string contents; contents.reserve(remaining); while (!is->eof() && remaining > 0) { - const utility::stream::size_type read = - is->read(buffer, std::min(remaining, sizeof(buffer))); + const size_t read = is->read(buffer, std::min(remaining, sizeof(buffer))); remaining -= read; - contents.append(buffer, read); + vmime::utility::stringUtils::appendBytesToString(contents, buffer, read); } mp->getOrCreateHeader().parse(contents); @@ -279,30 +278,30 @@ void maildirMessage::fetch(shared_ptr msgFolder, const fetchAttr // Need whole message contents for structure if (options.has(fetchAttributes::STRUCTURE)) { - utility::stream::value_type buffer[16384]; + byte_t buffer[16384]; contents.reserve(file->getLength()); while (!is->eof()) { - const utility::stream::size_type read = is->read(buffer, sizeof(buffer)); - contents.append(buffer, read); + const size_t read = is->read(buffer, sizeof(buffer)); + vmime::utility::stringUtils::appendBytesToString(contents, buffer, read); } } // Need only header else { - utility::stream::value_type buffer[1024]; + byte_t buffer[1024]; contents.reserve(4096); while (!is->eof()) { - const utility::stream::size_type read = is->read(buffer, sizeof(buffer)); - contents.append(buffer, read); + const size_t read = is->read(buffer, sizeof(buffer)); + vmime::utility::stringUtils::appendBytesToString(contents, buffer, read); - const string::size_type sep1 = contents.rfind("\r\n\r\n"); - const string::size_type sep2 = contents.rfind("\n\n"); + const size_t sep1 = contents.rfind("\r\n\r\n"); + const size_t sep2 = contents.rfind("\n\n"); if (sep1 != string::npos) { diff --git a/src/net/maildir/maildirMessagePart.cpp b/src/net/maildir/maildirMessagePart.cpp index 683e259e..6ae085c9 100644 --- a/src/net/maildir/maildirMessagePart.cpp +++ b/src/net/maildir/maildirMessagePart.cpp @@ -93,7 +93,7 @@ const mediaType& maildirMessagePart::getType() const } -int maildirMessagePart::getSize() const +size_t maildirMessagePart::getSize() const { return m_size; } @@ -123,25 +123,25 @@ header& maildirMessagePart::getOrCreateHeader() } -int maildirMessagePart::getHeaderParsedOffset() const +size_t maildirMessagePart::getHeaderParsedOffset() const { return m_headerParsedOffset; } -int maildirMessagePart::getHeaderParsedLength() const +size_t maildirMessagePart::getHeaderParsedLength() const { return m_headerParsedLength; } -int maildirMessagePart::getBodyParsedOffset() const +size_t maildirMessagePart::getBodyParsedOffset() const { return m_bodyParsedOffset; } -int maildirMessagePart::getBodyParsedLength() const +size_t maildirMessagePart::getBodyParsedLength() const { return m_bodyParsedLength; } diff --git a/src/net/maildir/maildirStore.cpp b/src/net/maildir/maildirStore.cpp index c7ceb6fa..87e733e2 100644 --- a/src/net/maildir/maildirStore.cpp +++ b/src/net/maildir/maildirStore.cpp @@ -122,7 +122,7 @@ bool maildirStore::isValidFolderName(const folder::path::component& name) const return false; // Name cannot start with '.' - const int length = buf.length(); + const size_t length = buf.length(); int pos = 0; while ((pos < length) && (buf[pos] == '.')) diff --git a/src/net/maildir/maildirUtils.cpp b/src/net/maildir/maildirUtils.cpp index 5a5ac90f..77aac715 100644 --- a/src/net/maildir/maildirUtils.cpp +++ b/src/net/maildir/maildirUtils.cpp @@ -71,7 +71,7 @@ bool maildirUtils::isMessageFile(const utility::file& file) const utility::file::path::component maildirUtils::extractId (const utility::file::path::component& filename) { - string::size_type sep = filename.getBuffer().rfind(':'); // try colon + size_t sep = filename.getBuffer().rfind(':'); // try colon if (sep == string::npos) { @@ -86,7 +86,7 @@ const utility::file::path::component maildirUtils::extractId int maildirUtils::extractFlags(const utility::file::path::component& comp) { - string::size_type sep = comp.getBuffer().rfind(':'); // try colon + size_t sep = comp.getBuffer().rfind(':'); // try colon if (sep == string::npos) { @@ -95,11 +95,11 @@ int maildirUtils::extractFlags(const utility::file::path::component& comp) } const string flagsString(comp.getBuffer().begin() + sep + 1, comp.getBuffer().end()); - const string::size_type count = flagsString.length(); + const size_t count = flagsString.length(); int flags = 0; - for (string::size_type i = 0 ; i < count ; ++i) + for (size_t i = 0 ; i < count ; ++i) { switch (flagsString[i]) { diff --git a/src/net/messageSet.cpp b/src/net/messageSet.cpp index 71a8a788..2939042e 100644 --- a/src/net/messageSet.cpp +++ b/src/net/messageSet.cpp @@ -151,14 +151,14 @@ messageSet::messageSet(const messageSet& other) { m_ranges.resize(other.m_ranges.size()); - for (unsigned int i = 0, n = other.m_ranges.size() ; i < n ; ++i) + for (size_t i = 0, n = other.m_ranges.size() ; i < n ; ++i) m_ranges[i] = other.m_ranges[i]->clone(); } messageSet::~messageSet() { - for (unsigned int i = 0, n = m_ranges.size() ; i < n ; ++i) + for (size_t i = 0, n = m_ranges.size() ; i < n ; ++i) delete m_ranges[i]; } @@ -256,12 +256,12 @@ messageSet messageSet::byUID(const std::vector & uids) { std::vector numericUIDs; - for (unsigned int i = 0, n = uids.size() ; i < n ; ++i) + for (size_t i = 0, n = uids.size() ; i < n ; ++i) { const string uid = uids[i]; int numericUID = 0; - const string::value_type* p = uid.c_str(); + const char* p = uid.c_str(); for ( ; *p >= '0' && *p <= '9' ; ++p) numericUID = (numericUID * 10) + (*p - '0'); @@ -271,7 +271,7 @@ messageSet messageSet::byUID(const std::vector & uids) messageSet set; // Non-numeric UID, fall back to plain UID list (single-UID ranges) - for (unsigned int i = 0, n = uids.size() ; i < n ; ++i) + for (size_t i = 0, n = uids.size() ; i < n ; ++i) set.m_ranges.push_back(new UIDMessageRange(uids[i])); return set; @@ -342,7 +342,7 @@ void messageSet::addRange(const messageRange& range) void messageSet::enumerate(messageSetEnumerator& en) const { - for (unsigned int i = 0, n = m_ranges.size() ; i < n ; ++i) + for (size_t i = 0, n = m_ranges.size() ; i < n ; ++i) m_ranges[i]->enumerate(en); } diff --git a/src/net/pop3/POP3Connection.cpp b/src/net/pop3/POP3Connection.cpp index 547ef5ef..5fa923f4 100644 --- a/src/net/pop3/POP3Connection.cpp +++ b/src/net/pop3/POP3Connection.cpp @@ -463,10 +463,10 @@ void POP3Connection::authenticateSASL() case POP3Response::CODE_READY: { byte_t* challenge = 0; - long challengeLen = 0; + size_t challengeLen = 0; byte_t* resp = 0; - long respLen = 0; + size_t respLen = 0; try { @@ -495,7 +495,7 @@ void POP3Connection::authenticateSASL() } // Cancel SASL exchange - m_socket->sendRaw("*\r\n", 3); + m_socket->send("*\r\n"); } catch (...) { diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp index 66ace31c..096de8af 100644 --- a/src/net/pop3/POP3Folder.cpp +++ b/src/net/pop3/POP3Folder.cpp @@ -318,8 +318,8 @@ void POP3Folder::fetchMessages(std::vector >& msg, const f else if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - const int total = msg.size(); - int current = 0; + const size_t total = msg.size(); + size_t current = 0; if (progress) progress->start(total); @@ -362,7 +362,7 @@ void POP3Folder::fetchMessages(std::vector >& msg, const f if (x != result.end()) { - int size = 0; + size_t size = 0; std::istringstream iss((*x).second); iss >> size; @@ -446,7 +446,7 @@ void POP3Folder::fetchMessage(shared_ptr msg, const fetchAttributes& o if (it != responseText.end()) { - int size = 0; + size_t size = 0; std::istringstream iss(string(it, responseText.end())); iss >> size; @@ -601,15 +601,17 @@ void POP3Folder::rename(const folder::path& /* newPath */) } -void POP3Folder::addMessage(shared_ptr /* msg */, const int /* flags */, - vmime::datetime* /* date */, utility::progressListener* /* progress */) +void POP3Folder::addMessage + (shared_ptr /* msg */, const int /* flags */, + vmime::datetime* /* date */, utility::progressListener* /* progress */) { throw exceptions::operation_not_supported(); } -void POP3Folder::addMessage(utility::inputStream& /* is */, const int /* size */, const int /* flags */, - vmime::datetime* /* date */, utility::progressListener* /* progress */) +void POP3Folder::addMessage + (utility::inputStream& /* is */, const size_t /* size */, const int /* flags */, + vmime::datetime* /* date */, utility::progressListener* /* progress */) { throw exceptions::operation_not_supported(); } diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp index 5f0fb725..08523611 100644 --- a/src/net/pop3/POP3Message.cpp +++ b/src/net/pop3/POP3Message.cpp @@ -78,9 +78,9 @@ const message::uid POP3Message::getUID() const } -int POP3Message::getSize() const +size_t POP3Message::getSize() const { - if (m_size == -1) + if (m_size == static_cast (-1)) throw exceptions::unfetched_object(); return (m_size); @@ -125,9 +125,11 @@ shared_ptr POP3Message::getHeader() const } -void POP3Message::extract(utility::outputStream& os, - utility::progressListener* progress, const int start, - const int length, const bool /* peek */) const +void POP3Message::extract + (utility::outputStream& os, + utility::progressListener* progress, + const size_t start, const size_t length, + const bool /* peek */) const { shared_ptr folder = m_folder.lock(); @@ -136,7 +138,7 @@ void POP3Message::extract(utility::outputStream& os, else if (!folder->getStore()) throw exceptions::illegal_state("Store disconnected"); - if (start != 0 && length != -1) + if (start != 0 && length != static_cast (-1)) throw exceptions::partial_fetch_not_supported(); // Emit the "RETR" command @@ -157,9 +159,10 @@ void POP3Message::extract(utility::outputStream& os, void POP3Message::extractPart - (shared_ptr /* p */, utility::outputStream& /* os */, + (shared_ptr /* p */, + utility::outputStream& /* os */, utility::progressListener* /* progress */, - const int /* start */, const int /* length */, + const size_t /* start */, const size_t /* length */, const bool /* peek */) const { throw exceptions::operation_not_supported(); diff --git a/src/net/pop3/POP3Response.cpp b/src/net/pop3/POP3Response.cpp index e24634c6..1dc5ee76 100644 --- a/src/net/pop3/POP3Response.cpp +++ b/src/net/pop3/POP3Response.cpp @@ -98,7 +98,7 @@ shared_ptr POP3Response::readMultilineResponse(shared_ptr POP3Response::readLargeResponse (shared_ptr conn, utility::outputStream& os, - utility::progressListener* progress, const long predictedSize) + utility::progressListener* progress, const size_t predictedSize) { shared_ptr resp = shared_ptr (new POP3Response(conn->getSocket(), conn->getTimeoutHandler())); @@ -159,7 +159,7 @@ void POP3Response::readResponseImpl(string& buffer, const bool multiLine) buffer.clear(); - string::value_type last1 = '\0', last2 = '\0'; + char last1 = '\0', last2 = '\0'; for ( ; !foundTerminator ; ) { @@ -187,7 +187,7 @@ void POP3Response::readResponseImpl(string& buffer, const bool multiLine) m_timeoutHandler->resetTimeOut(); // Check for transparent characters: '\n..' becomes '\n.' - const string::value_type first = receiveBuffer[0]; + const char first = receiveBuffer[0]; if (first == '.' && last2 == '\n' && last1 == '.') { @@ -199,7 +199,7 @@ void POP3Response::readResponseImpl(string& buffer, const bool multiLine) receiveBuffer.erase(receiveBuffer.begin()); } - for (string::size_type trans ; + for (size_t trans ; string::npos != (trans = receiveBuffer.find("\n..")) ; ) { receiveBuffer.replace(trans, 3, "\n."); @@ -228,9 +228,9 @@ void POP3Response::readResponseImpl(string& buffer, const bool multiLine) void POP3Response::readResponseImpl (string& firstLine, utility::outputStream& os, - utility::progressListener* progress, const long predictedSize) + utility::progressListener* progress, const size_t predictedSize) { - long current = 0, total = predictedSize; + size_t current = 0, total = predictedSize; string temp; bool codeDone = false; @@ -264,8 +264,8 @@ void POP3Response::readResponseImpl } // Receive data from the socket - utility::stream::value_type buffer[65536]; - const utility::stream::size_type read = is.read(buffer, sizeof(buffer)); + byte_t buffer[65536]; + const size_t read = is.read(buffer, sizeof(buffer)); if (read == 0) // buffer is empty { @@ -289,7 +289,7 @@ void POP3Response::readResponseImpl // If we don't have extracted the response code yet if (!codeDone) { - temp.append(buffer, read); + vmime::utility::stringUtils::appendBytesToString(temp, buffer, read); string responseData; @@ -322,7 +322,7 @@ void POP3Response::readResponseImpl bool POP3Response::stripFirstLine (const string& buffer, string& result, string* firstLine) { - const string::size_type end = buffer.find('\n'); + const size_t end = buffer.find('\n'); if (end != string::npos) { @@ -371,7 +371,7 @@ POP3Response::ResponseCode POP3Response::getResponseCode(const string& buffer) // static void POP3Response::stripResponseCode(const string& buffer, string& result) { - const string::size_type pos = buffer.find_first_of(" \t"); + const size_t pos = buffer.find_first_of(" \t"); if (pos != string::npos) result = buffer.substr(pos + 1); diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp index 68c96e51..8ef18e3b 100644 --- a/src/net/sendmail/sendmailTransport.cpp +++ b/src/net/sendmail/sendmailTransport.cpp @@ -137,7 +137,7 @@ void sendmailTransport::noop() void sendmailTransport::send (const mailbox& expeditor, const mailboxList& recipients, - utility::inputStream& is, const utility::stream::size_type size, + utility::inputStream& is, const size_t size, utility::progressListener* progress, const mailbox& sender) { // If no recipient/expeditor was found, throw an exception @@ -159,7 +159,7 @@ void sendmailTransport::send args.push_back("--"); - for (int i = 0 ; i < recipients.getMailboxCount() ; ++i) + for (size_t i = 0 ; i < recipients.getMailboxCount() ; ++i) args.push_back(recipients.getMailboxAt(i)->getEmail().generate()); // Call sendmail @@ -176,7 +176,7 @@ void sendmailTransport::send void sendmailTransport::internalSend (const std::vector args, utility::inputStream& is, - const utility::stream::size_type size, utility::progressListener* progress) + const size_t size, utility::progressListener* progress) { const utility::file::path path = vmime::platform::getHandler()-> getFileSystemFactory()->stringToPath(m_sendmailPath); diff --git a/src/net/smtp/SMTPChunkingOutputStreamAdapter.cpp b/src/net/smtp/SMTPChunkingOutputStreamAdapter.cpp index 0584f7e6..69f63bc9 100644 --- a/src/net/smtp/SMTPChunkingOutputStreamAdapter.cpp +++ b/src/net/smtp/SMTPChunkingOutputStreamAdapter.cpp @@ -47,7 +47,7 @@ SMTPChunkingOutputStreamAdapter::SMTPChunkingOutputStreamAdapter(shared_ptr SMTPCommand::MAIL(const mailbox& mbox, const bool utf8) // static -shared_ptr SMTPCommand::MAIL(const mailbox& mbox, const bool utf8, const unsigned long size) +shared_ptr SMTPCommand::MAIL(const mailbox& mbox, const bool utf8, const size_t size) { std::ostringstream cmd; cmd.imbue(std::locale::classic()); @@ -160,7 +160,7 @@ shared_ptr SMTPCommand::DATA() // static -shared_ptr SMTPCommand::BDAT(const unsigned long chunkSize, const bool last) +shared_ptr SMTPCommand::BDAT(const size_t chunkSize, const bool last) { std::ostringstream cmd; cmd.imbue(std::locale::classic()); diff --git a/src/net/smtp/SMTPConnection.cpp b/src/net/smtp/SMTPConnection.cpp index 9fcacbc1..26be25db 100644 --- a/src/net/smtp/SMTPConnection.cpp +++ b/src/net/smtp/SMTPConnection.cpp @@ -396,10 +396,10 @@ void SMTPConnection::authenticateSASL() case 334: { byte_t* challenge = 0; - long challengeLen = 0; + size_t challengeLen = 0; byte_t* resp = 0; - long respLen = 0; + size_t respLen = 0; try { @@ -428,7 +428,7 @@ void SMTPConnection::authenticateSASL() } // Cancel SASL exchange - m_socket->sendRaw("*\r\n", 3); + m_socket->send("*\r\n"); } catch (...) { diff --git a/src/net/smtp/SMTPResponse.cpp b/src/net/smtp/SMTPResponse.cpp index baefc38d..f7980351 100644 --- a/src/net/smtp/SMTPResponse.cpp +++ b/src/net/smtp/SMTPResponse.cpp @@ -128,11 +128,11 @@ const string SMTPResponse::readResponseLine() while (true) { // Get a line from the response buffer - const string::size_type lineEnd = currentBuffer.find_first_of('\n'); + const size_t lineEnd = currentBuffer.find_first_of('\n'); if (lineEnd != string::npos) { - string::size_type actualLineEnd = lineEnd; + size_t actualLineEnd = lineEnd; if (actualLineEnd != 0 && currentBuffer[actualLineEnd - 1] == '\r') // CRLF case actualLineEnd--; diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp index 4f409a03..0020d010 100644 --- a/src/net/smtp/SMTPTransport.cpp +++ b/src/net/smtp/SMTPTransport.cpp @@ -163,7 +163,7 @@ void SMTPTransport::noop() void SMTPTransport::sendEnvelope (const mailbox& expeditor, const mailboxList& recipients, const mailbox& sender, bool sendDATACommand, - const utility::stream::size_type size) + const size_t size) { // If no recipient/expeditor was found, throw an exception if (recipients.isEmpty()) @@ -315,7 +315,7 @@ void SMTPTransport::sendEnvelope void SMTPTransport::send (const mailbox& expeditor, const mailboxList& recipients, - utility::inputStream& is, const utility::stream::size_type size, + utility::inputStream& is, const size_t size, utility::progressListener* progress, const mailbox& sender) { if (!isConnected()) @@ -334,7 +334,7 @@ void SMTPTransport::send fos.flush(); // Send end-of-data delimiter - m_connection->getSocket()->sendRaw("\r\n.\r\n", 5); + m_connection->getSocket()->send("\r\n.\r\n"); shared_ptr resp; diff --git a/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp b/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp index bb21cb9d..5a90565b 100644 --- a/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp +++ b/src/net/tls/gnutls/TLSSocket_GnuTLS.cpp @@ -37,6 +37,10 @@ #include "vmime/security/cert/X509Certificate.hpp" +#include "vmime/utility/stringUtils.hpp" + +#include + namespace vmime { namespace net { @@ -110,7 +114,7 @@ bool TLSSocket_GnuTLS::isConnected() const } -TLSSocket::size_type TLSSocket_GnuTLS::getBlockSize() const +size_t TLSSocket_GnuTLS::getBlockSize() const { return 16384; // 16 KB } @@ -130,18 +134,24 @@ const string TLSSocket_GnuTLS::getPeerAddress() const void TLSSocket_GnuTLS::receive(string& buffer) { - const int size = receiveRaw(m_buffer, sizeof(m_buffer)); - buffer = vmime::string(m_buffer, size); + const size_t size = receiveRaw(m_buffer, sizeof(m_buffer)); + buffer = utility::stringUtils::makeStringFromBytes(m_buffer, size); } void TLSSocket_GnuTLS::send(const string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast (buffer.data()), buffer.length()); } -TLSSocket::size_type TLSSocket_GnuTLS::receiveRaw(char* buffer, const size_type count) +void TLSSocket_GnuTLS::send(const char* str) +{ + sendRaw(reinterpret_cast (str), ::strlen(str)); +} + + +size_t TLSSocket_GnuTLS::receiveRaw(byte_t* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; @@ -160,14 +170,14 @@ TLSSocket::size_type TLSSocket_GnuTLS::receiveRaw(char* buffer, const size_type return 0; } - TLSSession_GnuTLS::throwTLSException("gnutls_record_recv", ret); + TLSSession_GnuTLS::throwTLSException("gnutls_record_recv", static_cast (ret)); } - return static_cast (ret); + return static_cast (ret); } -void TLSSocket_GnuTLS::sendRaw(const char* buffer, const size_type count) +void TLSSocket_GnuTLS::sendRaw(const byte_t* buffer, const size_t count) { ssize_t ret = gnutls_record_send (*m_session->m_gnutlsSession, @@ -184,12 +194,12 @@ void TLSSocket_GnuTLS::sendRaw(const char* buffer, const size_type count) return; } - TLSSession_GnuTLS::throwTLSException("gnutls_record_send", ret); + TLSSession_GnuTLS::throwTLSException("gnutls_record_send", static_cast (ret)); } } -TLSSocket::size_type TLSSocket_GnuTLS::sendRawNonBlocking(const char* buffer, const size_type count) +size_t TLSSocket_GnuTLS::sendRawNonBlocking(const byte_t* buffer, const size_t count) { ssize_t ret = gnutls_record_send (*m_session->m_gnutlsSession, @@ -209,7 +219,7 @@ TLSSocket::size_type TLSSocket_GnuTLS::sendRawNonBlocking(const char* buffer, co TLSSession_GnuTLS::throwTLSException("gnutls_record_send", static_cast (ret)); } - return static_cast (ret); + return static_cast (ret); } @@ -288,7 +298,7 @@ ssize_t TLSSocket_GnuTLS::gnutlsPushFunc try { sok->m_wrapped->sendRaw - (reinterpret_cast (data), static_cast (len)); + (reinterpret_cast (data), len); } catch (exception& e) { @@ -318,8 +328,7 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc { const ssize_t ret = static_cast (sok->m_wrapped->receiveRaw - (reinterpret_cast (data), - static_cast (len))); + (reinterpret_cast (data), len)); if (ret == 0) { @@ -345,8 +354,7 @@ ssize_t TLSSocket_GnuTLS::gnutlsPullFunc { const ssize_t n = static_cast (sok->m_wrapped->receiveRaw - (reinterpret_cast (data), - static_cast (len))); + (reinterpret_cast (data), len)); if (n == 0 && sok->m_wrapped->getStatus() & socket::STATUS_WOULDBLOCK) return GNUTLS_E_AGAIN; diff --git a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp index 9aec43e5..8f304c78 100644 --- a/src/net/tls/openssl/TLSSocket_OpenSSL.cpp +++ b/src/net/tls/openssl/TLSSocket_OpenSSL.cpp @@ -38,7 +38,10 @@ #include "vmime/security/cert/openssl/X509Certificate_OpenSSL.hpp" +#include "vmime/utility/stringUtils.hpp" + #include +#include namespace vmime { @@ -60,7 +63,8 @@ BIO_METHOD TLSSocket_OpenSSL::sm_customBIOMethod = TLSSocket_OpenSSL::bio_gets, TLSSocket_OpenSSL::bio_ctrl, TLSSocket_OpenSSL::bio_create, - TLSSocket_OpenSSL::bio_destroy + TLSSocket_OpenSSL::bio_destroy, + 0 }; @@ -160,7 +164,7 @@ bool TLSSocket_OpenSSL::isConnected() const } -TLSSocket::size_type TLSSocket_OpenSSL::getBlockSize() const +size_t TLSSocket_OpenSSL::getBlockSize() const { return 16384; // 16 KB } @@ -180,20 +184,28 @@ const string TLSSocket_OpenSSL::getPeerAddress() const void TLSSocket_OpenSSL::receive(string& buffer) { - const size_type size = receiveRaw(m_buffer, sizeof(m_buffer)); + const size_t size = receiveRaw(m_buffer, sizeof(m_buffer)); - if (size >= 0) - buffer = vmime::string(m_buffer, size); + if (size != 0) + buffer = utility::stringUtils::makeStringFromBytes(m_buffer, size); + else + buffer.clear(); } void TLSSocket_OpenSSL::send(const string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast (buffer.data()), buffer.length()); } -TLSSocket::size_type TLSSocket_OpenSSL::receiveRaw(char* buffer, const size_type count) +void TLSSocket_OpenSSL::send(const char* str) +{ + sendRaw(reinterpret_cast (str), ::strlen(str)); +} + + +size_t TLSSocket_OpenSSL::receiveRaw(byte_t* buffer, const size_t count) { int rc = SSL_read(m_ssl, buffer, static_cast (count)); handleError(rc); @@ -205,14 +217,14 @@ TLSSocket::size_type TLSSocket_OpenSSL::receiveRaw(char* buffer, const size_type } -void TLSSocket_OpenSSL::sendRaw(const char* buffer, const size_type count) +void TLSSocket_OpenSSL::sendRaw(const byte_t* buffer, const size_t count) { int rc = SSL_write(m_ssl, buffer, static_cast (count)); handleError(rc); } -TLSSocket_OpenSSL::size_type TLSSocket_OpenSSL::sendRawNonBlocking(const char* buffer, const size_type count) +size_t TLSSocket_OpenSSL::sendRawNonBlocking(const byte_t* buffer, const size_t count) { int rc = SSL_write(m_ssl, buffer, static_cast (count)); handleError(rc); @@ -391,7 +403,8 @@ int TLSSocket_OpenSSL::bio_write(BIO* bio, const char* buf, int len) { BIO_clear_retry_flags(bio); - const size_type n = sok->m_wrapped->sendRawNonBlocking(buf, len); + const size_t n = sok->m_wrapped->sendRawNonBlocking + (reinterpret_cast (buf), len); BIO_clear_retry_flags(bio); @@ -422,7 +435,8 @@ int TLSSocket_OpenSSL::bio_read(BIO* bio, char* buf, int len) try { - const size_type n = sok->m_wrapped->receiveRaw(buf, len); + const size_t n = sok->m_wrapped->receiveRaw + (reinterpret_cast (buf), len); BIO_clear_retry_flags(bio); diff --git a/src/parameter.cpp b/src/parameter.cpp index d7fcd7d3..b8d5b36e 100644 --- a/src/parameter.cpp +++ b/src/parameter.cpp @@ -114,8 +114,8 @@ void parameter::setValue(const word& value) void parameter::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { m_value->setBuffer(string(buffer.begin() + position, buffer.begin() + end)); @@ -145,15 +145,15 @@ void parameter::parse(const parsingContext& ctx, const std::vector & // Decode following data if (chunk.encoded) { - const string::size_type len = chunk.data.length(); - string::size_type pos = 0; + const size_t len = chunk.data.length(); + size_t pos = 0; // If this is the first encoded chunk, extract charset // and language information if (!foundCharsetChunk) { // Eg. "us-ascii'en'This%20is%20even%20more%20" - string::size_type q = chunk.data.find_first_of('\''); + size_t q = chunk.data.find_first_of('\''); if (q != string::npos) { @@ -178,9 +178,9 @@ void parameter::parse(const parsingContext& ctx, const std::vector & foundCharsetChunk = true; } - for (string::size_type i = pos ; i < len ; ++i) + for (size_t i = pos ; i < len ; ++i) { - const string::value_type c = chunk.data[i]; + const char c = chunk.data[i]; if (c == '%' && i + 2 < len) { @@ -218,7 +218,7 @@ void parameter::parse(const parsingContext& ctx, const std::vector & break; } - value << static_cast (v); + value << static_cast (v); i += 2; // skip next 2 chars } @@ -273,7 +273,7 @@ void parameter::parse(const parsingContext& ctx, const std::vector & void parameter::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { const string& name = m_name; const string& value = m_value->getBuffer(); @@ -293,7 +293,7 @@ void parameter::generateImpl string sevenBitBuffer; utility::outputStreamStringAdapter sevenBitStream(sevenBitBuffer); - string::size_type pos = curLinePos; + size_t pos = curLinePos; if (pos + name.length() + 10 + value.length() > ctx.getMaxLineLength()) { @@ -303,10 +303,10 @@ void parameter::generateImpl bool needQuoting = false; bool needQuotedPrintable = false; - string::size_type valueLength = 0; + size_t valueLength = 0; // Use worst-case length name.length()+2 for 'name=' part of line - for (string::size_type i = 0 ; (i < value.length()) && (pos + name.length() + 2 + valueLength < ctx.getMaxLineLength() - 4) ; ++i, ++valueLength) + for (size_t i = 0 ; (i < value.length()) && (pos + name.length() + 2 + valueLength < ctx.getMaxLineLength() - 4) ; ++i, ++valueLength) { switch (value[i]) { @@ -378,7 +378,7 @@ void parameter::generateImpl else { // Do not chop off this value, but just add the complete name as one header line. - for (string::size_type i = 0 ; i < value.length() ; ++i) + for (size_t i = 0 ; i < value.length() ; ++i) { const char_t c = value[i]; @@ -446,7 +446,7 @@ void parameter::generateImpl // Check whether there is enough space for the first section: // parameter name, section identifier, charset and separators // + at least 5 characters for the value - const string::size_type firstSectionLength = + const size_t firstSectionLength = name.length() + 4 /* *0*= */ + 2 /* '' */ + m_value->getCharset().getName().length(); @@ -461,9 +461,9 @@ void parameter::generateImpl std::vector sectionText; string currentSection; - string::size_type currentSectionLength = firstSectionLength; + size_t currentSectionLength = firstSectionLength; - for (string::size_type i = 0 ; i < value.length() ; ++i) + for (size_t i = 0 ; i < value.length() ; ++i) { // Check whether we should start a new line (taking into // account the next character will be encoded = worst case) diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp index 95421b3f..e2925d25 100644 --- a/src/parameterizedHeaderField.cpp +++ b/src/parameterizedHeaderField.cpp @@ -71,23 +71,23 @@ struct paramInfo { bool extended; std::vector value; - string::size_type start; - string::size_type end; + size_t start; + size_t end; }; #endif // VMIME_BUILDING_DOC void parameterizedHeaderField::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pstart; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pstart; // Skip non-significant whitespaces - string::size_type valueStart = position; + size_t valueStart = position; while (p < pend && parserHelpers::isSpace(*p)) { @@ -96,7 +96,7 @@ void parameterizedHeaderField::parseImpl } // Advance up to ';', if any - string::size_type valueLength = 0; + size_t valueLength = 0; while (p < pend && *p != ';' && (!parserHelpers::isSpace(*p))) // FIXME: support ";" inside quoted or RFC-2047-encoded text { @@ -132,7 +132,7 @@ void parameterizedHeaderField::parseImpl while (p < pend && parserHelpers::isSpace(*p)) ++p; - const string::size_type attrStart = position + (p - pstart); + const size_t attrStart = position + (p - pstart); while (p < pend && !(*p == ';' || *p == '=')) ++p; @@ -148,7 +148,7 @@ void parameterizedHeaderField::parseImpl else { // Extract the attribute name - string::size_type attrEnd = position + (p - pstart); + size_t attrEnd = position + (p - pstart); while (attrEnd != attrStart && parserHelpers::isSpace(buffer[attrEnd - 1])) --attrEnd; @@ -173,7 +173,7 @@ void parameterizedHeaderField::parseImpl bool stop = false; std::ostringstream ss; - string::size_type start = position + (p - pstart); + size_t start = position + (p - pstart); for ( ; p < pend && !stop ; ++p) { @@ -218,12 +218,12 @@ void parameterizedHeaderField::parseImpl // -- the value is a simple token else { - const string::size_type valStart = position + (p - pstart); + const size_t valStart = position + (p - pstart); while (p < pend && *p != ';') ++p; - string::size_type valEnd = position + (p - pstart); + size_t valEnd = position + (p - pstart); while (valEnd != valStart && parserHelpers::isSpace(buffer[valEnd - 1])) --valEnd; @@ -250,13 +250,13 @@ void parameterizedHeaderField::parseImpl } // Check for RFC-2231 multi-section parameters - const string::size_type star = name.find_last_of('*'); + const size_t star = name.find_last_of('*'); if (star != string::npos) { bool allDigits = true; - for (string::size_type i = star + 1 ; allDigits && (i < name.length()) ; ++i) + for (size_t i = star + 1 ; allDigits && (i < name.length()) ; ++i) allDigits = parserHelpers::isDigit(name[i]); if (allDigits) @@ -337,9 +337,9 @@ void parameterizedHeaderField::parseImpl void parameterizedHeaderField::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { - string::size_type pos = curLinePos; + size_t pos = curLinePos; // Parent header field headerField::generateImpl(ctx, os, pos, &pos); diff --git a/src/path.cpp b/src/path.cpp index 8722c9a7..3f1bc6af 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -113,10 +113,10 @@ const std::vector > path::getChildComponents() void path::parseImpl - (const parsingContext& /* ctx */, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& /* ctx */, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - string::size_type pos = position; + size_t pos = position; while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; @@ -131,12 +131,12 @@ void path::parseImpl while (pos < end && parserHelpers::isSpace(buffer[pos])) ++pos; - const string::size_type addrStart = pos; + const size_t addrStart = pos; while (pos < end && buffer[pos] != '>') ++pos; - string::size_type addrEnd = pos; + size_t addrEnd = pos; while (addrEnd > addrStart && parserHelpers::isSpace(buffer[addrEnd - 1])) addrEnd--; @@ -148,7 +148,7 @@ void path::parseImpl addrSpec = string(buffer.begin() + position, buffer.begin() + end); } - const string::size_type at = addrSpec.find_first_of('@'); + const size_t at = addrSpec.find_first_of('@'); if (at != string::npos) { @@ -168,7 +168,7 @@ void path::parseImpl void path::generateImpl (const generationContext& /* ctx */, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { if (m_localPart.empty() && m_domain.empty()) { diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp index c4761624..54d4cd75 100644 --- a/src/platforms/posix/posixChildProcess.cpp +++ b/src/platforms/posix/posixChildProcess.cpp @@ -118,7 +118,14 @@ public: { } - void write(const value_type* const data, const size_type count) + void flush() + { + ::fsync(m_desc); + } + +protected: + + void writeImpl(const byte_t* const data, const size_t count) { if (::write(m_desc, data, count) == -1) { @@ -127,11 +134,6 @@ public: } } - void flush() - { - ::fsync(m_desc); - } - private: const int m_desc; @@ -159,13 +161,13 @@ public: // Do nothing: unsupported } - size_type skip(const size_type count) + size_t skip(const size_t count) { // TODO: not tested - value_type buffer[4096]; + byte_t buffer[4096]; - int bytesSkipped = 0; - int bytesRead = 0; + ssize_t bytesSkipped = 0; + ssize_t bytesRead = 0; while ((bytesRead = ::read(m_desc, buffer, std::min(sizeof(buffer), count - bytesSkipped))) != 0) @@ -179,12 +181,12 @@ public: bytesSkipped += bytesRead; } - return static_cast (bytesSkipped); + return static_cast (bytesSkipped); } - size_type read(value_type* const data, const size_type count) + size_t read(byte_t* const data, const size_t count) { - int bytesRead = 0; + ssize_t bytesRead = 0; if ((bytesRead = ::read(m_desc, data, count)) == -1) { @@ -194,7 +196,7 @@ public: m_eof = (bytesRead == 0); - return static_cast (bytesRead); + return static_cast (bytesRead); } private: diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp index 1e4dd070..9387414d 100644 --- a/src/platforms/posix/posixFile.cpp +++ b/src/platforms/posix/posixFile.cpp @@ -97,7 +97,7 @@ void posixFileIterator::getNextElement() while ((m_dirEntry = ::readdir(m_dir)) != NULL) { const char* name = m_dirEntry->d_name; - const int len = ::strlen(name); + const size_t len = ::strlen(name); if (!(len == 1 && name[0] == '.') && !(len == 2 && name[0] == '.' && name[1] == '.')) @@ -128,9 +128,10 @@ posixFileWriterOutputStream::~posixFileWriterOutputStream() } -void posixFileWriterOutputStream::write(const value_type* const data, const size_type count) +void posixFileWriterOutputStream::writeImpl + (const byte_t* const data, const size_t count) { - const value_type* array = data; + const byte_t* array = data; size_t size = count; while (1) @@ -196,8 +197,8 @@ void posixFileReaderInputStream::reset() } -vmime::utility::stream::size_type posixFileReaderInputStream::read - (value_type* const data, const size_type count) +size_t posixFileReaderInputStream::read + (byte_t* const data, const size_t count) { ssize_t c = 0; @@ -207,11 +208,11 @@ vmime::utility::stream::size_type posixFileReaderInputStream::read if (c == 0 && count != 0) m_eof = true; - return static_cast (c); + return static_cast (c); } -vmime::utility::stream::size_type posixFileReaderInputStream::skip(const size_type count) +size_t posixFileReaderInputStream::skip(const size_t count) { const off_t curPos = ::lseek(m_fd, 0, SEEK_CUR); @@ -223,22 +224,22 @@ vmime::utility::stream::size_type posixFileReaderInputStream::skip(const size_ty if (newPos == off_t(-1)) posixFileSystemFactory::reportError(m_path, errno); - return static_cast (newPos - curPos); + return static_cast (newPos - curPos); } -vmime::utility::stream::size_type posixFileReaderInputStream::getPosition() const +size_t posixFileReaderInputStream::getPosition() const { const off_t curPos = ::lseek(m_fd, 0, SEEK_CUR); if (curPos == off_t(-1)) posixFileSystemFactory::reportError(m_path, errno); - return static_cast (curPos); + return static_cast (curPos); } -void posixFileReaderInputStream::seek(const size_type pos) +void posixFileReaderInputStream::seek(const size_t pos) { const off_t newPos = ::lseek(m_fd, pos, SEEK_SET); @@ -528,8 +529,8 @@ const vmime::string posixFileSystemFactory::pathToString(const vmime::utility::f const vmime::utility::file::path posixFileSystemFactory::stringToPathImpl(const vmime::string& str) { - vmime::string::size_type offset = 0; - vmime::string::size_type prev = 0; + vmime::size_t offset = 0; + vmime::size_t prev = 0; vmime::utility::file::path path; diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp index b5d08ce6..7ab0341a 100644 --- a/src/platforms/posix/posixHandler.cpp +++ b/src/platforms/posix/posixHandler.cpp @@ -181,7 +181,7 @@ static inline bool isFQDN(const vmime::string& str) if (utility::stringUtils::isStringEqualNoCase(str, "localhost", 9)) return false; - const vmime::string::size_type p = str.find_first_of("."); + const vmime::size_t p = str.find_first_of("."); return p != vmime::string::npos && p > 0 && p != str.length() - 1; } diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp index e0bcf03a..eb00beb6 100644 --- a/src/platforms/posix/posixSocket.cpp +++ b/src/platforms/posix/posixSocket.cpp @@ -40,6 +40,8 @@ #include #include +#include "vmime/utility/stringUtils.hpp" + #include "vmime/exception.hpp" @@ -426,7 +428,7 @@ const string posixSocket::getPeerName() const } -posixSocket::size_type posixSocket::getBlockSize() const +size_t posixSocket::getBlockSize() const { return 16384; // 16 KB } @@ -434,12 +436,12 @@ posixSocket::size_type posixSocket::getBlockSize() const void posixSocket::receive(vmime::string& buffer) { - const size_type size = receiveRaw(m_buffer, sizeof(m_buffer)); - buffer = vmime::string(m_buffer, size); + const size_t size = receiveRaw(m_buffer, sizeof(m_buffer)); + buffer = utility::stringUtils::makeStringFromBytes(m_buffer, size); } -posixSocket::size_type posixSocket::receiveRaw(char* buffer, const size_type count) +size_t posixSocket::receiveRaw(byte_t* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; @@ -529,15 +531,21 @@ posixSocket::size_type posixSocket::receiveRaw(char* buffer, const size_type cou void posixSocket::send(const vmime::string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast (buffer.data()), buffer.length()); } -void posixSocket::sendRaw(const char* buffer, const size_type count) +void posixSocket::send(const char* str) +{ + sendRaw(reinterpret_cast (str), ::strlen(str)); +} + + +void posixSocket::sendRaw(const byte_t* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; - size_type size = count; + size_t size = count; while (size > 0) { @@ -563,7 +571,7 @@ void posixSocket::sendRaw(const char* buffer, const size_type count) } -posixSocket::size_type posixSocket::sendRawNonBlocking(const char* buffer, const size_type count) +size_t posixSocket::sendRawNonBlocking(const byte_t* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp index 8d2a19da..6aa0fea8 100644 --- a/src/platforms/windows/windowsFile.cpp +++ b/src/platforms/windows/windowsFile.cpp @@ -61,8 +61,8 @@ const vmime::string windowsFileSystemFactory::pathToString(const vmime::utility: const vmime::utility::file::path windowsFileSystemFactory::stringToPathImpl(const vmime::string& str) { - vmime::string::size_type offset = 0; - vmime::string::size_type prev = 0; + vmime::size_t offset = 0; + vmime::size_t prev = 0; vmime::utility::file::path path; @@ -117,7 +117,7 @@ bool windowsFileSystemFactory::isValidPathComponent( } // Check for invalid characters - for (string::size_type i = 0 ; i < buffer.length() ; ++i) + for (size_t i = 0 ; i < buffer.length() ; ++i) { const unsigned char c = buffer[i]; @@ -467,7 +467,7 @@ void windowsFileReaderInputStream::reset() SetFilePointer(m_hFile, 0, NULL, FILE_BEGIN); } -vmime::utility::stream::size_type windowsFileReaderInputStream::read(value_type* const data, const size_type count) +size_t windowsFileReaderInputStream::read(byte_t* const data, const size_t count) { DWORD dwBytesRead; if (!ReadFile(m_hFile, (LPVOID)data, (DWORD)count, &dwBytesRead, NULL)) @@ -475,24 +475,24 @@ vmime::utility::stream::size_type windowsFileReaderInputStream::read(value_type* return dwBytesRead; } -vmime::utility::stream::size_type windowsFileReaderInputStream::skip(const size_type count) +size_t windowsFileReaderInputStream::skip(const size_t count) { DWORD dwCurPos = SetFilePointer(m_hFile, 0, NULL, FILE_CURRENT); DWORD dwNewPos = SetFilePointer(m_hFile, (LONG)count, NULL, FILE_CURRENT); return (dwNewPos - dwCurPos); } -vmime::utility::stream::size_type windowsFileReaderInputStream::getPosition() const +size_t windowsFileReaderInputStream::getPosition() const { DWORD dwCurPos = SetFilePointer(m_hFile, 0, NULL, FILE_CURRENT); if (dwCurPos == INVALID_SET_FILE_POINTER) windowsFileSystemFactory::reportError(m_path, GetLastError()); - return static_cast (dwCurPos); + return static_cast (dwCurPos); } -void windowsFileReaderInputStream::seek(const size_type pos) +void windowsFileReaderInputStream::seek(const size_t pos) { DWORD dwNewPos = SetFilePointer(m_hFile, (LONG)pos, NULL, FILE_BEGIN); @@ -530,7 +530,7 @@ windowsFileWriterOutputStream::~windowsFileWriterOutputStream() CloseHandle(m_hFile); } -void windowsFileWriterOutputStream::write(const value_type* const data, const size_type count) +void windowsFileWriterOutputStream::writeImpl(const byte_t* const data, const size_t count) { DWORD dwBytesWritten; if (!WriteFile(m_hFile, data, (DWORD)count, &dwBytesWritten, NULL)) diff --git a/src/platforms/windows/windowsHandler.cpp b/src/platforms/windows/windowsHandler.cpp index 5b9c37ce..9c96b271 100644 --- a/src/platforms/windows/windowsHandler.cpp +++ b/src/platforms/windows/windowsHandler.cpp @@ -206,7 +206,7 @@ static inline bool isFQDN(const vmime::string& str) if (utility::stringUtils::isStringEqualNoCase(str, "localhost", 9)) return false; - const vmime::string::size_type p = str.find_first_of("."); + const vmime::size_t p = str.find_first_of("."); return p != vmime::string::npos && p > 0 && p != str.length() - 1; } diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index 502d1067..2cad21c0 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -230,7 +230,7 @@ const string windowsSocket::getPeerName() const } -windowsSocket::size_type windowsSocket::getBlockSize() const +size_t windowsSocket::getBlockSize() const { return 16384; // 16 KB } @@ -238,12 +238,12 @@ windowsSocket::size_type windowsSocket::getBlockSize() const void windowsSocket::receive(vmime::string& buffer) { - const size_type size = receiveRaw(m_buffer, sizeof(m_buffer)); + const size_t size = receiveRaw(m_buffer, sizeof(m_buffer)); buffer = vmime::string(m_buffer, size); } -windowsSocket::size_type windowsSocket::receiveRaw(char* buffer, const size_type count) +size_t windowsSocket::receiveRaw(char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; @@ -307,15 +307,21 @@ windowsSocket::size_type windowsSocket::receiveRaw(char* buffer, const size_type void windowsSocket::send(const vmime::string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast (buffer.data()), buffer.length()); } -void windowsSocket::sendRaw(const char* buffer, const size_type count) +void windowsSocket::send(const char* str) +{ + sendRaw(reinterpret_cast (str), strlen(str)); +} + + +void windowsSocket::sendRaw(const char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; - size_type size = count; + size_t size = count; while (size > 0) { @@ -344,7 +350,7 @@ void windowsSocket::sendRaw(const char* buffer, const size_type count) } -windowsSocket::size_type windowsSocket::sendRawNonBlocking(const char* buffer, const size_type count) +size_t windowsSocket::sendRawNonBlocking(const char* buffer, const size_t count) { m_status &= ~STATUS_WOULDBLOCK; diff --git a/src/propertySet.cpp b/src/propertySet.cpp index 151c3e12..c22e79a6 100644 --- a/src/propertySet.cpp +++ b/src/propertySet.cpp @@ -131,7 +131,7 @@ void propertySet::parse(const string& props) { value.reserve(50); - const string::value_type quoteChar = *pos; + const char quoteChar = *pos; bool theEnd = false; bool escape = false; diff --git a/src/relay.cpp b/src/relay.cpp index 327118c5..e5d30c9e 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -59,12 +59,12 @@ relay::relay(const relay& r) */ void relay::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { - const string::value_type* const pend = buffer.data() + end; - const string::value_type* const pstart = buffer.data() + position; - const string::value_type* p = pend - 1; + const char* const pend = buffer.data() + end; + const char* const pstart = buffer.data() + position; + const char* p = pend - 1; // Find the beginning of the date part while (p >= pstart && *p != ';') @@ -107,7 +107,7 @@ void relay::parseImpl // A little hack for handling comments if (inComment) { - string::size_type par = word.find(')'); + size_t par = word.find(')'); if (par != string::npos) { @@ -202,7 +202,7 @@ void relay::parseImpl void relay::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { std::ostringstream oss; int count = 0; diff --git a/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp b/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp index 327ddefa..f96ddddb 100644 --- a/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp +++ b/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp @@ -92,11 +92,11 @@ void* X509Certificate_GnuTLS::getInternalData() shared_ptr X509Certificate::import(utility::inputStream& is) { byteArray bytes; - utility::stream::value_type chunk[4096]; + byte_t chunk[4096]; while (!is.eof()) { - const utility::stream::size_type len = is.read(chunk, sizeof(chunk)); + const size_t len = is.read(chunk, sizeof(chunk)); bytes.insert(bytes.end(), chunk, chunk + len); } @@ -146,7 +146,7 @@ void X509Certificate_GnuTLS::write gnutls_x509_crt_export(m_data->cert, fmt, &data[0], &dataSize); - os.write(reinterpret_cast (&data[0]), dataSize); + os.write(reinterpret_cast (&data[0]), dataSize); } diff --git a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp index 8c7174a0..5f81b2bf 100644 --- a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp +++ b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp @@ -171,11 +171,11 @@ shared_ptr X509Certificate_OpenSSL::importInternal(X509* cert) shared_ptr X509Certificate::import(utility::inputStream& is) { byteArray bytes; - utility::stream::value_type chunk[4096]; + byte_t chunk[4096]; while (!is.eof()) { - const int len = is.read(chunk, sizeof(chunk)); + const size_t len = is.read(chunk, sizeof(chunk)); bytes.insert(bytes.end(), chunk, chunk + len); } @@ -189,7 +189,7 @@ shared_ptr X509Certificate::import { shared_ptr cert = make_shared (); - BIO* membio = BIO_new_mem_buf(const_cast (data), length); + BIO* membio = BIO_new_mem_buf(const_cast (data), static_cast (length)); if (!PEM_read_bio_X509(membio, &(cert->m_data->cert), 0, 0)) { @@ -207,7 +207,7 @@ void X509Certificate_OpenSSL::write (utility::outputStream& os, const Format format) const { BIO* membio = 0; - int dataSize = 0; + long dataSize = 0; unsigned char* out = 0; if (format == FORMAT_DER) @@ -215,7 +215,7 @@ void X509Certificate_OpenSSL::write if ((dataSize = i2d_X509(m_data->cert, &out)) < 0) goto err; - os.write(reinterpret_cast (out), dataSize); + os.write(reinterpret_cast (out), dataSize); os.flush(); OPENSSL_free(out); } @@ -228,7 +228,7 @@ void X509Certificate_OpenSSL::write goto pem_err; dataSize = BIO_get_mem_data(membio, &out); - os.write(reinterpret_cast (out), dataSize); + os.write(reinterpret_cast (out), dataSize); os.flush(); BIO_vfree(membio); } @@ -281,7 +281,7 @@ bool X509Certificate_OpenSSL::checkIssuer(shared_ptr cer out = BIO_new(BIO_s_mem()); X509_NAME_print_ex(out, X509_get_issuer_name(m_data->cert), 0, XN_FLAG_RFC2253); - int n = BIO_get_mem_data(out, &issuer); + long n = BIO_get_mem_data(out, &issuer); vmime::string thisIssuerName((char*)issuer, n); BIO_free(out); diff --git a/src/security/digest/md5/md5MessageDigest.cpp b/src/security/digest/md5/md5MessageDigest.cpp index 88f9c9de..a83f0623 100644 --- a/src/security/digest/md5/md5MessageDigest.cpp +++ b/src/security/digest/md5/md5MessageDigest.cpp @@ -83,7 +83,7 @@ void md5MessageDigest::init() } -static void copyUint8Array(vmime_uint8* dest, const vmime_uint8* src, unsigned long count) +static void copyUint8Array(vmime_uint8* dest, const vmime_uint8* src, size_t count) { for ( ; count >= 4 ; count -= 4, dest += 4, src += 4) { @@ -104,7 +104,7 @@ static inline vmime_uint32 swapUint32(const vmime_uint32 D) } -static inline void swapUint32Array(vmime_uint32* buf, unsigned long words) +static inline void swapUint32Array(vmime_uint32* buf, size_t words) { for ( ; words >= 4 ; words -= 4, buf += 4) { @@ -131,17 +131,16 @@ void md5MessageDigest::update(const string& s) } -void md5MessageDigest::update(const byte_t* data, const unsigned long offset, - const unsigned long len) +void md5MessageDigest::update(const byte_t* data, const size_t offset, const size_t len) { update(data + offset, len); } -void md5MessageDigest::update(const byte_t* data, const unsigned long length) +void md5MessageDigest::update(const byte_t* data, const size_t length) { - const unsigned long avail = 64 - (m_byteCount & 0x3f); - unsigned long len = length; + const size_t avail = 64 - (m_byteCount & 0x3f); + size_t len = length; m_byteCount += len; @@ -177,7 +176,7 @@ void md5MessageDigest::finalize(const string& s) } -void md5MessageDigest::finalize(const byte_t* buffer, const unsigned long len) +void md5MessageDigest::finalize(const byte_t* buffer, const size_t len) { update(buffer, len); finalize(); @@ -185,7 +184,7 @@ void md5MessageDigest::finalize(const byte_t* buffer, const unsigned long len) void md5MessageDigest::finalize(const byte_t* buffer, - const unsigned long offset, const unsigned long len) + const size_t offset, const size_t len) { update(buffer, offset, len); finalize(); @@ -329,7 +328,7 @@ void md5MessageDigest::transform() } -int md5MessageDigest::getDigestLength() const +size_t md5MessageDigest::getDigestLength() const { return 16; } diff --git a/src/security/digest/messageDigest.cpp b/src/security/digest/messageDigest.cpp index 2cc11617..18fc8628 100644 --- a/src/security/digest/messageDigest.cpp +++ b/src/security/digest/messageDigest.cpp @@ -34,14 +34,14 @@ namespace digest { const string messageDigest::getHexDigest() const { const byte_t* hash = getDigest(); - const int len = getDigestLength(); + const size_t len = getDigestLength(); static const unsigned char hex[] = "0123456789abcdef"; std::ostringstream oss; oss.imbue(std::locale::classic()); - for (int i = 0 ; i < len ; ++i) + for (size_t i = 0 ; i < len ; ++i) { oss << hex[(hash[i] & 0xf0) >> 4]; oss << hex[(hash[i] & 0x0f)]; diff --git a/src/security/digest/sha1/sha1MessageDigest.cpp b/src/security/digest/sha1/sha1MessageDigest.cpp index e022eb8a..aa055af5 100644 --- a/src/security/digest/sha1/sha1MessageDigest.cpp +++ b/src/security/digest/sha1/sha1MessageDigest.cpp @@ -95,14 +95,14 @@ void sha1MessageDigest::update(const string& s) } -void sha1MessageDigest::update(const byte_t* buffer, const unsigned long offset, +void sha1MessageDigest::update(const byte_t* buffer, const size_t offset, const unsigned long len) { update(buffer + offset, len); } -void sha1MessageDigest::update(const byte_t* buffer, const unsigned long len) +void sha1MessageDigest::update(const byte_t* buffer, const size_t len) { unsigned int i, j; @@ -174,7 +174,7 @@ void sha1MessageDigest::finalize(const string& s) } -void sha1MessageDigest::finalize(const byte_t* buffer, const unsigned long len) +void sha1MessageDigest::finalize(const byte_t* buffer, const size_t len) { update(buffer, len); finalize(); @@ -182,7 +182,7 @@ void sha1MessageDigest::finalize(const byte_t* buffer, const unsigned long len) void sha1MessageDigest::finalize(const byte_t* buffer, - const unsigned long offset, const unsigned long len) + const size_t offset, const size_t len) { finalize(buffer + offset, len); } @@ -251,7 +251,7 @@ void sha1MessageDigest::transform } -int sha1MessageDigest::getDigestLength() const +size_t sha1MessageDigest::getDigestLength() const { return 20; } diff --git a/src/security/sasl/SASLContext.cpp b/src/security/sasl/SASLContext.cpp index c4d60bd9..3474cbeb 100644 --- a/src/security/sasl/SASLContext.cpp +++ b/src/security/sasl/SASLContext.cpp @@ -106,7 +106,7 @@ shared_ptr SASLContext::suggestMechanism } -void SASLContext::decodeB64(const string& input, byte_t** output, long* outputLen) +void SASLContext::decodeB64(const string& input, byte_t** output, size_t* outputLen) { string res; @@ -127,7 +127,7 @@ void SASLContext::decodeB64(const string& input, byte_t** output, long* outputLe } -const string SASLContext::encodeB64(const byte_t* input, const long inputLen) +const string SASLContext::encodeB64(const byte_t* input, const size_t inputLen) { string res; diff --git a/src/security/sasl/SASLSession.cpp b/src/security/sasl/SASLSession.cpp index 1bdd0889..087ef27b 100644 --- a/src/security/sasl/SASLSession.cpp +++ b/src/security/sasl/SASLSession.cpp @@ -99,8 +99,8 @@ shared_ptr SASLSession::getContext() bool SASLSession::evaluateChallenge - (const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen) + (const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen) { return m_mech->step(dynamicCast (shared_from_this()), challenge, challengeLen, response, responseLen); diff --git a/src/security/sasl/SASLSocket.cpp b/src/security/sasl/SASLSocket.cpp index 37e297dc..12d634c2 100644 --- a/src/security/sasl/SASLSocket.cpp +++ b/src/security/sasl/SASLSocket.cpp @@ -30,9 +30,12 @@ #include "vmime/security/sasl/SASLSocket.hpp" #include "vmime/security/sasl/SASLSession.hpp" +#include "vmime/utility/stringUtils.hpp" + #include "vmime/exception.hpp" #include +#include #include @@ -75,7 +78,7 @@ bool SASLSocket::isConnected() const } -SASLSocket::size_type SASLSocket::getBlockSize() const +size_t SASLSocket::getBlockSize() const { return m_wrapped->getBlockSize(); } @@ -95,17 +98,17 @@ const string SASLSocket::getPeerAddress() const void SASLSocket::receive(string& buffer) { - const size_type n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); + const size_t n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); - buffer = string(m_recvBuffer, n); + buffer = utility::stringUtils::makeStringFromBytes(m_recvBuffer, n); } -SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count) +size_t SASLSocket::receiveRaw(byte_t* buffer, const size_t count) { if (m_pendingLen != 0) { - const size_type copyLen = + const size_t copyLen = (count >= m_pendingLen ? m_pendingLen : count); std::copy(m_pendingBuffer + m_pendingPos, @@ -127,14 +130,13 @@ SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count return copyLen; } - const size_type n = m_wrapped->receiveRaw(buffer, count); + const size_t n = m_wrapped->receiveRaw(buffer, count); byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->decode - (m_session, reinterpret_cast (buffer), n, - &output, &outputLen); + (m_session, buffer, n, &output, &outputLen); // If we can not copy all decoded data into the output buffer, put // remaining data into a pending buffer for next calls to receive() @@ -161,23 +163,27 @@ SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count void SASLSocket::send(const string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast (buffer.data()), buffer.length()); } -void SASLSocket::sendRaw(const char* buffer, const size_type count) +void SASLSocket::send(const char* str) +{ + sendRaw(reinterpret_cast (str), strlen(str)); +} + + +void SASLSocket::sendRaw(const byte_t* buffer, const size_t count) { byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->encode - (m_session, reinterpret_cast (buffer), count, - &output, &outputLen); + (m_session, buffer, count, &output, &outputLen); try { - m_wrapped->sendRaw - (reinterpret_cast (output), outputLen); + m_wrapped->sendRaw(output, outputLen); } catch (...) { @@ -189,21 +195,19 @@ void SASLSocket::sendRaw(const char* buffer, const size_type count) } -SASLSocket::size_type SASLSocket::sendRawNonBlocking(const char* buffer, const size_type count) +size_t SASLSocket::sendRawNonBlocking(const byte_t* buffer, const size_t count) { byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->encode - (m_session, reinterpret_cast (buffer), count, - &output, &outputLen); + (m_session, buffer, count, &output, &outputLen); - size_type bytesSent = 0; + size_t bytesSent = 0; try { - bytesSent = m_wrapped->sendRawNonBlocking - (reinterpret_cast (output), outputLen); + bytesSent = m_wrapped->sendRawNonBlocking(output, outputLen); } catch (...) { diff --git a/src/security/sasl/builtinSASLMechanism.cpp b/src/security/sasl/builtinSASLMechanism.cpp index e7bd723e..e179e715 100644 --- a/src/security/sasl/builtinSASLMechanism.cpp +++ b/src/security/sasl/builtinSASLMechanism.cpp @@ -63,8 +63,8 @@ const string builtinSASLMechanism::getName() const bool builtinSASLMechanism::step - (shared_ptr sess, const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen) + (shared_ptr sess, const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen) { char* output = 0; size_t outputLen = 0; @@ -121,8 +121,8 @@ bool builtinSASLMechanism::isComplete() const void builtinSASLMechanism::encode - (shared_ptr sess, const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) + (shared_ptr sess, const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) { char* coutput = 0; size_t coutputLen = 0; @@ -154,8 +154,8 @@ void builtinSASLMechanism::encode void builtinSASLMechanism::decode - (shared_ptr sess, const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) + (shared_ptr sess, const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) { char* coutput = 0; size_t coutputLen = 0; diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp index b84fdae5..8676cc34 100644 --- a/src/streamContentHandler.cpp +++ b/src/streamContentHandler.cpp @@ -40,7 +40,7 @@ streamContentHandler::streamContentHandler() streamContentHandler::streamContentHandler(shared_ptr is, - const utility::stream::size_type length, const vmime::encoding& enc) + const size_t length, const vmime::encoding& enc) { setData(is, length, enc); } @@ -52,7 +52,7 @@ streamContentHandler::~streamContentHandler() streamContentHandler::streamContentHandler(const streamContentHandler& cts) - : contentHandler(), m_encoding(cts.m_encoding), m_contentType(cts.m_contentType), + : contentHandler(), m_contentType(cts.m_contentType), m_encoding(cts.m_encoding), m_stream(cts.m_stream), m_length(cts.m_length) { } @@ -77,7 +77,7 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler void streamContentHandler::setData(shared_ptr is, - const utility::stream::size_type length, const vmime::encoding& enc) + const size_t length, const vmime::encoding& enc) { m_encoding = enc; m_length = length; @@ -86,7 +86,7 @@ void streamContentHandler::setData(shared_ptr is, void streamContentHandler::generate(utility::outputStream& os, const vmime::encoding& enc, - const string::size_type maxLineLength) const + const size_t maxLineLength) const { if (!m_stream) return; @@ -185,7 +185,7 @@ void streamContentHandler::extractRaw(utility::outputStream& os, } -string::size_type streamContentHandler::getLength() const +size_t streamContentHandler::getLength() const { return (m_length); } diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp index 0fb032dd..9a66663c 100644 --- a/src/stringContentHandler.cpp +++ b/src/stringContentHandler.cpp @@ -56,8 +56,8 @@ stringContentHandler::stringContentHandler(const utility::stringProxy& str, cons } -stringContentHandler::stringContentHandler(const string& buffer, const string::size_type start, - const string::size_type end, const vmime::encoding& enc) +stringContentHandler::stringContentHandler(const string& buffer, const size_t start, + const size_t end, const vmime::encoding& enc) : m_encoding(enc), m_string(buffer, start, end) { } @@ -98,8 +98,8 @@ void stringContentHandler::setData(const string& buffer, const vmime::encoding& } -void stringContentHandler::setData(const string& buffer, const string::size_type start, - const string::size_type end, const vmime::encoding& enc) +void stringContentHandler::setData(const string& buffer, const size_t start, + const size_t end, const vmime::encoding& enc) { m_encoding = enc; m_string.set(buffer, start, end); @@ -114,7 +114,7 @@ stringContentHandler& stringContentHandler::operator=(const string& buffer) void stringContentHandler::generate(utility::outputStream& os, - const vmime::encoding& enc, const string::size_type maxLineLength) const + const vmime::encoding& enc, const size_t maxLineLength) const { // Managed data is already encoded if (isEncoded()) @@ -191,7 +191,7 @@ void stringContentHandler::extractRaw(utility::outputStream& os, } -string::size_type stringContentHandler::getLength() const +size_t stringContentHandler::getLength() const { return (m_string.length()); } diff --git a/src/text.cpp b/src/text.cpp index 987510c1..08fc9ba9 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -68,12 +68,12 @@ text::~text() void text::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { removeAllWords(); - string::size_type newPos; + size_t newPos; const std::vector > words = word::parseMultiple(ctx, buffer, position, end, &newPos); @@ -88,7 +88,7 @@ void text::parseImpl void text::generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { encodeAndFold(ctx, os, curLinePos, newLinePos, 0); } @@ -251,8 +251,8 @@ shared_ptr text::newFromString(const string& in, const charset& ch) void text::createFromString(const string& in, const charset& ch) { - string::size_type asciiCount = 0; - string::size_type asciiPercent = 0; + size_t asciiCount = 0; + size_t asciiPercent = 0; removeAllWords(); @@ -281,7 +281,7 @@ void text::createFromString(const string& in, const charset& ch) bool prevIs8bit = false; // is previous word 8-bit? unsigned int count = 0; // total number of words - for (string::size_type end = in.size(), pos = 0, start = 0 ; ; ) + for (size_t end = in.size(), pos = 0, start = 0 ; ; ) { if (pos == end || parserHelpers::isSpace(in[pos])) { @@ -352,9 +352,9 @@ void text::createFromString(const string& in, const charset& ch) void text::encodeAndFold (const generationContext& ctx, utility::outputStream& os, - const string::size_type firstLineOffset, string::size_type* lastLineLength, const int flags) const + const size_t firstLineOffset, size_t* lastLineLength, const int flags) const { - string::size_type curLineLength = firstLineOffset; + size_t curLineLength = firstLineOffset; word::generatorState state; for (size_t wi = 0 ; wi < getWordCount() ; ++wi) diff --git a/src/utility/encoder/b64Encoder.cpp b/src/utility/encoder/b64Encoder.cpp index 20e16b98..274c23c0 100644 --- a/src/utility/encoder/b64Encoder.cpp +++ b/src/utility/encoder/b64Encoder.cpp @@ -70,34 +70,34 @@ const unsigned char b64Encoder::sm_decodeMap[256] = }; #ifndef VMIME_BUILDING_DOC - #define B64_WRITE(s, x, l) s.write(reinterpret_cast (x), l) + #define B64_WRITE(s, x, l) s.write(reinterpret_cast (x), l) #endif // VMIME_BUILDING_DOC -utility::stream::size_type b64Encoder::encode(utility::inputStream& in, +size_t b64Encoder::encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... - const string::size_type propMaxLineLength = - getProperties().getProperty ("maxlinelength", static_cast (-1)); + const size_t propMaxLineLength = + getProperties().getProperty ("maxlinelength", static_cast (-1)); - const bool cutLines = (propMaxLineLength != static_cast (-1)); - const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast (76)); + const bool cutLines = (propMaxLineLength != static_cast (-1)); + const size_t maxLineLength = std::min(propMaxLineLength, static_cast (76)); // Process data - utility::stream::value_type buffer[65536]; - utility::stream::size_type bufferLength = 0; - utility::stream::size_type bufferPos = 0; + byte_t buffer[65536]; + size_t bufferLength = 0; + size_t bufferPos = 0; - unsigned char bytes[3]; - unsigned char output[4]; + byte_t bytes[3]; + byte_t output[4]; - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; - string::size_type curCol = 0; + size_t curCol = 0; if (progress) progress->start(0); @@ -191,21 +191,21 @@ utility::stream::size_type b64Encoder::encode(utility::inputStream& in, } -utility::stream::size_type b64Encoder::decode(utility::inputStream& in, +size_t b64Encoder::decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... // Process the data - char buffer[16384]; - utility::stream::size_type bufferLength = 0; - utility::stream::size_type bufferPos = 0; + byte_t buffer[16384]; + size_t bufferLength = 0; + size_t bufferPos = 0; - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; - unsigned char bytes[4]; - unsigned char output[3]; + byte_t bytes[4]; + byte_t output[3]; if (progress) progress->start(0); @@ -234,7 +234,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, while (count < 4 && bufferPos < bufferLength) { - const unsigned char c = buffer[bufferPos++]; + const byte_t c = buffer[bufferPos++]; if (!parserHelpers::isSpace(c)) bytes[count++] = c; @@ -250,7 +250,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, while (count < 4 && bufferPos < bufferLength) { - const unsigned char c = buffer[bufferPos++]; + const byte_t c = buffer[bufferPos++]; if (!parserHelpers::isSpace(c)) bytes[count++] = c; @@ -259,13 +259,13 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, } // Decode the bytes - unsigned char c1 = bytes[0]; - unsigned char c2 = bytes[1]; + byte_t c1 = bytes[0]; + byte_t c2 = bytes[1]; if (c1 == '=' || c2 == '=') // end break; - output[0] = static_cast ((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4)); + output[0] = static_cast ((sm_decodeMap[c1] << 2) | ((sm_decodeMap[c2] & 0x30) >> 4)); c1 = bytes[2]; @@ -276,7 +276,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, break; } - output[1] = static_cast (((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2)); + output[1] = static_cast (((sm_decodeMap[c2] & 0xf) << 4) | ((sm_decodeMap[c1] & 0x3c) >> 2)); c2 = bytes[3]; @@ -287,7 +287,7 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, break; } - output[2] = static_cast (((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]); + output[2] = static_cast (((sm_decodeMap[c1] & 0x03) << 6) | sm_decodeMap[c2]); B64_WRITE(out, output, 3); total += 3; @@ -304,13 +304,13 @@ utility::stream::size_type b64Encoder::decode(utility::inputStream& in, } -utility::stream::size_type b64Encoder::getEncodedSize(const utility::stream::size_type n) const +size_t b64Encoder::getEncodedSize(const size_t n) const { - const string::size_type propMaxLineLength = - getProperties().getProperty ("maxlinelength", static_cast (-1)); + const size_t propMaxLineLength = + getProperties().getProperty ("maxlinelength", static_cast (-1)); - const bool cutLines = (propMaxLineLength != static_cast (-1)); - const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast (76)); + const bool cutLines = (propMaxLineLength != static_cast (-1)); + const size_t maxLineLength = std::min(propMaxLineLength, static_cast (76)); return (n * 4) / 3 // 3 bytes of input provide 4 bytes of output + (cutLines ? (n / maxLineLength) * 2 : 0) // CRLF (2 bytes) for each line. @@ -318,7 +318,7 @@ utility::stream::size_type b64Encoder::getEncodedSize(const utility::stream::siz } -utility::stream::size_type b64Encoder::getDecodedSize(const utility::stream::size_type n) const +size_t b64Encoder::getDecodedSize(const size_t n) const { // 4 bytes of input provide 3 bytes of output return (n * 3) / 4; diff --git a/src/utility/encoder/noopEncoder.cpp b/src/utility/encoder/noopEncoder.cpp index cf72a4f6..3d991b5d 100644 --- a/src/utility/encoder/noopEncoder.cpp +++ b/src/utility/encoder/noopEncoder.cpp @@ -36,13 +36,13 @@ noopEncoder::noopEncoder() } -utility::stream::size_type noopEncoder::encode(utility::inputStream& in, +size_t noopEncoder::encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... // No encoding performed - utility::stream::size_type res = 0; + size_t res = 0; if (progress) res = utility::bufferedStreamCopy(in, out, 0, progress); @@ -53,13 +53,13 @@ utility::stream::size_type noopEncoder::encode(utility::inputStream& in, } -utility::stream::size_type noopEncoder::decode(utility::inputStream& in, +size_t noopEncoder::decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... // No decoding performed - utility::stream::size_type res = 0; + size_t res = 0; if (progress) res = utility::bufferedStreamCopy(in, out, 0, progress); @@ -70,13 +70,13 @@ utility::stream::size_type noopEncoder::decode(utility::inputStream& in, } -utility::stream::size_type noopEncoder::getEncodedSize(const utility::stream::size_type n) const +size_t noopEncoder::getEncodedSize(const size_t n) const { return n; } -utility::stream::size_type noopEncoder::getDecodedSize(const utility::stream::size_type n) const +size_t noopEncoder::getDecodedSize(const size_t n) const { return n; } diff --git a/src/utility/encoder/qpEncoder.cpp b/src/utility/encoder/qpEncoder.cpp index 1768818c..c77b5163 100644 --- a/src/utility/encoder/qpEncoder.cpp +++ b/src/utility/encoder/qpEncoder.cpp @@ -69,7 +69,7 @@ const unsigned char qpEncoder::sm_hexDigits[] = "0123456789ABCDEF"; // This is a quick lookup table: // '1' means "encode", '0' means "no encoding" // -const unsigned char qpEncoder::sm_RFC2047EncodeTable[] = +const vmime_uint8 qpEncoder::sm_RFC2047EncodeTable[] = { /* 0 NUL */ 1, /* 1 SOH */ 1, /* 2 STX */ 1, /* 3 ETX */ 1, /* 4 EOT */ 1, /* 5 ENQ */ 1, /* 6 ACK */ 1, /* 7 BEL */ 1, /* 8 BS */ 1, /* 9 TAB */ 1, /* 10 LF */ 1, /* 11 VT */ 1, @@ -97,7 +97,7 @@ const unsigned char qpEncoder::sm_RFC2047EncodeTable[] = // Hex-decoding table -const unsigned char qpEncoder::sm_hexDecodeTable[256] = +const vmime_uint8 qpEncoder::sm_hexDecodeTable[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -119,14 +119,14 @@ const unsigned char qpEncoder::sm_hexDecodeTable[256] = // static -bool qpEncoder::RFC2047_isEncodingNeededForChar(const unsigned char c) +bool qpEncoder::RFC2047_isEncodingNeededForChar(const byte_t c) { return (c >= 128 || sm_RFC2047EncodeTable[c] != 0); } // static -int qpEncoder::RFC2047_getEncodedLength(const unsigned char c) +int qpEncoder::RFC2047_getEncodedLength(const byte_t c) { if (c >= 128 || sm_RFC2047EncodeTable[c] != 0) { @@ -157,37 +157,37 @@ int qpEncoder::RFC2047_getEncodedLength(const unsigned char c) outBufferPos += 3; \ curCol += 3 -#define QP_WRITE(s, x, l) s.write(reinterpret_cast (x), l) +#define QP_WRITE(s, x, l) s.write(reinterpret_cast (x), l) #endif // VMIME_BUILDING_DOC -utility::stream::size_type qpEncoder::encode(utility::inputStream& in, +size_t qpEncoder::encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... - const string::size_type propMaxLineLength = - getProperties().getProperty ("maxlinelength", static_cast (-1)); + const size_t propMaxLineLength = + getProperties().getProperty ("maxlinelength", static_cast (-1)); const bool rfc2047 = getProperties().getProperty ("rfc2047", false); const bool text = getProperties().getProperty ("text", false); // binary mode by default - const bool cutLines = (propMaxLineLength != static_cast (-1)); - const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast (74)); + const bool cutLines = (propMaxLineLength != static_cast (-1)); + const size_t maxLineLength = std::min(propMaxLineLength, static_cast (74)); // Process the data - char buffer[16384]; - utility::stream::size_type bufferLength = 0; - utility::stream::size_type bufferPos = 0; + byte_t buffer[16384]; + size_t bufferLength = 0; + size_t bufferPos = 0; - string::size_type curCol = 0; + size_t curCol = 0; - unsigned char outBuffer[16384]; - int outBufferPos = 0; + byte_t outBuffer[16384]; + size_t outBufferPos = 0; - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; if (progress) progress->start(0); @@ -215,7 +215,7 @@ utility::stream::size_type qpEncoder::encode(utility::inputStream& in, } // Get the next char and encode it - const unsigned char c = static_cast (buffer[bufferPos++]); + const byte_t c = buffer[bufferPos++]; if (rfc2047) { @@ -371,7 +371,7 @@ utility::stream::size_type qpEncoder::encode(utility::inputStream& in, } -utility::stream::size_type qpEncoder::decode(utility::inputStream& in, +size_t qpEncoder::decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... @@ -379,20 +379,20 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in, // Process the data const bool rfc2047 = getProperties().getProperty ("rfc2047", false); - char buffer[16384]; - utility::stream::size_type bufferLength = 0; - utility::stream::size_type bufferPos = 0; + byte_t buffer[16384]; + size_t bufferLength = 0; + size_t bufferPos = 0; - unsigned char outBuffer[16384]; - int outBufferPos = 0; + byte_t outBuffer[16384]; + size_t outBufferPos = 0; - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; while (bufferPos < bufferLength || !in.eof()) { // Flush current output buffer - if (outBufferPos >= static_cast (sizeof(outBuffer))) + if (outBufferPos >= sizeof(outBuffer)) { QP_WRITE(out, outBuffer, outBufferPos); @@ -412,7 +412,7 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in, } // Decode the next sequence (hex-encoded byte or printable character) - unsigned char c = static_cast (buffer[bufferPos++]); + byte_t c = buffer[bufferPos++]; ++inTotal; @@ -428,7 +428,7 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in, if (bufferPos < bufferLength) { - c = static_cast (buffer[bufferPos++]); + c = buffer[bufferPos++]; ++inTotal; @@ -468,11 +468,11 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in, if (bufferPos < bufferLength) { - const unsigned char next = static_cast (buffer[bufferPos++]); + const byte_t next = buffer[bufferPos++]; ++inTotal; - const unsigned char value = static_cast + const byte_t value = static_cast (sm_hexDecodeTable[c] * 16 + sm_hexDecodeTable[next]); outBuffer[outBufferPos++] = value; @@ -532,13 +532,13 @@ utility::stream::size_type qpEncoder::decode(utility::inputStream& in, } -utility::stream::size_type qpEncoder::getEncodedSize(const utility::stream::size_type n) const +size_t qpEncoder::getEncodedSize(const size_t n) const { - const string::size_type propMaxLineLength = - getProperties().getProperty ("maxlinelength", static_cast (-1)); + const size_t propMaxLineLength = + getProperties().getProperty ("maxlinelength", static_cast (-1)); - const bool cutLines = (propMaxLineLength != static_cast (-1)); - const string::size_type maxLineLength = std::min(propMaxLineLength, static_cast (74)); + const bool cutLines = (propMaxLineLength != static_cast (-1)); + const size_t maxLineLength = std::min(propMaxLineLength, static_cast (74)); // Worst cast: 1 byte of input provide 3 bytes of output // Count CRLF (2 bytes) for each line. @@ -546,7 +546,7 @@ utility::stream::size_type qpEncoder::getEncodedSize(const utility::stream::size } -utility::stream::size_type qpEncoder::getDecodedSize(const utility::stream::size_type n) const +size_t qpEncoder::getDecodedSize(const size_t n) const { // Worst case: 1 byte of input equals 1 byte of output return n; diff --git a/src/utility/encoder/uuEncoder.cpp b/src/utility/encoder/uuEncoder.cpp index 3f751d3b..0375a397 100644 --- a/src/utility/encoder/uuEncoder.cpp +++ b/src/utility/encoder/uuEncoder.cpp @@ -52,19 +52,19 @@ const std::vector uuEncoder::getAvailableProperties() const // This is the character encoding function to make a character printable -static inline unsigned char UUENCODE(const unsigned long c) +static inline byte_t UUENCODE(const unsigned int c) { - return static_cast ((c & 077) + ' '); + return static_cast ((c & 077) + ' '); } // Single character decoding -static inline unsigned char UUDECODE(const unsigned long c) +static inline unsigned int UUDECODE(const unsigned int c) { - return static_cast ((c - ' ') & 077); + return (c - ' ') & 077; } -utility::stream::size_type uuEncoder::encode(utility::inputStream& in, +size_t uuEncoder::encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... @@ -72,12 +72,11 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in, const string propFilename = getProperties().getProperty ("filename", ""); const string propMode = getProperties().getProperty ("mode", "644"); - const string::size_type maxLineLength = - std::min(getProperties().getProperty ("maxlinelength", 46), - static_cast (46)); + const size_t maxLineLength = + std::min(getProperties().getProperty ("maxlinelength", 46), static_cast (46)); - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; // Output the prelude text ("begin [mode] [filename]") out << "begin"; @@ -92,8 +91,8 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in, total += 7; // Process the data - utility::stream::value_type inBuffer[64]; - utility::stream::value_type outBuffer[64]; + byte_t inBuffer[64]; + byte_t outBuffer[64]; if (progress) progress->start(0); @@ -103,17 +102,17 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in, // Process up to 45 characters per line std::fill(inBuffer, inBuffer + sizeof(inBuffer), 0); - const utility::stream::size_type inLength = in.read(inBuffer, maxLineLength - 1); + const size_t inLength = in.read(inBuffer, maxLineLength - 1); - outBuffer[0] = UUENCODE(inLength); // Line length + outBuffer[0] = UUENCODE(static_cast (inLength)); // Line length - utility::stream::size_type j = 1; + size_t j = 1; - for (utility::stream::size_type i = 0 ; i < inLength ; i += 3, j += 4) + for (size_t i = 0 ; i < inLength ; i += 3, j += 4) { - const unsigned char c1 = static_cast (inBuffer[i]); - const unsigned char c2 = static_cast (inBuffer[i + 1]); - const unsigned char c3 = static_cast (inBuffer[i + 2]); + const byte_t c1 = inBuffer[i]; + const byte_t c2 = inBuffer[i + 1]; + const byte_t c3 = inBuffer[i + 2]; outBuffer[j] = UUENCODE(c1 >> 2); outBuffer[j + 1] = UUENCODE(((c1 << 4) & 060) | ((c2 >> 4) & 017)); @@ -143,17 +142,17 @@ utility::stream::size_type uuEncoder::encode(utility::inputStream& in, } -utility::stream::size_type uuEncoder::decode(utility::inputStream& in, +size_t uuEncoder::decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress) { in.reset(); // may not work... // Process the data - utility::stream::value_type inBuffer[64]; - utility::stream::value_type outBuffer[64]; + byte_t inBuffer[64]; + byte_t outBuffer[64]; - utility::stream::size_type total = 0; - utility::stream::size_type inTotal = 0; + size_t total = 0; + size_t inTotal = 0; bool stop = false; @@ -165,15 +164,14 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, while (!stop && !in.eof()) { // Get the line length - utility::stream::value_type lengthChar; + byte_t lengthChar; if (in.read(&lengthChar, 1) == 0) break; - const utility::stream::size_type outLength = UUDECODE(lengthChar); - const utility::stream::size_type inLength = - std::min((outLength * 4) / 3, static_cast (64)); - utility::stream::size_type inPos = 0; + const size_t outLength = UUDECODE(lengthChar); + const size_t inLength = std::min((outLength * 4) / 3, static_cast (64)); + size_t inPos = 0; switch (lengthChar) { @@ -199,10 +197,10 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, { inTotal += 5; - utility::stream::value_type c = 0; + byte_t c = 0; - utility::stream::size_type count = 0; - utility::stream::value_type buffer[512]; + size_t count = 0; + byte_t buffer[512]; while (count < sizeof(buffer) - 1 && in.read(&c, 1) == 1) { @@ -229,11 +227,11 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, { buffer[count] = '\0'; - utility::stream::value_type* p = buffer; + byte_t* p = buffer; while (*p && parserHelpers::isSpace(*p)) ++p; - utility::stream::value_type* modeStart = buffer; + byte_t* modeStart = buffer; while (*p && !parserHelpers::isSpace(*p)) ++p; @@ -241,7 +239,7 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, while (*p && parserHelpers::isSpace(*p)) ++p; - utility::stream::value_type* filenameStart = buffer; + byte_t* filenameStart = buffer; while (*p && !(*p == '\r' || *p == '\n')) ++p; @@ -289,22 +287,21 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, inTotal += (inLength - inPos); // Decode data - for (utility::stream::size_type i = 0, j = 0 ; i < inLength ; i += 4, j += 3) + for (size_t i = 0, j = 0 ; i < inLength ; i += 4, j += 3) { - const unsigned char c1 = static_cast (inBuffer[i]); - const unsigned char c2 = static_cast (inBuffer[i + 1]); - const unsigned char c3 = static_cast (inBuffer[i + 2]); - const unsigned char c4 = static_cast (inBuffer[i + 3]); + const byte_t c1 = inBuffer[i]; + const byte_t c2 = inBuffer[i + 1]; + const byte_t c3 = inBuffer[i + 2]; + const byte_t c4 = inBuffer[i + 3]; - const utility::stream::size_type n = - std::min(inLength - i, static_cast (3)); + const size_t n = std::min(inLength - i, static_cast (3)); switch (n) { default: - case 3: outBuffer[j + 2] = static_cast (UUDECODE(c3) << 6 | UUDECODE(c4)); - case 2: outBuffer[j + 1] = static_cast (UUDECODE(c2) << 4 | UUDECODE(c3) >> 2); - case 1: outBuffer[j] = static_cast (UUDECODE(c1) << 2 | UUDECODE(c2) >> 4); + case 3: outBuffer[j + 2] = static_cast (UUDECODE(c3) << 6 | UUDECODE(c4)); + case 2: outBuffer[j + 1] = static_cast (UUDECODE(c2) << 4 | UUDECODE(c3) >> 2); + case 1: outBuffer[j] = static_cast (UUDECODE(c1) << 2 | UUDECODE(c2) >> 4); case 0: break; } @@ -326,7 +323,7 @@ utility::stream::size_type uuEncoder::decode(utility::inputStream& in, } -utility::stream::size_type uuEncoder::getEncodedSize(const utility::stream::size_type n) const +size_t uuEncoder::getEncodedSize(const size_t n) const { // 3 bytes of input provide 4 bytes of output. // Count CRLF (2 bytes) for each line of 45 characters. @@ -335,7 +332,7 @@ utility::stream::size_type uuEncoder::getEncodedSize(const utility::stream::size } -utility::stream::size_type uuEncoder::getDecodedSize(const utility::stream::size_type n) const +size_t uuEncoder::getDecodedSize(const size_t n) const { // 4 bytes of input provide 3 bytes of output return (n * 3) / 4; diff --git a/src/utility/filteredStream.cpp b/src/utility/filteredStream.cpp index ecc2eae2..bb705162 100644 --- a/src/utility/filteredStream.cpp +++ b/src/utility/filteredStream.cpp @@ -32,7 +32,7 @@ namespace utility { // filteredInputStream -stream::size_type filteredInputStream::getBlockSize() +size_t filteredInputStream::getBlockSize() { return std::min(inputStream::getBlockSize(), getPreviousInputStream().getBlockSize()); } @@ -40,7 +40,7 @@ stream::size_type filteredInputStream::getBlockSize() // filteredOutputStream -stream::size_type filteredOutputStream::getBlockSize() +size_t filteredOutputStream::getBlockSize() { return std::min(outputStream::getBlockSize(), getNextOutputStream().getBlockSize()); } @@ -75,26 +75,26 @@ void dotFilteredInputStream::reset() } -stream::size_type dotFilteredInputStream::read(value_type* const data, const size_type count) +size_t dotFilteredInputStream::read(byte_t* const data, const size_t count) { - const stream::size_type read = m_stream.read(data, count); + const size_t read = m_stream.read(data, count); - const value_type* readPtr = data; - value_type* writePtr = data; + const byte_t* readPtr = data; + byte_t* writePtr = data; - const value_type* end = data + read; + const byte_t* end = data + read; - stream::size_type written = 0; + size_t written = 0; // Replace "\n.." with "\n." while (readPtr < end) { if (*readPtr == '.') { - const value_type prevChar2 = + const byte_t prevChar2 = (readPtr == data + 1 ? m_previousChar1 : readPtr == data ? m_previousChar2 : *(readPtr - 2)); - const value_type prevChar1 = + const byte_t prevChar1 = (readPtr == data ? m_previousChar1 : *(readPtr - 1)); if (prevChar2 == '\n' && prevChar1 == '.') @@ -127,7 +127,7 @@ stream::size_type dotFilteredInputStream::read(value_type* const data, const siz } -stream::size_type dotFilteredInputStream::skip(const size_type /* count */) +size_t dotFilteredInputStream::skip(const size_t /* count */) { // Skipping bytes is not supported return 0; @@ -148,15 +148,15 @@ outputStream& dotFilteredOutputStream::getNextOutputStream() } -void dotFilteredOutputStream::write - (const value_type* const data, const size_type count) +void dotFilteredOutputStream::writeImpl + (const byte_t* const data, const size_t count) { if (count == 0) return; - const value_type* pos = data; - const value_type* end = data + count; - const value_type* start = data; + const byte_t* pos = data; + const byte_t* end = data + count; + const byte_t* start = data; if (m_previousChar == '.') { @@ -172,7 +172,7 @@ void dotFilteredOutputStream::write // Replace "\n." with "\n.." while ((pos = std::find(pos, end, '.')) != end) { - const value_type previousChar = + const byte_t previousChar = (pos == data ? m_previousChar : *(pos - 1)); if (previousChar == '\n') @@ -224,15 +224,15 @@ outputStream& CRLFToLFFilteredOutputStream::getNextOutputStream() } -void CRLFToLFFilteredOutputStream::write - (const value_type* const data, const size_type count) +void CRLFToLFFilteredOutputStream::writeImpl + (const byte_t* const data, const size_t count) { if (count == 0) return; - const value_type* pos = data; - const value_type* end = data + count; - const value_type* start = data; + const byte_t* pos = data; + const byte_t* end = data + count; + const byte_t* start = data; // Warning: if the whole buffer finishes with '\r', this // last character will not be written back if flush() is @@ -249,7 +249,7 @@ void CRLFToLFFilteredOutputStream::write // Replace "\r\n" (CRLF) with "\n" (LF) while ((pos = std::find(pos, end, '\n')) != end) { - const value_type previousChar = + const byte_t previousChar = (pos == data ? m_previousChar : *(pos - 1)); if (previousChar == '\r') @@ -300,8 +300,8 @@ outputStream& LFToCRLFFilteredOutputStream::getNextOutputStream() } -void LFToCRLFFilteredOutputStream::write - (const value_type* const data, const size_type count) +void LFToCRLFFilteredOutputStream::writeImpl + (const byte_t* const data, const size_t count) { if (count == 0) return; @@ -309,10 +309,10 @@ void LFToCRLFFilteredOutputStream::write string buffer; buffer.reserve(count); - const value_type* pos = data; - const value_type* end = data + count; + const byte_t* pos = data; + const byte_t* end = data + count; - value_type previousChar = m_previousChar; + byte_t previousChar = m_previousChar; while (pos < end) { @@ -360,8 +360,8 @@ void LFToCRLFFilteredOutputStream::flush() // stopSequenceFilteredInputStream <1> template <> -stream::size_type stopSequenceFilteredInputStream <1>::read - (value_type* const data, const size_type count) +size_t stopSequenceFilteredInputStream <1>::read + (byte_t* const data, const size_t count) { if (eof() || m_stream.eof()) { @@ -369,10 +369,10 @@ stream::size_type stopSequenceFilteredInputStream <1>::read return 0; } - const size_type read = m_stream.read(data, count); - value_type* end = data + read; + const size_t read = m_stream.read(data, count); + byte_t* end = data + read; - value_type* pos = std::find(data, end, m_sequence[0]); + byte_t* pos = std::find(data, end, m_sequence[0]); if (pos == end) { diff --git a/src/utility/inputStreamAdapter.cpp b/src/utility/inputStreamAdapter.cpp index a9ce79f3..c0b06be4 100644 --- a/src/utility/inputStreamAdapter.cpp +++ b/src/utility/inputStreamAdapter.cpp @@ -48,16 +48,16 @@ void inputStreamAdapter::reset() } -stream::size_type inputStreamAdapter::read - (value_type* const data, const size_type count) +size_t inputStreamAdapter::read + (byte_t* const data, const size_t count) { m_stream.exceptions(std::ios_base::badbit); - m_stream.read(data, count); + m_stream.read(reinterpret_cast (data), count); return (m_stream.gcount()); } -stream::size_type inputStreamAdapter::skip(const size_type count) +size_t inputStreamAdapter::skip(const size_t count) { m_stream.exceptions(std::ios_base::badbit); m_stream.ignore(count); @@ -65,13 +65,13 @@ stream::size_type inputStreamAdapter::skip(const size_type count) } -stream::size_type inputStreamAdapter::getPosition() const +size_t inputStreamAdapter::getPosition() const { return m_stream.tellg(); } -void inputStreamAdapter::seek(const size_type pos) +void inputStreamAdapter::seek(const size_t pos) { m_stream.clear(); m_stream.seekg(pos, std::ios_base::beg); diff --git a/src/utility/inputStreamByteBufferAdapter.cpp b/src/utility/inputStreamByteBufferAdapter.cpp index e55fd47e..c270ea56 100644 --- a/src/utility/inputStreamByteBufferAdapter.cpp +++ b/src/utility/inputStreamByteBufferAdapter.cpp @@ -28,7 +28,7 @@ namespace vmime { namespace utility { -inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length) +inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_t length) : m_buffer(buffer), m_length(length), m_pos(0) { } @@ -46,10 +46,10 @@ void inputStreamByteBufferAdapter::reset() } -stream::size_type inputStreamByteBufferAdapter::read - (value_type* const data, const size_type count) +size_t inputStreamByteBufferAdapter::read + (byte_t* const data, const size_t count) { - const size_type remaining = m_length - m_pos; + const size_t remaining = m_length - m_pos; if (remaining < count) { @@ -68,9 +68,9 @@ stream::size_type inputStreamByteBufferAdapter::read } -stream::size_type inputStreamByteBufferAdapter::skip(const size_type count) +size_t inputStreamByteBufferAdapter::skip(const size_t count) { - const size_type remaining = m_length - m_pos; + const size_t remaining = m_length - m_pos; if (remaining < count) { @@ -85,13 +85,13 @@ stream::size_type inputStreamByteBufferAdapter::skip(const size_type count) } -stream::size_type inputStreamByteBufferAdapter::getPosition() const +size_t inputStreamByteBufferAdapter::getPosition() const { return m_pos; } -void inputStreamByteBufferAdapter::seek(const size_type pos) +void inputStreamByteBufferAdapter::seek(const size_t pos) { if (pos <= m_length) m_pos = pos; diff --git a/src/utility/inputStreamSocketAdapter.cpp b/src/utility/inputStreamSocketAdapter.cpp index 095522d6..d78855eb 100644 --- a/src/utility/inputStreamSocketAdapter.cpp +++ b/src/utility/inputStreamSocketAdapter.cpp @@ -53,22 +53,22 @@ void inputStreamSocketAdapter::reset() } -stream::size_type inputStreamSocketAdapter::read - (value_type* const data, const size_type count) +size_t inputStreamSocketAdapter::read + (byte_t* const data, const size_t count) { return m_socket.receiveRaw(data, count); } -stream::size_type inputStreamSocketAdapter::skip - (const size_type /* count */) +size_t inputStreamSocketAdapter::skip + (const size_t /* count */) { // Not supported return 0; } -stream::size_type inputStreamSocketAdapter::getBlockSize() +size_t inputStreamSocketAdapter::getBlockSize() { return m_socket.getBlockSize(); } diff --git a/src/utility/inputStreamStringAdapter.cpp b/src/utility/inputStreamStringAdapter.cpp index c6bcdf49..9b897b97 100644 --- a/src/utility/inputStreamStringAdapter.cpp +++ b/src/utility/inputStreamStringAdapter.cpp @@ -35,7 +35,7 @@ inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer) inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer, - const string::size_type begin, const string::size_type end) + const size_t begin, const size_t end) : m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin) { } @@ -53,12 +53,12 @@ void inputStreamStringAdapter::reset() } -stream::size_type inputStreamStringAdapter::read - (value_type* const data, const size_type count) +size_t inputStreamStringAdapter::read + (byte_t* const data, const size_t count) { if (m_pos + count >= m_end) { - const size_type remaining = m_end - m_pos; + const size_t remaining = m_end - m_pos; std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data); m_pos = m_end; @@ -73,11 +73,11 @@ stream::size_type inputStreamStringAdapter::read } -stream::size_type inputStreamStringAdapter::skip(const size_type count) +size_t inputStreamStringAdapter::skip(const size_t count) { if (m_pos + count >= m_end) { - const size_type remaining = m_end - m_pos; + const size_t remaining = m_end - m_pos; m_pos = m_end; return (remaining); } @@ -89,13 +89,13 @@ stream::size_type inputStreamStringAdapter::skip(const size_type count) } -stream::size_type inputStreamStringAdapter::getPosition() const +size_t inputStreamStringAdapter::getPosition() const { return m_pos - m_begin; } -void inputStreamStringAdapter::seek(const size_type pos) +void inputStreamStringAdapter::seek(const size_t pos) { if (m_begin + pos <= m_end) m_pos = m_begin + pos; diff --git a/src/utility/inputStreamStringProxyAdapter.cpp b/src/utility/inputStreamStringProxyAdapter.cpp index 4a78714a..5513de80 100644 --- a/src/utility/inputStreamStringProxyAdapter.cpp +++ b/src/utility/inputStreamStringProxyAdapter.cpp @@ -47,10 +47,10 @@ void inputStreamStringProxyAdapter::reset() } -stream::size_type inputStreamStringProxyAdapter::read - (value_type* const data, const size_type count) +size_t inputStreamStringProxyAdapter::read + (byte_t* const data, const size_t count) { - const size_type remaining = m_buffer.length() - m_pos; + const size_t remaining = m_buffer.length() - m_pos; if (count > remaining) { @@ -67,9 +67,9 @@ stream::size_type inputStreamStringProxyAdapter::read } -stream::size_type inputStreamStringProxyAdapter::skip(const size_type count) +size_t inputStreamStringProxyAdapter::skip(const size_t count) { - const size_type remaining = m_buffer.length() - m_pos; + const size_t remaining = m_buffer.length() - m_pos; if (count > remaining) { @@ -84,13 +84,13 @@ stream::size_type inputStreamStringProxyAdapter::skip(const size_type count) } -stream::size_type inputStreamStringProxyAdapter::getPosition() const +size_t inputStreamStringProxyAdapter::getPosition() const { return m_pos; } -void inputStreamStringProxyAdapter::seek(const size_type pos) +void inputStreamStringProxyAdapter::seek(const size_t pos) { if (pos <= m_buffer.length()) m_pos = pos; diff --git a/src/utility/outputStream.cpp b/src/utility/outputStream.cpp index a6238c41..070e28c5 100644 --- a/src/utility/outputStream.cpp +++ b/src/utility/outputStream.cpp @@ -28,6 +28,18 @@ namespace vmime { namespace utility { +void outputStream::write(const byte_t* const data, const size_t count) +{ + writeImpl(data, count); +} + + +void outputStream::write(const char* const data, const size_t count) +{ + writeImpl(reinterpret_cast (data), count); +} + + } // utility } // vmime diff --git a/src/utility/outputStreamAdapter.cpp b/src/utility/outputStreamAdapter.cpp index 54e983e7..ed90c7d3 100644 --- a/src/utility/outputStreamAdapter.cpp +++ b/src/utility/outputStreamAdapter.cpp @@ -34,11 +34,11 @@ outputStreamAdapter::outputStreamAdapter(std::ostream& os) } -void outputStreamAdapter::write - (const value_type* const data, const size_type count) +void outputStreamAdapter::writeImpl + (const byte_t* const data, const size_t count) { m_stream.exceptions(std::ios_base::badbit); - m_stream.write(data, count); + m_stream.write(reinterpret_cast (data), count); } diff --git a/src/utility/outputStreamByteArrayAdapter.cpp b/src/utility/outputStreamByteArrayAdapter.cpp index 48c0ca0c..1bed735b 100644 --- a/src/utility/outputStreamByteArrayAdapter.cpp +++ b/src/utility/outputStreamByteArrayAdapter.cpp @@ -34,7 +34,8 @@ outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array) } -void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count) +void outputStreamByteArrayAdapter::writeImpl + (const byte_t* const data, const size_t count) { m_array.insert(m_array.end(), data, data + count); } diff --git a/src/utility/outputStreamSocketAdapter.cpp b/src/utility/outputStreamSocketAdapter.cpp index 222ffb0a..03194497 100644 --- a/src/utility/outputStreamSocketAdapter.cpp +++ b/src/utility/outputStreamSocketAdapter.cpp @@ -40,8 +40,8 @@ outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok) } -void outputStreamSocketAdapter::write - (const value_type* const data, const size_type count) +void outputStreamSocketAdapter::writeImpl + (const byte_t* const data, const size_t count) { m_socket.sendRaw(data, count); } @@ -53,7 +53,7 @@ void outputStreamSocketAdapter::flush() } -stream::size_type outputStreamSocketAdapter::getBlockSize() +size_t outputStreamSocketAdapter::getBlockSize() { return m_socket.getBlockSize(); } diff --git a/src/utility/outputStreamStringAdapter.cpp b/src/utility/outputStreamStringAdapter.cpp index ee064202..7105480c 100644 --- a/src/utility/outputStreamStringAdapter.cpp +++ b/src/utility/outputStreamStringAdapter.cpp @@ -23,6 +23,8 @@ #include "vmime/utility/outputStreamStringAdapter.hpp" +#include "vmime/utility/stringUtils.hpp" + namespace vmime { namespace utility { @@ -34,9 +36,10 @@ outputStreamStringAdapter::outputStreamStringAdapter(string& buffer) } -void outputStreamStringAdapter::write(const value_type* const data, const size_type count) +void outputStreamStringAdapter::writeImpl + (const byte_t* const data, const size_t count) { - m_buffer.append(data, count); + vmime::utility::stringUtils::appendBytesToString(m_buffer, data, count); } diff --git a/src/utility/parserInputStreamAdapter.cpp b/src/utility/parserInputStreamAdapter.cpp index fd10a586..5ab26ef0 100644 --- a/src/utility/parserInputStreamAdapter.cpp +++ b/src/utility/parserInputStreamAdapter.cpp @@ -46,8 +46,8 @@ void parserInputStreamAdapter::reset() } -stream::size_type parserInputStreamAdapter::read - (value_type* const data, const size_type count) +size_t parserInputStreamAdapter::read + (byte_t* const data, const size_t count) { return m_stream->read(data, count); } @@ -59,17 +59,19 @@ shared_ptr parserInputStreamAdapter::getUnderlyingStream() } -const string parserInputStreamAdapter::extract(const size_type begin, const size_type end) const +const string parserInputStreamAdapter::extract(const size_t begin, const size_t end) const { - const size_type initialPos = m_stream->getPosition(); + const size_t initialPos = m_stream->getPosition(); + + byte_t *buffer = NULL; try { - value_type *buffer = new value_type[end - begin + 1]; + buffer = new byte_t[end - begin + 1]; m_stream->seek(begin); - const size_type readBytes = m_stream->read(buffer, end - begin); + const size_t readBytes = m_stream->read(buffer, end - begin); buffer[readBytes] = '\0'; m_stream->seek(initialPos); @@ -81,14 +83,16 @@ const string parserInputStreamAdapter::extract(const size_type begin, const size } catch (...) { + delete [] buffer; + m_stream->seek(initialPos); throw; } } -stream::size_type parserInputStreamAdapter::findNext - (const string& token, const size_type startPosition) +size_t parserInputStreamAdapter::findNext + (const string& token, const size_t startPosition) { static const unsigned int BUFFER_SIZE = 4096; @@ -96,28 +100,28 @@ stream::size_type parserInputStreamAdapter::findNext if (token.empty() || token.length() > BUFFER_SIZE / 2) return npos; - const size_type initialPos = getPosition(); + const size_t initialPos = getPosition(); seek(startPosition); try { - value_type findBuffer[BUFFER_SIZE]; - value_type* findBuffer1 = findBuffer; - value_type* findBuffer2 = findBuffer + (BUFFER_SIZE / 2) * sizeof(value_type); + byte_t findBuffer[BUFFER_SIZE]; + byte_t* findBuffer1 = findBuffer; + byte_t* findBuffer2 = findBuffer + (BUFFER_SIZE / 2); - size_type findBufferLen = 0; - size_type findBufferOffset = 0; + size_t findBufferLen = 0; + size_t findBufferOffset = 0; bool isEOF = false; // Fill in initial buffer - findBufferLen = read(findBuffer, BUFFER_SIZE * sizeof(value_type)); + findBufferLen = read(findBuffer, BUFFER_SIZE); while (findBufferLen != 0) { // Find token - for (value_type *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ; + for (byte_t *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ; begin <= end ; ++begin) { if (begin[0] == token[0] && @@ -132,7 +136,7 @@ stream::size_type parserInputStreamAdapter::findNext } // Rotate buffer - memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type)); + memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2)); // Read more bytes if (findBufferLen < BUFFER_SIZE && (eof() || isEOF)) @@ -141,7 +145,7 @@ stream::size_type parserInputStreamAdapter::findNext } else { - const size_type bytesRead = read(findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type)); + const size_t bytesRead = read(findBuffer2, BUFFER_SIZE / 2); if (bytesRead == 0) { diff --git a/src/utility/progressListener.cpp b/src/utility/progressListener.cpp index 4d54174f..cef074e5 100644 --- a/src/utility/progressListener.cpp +++ b/src/utility/progressListener.cpp @@ -31,7 +31,7 @@ namespace utility { // progressListenerSizeAdapter progressListenerSizeAdapter::progressListenerSizeAdapter - (progressListener* list, const long total) + (progressListener* list, const size_t total) : m_wrapped(list), m_total(total) { } @@ -43,14 +43,14 @@ bool progressListenerSizeAdapter::cancel() const } -void progressListenerSizeAdapter::start(const long predictedTotal) +void progressListenerSizeAdapter::start(const size_t predictedTotal) { if (m_wrapped) m_wrapped->start(predictedTotal); } -void progressListenerSizeAdapter::progress(const long current, const long currentTotal) +void progressListenerSizeAdapter::progress(const size_t current, const size_t currentTotal) { if (m_wrapped) { @@ -62,7 +62,7 @@ void progressListenerSizeAdapter::progress(const long current, const long curren } -void progressListenerSizeAdapter::stop(const long total) +void progressListenerSizeAdapter::stop(const size_t total) { if (m_wrapped) { diff --git a/src/utility/random.cpp b/src/utility/random.cpp index 40b27b57..97d12ddc 100644 --- a/src/utility/random.cpp +++ b/src/utility/random.cpp @@ -66,13 +66,13 @@ unsigned int random::getProcess() } -const string random::getString(const string::size_type length, const string& randomChars) +const string random::getString(const size_t length, const string& randomChars) { string res; res.resize(length); const unsigned int x = static_cast (randomChars.length()); - string::size_type c = 0; + size_t c = 0; while (c < length) { diff --git a/src/utility/seekableInputStreamRegionAdapter.cpp b/src/utility/seekableInputStreamRegionAdapter.cpp index 753d81a5..cede1ba9 100644 --- a/src/utility/seekableInputStreamRegionAdapter.cpp +++ b/src/utility/seekableInputStreamRegionAdapter.cpp @@ -29,7 +29,7 @@ namespace utility { seekableInputStreamRegionAdapter::seekableInputStreamRegionAdapter - (shared_ptr stream, const size_type begin, const size_type length) + (shared_ptr stream, const size_t begin, const size_t length) : m_stream(stream), m_begin(begin), m_length(length), m_position(0) { } @@ -47,16 +47,16 @@ void seekableInputStreamRegionAdapter::reset() } -stream::size_type seekableInputStreamRegionAdapter::read - (value_type* const data, const size_type count) +size_t seekableInputStreamRegionAdapter::read + (byte_t* const data, const size_t count) { m_stream->seek(m_begin + m_position); - size_type readBytes = 0; + size_t readBytes = 0; if (m_position + count >= m_length) { - const size_type remaining = m_length - m_position; + const size_t remaining = m_length - m_position; readBytes = m_stream->read(data, remaining); } else @@ -70,11 +70,11 @@ stream::size_type seekableInputStreamRegionAdapter::read } -stream::size_type seekableInputStreamRegionAdapter::skip(const size_type count) +size_t seekableInputStreamRegionAdapter::skip(const size_t count) { if (m_position + count >= m_length) { - const size_type remaining = m_length - m_position; + const size_t remaining = m_length - m_position; m_position += remaining; return remaining; } @@ -86,13 +86,13 @@ stream::size_type seekableInputStreamRegionAdapter::skip(const size_type count) } -stream::size_type seekableInputStreamRegionAdapter::getPosition() const +size_t seekableInputStreamRegionAdapter::getPosition() const { return m_position; } -void seekableInputStreamRegionAdapter::seek(const size_type pos) +void seekableInputStreamRegionAdapter::seek(const size_t pos) { if (pos > m_length) m_position = m_length; diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp index 3e7b5822..232b23c7 100644 --- a/src/utility/stream.cpp +++ b/src/utility/stream.cpp @@ -29,10 +29,7 @@ namespace vmime { namespace utility { -const stream::size_type stream::npos = static_cast (vmime::string::npos); - - -stream::size_type stream::getBlockSize() +size_t stream::getBlockSize() { return 32768; // 32 KB } diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp index 06ea17a1..f3cc69ef 100644 --- a/src/utility/streamUtils.cpp +++ b/src/utility/streamUtils.cpp @@ -32,7 +32,7 @@ namespace vmime { namespace utility { -outputStream& operator<<(outputStream& os, const stream::value_type c) +outputStream& operator<<(outputStream& os, const byte_t c) { os.write(&c, 1); return (os); @@ -46,29 +46,29 @@ outputStream& operator<<(outputStream& os, const string& str) } -stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os) +size_t bufferedStreamCopy(inputStream& is, outputStream& os) { return bufferedStreamCopy(is, os, 0, NULL); } -stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os, - const stream::size_type start, const stream::size_type length) +size_t bufferedStreamCopyRange(inputStream& is, outputStream& os, + const size_t start, const size_t length) { - const stream::size_type blockSize = + const size_t blockSize = std::min(is.getBlockSize(), os.getBlockSize()); is.skip(start); - std::vector vbuffer(blockSize); + std::vector vbuffer(blockSize); - stream::value_type* buffer = &vbuffer.front(); - stream::size_type total = 0; + byte_t* buffer = &vbuffer.front(); + size_t total = 0; while (!is.eof() && total < length) { - const stream::size_type remaining = std::min(length - total, blockSize); - const stream::size_type read = is.read(buffer, remaining); + const size_t remaining = std::min(length - total, blockSize); + const size_t read = is.read(buffer, remaining); if (read != 0) { @@ -81,23 +81,23 @@ stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os, } -stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os, - const stream::size_type length, progressListener* progress) +size_t bufferedStreamCopy(inputStream& is, outputStream& os, + const size_t length, progressListener* progress) { - const stream::size_type blockSize = + const size_t blockSize = std::min(is.getBlockSize(), os.getBlockSize()); - std::vector vbuffer(blockSize); + std::vector vbuffer(blockSize); - stream::value_type* buffer = &vbuffer.front(); - stream::size_type total = 0; + byte_t* buffer = &vbuffer.front(); + size_t total = 0; if (progress != NULL) progress->start(length); while (!is.eof()) { - const stream::size_type read = is.read(buffer, blockSize); + const size_t read = is.read(buffer, blockSize); if (read != 0) { diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp index 3320affb..67c96816 100644 --- a/src/utility/stringProxy.cpp +++ b/src/utility/stringProxy.cpp @@ -45,19 +45,19 @@ stringProxy::stringProxy(const stringProxy& s) } -stringProxy::stringProxy(const string_type& s, const size_type start, const size_type end) +stringProxy::stringProxy(const string& s, const size_t start, const size_t end) : m_buffer(s), m_start(start), - m_end(end == std::numeric_limits ::max() ? s.length() : end) + m_end(end == std::numeric_limits ::max() ? s.length() : end) { } -void stringProxy::set(const string_type& s, const size_type start, const size_type end) +void stringProxy::set(const string& s, const size_t start, const size_t end) { m_buffer = s; m_start = start; - if (end == std::numeric_limits ::max()) + if (end == std::numeric_limits ::max()) m_end = s.length(); else m_end = end; @@ -81,7 +81,7 @@ stringProxy& stringProxy::operator=(const stringProxy& s) } -stringProxy& stringProxy::operator=(const string_type& s) +stringProxy& stringProxy::operator=(const string& s) { m_buffer = s; m_start = 0; @@ -91,12 +91,12 @@ stringProxy& stringProxy::operator=(const string_type& s) } -void stringProxy::extract(outputStream& os, const size_type start, const size_type end, +void stringProxy::extract(outputStream& os, const size_t start, const size_t end, utility::progressListener* progress) const { - size_type len = 0; + size_t len = 0; - if (end == std::numeric_limits ::max()) + if (end == std::numeric_limits ::max()) len = m_end - start - m_start; else if (end > start) len = end - start; @@ -114,19 +114,19 @@ void stringProxy::extract(outputStream& os, const size_type start, const size_ty } -stringProxy::size_type stringProxy::length() const +size_t stringProxy::length() const { return (m_end - m_start); } -stringProxy::size_type stringProxy::start() const +size_t stringProxy::start() const { return (m_start); } -stringProxy::size_type stringProxy::end() const +size_t stringProxy::end() const { return (m_end); } diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp index 8e5f7205..dd99d845 100644 --- a/src/utility/stringUtils.cpp +++ b/src/utility/stringUtils.cpp @@ -30,7 +30,7 @@ namespace utility { bool stringUtils::isStringEqualNoCase - (const string& s1, const char* s2, const string::size_type n) + (const string& s1, const char* s2, const size_t n) { // 'n' is the number of characters to compare // 's2' must be in lowercase letters only @@ -42,7 +42,7 @@ bool stringUtils::isStringEqualNoCase bool equal = true; - for (string::size_type i = 0 ; equal && i < n ; ++i) + for (size_t i = 0 ; equal && i < n ; ++i) equal = (fac.tolower(static_cast (s1[i])) == s2[i]); return (equal); @@ -69,9 +69,9 @@ bool stringUtils::isStringEqualNoCase(const string& s1, const string& s2) bool stringUtils::isStringEqualNoCase (const string::const_iterator begin, const string::const_iterator end, - const char* s, const string::size_type n) + const char* s, const size_t n) { - if (static_cast (end - begin) < n) + if (static_cast (end - begin) < n) return (false); const std::ctype & fac = @@ -79,7 +79,7 @@ bool stringUtils::isStringEqualNoCase bool equal = true; char* c = const_cast(s); - string::size_type r = n; + size_t r = n; for (string::const_iterator i = begin ; equal && r && *c ; ++i, ++c, --r) equal = (fac.tolower(static_cast (*i)) == static_cast (*c)); @@ -96,7 +96,7 @@ const string stringUtils::toLower(const string& str) string out; out.resize(str.size()); - for (string::size_type i = 0, len = str.length() ; i < len ; ++i) + for (size_t i = 0, len = str.length() ; i < len ; ++i) out[i] = fac.tolower(static_cast (str[i])); return out; @@ -111,7 +111,7 @@ const string stringUtils::toUpper(const string& str) string out; out.resize(str.size()); - for (string::size_type i = 0, len = str.length() ; i < len ; ++i) + for (size_t i = 0, len = str.length() ; i < len ; ++i) out[i] = fac.toupper(static_cast (str[i])); return out; @@ -133,10 +133,10 @@ const string stringUtils::trim(const string& str) } -string::size_type stringUtils::countASCIIchars +size_t stringUtils::countASCIIchars (const string::const_iterator begin, const string::const_iterator end) { - string::size_type count = 0; + size_t count = 0; for (string::const_iterator i = begin ; i != end ; ++i) { @@ -157,10 +157,10 @@ bool stringUtils::is7bit(const string& str) } -string::size_type stringUtils::findFirstNonASCIIchar +size_t stringUtils::findFirstNonASCIIchar (const string::const_iterator begin, const string::const_iterator end) { - string::size_type pos = string::npos; + size_t pos = string::npos; for (string::const_iterator i = begin ; i != end ; ++i) { @@ -190,7 +190,7 @@ const string stringUtils::unquote(const string& str) for (string::const_iterator it = str.begin() + 1, end = str.end() - 1 ; it != end ; ++it) { - const string::value_type c = *it; + const char c = *it; if (escaped) { @@ -221,7 +221,7 @@ string stringUtils::quote (const string& str, const string& escapeSpecialChars, const string& escapeChar) { std::ostringstream oss; - string::size_type lastPos = 0, pos = 0; + size_t lastPos = 0, pos = 0; while ((pos = str.find_first_of(escapeSpecialChars, lastPos)) != string::npos) { diff --git a/src/utility/url.cpp b/src/utility/url.cpp index f9157d64..ce0dc39a 100644 --- a/src/utility/url.cpp +++ b/src/utility/url.cpp @@ -157,17 +157,17 @@ const string url::build() const void url::parse(const string& str) { // Protocol - const string::size_type protoEnd = str.find("://"); + const size_t protoEnd = str.find("://"); if (protoEnd == string::npos) throw exceptions::malformed_url("No protocol separator"); const string proto = utility::stringUtils::toLower(string(str.begin(), str.begin() + protoEnd)); // Username/password - string::size_type slashPos = str.find('/', protoEnd + 3); + size_t slashPos = str.find('/', protoEnd + 3); if (slashPos == string::npos) slashPos = str.length(); - string::size_type atPos = str.rfind('@', slashPos); + size_t atPos = str.rfind('@', slashPos); string hostPart; string username; @@ -183,7 +183,7 @@ void url::parse(const string& str) if (atPos != string::npos && atPos < slashPos) { const string userPart(str.begin() + protoEnd + 3, str.begin() + atPos); - const string::size_type colonPos = userPart.find(':'); + const size_t colonPos = userPart.find(':'); if (colonPos == string::npos) { @@ -204,7 +204,7 @@ void url::parse(const string& str) } // Host/port - const string::size_type colonPos = hostPart.find(':'); + const size_t colonPos = hostPart.find(':'); string host; string port; @@ -223,7 +223,7 @@ void url::parse(const string& str) string path = utility::stringUtils::trim(string(str.begin() + slashPos, str.end())); string params; - string::size_type paramSep = path.find_first_of('?'); + size_t paramSep = path.find_first_of('?'); if (paramSep != string::npos) { @@ -268,16 +268,16 @@ void url::parse(const string& str) if (!params.empty()) { - string::size_type pos = 0; + size_t pos = 0; do { - const string::size_type start = pos; + const size_t start = pos; pos = params.find_first_of('&', pos); - const string::size_type equal = params.find_first_of('=', start); - const string::size_type end = + const size_t equal = params.find_first_of('=', start); + const size_t end = (pos == string::npos ? params.length() : pos); string name; diff --git a/src/utility/urlUtils.cpp b/src/utility/urlUtils.cpp index 3a6836b7..20818764 100644 --- a/src/utility/urlUtils.cpp +++ b/src/utility/urlUtils.cpp @@ -40,7 +40,7 @@ const string urlUtils::encode(const string& s) for (string::const_iterator it = s.begin() ; it != s.end() ; ++it) { - const string::value_type c = *it; + const char c = *it; if (parserHelpers::isPrint(c) && !parserHelpers::isSpace(c) && static_cast (c) <= 127 && @@ -73,7 +73,7 @@ const string urlUtils::decode(const string& s) for (string::const_iterator it = s.begin() ; it != s.end() ; ) { - const string::value_type c = *it; + const char c = *it; switch (c) { @@ -114,7 +114,7 @@ const string urlUtils::decode(const string& s) } } - result += static_cast (r); + result += static_cast (r); break; } default: diff --git a/src/word.cpp b/src/word.cpp index fc791b53..ec0a20df 100644 --- a/src/word.cpp +++ b/src/word.cpp @@ -66,11 +66,11 @@ word::word(const string& buffer, const charset& charset) shared_ptr word::parseNext - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition, + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition, bool prevIsEncoded, bool* isEncoded, bool isFirst) { - string::size_type pos = position; + size_t pos = position; // Ignore white-spaces: // - before the first word @@ -84,7 +84,7 @@ shared_ptr word::parseNext ++pos; } - string::size_type startPos = pos; + size_t startPos = pos; string unencoded; const charset defaultCharset = ctx.getInternationalizedEmailSupport() @@ -96,7 +96,7 @@ shared_ptr word::parseNext // used to remove folding white-spaces from unencoded text. if (buffer[pos] == '\n') { - string::size_type endPos = pos; + size_t endPos = pos; if (pos > position && buffer[pos - 1] == '\r') { @@ -140,7 +140,7 @@ shared_ptr word::parseNext } // ...else find the finish sequence '?=' and return an encoded word - const string::size_type wordStart = pos; + const size_t wordStart = pos; pos += 2; @@ -227,13 +227,13 @@ shared_ptr word::parseNext const std::vector > word::parseMultiple - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { std::vector > res; shared_ptr w; - string::size_type pos = position; + size_t pos = position; bool prevIsEncoded = false; @@ -248,8 +248,8 @@ const std::vector > word::parseMultiple void word::parseImpl - (const parsingContext& ctx, const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) + (const parsingContext& ctx, const string& buffer, const size_t position, + const size_t end, size_t* newPosition) { if (position + 6 < end && // 6 = "=?(.+)?(.*)?=" buffer[position] == '=' && buffer[position + 1] == '?') @@ -333,17 +333,17 @@ void word::parseImpl void word::generateImpl(const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos) const + const size_t curLinePos, size_t* newLinePos) const { generate(ctx, os, curLinePos, newLinePos, 0, NULL); } void word::generate(const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, string::size_type* newLinePos, const int flags, + const size_t curLinePos, size_t* newLinePos, const int flags, generatorState* state) const { - string::size_type curLineLength = curLinePos; + size_t curLineLength = curLinePos; generatorState defaultGeneratorState; @@ -407,8 +407,8 @@ void word::generate(const generationContext& ctx, utility::outputStream& os, // Look in the buffer for any run (ie. whitespace-separated sequence) which // is longer than the maximum line length. If there is one, then force encoding, // so that no generated line is longer than the maximum line length. - string::size_type maxRunLength = 0; - string::size_type curRunLength = 0; + size_t maxRunLength = 0; + size_t curRunLength = 0; for (string::const_iterator p = buffer.begin(), end = buffer.end() ; p != end ; ++p) { @@ -593,10 +593,10 @@ void word::generate(const generationContext& ctx, utility::outputStream& os, 'encoded-word's is limited to 76 characters. " */ - const string::size_type maxLineLength3 = + const size_t maxLineLength3 = (ctx.getMaxLineLength() == lineLengthLimits::infinite) ? ctx.getMaxLineLength() - : std::min(ctx.getMaxLineLength(), static_cast (76)); + : std::min(ctx.getMaxLineLength(), static_cast (76)); wordEncoder wordEnc(m_buffer, m_charset); @@ -604,8 +604,8 @@ void word::generate(const generationContext& ctx, utility::outputStream& os, (wordEnc.getEncoding() == wordEncoder::ENCODING_B64 ? 'B' : 'Q') + "?"); const string wordEnd("?="); - const string::size_type minWordLength = wordStart.length() + wordEnd.length(); - const string::size_type maxLineLength2 = (maxLineLength3 < minWordLength + 1) + const size_t minWordLength = wordStart.length() + wordEnd.length(); + const size_t maxLineLength2 = (maxLineLength3 < minWordLength + 1) ? maxLineLength3 + minWordLength + 1 : maxLineLength3; // Checks whether remaining space on this line is usable. If too few @@ -614,7 +614,7 @@ void word::generate(const generationContext& ctx, utility::outputStream& os, if (curLineLength + 2 < maxLineLength2) { - const string::size_type remainingSpaceOnLine = maxLineLength2 - curLineLength - 2; + const size_t remainingSpaceOnLine = maxLineLength2 - curLineLength - 2; if (remainingSpaceOnLine < minWordLength + 10) { @@ -649,7 +649,7 @@ void word::generate(const generationContext& ctx, utility::outputStream& os, for (unsigned int i = 0 ; ; ++i) { // Compute the number of encoded chars that will fit on this line - const string::size_type fit = maxLineLength2 - minWordLength + const size_t fit = maxLineLength2 - minWordLength - (i == 0 ? curLineLength : NEW_LINE_SEQUENCE_LENGTH); // Get the next encoded chunk diff --git a/src/wordEncoder.cpp b/src/wordEncoder.cpp index b3e98fd2..421a9ecd 100644 --- a/src/wordEncoder.cpp +++ b/src/wordEncoder.cpp @@ -78,8 +78,8 @@ wordEncoder::wordEncoder(const string& buffer, const charset& charset, const Enc } -static string::size_type getUTF8CharLength - (const string& buffer, const string::size_type pos, const string::size_type length) +static size_t getUTF8CharLength + (const string& buffer, const size_t pos, const size_t length) { // Gives the number of extra bytes in a UTF8 char, given the leading char static const unsigned char UTF8_EXTRA_BYTES[256] = @@ -112,9 +112,9 @@ static string::size_type getUTF8CharLength } -const string wordEncoder::getNextChunk(const string::size_type maxLength) +const string wordEncoder::getNextChunk(const size_t maxLength) { - const string::size_type remaining = m_length - m_pos; + const size_t remaining = m_length - m_pos; if (remaining == 0) return string(); @@ -133,7 +133,7 @@ const string wordEncoder::getNextChunk(const string::size_type maxLength) // Here, we have a formula to compute the maximum number of source // bytes to encode knowing the maximum number of encoded chars. In // Base64 encoding, 3 bytes of input provide 4 bytes of output. - const string::size_type inputCount = + const size_t inputCount = std::min(remaining, (maxLength > 1) ? ((maxLength - 1) * 3) / 4 : 1); // Encode chunk @@ -147,8 +147,8 @@ const string wordEncoder::getNextChunk(const string::size_type maxLength) // Compute exactly how much input bytes are needed to have an output // string length of less than 'maxLength' bytes. In Quoted-Printable // encoding, encoded bytes take 3 bytes. - string::size_type inputCount = 0; - string::size_type outputCount = 0; + size_t inputCount = 0; + size_t outputCount = 0; while ((inputCount == 0 || outputCount < maxLength) && (inputCount < remaining)) { @@ -170,14 +170,14 @@ const string wordEncoder::getNextChunk(const string::size_type maxLength) { shared_ptr conv = charsetConverter::create(charsets::UTF_8, m_charset); - string::size_type inputCount = 0; - string::size_type outputCount = 0; + size_t inputCount = 0; + size_t outputCount = 0; string encodeBuffer; while ((inputCount == 0 || outputCount < maxLength) && (inputCount < remaining)) { // Get the next UTF8 character - const string::size_type inputCharLength = + const size_t inputCharLength = getUTF8CharLength(m_buffer, m_pos + inputCount, m_length); const string inputChar(m_buffer.begin() + m_pos + inputCount, @@ -192,12 +192,12 @@ const string wordEncoder::getNextChunk(const string::size_type maxLength) // Compute number of output bytes if (m_encoding == ENCODING_B64) { - outputCount = std::max(static_cast (4), + outputCount = std::max(static_cast (4), (encodeBuffer.length() * 4) / 3); } else // ENCODING_QP { - for (string::size_type i = 0, n = encodeBytes.length() ; i < n ; ++i) + for (size_t i = 0, n = encodeBytes.length() ; i < n ; ++i) { const unsigned char c = encodeBytes[i]; outputCount += utility::encoder::qpEncoder::RFC2047_getEncodedLength(c); @@ -270,10 +270,10 @@ wordEncoder::Encoding wordEncoder::guessBestEncoding } // Use Base64 if more than 40% non-ASCII, or Quoted-Printable else (default) - const string::size_type asciiCount = + const size_t asciiCount = utility::stringUtils::countASCIIchars(buffer.begin(), buffer.end()); - const string::size_type asciiPercent = + const size_t asciiPercent = (buffer.length() == 0 ? 100 : (100 * asciiCount) / buffer.length()); if (asciiPercent < 60) diff --git a/tests/net/smtp/SMTPTransportTestUtils.hpp b/tests/net/smtp/SMTPTransportTestUtils.hpp index dd7afeb5..c3296092 100644 --- a/tests/net/smtp/SMTPTransportTestUtils.hpp +++ b/tests/net/smtp/SMTPTransportTestUtils.hpp @@ -131,8 +131,8 @@ public: } else if (cmd == "RCPT") { - const vmime::string::size_type lt = line.find('<'); - const vmime::string::size_type gt = line.find('>'); + const vmime::size_t lt = line.find('<'); + const vmime::size_t gt = line.find('>'); VASSERT("RCPT <", lt != vmime::string::npos); VASSERT("RCPT >", gt != vmime::string::npos); @@ -261,8 +261,8 @@ public: { if (m_bdatChunkReceived != m_bdatChunkSize) { - const size_type remaining = m_bdatChunkSize - m_bdatChunkReceived; - const size_type received = localReceiveRaw(NULL, remaining); + const size_t remaining = m_bdatChunkSize - m_bdatChunkReceived; + const size_t received = localReceiveRaw(NULL, remaining); m_bdatChunkReceived += received; } @@ -408,7 +408,7 @@ class SMTPTestMessage : public vmime::message { public: - vmime::utility::stream::size_type getChunkBufferSize() const + vmime::size_t getChunkBufferSize() const { static vmime::net::smtp::SMTPChunkingOutputStreamAdapter chunkStream(vmime::null); return chunkStream.getBlockSize(); @@ -429,10 +429,9 @@ public: return chunks; } - void generateImpl(const vmime::generationContext& /* ctx */, - vmime::utility::outputStream& outputStream, - const vmime::string::size_type /* curLinePos */ = 0, - vmime::string::size_type* /* newLinePos */ = NULL) const + void generateImpl + (const vmime::generationContext& /* ctx */, vmime::utility::outputStream& outputStream, + const size_t /* curLinePos */ = 0, size_t* /* newLinePos */ = NULL) const { for (unsigned int i = 0, n = getChunks().size() ; i < n ; ++i) { @@ -576,16 +575,15 @@ class SMTPBigTestMessage : public vmime::message { public: - vmime::utility::stream::size_type getGeneratedSize - (const vmime::generationContext& /* ctx */) + size_t getGeneratedSize(const vmime::generationContext& /* ctx */) { return SIZE; } void generateImpl(const vmime::generationContext& /* ctx */, vmime::utility::outputStream& outputStream, - const vmime::string::size_type /* curLinePos */ = 0, - vmime::string::size_type* /* newLinePos */ = NULL) const + const vmime::size_t /* curLinePos */ = 0, + vmime::size_t* /* newLinePos */ = NULL) const { for (unsigned int i = 0, n = SIZE ; i < n ; ++i) outputStream.write("X", 1); diff --git a/tests/parser/charsetFilteredOutputStreamTest.cpp b/tests/parser/charsetFilteredOutputStreamTest.cpp index 4c91a71c..9b8397a8 100644 --- a/tests/parser/charsetFilteredOutputStreamTest.cpp +++ b/tests/parser/charsetFilteredOutputStreamTest.cpp @@ -85,7 +85,7 @@ VMIME_TEST_SUITE_BEGIN(charsetFilteredOutputStreamTest) vmime::utility::inputStreamStringAdapter is(in); - vmime::utility::stream::value_type buffer[16]; + vmime::byte_t buffer[16]; for (int i = 0 ; !is.eof() ; ++i) os->write(buffer, is.read(buffer, 1)); @@ -161,7 +161,7 @@ VMIME_TEST_SUITE_BEGIN(charsetFilteredOutputStreamTest) vmime::utility::inputStreamStringAdapter is(in); - vmime::utility::stream::value_type buffer[16]; + vmime::byte_t buffer[16]; for (int i = 0 ; !is.eof() ; ++i) os->write(buffer, is.read(buffer, 1)); @@ -201,7 +201,7 @@ VMIME_TEST_SUITE_BEGIN(charsetFilteredOutputStreamTest) vmime::utility::inputStreamStringAdapter is(in); - vmime::utility::stream::value_type buffer[16]; + vmime::byte_t buffer[16]; for (int i = 0 ; !is.eof() ; ++i) os->write(buffer, is.read(buffer, (i % 5) + 1)); diff --git a/tests/parser/charsetTestSuites.hpp b/tests/parser/charsetTestSuites.hpp index b12b3e37..cb10e29e 100644 --- a/tests/parser/charsetTestSuites.hpp +++ b/tests/parser/charsetTestSuites.hpp @@ -100,4 +100,4 @@ static const charsetTestSuiteStruct charsetTestSuites[] = }; -static const unsigned int charsetTestSuitesCount = sizeof(charsetTestSuites) / sizeof(charsetTestSuites[0]); +static const vmime::size_t charsetTestSuitesCount = sizeof(charsetTestSuites) / sizeof(charsetTestSuites[0]); diff --git a/tests/parser/messageTest.cpp b/tests/parser/messageTest.cpp index a7a16813..3891b47e 100644 --- a/tests/parser/messageTest.cpp +++ b/tests/parser/messageTest.cpp @@ -44,8 +44,8 @@ VMIME_TEST_SUITE_BEGIN(messageTest) textPart.generateIn(msg, msg); // Estimated/computed generated size must be greater than the actual generated size - const unsigned long genSize = msg->getGeneratedSize(ctx); - const unsigned long actualSize = msg->generate().length(); + const vmime::size_t genSize = msg->getGeneratedSize(ctx); + const vmime::size_t actualSize = msg->generate().length(); std::ostringstream oss; oss << "estimated size (" << genSize << ") >= actual size (" << actualSize << ")"; diff --git a/tests/testRunner.cpp b/tests/testRunner.cpp index 48a09d17..84f217a0 100644 --- a/tests/testRunner.cpp +++ b/tests/testRunner.cpp @@ -196,7 +196,7 @@ const std::string getNormalizedPath(const std::string& path) { std::string res = path; - for (std::string::size_type i = 0, n = res.length() ; i < n ; ++i) + for (std::size_t i = 0, n = res.length() ; i < n ; ++i) { if (res[i] == '\\') res[i] = '/'; @@ -208,7 +208,7 @@ const std::string getNormalizedPath(const std::string& path) const std::string getFileNameFromPath(const std::string& path) { - const std::string::size_type pos = path.find_last_of('/'); + const std::size_t pos = path.find_last_of('/'); if (pos == std::string::npos) return ""; diff --git a/tests/testUtils.cpp b/tests/testUtils.cpp index c22649e6..437b476b 100644 --- a/tests/testUtils.cpp +++ b/tests/testUtils.cpp @@ -23,6 +23,10 @@ #include "testUtils.hpp" +#include "vmime/utility/stringUtils.hpp" + +#include + // testSocket @@ -51,7 +55,7 @@ bool testSocket::isConnected() const } -testSocket::size_type testSocket::getBlockSize() const +vmime::size_t testSocket::getBlockSize() const { return 16384; } @@ -90,9 +94,15 @@ void testSocket::send(const vmime::string& buffer) } -testSocket::size_type testSocket::receiveRaw(char* buffer, const size_type count) +void testSocket::send(const char* str) { - const size_type n = std::min(count, static_cast (m_inBuffer.size())); + sendRaw(reinterpret_cast (str), strlen(str)); +} + + +vmime::size_t testSocket::receiveRaw(vmime::byte_t* buffer, const size_t count) +{ + const size_t n = std::min(count, static_cast (m_inBuffer.size())); std::copy(m_inBuffer.begin(), m_inBuffer.begin() + n, buffer); m_inBuffer.erase(m_inBuffer.begin(), m_inBuffer.begin() + n); @@ -101,13 +111,13 @@ testSocket::size_type testSocket::receiveRaw(char* buffer, const size_type count } -void testSocket::sendRaw(const char* buffer, const size_type count) +void testSocket::sendRaw(const vmime::byte_t* buffer, const size_t count) { - send(vmime::string(buffer, count)); + send(vmime::utility::stringUtils::makeStringFromBytes(buffer, count)); } -testSocket::size_type testSocket::sendRawNonBlocking(const char* buffer, const size_type count) +vmime::size_t testSocket::sendRawNonBlocking(const vmime::byte_t* buffer, const size_t count) { sendRaw(buffer, count); return count; @@ -129,7 +139,7 @@ void testSocket::localReceive(vmime::string& buffer) bool testSocket::localReceiveLine(vmime::string& line) { - vmime::string::size_type eol; + vmime::size_t eol; if ((eol = m_outBuffer.find('\n')) != vmime::string::npos) { @@ -147,9 +157,9 @@ bool testSocket::localReceiveLine(vmime::string& line) } -testSocket::size_type testSocket::localReceiveRaw(char* buffer, const size_type count) +vmime::size_t testSocket::localReceiveRaw(vmime::byte_t* buffer, const size_t count) { - const size_type received = std::min(count, static_cast (m_outBuffer.size())); + const size_t received = std::min(count, static_cast (m_outBuffer.size())); if (received != 0) { @@ -184,7 +194,7 @@ void lineBasedTestSocket::onDataReceived() m_buffer += chunk; - vmime::string::size_type eol; + vmime::size_t eol; while ((eol = m_buffer.find('\n')) != vmime::string::npos) { @@ -217,7 +227,7 @@ bool lineBasedTestSocket::haveMoreLines() const // testTimeoutHandler -testTimeoutHandler::testTimeoutHandler(const unsigned int delay) +testTimeoutHandler::testTimeoutHandler(const unsigned long delay) : m_delay(delay), m_start(0) { } diff --git a/tests/testUtils.hpp b/tests/testUtils.hpp index fdcca575..f0ecf454 100644 --- a/tests/testUtils.hpp +++ b/tests/testUtils.hpp @@ -250,12 +250,13 @@ public: void receive(vmime::string& buffer); void send(const vmime::string& buffer); + void send(const char* str); - size_type receiveRaw(char* buffer, const size_type count); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + size_t receiveRaw(vmime::byte_t* buffer, const size_t count); + void sendRaw(const vmime::byte_t* buffer, const size_t count); + size_t sendRawNonBlocking(const vmime::byte_t* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; @@ -287,7 +288,7 @@ public: * @param count number of bytes to receive * @return number of bytes received */ - testSocket::size_type localReceiveRaw(char* buffer, const size_type count); + vmime::size_t localReceiveRaw(vmime::byte_t* buffer, const size_t count); protected: @@ -349,7 +350,7 @@ class testTimeoutHandler : public vmime::net::timeoutHandler { public: - testTimeoutHandler(const unsigned int delay = 3); + testTimeoutHandler(const unsigned long delay = 3); bool isTimeOut(); void resetTimeOut(); @@ -357,8 +358,8 @@ public: private: - unsigned int m_delay; - unsigned int m_start; + unsigned long m_delay; + unsigned long m_start; }; diff --git a/tests/utility/filteredStreamTest.cpp b/tests/utility/filteredStreamTest.cpp index 76cb149b..ec1fc66a 100644 --- a/tests/utility/filteredStreamTest.cpp +++ b/tests/utility/filteredStreamTest.cpp @@ -24,6 +24,7 @@ #include "tests/testUtils.hpp" #include "vmime/utility/filteredStream.hpp" +#include "vmime/utility/stringUtils.hpp" VMIME_TEST_SUITE_BEGIN(filteredStreamTest) @@ -45,7 +46,7 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest) private: std::vector m_chunks; - std::vector ::size_type m_index; + size_t m_index; public: @@ -56,7 +57,7 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest) bool eof() const { return (m_index >= m_chunks.size()); } void reset() { m_index = 0; } - size_type read(value_type* const data, const size_type /* count */) + vmime::size_t read(vmime::byte_t* const data, const vmime::size_t /* count */) { if (eof()) return 0; @@ -72,7 +73,7 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest) return chunk.length(); } - size_type skip(const size_type /* count */) + vmime::size_t skip(const vmime::size_t /* count */) { // Not supported return 0; @@ -82,15 +83,14 @@ VMIME_TEST_SUITE_BEGIN(filteredStreamTest) const std::string readWhole(vmime::utility::inputStream& is) { - vmime::utility::stream::value_type buffer[256]; + vmime::byte_t buffer[256]; std::string whole; while (!is.eof()) { - const vmime::utility::stream::size_type read = - is.read(buffer, sizeof(buffer)); + const vmime::size_t read = is.read(buffer, sizeof(buffer)); - whole += std::string(buffer, read); + whole += vmime::utility::stringUtils::makeStringFromBytes(buffer, read); } return (whole); diff --git a/tests/utility/outputStreamByteArrayAdapterTest.cpp b/tests/utility/outputStreamByteArrayAdapterTest.cpp index 93e49fa1..b14d0a39 100644 --- a/tests/utility/outputStreamByteArrayAdapterTest.cpp +++ b/tests/utility/outputStreamByteArrayAdapterTest.cpp @@ -52,7 +52,7 @@ VMIME_TEST_SUITE_BEGIN(outputStreamByteArrayAdapterTest) void testWriteBinary() { - const vmime::string::value_type binaryData[] = + const char binaryData[] = "\xc5\x9a\xc3\xb8\xc9\xb1\xc9\x9b\x20\xc9\x93\xc9\xa8\xc9\xb2\xc9" "\x91\xc5\x95\xc9\xa3\x20\xc9\x96\xc9\x90\xca\x88\xc9\x92"; diff --git a/tests/utility/outputStreamSocketAdapterTest.cpp b/tests/utility/outputStreamSocketAdapterTest.cpp index 417eff8b..4920a75c 100644 --- a/tests/utility/outputStreamSocketAdapterTest.cpp +++ b/tests/utility/outputStreamSocketAdapterTest.cpp @@ -51,7 +51,7 @@ VMIME_TEST_SUITE_BEGIN(outputStreamSocketAdapterTest) void testWriteBinary() { - const vmime::string::value_type binaryData[] = + const char binaryData[] = "\xc5\x9a\xc3\xb8\xc9\xb1\xc9\x9b\x20\xc9\x93\xc9\xa8\xc9\xb2\xc9" "\x91\xc5\x95\xc9\xa3\x20\xc9\x96\xc9\x90\xca\x88\xc9\x92"; diff --git a/tests/utility/outputStreamStringAdapterTest.cpp b/tests/utility/outputStreamStringAdapterTest.cpp index 71ab9b38..1cd3b3a0 100644 --- a/tests/utility/outputStreamStringAdapterTest.cpp +++ b/tests/utility/outputStreamStringAdapterTest.cpp @@ -43,16 +43,18 @@ VMIME_TEST_SUITE_BEGIN(outputStreamStringAdapterTest) stream << "additional data"; stream.flush(); - VASSERT_EQ("Write 1", "initial dataadditional data", str); + VASSERT_EQ("Write 1 len", 27, str.length()); + VASSERT_EQ("Write 1 data", "initial dataadditional data", str); - stream.write("more data", 9); + stream.write("more data"); - VASSERT_EQ("Write 2", "initial dataadditional datamore data", str); + VASSERT_EQ("Write 2 len", 36, str.length()); + VASSERT_EQ("Write 2 data", "initial dataadditional datamore data", str); } void testWriteBinary() { - const vmime::string::value_type binaryData[] = + const vmime::byte_t binaryData[] = "\xc5\x9a\xc3\xb8\xc9\xb1\xc9\x9b\x20\xc9\x93\xc9\xa8\xc9\xb2\xc9" "\x91\xc5\x95\xc9\xa3\x20\xc9\x96\xc9\x90\xca\x88\xc9\x92"; diff --git a/tests/utility/seekableInputStreamRegionAdapterTest.cpp b/tests/utility/seekableInputStreamRegionAdapterTest.cpp index 1c33c056..d62e062f 100644 --- a/tests/utility/seekableInputStreamRegionAdapterTest.cpp +++ b/tests/utility/seekableInputStreamRegionAdapterTest.cpp @@ -25,6 +25,7 @@ #include "vmime/utility/inputStreamStringAdapter.hpp" #include "vmime/utility/seekableInputStreamRegionAdapter.hpp" +#include "vmime/utility/stringUtils.hpp" using namespace vmime::utility; @@ -88,14 +89,15 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) stream->seek(5); - stream::value_type buffer[100]; + vmime::byte_t buffer[100]; std::fill(vmime::begin(buffer), vmime::end(buffer), 0); - stream::size_type read = stream->read(buffer, 6); + vmime::size_t read = stream->read(buffer, 6); VASSERT_EQ("Pos", 11, stream->getPosition()); VASSERT_EQ("Read", 6, read); VASSERT_TRUE("EOF", stream->eof()); - VASSERT_EQ("Buffer", "BUFFER", vmime::string(buffer, 0, 6)); + VASSERT_EQ("Buffer", "BUFFER", + vmime::utility::stringUtils::makeStringFromBytes(buffer, 6)); } void testSkip() @@ -107,14 +109,15 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) VASSERT_EQ("Pos 1", 5, stream->getPosition()); VASSERT_FALSE("EOF 1", stream->eof()); - stream::value_type buffer[100]; + vmime::byte_t buffer[100]; std::fill(vmime::begin(buffer), vmime::end(buffer), 0); - stream::size_type read = stream->read(buffer, 3); + vmime::size_t read = stream->read(buffer, 3); VASSERT_EQ("Pos 2", 8, stream->getPosition()); VASSERT_EQ("Read", 3, read); VASSERT_FALSE("EOF 2", stream->eof()); - VASSERT_EQ("Buffer", "BUF", vmime::string(buffer, 0, 3)); + VASSERT_EQ("Buffer", "BUF", + vmime::utility::stringUtils::makeStringFromBytes(buffer, 3)); stream->skip(50); @@ -143,16 +146,18 @@ VMIME_TEST_SUITE_BEGIN(seekableInputStreamRegionAdapterTest) stream->seek(5); - stream::value_type buffer1[100]; + vmime::byte_t buffer1[100]; std::fill(vmime::begin(buffer1), vmime::end(buffer1), 0); - stream::size_type read = ustream->read(buffer1, 7); + vmime::size_t read = ustream->read(buffer1, 7); - stream::value_type buffer2[100]; + vmime::byte_t buffer2[100]; std::fill(vmime::begin(buffer2), vmime::end(buffer2), 0); - stream::size_type read2 = stream->read(buffer2, 6); + vmime::size_t read2 = stream->read(buffer2, 6); - VASSERT_EQ("Buffer 1", "THIS IS", vmime::string(buffer1, 0, 7)); - VASSERT_EQ("Buffer 2", "BUFFER", vmime::string(buffer2, 0, 6)); + VASSERT_EQ("Buffer 1", "THIS IS", + vmime::utility::stringUtils::makeStringFromBytes(buffer1, 7)); + VASSERT_EQ("Buffer 2", "BUFFER", + vmime::utility::stringUtils::makeStringFromBytes(buffer2, 6)); // ...but the underlying stream position is affected by read operations // from the region adapter (FIXME?) diff --git a/tests/utility/stringProxyTest.cpp b/tests/utility/stringProxyTest.cpp index 0d888f6a..d6513681 100644 --- a/tests/utility/stringProxyTest.cpp +++ b/tests/utility/stringProxyTest.cpp @@ -45,9 +45,9 @@ VMIME_TEST_SUITE_BEGIN(stringProxyTest) { vmime::utility::stringProxy s; - VASSERT_EQ("1", static_cast (0), s.length()); - VASSERT_EQ("2", static_cast (0), s.start()); - VASSERT_EQ("3", static_cast (0), s.end()); + VASSERT_EQ("1", static_cast (0), s.length()); + VASSERT_EQ("2", static_cast (0), s.start()); + VASSERT_EQ("3", static_cast (0), s.end()); } void testConstruct2() @@ -57,20 +57,20 @@ VMIME_TEST_SUITE_BEGIN(stringProxyTest) vmime::utility::stringProxy s1(str); VASSERT_EQ("1", str.length(), s1.length()); - VASSERT_EQ("2", static_cast (0), s1.start()); + VASSERT_EQ("2", static_cast (0), s1.start()); VASSERT_EQ("3", str.length(), s1.end()); vmime::utility::stringProxy s2(str, 10); VASSERT_EQ("4", str.length() - 10, s2.length()); - VASSERT_EQ("5", static_cast (10), s2.start()); + VASSERT_EQ("5", static_cast (10), s2.start()); VASSERT_EQ("6", str.length(), s2.end()); vmime::utility::stringProxy s3(str, 10, 14); - VASSERT_EQ("7", static_cast (4), s3.length()); - VASSERT_EQ("8", static_cast (10), s3.start()); - VASSERT_EQ("9", static_cast (14), s3.end()); + VASSERT_EQ("7", static_cast (4), s3.length()); + VASSERT_EQ("8", static_cast (10), s3.start()); + VASSERT_EQ("9", static_cast (14), s3.end()); VASSERT_EQ("10", 't', *s3.it_begin()); VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); @@ -85,9 +85,9 @@ VMIME_TEST_SUITE_BEGIN(stringProxyTest) s.detach(); - VASSERT_EQ("1", static_cast (0), s.length()); - VASSERT_EQ("2", static_cast (0), s.start()); - VASSERT_EQ("3", static_cast (0), s.end()); + VASSERT_EQ("1", static_cast (0), s.length()); + VASSERT_EQ("2", static_cast (0), s.start()); + VASSERT_EQ("3", static_cast (0), s.end()); } void testSet() @@ -98,22 +98,22 @@ VMIME_TEST_SUITE_BEGIN(stringProxyTest) s1.set(str); VASSERT_EQ("1", str.length(), s1.length()); - VASSERT_EQ("2", static_cast (0), s1.start()); + VASSERT_EQ("2", static_cast (0), s1.start()); VASSERT_EQ("3", str.length(), s1.end()); vmime::utility::stringProxy s2; s2.set(str, 10); VASSERT_EQ("4", str.length() - 10, s2.length()); - VASSERT_EQ("5", static_cast (10), s2.start()); + VASSERT_EQ("5", static_cast (10), s2.start()); VASSERT_EQ("6", str.length(), s2.end()); vmime::utility::stringProxy s3; s3.set(str, 10, 14); - VASSERT_EQ("7", static_cast (4), s3.length()); - VASSERT_EQ("8", static_cast (10), s3.start()); - VASSERT_EQ("9", static_cast (14), s3.end()); + VASSERT_EQ("7", static_cast (4), s3.length()); + VASSERT_EQ("8", static_cast (10), s3.start()); + VASSERT_EQ("9", static_cast (14), s3.end()); VASSERT_EQ("10", 't', *s3.it_begin()); VASSERT_EQ("11", 'e', *(s3.it_begin() + 1)); diff --git a/tests/utility/stringUtilsTest.cpp b/tests/utility/stringUtilsTest.cpp index efd623db..a21c2742 100644 --- a/tests/utility/stringUtilsTest.cpp +++ b/tests/utility/stringUtilsTest.cpp @@ -29,6 +29,9 @@ VMIME_TEST_SUITE_BEGIN(stringUtilsTest) VMIME_TEST_LIST_BEGIN + VMIME_TEST(testMakeStringFromBytes) + VMIME_TEST(testAppendBytesToString) + VMIME_TEST(testIsStringEqualNoCase1) VMIME_TEST(testIsStringEqualNoCase2) VMIME_TEST(testIsStringEqualNoCase3) @@ -46,6 +49,38 @@ VMIME_TEST_SUITE_BEGIN(stringUtilsTest) typedef vmime::utility::stringUtils stringUtils; + void testMakeStringFromBytes() + { + vmime::byte_t bytes[] = { 0x12, 0x34, 0x56, 0x78 }; + vmime::string str = vmime::utility::stringUtils::makeStringFromBytes(bytes, 3); + + VASSERT_EQ("length", 3, str.length()); + VASSERT_EQ("byte1", '\x12', str[0]); + VASSERT_EQ("byte2", '\x34', str[1]); + VASSERT_EQ("byte3", '\x56', str[2]); + } + + void testAppendBytesToString() + { + vmime::byte_t bytes[] = { 0x42, 0x56, 0x12, 0x00, 'f', 'o', 'o' }; + + vmime::string str = "test"; + vmime::utility::stringUtils::appendBytesToString(str, bytes, 7); + + VASSERT_EQ("length", 4 + 7, str.length()); + VASSERT_EQ("byte1", 't', str[0]); + VASSERT_EQ("byte2", 'e', str[1]); + VASSERT_EQ("byte3", 's', str[2]); + VASSERT_EQ("byte4", 't', str[3]); + VASSERT_EQ("byte5", '\x42', str[4]); + VASSERT_EQ("byte6", '\x56', str[5]); + VASSERT_EQ("byte7", '\x12', str[6]); + VASSERT_EQ("byte8", '\0', str[7]); + VASSERT_EQ("byte9", 'f', str[8]); + VASSERT_EQ("byte10", 'o', str[9]); + VASSERT_EQ("byte11", 'o', str[10]); + } + void testIsStringEqualNoCase1() { VASSERT_EQ("1", true, stringUtils::isStringEqualNoCase(vmime::string("foo"), "foo", 3)); @@ -101,19 +136,19 @@ VMIME_TEST_SUITE_BEGIN(stringUtilsTest) void testCountASCIIChars() { vmime::string str1("foo"); - VASSERT_EQ("1", static_cast (3), + VASSERT_EQ("1", static_cast (3), stringUtils::countASCIIchars(str1.begin(), str1.end())); vmime::string str2("f=?oo"); - VASSERT_EQ("2", static_cast (3 + 1), + VASSERT_EQ("2", static_cast (3 + 1), stringUtils::countASCIIchars(str2.begin(), str2.end())); vmime::string str3("foo\x7f"); - VASSERT_EQ("3", static_cast (4), + VASSERT_EQ("3", static_cast (4), stringUtils::countASCIIchars(str3.begin(), str3.end())); vmime::string str4("foo\x80"); - VASSERT_EQ("4", static_cast (3), + VASSERT_EQ("4", static_cast (3), stringUtils::countASCIIchars(str4.begin(), str4.end())); } diff --git a/vmime/address.hpp b/vmime/address.hpp index 110e1e6b..5eb510f9 100644 --- a/vmime/address.hpp +++ b/vmime/address.hpp @@ -76,8 +76,8 @@ public: */ static shared_ptr
parseNext (const parsingContext& ctx, const string& buffer, - const string::size_type position, const string::size_type end, - string::size_type* newPosition, bool *isLastAddressOfGroup); + const size_t position, const size_t end, + size_t* newPosition, bool *isLastAddressOfGroup); }; diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp index 2987b1ac..0df657d3 100644 --- a/vmime/addressList.hpp +++ b/vmime/addressList.hpp @@ -174,15 +174,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/base.hpp b/vmime/base.hpp index 36938cb7..f6515794 100644 --- a/vmime/base.hpp +++ b/vmime/base.hpp @@ -156,7 +156,7 @@ namespace vmime namespace lineLengthLimits { - extern VMIME_EXPORT const string::size_type infinite; + extern VMIME_EXPORT const size_t infinite; enum { @@ -168,7 +168,7 @@ namespace vmime // New line sequence to be used when folding header fields. extern VMIME_EXPORT const string NEW_LINE_SEQUENCE; - extern VMIME_EXPORT const string::size_type NEW_LINE_SEQUENCE_LENGTH; + extern VMIME_EXPORT const size_t NEW_LINE_SEQUENCE_LENGTH; // CR-LF sequence @@ -182,6 +182,12 @@ namespace vmime namespace utility { } + /** Constant value with the greatest possible value for an element + * of type size_t. The meaning is "infinite" or "until the end". + */ + extern VMIME_EXPORT const size_t npos; + + /** Clone helper (using a shared_ptr). * This is an alias for dynamic_pointer_cast (obj->clone()). */ diff --git a/vmime/body.hpp b/vmime/body.hpp index 465a7a81..e47f97e9 100644 --- a/vmime/body.hpp +++ b/vmime/body.hpp @@ -280,7 +280,7 @@ public: const std::vector > getChildComponents(); - utility::stream::size_type getGeneratedSize(const generationContext& ctx); + size_t getGeneratedSize(const generationContext& ctx); private: @@ -315,26 +315,26 @@ protected: * CR/LF and "--" before the boundary) * @param boundaryEnd will hold the end position of the boundary (position just * before the CRLF or "--" which follows) - * @return the position of the boundary string, or stream::npos if not found + * @return the position of the boundary string, or npos if not found */ - utility::stream::size_type findNextBoundaryPosition + size_t findNextBoundaryPosition (shared_ptr parser, const string& boundary, - const utility::stream::size_type position, const utility::stream::size_type end, - utility::stream::size_type* boundaryStart, utility::stream::size_type* boundaryEnd); + const size_t position, const size_t end, + size_t* boundaryStart, size_t* boundaryEnd); // Component parsing & assembling void parseImpl (const parsingContext& ctx, shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/bodyPart.hpp b/vmime/bodyPart.hpp index fd0deb73..214cb208 100644 --- a/vmime/bodyPart.hpp +++ b/vmime/bodyPart.hpp @@ -102,7 +102,7 @@ public: const std::vector > getChildComponents(); - utility::stream::size_type getGeneratedSize(const generationContext& ctx); + size_t getGeneratedSize(const generationContext& ctx); private: @@ -137,15 +137,15 @@ protected: void parseImpl (const parsingContext& ctx, shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/charset.hpp b/vmime/charset.hpp index 9c1325c6..5bd50fdf 100644 --- a/vmime/charset.hpp +++ b/vmime/charset.hpp @@ -130,15 +130,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/charsetConverter_iconv.hpp b/vmime/charsetConverter_iconv.hpp index 0309d848..4167dc4e 100644 --- a/vmime/charsetConverter_iconv.hpp +++ b/vmime/charsetConverter_iconv.hpp @@ -93,9 +93,12 @@ public: outputStream& getNextOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: // Maximum character width in any charset @@ -112,12 +115,12 @@ private: // Buffer in which unconverted bytes are left until they can // be converted (when more data arrives). The length should be // large enough to contain any character in any charset. - value_type m_unconvBuffer[MAX_CHARACTER_WIDTH]; - size_type m_unconvCount; + byte_t m_unconvBuffer[MAX_CHARACTER_WIDTH]; + size_t m_unconvCount; // Buffer used for conversion. Avoids declaring it in write(). // Should be at least MAX_CHARACTER_WIDTH * MAX_CHARACTER_WIDTH. - value_type m_outputBuffer[32768]; + byte_t m_outputBuffer[32768]; }; diff --git a/vmime/charsetConverter_icu.hpp b/vmime/charsetConverter_icu.hpp index 91cf0b86..5d054413 100644 --- a/vmime/charsetConverter_icu.hpp +++ b/vmime/charsetConverter_icu.hpp @@ -97,9 +97,12 @@ public: outputStream& getNextOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: UConverter* m_from; diff --git a/vmime/component.hpp b/vmime/component.hpp index 0c3716cb..87d465e8 100644 --- a/vmime/component.hpp +++ b/vmime/component.hpp @@ -70,7 +70,7 @@ public: * @param inputStream stream from which to read data * @param length data length, in bytes (0 = unknown/not specified) */ - void parse(shared_ptr inputStream, const utility::stream::size_type length); + void parse(shared_ptr inputStream, const size_t length); /** Parse RFC-822/MIME data for this component, using the default * parsing context. @@ -82,9 +82,9 @@ public: */ void parse (const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); /** Parse RFC-822/MIME data for this component. * @@ -97,9 +97,9 @@ public: void parse (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); /** Parse RFC-822/MIME data for this component. If stream is not seekable, * or if end position is not specified, entire contents of the stream will @@ -113,9 +113,9 @@ public: */ void parse (shared_ptr inputStream, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); /** Parse RFC-822/MIME data for this component. If stream is not seekable, * or if end position is not specified, entire contents of the stream will @@ -130,9 +130,9 @@ public: void parse (const parsingContext& ctx, shared_ptr inputStream, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); /** Generate RFC-2822/MIME data for this component. * @@ -143,8 +143,8 @@ public: * @return generated data */ virtual const string generate - (const string::size_type maxLineLength = lineLengthLimits::infinite, - const string::size_type curLinePos = 0) const; + (const size_t maxLineLength = lineLengthLimits::infinite, + const size_t curLinePos = 0) const; /** Generate RFC-2822/MIME data for this component, using the default generation context. * @@ -154,8 +154,8 @@ public: */ virtual void generate (utility::outputStream& outputStream, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; /** Generate RFC-2822/MIME data for this component, using the default generation context. * @@ -167,8 +167,8 @@ public: virtual void generate (const generationContext& ctx, utility::outputStream& outputStream, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; /** Clone this component. * @@ -191,7 +191,7 @@ public: * @return start position in parsed buffer * or 0 if this component has not been parsed */ - utility::stream::size_type getParsedOffset() const; + size_t getParsedOffset() const; /** Return the length of this component in the * parsed message contents. Use for debugging only. @@ -199,7 +199,7 @@ public: * @return length of the component in parsed buffer * or 0 if this component has not been parsed */ - utility::stream::size_type getParsedLength() const; + size_t getParsedLength() const; /** Return the list of children of this component. * @@ -215,39 +215,39 @@ public: * @param ctx generation context * @return component size when generated */ - virtual utility::stream::size_type getGeneratedSize(const generationContext& ctx); + virtual size_t getGeneratedSize(const generationContext& ctx); protected: - void setParsedBounds(const utility::stream::size_type start, const utility::stream::size_type end); + void setParsedBounds(const size_t start, const size_t end); // AT LEAST ONE of these parseImpl() functions MUST be implemented in derived class virtual void parseImpl (const parsingContext& ctx, shared_ptr parser, - const utility::stream::size_type position, - const utility::stream::size_type end, - utility::stream::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); virtual void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); virtual void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const = 0; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const = 0; private: - void offsetParsedBounds(const utility::stream::size_type offset); + void offsetParsedBounds(const size_t offset); - utility::stream::size_type m_parsedOffset; - utility::stream::size_type m_parsedLength; + size_t m_parsedOffset; + size_t m_parsedLength; }; diff --git a/vmime/constants.hpp b/vmime/constants.hpp index b4747f60..8e6e3f83 100644 --- a/vmime/constants.hpp +++ b/vmime/constants.hpp @@ -43,173 +43,173 @@ namespace vmime namespace mediaTypes { // Types - extern VMIME_EXPORT const string::value_type* const TEXT; - extern VMIME_EXPORT const string::value_type* const MULTIPART; - extern VMIME_EXPORT const string::value_type* const MESSAGE; - extern VMIME_EXPORT const string::value_type* const APPLICATION; - extern VMIME_EXPORT const string::value_type* const IMAGE; - extern VMIME_EXPORT const string::value_type* const AUDIO; - extern VMIME_EXPORT const string::value_type* const VIDEO; + extern VMIME_EXPORT const char* const TEXT; + extern VMIME_EXPORT const char* const MULTIPART; + extern VMIME_EXPORT const char* const MESSAGE; + extern VMIME_EXPORT const char* const APPLICATION; + extern VMIME_EXPORT const char* const IMAGE; + extern VMIME_EXPORT const char* const AUDIO; + extern VMIME_EXPORT const char* const VIDEO; // Sub-types - extern VMIME_EXPORT const string::value_type* const TEXT_PLAIN; - extern VMIME_EXPORT const string::value_type* const TEXT_HTML; - extern VMIME_EXPORT const string::value_type* const TEXT_RICHTEXT; - extern VMIME_EXPORT const string::value_type* const TEXT_ENRICHED; - extern VMIME_EXPORT const string::value_type* const TEXT_RFC822_HEADERS; // RFC-1892 - extern VMIME_EXPORT const string::value_type* const TEXT_DIRECTORY; // RFC-2426 + extern VMIME_EXPORT const char* const TEXT_PLAIN; + extern VMIME_EXPORT const char* const TEXT_HTML; + extern VMIME_EXPORT const char* const TEXT_RICHTEXT; + extern VMIME_EXPORT const char* const TEXT_ENRICHED; + extern VMIME_EXPORT const char* const TEXT_RFC822_HEADERS; // RFC-1892 + extern VMIME_EXPORT const char* const TEXT_DIRECTORY; // RFC-2426 - extern VMIME_EXPORT const string::value_type* const MULTIPART_MIXED; - extern VMIME_EXPORT const string::value_type* const MULTIPART_RELATED; - extern VMIME_EXPORT const string::value_type* const MULTIPART_ALTERNATIVE; - extern VMIME_EXPORT const string::value_type* const MULTIPART_PARALLEL; - extern VMIME_EXPORT const string::value_type* const MULTIPART_DIGEST; - extern VMIME_EXPORT const string::value_type* const MULTIPART_REPORT; // RFC-1892 + extern VMIME_EXPORT const char* const MULTIPART_MIXED; + extern VMIME_EXPORT const char* const MULTIPART_RELATED; + extern VMIME_EXPORT const char* const MULTIPART_ALTERNATIVE; + extern VMIME_EXPORT const char* const MULTIPART_PARALLEL; + extern VMIME_EXPORT const char* const MULTIPART_DIGEST; + extern VMIME_EXPORT const char* const MULTIPART_REPORT; // RFC-1892 - extern VMIME_EXPORT const string::value_type* const MESSAGE_RFC822; - extern VMIME_EXPORT const string::value_type* const MESSAGE_PARTIAL; - extern VMIME_EXPORT const string::value_type* const MESSAGE_EXTERNAL_BODY; - extern VMIME_EXPORT const string::value_type* const MESSAGE_DISPOSITION_NOTIFICATION; + extern VMIME_EXPORT const char* const MESSAGE_RFC822; + extern VMIME_EXPORT const char* const MESSAGE_PARTIAL; + extern VMIME_EXPORT const char* const MESSAGE_EXTERNAL_BODY; + extern VMIME_EXPORT const char* const MESSAGE_DISPOSITION_NOTIFICATION; - extern VMIME_EXPORT const string::value_type* const APPLICATION_OCTET_STREAM; + extern VMIME_EXPORT const char* const APPLICATION_OCTET_STREAM; - extern VMIME_EXPORT const string::value_type* const IMAGE_JPEG; - extern VMIME_EXPORT const string::value_type* const IMAGE_GIF; + extern VMIME_EXPORT const char* const IMAGE_JPEG; + extern VMIME_EXPORT const char* const IMAGE_GIF; - extern VMIME_EXPORT const string::value_type* const AUDIO_BASIC; + extern VMIME_EXPORT const char* const AUDIO_BASIC; - extern VMIME_EXPORT const string::value_type* const VIDEO_MPEG; + extern VMIME_EXPORT const char* const VIDEO_MPEG; } /** Constants for encoding types. */ namespace encodingTypes { - extern VMIME_EXPORT const string::value_type* const SEVEN_BIT; - extern VMIME_EXPORT const string::value_type* const EIGHT_BIT; - extern VMIME_EXPORT const string::value_type* const BASE64; - extern VMIME_EXPORT const string::value_type* const QUOTED_PRINTABLE; - extern VMIME_EXPORT const string::value_type* const BINARY; - extern VMIME_EXPORT const string::value_type* const UUENCODE; + extern VMIME_EXPORT const char* const SEVEN_BIT; + extern VMIME_EXPORT const char* const EIGHT_BIT; + extern VMIME_EXPORT const char* const BASE64; + extern VMIME_EXPORT const char* const QUOTED_PRINTABLE; + extern VMIME_EXPORT const char* const BINARY; + extern VMIME_EXPORT const char* const UUENCODE; } /** Constants for content disposition types (RFC-2183). */ namespace contentDispositionTypes { - extern VMIME_EXPORT const string::value_type* const INLINE; - extern VMIME_EXPORT const string::value_type* const ATTACHMENT; + extern VMIME_EXPORT const char* const INLINE; + extern VMIME_EXPORT const char* const ATTACHMENT; } /** Constants for charsets. */ namespace charsets { - extern VMIME_EXPORT const string::value_type* const ISO8859_1; - extern VMIME_EXPORT const string::value_type* const ISO8859_2; - extern VMIME_EXPORT const string::value_type* const ISO8859_3; - extern VMIME_EXPORT const string::value_type* const ISO8859_4; - extern VMIME_EXPORT const string::value_type* const ISO8859_5; - extern VMIME_EXPORT const string::value_type* const ISO8859_6; - extern VMIME_EXPORT const string::value_type* const ISO8859_7; - extern VMIME_EXPORT const string::value_type* const ISO8859_8; - extern VMIME_EXPORT const string::value_type* const ISO8859_9; - extern VMIME_EXPORT const string::value_type* const ISO8859_10; - extern VMIME_EXPORT const string::value_type* const ISO8859_13; - extern VMIME_EXPORT const string::value_type* const ISO8859_14; - extern VMIME_EXPORT const string::value_type* const ISO8859_15; - extern VMIME_EXPORT const string::value_type* const ISO8859_16; + extern VMIME_EXPORT const char* const ISO8859_1; + extern VMIME_EXPORT const char* const ISO8859_2; + extern VMIME_EXPORT const char* const ISO8859_3; + extern VMIME_EXPORT const char* const ISO8859_4; + extern VMIME_EXPORT const char* const ISO8859_5; + extern VMIME_EXPORT const char* const ISO8859_6; + extern VMIME_EXPORT const char* const ISO8859_7; + extern VMIME_EXPORT const char* const ISO8859_8; + extern VMIME_EXPORT const char* const ISO8859_9; + extern VMIME_EXPORT const char* const ISO8859_10; + extern VMIME_EXPORT const char* const ISO8859_13; + extern VMIME_EXPORT const char* const ISO8859_14; + extern VMIME_EXPORT const char* const ISO8859_15; + extern VMIME_EXPORT const char* const ISO8859_16; - extern VMIME_EXPORT const string::value_type* const CP_437; - extern VMIME_EXPORT const string::value_type* const CP_737; - extern VMIME_EXPORT const string::value_type* const CP_775; - extern VMIME_EXPORT const string::value_type* const CP_850; - extern VMIME_EXPORT const string::value_type* const CP_852; - extern VMIME_EXPORT const string::value_type* const CP_853; - extern VMIME_EXPORT const string::value_type* const CP_855; - extern VMIME_EXPORT const string::value_type* const CP_857; - extern VMIME_EXPORT const string::value_type* const CP_858; - extern VMIME_EXPORT const string::value_type* const CP_860; - extern VMIME_EXPORT const string::value_type* const CP_861; - extern VMIME_EXPORT const string::value_type* const CP_862; - extern VMIME_EXPORT const string::value_type* const CP_863; - extern VMIME_EXPORT const string::value_type* const CP_864; - extern VMIME_EXPORT const string::value_type* const CP_865; - extern VMIME_EXPORT const string::value_type* const CP_866; - extern VMIME_EXPORT const string::value_type* const CP_869; - extern VMIME_EXPORT const string::value_type* const CP_874; - extern VMIME_EXPORT const string::value_type* const CP_1125; - extern VMIME_EXPORT const string::value_type* const CP_1250; - extern VMIME_EXPORT const string::value_type* const CP_1251; - extern VMIME_EXPORT const string::value_type* const CP_1252; - extern VMIME_EXPORT const string::value_type* const CP_1253; - extern VMIME_EXPORT const string::value_type* const CP_1254; - extern VMIME_EXPORT const string::value_type* const CP_1255; - extern VMIME_EXPORT const string::value_type* const CP_1256; - extern VMIME_EXPORT const string::value_type* const CP_1257; + extern VMIME_EXPORT const char* const CP_437; + extern VMIME_EXPORT const char* const CP_737; + extern VMIME_EXPORT const char* const CP_775; + extern VMIME_EXPORT const char* const CP_850; + extern VMIME_EXPORT const char* const CP_852; + extern VMIME_EXPORT const char* const CP_853; + extern VMIME_EXPORT const char* const CP_855; + extern VMIME_EXPORT const char* const CP_857; + extern VMIME_EXPORT const char* const CP_858; + extern VMIME_EXPORT const char* const CP_860; + extern VMIME_EXPORT const char* const CP_861; + extern VMIME_EXPORT const char* const CP_862; + extern VMIME_EXPORT const char* const CP_863; + extern VMIME_EXPORT const char* const CP_864; + extern VMIME_EXPORT const char* const CP_865; + extern VMIME_EXPORT const char* const CP_866; + extern VMIME_EXPORT const char* const CP_869; + extern VMIME_EXPORT const char* const CP_874; + extern VMIME_EXPORT const char* const CP_1125; + extern VMIME_EXPORT const char* const CP_1250; + extern VMIME_EXPORT const char* const CP_1251; + extern VMIME_EXPORT const char* const CP_1252; + extern VMIME_EXPORT const char* const CP_1253; + extern VMIME_EXPORT const char* const CP_1254; + extern VMIME_EXPORT const char* const CP_1255; + extern VMIME_EXPORT const char* const CP_1256; + extern VMIME_EXPORT const char* const CP_1257; - extern VMIME_EXPORT const string::value_type* const US_ASCII; + extern VMIME_EXPORT const char* const US_ASCII; - extern VMIME_EXPORT const string::value_type* const UTF_7; - extern VMIME_EXPORT const string::value_type* const UTF_8; - extern VMIME_EXPORT const string::value_type* const UTF_16; - extern VMIME_EXPORT const string::value_type* const UTF_32; + extern VMIME_EXPORT const char* const UTF_7; + extern VMIME_EXPORT const char* const UTF_8; + extern VMIME_EXPORT const char* const UTF_16; + extern VMIME_EXPORT const char* const UTF_32; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1250; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1251; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1252; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1253; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1254; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1255; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1256; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1257; - extern VMIME_EXPORT const string::value_type* const WINDOWS_1258; + extern VMIME_EXPORT const char* const WINDOWS_1250; + extern VMIME_EXPORT const char* const WINDOWS_1251; + extern VMIME_EXPORT const char* const WINDOWS_1252; + extern VMIME_EXPORT const char* const WINDOWS_1253; + extern VMIME_EXPORT const char* const WINDOWS_1254; + extern VMIME_EXPORT const char* const WINDOWS_1255; + extern VMIME_EXPORT const char* const WINDOWS_1256; + extern VMIME_EXPORT const char* const WINDOWS_1257; + extern VMIME_EXPORT const char* const WINDOWS_1258; - extern VMIME_EXPORT const string::value_type* const IDNA; + extern VMIME_EXPORT const char* const IDNA; } /** Constants for standard field names. */ namespace fields { - extern VMIME_EXPORT const string::value_type* const RECEIVED; - extern VMIME_EXPORT const string::value_type* const FROM; - extern VMIME_EXPORT const string::value_type* const SENDER; - extern VMIME_EXPORT const string::value_type* const REPLY_TO; - extern VMIME_EXPORT const string::value_type* const TO; - extern VMIME_EXPORT const string::value_type* const CC; - extern VMIME_EXPORT const string::value_type* const BCC; - extern VMIME_EXPORT const string::value_type* const DATE; - extern VMIME_EXPORT const string::value_type* const SUBJECT; - extern VMIME_EXPORT const string::value_type* const ORGANIZATION; - extern VMIME_EXPORT const string::value_type* const USER_AGENT; - extern VMIME_EXPORT const string::value_type* const DELIVERED_TO; - extern VMIME_EXPORT const string::value_type* const RETURN_PATH; - extern VMIME_EXPORT const string::value_type* const MIME_VERSION; - extern VMIME_EXPORT const string::value_type* const MESSAGE_ID; - extern VMIME_EXPORT const string::value_type* const CONTENT_TYPE; - extern VMIME_EXPORT const string::value_type* const CONTENT_TRANSFER_ENCODING; - extern VMIME_EXPORT const string::value_type* const CONTENT_DESCRIPTION; - extern VMIME_EXPORT const string::value_type* const CONTENT_DISPOSITION; - extern VMIME_EXPORT const string::value_type* const CONTENT_ID; - extern VMIME_EXPORT const string::value_type* const CONTENT_LOCATION; - extern VMIME_EXPORT const string::value_type* const IN_REPLY_TO; - extern VMIME_EXPORT const string::value_type* const REFERENCES; + extern VMIME_EXPORT const char* const RECEIVED; + extern VMIME_EXPORT const char* const FROM; + extern VMIME_EXPORT const char* const SENDER; + extern VMIME_EXPORT const char* const REPLY_TO; + extern VMIME_EXPORT const char* const TO; + extern VMIME_EXPORT const char* const CC; + extern VMIME_EXPORT const char* const BCC; + extern VMIME_EXPORT const char* const DATE; + extern VMIME_EXPORT const char* const SUBJECT; + extern VMIME_EXPORT const char* const ORGANIZATION; + extern VMIME_EXPORT const char* const USER_AGENT; + extern VMIME_EXPORT const char* const DELIVERED_TO; + extern VMIME_EXPORT const char* const RETURN_PATH; + extern VMIME_EXPORT const char* const MIME_VERSION; + extern VMIME_EXPORT const char* const MESSAGE_ID; + extern VMIME_EXPORT const char* const CONTENT_TYPE; + extern VMIME_EXPORT const char* const CONTENT_TRANSFER_ENCODING; + extern VMIME_EXPORT const char* const CONTENT_DESCRIPTION; + extern VMIME_EXPORT const char* const CONTENT_DISPOSITION; + extern VMIME_EXPORT const char* const CONTENT_ID; + extern VMIME_EXPORT const char* const CONTENT_LOCATION; + extern VMIME_EXPORT const char* const IN_REPLY_TO; + extern VMIME_EXPORT const char* const REFERENCES; - extern VMIME_EXPORT const string::value_type* const X_MAILER; - extern VMIME_EXPORT const string::value_type* const X_PRIORITY; + extern VMIME_EXPORT const char* const X_MAILER; + extern VMIME_EXPORT const char* const X_PRIORITY; // RFC-3798: Message Disposition Notification - extern VMIME_EXPORT const string::value_type* const ORIGINAL_MESSAGE_ID; - extern VMIME_EXPORT const string::value_type* const DISPOSITION_NOTIFICATION_TO; - extern VMIME_EXPORT const string::value_type* const DISPOSITION_NOTIFICATION_OPTIONS; - extern VMIME_EXPORT const string::value_type* const DISPOSITION; - extern VMIME_EXPORT const string::value_type* const FAILURE; - extern VMIME_EXPORT const string::value_type* const ERROR; - extern VMIME_EXPORT const string::value_type* const WARNING; - extern VMIME_EXPORT const string::value_type* const ORIGINAL_RECIPIENT; - extern VMIME_EXPORT const string::value_type* const FINAL_RECIPIENT; - extern VMIME_EXPORT const string::value_type* const REPORTING_UA; - extern VMIME_EXPORT const string::value_type* const MDN_GATEWAY; + extern VMIME_EXPORT const char* const ORIGINAL_MESSAGE_ID; + extern VMIME_EXPORT const char* const DISPOSITION_NOTIFICATION_TO; + extern VMIME_EXPORT const char* const DISPOSITION_NOTIFICATION_OPTIONS; + extern VMIME_EXPORT const char* const DISPOSITION; + extern VMIME_EXPORT const char* const FAILURE; + extern VMIME_EXPORT const char* const ERROR; + extern VMIME_EXPORT const char* const WARNING; + extern VMIME_EXPORT const char* const ORIGINAL_RECIPIENT; + extern VMIME_EXPORT const char* const FINAL_RECIPIENT; + extern VMIME_EXPORT const char* const REPORTING_UA; + extern VMIME_EXPORT const char* const MDN_GATEWAY; } /** Constants for disposition action modes (RFC-3978). */ @@ -217,10 +217,10 @@ namespace vmime { /** User implicitely displayed or deleted the message (filter or * any other automatic action). */ - extern VMIME_EXPORT const string::value_type* const AUTOMATIC; + extern VMIME_EXPORT const char* const AUTOMATIC; /** User explicitely displayed or deleted the message (manual action). */ - extern VMIME_EXPORT const string::value_type* const MANUAL; + extern VMIME_EXPORT const char* const MANUAL; } /** Constants for disposition sending modes (RFC-3798). */ @@ -228,27 +228,27 @@ namespace vmime { /** The MDN was sent because the MUA had previously been configured * to do so automatically. */ - extern VMIME_EXPORT const string::value_type* const SENT_AUTOMATICALLY; + extern VMIME_EXPORT const char* const SENT_AUTOMATICALLY; /** User explicitly gave permission for this particular MDN to be sent. */ - extern VMIME_EXPORT const string::value_type* const SENT_MANUALLY; + extern VMIME_EXPORT const char* const SENT_MANUALLY; } /** Constants for disposition types (RFC-3798). */ namespace dispositionTypes { /** Message has been displayed to the user. */ - extern VMIME_EXPORT const string::value_type* const DISPLAYED; + extern VMIME_EXPORT const char* const DISPLAYED; /** Message has been deleted without being displayed. */ - extern VMIME_EXPORT const string::value_type* const DELETED; + extern VMIME_EXPORT const char* const DELETED; /** Message has been denied. */ - extern VMIME_EXPORT const string::value_type* const DENIED; + extern VMIME_EXPORT const char* const DENIED; } /** Constants for disposition modifiers (RFC-3798). */ namespace dispositionModifiers { - extern VMIME_EXPORT const string::value_type* const ERROR; + extern VMIME_EXPORT const char* const ERROR; } } diff --git a/vmime/contentDisposition.hpp b/vmime/contentDisposition.hpp index 0f417111..c934b81d 100644 --- a/vmime/contentDisposition.hpp +++ b/vmime/contentDisposition.hpp @@ -81,15 +81,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/contentHandler.hpp b/vmime/contentHandler.hpp index 5ae9e02b..f62af166 100644 --- a/vmime/contentHandler.hpp +++ b/vmime/contentHandler.hpp @@ -63,7 +63,7 @@ public: * @param enc encoding for output * @param maxLineLength maximum line length for output */ - virtual void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const = 0; + virtual void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const = 0; /** Extract the contents into the specified stream. If needed, data * will be decoded before being written into the stream. @@ -92,7 +92,7 @@ public: * * @return length of data */ - virtual string::size_type getLength() const = 0; + virtual size_t getLength() const = 0; /** Returns 'true' if data managed by this object is encoded. * diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp index 8a596f02..7af63040 100644 --- a/vmime/dateTime.hpp +++ b/vmime/dateTime.hpp @@ -245,15 +245,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/disposition.hpp b/vmime/disposition.hpp index 01de1653..7322c21d 100644 --- a/vmime/disposition.hpp +++ b/vmime/disposition.hpp @@ -140,15 +140,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/emailAddress.hpp b/vmime/emailAddress.hpp index e46afdf6..30ee24ab 100644 --- a/vmime/emailAddress.hpp +++ b/vmime/emailAddress.hpp @@ -117,15 +117,15 @@ public: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/emptyContentHandler.hpp b/vmime/emptyContentHandler.hpp index 1307f7eb..369a4206 100644 --- a/vmime/emptyContentHandler.hpp +++ b/vmime/emptyContentHandler.hpp @@ -40,12 +40,12 @@ public: shared_ptr clone() const; - void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; + void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os, utility::progressListener* progress = NULL) const; void extractRaw(utility::outputStream& os, utility::progressListener* progress = NULL) const; - string::size_type getLength() const; + size_t getLength() const; bool isEncoded() const; diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp index ba07a25f..3148f899 100644 --- a/vmime/encoding.hpp +++ b/vmime/encoding.hpp @@ -154,15 +154,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/fileAttachment.hpp b/vmime/fileAttachment.hpp index 2d9ff575..1e7a808a 100644 --- a/vmime/fileAttachment.hpp +++ b/vmime/fileAttachment.hpp @@ -158,18 +158,18 @@ public: * * @return file size */ - utility::stream::size_type getSize() const; + size_t getSize() const; /** Set the value of the 'size' property. * * @param size file size */ - void setSize(const utility::stream::size_type size); + void setSize(const size_t size); private: word* m_filename; - utility::stream::size_type* m_size; + size_t * m_size; datetime* m_creationDate; datetime* m_modifDate; datetime* m_readDate; diff --git a/vmime/generationContext.hpp b/vmime/generationContext.hpp index 743ae6f5..949f06ac 100644 --- a/vmime/generationContext.hpp +++ b/vmime/generationContext.hpp @@ -46,7 +46,7 @@ public: * * @return current maximum line length, in bytes */ - string::size_type getMaxLineLength() const; + size_t getMaxLineLength() const; /** Sets the maximum line length used when generating messages. * You may use the constants lineLengthLimits::convenient, @@ -54,7 +54,7 @@ public: * * @param maxLineLength new maximum line length, in bytes */ - void setMaxLineLength(const string::size_type maxLineLength); + void setMaxLineLength(const size_t maxLineLength); /** Returns the current prolog text used when generating MIME body parts. * @@ -93,7 +93,7 @@ public: protected: - string::size_type m_maxLineLength; + size_t m_maxLineLength; string m_prologText; string m_epilogText; diff --git a/vmime/header.hpp b/vmime/header.hpp index 4490e5d6..d2d20727 100644 --- a/vmime/header.hpp +++ b/vmime/header.hpp @@ -291,7 +291,7 @@ public: const std::vector > getChildComponents(); - utility::stream::size_type getGeneratedSize(const generationContext& ctx); + size_t getGeneratedSize(const generationContext& ctx); private: @@ -328,15 +328,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/headerField.hpp b/vmime/headerField.hpp index c9972317..555805db 100644 --- a/vmime/headerField.hpp +++ b/vmime/headerField.hpp @@ -157,26 +157,26 @@ public: static shared_ptr parseNext (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); - utility::stream::size_type getGeneratedSize(const generationContext& ctx); + size_t getGeneratedSize(const generationContext& ctx); protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; string m_name; diff --git a/vmime/headerFieldValue.hpp b/vmime/headerFieldValue.hpp index 2a04a823..a3681953 100644 --- a/vmime/headerFieldValue.hpp +++ b/vmime/headerFieldValue.hpp @@ -41,7 +41,7 @@ class VMIME_EXPORT headerFieldValue : public component { public: - utility::stream::size_type getGeneratedSize(const generationContext& ctx); + size_t getGeneratedSize(const generationContext& ctx); }; diff --git a/vmime/mailbox.hpp b/vmime/mailbox.hpp index 586f88ee..88abc0f5 100644 --- a/vmime/mailbox.hpp +++ b/vmime/mailbox.hpp @@ -105,15 +105,15 @@ public: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/mailboxField.hpp b/vmime/mailboxField.hpp index 75cae592..ca6863c0 100644 --- a/vmime/mailboxField.hpp +++ b/vmime/mailboxField.hpp @@ -53,8 +53,8 @@ protected: public: void parse(const parsingContext& ctx, const string& buffer, - const string::size_type position, const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, const size_t end, + size_t * newPosition = NULL); }; diff --git a/vmime/mailboxGroup.hpp b/vmime/mailboxGroup.hpp index a85c0232..b264cf60 100644 --- a/vmime/mailboxGroup.hpp +++ b/vmime/mailboxGroup.hpp @@ -176,15 +176,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/mailboxList.hpp b/vmime/mailboxList.hpp index 4003b680..125c238e 100644 --- a/vmime/mailboxList.hpp +++ b/vmime/mailboxList.hpp @@ -166,15 +166,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/mediaType.hpp b/vmime/mediaType.hpp index c2b214bd..a7d6f4e4 100644 --- a/vmime/mediaType.hpp +++ b/vmime/mediaType.hpp @@ -101,15 +101,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/message.hpp b/vmime/message.hpp index 22523efc..62ff77e1 100644 --- a/vmime/message.hpp +++ b/vmime/message.hpp @@ -50,8 +50,8 @@ public: // Override default generate() functions so that we can change // the default 'maxLineLength' value const string generate - (const string::size_type maxLineLength = generationContext::getDefaultContext().getMaxLineLength(), - const string::size_type curLinePos = 0) const; + (const size_t maxLineLength = generationContext::getDefaultContext().getMaxLineLength(), + const size_t curLinePos = 0) const; }; diff --git a/vmime/messageId.hpp b/vmime/messageId.hpp index 8c2f85d1..83527468 100644 --- a/vmime/messageId.hpp +++ b/vmime/messageId.hpp @@ -110,15 +110,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; /** Parse a message-id from an input buffer. * @@ -131,9 +131,9 @@ protected: static shared_ptr parseNext (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition); + const size_t position, + const size_t end, + size_t* newPosition); }; diff --git a/vmime/messageIdSequence.hpp b/vmime/messageIdSequence.hpp index 39c415c7..07f0c422 100644 --- a/vmime/messageIdSequence.hpp +++ b/vmime/messageIdSequence.hpp @@ -154,15 +154,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/net/folder.hpp b/vmime/net/folder.hpp index deefaf49..38ba4597 100644 --- a/vmime/net/folder.hpp +++ b/vmime/net/folder.hpp @@ -282,7 +282,7 @@ public: * @param progress progress listener, or NULL if not used * @throw exceptions::net_exception if an error occurs */ - virtual void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL) = 0; + virtual void addMessage(utility::inputStream& is, const size_t size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL) = 0; /** Copy messages from this folder to another folder. * diff --git a/vmime/net/imap/IMAPConnection.hpp b/vmime/net/imap/IMAPConnection.hpp index bc5590ba..b38d0c27 100644 --- a/vmime/net/imap/IMAPConnection.hpp +++ b/vmime/net/imap/IMAPConnection.hpp @@ -80,7 +80,7 @@ public: void send(bool tag, const string& what, bool end); - void sendRaw(const char* buffer, const int count); + void sendRaw(const byte_t* buffer, const size_t count); IMAPParser::response* readResponse(IMAPParser::literalHandler* lh = NULL); diff --git a/vmime/net/imap/IMAPFolder.hpp b/vmime/net/imap/IMAPFolder.hpp index 5edbfb16..cc7334ff 100644 --- a/vmime/net/imap/IMAPFolder.hpp +++ b/vmime/net/imap/IMAPFolder.hpp @@ -106,7 +106,7 @@ public: void setMessageFlags(const messageSet& msgs, const int flags, const int mode = message::FLAG_MODE_SET); void addMessage(shared_ptr msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); - void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); + void addMessage(utility::inputStream& is, const size_t size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); void copyMessages(const folder::path& dest, const messageSet& msgs); diff --git a/vmime/net/imap/IMAPMessage.hpp b/vmime/net/imap/IMAPMessage.hpp index 272fe17b..92903d69 100644 --- a/vmime/net/imap/IMAPMessage.hpp +++ b/vmime/net/imap/IMAPMessage.hpp @@ -80,7 +80,7 @@ public: */ vmime_uint64 getModSequence() const; - int getSize() const; + size_t getSize() const; bool isExpunged() const; @@ -92,8 +92,18 @@ public: int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); - void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(shared_ptr p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extract + (utility::outputStream& os, + utility::progressListener* progress = NULL, + const size_t start = 0, const size_t length = -1, + const bool peek = false) const; + + void extractPart + (shared_ptr p, + utility::outputStream& os, + utility::progressListener* progress = NULL, + const size_t start = 0, const size_t length = -1, + const bool peek = false) const; void fetchPartHeader(shared_ptr p); @@ -144,8 +154,12 @@ private: EXTRACT_PEEK = 0x10 }; - void extractImpl(shared_ptr p, utility::outputStream& os, utility::progressListener* progress, - const int start, const int length, const int extractFlags) const; + void extractImpl + (shared_ptr p, + utility::outputStream& os, + utility::progressListener* progress, + const size_t start, const size_t length, + const int extractFlags) const; shared_ptr
getOrCreateHeader(); @@ -156,7 +170,7 @@ private: weak_ptr m_folder; int m_num; - int m_size; + size_t m_size; int m_flags; bool m_expunged; uid m_uid; diff --git a/vmime/net/imap/IMAPMessagePart.hpp b/vmime/net/imap/IMAPMessagePart.hpp index f71d7d43..af8581d7 100644 --- a/vmime/net/imap/IMAPMessagePart.hpp +++ b/vmime/net/imap/IMAPMessagePart.hpp @@ -57,7 +57,7 @@ public: shared_ptr getParent() const; const mediaType& getType() const; - int getSize() const; + size_t getSize() const; int getNumber() const; shared_ptr getHeader() const; @@ -76,7 +76,7 @@ private: shared_ptr
m_header; int m_number; - int m_size; + size_t m_size; mediaType m_mediaType; }; diff --git a/vmime/net/imap/IMAPMessagePartContentHandler.hpp b/vmime/net/imap/IMAPMessagePartContentHandler.hpp index 80e1f0e5..cb52b2e3 100644 --- a/vmime/net/imap/IMAPMessagePartContentHandler.hpp +++ b/vmime/net/imap/IMAPMessagePartContentHandler.hpp @@ -48,12 +48,12 @@ public: shared_ptr clone() const; - void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; + void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os, utility::progressListener* progress = NULL) const; void extractRaw(utility::outputStream& os, utility::progressListener* progress = NULL) const; - string::size_type getLength() const; + size_t getLength() const; bool isEncoded() const; diff --git a/vmime/net/imap/IMAPParser.hpp b/vmime/net/imap/IMAPParser.hpp index 519cadd8..0b90829e 100644 --- a/vmime/net/imap/IMAPParser.hpp +++ b/vmime/net/imap/IMAPParser.hpp @@ -78,7 +78,7 @@ namespace imap { { public: - IMAPParserDebugResponse(const string& name, string& line, const string::size_type currentPos) + IMAPParserDebugResponse(const string& name, string& line, const size_t currentPos) : m_name(name), m_line(line), m_pos(currentPos) { ++IMAPParserDebugResponse_level; @@ -100,7 +100,7 @@ namespace imap { std::cout << string(m_line.begin() + (m_pos < 30 ? 0U : m_pos - 30), m_line.begin() + std::min(m_line.length(), m_pos + 30)) << std::endl; - for (string::size_type i = (m_pos < 30 ? m_pos : (m_pos - (m_pos - 30))) ; i != 0 ; --i) + for (size_t i = (m_pos < 30 ? m_pos : (m_pos - (m_pos - 30))) ; i != 0 ; --i) std::cout << " "; std::cout << "^" << std::endl; @@ -123,7 +123,7 @@ namespace imap { const string& m_name; string& m_line; - string::size_type m_pos; + size_t m_pos; }; @@ -287,11 +287,11 @@ public: component() { } virtual ~component() { } - virtual void go(IMAPParser& parser, string& line, string::size_type* currentPos) = 0; + virtual void go(IMAPParser& parser, string& line, size_t* currentPos) = 0; const string makeResponseLine(const string& comp, const string& line, - const string::size_type pos) + const size_t pos) { #if DEBUG_RESPONSE if (pos > line.length()) @@ -311,7 +311,7 @@ public: #define COMPONENT_ALIAS(parent, name) \ class name : public parent \ { \ - void go(IMAPParser& parser, string& line, string::size_type* currentPos) \ + void go(IMAPParser& parser, string& line, size_t* currentPos) \ { \ DEBUG_ENTER_COMPONENT(#name); \ parent::go(parser, line, currentPos); \ @@ -328,11 +328,11 @@ public: { public: - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT(string("one_char <") + C + ">: current='" + ((*currentPos < line.length() ? line[*currentPos] : '?')) + "'"); - const string::size_type pos = *currentPos; + const size_t pos = *currentPos; if (pos < line.length() && line[pos] == C) *currentPos = pos + 1; @@ -350,11 +350,11 @@ public: { public: - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("SPACE"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; while (pos < line.length() && (line[pos] == ' ' || line[pos] == '\t')) ++pos; @@ -377,11 +377,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("CRLF"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check (line, &pos, true); @@ -414,11 +414,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("tag"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; bool end = false; @@ -489,11 +489,11 @@ public: { } - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("number"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; bool valid = true; unsigned int val = 0; @@ -567,12 +567,12 @@ public: { } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("text"); - string::size_type pos = *currentPos; - string::size_type len = 0; + size_t pos = *currentPos; + size_t len = 0; if (m_allow8bits || !parser.isStrict()) { @@ -681,11 +681,11 @@ public: { public: - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("quoted_char"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; const unsigned char c = static_cast (pos < line.length() ? line[pos] : 0); @@ -730,12 +730,12 @@ public: { public: - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("quoted_text"); - string::size_type pos = *currentPos; - string::size_type len = 0; + size_t pos = *currentPos; + size_t len = 0; bool valid = false; m_value.reserve(line.length() - pos); @@ -817,11 +817,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("NIL"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.checkWithArg (line, &pos, "nil"); @@ -853,11 +853,11 @@ public: { } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("string"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (m_canBeNIL && parser.checkWithArg (line, &pos, "nil", true)) @@ -883,7 +883,7 @@ public: { m_value = "[literal-handler]"; - const string::size_type length = text->value().length(); + const size_t length = text->value().length(); utility::progressListener* progress = target->progressListener(); if (progress) @@ -920,7 +920,7 @@ public: number* num = parser.get (line, &pos); - const string::size_type length = num->value(); + const size_t length = num->value(); delete (num); parser.check >(line, &pos); @@ -1001,11 +1001,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("astring"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; xstring* str = NULL; @@ -1050,12 +1050,12 @@ public: { public: - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("atom"); - string::size_type pos = *currentPos; - string::size_type len = 0; + size_t pos = *currentPos; + size_t len = 0; for (bool end = false ; !end && pos < line.length() ; ) { @@ -1131,11 +1131,11 @@ public: { } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT(string("special_atom(") + m_string + ")"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; atom::go(parser, line, &pos); @@ -1177,11 +1177,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("text_mime2"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; atom* theCharset = NULL, *theEncoding = NULL; text* theText = NULL; @@ -1282,11 +1282,11 @@ public: delete m_number; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("seq_number"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -1335,11 +1335,11 @@ public: delete m_last; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("seq_range"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_first = parser.get (line, &pos); @@ -1386,11 +1386,11 @@ public: delete m_nextSet; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("sequence_set"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if ((m_range = parser.get (line, &pos, true)) == NULL) m_number = parser.get (line, &pos); @@ -1429,11 +1429,11 @@ public: { } - void go(IMAPParser& /* parser */, string& line, string::size_type* currentPos) + void go(IMAPParser& /* parser */, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mod_sequence_value"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; bool valid = true; vmime_uint64 val = 0; @@ -1464,7 +1464,7 @@ public: public: - const vmime_uint64 value() const { return m_value; } + vmime_uint64 value() const { return m_value; } }; @@ -1497,11 +1497,11 @@ public: delete (m_flag_keyword); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("flag_keyword"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -1587,11 +1587,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("flag_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -1626,11 +1626,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mailbox"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.checkWithArg (line, &pos, "inbox", true)) { @@ -1677,11 +1677,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mailbox_flag"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -1755,11 +1755,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mailbox_flag_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -1803,11 +1803,11 @@ public: delete (m_mailbox); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mailbox_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_mailbox_flag_list = parser.get (line, &pos); @@ -1854,7 +1854,7 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("auth_type"); @@ -1914,11 +1914,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("status_att"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; // "HIGHESTMODSEQ" SP mod-sequence-valzer if (parser.checkWithArg (line, &pos, "highestmodseq", true)) @@ -2009,11 +2009,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("status_att_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_values.push_back(parser.get (line, &pos)); @@ -2054,11 +2054,11 @@ public: delete (m_atom); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("capability"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; class atom* at = parser.get (line, &pos); @@ -2071,7 +2071,7 @@ public: (str[3] == 'h' || str[3] == 'H') && (str[4] == '=')) { - string::size_type pos = 5; + size_t pos = 5; m_auth_type = parser.get (value, &pos); delete (at); } @@ -2116,11 +2116,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("capability_data"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.checkWithArg (line, &pos, "capability"); @@ -2179,11 +2179,11 @@ public: { public: - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("date_time"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; // <"> date_day_fixed "-" date_month "-" date_year parser.check >(line, &pos); @@ -2225,9 +2225,9 @@ public: parser.check >(line, &pos); - m_datetime.setHour(std::min(std::max(nh->value(), 0ul), 23ul)); - m_datetime.setMinute(std::min(std::max(nmi->value(), 0ul), 59ul)); - m_datetime.setSecond(std::min(std::max(ns->value(), 0ul), 59ul)); + m_datetime.setHour(static_cast (std::min(std::max(nh->value(), 0ul), 23ul))); + m_datetime.setMinute(static_cast (std::min(std::max(nmi->value(), 0ul), 59ul))); + m_datetime.setSecond(static_cast (std::min(std::max(ns->value(), 0ul), 59ul))); const int zone = static_cast (nz->value()); const int zh = zone / 100; // hour offset @@ -2235,8 +2235,8 @@ public: m_datetime.setZone(((zh * 60) + zm) * sign); - m_datetime.setDay(std::min(std::max(nd->value(), 1ul), 31ul)); - m_datetime.setYear(ny->value()); + m_datetime.setDay(static_cast (std::min(std::max(nd->value(), 1ul), 31ul))); + m_datetime.setYear(static_cast (ny->value())); const string month(utility::stringUtils::toLower(amo->value())); int mon = vmime::datetime::JANUARY; @@ -2328,11 +2328,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("header_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -2386,9 +2386,9 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -2445,11 +2445,11 @@ public: delete (m_header_list); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("section_text"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; // "HEADER.FIELDS" [".NOT"] SPACE header_list const bool b1 = parser.checkWithArg (line, &pos, "header.fields.not", true); @@ -2525,11 +2525,11 @@ public: delete (m_section_text2); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("section"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -2538,14 +2538,14 @@ public: if (!(m_section_text1 = parser.get (line, &pos, true))) { nz_number* num = parser.get (line, &pos); - m_nz_numbers.push_back(num->value()); + m_nz_numbers.push_back(static_cast (num->value())); delete (num); while (parser.check >(line, &pos, true)) { if ((num = parser.get (line, &pos, true))) { - m_nz_numbers.push_back(num->value()); + m_nz_numbers.push_back(static_cast (num->value())); delete (num); } else @@ -2617,11 +2617,11 @@ public: delete (m_addr_host); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("address"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); m_addr_name = parser.get (line, &pos); @@ -2669,11 +2669,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("address_list"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (!parser.check (line, &pos, true)) { @@ -2802,11 +2802,11 @@ public: delete (m_env_message_id); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("envelope"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -2934,11 +2934,11 @@ public: delete (m_string2); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_fld_param_item"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_string1 = parser.get (line, &pos); parser.check (line, &pos); @@ -2978,11 +2978,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_fld_param"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -3031,11 +3031,11 @@ public: delete (m_body_fld_param); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_fld_dsp"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -3081,11 +3081,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_fld_lang"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -3140,11 +3140,11 @@ public: delete (m_body_fld_octets); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_fields"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_body_fld_param = parser.get (line, &pos); parser.check (line, &pos); @@ -3204,11 +3204,11 @@ public: delete (m_media_subtype); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("media_text"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.checkWithArg (line, &pos, "text"); @@ -3249,11 +3249,11 @@ public: delete m_media_subtype; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("media_message"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.checkWithArg (line, &pos, "message"); @@ -3300,11 +3300,11 @@ public: delete (m_media_subtype); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("media_basic"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_media_type = parser.get (line, &pos); @@ -3357,11 +3357,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_ext_1part"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_body_fld_md5 = parser.get (line, &pos); @@ -3444,11 +3444,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_ext_mpart"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_body_fld_param = parser.get (line, &pos); @@ -3518,11 +3518,11 @@ public: delete (m_body_fields); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_type_basic"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_media_basic = parser.get (line, &pos); parser.check (line, &pos); @@ -3570,11 +3570,11 @@ public: delete (m_body_fld_lines); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_type_msg"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_media_message = parser.get (line, &pos); parser.check (line, &pos); @@ -3631,11 +3631,11 @@ public: delete (m_body_fld_lines); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_type_text"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_media_text = parser.get (line, &pos); parser.check (line, &pos); @@ -3684,11 +3684,11 @@ public: delete (m_body_ext_1part); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_type_1part"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (!(m_body_type_text = parser.get (line, &pos, true))) if (!(m_body_type_msg = parser.get (line, &pos, true))) @@ -3749,11 +3749,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body_type_mpart"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_list.push_back(parser.get (line, &pos)); @@ -3805,11 +3805,11 @@ public: delete (m_body_type_mpart); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("body"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -3875,11 +3875,11 @@ public: delete m_mod_sequence_value; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("msg_att_item"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; // "ENVELOPE" SPACE envelope if (parser.checkWithArg (line, &pos, "envelope", true)) @@ -4073,11 +4073,11 @@ public: } } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("msg_att"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); @@ -4121,14 +4121,14 @@ public: delete (m_msg_att); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("message_data"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; nz_number* num = parser.get (line, &pos); - m_number = num->value(); + m_number = static_cast (num->value()); delete (num); parser.check (line, &pos); @@ -4205,11 +4205,11 @@ public: delete m_capability_data; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("resp_text_code"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; // "ALERT" if (parser.checkWithArg (line, &pos, "alert", true)) @@ -4376,11 +4376,11 @@ public: delete (m_resp_text_code); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("resp_text"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.check >(line, &pos, true)) { @@ -4446,11 +4446,11 @@ public: delete (m_resp_text); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("continue_req"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.check (line, &pos); @@ -4491,11 +4491,11 @@ public: delete (m_resp_text); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("resp_cond_state"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.checkWithArg (line, &pos, "ok", true)) { @@ -4556,11 +4556,11 @@ public: delete (m_resp_text); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("resp_cond_bye"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.checkWithArg (line, &pos, "bye"); @@ -4600,11 +4600,11 @@ public: delete (m_resp_text); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("resp_cond_auth"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (parser.checkWithArg (line, &pos, "ok", true)) { @@ -4682,11 +4682,11 @@ public: delete m_status_att_list; } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("mailbox_data"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; m_number = parser.get (line, &pos, true); @@ -4847,11 +4847,11 @@ public: delete (m_capability_data); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("response_data"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.check (line, &pos); @@ -4907,11 +4907,11 @@ public: delete (m_response_data); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("continue_req_or_response_data"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (!(m_continue_req = parser.get (line, &pos, true))) m_response_data = parser.get (line, &pos); @@ -4950,11 +4950,11 @@ public: delete (m_resp_cond_bye); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("response_fatal"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.check (line, &pos); @@ -5001,11 +5001,11 @@ public: delete (m_resp_cond_state); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("response_tagged"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check (line, &pos); parser.check (line, &pos); @@ -5052,11 +5052,11 @@ public: delete (m_response_fatal); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("response_done"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; if (!(m_response_tagged = parser.get (line, &pos, true))) m_response_fatal = parser.get (line, &pos); @@ -5101,11 +5101,11 @@ public: delete (m_response_done); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("response"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; string curLine = line; bool partial = false; // partial response @@ -5194,11 +5194,11 @@ public: delete (m_resp_cond_bye); } - void go(IMAPParser& parser, string& line, string::size_type* currentPos) + void go(IMAPParser& parser, string& line, size_t* currentPos) { DEBUG_ENTER_COMPONENT("greeting"); - string::size_type pos = *currentPos; + size_t pos = *currentPos; parser.check >(line, &pos); parser.check (line, &pos); @@ -5242,7 +5242,7 @@ public: response* readResponse(literalHandler* lh = NULL) { - string::size_type pos = 0; + size_t pos = 0; string line = readLine(); m_literalHandler = lh; @@ -5257,7 +5257,7 @@ public: greeting* readGreeting() { - string::size_type pos = 0; + size_t pos = 0; string line = readLine(); greeting* greet = get (line, &pos); @@ -5273,7 +5273,7 @@ public: // template - TYPE* get(string& line, string::size_type* currentPos, + TYPE* get(string& line, size_t* currentPos, const bool noThrow = false) { component* resp = new TYPE; @@ -5282,7 +5282,7 @@ public: template - TYPE* getWithArgs(string& line, string::size_type* currentPos, + TYPE* getWithArgs(string& line, size_t* currentPos, ARG1_TYPE arg1, ARG2_TYPE arg2, const bool noThrow = false) { component* resp = new TYPE(arg1, arg2); @@ -5293,10 +5293,10 @@ public: private: template - TYPE* internalGet(component* resp, string& line, string::size_type* currentPos, + TYPE* internalGet(component* resp, string& line, size_t* currentPos, const bool noThrow = false) { - const string::size_type oldPos = *currentPos; + const size_t oldPos = *currentPos; try { @@ -5350,10 +5350,10 @@ public: // template - bool check(string& line, string::size_type* currentPos, + bool check(string& line, size_t* currentPos, const bool noThrow = false) { - const string::size_type oldPos = *currentPos; + const size_t oldPos = *currentPos; try { @@ -5377,10 +5377,10 @@ public: } template - bool checkWithArg(string& line, string::size_type* currentPos, + bool checkWithArg(string& line, size_t* currentPos, const ARG_TYPE arg, const bool noThrow = false) { - const string::size_type oldPos = *currentPos; + const size_t oldPos = *currentPos; try { @@ -5430,7 +5430,7 @@ public: const string readLine() { - string::size_type pos; + size_t pos; while ((pos = m_buffer.find('\n')) == string::npos) { @@ -5494,9 +5494,9 @@ public: } - void readLiteral(literalHandler::target& buffer, string::size_type count) + void readLiteral(literalHandler::target& buffer, size_t count) { - string::size_type len = 0; + size_t len = 0; string receiveBuffer; shared_ptr toh = m_timeoutHandler.lock(); @@ -5550,7 +5550,7 @@ public: if (len + receiveBuffer.length() > count) { - const string::size_type remaining = count - len; + const size_t remaining = count - len; // Get the needed amount of data buffer.putData(string(receiveBuffer.begin(), receiveBuffer.begin() + remaining)); diff --git a/vmime/net/maildir/maildirFolder.hpp b/vmime/net/maildir/maildirFolder.hpp index 338c6f96..5cff53fc 100644 --- a/vmime/net/maildir/maildirFolder.hpp +++ b/vmime/net/maildir/maildirFolder.hpp @@ -103,7 +103,7 @@ public: void setMessageFlags(const messageSet& msgs, const int flags, const int mode = message::FLAG_MODE_SET); void addMessage(shared_ptr msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); - void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); + void addMessage(utility::inputStream& is, const size_t size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); void copyMessages(const folder::path& dest, const messageSet& msgs); @@ -144,7 +144,7 @@ private: void setMessageFlagsImpl(const std::vector & nums, const int flags, const int mode); void copyMessagesImpl(const folder::path& dest, const std::vector & nums); - void copyMessageImpl(const utility::file::path& tmpDirPath, const utility::file::path& curDirPath, const utility::file::path::component& filename, utility::inputStream& is, const utility::stream::size_type size, utility::progressListener* progress); + void copyMessageImpl(const utility::file::path& tmpDirPath, const utility::file::path& curDirPath, const utility::file::path::component& filename, utility::inputStream& is, const size_t size, utility::progressListener* progress); void notifyMessagesCopied(const folder::path& dest); diff --git a/vmime/net/maildir/maildirMessage.hpp b/vmime/net/maildir/maildirMessage.hpp index 6218c812..7480d49c 100644 --- a/vmime/net/maildir/maildirMessage.hpp +++ b/vmime/net/maildir/maildirMessage.hpp @@ -63,7 +63,7 @@ public: const uid getUID() const; - int getSize() const; + size_t getSize() const; bool isExpunged() const; @@ -75,8 +75,8 @@ public: int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); - void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(shared_ptr p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const size_t start = 0, const size_t length = -1, const bool peek = false) const; + void extractPart(shared_ptr p, utility::outputStream& os, utility::progressListener* progress = NULL, const size_t start = 0, const size_t length = -1, const bool peek = false) const; void fetchPartHeader(shared_ptr p); @@ -90,13 +90,13 @@ private: shared_ptr
getOrCreateHeader(); - void extractImpl(utility::outputStream& os, utility::progressListener* progress, const int start, const int length, const int partialStart, const int partialLength, const bool peek) const; + void extractImpl(utility::outputStream& os, utility::progressListener* progress, const size_t start, const size_t length, const size_t partialStart, const size_t partialLength, const bool peek) const; weak_ptr m_folder; int m_num; - int m_size; + size_t m_size; int m_flags; bool m_expunged; uid m_uid; diff --git a/vmime/net/maildir/maildirMessagePart.hpp b/vmime/net/maildir/maildirMessagePart.hpp index 00c931ec..3a4be0f3 100644 --- a/vmime/net/maildir/maildirMessagePart.hpp +++ b/vmime/net/maildir/maildirMessagePart.hpp @@ -56,18 +56,18 @@ public: weak_ptr getParent() const { return (m_parent); } const mediaType& getType() const; - int getSize() const; + size_t getSize() const; int getNumber() const; shared_ptr getHeader() const; header& getOrCreateHeader(); - int getHeaderParsedOffset() const; - int getHeaderParsedLength() const; + size_t getHeaderParsedOffset() const; + size_t getHeaderParsedLength() const; - int getBodyParsedOffset() const; - int getBodyParsedLength() const; + size_t getBodyParsedOffset() const; + size_t getBodyParsedLength() const; void initStructure(const bodyPart& part); @@ -78,14 +78,14 @@ private: shared_ptr
m_header; int m_number; - int m_size; + size_t m_size; mediaType m_mediaType; - int m_headerParsedOffset; - int m_headerParsedLength; + size_t m_headerParsedOffset; + size_t m_headerParsedLength; - int m_bodyParsedOffset; - int m_bodyParsedLength; + size_t m_bodyParsedOffset; + size_t m_bodyParsedLength; }; diff --git a/vmime/net/message.hpp b/vmime/net/message.hpp index 4e291089..5bb62c53 100644 --- a/vmime/net/message.hpp +++ b/vmime/net/message.hpp @@ -90,7 +90,7 @@ public: * * @return size of the part (in bytes) */ - virtual int getSize() const = 0; + virtual size_t getSize() const = 0; /** Return the part sequence number (index). * The first part is at index zero. @@ -238,7 +238,7 @@ public: * * @return size of the message (in bytes) */ - virtual int getSize() const = 0; + virtual size_t getSize() const = 0; /** Check whether this message has been expunged (ie: definitively * deleted) and does not exist in the folder anymore. @@ -297,7 +297,12 @@ public: * be supported by the protocol (IMAP supports this), but it will NOT throw * an exception if not supported. */ - virtual void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const = 0; + virtual void extract + (utility::outputStream& os, + utility::progressListener* progress = NULL, + const size_t start = 0, + const size_t length = -1, + const bool peek = false) const = 0; /** Extract the specified MIME part of the message (header + contents). * @@ -316,8 +321,8 @@ public: (shared_ptr p, utility::outputStream& os, utility::progressListener* progress = NULL, - const int start = 0, - const int length = -1, + const size_t start = 0, + const size_t length = -1, const bool peek = false) const = 0; /** Fetch the MIME header for the specified part. diff --git a/vmime/net/pop3/POP3Folder.hpp b/vmime/net/pop3/POP3Folder.hpp index 93a2bf35..27ea6e5f 100644 --- a/vmime/net/pop3/POP3Folder.hpp +++ b/vmime/net/pop3/POP3Folder.hpp @@ -100,7 +100,7 @@ public: void setMessageFlags(const messageSet& msgs, const int flags, const int mode = message::FLAG_MODE_SET); void addMessage(shared_ptr msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); - void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); + void addMessage(utility::inputStream& is, const size_t size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL); void copyMessages(const folder::path& dest, const messageSet& msgs); diff --git a/vmime/net/pop3/POP3Message.hpp b/vmime/net/pop3/POP3Message.hpp index 6cb3c719..87e71ba7 100644 --- a/vmime/net/pop3/POP3Message.hpp +++ b/vmime/net/pop3/POP3Message.hpp @@ -65,7 +65,7 @@ public: const uid getUID() const; - int getSize() const; + size_t getSize() const; bool isExpunged() const; @@ -77,8 +77,18 @@ public: int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); - void extract(utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; - void extractPart(shared_ptr p, utility::outputStream& os, utility::progressListener* progress = NULL, const int start = 0, const int length = -1, const bool peek = false) const; + void extract + (utility::outputStream& os, + utility::progressListener* progress = NULL, + const size_t start = 0, const size_t length = -1, + const bool peek = false) const; + + void extractPart + (shared_ptr p, + utility::outputStream& os, + utility::progressListener* progress = NULL, + const size_t start = 0, const size_t length = -1, + const bool peek = false) const; void fetchPartHeader(shared_ptr p); @@ -93,7 +103,7 @@ private: weak_ptr m_folder; int m_num; uid m_uid; - int m_size; + size_t m_size; bool m_deleted; diff --git a/vmime/net/pop3/POP3Response.hpp b/vmime/net/pop3/POP3Response.hpp index 4b69290f..20477b5e 100644 --- a/vmime/net/pop3/POP3Response.hpp +++ b/vmime/net/pop3/POP3Response.hpp @@ -101,7 +101,7 @@ public: */ static shared_ptr readLargeResponse (shared_ptr conn, utility::outputStream& os, - utility::progressListener* progress, const long predictedSize); + utility::progressListener* progress, const size_t predictedSize); /** Returns whether the response is successful ("OK"). @@ -148,7 +148,7 @@ private: void readResponseImpl(string& buffer, const bool multiLine); void readResponseImpl (string& firstLine, utility::outputStream& os, - utility::progressListener* progress, const long predictedSize); + utility::progressListener* progress, const size_t predictedSize); static bool stripFirstLine(const string& buffer, string& result, string* firstLine); diff --git a/vmime/net/sendmail/sendmailTransport.hpp b/vmime/net/sendmail/sendmailTransport.hpp index 7967ab87..d1c6aec0 100644 --- a/vmime/net/sendmail/sendmailTransport.hpp +++ b/vmime/net/sendmail/sendmailTransport.hpp @@ -68,7 +68,7 @@ public: (const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, - const utility::stream::size_type size, + const size_t size, utility::progressListener* progress = NULL, const mailbox& sender = mailbox()); @@ -80,7 +80,7 @@ private: void internalDisconnect(); void internalSend(const std::vector args, utility::inputStream& is, - const utility::stream::size_type size, utility::progressListener* progress); + const size_t size, utility::progressListener* progress); string m_sendmailPath; diff --git a/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp b/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp index 6ca6c527..cfb3f50f 100644 --- a/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp +++ b/vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp @@ -50,23 +50,26 @@ public: SMTPChunkingOutputStreamAdapter(shared_ptr conn); - void write(const value_type* const data, const size_type count); void flush(); - size_type getBlockSize(); + size_t getBlockSize(); + +protected: + + void writeImpl(const byte_t* const data, const size_t count); private: SMTPChunkingOutputStreamAdapter(const SMTPChunkingOutputStreamAdapter&); - void sendChunk(const value_type* const data, const size_type count, const bool last); + void sendChunk(const byte_t* const data, const size_t count, const bool last); shared_ptr m_connection; - value_type m_buffer[262144]; // 256 KB - size_type m_bufferSize; + byte_t m_buffer[262144]; // 256 KB + size_t m_bufferSize; unsigned int m_chunkCount; }; diff --git a/vmime/net/smtp/SMTPCommand.hpp b/vmime/net/smtp/SMTPCommand.hpp index 4005dcdf..dbb0888b 100644 --- a/vmime/net/smtp/SMTPCommand.hpp +++ b/vmime/net/smtp/SMTPCommand.hpp @@ -62,11 +62,11 @@ public: static shared_ptr AUTH(const string& mechName); static shared_ptr STARTTLS(); static shared_ptr MAIL(const mailbox& mbox, const bool utf8); - static shared_ptr MAIL(const mailbox& mbox, const bool utf8, const unsigned long size); + static shared_ptr MAIL(const mailbox& mbox, const bool utf8, const size_t size); static shared_ptr RCPT(const mailbox& mbox, const bool utf8); static shared_ptr RSET(); static shared_ptr DATA(); - static shared_ptr BDAT(const unsigned long chunkSize, const bool last); + static shared_ptr BDAT(const size_t chunkSize, const bool last); static shared_ptr NOOP(); static shared_ptr QUIT(); diff --git a/vmime/net/smtp/SMTPTransport.hpp b/vmime/net/smtp/SMTPTransport.hpp index 90ad447c..a0f02418 100644 --- a/vmime/net/smtp/SMTPTransport.hpp +++ b/vmime/net/smtp/SMTPTransport.hpp @@ -72,7 +72,7 @@ public: (const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, - const utility::stream::size_type size, + const size_t size, utility::progressListener* progress = NULL, const mailbox& sender = mailbox()); @@ -106,7 +106,7 @@ private: const mailboxList& recipients, const mailbox& sender, bool sendDATACommand, - const utility::stream::size_type size); + const size_t size); shared_ptr m_connection; diff --git a/vmime/net/socket.hpp b/vmime/net/socket.hpp index 3dadc72b..537c34bb 100644 --- a/vmime/net/socket.hpp +++ b/vmime/net/socket.hpp @@ -55,10 +55,6 @@ public: virtual ~socket() { } - /** Type used for lengths in streams. - */ - typedef long size_type; - /** Connect to the specified address and port. * @@ -78,48 +74,54 @@ public: */ virtual bool isConnected() const = 0; - /** Receive (text) data from the socket. + /** Receive text data from the socket. * * @param buffer buffer in which to write received data */ virtual void receive(string& buffer) = 0; - /** Receive (raw) data from the socket. + /** Receive raw data from the socket. * * @param buffer buffer in which to write received data * @param count maximum number of bytes to receive (size of buffer) * @return number of bytes received/written into output buffer */ - virtual size_type receiveRaw(char* buffer, const size_type count) = 0; + virtual size_t receiveRaw(byte_t* buffer, const size_t count) = 0; - /** Send (text) data to the socket. + /** Send text data to the socket. * * @param buffer data to send */ virtual void send(const string& buffer) = 0; - /** Send (raw) data to the socket. + /** Send text data to the socket. + * + * @param str null-terminated string + */ + virtual void send(const char* str) = 0; + + /** Send raw data to the socket. * * @param buffer data to send * @param count number of bytes to send (size of buffer) */ - virtual void sendRaw(const char* buffer, const size_type count) = 0; + virtual void sendRaw(const byte_t* buffer, const size_t count) = 0; - /** Send (raw) data to the socket. + /** Send raw data to the socket. * Function may returns before all data is sent. * * @param buffer data to send * @param count number of bytes to send (size of buffer) * @return number of bytes sent */ - virtual size_type sendRawNonBlocking(const char* buffer, const size_type count) = 0; + virtual size_t sendRawNonBlocking(const byte_t* buffer, const size_t count) = 0; /** Return the preferred maximum block size when reading * from or writing to this stream. * * @return block size, in bytes */ - virtual size_type getBlockSize() const = 0; + virtual size_t getBlockSize() const = 0; /** Return the current status of this socket. * diff --git a/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp b/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp index 43848ec9..885fac13 100644 --- a/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp +++ b/vmime/net/tls/gnutls/TLSSocket_GnuTLS.hpp @@ -64,13 +64,14 @@ public: bool isConnected() const; void receive(string& buffer); - size_type receiveRaw(char* buffer, const size_type count); + size_t receiveRaw(byte_t* buffer, const size_t count); void send(const string& buffer); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + void send(const char* str); + void sendRaw(const byte_t* buffer, const size_t count); + size_t sendRawNonBlocking(const byte_t* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; @@ -95,7 +96,7 @@ private: bool m_connected; - char m_buffer[65536]; + byte_t m_buffer[65536]; bool m_handshaking; shared_ptr m_toHandler; diff --git a/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp b/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp index b4ff5872..3dda9fa5 100644 --- a/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp +++ b/vmime/net/tls/openssl/TLSSocket_OpenSSL.hpp @@ -68,13 +68,14 @@ public: bool isConnected() const; void receive(string& buffer); - size_type receiveRaw(char* buffer, const size_type count); + size_t receiveRaw(byte_t* buffer, const size_t count); void send(const string& buffer); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + void send(const char* str); + void sendRaw(const byte_t* buffer, const size_t count); + size_t sendRawNonBlocking(const byte_t* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; @@ -105,7 +106,7 @@ private: bool m_connected; - char m_buffer[65536]; + byte_t m_buffer[65536]; shared_ptr m_toHandler; diff --git a/vmime/net/transport.hpp b/vmime/net/transport.hpp index 96e37669..6c405cbb 100644 --- a/vmime/net/transport.hpp +++ b/vmime/net/transport.hpp @@ -82,7 +82,7 @@ public: (const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, - const utility::stream::size_type size, + const size_t size, utility::progressListener* progress = NULL, const mailbox& sender = mailbox()) = 0; diff --git a/vmime/parameter.hpp b/vmime/parameter.hpp index d872b312..682c391b 100644 --- a/vmime/parameter.hpp +++ b/vmime/parameter.hpp @@ -127,15 +127,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; private: diff --git a/vmime/parameterizedHeaderField.hpp b/vmime/parameterizedHeaderField.hpp index cc24ccf0..509506a9 100644 --- a/vmime/parameterizedHeaderField.hpp +++ b/vmime/parameterizedHeaderField.hpp @@ -190,15 +190,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/path.hpp b/vmime/path.hpp index 87409413..2ffa3c22 100644 --- a/vmime/path.hpp +++ b/vmime/path.hpp @@ -88,15 +88,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/platforms/posix/posixFile.hpp b/vmime/platforms/posix/posixFile.hpp index a1353841..20a56699 100644 --- a/vmime/platforms/posix/posixFile.hpp +++ b/vmime/platforms/posix/posixFile.hpp @@ -50,9 +50,12 @@ public: posixFileWriterOutputStream(const vmime::utility::file::path& path, const int fd); ~posixFileWriterOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: const vmime::utility::file::path m_path; @@ -72,12 +75,12 @@ public: void reset(); - size_type read(value_type* const data, const size_type count); + size_t read(byte_t* const data, const size_t count); - size_type skip(const size_type count); + size_t skip(const size_t count); - size_type getPosition() const; - void seek(const size_type pos); + size_t getPosition() const; + void seek(const size_t pos); private: diff --git a/vmime/platforms/posix/posixSocket.hpp b/vmime/platforms/posix/posixSocket.hpp index 10df657e..4ec3edec 100644 --- a/vmime/platforms/posix/posixSocket.hpp +++ b/vmime/platforms/posix/posixSocket.hpp @@ -51,13 +51,14 @@ public: void disconnect(); void receive(vmime::string& buffer); - size_type receiveRaw(char* buffer, const size_type count); + size_t receiveRaw(byte_t* buffer, const size_t count); void send(const vmime::string& buffer); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + void send(const char* str); + void sendRaw(const byte_t* buffer, const size_t count); + size_t sendRawNonBlocking(const byte_t* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; @@ -72,7 +73,7 @@ private: shared_ptr m_timeoutHandler; - char m_buffer[65536]; + byte_t m_buffer[65536]; int m_desc; unsigned int m_status; diff --git a/vmime/platforms/windows/windowsFile.hpp b/vmime/platforms/windows/windowsFile.hpp index 65049b8f..3543ee8a 100644 --- a/vmime/platforms/windows/windowsFile.hpp +++ b/vmime/platforms/windows/windowsFile.hpp @@ -160,10 +160,10 @@ public: bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: @@ -198,9 +198,12 @@ public: public: - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: const vmime::utility::file::path m_path; diff --git a/vmime/platforms/windows/windowsSocket.hpp b/vmime/platforms/windows/windowsSocket.hpp index 4c4344d8..e3f43b7c 100644 --- a/vmime/platforms/windows/windowsSocket.hpp +++ b/vmime/platforms/windows/windowsSocket.hpp @@ -55,13 +55,13 @@ public: void disconnect(); void receive(vmime::string& buffer); - size_type receiveRaw(char* buffer, const size_type count); + size_t receiveRaw(char* buffer, const size_t count); void send(const vmime::string& buffer); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + void sendRaw(const char* buffer, const size_t count); + size_t sendRawNonBlocking(const char* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; diff --git a/vmime/relay.hpp b/vmime/relay.hpp index 62ed5bf0..35949ff1 100644 --- a/vmime/relay.hpp +++ b/vmime/relay.hpp @@ -90,15 +90,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; }; diff --git a/vmime/security/digest/md5/md5MessageDigest.hpp b/vmime/security/digest/md5/md5MessageDigest.hpp index f7dff079..ef94f5c8 100644 --- a/vmime/security/digest/md5/md5MessageDigest.hpp +++ b/vmime/security/digest/md5/md5MessageDigest.hpp @@ -42,15 +42,15 @@ public: void update(const byte_t b); void update(const string& s); - void update(const byte_t* buffer, const unsigned long len); - void update(const byte_t* buffer, const unsigned long offset, const unsigned long len); + void update(const byte_t* buffer, const size_t len); + void update(const byte_t* buffer, const size_t offset, const size_t len); void finalize(); void finalize(const string& s); - void finalize(const byte_t* buffer, const unsigned long len); - void finalize(const byte_t* buffer, const unsigned long offset, const unsigned long len); + void finalize(const byte_t* buffer, const size_t len); + void finalize(const byte_t* buffer, const size_t offset, const size_t len); - int getDigestLength() const; + size_t getDigestLength() const; const byte_t* getDigest() const; void reset(); @@ -69,7 +69,7 @@ protected: vmime_uint8 b8[64]; }; - unsigned long m_byteCount; + size_t m_byteCount; BlockType m_block; bool m_finalized; diff --git a/vmime/security/digest/messageDigest.hpp b/vmime/security/digest/messageDigest.hpp index 512b68aa..d17dfbc2 100644 --- a/vmime/security/digest/messageDigest.hpp +++ b/vmime/security/digest/messageDigest.hpp @@ -59,7 +59,7 @@ public: * @param buffer array of bytes * @param len number of bytes to use in the buffer */ - virtual void update(const byte_t* buffer, const unsigned long len) = 0; + virtual void update(const byte_t* buffer, const size_t len) = 0; /** Updates the digest using the specified array of bytes, * starting at the specified offset. @@ -69,8 +69,8 @@ public: * @param len number of bytes to use, starting at offset */ virtual void update(const byte_t* buffer, - const unsigned long offset, - const unsigned long len) = 0; + const size_t offset, + const size_t len) = 0; /** Completes the hash computation by performing final operations * such as padding. @@ -88,22 +88,22 @@ public: * then finalize(). */ virtual void finalize(const byte_t* buffer, - const unsigned long len) = 0; + const size_t len) = 0; /** Completes the hash computation by performing final operations * such as padding. This is equivalent to calling update() and * then finalize(). */ virtual void finalize(const byte_t* buffer, - const unsigned long offset, - const unsigned long len) = 0; + const size_t offset, + const size_t len) = 0; /** Returns the length of the hash. * This is the length of the array returned by getDigest(). * * @return length of computed hash */ - virtual int getDigestLength() const = 0; + virtual size_t getDigestLength() const = 0; /** Returns the hash, as computed by the algorithm. * You must call finalize() before using this function, or the diff --git a/vmime/security/digest/sha1/sha1MessageDigest.hpp b/vmime/security/digest/sha1/sha1MessageDigest.hpp index 8d8e82a3..1eb09c2f 100644 --- a/vmime/security/digest/sha1/sha1MessageDigest.hpp +++ b/vmime/security/digest/sha1/sha1MessageDigest.hpp @@ -42,15 +42,15 @@ public: void update(const byte_t b); void update(const string& s); - void update(const byte_t* buffer, const unsigned long len); - void update(const byte_t* buffer, const unsigned long offset, const unsigned long len); + void update(const byte_t* buffer, const size_t len); + void update(const byte_t* buffer, const size_t offset, const size_t len); void finalize(); void finalize(const string& s); - void finalize(const byte_t* buffer, const unsigned long len); - void finalize(const byte_t* buffer, const unsigned long offset, const unsigned long len); + void finalize(const byte_t* buffer, const size_t len); + void finalize(const byte_t* buffer, const size_t offset, const size_t len); - int getDigestLength() const; + size_t getDigestLength() const; const byte_t* getDigest() const; void reset(); diff --git a/vmime/security/sasl/SASLContext.hpp b/vmime/security/sasl/SASLContext.hpp index 7afcddf2..200f78db 100644 --- a/vmime/security/sasl/SASLContext.hpp +++ b/vmime/security/sasl/SASLContext.hpp @@ -93,7 +93,7 @@ public: * @param output output buffer * @param outputLen length of output buffer */ - void decodeB64(const string& input, byte_t** output, long* outputLen); + void decodeB64(const string& input, byte_t** output, size_t* outputLen); /** Helper function for encoding challenge in Base64. * @@ -101,7 +101,7 @@ public: * @param inputLen length of input buffer * @return Base64-encoded challenge */ - const string encodeB64(const byte_t* input, const long inputLen); + const string encodeB64(const byte_t* input, const size_t inputLen); private: diff --git a/vmime/security/sasl/SASLMechanism.hpp b/vmime/security/sasl/SASLMechanism.hpp index 623069d5..5492e48c 100644 --- a/vmime/security/sasl/SASLMechanism.hpp +++ b/vmime/security/sasl/SASLMechanism.hpp @@ -72,8 +72,8 @@ public: */ virtual bool step (shared_ptr sess, - const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen) = 0; + const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen) = 0; /** Check whether authentication has completed. If false, more * calls to evaluateChallenge() are needed to complete the @@ -98,8 +98,8 @@ public: * 'outputLen' are undetermined) */ virtual void encode(shared_ptr sess, - const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) = 0; + const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) = 0; /** Decode data according to negotiated SASL mechanism. This * might mean that data is integrity or privacy protected. @@ -115,8 +115,8 @@ public: * 'outputLen' are undetermined) */ virtual void decode(shared_ptr sess, - const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) = 0; + const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) = 0; }; diff --git a/vmime/security/sasl/SASLSession.hpp b/vmime/security/sasl/SASLSession.hpp index 830d9970..ccf181cb 100644 --- a/vmime/security/sasl/SASLSession.hpp +++ b/vmime/security/sasl/SASLSession.hpp @@ -108,8 +108,8 @@ public: * 'responseLen' are undetermined) */ bool evaluateChallenge - (const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen); + (const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen); /** Return a socket in which transmitted data is integrity * and/or privacy protected, depending on the QOP (Quality of diff --git a/vmime/security/sasl/SASLSocket.hpp b/vmime/security/sasl/SASLSocket.hpp index 33487eba..e52911b4 100644 --- a/vmime/security/sasl/SASLSocket.hpp +++ b/vmime/security/sasl/SASLSocket.hpp @@ -59,13 +59,14 @@ public: bool isConnected() const; void receive(string& buffer); - size_type receiveRaw(char* buffer, const size_type count); + size_t receiveRaw(byte_t* buffer, const size_t count); void send(const string& buffer); - void sendRaw(const char* buffer, const size_type count); - size_type sendRawNonBlocking(const char* buffer, const size_type count); + void send(const char* str); + void sendRaw(const byte_t* buffer, const size_t count); + size_t sendRawNonBlocking(const byte_t* buffer, const size_t count); - size_type getBlockSize() const; + size_t getBlockSize() const; unsigned int getStatus() const; @@ -78,10 +79,10 @@ private: shared_ptr m_wrapped; byte_t* m_pendingBuffer; - size_type m_pendingPos; - size_type m_pendingLen; + size_t m_pendingPos; + size_t m_pendingLen; - char m_recvBuffer[65536]; + byte_t m_recvBuffer[65536]; }; diff --git a/vmime/security/sasl/builtinSASLMechanism.hpp b/vmime/security/sasl/builtinSASLMechanism.hpp index e7081a27..09b46f00 100644 --- a/vmime/security/sasl/builtinSASLMechanism.hpp +++ b/vmime/security/sasl/builtinSASLMechanism.hpp @@ -56,18 +56,18 @@ public: const string getName() const; bool step(shared_ptr sess, - const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen); + const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen); bool isComplete() const; void encode(shared_ptr sess, - const byte_t* input, const long inputLen, - byte_t** output, long* outputLen); + const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen); void decode(shared_ptr sess, - const byte_t* input, const long inputLen, - byte_t** output, long* outputLen); + const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen); private: diff --git a/vmime/streamContentHandler.hpp b/vmime/streamContentHandler.hpp index 52f6718a..9b72c073 100644 --- a/vmime/streamContentHandler.hpp +++ b/vmime/streamContentHandler.hpp @@ -59,7 +59,7 @@ public: */ streamContentHandler (shared_ptr is, - const utility::stream::size_type length, + const size_t length, const vmime::encoding& enc = NO_ENCODING); ~streamContentHandler(); @@ -80,16 +80,16 @@ public: */ void setData (shared_ptr is, - const utility::stream::size_type length, + const size_t length, const vmime::encoding& enc = NO_ENCODING); - void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; + void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os, utility::progressListener* progress = NULL) const; void extractRaw(utility::outputStream& os, utility::progressListener* progress = NULL) const; - string::size_type getLength() const; + size_t getLength() const; bool isEncoded() const; @@ -112,7 +112,7 @@ private: // Actual data mutable shared_ptr m_stream; - string::size_type m_length; + size_t m_length; }; diff --git a/vmime/stringContentHandler.hpp b/vmime/stringContentHandler.hpp index b8fdaa71..e9d34405 100644 --- a/vmime/stringContentHandler.hpp +++ b/vmime/stringContentHandler.hpp @@ -39,7 +39,7 @@ public: stringContentHandler(); stringContentHandler(const string& buffer, const vmime::encoding& enc = NO_ENCODING); stringContentHandler(const utility::stringProxy& str, const vmime::encoding& enc = NO_ENCODING); - stringContentHandler(const string& buffer, const string::size_type start, const string::size_type end, const vmime::encoding& enc = NO_ENCODING); + stringContentHandler(const string& buffer, const size_t start, const size_t end, const vmime::encoding& enc = NO_ENCODING); ~stringContentHandler(); @@ -60,16 +60,16 @@ public: // to generate() is different from this one... void setData(const utility::stringProxy& str, const vmime::encoding& enc = NO_ENCODING); void setData(const string& buffer, const vmime::encoding& enc = NO_ENCODING); - void setData(const string& buffer, const string::size_type start, const string::size_type end, const vmime::encoding& enc = NO_ENCODING); + void setData(const string& buffer, const size_t start, const size_t end, const vmime::encoding& enc = NO_ENCODING); stringContentHandler& operator=(const string& buffer); - void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; + void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os, utility::progressListener* progress = NULL) const; void extractRaw(utility::outputStream& os, utility::progressListener* progress = NULL) const; - string::size_type getLength() const; + size_t getLength() const; bool isEncoded() const; diff --git a/vmime/text.hpp b/vmime/text.hpp index 98e2459a..b7e25669 100644 --- a/vmime/text.hpp +++ b/vmime/text.hpp @@ -209,7 +209,7 @@ public: * @param flags encoding flags (see EncodeAndFoldFlags) */ void encodeAndFold(const generationContext& ctx, utility::outputStream& os, - const string::size_type firstLineOffset, string::size_type* lastLineLength, const int flags) const; + const size_t firstLineOffset, size_t* lastLineLength, const int flags) const; /** Decode and unfold text (RFC-2047), using the default parsing context. * @@ -255,15 +255,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; private: diff --git a/vmime/types.hpp b/vmime/types.hpp index b647d6f5..034330bc 100644 --- a/vmime/types.hpp +++ b/vmime/types.hpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "vmime/config.hpp" @@ -89,9 +90,7 @@ namespace vmime typedef vmime_uint8 byte_t; typedef std::vector byteArray; -#if !VMIME_HAVE_SIZE_T - typedef unsigned long size_t; -#endif // !VMIME_HAVE_SIZE_T + typedef std::size_t size_t; // For compatibility with versions <= 0.7.1 (deprecated) namespace net { } diff --git a/vmime/utility/encoder/b64Encoder.hpp b/vmime/utility/encoder/b64Encoder.hpp index e2bb5780..2d23d9e3 100644 --- a/vmime/utility/encoder/b64Encoder.hpp +++ b/vmime/utility/encoder/b64Encoder.hpp @@ -42,13 +42,13 @@ public: b64Encoder(); - utility::stream::size_type encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); - utility::stream::size_type decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); const std::vector getAvailableProperties() const; - utility::stream::size_type getEncodedSize(const utility::stream::size_type n) const; - utility::stream::size_type getDecodedSize(const utility::stream::size_type n) const; + size_t getEncodedSize(const size_t n) const; + size_t getDecodedSize(const size_t n) const; protected: diff --git a/vmime/utility/encoder/encoder.hpp b/vmime/utility/encoder/encoder.hpp index 65114867..34cd10b7 100644 --- a/vmime/utility/encoder/encoder.hpp +++ b/vmime/utility/encoder/encoder.hpp @@ -54,7 +54,7 @@ public: * want to receive progress notifications * @return number of bytes written into output stream */ - virtual utility::stream::size_type encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL) = 0; + virtual size_t encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL) = 0; /** Decode data. * @@ -64,7 +64,7 @@ public: * want to receive progress notifications * @return number of bytes written into output stream */ - virtual utility::stream::size_type decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL) = 0; + virtual size_t decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL) = 0; /** Return the properties of the encoder. * @@ -98,7 +98,7 @@ public: * @param n count of input (decoded) bytes * @return count of output (encoded) bytes */ - virtual utility::stream::size_type getEncodedSize(const utility::stream::size_type n) const = 0; + virtual size_t getEncodedSize(const size_t n) const = 0; /** Return the encoded size for the specified input (encoded) size. * If the size is not exact, it may be an estimate which should always @@ -107,7 +107,7 @@ public: * @param n count of input (encoded) bytes * @return count of output (decoded) bytes */ - virtual utility::stream::size_type getDecodedSize(const utility::stream::size_type n) const = 0; + virtual size_t getDecodedSize(const size_t n) const = 0; protected: diff --git a/vmime/utility/encoder/noopEncoder.hpp b/vmime/utility/encoder/noopEncoder.hpp index 7e18e3f9..6314812b 100644 --- a/vmime/utility/encoder/noopEncoder.hpp +++ b/vmime/utility/encoder/noopEncoder.hpp @@ -42,11 +42,11 @@ public: noopEncoder(); - utility::stream::size_type encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); - utility::stream::size_type decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); - utility::stream::size_type getEncodedSize(const utility::stream::size_type n) const; - utility::stream::size_type getDecodedSize(const utility::stream::size_type n) const; + size_t getEncodedSize(const size_t n) const; + size_t getDecodedSize(const size_t n) const; }; diff --git a/vmime/utility/encoder/qpEncoder.hpp b/vmime/utility/encoder/qpEncoder.hpp index 254a38d0..c666795b 100644 --- a/vmime/utility/encoder/qpEncoder.hpp +++ b/vmime/utility/encoder/qpEncoder.hpp @@ -42,16 +42,16 @@ public: qpEncoder(); - utility::stream::size_type encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); - utility::stream::size_type decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); const std::vector getAvailableProperties() const; static bool RFC2047_isEncodingNeededForChar(const unsigned char c); static int RFC2047_getEncodedLength(const unsigned char c); - utility::stream::size_type getEncodedSize(const utility::stream::size_type n) const; - utility::stream::size_type getDecodedSize(const utility::stream::size_type n) const; + size_t getEncodedSize(const size_t n) const; + size_t getDecodedSize(const size_t n) const; protected: diff --git a/vmime/utility/encoder/uuEncoder.hpp b/vmime/utility/encoder/uuEncoder.hpp index f0bcbb33..7365263c 100644 --- a/vmime/utility/encoder/uuEncoder.hpp +++ b/vmime/utility/encoder/uuEncoder.hpp @@ -42,13 +42,13 @@ public: uuEncoder(); - utility::stream::size_type encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); - utility::stream::size_type decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t encode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); + size_t decode(utility::inputStream& in, utility::outputStream& out, utility::progressListener* progress = NULL); const std::vector getAvailableProperties() const; - utility::stream::size_type getEncodedSize(const utility::stream::size_type n) const; - utility::stream::size_type getDecodedSize(const utility::stream::size_type n) const; + size_t getEncodedSize(const size_t n) const; + size_t getDecodedSize(const size_t n) const; }; diff --git a/vmime/utility/filteredStream.hpp b/vmime/utility/filteredStream.hpp index 0cb7a0ef..c60373b9 100644 --- a/vmime/utility/filteredStream.hpp +++ b/vmime/utility/filteredStream.hpp @@ -42,7 +42,7 @@ class VMIME_EXPORT filteredInputStream : public inputStream { public: - virtual size_type getBlockSize(); + virtual size_t getBlockSize(); /** Return a reference to the stream being filtered. * @@ -59,7 +59,7 @@ class VMIME_EXPORT filteredOutputStream : public outputStream { public: - virtual size_type getBlockSize(); + virtual size_t getBlockSize(); /** Return a reference to the stream being filtered. * @@ -89,16 +89,16 @@ public: void reset(); - size_type read(value_type* const data, const size_type count); + size_t read(byte_t* const data, const size_t count); - size_type skip(const size_type count); + size_t skip(const size_t count); private: inputStream& m_stream; - value_type m_previousChar2; // (N - 1)th character of previous buffer - value_type m_previousChar1; // (N)th (last) character of previous buffer + byte_t m_previousChar2; // (N - 1)th character of previous buffer + byte_t m_previousChar1; // (N)th (last) character of previous buffer }; @@ -118,13 +118,16 @@ public: outputStream& getNextOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: outputStream& m_stream; - value_type m_previousChar; + byte_t m_previousChar; bool m_start; }; @@ -145,13 +148,16 @@ public: outputStream& getNextOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: outputStream& m_stream; - value_type m_previousChar; + byte_t m_previousChar; }; @@ -171,13 +177,16 @@ public: outputStream& getNextOutputStream(); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: outputStream& m_stream; - value_type m_previousChar; + byte_t m_previousChar; }; @@ -195,11 +204,22 @@ public: * @param is stream from which to read data to be filtered * @param sequence sequence on which to stop */ - stopSequenceFilteredInputStream(inputStream& is, const value_type* sequence) + stopSequenceFilteredInputStream(inputStream& is, const byte_t* sequence) : m_stream(is), m_sequence(sequence), m_found(0), m_eof(false) { } + /** Construct a new filter for the specified input stream. + * + * @param is stream from which to read data to be filtered + * @param sequence sequence on which to stop + */ + stopSequenceFilteredInputStream(inputStream& is, const char* sequence) + : m_stream(is), m_sequence(reinterpret_cast (sequence)), + m_found(0), m_eof(false) + { + } + inputStream& getPreviousInputStream() { return (m_stream); @@ -216,9 +236,9 @@ public: m_stream.reset(); } - size_type read(value_type* const data, const size_type count); + size_t read(byte_t* const data, const size_t count); - size_type skip(const size_type /* count */) + size_t skip(const size_t /* count */) { // Not supported return 0; @@ -228,21 +248,21 @@ private: inputStream& m_stream; - const value_type* m_sequence; - size_type m_found; + const byte_t* m_sequence; + size_t m_found; bool m_eof; }; template <> -stream::size_type stopSequenceFilteredInputStream <1>::read - (value_type* const data, const size_type count); +size_t stopSequenceFilteredInputStream <1>::read + (byte_t* const data, const size_t count); template -stream::size_type stopSequenceFilteredInputStream ::read - (value_type* const data, const size_type count) +size_t stopSequenceFilteredInputStream ::read + (byte_t* const data, const size_t count) { // Read buffer must be at least 'COUNT' size + 1 byte if (eof() || count <= COUNT) @@ -252,9 +272,9 @@ stream::size_type stopSequenceFilteredInputStream ::read { if (m_found != 0) { - const size_type found = m_found; + const size_t found = m_found; - for (size_type f = 0 ; f < found ; ++f) + for (size_t f = 0 ; f < found ; ++f) data[f] = m_sequence[f]; m_found = 0; @@ -269,10 +289,10 @@ stream::size_type stopSequenceFilteredInputStream ::read } } - size_type read = m_stream.read(data, count - COUNT); + size_t read = m_stream.read(data, count - COUNT); - value_type* end = data + read; - value_type* pos = data; + byte_t* end = data + read; + byte_t* pos = data; while (pos < end) { @@ -344,12 +364,12 @@ stream::size_type stopSequenceFilteredInputStream ::read // the stream data // -- shift right data - const size_type n = pos - data; + const size_t n = pos - data; - value_type* newEnd = data + read + m_found - n; - value_type* oldEnd = data + read; + byte_t* newEnd = data + read + m_found - n; + byte_t* oldEnd = data + read; - for (size_type i = 0 ; i < read - n ; ++i) + for (size_t i = 0 ; i < read - n ; ++i) { --newEnd; --oldEnd; @@ -358,7 +378,7 @@ stream::size_type stopSequenceFilteredInputStream ::read } // -- copy the prefix just before data - for (size_type f = 0 ; f < m_found ; ++f) + for (size_t f = 0 ; f < m_found ; ++f) data[f] = m_sequence[f]; read += m_found - n; diff --git a/vmime/utility/inputStream.hpp b/vmime/utility/inputStream.hpp index 2503663c..809996ce 100644 --- a/vmime/utility/inputStream.hpp +++ b/vmime/utility/inputStream.hpp @@ -57,14 +57,14 @@ public: * @param count maximum number of bytes to read * @return number of bytes read */ - virtual size_type read(value_type* const data, const size_type count) = 0; + virtual size_t read(byte_t* const data, const size_t count) = 0; /** Skip a number of bytes. * * @param count maximum number of bytes to ignore * @return number of bytes skipped */ - virtual size_type skip(const size_type count) = 0; + virtual size_t skip(const size_t count) = 0; }; diff --git a/vmime/utility/inputStreamAdapter.hpp b/vmime/utility/inputStreamAdapter.hpp index 155debc2..dd761736 100644 --- a/vmime/utility/inputStreamAdapter.hpp +++ b/vmime/utility/inputStreamAdapter.hpp @@ -47,10 +47,10 @@ public: bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: diff --git a/vmime/utility/inputStreamByteBufferAdapter.hpp b/vmime/utility/inputStreamByteBufferAdapter.hpp index 4a6247f7..f201f433 100644 --- a/vmime/utility/inputStreamByteBufferAdapter.hpp +++ b/vmime/utility/inputStreamByteBufferAdapter.hpp @@ -39,21 +39,21 @@ class VMIME_EXPORT inputStreamByteBufferAdapter : public seekableInputStream { public: - inputStreamByteBufferAdapter(const byte_t* buffer, size_type length); + inputStreamByteBufferAdapter(const byte_t* buffer, size_t length); bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: const byte_t* m_buffer; - const size_type m_length; + const size_t m_length; - size_type m_pos; + size_t m_pos; }; diff --git a/vmime/utility/inputStreamSocketAdapter.hpp b/vmime/utility/inputStreamSocketAdapter.hpp index 8d23694d..a990f628 100644 --- a/vmime/utility/inputStreamSocketAdapter.hpp +++ b/vmime/utility/inputStreamSocketAdapter.hpp @@ -53,10 +53,10 @@ public: bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); - size_type getBlockSize(); + size_t getBlockSize(); private: diff --git a/vmime/utility/inputStreamStringAdapter.hpp b/vmime/utility/inputStreamStringAdapter.hpp index 605dd34e..4ee597e6 100644 --- a/vmime/utility/inputStreamStringAdapter.hpp +++ b/vmime/utility/inputStreamStringAdapter.hpp @@ -40,23 +40,23 @@ class VMIME_EXPORT inputStreamStringAdapter : public seekableInputStream public: inputStreamStringAdapter(const string& buffer); - inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end); + inputStreamStringAdapter(const string& buffer, const size_t begin, const size_t end); bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: inputStreamStringAdapter(const inputStreamStringAdapter&); const string m_buffer; // do _NOT_ keep a reference... - const string::size_type m_begin; - const string::size_type m_end; - string::size_type m_pos; + const size_t m_begin; + const size_t m_end; + size_t m_pos; }; diff --git a/vmime/utility/inputStreamStringProxyAdapter.hpp b/vmime/utility/inputStreamStringProxyAdapter.hpp index 725712a3..02dc2056 100644 --- a/vmime/utility/inputStreamStringProxyAdapter.hpp +++ b/vmime/utility/inputStreamStringProxyAdapter.hpp @@ -48,17 +48,17 @@ public: bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&); const stringProxy& m_buffer; - string::size_type m_pos; + size_t m_pos; }; diff --git a/vmime/utility/outputStream.hpp b/vmime/utility/outputStream.hpp index 99e1e41b..62ee7336 100644 --- a/vmime/utility/outputStream.hpp +++ b/vmime/utility/outputStream.hpp @@ -49,26 +49,55 @@ public: * @param data buffer containing data to write * @param count number of bytes to write */ - virtual void write(const value_type* const data, const size_type count) = 0; + void write(const byte_t* const data, const size_t count); + + /** Write data to the stream. + * + * @param data buffer containing data to write + * @param count number of bytes to write + */ + void write(const char* const data, const size_t count); + + /** Write data to the stream. + * + * @param data buffer containing data to write + * @param N number of bytes to write, including terminating + * null (value is induced by compiler) + */ + template + void write(const char (&data)[N]) + { + write(data, N - 1); + } /** Flush this output stream and forces any buffered output * bytes to be written out to the stream. */ virtual void flush() = 0; + +protected: + + /** Write data to the stream. + * This is the method to be implemented is subclasses. + * + * @param data buffer containing data to write + * @param count number of bytes to write + */ + virtual void writeImpl(const byte_t* const data, const size_t count) = 0; }; // Helpers functions VMIME_EXPORT outputStream& operator<<(outputStream& os, const string& str); -VMIME_EXPORT outputStream& operator<<(outputStream& os, const stream::value_type c); +VMIME_EXPORT outputStream& operator<<(outputStream& os, const byte_t c); #if defined(_MSC_VER) && (_MSC_VER <= 1200) // Internal compiler error with VC++6 inline outputStream& operator<<(outputStream& os, const char* str) { - os.write(str, ::strlen(str)); + os.write(reinterpret_cast (str), ::strlen(str)); return (os); } @@ -77,7 +106,7 @@ inline outputStream& operator<<(outputStream& os, const char* str) template outputStream& operator<<(outputStream& os, const char (&str)[N]) { - os.write(str, N - 1); + os.write(reinterpret_cast (str), N - 1); return (os); } diff --git a/vmime/utility/outputStreamAdapter.hpp b/vmime/utility/outputStreamAdapter.hpp index 3228db7f..f0125584 100644 --- a/vmime/utility/outputStreamAdapter.hpp +++ b/vmime/utility/outputStreamAdapter.hpp @@ -45,9 +45,12 @@ public: */ outputStreamAdapter(std::ostream& os); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: std::ostream& m_stream; diff --git a/vmime/utility/outputStreamByteArrayAdapter.hpp b/vmime/utility/outputStreamByteArrayAdapter.hpp index ce9cf82a..a2178a9c 100644 --- a/vmime/utility/outputStreamByteArrayAdapter.hpp +++ b/vmime/utility/outputStreamByteArrayAdapter.hpp @@ -41,9 +41,12 @@ public: outputStreamByteArrayAdapter(byteArray& array); - void write(const value_type* const data, const size_type count); void flush(); +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: byteArray& m_array; diff --git a/vmime/utility/outputStreamSocketAdapter.hpp b/vmime/utility/outputStreamSocketAdapter.hpp index e80be6a3..6cd00626 100644 --- a/vmime/utility/outputStreamSocketAdapter.hpp +++ b/vmime/utility/outputStreamSocketAdapter.hpp @@ -51,10 +51,13 @@ public: outputStreamSocketAdapter(net::socket& sok); - void write(const value_type* const data, const size_type count); void flush(); - size_type getBlockSize(); + size_t getBlockSize(); + +protected: + + void writeImpl(const byte_t* const data, const size_t count); private: diff --git a/vmime/utility/outputStreamStringAdapter.hpp b/vmime/utility/outputStreamStringAdapter.hpp index 689e4307..89516827 100644 --- a/vmime/utility/outputStreamStringAdapter.hpp +++ b/vmime/utility/outputStreamStringAdapter.hpp @@ -41,10 +41,12 @@ public: outputStreamStringAdapter(string& buffer); - void write(const value_type* const data, const size_type count); void flush(); -size_type getBlockSize(){return 8192;} +protected: + + void writeImpl(const byte_t* const data, const size_t count); + private: string& m_buffer; diff --git a/vmime/utility/parserInputStreamAdapter.hpp b/vmime/utility/parserInputStreamAdapter.hpp index 16ed6f68..9b0639b1 100644 --- a/vmime/utility/parserInputStreamAdapter.hpp +++ b/vmime/utility/parserInputStreamAdapter.hpp @@ -49,19 +49,19 @@ public: bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); + size_t read(byte_t* const data, const size_t count); - void seek(const size_type pos) + void seek(const size_t pos) { m_stream->seek(pos); } - size_type skip(const size_type count) + size_t skip(const size_t count) { return m_stream->skip(count); } - size_type getPosition() const + size_t getPosition() const { return m_stream->getPosition(); } @@ -71,18 +71,18 @@ public: * * @return byte at the current position */ - value_type peekByte() const + byte_t peekByte() const { - const size_type initialPos = m_stream->getPosition(); + const size_t initialPos = m_stream->getPosition(); try { - value_type buffer[1]; - const size_type readBytes = m_stream->read(buffer, 1); + byte_t buffer[1]; + const size_t readBytes = m_stream->read(buffer, 1); m_stream->seek(initialPos); - return (readBytes == 1 ? buffer[0] : static_cast (0)); + return (readBytes == 1 ? buffer[0] : static_cast (0)); } catch (...) { @@ -96,12 +96,12 @@ public: * * @return byte at the current position */ - value_type getByte() + byte_t getByte() { - value_type buffer[1]; - const size_type readBytes = m_stream->read(buffer, 1); + byte_t buffer[1]; + const size_t readBytes = m_stream->read(buffer, 1); - return (readBytes == 1 ? buffer[0] : static_cast (0)); + return (readBytes == 1 ? buffer[0] : static_cast (0)); } /** Check whether the bytes following the current position match @@ -111,14 +111,15 @@ public: * @param length number of bytes * @return true if the next bytes match the pattern, false otherwise */ - bool matchBytes(const value_type* bytes, const size_type length) const + template + bool matchBytes(const T* bytes, const size_t length) const { - const size_type initialPos = m_stream->getPosition(); + const size_t initialPos = m_stream->getPosition(); try { - value_type buffer[32]; - const size_type readBytes = m_stream->read(buffer, length); + byte_t buffer[32]; + const size_t readBytes = m_stream->read(buffer, length); m_stream->seek(initialPos); @@ -132,7 +133,7 @@ public: } } - const string extract(const size_type begin, const size_type end) const; + const string extract(const size_t begin, const size_t end) const; /** Skips bytes matching a predicate from the current position. * The current position is updated to the next following byte @@ -144,10 +145,10 @@ public: * @return number of bytes skipped */ template - size_type skipIf(PREDICATE pred, const size_type endPosition) + size_t skipIf(PREDICATE pred, const size_t endPosition) { - const size_type initialPos = getPosition(); - size_type pos = initialPos; + const size_t initialPos = getPosition(); + size_t pos = initialPos; while (!m_stream->eof() && pos < endPosition && pred(getByte())) ++pos; @@ -157,7 +158,7 @@ public: return pos - initialPos; } - size_type findNext(const string& token, const size_type startPosition = 0); + size_t findNext(const string& token, const size_t startPosition = 0); private: diff --git a/vmime/utility/progressListener.hpp b/vmime/utility/progressListener.hpp index 54ab9683..4d0e9bf8 100644 --- a/vmime/utility/progressListener.hpp +++ b/vmime/utility/progressListener.hpp @@ -26,6 +26,7 @@ #include "vmime/config.hpp" +#include "vmime/types.hpp" namespace vmime { @@ -58,20 +59,20 @@ public: * @param predictedTotal predicted amount of units (this has * no concrete meaning: these are not bytes, nor percentage...) */ - virtual void start(const long predictedTotal) = 0; + virtual void start(const size_t predictedTotal) = 0; /** Called during the operation (can be called several times). * * @param current current position * @param currentTotal adjusted total amount of units */ - virtual void progress(const long current, const long currentTotal) = 0; + virtual void progress(const size_t current, const size_t currentTotal) = 0; /** Called at the end of the operation. * * @param total final total amount of units */ - virtual void stop(const long total) = 0; + virtual void stop(const size_t total) = 0; }; @@ -80,7 +81,7 @@ public: * receiver, but not by the notifier. */ -class progressListenerSizeAdapter : public progressListener +class VMIME_EXPORT progressListenerSizeAdapter : public progressListener { public: @@ -89,18 +90,18 @@ public: * @param list wrapped progress listener (can be NULL) * @param total predicted total */ - progressListenerSizeAdapter(progressListener* list, const long total); + progressListenerSizeAdapter(progressListener* list, const size_t total); bool cancel() const; - void start(const long predictedTotal); - void progress(const long current, const long currentTotal); - void stop(const long total); + void start(const size_t predictedTotal); + void progress(const size_t current, const size_t currentTotal); + void stop(const size_t total); private: progressListener* m_wrapped; - long m_total; + size_t m_total; }; diff --git a/vmime/utility/random.hpp b/vmime/utility/random.hpp index 6c0aabf8..b667c3a2 100644 --- a/vmime/utility/random.hpp +++ b/vmime/utility/random.hpp @@ -65,7 +65,7 @@ public: * @param randomChars list of characters to use * @return random string */ - static const string getString(const string::size_type length, const string& randomChars + static const string getString(const size_t length, const string& randomChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); }; diff --git a/vmime/utility/seekableInputStream.hpp b/vmime/utility/seekableInputStream.hpp index f861fb0f..f56af9c4 100644 --- a/vmime/utility/seekableInputStream.hpp +++ b/vmime/utility/seekableInputStream.hpp @@ -44,7 +44,7 @@ public: * @return the offset from the beginning of the stream, in bytes, * at which the next read occurs */ - virtual size_type getPosition() const = 0; + virtual size_t getPosition() const = 0; /** Sets the position, measured from the beginning of this stream, * at which the next read occurs. @@ -52,7 +52,7 @@ public: * @param pos the offset position, measured in bytes from the * beginning of the stream, at which to set the stream pointer. */ - virtual void seek(const size_type pos) = 0; + virtual void seek(const size_t pos) = 0; }; diff --git a/vmime/utility/seekableInputStreamRegionAdapter.hpp b/vmime/utility/seekableInputStreamRegionAdapter.hpp index ce73b456..4716d2de 100644 --- a/vmime/utility/seekableInputStreamRegionAdapter.hpp +++ b/vmime/utility/seekableInputStreamRegionAdapter.hpp @@ -46,21 +46,21 @@ public: * @param length region length in source stream */ seekableInputStreamRegionAdapter(shared_ptr stream, - const size_type begin, const size_type length); + const size_t begin, const size_t length); bool eof() const; void reset(); - size_type read(value_type* const data, const size_type count); - size_type skip(const size_type count); - size_type getPosition() const; - void seek(const size_type pos); + size_t read(byte_t* const data, const size_t count); + size_t skip(const size_t count); + size_t getPosition() const; + void seek(const size_t pos); private: shared_ptr m_stream; - size_type m_begin; - size_type m_length; - size_type m_position; + size_t m_begin; + size_t m_length; + size_t m_position; }; diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp index 84a34f59..980a2407 100644 --- a/vmime/utility/stream.hpp +++ b/vmime/utility/stream.hpp @@ -46,24 +46,12 @@ public: virtual ~stream() { } - /** Type used to read/write one byte in the stream. - */ - typedef string::value_type value_type; - - /** Type used for lengths in streams. - */ - typedef string::size_type size_type; - - /** Constant value with the greatest possible value for an element of type size_type. - */ - static const size_type npos; - /** Return the preferred maximum block size when reading * from or writing to this stream. * * @return block size, in bytes */ - virtual size_type getBlockSize(); + virtual size_t getBlockSize(); }; diff --git a/vmime/utility/streamUtils.hpp b/vmime/utility/streamUtils.hpp index c9d63347..406b6b64 100644 --- a/vmime/utility/streamUtils.hpp +++ b/vmime/utility/streamUtils.hpp @@ -42,7 +42,7 @@ namespace utility { * @return number of bytes copied */ -VMIME_EXPORT stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os); +VMIME_EXPORT size_t bufferedStreamCopy(inputStream& is, outputStream& os); /** Copy data from one stream into another stream using a buffered method * and copying only a specified range of data. @@ -54,8 +54,8 @@ VMIME_EXPORT stream::size_type bufferedStreamCopy(inputStream& is, outputStream& * @return number of bytes copied */ -VMIME_EXPORT stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os, - const stream::size_type start, const stream::size_type length); +VMIME_EXPORT size_t bufferedStreamCopyRange(inputStream& is, outputStream& os, + const size_t start, const size_t length); /** Copy data from one stream into another stream using a buffered method * and notify progress state of the operation. @@ -67,8 +67,8 @@ VMIME_EXPORT stream::size_type bufferedStreamCopyRange(inputStream& is, outputSt * @return number of bytes copied */ -VMIME_EXPORT stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os, - const stream::size_type length, progressListener* progress); +VMIME_EXPORT size_t bufferedStreamCopy(inputStream& is, outputStream& os, + const size_t length, progressListener* progress); } // utility diff --git a/vmime/utility/stringProxy.hpp b/vmime/utility/stringProxy.hpp index 4815c5f1..e5efa135 100644 --- a/vmime/utility/stringProxy.hpp +++ b/vmime/utility/stringProxy.hpp @@ -46,42 +46,38 @@ class VMIME_EXPORT stringProxy { public: - typedef string::size_type size_type; - typedef string string_type; - - // Consruction stringProxy(); stringProxy(const stringProxy& s); - stringProxy(const string_type& s, const size_type start = 0, const size_type end = std::numeric_limits ::max()); + stringProxy(const string& s, const size_t start = 0, const size_t end = std::numeric_limits ::max()); // Assignment - void set(const string_type& s, const size_type start = 0, const size_type end = std::numeric_limits ::max()); + void set(const string& s, const size_t start = 0, const size_t end = std::numeric_limits ::max()); void detach(); stringProxy& operator=(const stringProxy& s); - stringProxy& operator=(const string_type& s); + stringProxy& operator=(const string& s); // Extract some portion (or whole) of the string // and output it into a stream. - void extract(outputStream& os, const size_type start = 0, const size_type end = std::numeric_limits ::max(), utility::progressListener* progress = NULL) const; + void extract(outputStream& os, const size_t start = 0, const size_t end = std::numeric_limits ::max(), utility::progressListener* progress = NULL) const; // Return the "virtual" length of the string - size_type length() const; + size_t length() const; // Return the boundaries of the "virtual" string - size_type start() const; - size_type end() const; + size_t start() const; + size_t end() const; string::const_iterator it_begin() const { return (m_buffer.begin() + m_start); } string::const_iterator it_end() const { return (m_buffer.begin() + m_end); } private: - string_type m_buffer; + string m_buffer; - size_type m_start; - size_type m_end; + size_t m_start; + size_t m_end; }; diff --git a/vmime/utility/stringUtils.hpp b/vmime/utility/stringUtils.hpp index 8521092c..7d9925e2 100644 --- a/vmime/utility/stringUtils.hpp +++ b/vmime/utility/stringUtils.hpp @@ -42,6 +42,30 @@ class VMIME_EXPORT stringUtils { public: + /** Makes a string from bytes. + * + * @param data pointer to buffer containing data + * @param count number of bytes to use from buffer + * @return a string object containing a copy of the specified data + */ + static const string makeStringFromBytes(const byte_t* data, const size_t count) + { + return string(reinterpret_cast (data), count); + } + + /** Appends bytes to a string. + * + * @param str string to which append data + * @param data pointer to buffer containing data + * @param count number of bytes to use from buffer + * @return a reference to modified string + */ + static string& appendBytesToString(string& str, const byte_t* data, const size_t count) + { + str.append(reinterpret_cast (data), count); + return str; + } + /** Test two strings for equality (case insensitive). * \warning Use this with ASCII-only strings. * @@ -50,7 +74,7 @@ public: * @param n length of the second string * @return true if the two strings compare equally, false otherwise */ - static bool isStringEqualNoCase(const string& s1, const char* s2, const string::size_type n); + static bool isStringEqualNoCase(const string& s1, const char* s2, const size_t n); /** Test two strings for equality (case insensitive). * \warning Use this with ASCII-only strings. @@ -70,7 +94,7 @@ public: * @param n length of the second string * @return true if the two strings compare equally, false otherwise */ - static bool isStringEqualNoCase(const string::const_iterator begin, const string::const_iterator end, const char* s, const string::size_type n); + static bool isStringEqualNoCase(const string::const_iterator begin, const string::const_iterator end, const char* s, const size_t n); /** Transform all the characters in a string to lower-case. * \warning Use this with ASCII-only strings. @@ -102,7 +126,7 @@ public: * @param end end position * @return number of ASCII characters */ - static string::size_type countASCIIchars(const string::const_iterator begin, const string::const_iterator end); + static size_t countASCIIchars(const string::const_iterator begin, const string::const_iterator end); /** Returns whether the specified string is composed exclusively * of 7-bit ASCII characters. @@ -118,7 +142,7 @@ public: * @param end end position * @return position since begin, or string::npos */ - static string::size_type findFirstNonASCIIchar(const string::const_iterator begin, const string::const_iterator end); + static size_t findFirstNonASCIIchar(const string::const_iterator begin, const string::const_iterator end); /** Convert the specified value to a string value. * diff --git a/vmime/word.hpp b/vmime/word.hpp index 29d2969c..a6e2402e 100644 --- a/vmime/word.hpp +++ b/vmime/word.hpp @@ -136,15 +136,15 @@ protected: void parseImpl (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition = NULL); + const size_t position, + const size_t end, + size_t* newPosition = NULL); void generateImpl (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const; + const size_t curLinePos = 0, + size_t* newLinePos = NULL) const; public: @@ -154,8 +154,8 @@ public: void generate (const generationContext& ctx, utility::outputStream& os, - const string::size_type curLinePos, - string::size_type* newLinePos, + const size_t curLinePos, + size_t* newLinePos, const int flags, generatorState* state) const; #endif @@ -167,9 +167,9 @@ private: static shared_ptr parseNext (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition, + const size_t position, + const size_t end, + size_t* newPosition, bool prevIsEncoded, bool* isEncoded, bool isFirst); @@ -177,9 +177,9 @@ private: static const std::vector > parseMultiple (const parsingContext& ctx, const string& buffer, - const string::size_type position, - const string::size_type end, - string::size_type* newPosition); + const size_t position, + const size_t end, + size_t* newPosition); // The "m_buffer" of this word holds the data, and this data is encoded diff --git a/vmime/wordEncoder.hpp b/vmime/wordEncoder.hpp index 557578fa..6f652fa2 100644 --- a/vmime/wordEncoder.hpp +++ b/vmime/wordEncoder.hpp @@ -65,7 +65,7 @@ public: * @param maxLength maximal length of the chunk * @return next chunk, of maximal length 'maxLength' if possible */ - const string getNextChunk(const string::size_type maxLength); + const string getNextChunk(const size_t maxLength); /** Return the encoding used. * @@ -93,8 +93,8 @@ public: private: string m_buffer; - string::size_type m_pos; - string::size_type m_length; + size_t m_pos; + size_t m_length; bool m_simple;