Skip to content

Commit

Permalink
Dev dependency version bump; executed prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Sep 19, 2022
1 parent 8ba20c4 commit a5b9cac
Show file tree
Hide file tree
Showing 14 changed files with 1,450 additions and 5,305 deletions.
8 changes: 4 additions & 4 deletions bin/dbus2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

const fs = require('fs');
const xml2js = require('xml2js');
const xml2js_opts = Object.assign({}, xml2js.defaults["0.1"], { explicitArray: true });
const xml2js_opts = Object.assign({}, xml2js.defaults['0.1'], {
explicitArray: true
});
const dbus = require('../index');
const optimist = require('optimist');

Expand Down Expand Up @@ -65,9 +67,7 @@ if (!argv.server) {
output.push(' if (err) throw new Error(err);');
output.push(' });');
output.push(
` var signalFullName = bus.mangle('${argv.path}', '${
ifaceName
}', signame);`
` var signalFullName = bus.mangle('${argv.path}', '${ifaceName}', signame);`
);
output.push(
' bus.signals.on(signalFullName, function(messageBody) {'
Expand Down
4 changes: 1 addition & 3 deletions examples/basic-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const service = sessionBus.getService(serviceName);
service.getInterface(objectPath, interfaceName, (err, iface) => {
if (err) {
console.error(
`Failed to request interface '${interfaceName}' at '${objectPath}' : ${
err
}`
`Failed to request interface '${interfaceName}' at '${objectPath}' : ${err}`
? err
: '(no error)'
);
Expand Down
4 changes: 1 addition & 3 deletions examples/basic-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ sessionBus.requestName(serviceName, 0x4, (err, retCode) => {
information
*/
throw new Error(
`Failed to request service name "${
serviceName
}". Check what return code "${retCode}" means.`
`Failed to request service name "${serviceName}". Check what return code "${retCode}" means.`
);
}
});
Expand Down
10 changes: 6 additions & 4 deletions examples/return-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ sessionBus.requestName(serviceName, 0x4, (err, retCode) => {
information
*/
throw new Error(
`Failed to request service name "${
serviceName
}". Check what return code "${retCode}" means.`
`Failed to request service name "${serviceName}". Check what return code "${retCode}" means.`
);
}
});
Expand Down Expand Up @@ -183,7 +181,11 @@ function proceed() {
MUST be single types, so string, integers, double, booleans, etc.) and the second being
the value (here, an int32 ; keys can be any type, including complex one: struct, etc.)
*/
return [[key1, i1], [key2, i2], [key3, i3]];
return [
[key1, i1],
[key2, i2],
[key3, i3]
];
}
};

Expand Down
4 changes: 1 addition & 3 deletions examples/service-signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ sessionBus.requestName(serviceName, 0x4, (err, retCode) => {
information
*/
throw new Error(
`Failed to request service name "${
serviceName
}". Check what return code "${retCode}" means.`
`Failed to request service name "${serviceName}". Check what return code "${retCode}" means.`
);
}
});
Expand Down
4 changes: 1 addition & 3 deletions lib/address-x11.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ function getDbusAddress(callback) {
var hostname = os.hostname().split('-')[0];
x11.createClient(function(err, display) {
var X = display.client;
var selectionName = `_DBUS_SESSION_BUS_SELECTION_${
hostname
}_${uuid.trim()}`;
var selectionName = `_DBUS_SESSION_BUS_SELECTION_${hostname}_${uuid.trim()}`;
X.InternAtom(false, selectionName, function(err, id) {
if (err) return callback(err);
X.GetSelectionOwner(id, function(err, win) {
Expand Down
2 changes: 1 addition & 1 deletion lib/align.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Buffer = require('safe-buffer').Buffer;

function align(ps, n) {
var pad = n - ps._offset % n;
var pad = n - (ps._offset % n);
if (pad === 0 || pad === n) return;
// TODO: write8(0) in a loop (3 to 7 times here) could be more efficient
var padBuff = Buffer.alloc(pad);
Expand Down
4 changes: 1 addition & 3 deletions lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ module.exports = function bus(conn, opts) {
self.sendError(
msg,
'org.freedesktop.DBus.Error.UnknownMethod',
`Method "${msg.member}" on interface "${
msg.interface
}" doesn't exist`
`Method "${msg.member}" on interface "${msg.interface}" doesn't exist`
);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function getCookie(context, id, cb) {
'User keyrings directory is writeable by other users. Aborting authentication'
)
);
// eslint-disable-next-line no-prototype-builtins
if (process.hasOwnProperty('getuid') && stat.uid !== process.getuid())
return cb(
new Error(
Expand Down Expand Up @@ -72,6 +73,7 @@ function tryAuth(stream, methods, cb) {
}

var authMethod = methods.shift();
// eslint-disable-next-line no-prototype-builtins
var uid = process.hasOwnProperty('getuid') ? process.getuid() : 0;
var id = hexlify(uid);

Expand Down
98 changes: 55 additions & 43 deletions lib/introspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports.introspectBus = function(obj, callback) {
interface: 'org.freedesktop.DBus.Introspectable',
member: 'Introspect'
},
function(err, xml) { module.exports.processXML(err, xml, obj, callback); }
function(err, xml) {
module.exports.processXML(err, xml, obj, callback);
}
);
};

Expand Down Expand Up @@ -59,17 +61,19 @@ module.exports.processXML = function(err, xml, obj, callback) {
}
for (var p = 0; iface.property && p < iface.property.length; ++p) {
property = iface.property[p];
currentIface.$createProp(property['$'].name, property['$'].type, property['$'].access)
currentIface.$createProp(
property['$'].name,
property['$'].type,
property['$'].access
);
}
// TODO: introspect signals
}
callback(null, proxy, nodes);
});
}

};

function DBusInterface(parent_obj, ifname)
{
function DBusInterface(parent_obj, ifname) {
// Since methods and props presently get added directly to the object, to avoid collision with existing names we must use $ naming convention as $ is invalid for dbus member names
// https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
this.$parent = parent_obj; // parent DbusObject
Expand All @@ -89,52 +93,62 @@ DBusInterface.prototype.$getSigHandler = function(callback) {
};
}
return this.$sigHandlers[index];
}
DBusInterface.prototype.addListener = DBusInterface.prototype.on = function(signame, callback) {
};
DBusInterface.prototype.addListener = DBusInterface.prototype.on = function(
signame,
callback
) {
// http://dbus.freedesktop.org/doc/api/html/group__DBusBus.html#ga4eb6401ba014da3dbe3dc4e2a8e5b3ef
// An example is "type='signal',sender='org.freedesktop.DBus', interface='org.freedesktop.DBus',member='Foo', path='/bar/foo',destination=':452345.34'" ...
var bus = this.$parent.service.bus;
var signalFullName = bus.mangle(this.$parent.name, this.$name, signame);
if (!bus.signals.listeners(signalFullName).length) {
// This is the first time, so call addMatch
var match = getMatchRule(this.$parent.name, this.$name, signame);
bus.addMatch(match, function(err) {
if (err) throw new Error(err);
bus.signals.on(signalFullName, this.$getSigHandler(callback));
}.bind(this));
bus.addMatch(
match,
function(err) {
if (err) throw new Error(err);
bus.signals.on(signalFullName, this.$getSigHandler(callback));
}.bind(this)
);
} else {
// The match is already there, just add event listener
bus.signals.on(signalFullName, this.$getSigHandler(callback));
}
}
DBusInterface.prototype.removeListener = DBusInterface.prototype.off = function(signame, callback) {
};
DBusInterface.prototype.removeListener = DBusInterface.prototype.off = function(
signame,
callback
) {
var bus = this.$parent.service.bus;
var signalFullName = bus.mangle(this.$parent.name, this.$name, signame);
bus.signals.removeListener( signalFullName, this.$getSigHandler(callback) );
bus.signals.removeListener(signalFullName, this.$getSigHandler(callback));
if (!bus.signals.listeners(signalFullName).length) {
// There is no event handlers for this match
var match = getMatchRule(this.$parent.name, this.$name, signame);
bus.removeMatch(match, function(err) {
if (err) throw new Error(err);
// Now it is safe to empty these arrays
this.$callbacks.length = 0;
this.$sigHandlers.length = 0;
}.bind(this));
bus.removeMatch(
match,
function(err) {
if (err) throw new Error(err);
// Now it is safe to empty these arrays
this.$callbacks.length = 0;
this.$sigHandlers.length = 0;
}.bind(this)
);
}
}
DBusInterface.prototype.$createMethod = function(mName, signature)
{
};
DBusInterface.prototype.$createMethod = function(mName, signature) {
this.$methods[mName] = signature;
this[mName] = function() { this.$callMethod(mName, arguments); }
}
DBusInterface.prototype.$callMethod = function(mName, args)
{
this[mName] = function() {
this.$callMethod(mName, arguments);
};
};
DBusInterface.prototype.$callMethod = function(mName, args) {
var bus = this.$parent.service.bus;
if (!Array.isArray(args)) args = Array.from(args); // Array.prototype.slice.apply(args)
var callback =
typeof args[args.length - 1] === 'function'
? args.pop()
: function() {};
typeof args[args.length - 1] === 'function' ? args.pop() : function() {};
var msg = {
destination: this.$parent.service.name,
path: this.$parent.name,
Expand All @@ -146,18 +160,18 @@ DBusInterface.prototype.$callMethod = function(mName, args)
msg.body = args;
}
bus.invoke(msg, callback);
}
DBusInterface.prototype.$createProp = function(propName, propType, propAccess)
{
};
DBusInterface.prototype.$createProp = function(propName, propType, propAccess) {
this.$properties[propName] = { type: propType, access: propAccess };
Object.defineProperty(this, propName, {
enumerable: true,
get: () => callback => this.$readProp(propName, callback),
set: function(val) { this.$writeProp(propName, val) }
set: function(val) {
this.$writeProp(propName, val);
}
});
}
DBusInterface.prototype.$readProp = function(propName, callback)
{
};
DBusInterface.prototype.$readProp = function(propName, callback) {
var bus = this.$parent.service.bus;
bus.invoke(
{
Expand All @@ -181,9 +195,8 @@ DBusInterface.prototype.$readProp = function(propName, callback)
}
}
);
}
DBusInterface.prototype.$writeProp = function(propName, val)
{
};
DBusInterface.prototype.$writeProp = function(propName, val) {
var bus = this.$parent.service.bus;
bus.invoke({
destination: this.$parent.service.name,
Expand All @@ -193,8 +206,7 @@ DBusInterface.prototype.$writeProp = function(propName, val)
signature: 'ssv',
body: [this.$name, propName, [this.$properties[propName].type, val]]
});
}

};

function getMatchRule(objName, ifName, signame) {
return `type='signal',path='${objName}',interface='${ifName}',member='${signame}'`;
Expand Down
10 changes: 4 additions & 6 deletions lib/stdifaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ function interfaceToXML(iface) {
var argName = argsNames ? argsNames[num] : direction + num;
var dirStr = direction === 'signal' ? '' : `" direction="${direction}`;
result.push(
` <arg type="${dumpSignature([arg])}" name="${argName}${
dirStr
}" />`
` <arg type="${dumpSignature([
arg
])}" name="${argName}${dirStr}" />`
);
});
};
Expand All @@ -180,9 +180,7 @@ function interfaceToXML(iface) {
for (const propertyName in iface.properties) {
// TODO: decide how to encode access
result.push(
` <property name="${propertyName}" type="${
iface.properties[propertyName]
}" access="readwrite"/>`
` <property name="${propertyName}" type="${iface.properties[propertyName]}" access="readwrite"/>`
);
}
}
Expand Down
Loading

0 comments on commit a5b9cac

Please sign in to comment.