Exemple #1
0
AtomicURL::AtomicURL( const KURL &url )
{
    if( url.isEmpty() )
        return;

    QString s = url.protocol() + "://";
    QString host = url.host();
    if( url.hasUser() )
    {
        s += url.user();
        host.prepend("@");
    }
    if( url.hasPass() )
        s += ':' + url.pass();
    if( url.port() )
        host += QString(":") + QString::number( url.port() );

    m_beginning = s + host;
    m_directory = url.directory();
    m_filename = url.fileName();
    m_end = url.query();
    if( url.hasRef() )
        m_end += QString("#") + url.ref();
    if (url != this->url())
    {
        debug() << "from: " << url << endl;
        debug() << "to:   " << this->url() << endl;
    }
}
Exemple #2
0
void tdeio_isoProtocol::stat( const KURL & url )
{
    TQString path;
    UDSEntry entry;

    kdDebug() << "tdeio_isoProtocol::stat " << url.url() << endl;
    if ( !checkNewFile( url.path(), path, url.hasRef() ? url.htmlRef().toInt() : -1 ) )
    {
        // We may be looking at a real directory - this happens
        // when pressing up after being in the root of an archive
        TQCString _path( TQFile::encodeName(url.path()));
        kdDebug()  << "tdeio_isoProtocol::stat (stat) on " << _path << endl;
        struct stat buff;
        if ( ::stat( _path.data(), &buff ) == -1 || !S_ISDIR( buff.st_mode ) ) {
            kdDebug() << "isdir=" << S_ISDIR( buff.st_mode ) << "  errno=" << strerror(errno) << endl;
            error( TDEIO::ERR_DOES_NOT_EXIST, url.path() );
            return;
        }
        // Real directory. Return just enough information for KRun to work
        UDSAtom atom;
        atom.m_uds = TDEIO::UDS_NAME;
        atom.m_str = url.fileName();
        entry.append( atom );
        kdDebug()  << "tdeio_isoProtocol::stat returning name=" << url.fileName() << endl;

        atom.m_uds = TDEIO::UDS_FILE_TYPE;
        atom.m_long = buff.st_mode & S_IFMT;
        entry.append( atom );

        statEntry( entry );

        finished();

        // And let go of the iso file - for people who want to unmount a cdrom after that
        delete m_isoFile;
        m_isoFile = 0L;
        return;
    }

    const KArchiveDirectory* root = m_isoFile->directory();
    const KArchiveEntry* isoEntry;
    if ( path.isEmpty() )
    {
        path = TQString::fromLatin1( "/" );
        isoEntry = root;
    } else {
        isoEntry = root->entry( path );
    }
    if ( !isoEntry )
    {
        error( TDEIO::ERR_DOES_NOT_EXIST, path );
        return;
    }
    createUDSEntry( isoEntry, entry );
    statEntry( entry );
    finished();
}
Exemple #3
0
void filter(const char *u, const char *expectedResult = 0, int expectedUriType = -1, QStringList list = QStringList(), const char *abs_path = 0,
            bool checkForExecutables = true)
{
    QString a = QString::fromUtf8(u);
    KURIFilterData *m_filterData = new KURIFilterData;
    m_filterData->setData(a);
    m_filterData->setCheckForExecutables(checkForExecutables);

    if(abs_path)
    {
        m_filterData->setAbsolutePath(QString::fromLatin1(abs_path));
        kdDebug() << "Filtering: " << a << " with abs_path=" << abs_path << endl;
    }
    else
        kdDebug() << "Filtering: " << a << endl;

    if(KURIFilter::self()->filterURI(*m_filterData, list))
    {
        // Copied from minicli...
        QString cmd;
        KURL uri = m_filterData->uri();

        if(uri.isLocalFile() && !uri.hasRef() && uri.query().isEmpty())
            cmd = uri.path();
        else
            cmd = uri.url();

        switch(m_filterData->uriType())
        {
            case KURIFilterData::LOCAL_FILE:
            case KURIFilterData::LOCAL_DIR:
            case KURIFilterData::HELP:
                kdDebug() << "*** Result: Local Resource =>  '" << m_filterData->uri().url() << "'" << endl;
                break;
            case KURIFilterData::NET_PROTOCOL:
                kdDebug() << "*** Result: Network Resource => '" << m_filterData->uri().url() << "'" << endl;
                break;
            case KURIFilterData::SHELL:
            case KURIFilterData::EXECUTABLE:
                if(m_filterData->hasArgsAndOptions())
                    cmd += m_filterData->argsAndOptions();
                kdDebug() << "*** Result: Executable/Shell => '" << cmd << "'" << endl;
                break;
            case KURIFilterData::ERROR:
                kdDebug() << "*** Result: Encountered error. See reason below." << endl;
                break;
            default:
                kdDebug() << "*** Result: Unknown or invalid resource." << endl;
        }

        if(expectedUriType != -1 && expectedUriType != m_filterData->uriType())
        {
            kdError() << " Got URI type " << s_uritypes[m_filterData->uriType()] << " expected " << s_uritypes[expectedUriType] << endl;
            ::exit(1);
        }

        if(expectedResult)
        {
            // Hack for other locales than english, normalize google hosts to google.com
            cmd = cmd.replace(QRegExp("www\\.google\\.[^/]*/"), "www.google.com/");
            if(cmd != QString::fromLatin1(expectedResult))
            {
                kdError() << " Got " << cmd << " expected " << expectedResult << endl;
                ::exit(1);
            }
        }
    }
    else
    {
        if(expectedUriType == NO_FILTERING)
            kdDebug() << "*** No filtering required." << endl;
        else
        {
            kdDebug() << "*** Could not be filtered." << endl;
            if(expectedUriType != m_filterData->uriType())
            {
                kdError() << " Got URI type " << s_uritypes[m_filterData->uriType()] << " expected " << s_uritypes[expectedUriType] << endl;
                ::exit(1);
            }
        }
    }

    delete m_filterData;
    kdDebug() << "-----" << endl;
}
Exemple #4
0
void tdeio_isoProtocol::listDir( const KURL & url )
{
    kdDebug() << "tdeio_isoProtocol::listDir " << url.url() << endl;

    TQString path;
    if ( !checkNewFile( url.path(), path, url.hasRef() ? url.htmlRef().toInt() : -1 ) )
    {
        TQCString _path( TQFile::encodeName(url.path()));
        kdDebug()  << "Checking (stat) on " << _path << endl;
        struct stat buff;
        if ( ::stat( _path.data(), &buff ) == -1 || !S_ISDIR( buff.st_mode ) ) {
            error( TDEIO::ERR_DOES_NOT_EXIST, url.path() );
            return;
        }
        // It's a real dir -> redirect
        KURL redir;
        redir.setPath( url.path() );
        if (url.hasRef()) redir.setRef(url.htmlRef());
        kdDebug()  << "Ok, redirection to " << redir.url() << endl;
        redirection( redir );
        finished();
        // And let go of the iso file - for people who want to unmount a cdrom after that
        delete m_isoFile;
        m_isoFile = 0L;
        return;
    }

    if ( path.isEmpty() )
    {
        KURL redir( TQString::fromLatin1( "iso:/") );
        kdDebug() << "url.path()==" << url.path() << endl;
        if (url.hasRef()) redir.setRef(url.htmlRef());
        redir.setPath( url.path() + TQString::fromLatin1("/") );
        kdDebug() << "tdeio_isoProtocol::listDir: redirection " << redir.url() << endl;
        redirection( redir );
        finished();
        return;
    }

    kdDebug()  << "checkNewFile done" << endl;
    const KArchiveDirectory* root = m_isoFile->directory();
    const KArchiveDirectory* dir;
    if (!path.isEmpty() && path != "/")
    {
        kdDebug()   << TQString(TQString("Looking for entry %1").arg(path)) << endl;
        const KArchiveEntry* e = root->entry( path );
        if ( !e )
        {
            error( TDEIO::ERR_DOES_NOT_EXIST, path );
            return;
        }
        if ( ! e->isDirectory() )
        {
            error( TDEIO::ERR_IS_FILE, path );
            return;
        }
        dir = (KArchiveDirectory*)e;
    } else {
        dir = root;
    }

    TQStringList l = dir->entries();
    totalSize( l.count() );

    UDSEntry entry;
    TQStringList::Iterator it = l.begin();
    for( ; it != l.end(); ++it )
    {
        kdDebug()   << (*it) << endl;
        const KArchiveEntry* isoEntry = dir->entry( (*it) );

        createUDSEntry( isoEntry, entry );

        listEntry( entry, false );
    }

    listEntry( entry, true ); // ready

    finished();

    kdDebug()  << "tdeio_isoProtocol::listDir done" << endl;
}