networkAgent: Use libnm for plugin loading

After the networking code has been ported to libnm, we can use its
API for loading VPN plugins instead of rolling our own ...

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/39
This commit is contained in:
Florian Müllner 2016-11-03 15:25:49 +01:00 committed by Florian Müllner
parent 11ca8dd54f
commit 71515a8a11

View File

@ -765,57 +765,29 @@ var NetworkAgent = new Lang.Class({
this._vpnCacheBuilt = true; this._vpnCacheBuilt = true;
this._vpnBinaries = { }; this._vpnBinaries = { };
try { NM.VpnPluginInfo.list_load().forEach(plugin => {
let fileEnum = this._pluginDir.enumerate_children('standard::name', Gio.FileQueryInfoFlags.NONE, null); let service = plugin.get_service();
let info; let fileName = plugin.get_auth_dialog();
let supportsHints = plugin.supports_hints();
while ((info = fileEnum.next_file(null))) {
let name = info.get_name();
if (name.substr(-5) != '.name')
continue;
try {
let keyfile = new GLib.KeyFile();
keyfile.load_from_file(this._pluginDir.get_child(name).get_path(), GLib.KeyFileFlags.NONE);
let service = keyfile.get_string('VPN Connection', 'service');
let binary = keyfile.get_string('GNOME', 'auth-dialog');
let externalUIMode = false; let externalUIMode = false;
let hints = false;
try { let prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
externalUIMode = keyfile.get_boolean('GNOME', 'supports-external-ui-mode'); if (prop) {
} catch(e) { } // ignore errors if key does not exist prop = prop.trim().toLowerCase();
externalUIMode = ['true', 'yes', 'on', '1'].includes(prop);
try {
hints = keyfile.get_boolean('GNOME', 'supports-hints');
} catch(e) { } // ignore errors if key does not exist
let path = binary;
if (!GLib.path_is_absolute(path)) {
path = GLib.build_filenamev([Config.LIBEXECDIR, path]);
} }
if (GLib.file_test(path, GLib.FileTest.IS_EXECUTABLE)) { if (GLib.file_test(fileName, GLib.FileTest.IS_EXECUTABLE)) {
this._vpnBinaries[service] = { fileName: path, externalUIMode: externalUIMode, supportsHints: hints }; let binary = { fileName, externalUIMode, supportsHints };
try { this._vpnBinaries[service] = binary;
let aliases = keyfile.get_string_list('VPN Connection', 'aliases');
for (let alias of aliases) { plugin.get_aliases().forEach(alias => {
this._vpnBinaries[alias] = { fileName: path, externalUIMode: externalUIMode, supportsHints: hints }; this._vpnBinaries[alias] = binary;
} });
} catch(e) { } // ignore errors if key does not exist
} else { } else {
throw new Error('VPN plugin at %s is not executable'.format(path)); log('VPN plugin at %s is not executable'.format(fileName));
}
} catch(e) {
log('Error \'%s\' while processing VPN keyfile \'%s\''.
format(e.message, this._pluginDir.get_child(name).get_path()));
continue;
}
}
} catch(e) {
logError(e, 'error while enumerating VPN auth helpers');
} }
});
} }
}); });
var Component = NetworkAgent; var Component = NetworkAgent;