Compare commits

..

5 Commits

Author SHA1 Message Date
137793cd77
Update caterpillar.js
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
2024-06-26 17:18:36 +09:00
27636a4a72
Update jsonrpc2.js 2024-06-26 17:17:15 +09:00
d86c9728e3
Update caterpillar.js 2024-06-26 17:16:35 +09:00
7de4e4f1be
Create caterpillar.js 2024-06-26 17:07:52 +09:00
3733eaea45
Update jsonrpc2.js 2024-06-26 16:37:04 +09:00
2 changed files with 83 additions and 46 deletions

68
lib/caterpillar.js Normal file
View File

@ -0,0 +1,68 @@
// 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,47 +3,9 @@
// https://github.com/gnh1201/welsonjs // https://github.com/gnh1201/welsonjs
var HTTP = require("lib/http"); var HTTP = require("lib/http");
function encode(method, params, id) { function jsonrpc2(url) {
var data = { this.url = url;
"jsonrpc": "2.0", this.invoke = function(method, params, id) {
"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")
@ -67,16 +29,23 @@ function JsonRpcObject() {
} }
} }
function create() { function encode(method, params, id) {
return new JsonRpcObject(); return JSON.stringify({
"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"; exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.2";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;