Allow to specify allowed <custom/> keys
If no <custom/> tags are set to be propagated to the output, we will simply ignore them all.
This commit is contained in:
parent
022ba9638f
commit
a28b844e0a
@ -50,6 +50,7 @@ Oldsuites | This key exists to support migration from an alternative appstream g
|
||||
Suites | Suites which should be recognized by the generator. Each suite has the components and architectures which should be searched for metadata as children. See below for more information.
|
||||
Features | Disable or enable selected generator features. For a detailed description see below.
|
||||
CAInfo | Set the CA certificate bundle file to use for SSL peer verification. If this is not set, the generator will use the system default.
|
||||
AllowedCustomKeys | Set which keys of the <custom/> tag are allowed to be propagated to the collection metadata output. This key takes a list of custom-key strings as value.
|
||||
|
||||
|
||||
### Suite fields
|
||||
|
@ -99,6 +99,8 @@ class Config
|
||||
DataType metadataType;
|
||||
uint enabledFeatures; // bitfield
|
||||
|
||||
bool[string] allowedCustomKeys; // set of allowed keys in <custom/> tags
|
||||
|
||||
string workspaceDir;
|
||||
|
||||
string caInfo;
|
||||
@ -338,6 +340,10 @@ class Config
|
||||
oldsuites = map!"a.str"(root["Oldsuites"].array).array;
|
||||
}
|
||||
|
||||
if ("AllowedCustomKeys" in root.object)
|
||||
foreach (ref key; root["AllowedCustomKeys"].array)
|
||||
allowedCustomKeys[key.str] = true;
|
||||
|
||||
// Enable features which are default-enabled
|
||||
setFeature (GeneratorFeature.PROCESS_DESKTOP, true);
|
||||
setFeature (GeneratorFeature.VALIDATE, true);
|
||||
|
@ -29,8 +29,25 @@ import appstream.Component;
|
||||
import asgen.hint;
|
||||
import asgen.utils : buildCptGlobalID;
|
||||
import asgen.backends.interfaces;
|
||||
import asgen.config : Config;
|
||||
|
||||
|
||||
/**
|
||||
* Helper function for GeneratorResult.finalize()
|
||||
*/
|
||||
extern(C)
|
||||
int evaluateCustomEntry (void *keyPtr, void *value, void *userData)
|
||||
{
|
||||
auto key = (cast(const(char)*) keyPtr).fromStringz;
|
||||
auto conf = *cast(Config*) userData;
|
||||
|
||||
if (key in conf.allowedCustomKeys)
|
||||
return false; // FALSE, do not delete
|
||||
|
||||
// remove invalid key
|
||||
return true;
|
||||
}
|
||||
|
||||
class GeneratorResult
|
||||
{
|
||||
|
||||
@ -208,6 +225,8 @@ public:
|
||||
*/
|
||||
void finalize ()
|
||||
{
|
||||
auto conf = Config.get ();
|
||||
|
||||
// we need to duplicate the associative array, because the addHint() function
|
||||
// may remove entries from "cpts", breaking our foreach loop.
|
||||
foreach (cpt; cpts.dup.byValue ()) {
|
||||
@ -230,8 +249,8 @@ public:
|
||||
addHint (cpt.getId (), "metainfo-no-summary");
|
||||
}
|
||||
|
||||
// inject package descriptions, if needed
|
||||
foreach (cpt; cpts.byValue ()) {
|
||||
// inject package descriptions, if needed
|
||||
if (cpt.getKind () == ComponentKind.DESKTOP_APP) {
|
||||
auto flags = cpt.getValueFlags;
|
||||
cpt.setValueFlags (flags | AsValueFlags.NO_TRANSLATION_FALLBACK);
|
||||
@ -250,6 +269,22 @@ public:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// filter custom tags
|
||||
auto customHashTable = cpt.getCustom ();
|
||||
auto noCustomKeysAllowed = conf.allowedCustomKeys.length == 0;
|
||||
if (customHashTable.size () > 0) {
|
||||
import gi.glibtypes;
|
||||
|
||||
if (noCustomKeysAllowed) {
|
||||
// if we don't allow any custom keys, we can delete them faster
|
||||
customHashTable.removeAll ();
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter the custom values
|
||||
customHashTable.foreachRemove (&evaluateCustomEntry, &conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user