예제 #1
0
/*!
    Constructs a QMimeType from a \a fileName.
*/
QMimeType QMimeType::fromFileName( const QString &fileName )
{
    QMimeType type;

    int slashIndex = fileName.lastIndexOf( QLatin1Char( '/' ) );

    int dotIndex = fileName.lastIndexOf( QLatin1Char( '.' ) );

    if( dotIndex > slashIndex )
    {
        if(loadedTimes()->count() == 0)
            loadExtensions();
        QString extension = fileName.mid( dotIndex + 1 ).toLower();

        type.mimeId = typeFor()->value( extension );
    }

    if( type.mimeId.isEmpty() )
    {
        const char elfMagic[] = { '\177', 'E', 'L', 'F', '\0' };

        QFile ef( fileName );

        if ( ef.size() > 5 && ef.open( QIODevice::ReadOnly ) && ef.peek(5) == elfMagic)  // try to find from magic
            type.mimeId = QLatin1String("application/x-executable");  // could be a shared library or an exe
        else
            type.mimeId = QLatin1String("application/octet-stream");
    }

    return type;
}
예제 #2
0
/*!
    \internal
    Clears out the internal structures, to force a reload of the information.
*/
void QMimeType::clear()
{
    QMutexLocker staticsGuard(&staticsGuardMutex);
    extFor()->clear();
    typeFor()->clear();
    loadedTimes()->clear();
    mimeTypeDataCache()->clear();
}
예제 #3
0
/*!
    Constructs a QMimeType from a file \a extension.

    To note, do not include the period.
*/
QMimeType QMimeType::fromExtension( const QString &extension )
{
    if(loadedTimes()->count() == 0)
        loadExtensions();

    QMimeType type;

    type.mimeId = typeFor()->value( extension.toLower() );

    return type;
}
예제 #4
0
/*!
    Returns the string mime type based on the filename \a filename.
*/
QString QMail::mimeTypeFromFileName(const QString& filename)
{
    if (filename.isEmpty())
        return QString();

    loadExtensions();

    // do a case insensitive search for a known mime type.
    QString lwrExtOrId = filename.toLower();
    QHash<QString,QStringList>::const_iterator it = extFor()->find(lwrExtOrId);
    if (it != extFor()->end()) {
        return lwrExtOrId;
    }

    // either it doesnt have exactly one mime-separator, or it has
    // a path separator at the beginning
    QString mime_sep = QLatin1String("/");
    bool doesntLookLikeMimeString = (filename.count(mime_sep) != 1) || (filename[0] == QDir::separator());

    if (doesntLookLikeMimeString || QFile::exists(filename)) {
        int dot = filename.lastIndexOf('.');
        QString ext = dot >= 0 ? filename.mid(dot+1) : filename;

        QHash<QString,QString>::const_iterator it = typeFor()->find(ext.toLower());
        if (it != typeFor()->end()) {
            return *it;
        }

        const char elfMagic[] = { '\177', 'E', 'L', 'F', '\0' };
        QFile ef(filename);
        if (ef.exists() && (ef.size() > 5) && ef.open(QIODevice::ReadOnly) && (ef.peek(5) == elfMagic)) { // try to find from magic
            return QLatin1String("application/x-executable");  // could be a shared library or an exe
        } else {
            return QLatin1String("application/octet-stream");
        }
    }

    // could be something like application/vnd.oma.rights+object
    return lwrExtOrId;
}
예제 #5
0
/*!
    \internal
    Loads the mime type to extensions mapping
*/
static void loadExtensions()
{
    QMutex mutex;
    mutex.lock();
    static bool loaded = false;

    if(loaded)
    {
        mutex.unlock();
        return;
    }

    QFile file(":qtopiamail/mime.types");
    if ( file.open(QIODevice::ReadOnly) ) {
        char line[1024];

        while (file.readLine(line, sizeof(line)) > 0) {
            if (line[0] == '\0' || line[0] == '#')
                continue;
            int posn = 0;
            QString id = nextString(line, posn);
            if ( id.isEmpty() )
                continue;
            id = id.toLower();

            QStringList exts = extFor()->value(id);

            for( QString ext = nextString( line, posn ); !ext.isEmpty(); ext = nextString(line, posn).toLower() )
            {
                if( !exts.contains( ext ) )
                {
                    exts.append( ext );

                    typeFor()->insert(ext, id);
                }
            }
            (*extFor())[ id ] = exts;
        }
        loaded = true;
    }
    mutex.unlock();
}
예제 #6
0
CFDictionaryRef PolicyEngine::update(CFTypeRef target, SecAssessmentFlags flags, CFDictionaryRef context)
{
	// update GKE
	installExplicitSet(gkeAuthFile, gkeSigsFile);

	AuthorityType type = typeFor(context, kAuthorityInvalid);
	CFStringRef edit = CFStringRef(CFDictionaryGetValue(context, kSecAssessmentContextKeyUpdate));
	CFDictionaryRef result;
	if (CFEqual(edit, kSecAssessmentUpdateOperationAdd))
		result = this->add(target, type, flags, context);
	else if (CFEqual(edit, kSecAssessmentUpdateOperationRemove))
		result = this->remove(target, type, flags, context);
	else if (CFEqual(edit, kSecAssessmentUpdateOperationEnable))
		result = this->enable(target, type, flags, context);
	else if (CFEqual(edit, kSecAssessmentUpdateOperationDisable))
		result = this->disable(target, type, flags, context);
	else if (CFEqual(edit, kSecAssessmentUpdateOperationFind))
		result = this->find(target, type, flags, context);
	else
		MacOSError::throwMe(errSecCSInvalidAttributeValues);
	if (result == NULL)
		result = makeCFDictionary(0);		// success, no details
	return result;
}