oncrpc
Version:
Library for creating ONC RPC Node.js servers and clients
117 lines (84 loc) • 2.63 kB
JavaScript
// Copyright 2013 Joyent, Inc. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
var util = require('util');
var assert = require('assert-plus');
var clone = require('clone');
var RpcServer = require('../server').RpcServer;
var PortmapGetPortCall = require('./get_port_call').PortmapGetPortCall;
var PortmapGetPortReply = require('./get_port_reply').PortmapGetPortReply;
var PortmapDumpReply = require('./dump_reply').PortmapDumpReply;
var PortmapSetCall = require('./set_call').PortmapSetCall;
var PortmapSetReply = require('./set_reply').PortmapSetReply;
var PortmapUnsetCall = require('./unset_call').PortmapUnsetCall;
var PortmapUnsetReply = require('./unset_reply').PortmapUnsetReply;
///--- Globals
var slice = Function.prototype.call.bind(Array.prototype.slice);
///--- API
function PortmapServer(opts) {
assert.object(opts, 'options');
if (opts.log) {
var l = opts.log;
delete opts.log;
}
var _opts = clone(opts);
_opts.log = opts.log = l;
_opts.name = 'portmap';
_opts.program = 100000;
_opts.version = 2;
RpcServer.call(this, _opts);
}
util.inherits(PortmapServer, RpcServer);
PortmapServer.prototype.set = function set() {
var cfg = {
name: 'set',
procedure: 1,
call: PortmapSetCall,
reply: PortmapSetReply
};
this._mount(cfg, slice(arguments));
return (this);
};
PortmapServer.prototype.unset = function unset() {
var cfg = {
name: 'unset',
procedure: 2,
call: PortmapUnsetCall,
reply: PortmapUnsetReply
};
this._mount(cfg, slice(arguments));
return (this);
};
PortmapServer.prototype.get_port = function get_port() {
var cfg = {
name: 'get_port',
procedure: 3,
call: PortmapGetPortCall,
reply: PortmapGetPortReply
};
this._mount(cfg, slice(arguments));
return (this);
};
PortmapServer.prototype.dump = function dump() {
var cfg = {
name: 'dump',
procedure: 4,
reply: PortmapDumpReply
};
this._mount(cfg, slice(arguments));
return (this);
};
PortmapServer.prototype.start = function start(host, cb) {
var args = slice(arguments);
args.unshift(111);
this.listen.apply(this, args);
};
///--- Exports
module.exports = {
PortmapServer: PortmapServer,
createPortmapServer: function createPortmapServer(opts) {
return (new PortmapServer(opts));
}
};