@homebridge/dbus-native 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dbus2js.js +9 -6
- package/lib/address-x11.js +1 -3
- package/lib/align.js +1 -1
- package/lib/bus.js +1 -3
- package/lib/handshake.js +2 -0
- package/lib/introspect.js +55 -43
- package/lib/marshall.js +1 -1
- package/lib/stdifaces.js +4 -6
- package/package.json +9 -7
package/bin/dbus2js.js
CHANGED
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const xml2js = require('xml2js');
|
|
5
|
-
const xml2js_opts = Object.assign({}, xml2js.defaults[
|
|
5
|
+
const xml2js_opts = Object.assign({}, xml2js.defaults['0.1'], {
|
|
6
|
+
explicitArray: true
|
|
7
|
+
});
|
|
6
8
|
const dbus = require('../index');
|
|
7
|
-
const
|
|
9
|
+
const minimist = require('minimist');
|
|
8
10
|
|
|
9
|
-
var argv =
|
|
11
|
+
var argv = minimist(process.argv.slice(2), {
|
|
12
|
+
boolean: ['server', 'dump', 'xml'],
|
|
13
|
+
string: ['bus', 'service', 'path']
|
|
14
|
+
});
|
|
10
15
|
|
|
11
16
|
function die(err) {
|
|
12
17
|
console.log(err);
|
|
@@ -65,9 +70,7 @@ if (!argv.server) {
|
|
|
65
70
|
output.push(' if (err) throw new Error(err);');
|
|
66
71
|
output.push(' });');
|
|
67
72
|
output.push(
|
|
68
|
-
` var signalFullName = bus.mangle('${argv.path}', '${
|
|
69
|
-
ifaceName
|
|
70
|
-
}', signame);`
|
|
73
|
+
` var signalFullName = bus.mangle('${argv.path}', '${ifaceName}', signame);`
|
|
71
74
|
);
|
|
72
75
|
output.push(
|
|
73
76
|
' bus.signals.on(signalFullName, function(messageBody) {'
|
package/lib/address-x11.js
CHANGED
|
@@ -11,9 +11,7 @@ function getDbusAddress(callback) {
|
|
|
11
11
|
var hostname = os.hostname().split('-')[0];
|
|
12
12
|
x11.createClient(function(err, display) {
|
|
13
13
|
var X = display.client;
|
|
14
|
-
var selectionName = `_DBUS_SESSION_BUS_SELECTION_${
|
|
15
|
-
hostname
|
|
16
|
-
}_${uuid.trim()}`;
|
|
14
|
+
var selectionName = `_DBUS_SESSION_BUS_SELECTION_${hostname}_${uuid.trim()}`;
|
|
17
15
|
X.InternAtom(false, selectionName, function(err, id) {
|
|
18
16
|
if (err) return callback(err);
|
|
19
17
|
X.GetSelectionOwner(id, function(err, win) {
|
package/lib/align.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const Buffer = require('safe-buffer').Buffer;
|
|
2
2
|
|
|
3
3
|
function align(ps, n) {
|
|
4
|
-
var pad = n - ps._offset % n;
|
|
4
|
+
var pad = n - (ps._offset % n);
|
|
5
5
|
if (pad === 0 || pad === n) return;
|
|
6
6
|
// TODO: write8(0) in a loop (3 to 7 times here) could be more efficient
|
|
7
7
|
var padBuff = Buffer.alloc(pad);
|
package/lib/bus.js
CHANGED
|
@@ -158,9 +158,7 @@ module.exports = function bus(conn, opts) {
|
|
|
158
158
|
self.sendError(
|
|
159
159
|
msg,
|
|
160
160
|
'org.freedesktop.DBus.Error.UnknownMethod',
|
|
161
|
-
`Method "${msg.member}" on interface "${
|
|
162
|
-
msg.interface
|
|
163
|
-
}" doesn't exist`
|
|
161
|
+
`Method "${msg.member}" on interface "${msg.interface}" doesn't exist`
|
|
164
162
|
);
|
|
165
163
|
return;
|
|
166
164
|
}
|
package/lib/handshake.js
CHANGED
|
@@ -32,6 +32,7 @@ function getCookie(context, id, cb) {
|
|
|
32
32
|
'User keyrings directory is writeable by other users. Aborting authentication'
|
|
33
33
|
)
|
|
34
34
|
);
|
|
35
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
35
36
|
if (process.hasOwnProperty('getuid') && stat.uid !== process.getuid())
|
|
36
37
|
return cb(
|
|
37
38
|
new Error(
|
|
@@ -72,6 +73,7 @@ function tryAuth(stream, methods, cb) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
var authMethod = methods.shift();
|
|
76
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
75
77
|
var uid = process.hasOwnProperty('getuid') ? process.getuid() : 0;
|
|
76
78
|
var id = hexlify(uid);
|
|
77
79
|
|
package/lib/introspect.js
CHANGED
|
@@ -9,7 +9,9 @@ module.exports.introspectBus = function(obj, callback) {
|
|
|
9
9
|
interface: 'org.freedesktop.DBus.Introspectable',
|
|
10
10
|
member: 'Introspect'
|
|
11
11
|
},
|
|
12
|
-
function(err, xml) {
|
|
12
|
+
function(err, xml) {
|
|
13
|
+
module.exports.processXML(err, xml, obj, callback);
|
|
14
|
+
}
|
|
13
15
|
);
|
|
14
16
|
};
|
|
15
17
|
|
|
@@ -59,17 +61,19 @@ module.exports.processXML = function(err, xml, obj, callback) {
|
|
|
59
61
|
}
|
|
60
62
|
for (var p = 0; iface.property && p < iface.property.length; ++p) {
|
|
61
63
|
property = iface.property[p];
|
|
62
|
-
currentIface.$createProp(
|
|
64
|
+
currentIface.$createProp(
|
|
65
|
+
property['$'].name,
|
|
66
|
+
property['$'].type,
|
|
67
|
+
property['$'].access
|
|
68
|
+
);
|
|
63
69
|
}
|
|
64
70
|
// TODO: introspect signals
|
|
65
71
|
}
|
|
66
72
|
callback(null, proxy, nodes);
|
|
67
73
|
});
|
|
68
|
-
}
|
|
69
|
-
|
|
74
|
+
};
|
|
70
75
|
|
|
71
|
-
function DBusInterface(parent_obj, ifname)
|
|
72
|
-
{
|
|
76
|
+
function DBusInterface(parent_obj, ifname) {
|
|
73
77
|
// 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
|
|
74
78
|
// https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
|
|
75
79
|
this.$parent = parent_obj; // parent DbusObject
|
|
@@ -89,8 +93,11 @@ DBusInterface.prototype.$getSigHandler = function(callback) {
|
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
95
|
return this.$sigHandlers[index];
|
|
92
|
-
}
|
|
93
|
-
DBusInterface.prototype.addListener = DBusInterface.prototype.on = function(
|
|
96
|
+
};
|
|
97
|
+
DBusInterface.prototype.addListener = DBusInterface.prototype.on = function(
|
|
98
|
+
signame,
|
|
99
|
+
callback
|
|
100
|
+
) {
|
|
94
101
|
// http://dbus.freedesktop.org/doc/api/html/group__DBusBus.html#ga4eb6401ba014da3dbe3dc4e2a8e5b3ef
|
|
95
102
|
// An example is "type='signal',sender='org.freedesktop.DBus', interface='org.freedesktop.DBus',member='Foo', path='/bar/foo',destination=':452345.34'" ...
|
|
96
103
|
var bus = this.$parent.service.bus;
|
|
@@ -98,43 +105,50 @@ DBusInterface.prototype.addListener = DBusInterface.prototype.on = function(sign
|
|
|
98
105
|
if (!bus.signals.listeners(signalFullName).length) {
|
|
99
106
|
// This is the first time, so call addMatch
|
|
100
107
|
var match = getMatchRule(this.$parent.name, this.$name, signame);
|
|
101
|
-
bus.addMatch(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
bus.addMatch(
|
|
109
|
+
match,
|
|
110
|
+
function(err) {
|
|
111
|
+
if (err) throw new Error(err);
|
|
112
|
+
bus.signals.on(signalFullName, this.$getSigHandler(callback));
|
|
113
|
+
}.bind(this)
|
|
114
|
+
);
|
|
105
115
|
} else {
|
|
106
116
|
// The match is already there, just add event listener
|
|
107
117
|
bus.signals.on(signalFullName, this.$getSigHandler(callback));
|
|
108
118
|
}
|
|
109
|
-
}
|
|
110
|
-
DBusInterface.prototype.removeListener = DBusInterface.prototype.off = function(
|
|
119
|
+
};
|
|
120
|
+
DBusInterface.prototype.removeListener = DBusInterface.prototype.off = function(
|
|
121
|
+
signame,
|
|
122
|
+
callback
|
|
123
|
+
) {
|
|
111
124
|
var bus = this.$parent.service.bus;
|
|
112
125
|
var signalFullName = bus.mangle(this.$parent.name, this.$name, signame);
|
|
113
|
-
bus.signals.removeListener(
|
|
126
|
+
bus.signals.removeListener(signalFullName, this.$getSigHandler(callback));
|
|
114
127
|
if (!bus.signals.listeners(signalFullName).length) {
|
|
115
128
|
// There is no event handlers for this match
|
|
116
129
|
var match = getMatchRule(this.$parent.name, this.$name, signame);
|
|
117
|
-
bus.removeMatch(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
bus.removeMatch(
|
|
131
|
+
match,
|
|
132
|
+
function(err) {
|
|
133
|
+
if (err) throw new Error(err);
|
|
134
|
+
// Now it is safe to empty these arrays
|
|
135
|
+
this.$callbacks.length = 0;
|
|
136
|
+
this.$sigHandlers.length = 0;
|
|
137
|
+
}.bind(this)
|
|
138
|
+
);
|
|
123
139
|
}
|
|
124
|
-
}
|
|
125
|
-
DBusInterface.prototype.$createMethod = function(mName, signature)
|
|
126
|
-
{
|
|
140
|
+
};
|
|
141
|
+
DBusInterface.prototype.$createMethod = function(mName, signature) {
|
|
127
142
|
this.$methods[mName] = signature;
|
|
128
|
-
this[mName] = function() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
this[mName] = function() {
|
|
144
|
+
this.$callMethod(mName, arguments);
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
DBusInterface.prototype.$callMethod = function(mName, args) {
|
|
132
148
|
var bus = this.$parent.service.bus;
|
|
133
149
|
if (!Array.isArray(args)) args = Array.from(args); // Array.prototype.slice.apply(args)
|
|
134
150
|
var callback =
|
|
135
|
-
typeof args[args.length - 1] === 'function'
|
|
136
|
-
? args.pop()
|
|
137
|
-
: function() {};
|
|
151
|
+
typeof args[args.length - 1] === 'function' ? args.pop() : function() {};
|
|
138
152
|
var msg = {
|
|
139
153
|
destination: this.$parent.service.name,
|
|
140
154
|
path: this.$parent.name,
|
|
@@ -146,18 +160,18 @@ DBusInterface.prototype.$callMethod = function(mName, args)
|
|
|
146
160
|
msg.body = args;
|
|
147
161
|
}
|
|
148
162
|
bus.invoke(msg, callback);
|
|
149
|
-
}
|
|
150
|
-
DBusInterface.prototype.$createProp = function(propName, propType, propAccess)
|
|
151
|
-
{
|
|
163
|
+
};
|
|
164
|
+
DBusInterface.prototype.$createProp = function(propName, propType, propAccess) {
|
|
152
165
|
this.$properties[propName] = { type: propType, access: propAccess };
|
|
153
166
|
Object.defineProperty(this, propName, {
|
|
154
167
|
enumerable: true,
|
|
155
168
|
get: () => callback => this.$readProp(propName, callback),
|
|
156
|
-
set: function(val) {
|
|
169
|
+
set: function(val) {
|
|
170
|
+
this.$writeProp(propName, val);
|
|
171
|
+
}
|
|
157
172
|
});
|
|
158
|
-
}
|
|
159
|
-
DBusInterface.prototype.$readProp = function(propName, callback)
|
|
160
|
-
{
|
|
173
|
+
};
|
|
174
|
+
DBusInterface.prototype.$readProp = function(propName, callback) {
|
|
161
175
|
var bus = this.$parent.service.bus;
|
|
162
176
|
bus.invoke(
|
|
163
177
|
{
|
|
@@ -181,9 +195,8 @@ DBusInterface.prototype.$readProp = function(propName, callback)
|
|
|
181
195
|
}
|
|
182
196
|
}
|
|
183
197
|
);
|
|
184
|
-
}
|
|
185
|
-
DBusInterface.prototype.$writeProp = function(propName, val)
|
|
186
|
-
{
|
|
198
|
+
};
|
|
199
|
+
DBusInterface.prototype.$writeProp = function(propName, val) {
|
|
187
200
|
var bus = this.$parent.service.bus;
|
|
188
201
|
bus.invoke({
|
|
189
202
|
destination: this.$parent.service.name,
|
|
@@ -193,8 +206,7 @@ DBusInterface.prototype.$writeProp = function(propName, val)
|
|
|
193
206
|
signature: 'ssv',
|
|
194
207
|
body: [this.$name, propName, [this.$properties[propName].type, val]]
|
|
195
208
|
});
|
|
196
|
-
}
|
|
197
|
-
|
|
209
|
+
};
|
|
198
210
|
|
|
199
211
|
function getMatchRule(objName, ifName, signame) {
|
|
200
212
|
return `type='signal',path='${objName}',interface='${ifName}',member='${signame}'`;
|
package/lib/marshall.js
CHANGED
package/lib/stdifaces.js
CHANGED
|
@@ -152,9 +152,9 @@ function interfaceToXML(iface) {
|
|
|
152
152
|
var argName = argsNames ? argsNames[num] : direction + num;
|
|
153
153
|
var dirStr = direction === 'signal' ? '' : `" direction="${direction}`;
|
|
154
154
|
result.push(
|
|
155
|
-
` <arg type="${dumpSignature([
|
|
156
|
-
|
|
157
|
-
}" />`
|
|
155
|
+
` <arg type="${dumpSignature([
|
|
156
|
+
arg
|
|
157
|
+
])}" name="${argName}${dirStr}" />`
|
|
158
158
|
);
|
|
159
159
|
});
|
|
160
160
|
};
|
|
@@ -180,9 +180,7 @@ function interfaceToXML(iface) {
|
|
|
180
180
|
for (const propertyName in iface.properties) {
|
|
181
181
|
// TODO: decide how to encode access
|
|
182
182
|
result.push(
|
|
183
|
-
` <property name="${propertyName}" type="${
|
|
184
|
-
iface.properties[propertyName]
|
|
185
|
-
}" access="readwrite"/>`
|
|
183
|
+
` <property name="${propertyName}" type="${iface.properties[propertyName]}" access="readwrite"/>`
|
|
186
184
|
);
|
|
187
185
|
}
|
|
188
186
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebridge/dbus-native",
|
|
3
3
|
"author": "Andrey Sidorov <sidorares@yandex.com>",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dbus",
|
|
7
7
|
"dcop",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"dbus2js": "./bin/dbus2js.js"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"@homebridge/long": "^5.2.1",
|
|
41
42
|
"event-stream": "^4.0.0",
|
|
42
43
|
"hexy": "^0.2.10",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"put": "0.0.6",
|
|
44
|
+
"minimist": "^1.2.6",
|
|
45
|
+
"@homebridge/put": "~0.0.8",
|
|
46
46
|
"safe-buffer": "^5.1.1",
|
|
47
47
|
"xml2js": "^0.4.17"
|
|
48
48
|
},
|
|
@@ -52,13 +52,15 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"
|
|
55
|
+
"@types/minimist": "^1.2.2",
|
|
56
|
+
"eslint": "^6.0.0",
|
|
56
57
|
"eslint-config-prettier": "^3.0.0",
|
|
57
|
-
"eslint-plugin-markdown": "^
|
|
58
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
58
59
|
"eslint-plugin-prettier": "^3.0.0",
|
|
59
60
|
"husky": "^1.0.0",
|
|
60
|
-
"lint-staged": "^
|
|
61
|
+
"lint-staged": "^13.0.3",
|
|
61
62
|
"mocha": "*",
|
|
63
|
+
"nyc": "^15.1.0",
|
|
62
64
|
"prettier": "^1.7.4"
|
|
63
65
|
},
|
|
64
66
|
"scripts": {
|