void Browser::doHTTPRequest(const KURL& url)
{
  initHTTPCommunication();

  kdDebug() << "HTTP request \"" << url.path() + url.query() <<  "\" from " << url.host() << endl;

  m_http->setHost(url.host());
  m_http->get(url.path() + url.query());
}
static String resourceName(const KURL& url)
{
    String name = url.path();
    if (name.isEmpty())
        name = "/";
    if (!url.query().isNull())
        name += "?" + url.query();
    ASSERT(!name.isEmpty());
    ASSERT(!name.contains(' '));
    return name;
}
Exemple #3
0
static String resourceName(const KURL& url)
{
    StringBuilder name;
    name.append(url.path());
    if (name.isEmpty())
        name.append('/');
    if (!url.query().isNull()) {
        name.append('?');
        name.append(url.query());
    }
    String result = name.toString();
    ASSERT(!result.isEmpty());
    ASSERT(!result.contains(' '));
    return result;
}
Exemple #4
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 #5
0
/**
 * Test if the url contains a directory or a file.
 */
void LDAPProtocol::stat( const KURL &_url )
{
  kdDebug(7125) << "stat(" << _url << ")" << endl;

  TQStringList att,saveatt;
  LDAPUrl usrc(_url);
  LDAPMessage *msg;
  int ret, id;
  
  changeCheck( usrc );
  if ( !mLDAP ) {
    finished();
    return;
  }
  
  // look how many entries match
  saveatt = usrc.attributes();
  att.append( "dn" );
  usrc.setAttributes( att );
  if ( _url.query().isEmpty() ) usrc.setScope( LDAPUrl::One );
  
  if ( (id = asyncSearch( usrc )) == -1 ) {
    LDAPErr( _url );
    return;
  }
  
  kdDebug(7125) << "stat() getting result" << endl;
  do {
    ret = ldap_result( mLDAP, id, 0, NULL, &msg );
    if ( ret == -1 ) {
      LDAPErr( _url );
      return;
    }
    if ( ret == LDAP_RES_SEARCH_RESULT ) {
      ldap_msgfree( msg );
      error( ERR_DOES_NOT_EXIST, _url.prettyURL() );
      return;
    }
  } while ( ret != LDAP_RES_SEARCH_ENTRY );
  
  ldap_msgfree( msg );
  ldap_abandon( mLDAP, id );
  
  usrc.setAttributes( saveatt );
  
  UDSEntry uds;  
  bool critical;
  LDAPEntry2UDSEntry( usrc.dn(), uds, usrc, usrc.extension("x-dir", critical) != "base" );
  
  statEntry( uds );
  // we are done
  finished();
}
Exemple #6
0
void Groupwise::get(const KURL &url)
{
    kdDebug(7000) << "Groupwise::get()" << endl;
    kdDebug(7000) << " URL: " << url.url() << endl;
#if 1
    kdDebug(7000) << " Path: " << url.path() << endl;
    kdDebug(7000) << " Query: " << url.query() << endl;
    kdDebug(7000) << " Protocol: " << url.protocol() << endl;
    kdDebug(7000) << " Filename: " << url.filename() << endl;
#endif

    mimeType("text/plain");

    QString path = url.path();
    debugMessage("Path: " + path);

    if(path.contains("/freebusy"))
    {
        getFreeBusy(url);
    }
    else if(path.contains("/calendar"))
    {
        getCalendar(url);
    }
    else if(path.contains("/addressbook"))
    {
        if(url.query().contains("update=true"))
            updateAddressbook(url);
        else
            getAddressbook(url);
    }
    else
    {
        QString error = i18n("Unknown path. Known paths are '/freebusy/', "
                             "'/calendar/' and '/addressbook/'.") + QString(" path was %1").arg(url.url());
        errorMessage(error);
    }

    kdDebug(7000) << "Groupwise::get() done" << endl;
}
Exemple #7
0
/*
        bundle->setUrl( Amarok::QStringx("http://%1:3689/databases/%2/items/%3.%4?%5").args(
            QStringList() << m_host
                        << m_databaseId
                        << QString::number( (*it).asMap()["miid"].asList()[0].asInt() )
                        << (*it).asMap()["asfm"].asList()[0].asString()
                        << m_loginString ) );

*/
Proxy::Proxy(KURL stream, DaapClient* client, const char* name)
    : QObject(client, name)
    , m_proxy( new Amarok::ProcIO() )
{
    DEBUG_BLOCK
    //find the request id and increment it
    const QString hostKey = stream.host() + ':' + QString::number(stream.port());
    const int revisionId = client->incRevision( hostKey );
    const int sessionId = client->getSession( hostKey );
    //compose URL
    KURL realStream = realStreamUrl( stream, sessionId );

    //get hash
    char hash[33] = {0};
    GenerateHash( 3
        , reinterpret_cast<const unsigned char*>((realStream.path() + realStream.query()).ascii())
        , 2
        , reinterpret_cast<unsigned char*>(hash)
        , revisionId );

    // Find free port
    MyServerSocket* socket = new MyServerSocket();
    const int port = socket->port();
    debug() << "Proxy server using port: " << port << endl;
    delete socket;
    m_proxyUrl = KURL( QString("http://localhost:%1/daap.mp3").arg( port ) );
    //start proxy
    m_proxy->setComm( KProcess::Communication( KProcess::AllOutput ) );
    *m_proxy << "amarok_proxy.rb";
    *m_proxy << "--daap";
    *m_proxy << QString::number( port );
    *m_proxy << realStream.url();
    *m_proxy << AmarokConfig::soundSystem();
    *m_proxy << hash;
    *m_proxy << QString::number( revisionId );
    *m_proxy << Amarok::proxyForUrl( realStream.url() );

    if( !m_proxy->start( KProcIO::NotifyOnExit, true ) ) {
        error() << "Failed to start amarok_proxy.rb" << endl;
        return;
    }

    QString line;
    while( true ) {
        kapp->processEvents();
        m_proxy->readln( line );
        if( line == "AMAROK_PROXY: startup" ) break;
    }
    debug() << "started amarok_proxy.rb --daap " << QString::number( port ) << ' ' << realStream.url() << ' ' << AmarokConfig::soundSystem() << ' ' << hash << ' ' << revisionId << endl;
    connect( m_proxy, SIGNAL( processExited( KProcess* ) ), this, SLOT( playbackStopped() ) );
    connect( m_proxy, SIGNAL( readReady( KProcIO* ) ), this, SLOT( readProxy() ) );
}
bool ReadWritePart::saveAs( const KURL & kurl )
{
    if ( kurl.isMalformed() || !kurl.isLocalFile() || !kurl.query().isEmpty() )
    {
	KMessageBox::sorry( widget(), i18n( "Can save only to local files." ) );
	return false;
    }

    if ( QFile::exists( kurl.path() ) &&
	 KMessageBox::warningYesNo( widget(),
	    i18n( "Overwrite existing file ?" ) ) != KMessageBox::Yes )
	return false;

    ReadOnlyPart::closeURL();
    m_url = kurl;
    m_file = m_url.path();
    emit setWindowCaption( m_url.prettyURL() );
    return save();
}
Exemple #9
0
static void appendMailtoPostFormDataToURL(KURL& url, const FormData& data, const String& encodingType)
{
    String body = data.flattenToString();

    if (equalIgnoringCase(encodingType, "text/plain")) {
        // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are encoded as %20.
        body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' ') + "\r\n");
    }

    Vector<char> bodyData;
    bodyData.append("body=", 5);
    FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8());
    body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20");

    String query = url.query();
    if (!query.isEmpty())
        query.append('&');
    query.append(body);
    url.setQuery(query);
}
Exemple #10
0
void HelpProtocol::get(const KURL &url)
{
    kdDebug(7119) << "get: path=" << url.path() << " query=" << url.query() << endl;

    bool redirect;
    QString doc;
    doc = url.path();

    if(!mGhelp)
    {
        if(doc.at(0) != '/')
            doc = doc.prepend('/');

        if(doc.at(doc.length() - 1) == '/')
            doc += "index.html";
    }

    infoMessage(i18n("Looking up correct file"));

    if(!mGhelp)
    {
        doc = lookupFile(doc, url.query(), redirect);

        if(redirect)
        {
            finished();
            return;
        }
    }

    if(doc.isEmpty())
    {
        error(KIO::ERR_DOES_NOT_EXIST, url.url());
        return;
    }

    mimeType("text/html");
    KURL target;
    target.setPath(doc);
    if(url.hasHTMLRef())
        target.setHTMLRef(url.htmlRef());

    kdDebug(7119) << "target " << target.url() << endl;

    QString file = target.path();

    if(mGhelp)
    {
        if(file.right(4) != ".xml")
        {
            get_file(target);
            return;
        }
    }
    else
    {
        QString docbook_file = file.left(file.findRev('/')) + "/index.docbook";
        if(!KStandardDirs::exists(file))
        {
            file = docbook_file;
        }
        else
        {
            QFileInfo fi(file);
            if(fi.isDir())
            {
                file = file + "/index.docbook";
            }
            else
            {
                if(file.right(5) != ".html" || !compareTimeStamps(file, docbook_file))
                {
                    get_file(target);
                    return;
                }
                else
                    file = docbook_file;
            }
        }
    }

    infoMessage(i18n("Preparing document"));

    if(mGhelp)
    {
        QString xsl = "customization/kde-nochunk.xsl";
        mParsed = transform(file, locate("dtd", xsl));

        kdDebug(7119) << "parsed " << mParsed.length() << endl;

        if(mParsed.isEmpty())
        {
            unicodeError(i18n("The requested help file could not be parsed:<br>%1").arg(file));
        }
        else
        {
            int pos1 = mParsed.find("charset=");
            if(pos1 > 0)
            {
                int pos2 = mParsed.find('"', pos1);
                if(pos2 > 0)
                {
                    mParsed.replace(pos1, pos2 - pos1, "charset=UTF-8");
                }
            }
            data(mParsed.utf8());
        }
    }
    else
    {

        kdDebug(7119) << "look for cache for " << file << endl;

        mParsed = lookForCache(file);

        kdDebug(7119) << "cached parsed " << mParsed.length() << endl;

        if(mParsed.isEmpty())
        {
            mParsed = transform(file, locate("dtd", "customization/kde-chunk.xsl"));
            if(!mParsed.isEmpty())
            {
                infoMessage(i18n("Saving to cache"));
                QString cache = file.left(file.length() - 7);
                saveToCache(mParsed, locateLocal("cache", "kio_help" + cache + "cache.bz2"));
            }
        }
        else
            infoMessage(i18n("Using cached version"));

        kdDebug(7119) << "parsed " << mParsed.length() << endl;

        if(mParsed.isEmpty())
        {
            unicodeError(i18n("The requested help file could not be parsed:<br>%1").arg(file));
        }
        else
        {
            QString query = url.query(), anchor;

            // if we have a query, look if it contains an anchor
            if(!query.isEmpty())
                if(query.left(8) == "?anchor=")
                {
                    anchor = query.mid(8).lower();

                    KURL redirURL(url);

                    redirURL.setQuery(QString::null);
                    redirURL.setHTMLRef(anchor);
                    redirection(redirURL);
                    finished();
                    return;
                }
            if(anchor.isEmpty() && url.hasHTMLRef())
                anchor = url.htmlRef();

            kdDebug(7119) << "anchor: " << anchor << endl;

            if(!anchor.isEmpty())
            {
                int index = 0;
                while(true)
                {
                    index = mParsed.find(QRegExp("<a name="), index);
                    if(index == -1)
                    {
                        kdDebug(7119) << "no anchor\n";
                        break; // use whatever is the target, most likely index.html
                    }

                    if(mParsed.mid(index, 11 + anchor.length()).lower() == QString("<a name=\"%1\">").arg(anchor))
                    {
                        index = mParsed.findRev("<FILENAME filename=", index) + strlen("<FILENAME filename=\"");
                        QString filename = mParsed.mid(index, 2000);
                        filename = filename.left(filename.find('\"'));
                        QString path = target.path();
                        path = path.left(path.findRev('/') + 1) + filename;
                        kdDebug(7119) << "anchor found in " << path << endl;
                        target.setPath(path);
                        break;
                    }
                    index++;
                }
            }
            emitFile(target);
        }
    }

    finished();
}
Exemple #11
0
// get() called when a file is to be read
void MacProtocol::get(const KURL &url)
{
    QString path = prepareHP(url); // mount and change to correct directory - return the filename
    QString query = url.query();
    QString mode("-");
    QString mime;
    processedBytes = 0;

    // Find out the size and if it's a text file
    UDSEntry entry = doStat(url);
    UDSEntry::Iterator it;
    for(it = entry.begin(); it != entry.end(); ++it)
    {
        if((*it).m_uds == KIO::UDS_MIME_TYPE)
        {
            mime = (*it).m_str;
        }
        if((*it).m_uds == KIO::UDS_SIZE)
        {
            totalSize((*it).m_long);
        }
    }

    // find out if a mode has been specified in the query e.g. ?mode=t
    // or if it's a text file then set the mode to text
    int modepos = query.find("mode=");
    int textpos = mime.find("text");
    if(modepos != -1)
    {
        mode += query.mid(modepos + 5, 1);
        if(mode != "-r" && mode != "-b" && mode != "-m" && mode != "-t" && mode != "-a")
        {
            error(ERR_SLAVE_DEFINED, i18n("Unknown mode"));
        }
    }
    else if(textpos != -1)
    {
        mode += "t";
    }
    else
    {
        mode += "r";
    }

    // now we can read the file
    myKProcess = new KProcess();

    *myKProcess << "hpcopy" << mode << path << "-";

    // data is now sent directly from the slot
    connect(myKProcess, SIGNAL(receivedStdout(KProcess *, char *, int)), this, SLOT(slotSetDataStdOutput(KProcess *, char *, int)));

    myKProcess->start(KProcess::Block, KProcess::All);

    if(!myKProcess->normalExit() || !(myKProcess->exitStatus() == 0))
    {
        error(ERR_SLAVE_DEFINED, i18n("There was an error with hpcopy - please ensure it is installed"));
        return;
    }

    // clean up
    delete myKProcess;
    myKProcess = 0;
    // finish
    data(QByteArray());
    finished();
}
void ResourceHandleManager::initializeHandle(ResourceHandle* job)
{
    KURL kurl = job->request().url();

    // Remove any fragment part, otherwise curl will send it as part of the request.
    kurl.setRef("");

    ResourceHandleInternal* d = job->getInternal();
    String url = kurl.string();

    if (kurl.isLocalFile()) {
        String query = kurl.query();
        // Remove any query part sent to a local file.
        if (!query.isEmpty())
            url = url.left(url.find(query));
        // Determine the MIME type based on the path.
        d->m_response.setMimeType(MIMETypeRegistry::getMIMETypeForPath(url));
    }

    d->m_handle = curl_easy_init();
#ifndef NDEBUG
    if (getenv("DEBUG_CURL"))
        curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1);
