Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var manifest2policy = function(manifestFile, appId, features) {
var manifest = null;
try {
var xmlManifest = fs.readFileSync(manifestFile);
// Load xml parser
var xmlParser = new xml2js.Parser(xml2js.defaults["0.2"]);
// Parse manifest
xmlParser.parseString(xmlManifest, function(err, data) {
if (err === undefined || err === null) {
manifest = data['widget'];
} else {
console.log(err);
return '';
}
});
} catch (error) {
console.log(error);
return '';
}
// target
var target = [];
req.get(reqParams, function (e, res, body) {
if (e || res.statusCode != 200) {
return callback(body, null);
}
var spJs = body;
var xml2jsSettings = xml2js.defaults['0.2'];
// these determine what happens if the xml contains attributes
xml2jsSettings.attrkey = '$';
xml2jsSettings.charkey = '_';
// from xml2js guide: always put child nodes in an array if true; otherwise an array is created only if there is more than one.
xml2jsSettings.explicitArray = false;
var parser = new xml2js.Parser(xml2jsSettings);
body = body.toString();
if (body.charCodeAt(0) === 0xfeff || body.charCodeAt(0) === 0xffef) {
body = body.substring(1);
}
parser.parseString(body, function (err, parsedBody) {
if (err) {
return callback(err, null);
}
StorageServiceClient._getDefaultXml2jsSettings = function() {
var xml2jsSettings = _.clone(xml2js.defaults['0.2']);
// these determine what happens if the xml contains attributes
xml2jsSettings.attrkey = Constants.TableConstants.XML_METADATA_MARKER;
xml2jsSettings.charkey = Constants.TableConstants.XML_VALUE_MARKER;
// from xml2js guide: always put child nodes in an array if true; otherwise an array is created only if there is more than one.
xml2jsSettings.explicitArray = false;
return xml2jsSettings;
};
var policyEditor = function(policy, pmInstance) {
console.log("Policy editor constructor");
var pm = pmInstance;
var policyFile = policy;
var policySet = null;
//Load the xml parser
var xmlParser = new xml2js.Parser(xml2js.defaults["0.2"]);
this.addRule = function(request, decision) {
//console.log("\nPolicy Editor - addRule");
var newTarget = createNewTarget(request);
var newRule = createNewRule(request, decision);
loadPolicy(function(){
insertRule(newTarget, newRule);
savePolicy();
});
//pm.reloadPolicy();
}
this.removeRule = function() {
}
this.parseXMLFile= function(fileName, callback) {
var xml2js = require('xml2js');
var xmlParser = new xml2js.Parser(xml2js.defaults["0.2"]);
var data = fs.readFileSync(fileName);
var result = xmlParser.parseString(data, function(err, xmlData) {
if(!err) {
callback(xmlData);
}
});
}
};
},
pswd: {
type: 'string',
required: true
},
userid: {
type: 'string',
required: true
}
}
}, true);
var result = JSONSchema.validate(json, schema);
if (!result.valid) throw new Error(result.errors);
this.query = Object.clone(json) || {};
this.url = url;
this.parser = new xml2js.Parser(xml2js.defaults['0.1']);
}
child_process("mediainfo --Output=XML " + directoryPath, function (error, stderr, stdout) {
if (!error) {
var xmlParser = new xml2js.Parser(xml2js.defaults["0.2"]);
xmlParser.parseString(stderr, function(err, xmlData) {
if(!err){
callback(id, xmlData);
}
});
}
});
}
function parseResult(body, contentElementName) {
if (!body) {
return;
}
var settings = _.clone(xml2js.defaults['0.1']);
settings.explicitRoot = true;
var parser = new xml2js.Parser(settings);
var parsedResult;
parser.addListener('end', function (result) {
parsedResult = result;
});
parser.parseString(body);
if (parsedResult.feed) {
return parseFeedResult(parsedResult.feed, contentElementName);
}
if (parsedResult.entry) {
return parseEntryResult(parsedResult.entry, contentElementName);
}
}, function(err, response, body){
if (err) {
return cb( err );
} else if( response.statusCode === 401 ) {
return cb( new Error("Invalid authorization key."));
} else if ( response.statusCode >= 400 ) {
return cb( new Error("HTTP error " + response.statusCode + ": " + http.STATUS_CODES[response.statusCode]));
}
if ( body ){
var parser = new xml2js.Parser(xml2js.defaults["0.1"]);
parser.on("end", function(result) {
cb( null, result, body );
});
parser.on("error", function(err) {
cb( err );
});
parser.parseString(body);
} else {
if ( err ) cb( err );
else cb( null, true );
}
})
}
ServiceClient._getDefaultXml2jsSettings = function() {
var xml2jsSettings = _.clone(xml2js.defaults['0.2']);
xml2jsSettings.normalize = false;
xml2jsSettings.trim = false;
xml2jsSettings.attrkey = Constants.XML_METADATA_MARKER;
xml2jsSettings.charkey = Constants.XML_VALUE_MARKER;
xml2jsSettings.explicitArray = false;
return xml2jsSettings;
};