Skip to content

Commit

Permalink
Merge pull request #51 from imobach/add-pkg-gpg-check-callback
Browse files Browse the repository at this point in the history
Add pkgGpgCheck callback
  • Loading branch information
imobachgs committed Oct 9, 2015
2 parents 7c0618d + 81b6dd7 commit e7592fe
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings-devel-doc.spec
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-pkg-bindings-devel-doc
Version: 3.1.30
Version: 3.1.31
Release: 0
License: GPL-2.0
Group: Documentation/HTML
Expand Down
6 changes: 6 additions & 0 deletions package/yast2-pkg-bindings.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Oct 8 21:07:44 UTC 2015 - igonzalezsosa@suse.com

- Add pkgGpgCheck callback (bsc#948608)
- 3.1.31

-------------------------------------------------------------------
Mon Oct 5 14:00:31 UTC 2015 - ancor@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-pkg-bindings.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-pkg-bindings
Version: 3.1.30
Version: 3.1.31
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
2 changes: 1 addition & 1 deletion src/Callbacks.YCP.h
Expand Up @@ -78,7 +78,7 @@ class PkgFunctions::CallbackHandler::YCPCallbacks
CB_StartSourceRefresh, CB_ErrorSourceRefresh, CB_DoneSourceRefresh, CB_ProgressSourceRefresh,
CB_StartDeltaDownload, CB_ProgressDeltaDownload, CB_ProblemDeltaDownload,
CB_StartDeltaApply, CB_ProgressDeltaApply, CB_ProblemDeltaApply,
CB_FinishDeltaDownload, CB_FinishDeltaApply,
CB_FinishDeltaDownload, CB_FinishDeltaApply, CB_PkgGpgCheck,
CB_StartDownload, CB_ProgressDownload, CB_DoneDownload, CB_InitDownload, CB_DestDownload,

CB_FileConflictStart, CB_FileConflictProgress, CB_FileConflictReport, CB_FileConflictFinish,
Expand Down
57 changes: 57 additions & 0 deletions src/Callbacks.cc
Expand Up @@ -39,6 +39,8 @@
#include "zypp/Digest.h"
#include "zypp/base/String.h"
#include "zypp/sat/FileConflicts.h"
#include "zypp/UserData.h"
#include "zypp/target/rpm/RpmDb.h"

#include <ctime>

Expand Down Expand Up @@ -705,6 +707,61 @@ namespace ZyppRecipients {
callback.evaluate();
}
}

///////////////////////////////////////////////////////////////////
// pkgGpgCheck callback
//
// A map containing the following information will be sent:
//
// * CheckPackageResult: Check result code.
// * Package: Package's name.
// * Localpath: Path to RPM file.
// * RepoMediaUrl: Repository URL
//
// It will set userData_r "Action" key according to value returned
// by callback.
///////////////////////////////////////////////////////////////////
virtual void pkgGpgCheck(const UserData & userData_r = UserData() )
{
typedef zypp::target::rpm::RpmDb RpmDb;
CB callback( ycpcb( YCPCallbacks::CB_PkgGpgCheck ) );
YCPMap data;

if (callback._set) {
// Package
const zypp::Package::constPtr & package_r = userData_r.get<zypp::Package::constPtr>("Package");
YCPString package = userData_r.get<std::string>("Package", package_r->name());
data->add(YCPString("Package"), package);

const zypp::RepoInfo repo = package_r->repoInfo();
const std::string url = repo.rawUrl().asString();
data->add(YCPString("RepoMediaUrl"), YCPString(url));

// Localpath
zypp::Pathname localpath = userData_r.get<zypp::Pathname>("Localpath");
data->add(YCPString("Localpath"), YCPString(localpath.asString()));

// Result
YCPInteger checkPackageResult = userData_r.get<RpmDb::CheckPackageResult>("CheckPackageResult");
data->add(YCPString("CheckPackageResult"), checkPackageResult);

callback.addMap(data);

std::string ret = callback.evaluateStr();

if (ret == "A") { // "A" = Abort
userData_r.set("Action", zypp::repo::DownloadResolvableReport::ABORT);
}

if (ret == "I") { // "I" = Ignore
userData_r.set("Action", zypp::repo::DownloadResolvableReport::IGNORE);
}

if (ret == "R") { // "R" = Retry
userData_r.set("Action", zypp::repo::DownloadResolvableReport::RETRY);
}
}
}
};

