Пример #1
0
QByteArray K3BookmarkDrag::encodedData( const char* mime ) const
{
    QByteArray a;
    Q3CString mimetype( mime );
    if ( mimetype == "text/uri-list" )
        return Q3UriDrag::encodedData( mime );
    else if ( mimetype == "application/x-xbel" )
    {
        a = m_doc.toByteArray();
        //kDebug(7043) << "K3BookmarkDrag::encodedData " << m_doc.toCString();
    }
    else if ( mimetype == "text/plain" )
    {
        KUrl::List m_lstDragURLs;
        if ( K3URLDrag::decode( this, m_lstDragURLs ) )
        {
            QStringList uris;
            KUrl::List::ConstIterator uit = m_lstDragURLs.constBegin();
            KUrl::List::ConstIterator uEnd = m_lstDragURLs.constEnd();
            for ( ; uit != uEnd ; ++uit )
                uris.append( (*uit).prettyUrl() );

            Q3CString s = uris.join( "\n" ).toLocal8Bit();
            a.resize( s.length() + 1 ); // trailing zero
            memcpy( a.data(), s.data(), s.length() + 1 );
        }
    }
    return a;
}
Пример #2
0
QVariant SuovaFileInfo::information(const QString &key) const
{
    QString shortKey = withoutContext(key); // nie:title --> title

    if( shortKey == "fileLastAccessed")
        return accessed();
    else if( shortKey == "fileLastModified")
        return modified();
    else if( shortKey == "fileName")
        return fileName();
    else if( shortKey == "fileSize")
        return bytes();
    else if( shortKey == "contentCreated")
        return created();
    else if( shortKey == "isStoredAs")
        return urn();
    else if( shortKey == "mimeType")
        return mimetype();
    else if( shortKey == "title")
        return title();
    else if( shortKey == "url")
        return url();

    return QVariant();
}
Пример #3
0
void
MimeTypeList::Build()
{
	ASSERT(fLock.IsLocked());

	BMessage message;
	BMimeType::GetInstalledTypes(&message);

	int32 count;
	uint32 type;
	message.GetInfo("types", &type, &count);

	for (int32 index = 0; index < count; index++) {
		const char* str;
		if (message.FindString("types", index, &str) != B_OK)
			continue;

		BMimeType mimetype(str);
		if (mimetype.InitCheck() != B_OK)
			continue;

		ShortMimeInfo* mimeInfo = new ShortMimeInfo(mimetype);
		fMimeList.AddItem(mimeInfo);
		if (mimeInfo->IsCommonMimeType())
			fCommonMimeList.AddItem(mimeInfo);
	}

	fCommonMimeList.SortItems(&ShortMimeInfo::CompareShortDescription);
	fLock.Unlock();
}
Пример #4
0
int cdmifs_write(
		const char *path,
		const char *data, size_t size, off_t offset,
		struct fuse_file_info *fi )
{
	json_t *handle = long2pointer( fi->fh );

	int ret;
	const char *mime = NULL;
	cdmi_request_t request;

	if( data == NULL )
		data = "";

	mime = json_string_value( json_object_get(handle, "mimetype") );
	if( offset == 0 )
		mime = mimetype( data, size, mime );

	memset( &request, 0, sizeof( cdmi_request_t ) );
	request.type = PUT;
	request.cdmi = 0;
	request.rawdata = data;
	request.length = size;
	request.offset = offset;
	request.flags = CDMI_DATAOBJECT;
	ret = cdmi_put( &request, path );
	cdmi_free( &request );
	if( ret < 1 )
		return errno == 0 ? -EIO : -errno;
	return size;
}
OMX_ERRORTYPE COmxILAudioFileSourceAPB0Port::SetFormatInPortDefinition(const OMX_PARAM_PORTDEFINITIONTYPE& aPortDefinition,
																TBool& /*aUpdateProcessingFunction*/)
	{
	OMX_ERRORTYPE omxErr = OMX_ErrorNone;
    if (aPortDefinition.format.audio.eEncoding == OMX_AUDIO_CodingUnused)
        {
        OMX_STRING ptempMIMEType = GetParamPortDefinition().format.audio.cMIMEType;
        GetParamPortDefinition().format.audio = aPortDefinition.format.audio;
        GetParamPortDefinition().format.audio.cMIMEType = ptempMIMEType;
        
        if(aPortDefinition.format.audio.cMIMEType)
            {
            TInt len= strlen (aPortDefinition.format.audio.cMIMEType);
            if(len > 0)
                {
                TPtrC8 mimetype(reinterpret_cast<const TUint8 *>(aPortDefinition.format.audio.cMIMEType), len +1 );
                HBufC8 *pHBuf = mimetype.Alloc();
                if(pHBuf != NULL )
                    {
                    iMimeType.Close();
                    iMimeType.Assign(pHBuf );
                    TUint8* pTempBuff = const_cast<TUint8*>(iMimeType.PtrZ() );
                    GetParamPortDefinition().format.audio.cMIMEType = reinterpret_cast<OMX_STRING>(pTempBuff );
                    }
                }
            }
        }
    else
        {
        omxErr = OMX_ErrorUnsupportedSetting;
        }
	    
	    return omxErr;
	}
