+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-
-#ifndef ZYPP_QUERYPOOL_KEYRINGCALLBACKS_H
-#define ZYPP_QUERYPOOL_KEYRINGCALLBACKS_H
-
-#include <stdlib.h>
-#include <iostream>
-
-#include <zypp/base/Logger.h>
-#include <zypp/base/Sysconfig.h>
-#include <zypp/ZYppCallbacks.h>
-#include <zypp/Pathname.h>
-#include <zypp/KeyRing.h>
-#include <zypp/Digest.h>
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{
-///////////////////////////////////////////////////////////////////
-
-
-///////////////////////////////////////////////////////////////////
-// KeyRingReceive
-///////////////////////////////////////////////////////////////////
-struct KeyRingReceive : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
-{
- KeyRingReceive()
- {}
-
- virtual bool askUserToAcceptUnsignedFile( const std::string &file, const zypp::KeyContext &keycontext )
- {
- return true;
- }
- virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const zypp::KeyContext &keycontext )
- {
- return true;
- }
-
- virtual bool askUserAcceptKey( const PublicKey &key, const zypp::KeyContext &keycontext )
- {
- DBG << "By default zypp-query-pool does not import keys for now." << std::endl;
- return zypp::KeyRingReport::KEY_TRUST_TEMPORARILY;
- }
-
- virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const zypp::KeyContext &keycontext )
- {
- return true;
- }
-};
-
-
-struct DigestReceive : public zypp::callback::ReceiveReport<zypp::DigestReport>
-{
- DigestReceive()
- {}
-
- virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
- {
- return true;
- }
- virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
- {
- return true;
- }
- virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
- {
- // this smells like false
- return true;
- }
-};
-
-///////////////////////////////////////////////////////////////////
-}
-; // namespace zypp
-///////////////////////////////////////////////////////////////////
-
-class KeyRingCallbacks
-{
-
-private:
- zypp::KeyRingReceive _keyRingReport;
-
-public:
- KeyRingCallbacks()
- {
- _keyRingReport.connect();
- }
-
- ~KeyRingCallbacks()
- {
- _keyRingReport.disconnect();
- }
-
-};
-
-class DigestCallbacks
-{
-
-private:
- zypp::DigestReceive _digestReport;
-
-public:
- DigestCallbacks()
- {
- _digestReport.connect();
- }
-
- ~DigestCallbacks()
- {
- _digestReport.disconnect();
- }
-
-};
-
-
-#endif // ZMD_BACKEND_KEYRINGCALLBACKS_H
+++ /dev/null
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-
-#include <iostream>
-
-#include <zypp/ZYpp.h>
-#include <zypp/zypp_detail/ZYppReadOnlyHack.h>
-#include <zypp/parser/ProductConfReader.h>
-#include <zypp/ZYppFactory.h>
-#include <zypp/RepoManager.h>
-#include <zypp/base/Logger.h>
-#include <zypp/base/Exception.h>
-#include <zypp/base/Algorithm.h>
-#include <zypp/Product.h>
-#include <zypp/ResFilters.h>
-#include <zypp/PoolItem.h>
-
-#undef ZYPP_BASE_LOGGER_LOGGROUP
-#define ZYPP_BASE_LOGGER_LOGGROUP "zypp-query-pool"
-
-#include "keyring-callbacks.h"
-
-using namespace std;
-using namespace zypp;
-using namespace zypp::resfilter;
-
-struct ByPresent : public PoolItemFilterFunctor
-{
- bool operator()( const PoolItem & p ) const
- {
- if ( traits::isPseudoInstalled( p->kind() ) )
- return p.status().isSatisfied();
- else
- return p.status().isInstalled();
- }
-};
-
-
-//-----------------------------------------------------------------------------
-
-class PrintItem : public resfilter::PoolItemFilterFunctor
-{
-public:
- string _repository;
-
- PrintItem( const string & repository )
- : _repository( repository )
- { }
-
- bool operator()( PoolItem item )
- {
- if (_repository.empty()
- || _repository == item->repository().info().alias())
- {
-
- if ( traits::isPseudoInstalled( item->kind() ) )
- cout << (item.status().isSatisfied() ? "i" : " ");
- else
- cout << (item.status().isInstalled() ? "i" : " ");
-
- cout << "|" << item->kind();
- cout << "|" << item->name();
- cout << "|" << item->edition().version();
- if (!item->edition().release().empty())
- cout << "-" << item->edition().release();
- cout << "|" << item->arch();
- cout << endl;
- }
- return true;
- }
-};
-
-
-bool printAdditionalProducts( const zypp::parser::ProductConfData & d )
-{
- cout << str::form( "i|product|%s|%s|%s|%s|%s\n",
- d.name().c_str(),
- d.edition().c_str(),
- d.arch().c_str(),
- d.distName().c_str(),
- d.distEdition().c_str() );
- return true;
-}
-
-
-static void
-query_pool( ZYpp::Ptr Z,
- string filter,
- const string & repository,
- bool installed_only )
-{
- Resolvable::Kind kind;
-
-#define FILTER_ALL "all"
- if ( filter.empty() ) filter = FILTER_ALL;
-
- if (filter == "packages") kind = ResKind::package;
- else if (filter == "patches") kind = ResKind::patch;
- else if (filter == "patterns") kind = ResKind::pattern;
- else if (filter == "products") kind = ResKind::product;
- else if (filter != FILTER_ALL)
- {
- std::cerr << "usage: zypp-query-pool [--registrable|-r] [packages|patches|patterns|products] [<alias>]" << endl;
- exit( 1 );
- }
-
- MIL << "query_pool kind '" << kind << "', repository '" << repository << "'" << endl;
-
- try
- {
- MIL << "Load enabled repositories..." << endl;
- RepoManager repoManager;
- RepoInfoList repos = repoManager.knownRepositories();
- for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
- {
- RepoInfo & repo( *it );
-
- if ( ! repo.enabled() )
- continue;
-
- MIL << "Loading " << repo << endl;
- if ( ! repoManager.isCached( repo ) )
- {
- MIL << "Must build cache..." << repo << endl;
- repoManager.buildCache( repo );
- }
- repoManager.loadFromCache( repo );
- }
- MIL << "Loaded enabled repositories." << endl;
- }
- catch (Exception & excpt_r)
- {
- ZYPP_CAUGHT( excpt_r );
- ERR << "Couldn't restore sources" << endl;
- exit( 1 );
- }
-
-// add resolvables from the system
- MIL << "Loading target..." << endl;
- Z->target()->load();
-
- MIL << "Loaded target." << endl;
-
- MIL << "Pool has " << Z->pool().size() << " entries" << endl;
-
-// solve to get the status satisfied available
- getZYpp()->resolver()->setOnlyRequires( true );
- getZYpp()->resolver()->resolvePool();
-
- if ( filter == FILTER_ALL)
- {
- PrintItem printitem( repository );
- if (installed_only)
- zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
- ByPresent(),
- zypp::functor::functorRef<bool,PoolItem> (printitem) );
- else
- zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
- zypp::functor::functorRef<bool,PoolItem> (printitem) );
-
- }
- else
- {
- PrintItem printitem( repository );
- if (installed_only)
- zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
- ByPresent(),
- zypp::functor::functorRef<bool,PoolItem> (printitem) );
- else
- zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
- zypp::functor::functorRef<bool,PoolItem> (printitem) );
- }
-
- if ( installed_only
- && repository.empty()
- && ( filter == FILTER_ALL || filter == "products" ) )
- {
- // write out additional products from /etc/zypp/products.d
- // if -r is active and no repo filter is defined.
- zypp::parser::ProductConfReader::scanDir( &printAdditionalProducts,
- ZConfig::instance().productsPath() );
- }
-
- return;
-}
-
-//-----------------------------------------------------------------------------
-
-int
-main (int argc, char **argv)
-{
- MIL << "-------------------------------------" << endl;
- string filter;
- string repository;
- bool only_installed = false;
- int offset = 1;
-
- if ( (argc>1) && ( (string(argv[offset]) == "--registrable")
- || ( string(argv[offset]) == "-r" ) ) )
- {
- only_installed = true;
- ++offset; --argc;
- }
-
- if ( argc > 1 )
- {
- filter = argv[offset];
- --argc; ++offset;
-
- if ( argc > 1 )
- {
- repository = argv[offset];
- ++offset; --argc;
- }
- }
-
- MIL << "START zypp-query-pool " << filter << " " << repository << endl;
-
- zypp::zypp_readonly_hack::IWantIt();
- ZYpp::Ptr Z = zypp::getZYpp();
-
- KeyRingCallbacks keyring_callbacks;
- DigestCallbacks digest_callbacks;
-
- Z->initializeTarget( "/" );
-
- query_pool( Z, filter, repository, only_installed );
-
- MIL << "END zypp-query-pool, result 0" << endl;
-
- return 0;
-}
// check for credentials in Urls
bool havePasswords = false;
for_( urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd() )
- if ( !urlit->getUsername().empty() && !urlit->getPassword().empty() )
- { havePasswords = true; break; }
+ if ( urlit->hasCredentialsInAuthority() )
+ {
+ havePasswords = true;
+ break;
+ }
// save the credentials
if ( havePasswords )
{
media::CredManagerOptions(_pimpl->options.rootDir) );
for_(urlit, tosave.baseUrlsBegin(), tosave.baseUrlsEnd())
- if (!urlit->getPassword().empty() && !urlit->getUsername().empty())
+ if (urlit->hasCredentialsInAuthority())
//! \todo use a method calling UI callbacks to ask where to save creds?
cm.saveInUser(media::AuthData(*urlit));
}
-
+
HistoryLog().addRepository(tosave);
progress.toMax();
_pimpl->services.insert( toSave );
// check for credentials in Url (username:password, not ?credentials param)
- if ( !toSave.url().getUsername().empty() && !toSave.url().getPassword().empty() )
+ if ( toSave.url().hasCredentialsInAuthority() )
{
media::CredentialManager cm(
media::CredManagerOptions(_pimpl->options.rootDir) );
url = service.url();
else
{
- // service repo can contain only one URL now, so no need to iterate
+ // service repo can contain only one URL now, so no need to iterate.
url = *it->baseUrlsBegin();
-
- url::ViewOption vopt;
- vopt = vopt
- - url::ViewOption::WITH_USERNAME
- - url::ViewOption::WITH_PASSWORD
- - url::ViewOption::WITH_QUERY_STR;
-
- // use the same username as the service in case the URL starts with
- // the service url
- if (url.asString(vopt).find(service.url().asString(vopt)) == 0
- && !service.url().getUsername().empty())
- url.setUsername(service.url().getUsername());
}
// libzypp currently has problem with separate url + path handling