///////////////////////////////////////////////////////////////////
Expand Down
13 changes: 12 additions & 1 deletion src/Callbacks_Register.cc
Expand Up @@ -78,7 +78,7 @@ YCPValue PkgFunctions::CallbackImportGpgKey( const YCPValue& args ) {
/**
* @builtin CallbackAcceptUnknownGpgKey
* @short Register callback function
* @param string args Name of the callback handler function. Required callback prototype is <code>boolean(string filename, string keyid)</code>. The callback function should ask user whether the unknown key can be accepted, returned true value means to accept the key.
* @param string args Name of the callback handler function. Required callback prototype is <code>boolean(string filename, string keyid)</code>. The callback function should ask user whether the unknown key can be accepted, returned true value means to accept the key.
* @return void
*/
YCPValue PkgFunctions::CallbackAcceptUnknownGpgKey( const YCPValue& args ) {
Expand Down Expand Up @@ -323,6 +323,17 @@ YCPValue PkgFunctions::CallbackFinishDeltaApply( const YCPValue& args)
return SET_YCP_CB( CB_FinishDeltaApply, args);
}

/**
* @builtin CallbackPkgGpgCheck
* @short Register callback function
* @param string args Name of the callback handler function. Required callback prototype is <code>void()</code>. The callback function is evaluated when a package GPG signature is checked.
* @return void
*/
YCPValue PkgFunctions::CallbackPkgGpgCheck( const YCPValue& args)
{
return SET_YCP_CB( CB_PkgGpgCheck, args);
}

/**
* @builtin CallbackSourceCreateStart
* @short Register callback function
Expand Down
40 changes: 21 additions & 19 deletions src/PkgFunctions.h
Expand Up @@ -83,7 +83,7 @@ class PkgFunctions

zypp::Pathname _target_root;
bool _target_loaded;

zypp::ZYpp::Ptr zypp_pointer;

// use a single RepoManager instance to avoid "unused" metadata cleanup
Expand All @@ -96,7 +96,7 @@ class PkgFunctions

zypp::Pathname _download_area;

/**
/**
* ZYPP
*/
zypp::ZYpp::Ptr zypp_ptr();
Expand All @@ -113,13 +113,13 @@ class PkgFunctions
RepoId current_repo_id() const { return current_repo; }

private: // source related

// all known installation sources
RepoCont repos;

// table for converting libzypp source type to Yast type (for backward compatibility)
std::map<std::string, std::string> type_conversion_table;

// flag for skipping autorefresh
volatile bool autorefresh_skipped;

Expand Down Expand Up @@ -164,7 +164,7 @@ class PkgFunctions
YCPValue PkgProp(const zypp::PoolItem &item);
YCPValue PkgMediaSizesOrCount (bool sizes, bool download_size = false);
YCPValue TargetInitInternal(const YCPString& root, bool rebuild_rpmdb);

bool aliasExists(const std::string &alias, const std::list<zypp::RepoInfo> &reps) const;

// remember the base product attributes for finding it later in
Expand Down Expand Up @@ -243,7 +243,7 @@ class PkgFunctions
* and setLastError AND RETHROW
*/
YRepo_Ptr logFindRepository(RepoId id);

RepoId createManagedSource(const zypp::Url & url_r,
const zypp::Pathname & path_r, const std::string& type,
const std::string &alias_r, PkgProgress &progress, const zypp::ProgressData::ReceiverFnc & progressrcv = zypp::ProgressData::ReceiverFnc());
Expand All @@ -257,7 +257,7 @@ class PkgFunctions

// a helper function to add or remove an upgrade repository
YCPValue AddRemoveUpgradeRepo(const YCPInteger &repo, bool add);

// action for a resolvable
enum ResolvableAction
{
Expand Down Expand Up @@ -329,6 +329,8 @@ class PkgFunctions
YCPValue CallbackProblemDeltaApply( const YCPValue& /*nil*/ args);
/* TYPEINFO: void(boolean(integer)) */
YCPValue CallbackFinishDeltaDownload( const YCPValue& /*nil*/ args);
/* TYPEINFO: void(boolean(integer)) */
YCPValue CallbackPkgGpgCheck( const YCPValue& /*nil*/ args);
/* TYPEINFO: void(void()) */
YCPValue CallbackFinishDeltaApply( const YCPValue& /*nil*/ args);

Expand Down Expand Up @@ -458,33 +460,33 @@ class PkgFunctions
YCPValue CallbackResolvableReport( const YCPValue& /*nil*/ args );

/* TYPEINFO: void(boolean(map<string,any>,integer)) */
YCPValue CallbackImportGpgKey( const YCPValue& /*nil*/ args );
YCPValue CallbackImportGpgKey( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(string,string,integer)) */
YCPValue CallbackAcceptUnknownGpgKey( const YCPValue& /*nil*/ args );
YCPValue CallbackAcceptUnknownGpgKey( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(string,integer)) */
YCPValue CallbackAcceptUnsignedFile( const YCPValue& /*nil*/ args );
YCPValue CallbackAcceptUnsignedFile( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(string,map<string,any>,integer)) */
YCPValue CallbackAcceptVerificationFailed( const YCPValue& /*nil*/ args );
YCPValue CallbackAcceptVerificationFailed( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(string,string,string)) */
YCPValue CallbackAcceptWrongDigest( const YCPValue& /*nil*/ args);
/* TYPEINFO: void(boolean(string,string)) */
YCPValue CallbackAcceptUnknownDigest( const YCPValue& /*nil*/ args);
/* TYPEINFO: void(void(map<string,any>)) */
YCPValue CallbackTrustedKeyAdded( const YCPValue& /*nil*/ args );
YCPValue CallbackTrustedKeyAdded( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(void(map<string,any>)) */
YCPValue CallbackTrustedKeyRemoved( const YCPValue& /*nil*/ args );
YCPValue CallbackTrustedKeyRemoved( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(string)) */
YCPValue CallbackAcceptFileWithoutChecksum( const YCPValue& /*nil*/ args );
YCPValue CallbackAcceptFileWithoutChecksum( const YCPValue& /*nil*/ args );


/* TYPEINFO: void(void(string,list<string>,string)) */
YCPValue CallbackProcessStart( const YCPValue& /*nil*/ args );
YCPValue CallbackProcessStart( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(boolean(integer)) */
YCPValue CallbackProcessProgress( const YCPValue& /*nil*/ args );
YCPValue CallbackProcessProgress( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(void()) */
YCPValue CallbackProcessNextStage( const YCPValue& /*nil*/ args );
YCPValue CallbackProcessNextStage( const YCPValue& /*nil*/ args );
/* TYPEINFO: void(void()) */
YCPValue CallbackProcessDone( const YCPValue& /*nil*/ args );
YCPValue CallbackProcessDone( const YCPValue& /*nil*/ args );

// source related
/* TYPEINFO: boolean(boolean)*/
Expand Down Expand Up @@ -808,7 +810,7 @@ class PkgFunctions
* Constructor.
*/
PkgFunctions ();

/**
* Destructor.
*/
Expand Down

0 comments on commit e7592fe

Please sign in to comment.