diff --git a/exec/load/finger_lib.js b/exec/load/finger_lib.js new file mode 100644 index 0000000000000000000000000000000000000000..85964687befe273e8ebce58fc6e6014113d6b3b6 --- /dev/null +++ b/exec/load/finger_lib.js @@ -0,0 +1,35 @@ +// $Id$ + +// A Finger/SYSTAT client library + +"use strict"; + +require('sockdefs.js', 'SOCK_DGRAM'); +require('portdefs.js', 'standard_service_port'); + +// Returns a String on failure, an Array of lines on success +function request(host, query, protocol, udp) +{ + if (protocol === undefined) + protocol = "finger"; + var sock = new Socket(udp === true ? SOCK_DGRAM : SOCK_STREAM); + if(!sock.connect(host, standard_service_port[protocol])) + return "Connection to " + host + " failed with error " + sock.last_error; + if(query !== undefined) + sock.send(query + "\r\n"); + var output = []; + if(udp) { + output.push(sock.recvfrom().data); + } + else { + while(sock.is_connected && !js.terminated) { + var line = sock.readline(); + if(line != null) + output.push(line); + } + } + sock.close(); + return output; +} + +this; \ No newline at end of file