Socket
Socket
Sign inDemoInstall

virtualbox-soap

Package Overview
Dependencies
94
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

.prettierignore

492

generate-index.js

@@ -21,170 +21,210 @@ /*

const xidlParser = function () {
const saxStream = sax.createStream(true);
const stack = [];
const interfaces = Object.create(null);
const enums = Object.create(null);
const results = Object.create(null)
const basicTypes = Object.create(null);
const xidlParser = function() {
const saxStream = sax.createStream(true);
const stack = [];
const interfaces = Object.create(null);
const enums = Object.create(null);
const results = Object.create(null);
const typesMap = {
wstring: "string",
boolean: "boolean",
short: "number",
"unsigned short": "number",
long: "number",
"long long": "number",
"unsigned long": "number",
uuid: "string"
};
const checkParent = function (nodeName) {
return stack[stack.length - 1].name === nodeName;
};
const checkParent = function(nodeName) {
return stack[stack.length - 1].name === nodeName;
};
const getParentNode = function (nodeName) {
for (let i = stack.length - 1; i >= 0 ; i--) {
let curNode = stack[i];
if (curNode.name === nodeName) {
return curNode;
}
const getParentNode = function(nodeName) {
for (let i = stack.length - 1; i >= 0; i--) {
let curNode = stack[i];
if (curNode.name === nodeName) {
return curNode;
}
}
return null;
};
const tagHandlers = {
idl: function(node) {},
library: function(node) {
node.skip = !checkParent("idl");
},
result: function(node) {
if (checkParent("library")) {
const attributes = node.attributes;
results[attributes.name] = attributes.value;
} else {
node.skip = true;
}
},
if: function(node) {
node.skip = node.attributes.target !== "wsdl";
},
interface: function(node) {
const attributes = node.attributes;
const name = attributes.name;
const parentInterfaceName = attributes.extends;
const parentInterface = parentInterfaceName
? interfaces[parentInterfaceName] || null
: null;
if (
parentInterfaceName &&
!parentInterface &&
parentInterfaceName !== "$unknown" &&
parentInterfaceName !== "$errorinfo"
) {
throw new Error(
`Unknown parent interface: ${parentInterfaceName} for ${name}`
);
}
const interfaceObject = {
name: name,
parent: parentInterface,
methods: []
};
interfaces[name] = interfaceObject;
node.object = interfaceObject;
},
method: function(node) {
const interfaceObject = getParentNode("interface").object;
const methodObject = {
name: node.attributes.name,
in: [],
out: [],
returnval: null
};
interfaceObject.methods.push(methodObject);
node.object = methodObject;
},
const: function(node) {
const enumObject = getParentNode("enum").object;
const name = node.attributes.name;
const value = node.attributes.value;
enumObject.values[name] = value;
},
enum: function(node) {
const name = node.attributes.name;
node.object = enums[name] = {
name: name,
values: {}
};
},
param: function(node) {
const methodObject = getParentNode("method").object;
const attributes = node.attributes;
const dir = attributes.dir;
const paramObject = {
name: attributes.name,
type: attributes.type,
array: attributes.safearray === "yes"
};
if (dir === "in") {
methodObject.in.push(paramObject);
} else if (dir === "out") {
methodObject.out.push(paramObject);
} else if (dir === "return") {
methodObject.returnval = paramObject;
} else {
throw new Error(`Invalid dir: ${dir}`);
}
},
attribute: function(node) {
const interfaceObject = getParentNode("interface").object;
const attributes = node.attributes;
const name = attributes.name;
if (name == "midlDoesNotLikeEmptyInterfaces") {
return;
}
const type = attributes.type;
const baseName = name[0].toUpperCase() + name.slice(1);
interfaceObject.methods.push({
name: "get" + baseName,
in: [],
out: [],
returnval: {
name: name,
type: type,
array: attributes.safearray === "yes"
}
return null;
};
const tagHandlers = {
"idl" : function (node) {},
"library" : function (node) {
node.skip = !checkParent("idl");
},
"result" : function (node) {
if (checkParent("library")) {
const attributes = node.attributes;
results[attributes.name] = attributes.value;
} else {
node.skip = true;
});
if (attributes.readonly !== "yes") {
interfaceObject.methods.push({
name: "set" + baseName,
in: [
{
name: name,
type: type,
array: attributes.safearray === "yes"
}
},
"if": function (node) {
node.skip = (node.attributes.target !== "wsdl");
},
"interface": function (node) {
const attributes = node.attributes;
const name = attributes.name;
const parentInterfaceName = attributes.extends;
const parentInterface = parentInterfaceName ? interfaces[parentInterfaceName] || null : null;
if (parentInterfaceName && !parentInterface && parentInterfaceName !== "$unknown" && parentInterfaceName !== "$errorinfo") {
throw new Error(`Unknown parent interface: ${parentInterfaceName} for ${name}`);
}
const interfaceObject = {
name: name,
parent: parentInterface,
methods: []
};
interfaces[name] = interfaceObject;
node.object = interfaceObject;
},
"method" : function (node) {
const interfaceObject = getParentNode("interface").object;
const methodObject = {
name: node.attributes.name,
in: [],
out: [],
returnval: null
};
interfaceObject.methods.push(methodObject);
node.object = methodObject;
},
"enum" : function (node) {
const name = node.attributes.name;
enums[name] = {
name: name
};
},
"param" : function (node) {
const methodObject = getParentNode("method").object;
const attributes = node.attributes;
const dir = attributes.dir;
const paramObject = {
name: attributes.name,
type: attributes.type,
array: attributes.safearray === "yes"
};
if (dir === "in") {
methodObject.in.push(paramObject);
} else if (dir === "out") {
methodObject.out.push(paramObject);
} else if (dir === "return") {
methodObject.returnval = paramObject;
} else {
throw new Error(`Invalid dir: ${dir}`);
}
},
"attribute": function (node) {
const interfaceObject = getParentNode("interface").object;
const attributes = node.attributes;
const name = attributes.name;
if (name == "midlDoesNotLikeEmptyInterfaces") {
return;
}
const type = attributes.type;
const baseName = name[0].toUpperCase() + name.slice(1);
interfaceObject.methods.push({
name: "get" + baseName,
in: [],
out: [],
returnval: {
name: name,
type: type,
array: attributes.safearray === "yes"
}
});
if (attributes.readonly !== "yes") {
interfaceObject.methods.push({
name: "set" + baseName,
in: [{
name: name,
type: type,
array: attributes.safearray === "yes"
}],
out: [],
returnval: null
});
}
}
};
],
out: [],
returnval: null
});
}
}
};
saxStream.on("opentag", function (node) {
const skip = stack.length > 0 ? stack[stack.length - 1].skip : false;
const tagHandler = tagHandlers[node.name];
if (tagHandler && !skip) {
tagHandler(node);
} else {
node.skip = true;
}
stack.push(node);
});
saxStream.on("opentag", function(node) {
const skip = stack.length > 0 ? stack[stack.length - 1].skip : false;
const tagHandler = tagHandlers[node.name];
if (tagHandler && !skip) {
tagHandler(node);
} else {
node.skip = true;
}
stack.push(node);
});
saxStream.on("closetag", function () {
const node = stack.pop();
});
saxStream.on("closetag", function() {
stack.pop();
});
const wrapReturnValue = function (param) {
let value = `__result.${param.name}`;
const type = param.type;
if (interfaces[type]) {
if (param.array) {
value = `__result.${param.name} ? __result.${param.name}.map(object => new virtualbox.${type}(this.__client, object)) : []`;
} else {
value = `__result.${param.name} ? new virtualbox.${type}(this.__client, __result.${param.name}) : null`;
}
}
return value;
};
const wrapReturnValue = function(param) {
let value = `__result.${param.name}`;
const type = param.type;
if (interfaces[type]) {
if (param.array) {
value = `__result.${param.name} ? __result.${
param.name
}.map((object: any) => new ${type}(this.__client, object)) : []`;
} else {
value = `__result.${param.name} ? new ${type}(this.__client, __result.${
param.name
}) : null`;
}
}
return `(${value}) as ${getParamType(param)}`;
};
const unwrapInputValue = function (param) {
let value = '$' + param.name;
const type = param.type;
if (interfaces[type]) {
if (param.array) {
value = `${value} ? ${value}.map(object => object.__object) : null`;
} else {
value = `${value} ? ${value}.__object : null`;
}
}
return value;
};
const unwrapInputValue = function(param) {
let value = "$" + param.name;
const type = param.type;
if (interfaces[type]) {
if (param.array) {
value = `${value} ? ${value}.map((object: any) => object.__object) : null`;
} else {
value = `${value} ? (${value} as any).__object : null`;
}
}
return value;
};
saxStream.on("end", function () {
const output = [
`/*
const getParamType = function(param) {
const type = param.type;
let res = typesMap[type];
if (!res && (interfaces[type] || enums[type])) {
res = type;
}
return `${res || "any"}${param.array ? "[]" : ""}`;
};
saxStream.on("end", function() {
const output = [
`/*
* Copyright 2015 Amadeus s.a.s.

@@ -203,27 +243,16 @@ * Licensed under the Apache License, Version 2.0 (the "License");

*/
"use strict";
const path = require("path");
const soap = require("soap");
const virtualbox = module.exports = function (endpoint) {
return new Promise((resolve, reject) => {
soap.createClient(path.join(__dirname, "sdk-files", "vboxwebService.wsdl"), {
endpoint: endpoint
}, function (error, client) {
if (error) {
reject(error);
} else {
resolve(new virtualbox.IWebsessionManager(client.vboxService.vboxServicePort));
}
});
import * as path from "path";
import * as soap from "soap";
export async function connect (endpoint: string) {
const client: any = await soap.createClientAsync(path.join(__dirname, "sdk-files", "vboxwebService.wsdl"), {
endpoint: endpoint
});
};
return new IWebsessionManager(client.vboxService.vboxServicePort);
}
const errorCodeRegExp = /rc=0x([0-9a-f]{8})/;
const RootClass = class {
constructor(__client, __object) {
this.__client = __client;
this.__object = __object;
}
__invoke(name, args) {
export class RootClass {
constructor(protected __client: any, protected __object?: any) {}
protected __invoke(name: string, args: any): Promise<any> {
return new Promise((resolve, reject) => {
this.__client[name](args, (error, result) => {
this.__client[name](args, (error: any, result: any) => {
if (error) {

@@ -244,43 +273,70 @@ if (error.root && error.root.Envelope && error.root.Envelope.Body && error.root.Envelope.Body.Fault && error.root.Envelope.Body.Fault.faultstring) {

}
};`
];
Object.keys(interfaces).forEach(function(interfaceName) {
const interfaceObject = interfaces[interfaceName];
const parentClass = interfaceObject.parent ? `virtualbox.${interfaceObject.parent.name}` : "RootClass";
output.push(`virtualbox.${interfaceObject.name} = class extends ${parentClass} {`);
interfaceObject.methods.forEach(function (method) {
const args = method.in.map(param => `${JSON.stringify(param.name)}: ${unwrapInputValue(param)}`);
const skipThis = interfaceName === "IWebsessionManager";
if (!skipThis) {
args.push(`"_this": this.__object`);
}
if (method.returnval) {
method.returnval.name = "returnval";
}
if (method.returnval && method.out.length > 0) {
method.out.push(method.returnval);
method.returnval = null;
}
let returnBody = "null";
if (method.returnval) {
returnBody = wrapReturnValue(method.returnval);
} else if (method.out.length > 0) {
returnBody = `({${method.out.map(param => `${JSON.stringify(param.name)}: ${wrapReturnValue(param)}`)}})`
}
output.push(` ${method.name}(${method.in.map(param => '$' + param.name).join(', ')}) {`);
output.push(` return this.__invoke(${JSON.stringify(`${interfaceObject.name}_${method.name}`)}, {${args.join(",")}}).then(__result => ${returnBody});`);
output.push(` }`);
});
output.push(`};`);
});
Object.keys(results).forEach(function (keyName) {
output.push(`virtualbox.${keyName} = ${results[keyName]};`);
});
fs.writeFile(path.join(__dirname, "index.js"), output.join("\n"));
}`
];
Object.keys(enums).forEach(function(keyName) {
output.push(`export const enum ${keyName} {`);
const enumInfo = enums[keyName];
const values = enumInfo.values;
Object.keys(values).forEach(function(enumName) {
output.push(`${enumName} = ${JSON.stringify(enumName)},`);
});
output.push(`}`);
});
Object.keys(interfaces).forEach(function(interfaceName) {
const interfaceObject = interfaces[interfaceName];
const parentClass = interfaceObject.parent
? interfaceObject.parent.name
: "RootClass";
output.push(
`export class ${interfaceObject.name} extends ${parentClass} {`
);
interfaceObject.methods.forEach(function(method) {
const args = method.in.map(
param => `${JSON.stringify(param.name)}: ${unwrapInputValue(param)}`
);
const skipThis = interfaceName === "IWebsessionManager";
if (!skipThis) {
args.push(`"_this": this.__object`);
}
if (method.returnval) {
method.returnval.name = "returnval";
}
if (method.returnval && method.out.length > 0) {
method.out.push(method.returnval);
method.returnval = null;
}
let returnBody = "null";
if (method.returnval) {
returnBody = wrapReturnValue(method.returnval);
} else if (method.out.length > 0) {
returnBody = `({${method.out.map(
param => `${JSON.stringify(param.name)}: ${wrapReturnValue(param)}`
)}})`;
}
output.push(
` ${method.name}(${method.in
.map(param => `$${param.name}: ${getParamType(param)}`)
.join(", ")}) {`
);
output.push(
` return this.__invoke(${JSON.stringify(
`${interfaceObject.name}_${method.name}`
)}, {${args.join(",")}}).then(__result => ${returnBody});`
);
output.push(` }`);
});
output.push(`}`);
});
Object.keys(results).forEach(function(keyName) {
output.push(`export const ${keyName} = ${results[keyName]};`);
});
fs.writeFileSync(path.join(__dirname, "index.ts"), output.join("\n"));
});
return saxStream;
return saxStream;
};
const p = xidlParser();
fs.createReadStream(path.join(__dirname, "sdk-files", "VirtualBox.xidl")).pipe(p);
fs.createReadStream(path.join(__dirname, "sdk-files", "VirtualBox.xidl")).pipe(
p
);
{
"author": "ariatemplates <contact@ariatemplates.com> (http://github.com/ariatemplates)",
"name": "virtualbox-soap",
"version": "1.0.0",
"version": "2.0.0",
"description": "A wrapper for the SOAP API of Virtual Box.",

@@ -13,14 +13,19 @@ "repository": {

"test": "node index.js",
"prepublish": "node generate-index"
"generate-index": "node generate-index",
"tsc": "tsc",
"prepare": "npm run generate-index && npm run tsc",
"format": "prettier '*.{ts,js,json}'",
"format:check": "npm run format -- --check",
"format:fix": "npm run format -- --write"
},
"license": "Apache-2.0",
"devDependencies": {
"sax": "^1.1.4"
"@types/node": "11.13.5",
"prettier": "1.17.0",
"sax": "1.2.4",
"typescript": "3.4.3"
},
"dependencies": {
"soap": "^0.11.1"
},
"engines": {
"node": ">=4.2"
"soap": "0.26.0"
}
}
# virtualbox-soap
`virtualbox-soap` allows to easily use the [VirtualBox API](https://www.virtualbox.org/sdkref) from [nodejs](https://nodejs.org).
It requires nodejs version 4.2 or later.

@@ -10,6 +9,6 @@ It is designed to connect to VirtualBox through the SOAP protocol (over HTTP), which means that the `VBoxWebSrv` executable (which is included with VirtualBox) needs to be started on the machine where VirtualBox is installed.

Install `virtualbox-soap` and `co` from the npm repository:
Install `virtualbox-soap` from the npm repository:
```bash
npm install virtualbox-soap co
npm install virtualbox-soap
```

@@ -26,16 +25,14 @@

```js
"use strict";
const virtualbox = require("virtualbox");
const co = require("co");
import * as virtualbox from "virtualbox-soap";
co(function *() {
(async function () {
try {
const serverURL = "http://localhost:18083"; // This url is the default one, it can be omitted
const websessionManager = yield virtualbox(serverURL);
const vbox = yield websessionManager.logon("username", "password");
const machine = yield vbox.findMachine("myMachineNameOrId");
const session = yield websessionManager.getSessionObject(vbox);
const progress = yield machine.launchVMProcess(session);
yield progress.waitForCompletion(-1);
const machineState = yield machine.getState();
const websessionManager = await virtualbox.connect(serverURL);
const vbox = await websessionManager.logon("username", "password");
const machine = await vbox.findMachine("myMachineNameOrId");
const session = await websessionManager.getSessionObject(vbox);
const progress = await machine.launchVMProcess(session);
await progress.waitForCompletion(-1);
const machineState = await machine.getState();
console.log(`The virtual machine is ${machineState}`);

@@ -46,3 +43,3 @@ // ...

}
});
})();
```

@@ -49,0 +46,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc