Пример #1
0
utility::stream::size_type body::getGeneratedSize(const generationContext& ctx)
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		utility::stream::size_type size = 0;

		// Size of parts and boundaries
		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			size += 100;  // boundary, CRLF...
			size += getPartAt(p)->getGeneratedSize(ctx);
		}

		// Size of prolog/epilog text
		const text prologText = getActualPrologText(ctx);

		if (!prologText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			prologText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		const text epilogText = getActualEpilogText(ctx);

		if (!epilogText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			epilogText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		return size;
	}
	// Simple body
	else
	{
		ref <utility::encoder::encoder> srcEncoder = m_contents->getEncoding().getEncoder();
		ref <utility::encoder::encoder> dstEncoder = getEncoding().getEncoder();

		return dstEncoder->getEncodedSize(srcEncoder->getDecodedSize(m_contents->getLength()));
	}
}
Пример #2
0
void GunTower::onUpdate(float frametime)
{
	move(-EntityManager::FOREGROUND_SPEED * frametime, 0.f);
	updateParts(frametime);

	// Rotate turret toward player
	Part& turret = getPartAt(0);
	if (!turret.isDead())
	{
		turret.setRotation(180 - math::to_degrees(math::angle(getPosition(), m_target->getPosition())));
		m_weapon.shoot(m_target->getCenter());
	}
}
Пример #3
0
void body::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
                        const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
    // MIME-Multipart
    if (getPartCount() != 0)
    {
        string boundary;

        if (m_header.acquire() == NULL)
        {
            boundary = generateRandomBoundaryString();
        }
        else
        {
            try
            {
                ref <const contentTypeField> ctf =
                    m_header.acquire()->findField(fields::CONTENT_TYPE)
                    .dynamicCast <const contentTypeField>();

                boundary = ctf->getBoundary();
            }
            catch (exceptions::no_such_field&)
            {
                // Warning: no content-type and no boundary string specified!
                boundary = generateRandomBoundaryString();
            }
            catch (exceptions::no_such_parameter&)
            {
                // Warning: no boundary string specified!
                boundary = generateRandomBoundaryString();
            }
        }

        const string& prologText =
            m_prologText.empty()
            ? (isRootPart()
               ? options::getInstance()->multipart.getPrologText()
               : NULL_STRING
              )
            : m_prologText;

        const string& epilogText =
            m_epilogText.empty()
            ? (isRootPart()
               ? options::getInstance()->multipart.getEpilogText()
               : NULL_STRING
              )
            : m_epilogText;

        if (!prologText.empty())
        {
            text prolog(prologText, vmime::charset("us-ascii"));

            prolog.encodeAndFold(os, maxLineLength, 0,
                                 NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

            os << CRLF;
        }

        os << "--" << boundary;

        for (int p = 0 ; p < getPartCount() ; ++p)
        {
            os << CRLF;

            getPartAt(p)->generate(os, maxLineLength, 0);

            os << CRLF << "--" << boundary;
        }

        os << "--" << CRLF;

        if (!epilogText.empty())
        {
            text epilog(epilogText, vmime::charset("us-ascii"));

            epilog.encodeAndFold(os, maxLineLength, 0,
                                 NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

            os << CRLF;
        }

        if (newLinePos)
            *newLinePos = 0;
    }
    // Simple body
    else
    {
        // Generate the contents
        m_contents->generate(os, getEncoding(), maxLineLength);
    }
}
Пример #4
0
void body::generateImpl
	(const generationContext& ctx, utility::outputStream& os,
	 const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		string boundary;

		if (m_header.acquire() == NULL)
		{
			boundary = generateRandomBoundaryString();
		}
		else
		{
			try
			{
				ref <const contentTypeField> ctf =
					m_header.acquire()->findField(fields::CONTENT_TYPE)
						.dynamicCast <const contentTypeField>();

				boundary = ctf->getBoundary();
			}
			catch (exceptions::no_such_field&)
			{
				// Warning: no content-type and no boundary string specified!
				boundary = generateRandomBoundaryString();
			}
			catch (exceptions::no_such_parameter&)
			{
				// Warning: no boundary string specified!
				boundary = generateRandomBoundaryString();
			}
		}

		const text prologText = getActualPrologText(ctx);
		const text epilogText = getActualEpilogText(ctx);

		if (!prologText.isEmpty())
		{
			prologText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		os << "--" << boundary;

		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			os << CRLF;

			getPartAt(p)->generate(ctx, os, 0);

			os << CRLF << "--" << boundary;
		}

		os << "--" << CRLF;

		if (!epilogText.isEmpty())
		{
			epilogText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		if (newLinePos)
			*newLinePos = 0;
	}
	// Simple body
	else
	{
		// Generate the contents
		ref <contentHandler> contents = m_contents->clone();
		contents->setContentTypeHint(getContentType());

		contents->generate(os, getEncoding(), ctx.getMaxLineLength());
	}
}
Пример #5
0
void body::generateImpl
	(const generationContext& ctx, utility::outputStream& os,
	 const size_t /* curLinePos */, size_t* newLinePos) const
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		string boundary;

		if (!m_part)
		{
			boundary = generateRandomBoundaryString();
		}
		else
		{
			// Use current boundary string, if specified. If no "Content-Type" field is
			// present, or the boundary is not specified, generate a random one
			shared_ptr <contentTypeField> ctf =
				m_part->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE);

			if (ctf)
			{
				if (ctf->hasBoundary())
				{
					boundary = ctf->getBoundary();
				}
				else
				{
					// No boundary string specified
					boundary = generateRandomBoundaryString();
				}
			}
			else
			{
				// No Content-Type (and no boundary string specified)
				boundary = generateRandomBoundaryString();
			}
		}

		const text prologText = getActualPrologText(ctx);
		const text epilogText = getActualEpilogText(ctx);

		if (!prologText.isEmpty())
		{
			prologText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		os << "--" << boundary;

		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			os << CRLF;

			getPartAt(p)->generate(ctx, os, 0);

			os << CRLF << "--" << boundary;
		}

		os << "--" << CRLF;

		if (!epilogText.isEmpty())
		{
			epilogText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		if (newLinePos)
			*newLinePos = 0;
	}
	// Simple body
	else
	{
		// Generate the contents
		shared_ptr <contentHandler> contents = m_contents->clone();
		contents->setContentTypeHint(getContentType());

		contents->generate(os, getEncoding(), ctx.getMaxLineLength());
	}
}