textPartFactory::textPartFactory()
{
	// Register some default names
	registerType <plainTextPart>(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
    // FIX by Elmue:
    // Added support for Microsoft Outlook Calendar events, treat them as plain text
    registerType <plainTextPart>(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_CALENDAR));
	registerType <htmlTextPart> (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
}
Exemplo n.º 2
0
// static
std::shared_ptr<const attachment> attachmentHelper::getBodyPartAttachment
	(std::shared_ptr<const bodyPart> part, const unsigned int options)
{
	if (!isBodyPartAnAttachment(part, options))
		return NULL;

	mediaType type;

	try
	{
		const contentTypeField& ctf = dynamic_cast<const contentTypeField&>
			(*part->getHeader()->findField(fields::CONTENT_TYPE));

		//type = *ctf.getValue().dynamicCast <const mediaType>(); TODO shared_ptr
		type = *dynamic_cast<const mediaType*>(ctf.getValue().get());
	}
	catch (exceptions::no_such_field&)
	{
		// No "Content-type" field: assume "application/octet-stream".
		type = mediaType(mediaTypes::APPLICATION,
		                 mediaTypes::APPLICATION_OCTET_STREAM);
	}

	if (type.getType() == mediaTypes::MESSAGE &&
	    type.getSubType() == mediaTypes::MESSAGE_RFC822)
	{
		return vmime::factory<generatedMessageAttachment>::create(part);
	}
	else
	{
		return std::dynamic_pointer_cast<const attachment>(
				vmime::factory<bodyPartAttachment>::create(part)
			);
	}
}
std::shared_ptr<MediaSourceImpl>
MediaElementImpl::getOrCreateVideoMediaSrc()
{
  mutex.lock();

  std::shared_ptr<MediaSourceImpl> locked;

  try {
    locked = videoMediaSrc.lock();
  } catch (const std::bad_weak_ptr &e) {
  }

  if (locked.get() == NULL) {
    std::shared_ptr<MediaType> mediaType (new MediaType (MediaType::VIDEO) );

    MediaSourceImpl *source = new  MediaSourceImpl (mediaType, "",
        std::dynamic_pointer_cast <MediaElementImpl> (shared_from_this() ) );

    locked = std::dynamic_pointer_cast<MediaSourceImpl>
             (MediaSet::getMediaSet().ref (source) );

    videoMediaSrc = std::weak_ptr<MediaSourceImpl> (locked);
  }

  mutex.unlock();

  return locked;
}
std::shared_ptr<MediaSinkImpl>
MediaElementImpl::getOrCreateAudioMediaSink()
{
  mutex.lock();

  std::shared_ptr<MediaSinkImpl> locked;

  try {
    locked = audioMediaSink.lock();
  } catch (const std::bad_weak_ptr &e) {
  }

  if (locked.get() == NULL) {
    std::shared_ptr<MediaType> mediaType (new MediaType (MediaType::AUDIO) );

    MediaSinkImpl *sink = new  MediaSinkImpl (mediaType, "",
        std::dynamic_pointer_cast <MediaElementImpl> (shared_from_this() ) );

    locked = std::dynamic_pointer_cast<MediaSinkImpl>
             (MediaSet::getMediaSet().ref (sink) );

    audioMediaSink = std::weak_ptr<MediaSinkImpl> (locked);
  }

  mutex.unlock();

  return locked;
}
Exemplo n.º 5
0
int K3b::Device::DiskInfo::numLayers() const
{
    if( isDvdMedia( mediaType() ) )
        return d->numLayers;
    else
        return 1;
}
Exemplo n.º 6
0
void MailMessage::makeMultipart()
{
	if (!isMultipart())
	{
		MediaType mediaType("multipart", "mixed");
		setContentType(mediaType);	
	}
}
Exemplo n.º 7
0
        void FixedPathHandler::handleRequest(Poco::Net::HTTPServerRequest &, Poco::Net::HTTPServerResponse &response) {
            Poco::Net::MediaType mediaType("text", "plain");
            response.setContentType(mediaType);
            response.setStatus(Poco::Net::HTTPResponse::HTTP_OK);

            std::ostream &stream = response.send();
            stream << "value";
        }
Exemplo n.º 8
0
bool PlatformMediaSession::activeAudioSessionRequired()
{
    if (mediaType() == PlatformMediaSession::None)
        return false;
    if (state() != PlatformMediaSession::State::Playing)
        return false;
    return m_canProduceAudio;
}
Exemplo n.º 9
0
void K3b::Device::DiskInfo::debug() const
{
    kDebug() << "DiskInfo:" << endl
             << "Mediatype:       " << K3b::Device::mediaTypeString( mediaType() ) << endl
             << "Current Profile: " << K3b::Device::mediaTypeString( currentProfile() ) << endl
             << "Disk state:      " << ( diskState() == K3b::Device::STATE_EMPTY ?
                                         "empty" :
                                         ( diskState() == K3b::Device::STATE_INCOMPLETE ?
                                           "incomplete" :
                                           ( diskState() == K3b::Device::STATE_COMPLETE ?
                                             "complete" :
                                             ( diskState() == K3b::Device::STATE_NO_MEDIA ?
                                               "no media" :
                                               "unknown" ) ) ) ) << endl
             << "Empty:           " << empty() << endl
             << "Rewritable:      " << rewritable() << endl
             << "Appendable:      " << appendable() << endl
             << "Sessions:        " << numSessions() << endl
             << "Tracks:          " << numTracks() << endl
             << "Layers:          " << numLayers() << endl
             << "Capacity:        " << capacity()
             << " (LBA " << capacity().lba()
             << ") (" << capacity().mode1Bytes() << " Bytes)" << endl

             << "Remaining size:  " << remainingSize()
             << " (LBA " << remainingSize().lba()
             << ") (" << remainingSize().mode1Bytes() << " Bytes)" << endl

             << "Used Size:       " << size()
             << " (LBA " << size().lba()
             << ") (" << size().mode1Bytes() << " Bytes)" << endl;

    if( mediaType() == K3b::Device::MEDIA_DVD_PLUS_RW )
        kDebug() << "Bg Format:       " << ( bgFormatState() == BG_FORMAT_NONE ?
                                             "none" :
                                             ( bgFormatState() == BG_FORMAT_INCOMPLETE ?
                                               "incomplete" :
                                               ( bgFormatState() == BG_FORMAT_IN_PROGRESS ?
                                                 "in progress" :
                                                 ( bgFormatState() == BG_FORMAT_COMPLETE ?
                                                   "complete" : "unknown" ) ) ) ) << endl;
}
Exemplo n.º 10
0
void plainTextPart::generateIn(std::shared_ptr<bodyPart> /* message */, std::shared_ptr<bodyPart> parent) const
{
	// Create a new part
	std::shared_ptr<bodyPart> part = vmime::factory<bodyPart>::create();
	parent->getBody()->appendPart(part);

	// Set contents
	part->getBody()->setContents(m_text,
		mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN), m_charset,
		encoding::decide(m_text, m_charset, encoding::USAGE_TEXT));
}
//------------------------------------------------------------------------------
void ofxIpVideoServerRouteHandler::handleRequest(HTTPServerRequest& request,
                                                 HTTPServerResponse& response) {
    
    
    if(isValidRequest(settings.route,request,response)) {
        MediaType mediaType("multipart/x-mixed-replace");
        mediaType.setParameter("boundary", settings.boundary);

        string expires = DateTimeFormatter::format(Timestamp(0), // the beginning of time
                                                   DateTimeFormat::HTTP_FORMAT);
        
        response.set("Cache-control","no-cache");
        response.setContentType(mediaType);
        response.set("Expires",expires);
        response.set("Pragma","no-cache");
        
        std::ostream& ostr = response.send(); // get output stream

        bool stopStreaming = false;
        
        while(ostr.good() && !stopStreaming) {
            if(!queue.empty()) {
                ofxIpVideoServerFramePtr frame = queue.pop();
                    if(frame != NULL) {
                        ofBuffer* buffer = &frame.get()->buffer;
                        ostr << settings.boundary;
                        ostr << "\r\n";
                        ostr << "Content-Type: image/jpeg";
                        ostr << "\r\n";
                        ostr << "Content-Length: " << ofToString(buffer->size());
                        ostr << "\r\n";
                        ostr << "\r\n";
                        ostr << *buffer;
                    } else {
                        ofLogVerbose("ofxIpVideoServerRouteHandler::handleRequest") << "Null buffer.";
                    }
                } else {
                    ofLogVerbose("ofxIpVideoServerRouteHandler::handleRequest") << "Queue empty.";
                }
            
            Thread::sleep(50);
        }
        
        queue.setActive(false); // a desperate move 
        
        ofLogNotice("ofxIpVideoServerRouteHandler::handleRequest") << "Client disconneted.";
        
        //sendErrorResponse(response);
    }
}
Exemplo n.º 12
0
void body::initNewPart(shared_ptr <bodyPart> part)
{
	// A part can be in only one body at the same time: if part is
	// already attached to a parent part, remove it from the current
	// parent part
	if (part->getParentPart())
		part->getParentPart()->getBody()->removePart(part);

	if (m_part != NULL)
	{
		m_part->importChildPart(part);

		shared_ptr <header> hdr = m_part->getHeader();

		// Check whether we have a boundary string
		shared_ptr <contentTypeField> ctf =
			hdr->findField <contentTypeField>(fields::CONTENT_TYPE);

		if (ctf)
		{
			if (ctf->hasBoundary())
			{
				const string boundary = ctf->getBoundary();

				if (boundary.empty() || !isValidBoundary(boundary))
					ctf->setBoundary(generateRandomBoundaryString());
			}
			else
			{
				// No "boundary" parameter: generate a random one.
				ctf->setBoundary(generateRandomBoundaryString());
			}

			if (ctf->getValue <mediaType>()->getType() != mediaTypes::MULTIPART)
			{
				// Warning: multi-part body but the Content-Type is
				// not specified as "multipart/..."
			}
		}
		else
		{
			// No "Content-Type" field: create a new one and generate
			// a random boundary string.
			ctf = hdr->getField <contentTypeField>(fields::CONTENT_TYPE);

			ctf->setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
			ctf->setBoundary(generateRandomBoundaryString());
		}
	}
}
PassOwnPtr<MediaQueryEvaluator> MediaQueryMatcher::prepareEvaluator() const
{
    if (!m_document || !m_document->frame())
        return nullptr;

    Element* documentElement = m_document->documentElement();
    if (!documentElement)
        return nullptr;

    StyleResolver* styleResolver = m_document->ensureStyleResolver();

    RefPtr<RenderStyle> rootStyle = styleResolver->styleForElement(documentElement, 0 /*defaultParent*/, DisallowStyleSharing, MatchOnlyUserAgentRules);

    return adoptPtr(new MediaQueryEvaluator(mediaType(), m_document->frame(), rootStyle.get()));
}
Exemplo n.º 14
0
const mediaType body::getContentType() const
{
    try
    {
        ref <const contentTypeField> ctf =
            m_header.acquire()->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();

        return (*ctf->getValue().dynamicCast <const mediaType>());
    }
    catch (exceptions::no_such_field&)
    {
        // Defaults to "text/plain" (RFC-1521)
        return (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
    }
}
Exemplo n.º 15
0
const mediaType body::getContentType() const
{
	shared_ptr <const contentTypeField> ctf =
		m_part->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE);

	if (ctf)
	{
		return *ctf->getValue <mediaType>();
	}
	else
	{
		// Defaults to "text/plain" (RFC-1521)
		return (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
	}
}
Exemplo n.º 16
0
void MailMessage::writeMultipart(MessageHeader& header, std::ostream& ostr) const
{
	if (_boundary.empty()) _boundary = MultipartWriter::createBoundary();
	MediaType mediaType(getContentType());
	mediaType.setParameter("boundary", _boundary);
	header.set(HEADER_CONTENT_TYPE, mediaType.toString());
	header.set(HEADER_MIME_VERSION, "1.0");
	writeHeader(header, ostr);
	
	MultipartWriter writer(ostr, _boundary);
	for (PartVec::const_iterator it = _parts.begin(); it != _parts.end(); ++it)
	{
		writePart(writer, *it);
	}
	writer.close();
}
Exemplo n.º 17
0
K3b::Msf K3b::Device::DiskInfo::remainingSize() const
{
    if( empty() )
        return capacity();

    //
    // There is no way to properly determine the used size on an overwrite media
    // without having a look at the filesystem (or is there?)
    //
    else if( appendable() ||
             mediaType() & (MEDIA_DVD_PLUS_RW|MEDIA_DVD_RW_OVWR) )
        return capacity() - d->usedCapacity;

    else
        return 0;
}
Exemplo n.º 18
0
void body::setCharset(const charset& chset)
{
	shared_ptr <contentTypeField> ctf =
		m_part->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE);

	// If a Content-Type field exists, set charset
	if (ctf)
	{
		ctf->setCharset(chset);
	}
	// Else, create a new Content-Type field of default type "text/plain"
	// and set charset on it
	else
	{
		setContentType(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN), chset);
	}
}
Exemplo n.º 19
0
PassOwnPtr<MediaQueryEvaluator> MediaQueryMatcher::prepareEvaluator() const
{
    if (!m_document || !m_document->frame())
        return nullptr;

    Element* documentElement = m_document->documentElement();
    if (!documentElement)
        return nullptr;

    CSSStyleSelector* styleSelector = m_document->styleSelector();
    if (!styleSelector)
        return nullptr;

    RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(documentElement, 0 /*defaultParent*/, false /*allowSharing*/, true /*resolveForRootDefault*/);

    return adoptPtr(new MediaQueryEvaluator(mediaType(), m_document->frame(), rootStyle.get()));
}
Exemplo n.º 20
0
const mediaType bodyPartAttachment::getType() const
{
	mediaType type;

	try
	{
		type = *getContentType()->getValue().dynamicCast <const mediaType>();
	}
	catch (exceptions::no_such_field&)
	{
		// No "Content-type" field: assume "application/octet-stream".
		type = mediaType(mediaTypes::APPLICATION,
				 mediaTypes::APPLICATION_OCTET_STREAM);
	}

	return type;
}
Exemplo n.º 21
0
void body::setCharset(const charset& chset)
{
    // If a Content-Type field exists, set charset
    try
    {
        ref <contentTypeField> ctf =
            m_header.acquire()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();

        ctf->setCharset(chset);
    }
    // Else, create a new Content-Type field of default type "text/plain"
    // and set charset on it
    catch (exceptions::no_such_field&)
    {
        setContentType(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN), chset);
    }
}
Exemplo n.º 22
0
void body::initNewPart(ref <bodyPart> part)
{
    part->m_parent = m_part;

    ref <header> hdr = m_header.acquire();

    if (hdr != NULL)
    {
        // Check whether we have a boundary string
        try
        {
            ref <contentTypeField> ctf =
                hdr->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();

            try
            {
                const string boundary = ctf->getBoundary();

                if (boundary.empty() || !isValidBoundary(boundary))
                    ctf->setBoundary(generateRandomBoundaryString());
            }
            catch (exceptions::no_such_parameter&)
            {
                // No "boundary" parameter: generate a random one.
                ctf->setBoundary(generateRandomBoundaryString());
            }

            if (ctf->getValue().dynamicCast <const mediaType>()->getType() != mediaTypes::MULTIPART)
            {
                // Warning: multi-part body but the Content-Type is
                // not specified as "multipart/..."
            }
        }
        catch (exceptions::no_such_field&)
        {
            // No "Content-Type" field: create a new one and generate
            // a random boundary string.
            ref <contentTypeField> ctf =
                hdr->getField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();

            ctf->setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
            ctf->setBoundary(generateRandomBoundaryString());
        }
    }
}
Exemplo n.º 23
0
ref <bodyPart> MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
                                             const string& text, const charset& ch)
{
	ref <bodyPart> part = vmime::create <bodyPart>();

	// Header
	ref <header> hdr = part->getHeader();

	hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
	                                       vmime::mediaTypes::TEXT_PLAIN));

	hdr->ContentType().dynamicCast <contentTypeField>()->setCharset(ch);

	// Body
	part->getBody()->setContents(vmime::create <stringContentHandler>(text));

	return (part);
}
Exemplo n.º 24
0
bool PostRouteFileHandler::isContentTypeValid(const std::string& contentType) const
{
    Poco::Net::MediaType mediaType(contentType);

    std::set<Poco::Net::MediaType> validContentTypes = _parent.getSettings().getValidContentTypes();
    std::set<Poco::Net::MediaType>::const_iterator iter = validContentTypes.begin();

    while(iter != validContentTypes.end())
    {
        if((*iter).matchesRange(mediaType))
        {
            return true;
        }

        ++iter;
    }
    
    return false;
}
Exemplo n.º 25
0
std::shared_ptr<bodyPart> MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
                                             const string& text, const charset& ch)
{
	std::shared_ptr<bodyPart> part = vmime::factory<bodyPart>::create();

	// Header
	std::shared_ptr<header> hdr = part->getHeader();

	hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
	                                       vmime::mediaTypes::TEXT_PLAIN));

	//hdr->ContentType().dynamicCast <contentTypeField>()->setCharset(ch); TODO shared
	std::dynamic_pointer_cast<contentTypeField>(hdr->ContentType())->setCharset(ch);

	// Body
	part->getBody()->setContents(vmime::factory<stringContentHandler>::create(text));

	return (part);
}
Exemplo n.º 26
0
HRESULT STDMETHODCALLTYPE XnVideoStream::SetFormat(AM_MEDIA_TYPE *pmt)
{
	XN_METHOD_START;

	XN_METHOD_CHECK_POINTER(pmt);
	if (pmt == NULL)
	{
		XN_METHOD_RETURN(E_INVALIDARG);
	}

	xnLogVerbose(XN_MASK_FILTER, "SetFormat was called");

	// check if this format is supported
	CMediaType mediaType(*pmt);
	int index = FindCapability(mediaType);
	if (index == -1)
	{
		XN_METHOD_RETURN(VFW_E_INVALIDMEDIATYPE);
	}

	// keep previous one (so we can rollback)
	int prevPreferred = m_nPreferredMode;

	// set the preferred mode
	m_nPreferredMode = index;

	// try to reconnect (if needed)
	IPin* pin; 
	ConnectedTo(&pin);
	if (pin)
	{
		IFilterGraph *pGraph = ((XnVideoSource*)m_pFilter)->GetGraph();
		HRESULT hr = pGraph->Reconnect(this);
		if (FAILED(hr))
		{
			// rollback
			m_nPreferredMode = prevPreferred;
			XN_METHOD_RETURN(hr);
		}
	}

	XN_METHOD_RETURN(S_OK);
}
Exemplo n.º 27
0
ref <bodyPart> MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
{
	ref <bodyPart> part = vmime::create <bodyPart>();

	// Header
	ref <header> hdr = part->getHeader();

	hdr->ContentDisposition()->setValue(vmime::contentDispositionTypes::INLINE);
	hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
	                                       vmime::mediaTypes::TEXT_RFC822_HEADERS));

	// Body: original message headers
	std::ostringstream oss;
	utility::outputStreamAdapter vos(oss);

	mdnInfos.getMessage()->getHeader()->generate(vos);

	part->getBody()->setContents(vmime::create <stringContentHandler>(oss.str()));

	return (part);
}
Exemplo n.º 28
0
std::shared_ptr<message> MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
                                  const string& text,
                                  const charset& ch,
                                  const mailbox& expeditor,
                                  const disposition& dispo,
                                  const string& reportingUA,
                                  const std::vector <string>& reportingUAProducts)
{
	// Create a new message
	std::shared_ptr<message> msg = vmime::factory<message>::create();

	// Fill-in header fields
	std::shared_ptr<header> hdr = msg->getHeader();

	hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MULTIPART,
	                                       vmime::mediaTypes::MULTIPART_REPORT));
	//hdr->ContentType().dynamicCast <contentTypeField>()->setReportType("disposition-notification"); TODO shared
	std::dynamic_pointer_cast<contentTypeField>(hdr->ContentType())->setReportType("disposition-notification");

	hdr->Disposition()->setValue(dispo);

	addressList to;
	to.appendAddress(vmime::factory<mailbox>::create(mdnInfos.getRecipient()));
	hdr->To()->setValue(to);

	hdr->From()->setValue(expeditor);

	hdr->Subject()->setValue(vmime::text(word("Disposition notification")));

	hdr->Date()->setValue(datetime::now());
	hdr->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));

	msg->getBody()->appendPart(createFirstMDNPart(mdnInfos, text, ch));
	msg->getBody()->appendPart(createSecondMDNPart(mdnInfos,
		dispo, reportingUA, reportingUAProducts));
	msg->getBody()->appendPart(createThirdMDNPart(mdnInfos));

	return (msg);
}
Exemplo n.º 29
0
bool PostRouteFileHandler::isContentTypeValid(const std::string& contentType) const
{
    Poco::Net::MediaType mediaType(contentType);
    
    const BaseRouteSettings::MediaTypeSet& validContentTypes = _route.settings().getValidContentTypes();

    BaseRouteSettings::MediaTypeSet::const_iterator iter = validContentTypes.begin();
    
    while (iter != validContentTypes.end())
    {
        Poco::Net::MediaType type(*iter);

        if (type.matchesRange(mediaType))
        {
            return true;
        }
        
        ++iter;
    }

    return false;
}
Exemplo n.º 30
0
void MailMessage::writePart(MultipartWriter& writer, const Part& part) const
{
	MessageHeader partHeader(part.pSource->headers());
	MediaType mediaType(part.pSource->mediaType());
	if (!part.name.empty())
		mediaType.setParameter("name", part.name);
	partHeader.set(HEADER_CONTENT_TYPE, mediaType.toString());
	partHeader.set(HEADER_CONTENT_TRANSFER_ENCODING, contentTransferEncodingToString(part.encoding));
	std::string disposition;
	if (part.disposition == CONTENT_ATTACHMENT)
	{
		disposition = "attachment";
		const std::string& filename = part.pSource->filename();
		if (!filename.empty())
		{
			disposition.append("; filename=");
			quote(filename, disposition);
		}
	}
	else disposition = "inline";
	partHeader.set(HEADER_CONTENT_DISPOSITION, disposition);
	writer.nextPart(partHeader);
	writeEncoded(part.pSource->stream(), writer.stream(), part.encoding);
}