#endif
    curl_easy_setopt(d->m_handle, CURLOPT_PRIVATE, job);
    curl_easy_setopt(d->m_handle, CURLOPT_ERRORBUFFER, m_curlErrorBuffer);
    curl_easy_setopt(d->m_handle, CURLOPT_WRITEFUNCTION, writeCallback);
    curl_easy_setopt(d->m_handle, CURLOPT_WRITEDATA, job);
    curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback);
    curl_easy_setopt(d->m_handle, CURLOPT_WRITEHEADER, job);
    curl_easy_setopt(d->m_handle, CURLOPT_AUTOREFERER, 1);
    curl_easy_setopt(d->m_handle, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10);
    curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_easy_setopt(d->m_handle, CURLOPT_SHARE, m_curlShareHandle);
    curl_easy_setopt(d->m_handle, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 5); // 5 minutes
    // FIXME: Enable SSL verification when we have a way of shipping certs
    // and/or reporting SSL errors to the user.
    if (ignoreSSLErrors)
        curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false);
    // enable gzip and deflate through Accept-Encoding:
    curl_easy_setopt(d->m_handle, CURLOPT_ENCODING, "");

    // url must remain valid through the request
    ASSERT(!d->m_url);

    // url is in ASCII so latin1() will only convert it to char* without character translation.
    d->m_url = strdup(url.latin1().data());
    curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url);

    if (m_cookieJarFileName) {
        curl_easy_setopt(d->m_handle, CURLOPT_COOKIEFILE, m_cookieJarFileName);
        curl_easy_setopt(d->m_handle, CURLOPT_COOKIEJAR, m_cookieJarFileName);
    }

    struct curl_slist* headers = 0;
    if (job->request().httpHeaderFields().size() > 0) {
        HTTPHeaderMap customHeaders = job->request().httpHeaderFields();
        HTTPHeaderMap::const_iterator end = customHeaders.end();
        for (HTTPHeaderMap::const_iterator it = customHeaders.begin(); it != end; ++it) {
            String key = it->first;
            String value = it->second;
            String headerString(key);
            headerString.append(": ");
            headerString.append(value);
            CString headerLatin1 = headerString.latin1();
            headers = curl_slist_append(headers, headerLatin1.data());
        }
    }

    if ("GET" == job->request().httpMethod())
        curl_easy_setopt(d->m_handle, CURLOPT_HTTPGET, TRUE);
    else if ("POST" == job->request().httpMethod())
        setupPOST(job, &headers);
    else if ("PUT" == job->request().httpMethod())
        setupPUT(job, &headers);
    else if ("HEAD" == job->request().httpMethod())
        curl_easy_setopt(d->m_handle, CURLOPT_NOBODY, TRUE);

    if (headers) {
        curl_easy_setopt(d->m_handle, CURLOPT_HTTPHEADER, headers);
        d->m_customHeaders = headers;
    }
}
Exemple #13
0
void Groupwise::getAddressbook(const KURL &url)
{
    QString u = soapUrl(url);

    QString user = url.user();
    QString pass = url.pass();

    debugMessage("URL: " + u);
    debugMessage("User: "******"Password: "******"?")
    {
        errorMessage(i18n("No addressbook IDs given."));
    }
    else
    {
        QStringList ids;

        query = query.mid(1);
        QStringList queryItems = QStringList::split("&", query);
        QStringList::ConstIterator it;
        for(it = queryItems.begin(); it != queryItems.end(); ++it)
        {
            QStringList item = QStringList::split("=", (*it));
            if(item.count() == 2 && item[ 0 ] == "addressbookid")
            {
                ids.append(item[ 1 ]);
            }
        }

        debugMessage("IDs: " + ids.join(","));

        GroupwiseServer server(u, user, pass, 0);

        connect(&server, SIGNAL(readAddressBookTotalSize(int)),
                SLOT(slotReadAddressBookTotalSize(int)));
        connect(&server, SIGNAL(readAddressBookProcessedSize(int)),
                SLOT(slotReadAddressBookProcessedSize(int)));
        connect(&server, SIGNAL(errorMessage(const QString &, bool)),
                SLOT(slotServerErrorMessage(const QString &, bool)));
        connect(&server, SIGNAL(gotAddressees(const KABC::Addressee::List)),
                SLOT(slotReadReceiveAddressees(const KABC::Addressee::List)));

        kdDebug() << "Login" << endl;
        if(!server.login())
        {
            errorMessage(i18n("Unable to login: "******"Read Addressbook" << endl;
            if(!server.readAddressBooksSynchronous(ids))
            {
                errorMessage(i18n("Unable to read addressbook data: ") + server.errorText());
            }
            kdDebug() << "Logout" << endl;
            server.logout();
            finished();
        }
    }
}
Exemple #14
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 #15
0
void Groupwise::updateAddressbook(const KURL &url)
{
    kdDebug() << "Groupwise::updateAddressbook() " << url << endl;
    QString u = soapUrl(url);

    QString user = url.user();
    QString pass = url.pass();

    debugMessage("update AB URL: " + u);
    debugMessage("update AB User: "******"update AB Password: "******"?")
    {
        errorMessage(i18n("No addressbook IDs given."));
        return;
    }
    else
    {
        QStringList ids;

        query = query.mid(1);
        QStringList queryItems = QStringList::split("&", query);
        QStringList::ConstIterator it;
        for(it = queryItems.begin(); it != queryItems.end(); ++it)
        {
            QStringList item = QStringList::split("=", (*it));
            if(item.count() == 2 && item[ 0 ] == "addressbookid")
            {
                ids.append(item[ 1 ]);
            }
            if(item.count() == 2 && item[ 0 ] == "lastSeqNo")
                lastSequenceNumber = item[ 1 ].toULong();
            if(item.count() == 2 && item[ 0 ] == "PORebuildTime")
                lastPORebuildTime = item[ 1 ].toULong();
        }

        debugMessage("update IDs: " + ids.join(","));

        GroupwiseServer server(u, user, pass, 0);
        connect(&server, SIGNAL(errorMessage(const QString &, bool)),
                SLOT(slotServerErrorMessage(const QString &, bool)));
        connect(&server, SIGNAL(gotAddressees(const KABC::Addressee::List)),
                SLOT(slotReadReceiveAddressees(const KABC::Addressee::List)));

        kdDebug() << "  Login" << endl;
        if(!server.login())
        {
            errorMessage(i18n("Unable to login: "******"  Updating Addressbook" << endl;
            if(!server.updateAddressBooks(ids, lastSequenceNumber + 1, lastPORebuildTime))
            {
                error(KIO::ERR_NO_CONTENT, server.errorText());
                //errorMessage( i18n("Unable to update addressbook data: ") + server.errorText() );
            }
            kdDebug() << "  Logout" << endl;
            server.logout();
            finished();
        }
    }
}
String DOMURLUtilsReadOnly::search(const KURL& kurl)
{
    String query = kurl.query();
    return query.isEmpty() ? emptyString() : "?" + query;
}
Exemple #17
0
/**
 * List the contents of a directory.
 */
void LDAPProtocol::listDir( const KURL &_url )
{
  int ret, ret2, id, id2;
  unsigned long total=0;
  char *dn;
  TQStringList att,saveatt;
  LDAPMessage *entry,*msg,*entry2,*msg2;
  LDAPUrl usrc(_url),usrc2;
  bool critical;
  bool isSub = ( usrc.extension( "x-dir", critical ) == "sub" );
  
  kdDebug(7125) << "listDir(" << _url << ")" << endl;
  
  changeCheck( usrc );
  if ( !mLDAP ) {
    finished();
    return;
  }
  usrc2 = usrc;

  saveatt = usrc.attributes();
  // look up the entries
  if ( isSub ) {
    att.append("dn");
    usrc.setAttributes(att);  
  }
  if ( _url.query().isEmpty() ) usrc.setScope( LDAPUrl::One );
  
  if ( (id = asyncSearch( usrc )) == -1 ) {
    LDAPErr( _url );
    return;
  }

  usrc.setAttributes( "" );
  usrc.setExtension( "x-dir", "base" );
  // publish the results
  UDSEntry uds;

  while( true ) {
    ret = ldap_result( mLDAP, id, 0, NULL, &msg );
    if ( ret == -1 ) {
      LDAPErr( _url );
      return;
    }
    if ( ret == LDAP_RES_SEARCH_RESULT ) break;
    if ( ret != LDAP_RES_SEARCH_ENTRY ) continue;
    kdDebug(7125) << " ldap_result: " << ret << endl;
    
    entry = ldap_first_entry( mLDAP, msg );
    while( entry ) {
  
      total++;
      uds.clear();
    
      dn = ldap_get_dn( mLDAP, entry );
      kdDebug(7125) << "dn: " << dn  << endl;
      LDAPEntry2UDSEntry( TQString::fromUtf8(dn), uds, usrc );
      listEntry( uds, false );
//      processedSize( total );
      kdDebug(7125) << " total: " << total << " " << usrc.prettyURL() << endl;
    
    // publish the sub-directories (if dirmode==sub)
      if ( isSub ) {
        usrc2.setDn( TQString::fromUtf8( dn ) );
        usrc2.setScope( LDAPUrl::One );
        usrc2.setAttributes( att );
        usrc2.setFilter( TQString::null );
        kdDebug(7125) << "search2 " << dn << endl;
        if ( (id2 = asyncSearch( usrc2 )) != -1 ) {
          while ( true ) {
            kdDebug(7125) << " next result " << endl;
            ret2 = ldap_result( mLDAP, id2, 0, NULL, &msg2 );
            if ( ret2 == -1 ) break;
            if ( ret2 == LDAP_RES_SEARCH_RESULT ) {
              ldap_msgfree( msg2 );
              break;
            }
            if ( ret2 == LDAP_RES_SEARCH_ENTRY ) {
              entry2=ldap_first_entry( mLDAP, msg2 );
              if  ( entry2 ) {
                usrc2.setAttributes( saveatt );
                usrc2.setFilter( usrc.filter() );
                LDAPEntry2UDSEntry( TQString::fromUtf8( dn ), uds, usrc2, true );
                listEntry( uds, false );
                total++;
              }
              ldap_msgfree( msg2 );
              ldap_abandon( mLDAP, id2 );
              break;
            }
          }
        }
      }
      free( dn );
    
      entry = ldap_next_entry( mLDAP, entry );
    }
    LDAPErr( _url );
    ldap_msgfree( msg );
  }
  
//  totalSize( total );
  
  uds.clear();
  listEntry( uds, true );
  // we are done
  finished();
}