Пример #6
0
QList<QVariant> SuovaFileInfo::allInformation() const
{
    QList<QVariant> information;
    information << accessed() << modified() << fileName()
                << bytes() << created() << urn()
                << mimetype() << title() << url();
    return information;
}
Пример #7
0
KFileMetaInfo KFileItem::metaInfo(bool autoget, int what) const
{
    if ((isRegularFile() || isDir()) && autoget && !d->m_metaInfo.isValid())
    {
        bool isLocalUrl;
        KUrl url(mostLocalUrl(isLocalUrl));
        d->m_metaInfo = KFileMetaInfo(url.toLocalFile(), mimetype(), (KFileMetaInfo::What)what);
    }
    return d->m_metaInfo;
}
Пример #8
0
wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
{
    InitIfNeeded();

    wxFileType * fileType = NULL;
    // mime types are not case-sensitive
    wxString mimetype(mimeType);
    mimetype.MakeLower();

    // first look for an exact match
    int index = m_aTypes.Index(mimetype);

    if ( index != wxNOT_FOUND )
    {
        fileType = new wxFileType;
        fileType->m_impl->Init(this, index);
    }

    // then try to find "text/*" as match for "text/plain" (for example)
    // NB: if mimeType doesn't contain '/' at all, BeforeFirst() will return
    //     the whole string - ok.

    index = wxNOT_FOUND;
    wxString strCategory = mimetype.BeforeFirst(wxT('/'));

    size_t nCount = m_aTypes.GetCount();
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
    for ( size_t n = 0; n < nCount; n++ )
    {
        if ( (m_aTypes[n].BeforeFirst(wxT('/')) == strCategory ) &&
                m_aTypes[n].AfterFirst(wxT('/')) == wxT("*") )
        {
            index = n;
            break;
        }
    }

    if ( index != wxNOT_FOUND )
    {
       // don't throw away fileType that was already found
        if (!fileType)
            fileType = new wxFileType;
        fileType->m_impl->Init(this, index);
    }

    return fileType;
}
Пример #9
0
/**
 * If the load fails, you can get the (translateable) error message using \a error().
 * @return true on success
 */
