mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
commit
be8079d540
2 changed files with 26 additions and 21 deletions
34
lib/auth.js
34
lib/auth.js
|
|
@ -9,6 +9,14 @@ function parseXauth( buf )
|
||||||
{
|
{
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
var auth = [];
|
var auth = [];
|
||||||
|
var cookieProperties = ['address', 'display', 'authName', 'authData'];
|
||||||
|
|
||||||
|
function handleCookieProperty(property) {
|
||||||
|
var length = buf.unpack('n', offset)[0];
|
||||||
|
offset += 2;
|
||||||
|
cookie[property] = buf.unpackString(length, offset);
|
||||||
|
offset += length;
|
||||||
|
}
|
||||||
|
|
||||||
while (offset < buf.length)
|
while (offset < buf.length)
|
||||||
{
|
{
|
||||||
|
|
@ -22,28 +30,16 @@ function parseXauth( buf )
|
||||||
0: 'Internet',
|
0: 'Internet',
|
||||||
1: 'DECnet',
|
1: 'DECnet',
|
||||||
2: 'Chaos',
|
2: 'Chaos',
|
||||||
5: 'ServerInterpreted',
|
5: 'ServerInterpreted',
|
||||||
6: 'InternetV6'
|
6: 'InternetV6'
|
||||||
};
|
};
|
||||||
cookie.type = buf.unpack('n')[0];
|
cookie.type = buf.unpack('n')[0];
|
||||||
|
if (!typeToName[cookie.type]) {
|
||||||
|
console.warn('Unknown address type');
|
||||||
|
}
|
||||||
offset += 2;
|
offset += 2;
|
||||||
// TODO: rewrite following using loop (16bits length + string data)
|
//JSHint becomes angry when handleCookieProperty is declared inside loop
|
||||||
var addressLen = buf.unpack('n', offset)[0];
|
cookieProperties.forEach(handleCookieProperty);
|
||||||
offset += 2;
|
|
||||||
cookie.address = buf.unpackString(addressLen, offset);
|
|
||||||
offset += addressLen;
|
|
||||||
var displayNumLen = buf.unpack('n', offset)[0];
|
|
||||||
offset += 2;
|
|
||||||
cookie.display = buf.unpackString(displayNumLen, offset);
|
|
||||||
offset += displayNumLen;
|
|
||||||
var authNameLen = buf.unpack('n', offset)[0];
|
|
||||||
offset += 2;
|
|
||||||
cookie.authName = buf.unpackString(authNameLen, offset);
|
|
||||||
offset += authNameLen;
|
|
||||||
var authDataLen = buf.unpack('n', offset)[0];
|
|
||||||
offset += 2;
|
|
||||||
cookie.authData = buf.unpackString(authDataLen, offset);
|
|
||||||
offset += authDataLen;
|
|
||||||
auth.push(cookie);
|
auth.push(cookie);
|
||||||
}
|
}
|
||||||
return auth;
|
return auth;
|
||||||
|
|
@ -92,4 +88,4 @@ module.exports = function( display, host, cb )
|
||||||
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
|
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
|
||||||
cb( '', '' );
|
cb( '', '' );
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
|
||||||
|
|
@ -180,10 +180,19 @@ bl.unpack('C', function(res) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getByteOrder() {
|
||||||
|
var isLittleEndian = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201);
|
||||||
|
if (isLittleEndian) {
|
||||||
|
return 'l'.charCodeAt(0);
|
||||||
|
} else {
|
||||||
|
return 'B'.charCodeAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function writeClientHello(stream, displayNum, authHost)
|
function writeClientHello(stream, displayNum, authHost)
|
||||||
{
|
{
|
||||||
getAuthString( displayNum, authHost, function( authType, authData ) {
|
getAuthString( displayNum, authHost, function( authType, authData ) {
|
||||||
var byte_order = 'l'.charCodeAt(0); // TODO: byteorder!!!
|
var byte_order = getByteOrder();
|
||||||
var protocol_major = 11; // TODO: config? env?
|
var protocol_major = 11; // TODO: config? env?
|
||||||
var protocol_minor = 0;
|
var protocol_minor = 0;
|
||||||
stream.pack(
|
stream.pack(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue