Compare commits

..

No commits in common. "137793cd774841256a71805fec9badb0bb6add26" and "c9c70d9be6ad4920c01f306fa800ecf7620a99f0" have entirely different histories.

2 changed files with 46 additions and 83 deletions

View File

@ -1,68 +0,0 @@
// caterpillar.js
// Integration with [Caterpillar Proxy](https://github.com/gnh1201/caterpillar) project
// https://github.com/gnh1201/welsonjs
var JSONRPC2 = require("lib/jsonrpc2");
function Caterpillar(url) {
var rpc = JSONRPC2.create(url);
var env = {
"target": "http://localhost/",
"method": ""
};
this.set_env = function(k, v) {
env[k] = v || null;
};
this.set_default_env = function(_env) {
for (k in _env) {
if (!(k in env)) {
env[k] = _env[k];
}
}
};
this.set_method = function(method) {
this.set_env("method", method);
if (env.method == "relay_mysql_query") {
this.set_default_env({
"mysql_hostname": "localhost",
"mysql_username": "root",
"mysql_password": null,
"mysql_database": null,
"mysql_port": "3306",
"mysql_charset": "utf8"
});
return;
}
}
this.exec = function() {
var args = arguments;
if (env.method == "relay_mysql_query") {
var query = arguments.join(' ');
rpc.invoke(env.method, {
"hostname": env.mysql_hostname,
"username": env.mysql_username,
"password": env.mysql_password,
"database": env.mysql_database,
"port": env.mysql_port,
"charset": env.mysql_charset,
"query": query
}, null);
return;
}
rpc.invoke(env.method, {}, null);
}
}
function create(url) {
return new Caterpillar(url);
}
exports.create = create;
exports.VERSIONINFO = "Caterpillar Proxy Integration (caterpillar.js) version 0.1.1";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;

View File

@ -3,9 +3,47 @@
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
var HTTP = require("lib/http"); var HTTP = require("lib/http");
function jsonrpc2(url) { function encode(method, params, id) {
this.url = url; var data = {
this.invoke = function(method, params, id) { "jsonrpc": "2.0",
"method": method,
"params": params,
"id": id
};
return JSON.stringify(data);
}
function resultEncode(result, id) {
var data = {
"jsonrpc": "2.0",
"result": result
"id": id
};
return JSON.stringify(data);
}
function errorEncode(error, id) {
var data = {
"jsonrpc": "2.0",
"error": error,
"id": id
}
return JSON.stringify(data);
}
// See also: https://github.com/gnh1201/caterpillar
function JsonRpcObject() {
this.url = "http://localhost:5555";
this.setUrl = function(url) {
this.url = url;
return this;
}
this.call = function(method, params, id) {
var result; var result;
var response = HTTP.create("MSXML") var response = HTTP.create("MSXML")
.setContentType("application/json") .setContentType("application/json")
@ -29,23 +67,16 @@ function jsonrpc2(url) {
} }
} }
function encode(method, params, id) { function create() {
return JSON.stringify({ return new JsonRpcObject();
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": id
});
}
function create(url) {
return new jsonrpc2(url);
} }
exports.encode = encode; exports.encode = encode;
exports.resultEncode = resultEncode;
exports.errorEncode = errorEncode;
exports.create = create; exports.create = create;
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.2"; exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;