bool Reader::load(const QString &filename)
{
	QFile orafile(filename);
	if(!orafile.open(QIODevice::ReadOnly)) {
		_error = orafile.errorString();
		return false;
	}

	ZipReader zip(&orafile);

	if(!zip.isReadable()) {
		_error = QApplication::tr("ORA file is unreadable!");
		return false;
	}

	// Make sure this is an OpenRaster file
	{
		QByteArray mimetype(zip.fileData("mimetype"));
		qDebug() << "read mimetype:" << mimetype;
		if(mimetype != "image/openraster") {
			_error = QApplication::tr("File is not an OpenRaster file");
			return false;
		}
	}

	// Read the stack
	QDomDocument doc;
	if(doc.setContent(zip.fileData("stack.xml"), true, &_error) == false)
		return false;

	const QDomElement stackroot = doc.documentElement().firstChildElement("stack");

	// Get the size of the image
	// These attributes are required by ORA standard.
	QSize imagesize(
			doc.documentElement().attribute("w").toInt(),
			doc.documentElement().attribute("h").toInt()
			);

	if(imagesize.isEmpty()) {
		_error = QApplication::tr("Image has zero size!");
		return false;
	}

	// Initialize the layer stack now that we know the size
	_commands.append(MessagePtr(new protocol::CanvasResize(imagesize.width(), imagesize.height())));

	_layerid = 0;
	_annotationid = 0;
	// Load the layer images
	if(loadLayers(zip, stackroot, QPoint()) == false)
		return false;

	return true;
}
Пример #10
0
KIso::KIso(const QString& filename, const QString & _mimetype)
        : KArchive(0L)
{
    KISOFUNC;
    KISODEBUG("Starting KIso: " << filename << " - type: " << _mimetype);

    m_startsec = -1;
    m_filename = filename;
    d = new KIsoPrivate;
    QString mimetype(_mimetype);
    bool forced = true;
    if (mimetype.isEmpty()) {
        QMimeDatabase db;
        QMimeType mt = db.mimeTypeForFile(filename, QMimeDatabase::MatchContent);
        if (mt.isValid())
            mimetype = mt.name();

        //qDebug() << "KIso::KIso mimetype=" << mimetype << endl;

        // Don't move to prepareDevice - the other constructor theoretically allows ANY filter
        if (mimetype == "application/x-tgz" || mimetype == "application/x-targz" ||  // the latter is deprecated but might still be around
                mimetype == "application/x-webarchive")
            // that's a gzipped tar file, so ask for gzip filter
            mimetype = "application/x-gzip";
        else if (mimetype == "application/x-tbz")   // that's a bzipped2 tar file, so ask for bz2 filter
            mimetype = "application/x-bzip2";
        else {
            // Something else. Check if it's not really gzip though (e.g. for KOffice docs)
            QFile file(filename);
            if (file.open(QIODevice::ReadOnly)) {
                char firstByte;
                char secondByte;
                char thirdByte;
                file.getChar(&firstByte);
                file.getChar(&secondByte);
                file.getChar(&thirdByte);
                if (firstByte == 0037 && secondByte == (char)0213)
                    mimetype = "application/x-gzip";
                else if (firstByte == 'B' && secondByte == 'Z' && thirdByte == 'h')
                    mimetype = "application/x-bzip2";
                else if (firstByte == 'P' && secondByte == 'K' && thirdByte == 3) {
                    char fourthByte;
                    file.getChar(&fourthByte);
                    if (fourthByte == 4)
                        mimetype = "application/x-zip";
                }
            }
        }
        forced = false;
    }

    prepareDevice(filename, mimetype, forced);
}
Пример #11
0
const char* FileInfo::mimeclass()
{

  mimetype();

	if ( _mimetype == "wav" )  _mimeclass = "audio";
	if ( _mimetype == "mp3" )  _mimeclass = "audio";
	if ( _mimetype == "trs" )  _mimeclass = "transcript";
	if ( _mimetype == "tag" )  _mimeclass = "transcript";

  return _mimeclass.c_str();
}
Пример #12
0
const KFileMetaInfo & KFileItem::metaInfo(bool autoget, int) const
{
    bool isLocalURL;
    KURL url = mostLocalURL(isLocalURL);

    if ( autoget && !m_metaInfo.isValid() &&
         KGlobalSettings::showFilePreview(url) )
    {
        m_metaInfo = KFileMetaInfo( url, mimetype() );
    }

    return m_metaInfo;
}
    void HttpGetThread::run()
    {
        int pos;
        std::string querystring = "";
        if((pos = (int) mRequest.uri.find_last_of('?')) != std::string::npos)
        {
            querystring = mRequest.uri.substr(pos+1);
        }
        else pos = (int) mRequest.uri.length();
        
        std::string uri = mRequest.uri.substr(0,pos);
        
        if(Script::is_uri_a_script(uri))
        {
            Script * script = Script::buildScript(uri,querystring);
            mResponse.body = script->execute();
        }
        else
        {
            std::ifstream file(mRequest.uri.c_str());
            std::string data;
            char c;
            
            while(file.good())
            {
                c = file.get();
                if(file.good())
                  data.push_back(c);
            }
            
            mResponse.body = data;
        }

        std::stringstream ss(std::stringstream::in | std::stringstream::out);
        int length = (int) mResponse.body.length();
        ss << length;

        mResponse.add_header("Content-Length",ss.str());
        
        MIME mimetype(mRequest.uri);
        mResponse.add_header("Content-Type", mimetype.type());

        mResponse.code = Response::OK;
    }
Пример #14
0
bool KFileItem::acceptsDrops() const
{
    // A directory ?
    if ( S_ISDIR( mode() ) ) {
        return isWritable();
    }

    // But only local .desktop files and executables
    if ( !d->m_bIsLocalUrl )
        return false;

    if ( mimetype() == "application/x-desktop")
        return true;

    // Executable, shell script ... ?
    if ( QFileInfo(d->m_url.toLocalFile()).isExecutable() )
        return true;

    return false;
}
Пример #15
0
bool KFileItem::acceptsDrops()
{
  // A directory ?
  if ( S_ISDIR( mode() ) ) {
      return isWritable();
  }

  // But only local .desktop files and executables
  if ( !m_bIsLocalURL )
    return false;

  if ( mimetype() == "application/x-desktop")
    return true;

  // Executable, shell script ... ?
  if ( ::access( QFile::encodeName(m_url.path()), X_OK ) == 0 )
    return true;

  return false;
}
Пример #16
0
QMimeSource* Q3MimeSourceFactory::dataInternal(const QString& abs_name, const QMap<QString, QString> &extensions) const
{
    QMimeSource* r = 0;
    QStringList attempted_names(abs_name);
    QFileInfo fi(abs_name);
    if (fi.isReadable()) {
        // get the right mimetype
        QString e = fi.extension(false);
        QByteArray mimetype("application/octet-stream");
        if (extensions.contains(e))
            mimetype = extensions[e].latin1();
        if (!QImageReader::imageFormat(abs_name).isEmpty())
            mimetype = "application/x-qt-image";

        QFile f(abs_name);
        if (f.open(QIODevice::ReadOnly) && f.size()) {
            QByteArray ba;
            ba.resize(f.size());
            f.readBlock(ba.data(), ba.size());
            Q3StoredDrag* sr = new Q3StoredDrag(mimetype);
            sr->setEncodedData(ba);
            delete d->last;
            d->last = r = sr;
        }
    }

    // we didn't find the mime-source, so ask the default factory for
    // the mime-source (this one will iterate over all installed ones)
    //
    // this looks dangerous, as this dataInternal() function will be
    // called again when the default factory loops over all installed
    // factories (including this), but the static bool looping in
    // data() avoids endless recursions
    if (!r && this != defaultFactory())
        r = (QMimeSource*)defaultFactory()->data(abs_name);

    return r;
}
Пример #17
0
bool CPyMFC_CustomProtocol::doCallback(LPCWSTR url) {
	PyMFCEnterPython e;
	{
		if (!mapfunc | !*mapfunc) {
			return false;
		}

		PyDTObject f(*mapfunc, true);
		f.incRef();
		
		PyDTUnicode s(url);
		try {
			PyDTObject ret = f.call("O", s.get());
			if (!ret.isTrue()) {
				return false;
			}
			m_dwPos = 0;
	
			PyDTDict d(ret);
			PyDTUnicode mimetype(d.getItem("mimetype"));

			m_mimetype = mimetype.asUnicode();
			PyDTString src(d.getItem("src"));
			
			m_src.SetCount(src.size());
			memcpy(m_src.GetData(), src.asString(), src.size());

		}
		catch (PyDTException &exc) {
			exc.setError();
			PyErr_Print();
			return false;
		}

	}
	return true;
}
Пример #18
0
// grab the content type header
String HTTPHeader::getContentType()
{
	if (pcontenttype != NULL) {
		String mimetype(pcontenttype->after(" "));
		if (mimetype.length() < 1)
			return "-";
		
		unsigned char c;
		size_t j = 0;
		while (j < mimetype.length()) {
			c = mimetype[j];
			if (c == ' ' || c == ';' || c < 32) {	// remove the
				mimetype = mimetype.subString(0, j);
				// extra info not needed
				j = 0;
			}
			++j;
		}
		
		mimetype.toLower();
		return mimetype;
	}
	return "-";
}
String FrameLoaderClientAndroid::generatedMIMETypeForURLScheme(const String& URLScheme) const {
    // FIXME, copy from Apple's port
    String mimetype("x-apple-web-kit/");
    mimetype.append(URLScheme.lower());
    return mimetype;
}
Пример #20
0
// test whether or not a request should be scanned based on sent & received headers
int CSPlugin::scanTest(HTTPHeader * requestheader, HTTPHeader * docheader, const char *user, int filtergroup, const char *ip)
{
	char *i;

	//exceptionvirusmimetypelist
	String mimetype(docheader->getContentType());
#ifdef DGDEBUG
	std::cout<<"mimetype: "<<mimetype<<std::endl;
#endif
	i = exceptionvirusmimetypelist.findInList(mimetype.toCharArray());
	if (i != NULL) {
		return DGCS_NOSCAN;  // match
	}

	String disposition(docheader->disposition());
#ifdef DGDEBUG
	std::cout<<"disposition: "<<disposition<<std::endl;
#endif
	String url(requestheader->url());
	String urld(requestheader->decode(url));
	urld.removeWhiteSpace();
	urld.toLower();
	urld.removePTP();
	String domain, tempurl, foundurl, path, extension;
	unsigned int fl;
	if (urld.contains("/")) {
		domain = urld.before("/");
		path = "/" + urld.after("/");
		path.hexDecode();
		path.realPath();
	} else {
		domain = urld;
	}

	// don't scan our web server
	if (((o.fg[filtergroup]->reporting_level == 1) || (o.fg[filtergroup]->reporting_level == 2)) && domain.startsWith(o.fg[filtergroup]->access_denied_domain)) {
		return DGCS_NOSCAN;
	}

	//exceptionvirusextensionlist
	if (disposition.length() > 2) {
		extension = disposition;
		while (extension.contains(".")) {
			extension = extension.after(".");
		}
		extension = "." + extension;
	} else {
		if (!path.contains("?")) {
			extension = path;
		}
		else if (mimetype.contains("application/")) {
			extension = path;
			if (extension.contains("?")) {
				extension = extension.before("?");
			}
		}
	}
#ifdef DGDEBUG
	std::cout<<"extension: "<<extension<<std::endl;
#endif
	if (extension.contains(".")) {
		i = exceptionvirusextensionlist.findEndsWith(extension.toCharArray());
		if (i != NULL) {
			return DGCS_NOSCAN;  // match
		}
	}

	// exceptionvirussitelist
	tempurl = domain;
#ifdef DGDEBUG
	std::cout<<"domain: "<<domain<<std::endl;
#endif
	while (tempurl.contains(".")) {
		i = exceptionvirussitelist.findInList(tempurl.toCharArray());
		if (i != NULL) {
			return DGCS_NOSCAN;  // exact match
		}
		tempurl = tempurl.after(".");  // check for being in higher level domains
	}
	if (tempurl.length() > 1) {	// allows matching of .tld
		tempurl = "." + tempurl;
		i = exceptionvirussitelist.findInList(tempurl.toCharArray());
		if (i != NULL) {
			return DGCS_NOSCAN;  // exact match
		}
	}

	// exceptionvirusurllist
	tempurl = domain + path;
	if (tempurl.endsWith("/")) {
		tempurl.chop();  // chop off trailing / if any
	}
	while (tempurl.before("/").contains(".")) {
		i = exceptionvirusurllist.findStartsWith(tempurl.toCharArray());
		if (i != NULL) {
			foundurl = i;
			fl = foundurl.length();
			if (tempurl.length() > fl) {
				unsigned char c = tempurl[fl];
				if (c == '/' || c == '?' || c == '&' || c == '=') {
					return DGCS_NOSCAN;  // matches /blah/ or /blah/foo but not /blahfoo
				}
			} else {
				return DGCS_NOSCAN;  // exact match
			}
		}
		tempurl = tempurl.after(".");  // check for being in higher level domains
	}

#ifdef DGDEBUG
	std::cout << "URL " << url << " is going to need AV scanning." << std::endl;
#endif

	return DGCS_NEEDSCAN;
}
Пример #21
0
// default method for deciding whether we will handle a request
bool DMPlugin::willHandle(HTTPHeader *requestheader, HTTPHeader *docheader)
{
	// match user agent first (quick)
	if (!(alwaysmatchua || ua_match.match(requestheader->userAgent().toCharArray())))
		return false;
	
	// then check standard lists (mimetypes & extensions)

	// mimetypes
	String mimetype("");
	bool matchedmime = false;
	if (mimelistenabled) {
		mimetype = docheader->getContentType();
#ifdef DGDEBUG
		std::cout<<"mimetype: "<<mimetype<<std::endl;
#endif
		if (mimetypelist.findInList(mimetype.toCharArray()) == NULL) {
			if (!extensionlistenabled)
				return false;
		} else
			matchedmime = true;
	}
	
	if (extensionlistenabled && !matchedmime) {
		// determine the extension
		String path(requestheader->decode(requestheader->url()));
		path.removeWhiteSpace();
		path.toLower();
		path.removePTP();
		path = path.after("/");
		path.hexDecode();
		path.realPath();
		String disposition(docheader->disposition());
		String extension;
		if (disposition.length() > 2) {
			extension = disposition;
			while (extension.contains(".")) {
				extension = extension.after(".");
			}
			extension = "." + extension;
		} else {
			if (!path.contains("?")) {
				extension = path;
			}
			else {
				if (mimetype.length() == 0)
					mimetype = docheader->getContentType();
				if (mimetype.contains("application/")) {
					extension = path;
					if (extension.contains("?")) {
						extension = extension.before("?");
					}
				}
			}
		}
	#ifdef DGDEBUG
		std::cout<<"extension: "<<extension<<std::endl;
	#endif
		// check the extension list
		if (!extension.contains(".") || (extensionlist.findEndsWith(extension.toCharArray()) == NULL))
				return matchedmime;
	}

	return true;
}
Пример #22
0
void nuiMimeMultiPart::Dump(nglOStream* pStream)
{
  nglString varname(_T("MyParam"));
  nglString value(_T("MyValue"));
  
  nglString fileref(_T("MyFile"));
  nglString filename(_T("prout.txt"));
  //  nglString filename(_T(""));
  
  nglString mimetype("plain/text");
  const uint8* data = (const uint8*)"YATTA!";
  uint32 datalen = strlen((const char*)data);
  //////////////////////////////////////
  
  nglString str;

  // prepare start and end boundaries:
  nglString start;
  start.CFormat(_T("--%s"), mBoundary.GetChars());
  
  nglString end;
  end.Add(_T("\n"));
  end.Add(start);
  end.Add(_T("--\n"));
  start.Add(_T("\n"));
  
  
  {
    std::map<nglString, nglString>::const_iterator it = mVariables.begin();
    std::map<nglString, nglString>::const_iterator end = mVariables.end();
    while (it != end)
    {
      pStream->WriteText(start);
      
      str.CFormat(_T("Content-Disposition: form-data; name=\"%s\"\n\n"), it->first.GetChars());
      pStream->WriteText(str);
      pStream->WriteText(it->second);
      pStream->WriteText(_T("\n"));
      
      ++it;
    }
  }

  {  
    for (uint32 i = 0; i < mpFiles.size(); i++)
    {
      pStream->WriteText(start);
      str.CFormat(_T("Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\n"), mpFiles[i]->mVarName.GetChars(), mpFiles[i]->mFileName.GetChars());
      pStream->WriteText(str);
      str.CFormat(_T("Content-Transfer-Encoding: %s\n"), mpFiles[i]->mContentTransfertEncoding.GetChars());
      pStream->WriteText(str);
      str.CFormat(_T("Content-Type: %s\n\n"), mpFiles[i]->mType.GetChars());
      pStream->WriteText(str);
      pStream->WriteUInt8(&mpFiles[i]->mContents[0], mpFiles[i]->mContents.size());
    }
  }

  if (mVariables.empty() && mpFiles.empty())
    pStream->WriteText(start);
    
  pStream->WriteText(end);
  
  
  //mem.WriteUInt8((const uint8*)"\0", 1); // Add final 0 for printf
  //nglString enc(mem.GetBufferData(),  mem.GetSize());
  //NGL_OUT(_T("Mime encoded:\n%s\n"), enc.GetChars());
}