Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ChangeGC #86

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/simple/text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"freetype2_render": "~0.1.2"
"freetype2_render": "1.3.11"
}
}
140 changes: 66 additions & 74 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,79 @@ var Buffer = require('buffer').Buffer;
// add 'unpack' method for buffer
require('./unpackbuffer').addUnpack(Buffer);

function parseXauth( buf )
{
var offset = 0;
var auth = [];
var cookieProperties = ['address', 'display', 'authName', 'authData'];
function parseXauth(buf) {
var offset = 0;
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;
}
function handleCookieProperty(property) {
var length = buf.unpack('n', offset)[0];
offset += 2;
cookie[property] = buf.unpackString(length, offset);
offset += length;
}

while (offset < buf.length)
{
var cookie = {};
var typeToName = {
256: 'Local',
65535: 'Wild',
254: 'Netname',
253: 'Krb5Principal',
252: 'LocalHost',
0: 'Internet',
1: 'DECnet',
2: 'Chaos',
5: 'ServerInterpreted',
6: 'InternetV6'
};
cookie.type = buf.unpack('n')[0];
if (!typeToName[cookie.type]) {
console.warn('Unknown address type');
}
offset += 2;
//JSHint becomes angry when handleCookieProperty is declared inside loop
cookieProperties.forEach(handleCookieProperty);
auth.push(cookie);
while (offset < buf.length) {
var cookie = {};
var typeToName = {
256 : 'Local',
65535: 'Wild',
254 : 'Netname',
253 : 'Krb5Principal',
252 : 'LocalHost',
0 : 'Internet',
1 : 'DECnet',
2 : 'Chaos',
5 : 'ServerInterpreted',
6 : 'InternetV6'
};
cookie.type = buf.unpack('n')[0];
if (!typeToName[cookie.type]) {
console.warn('Unknown address type');
}
return auth;
offset += 2;
//JSHint becomes angry when handleCookieProperty is declared inside loop
cookieProperties.forEach(handleCookieProperty);
auth.push(cookie);
}
return auth;
}

module.exports = function( display, host, cb )
{
var XAuthorityFile = process.env.XAUTHORITY;
if (!XAuthorityFile)
{
if ( process.platform.match(/win/) ) {
// http://www.straightrunning.com/XmingNotes/trouble.php
//
// The Xming magic cookie program, xauth (user-based), uses an
// Xauthority file (not the traditional .Xauthority file) in
// the %HOME% directory. To use xauth from Command Processor
// e.g. on Windows machine 192.168.0.2 with user colin...
XAuthorityFile = process.env.USERPROFILE + '\\Xauthority';
} else {
XAuthorityFile = process.env.HOME + '/.Xauthority';
}
module.exports = function(display, host, cb) {
var XAuthorityFile = process.env.XAUTHORITY;
if (!XAuthorityFile) {
if (process.platform.match(/^win/)) {
// http://www.straightrunning.com/XmingNotes/trouble.php
//
// The Xming magic cookie program, xauth (user-based), uses an
// Xauthority file (not the traditional .Xauthority file) in
// the %HOME% directory. To use xauth from Command Processor
// e.g. on Windows machine 192.168.0.2 with user colin...
XAuthorityFile = process.env.USERPROFILE + '\\Xauthority';
} else {
XAuthorityFile = process.env.HOME + '/.Xauthority';
}
}

fs.readFile(XAuthorityFile, function (err, data) {
fs.readFile(XAuthorityFile, function(err, data) {

if (err)
{
if (err.code == 'ENOENT')
{
cb('','');
return;
}
throw err;
}
if (err) {
if (err.code == 'ENOENT') {
cb('', '');
return;
}
throw err;
}

var auth = parseXauth(data);
for (var cookieNum in auth)
{
var cookie = auth[cookieNum];
if (cookie.display == display && cookie.address == host)
{
cb( cookie.authName, cookie.authData );
return;
}
}
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
cb( '', '' );
});
var auth = parseXauth(data);
for (var cookieNum in auth) {
var cookie = auth[cookieNum];
if (cookie.display == display && cookie.address == host) {
cb(cookie.authName, cookie.authData);
return;
}
}
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
cb('', '');
});
};
Loading