Skip to content
Browse files

remove obsolete/

  • Loading branch information...
1 parent a79bc66 commit 5a494141a999678e5a649ef6cb12884a450062a4 @jeromeetienne committed Aug 24, 2010
View
176 obsolete/lib.old/base64.js
@@ -1,176 +0,0 @@
-/**
- * - this file provide a way to encode/decode base64 using the url-self alphabet
- * - it is used to build the dupuri in the nested uri
- * - adapted to use the base64 safe alphabet
- * - rfc3548.4 "Base 64 Encoding with URL and Filename Safe Alphabet"
- * - this source has been taken from http://www.webtoolkit.info/
- * - the license is unknown aka unspecified
- * - TODO put this in the neoip namespace
-**/
-
-
-/**
-*
-* Base64 encode / decode
-* http://www.webtoolkit.info/
-*
-**/
-
-var base64 = {
- // private property
- _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",
-
- // public method for encoding
- encode_safe : function (input) {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
-
- input = base64._utf8_encode(input);
-
- while (i < input.length) {
-
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
-
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
-
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
-
- output = output +
- base64._keyStr.charAt(enc1) + base64._keyStr.charAt(enc2) +
- base64._keyStr.charAt(enc3) + base64._keyStr.charAt(enc4);
-
- }
-
- return output;
- },
-
- // public method for decoding
- decode_safe : function (input) {
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
-
- input = input.replace(/[^A-Za-z0-9\-\_\=]/g, "");
-
- while (i < input.length) {
-
- enc1 = base64._keyStr.indexOf(input.charAt(i++));
- enc2 = base64._keyStr.indexOf(input.charAt(i++));
- enc3 = base64._keyStr.indexOf(input.charAt(i++));
- enc4 = base64._keyStr.indexOf(input.charAt(i++));
-
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
-
- output = output + String.fromCharCode(chr1);
-
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
-
- }
-
- output = base64._utf8_decode(output);
-
- return output;
-
- },
-
- // private method for UTF-8 encoding
- _utf8_encode : function (string) {
- string = string.replace(/\r\n/g,"\n");
- var utftext = "";
-
- for (var n = 0; n < string.length; n++) {
-
- var c = string.charCodeAt(n);
-
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
-
- }
-
- return utftext;
- },
-
- // private method for UTF-8 decoding
- _utf8_decode : function (utftext) {
- var string = "";
- var i = 0;
- var c = c1 = c2 = 0;
-
- while ( i < utftext.length ) {
-
- c = utftext.charCodeAt(i);
-
- if (c < 128) {
- string += String.fromCharCode(c);
- i++;
- }
- else if((c > 191) && (c < 224)) {
- c2 = utftext.charCodeAt(i+1);
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- }
- else {
- c2 = utftext.charCodeAt(i+1);
- c3 = utftext.charCodeAt(i+2);
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
-
- }
-
- return string;
- }
-
-}
-
-// export it via commonjs
-exports.base64 = base64;
-
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-// Main program - for unit testing
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-if( module === require.main ){
- var console = require('./firebug').console;
- console.log("Testing Started");
-
- var origin = "slota";
- var encoded = base64.encode_safe(origin);
- var decoded = base64.decode_safe(encoded);
- console.log("origin="+origin);
- console.log("encoded="+encoded);
- console.log("decoded="+decoded);
- console.assert(origin==decoded);
- console.log("Testing Done");
-}
View
284 obsolete/lib.old/casti_ctrl_t.js
@@ -1,284 +0,0 @@
-#!/usr/bin/env node
-
-var neoip_rpc = require('./neoip_rpc_node');
-var sys = require('sys');
-var underscore = require('../vendor/underscore/underscore')._; underscore.noConflict();
-
-/**
-*/
-var casti_ctrl_t = function(ctor_opts){
- //////////////////////////////////////////////////////////////////////////
- // class variables //
- //////////////////////////////////////////////////////////////////////////
- // alias 'this' for this object, to self
- var self = this;
- // copy ctor_opts + set default values if needed
- var call_url = ctor_opts.call_url || console.assert(false);
- var casti_opts = ctor_opts.casti_opts || console.assert(false);
- var event_cb = ctor_opts.event_cb || function(event_type, event_data){}
- var req_timer_delay = ctor_opts.req_timer_delay || 0.5*1000;
- var verbose = ctor_opts.verbose || 0;
- // private methods
- var cast_privhash = null;
-
- //////////////////////////////////////////////////////////////////////////
- // ctor/dtor //
- //////////////////////////////////////////////////////////////////////////
- var ctor = function(){
- rpc_call_request();
- }
- var dtor = function(){
- // destroy pending rpc_call if needed
- rpc_call_destroy();
- // stop the req_timer if needed
- req_timer_stop();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // misc //
- //////////////////////////////////////////////////////////////////////////
- var start_release = function(){
- // destroy pending rpc_call if needed
- rpc_call_destroy();
- // stop the req_timer if needed
- req_timer_stop();
- // launch_rpc_call_release
- rpc_call_release();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // req_timer //
- //////////////////////////////////////////////////////////////////////////
- var req_timer_id = null;
- var req_timer_start = function(delay){
- // if not specified, set delay to default value
- if( delay == undefined ) delay = req_timer_delay;
- console.assert(req_timer_id === null);
- req_timer_id = setTimeout(req_timer_cb, delay);
- }
- var req_timer_stop = function(){
- if( req_timer_id !== null ) clearTimeout(req_timer_id);
- req_timer_id = null;
- }
- var req_timer_refresh = function(){
- req_timer_stop();
- req_timer_start();
- }
- var req_timer_cb = function(){
- if( verbose > 1 ) console.log("req_timer expired. next in "+req_timer_delay+"-msec");
- rpc_call_request();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // rpc_call //
- //////////////////////////////////////////////////////////////////////////
- var rpc_call = null;
- var rpc_call_request = function(){
- // log to debug
- if( verbose > 1 ) console.log("rpc: rpc_call_request enter")
- // sanity check
- console.assert(rpc_call === null);
- // create the neoip_rpc.call
- var co = casti_opts;
- rpc_call = neoip_rpc.rpc_call.create({
- call_url : call_url,
- method_name : 'request_stream',
- method_args : [co.mdata_srv_uri, co.cast_name, co.cast_privtext, co.scasti_uri
- , co.scasti_mod, co.http_peersrc_uri, co.web2srv_str],
- success_cb : function(returned_val){
- rpc_call_destroy();
- req_timer_refresh();
- if(returned_val.length > 0){
- // mark this cast as "published"
- cast_privhash = returned_val;
- notify_event("ispublished", {cast_privhash: returned_val});
- }else{
- // mark this cast as "not published"
- cast_privhash = null;
- notify_event("nopublished", null);
- }
- },
- failure_cb : function(fault){
- // mark this cast as "not published"
- cast_privhash = null;
- if( verbose ) console.log("failure: "+require('sys').inspect(fault));
- rpc_call_destroy();
- notify_event("rpc_error", null);
- }
- });
- }
- var rpc_call_release = function(){
- // log to debug
- if( verbose > 1 ) console.log("rpc: rpc_call_release enter")
- // sanity check
- console.assert(rpc_call === null);
- // mark this cast as "not published"
- cast_privhash = null;
- // create the neoip_rpc.call
- var co = casti_opts;
- rpc_call = neoip_rpc.rpc_call.create({
- call_url : call_url,
- method_name : 'release_stream',
- method_args : [co.mdata_srv_uri, co.cast_name, co.cast_privtext],
- success_cb : function(returned_val){
- rpc_call_destroy();
- notify_event("released", null);
- },
- failure_cb : function(fault){
- if( verbose ) console.log("failure: "+require('sys').inspect(fault));
- rpc_call_destroy();
- notify_event("rpc_error", null);
- }
- });
- }
- var rpc_call_destroy = function(){
- if( rpc_call !== null ) rpc_call.destroy();
- rpc_call = null;
- }
-
- //////////////////////////////////////////////////////////////////////////
- // notify_event //
- //////////////////////////////////////////////////////////////////////////
- var last_event_type = null;
- var last_event_data = null;
- var notify_event = function(event_type, event_data){
- // return if current event is equal to last event
- if( event_type == last_event_type && underscore.isEqual(event_data, last_event_data) )
- return;
- // backup current event_type/event_data
- last_event_data = event_data;
- last_event_type = event_type;
- // do notify the event_cb
- event_cb(event_type, event_data);
- }
-
-
- //////////////////////////////////////////////////////////////////////////
- // run initialisation //
- //////////////////////////////////////////////////////////////////////////
- // call the contructor
- ctor();
- // return the public properties
- return {
- release : start_release,
- published : function(){ return cast_privhash !== null },
- cast_privhash : function(){ return cast_privhash; },
- destroy : dtor
- }
-}
-
-/**
- * Class method to create an object
- * - thus avoid new operator
-*/
-casti_ctrl_t.create = function(ctor_opts){
- return new casti_ctrl_t(ctor_opts);
-}
-
-// export it via commonjs
-exports.create = casti_ctrl_t.create;
-
-//////////////////////////////////////////////////////////////////////////////////
-// main programm //
-//////////////////////////////////////////////////////////////////////////////////
-if( process.argv[1] == __filename ){
-// ************************************
-// - in neoip-casti
-// - idle timeout (given by casti cmd with default. with a max in .conf)
-// - faster publishing
-
-
- //////////////////////////////////////////////////////////////////////////////////
- // parse cmdline //
- //////////////////////////////////////////////////////////////////////////////////
- // cmdline_opts default
- cmdline_opts = {
- casti_opts : {},
- call_url : null,
- req_timer_delay : null,
- verbose : 0,
- no_gracefull_shutdown : false
- };
- var disp_usage = function(prefix){
- if(prefix) console.log(prefix + "\n");
- console.log("usage: casti_ctrl -o key val -u url [-d msec] [-n] [-v [-v]]");
- console.log("");
- console.log("Control neoip-casti");
- console.log("");
- console.log("-o|--casti_opts key val\t\tSet the key/val options for casti call.");
- console.log("-u|--call_url url\t\tSet the call_url for the rpc");
- console.log("-d|--req_timer_delay sec\tSet the delay between 2 request_stream calls.");
- console.log("-n|--no_gracefull_shutdown\tDont explicitly release the stream on SIGINT");
- console.log("-v|--verbose\t\t\tIncrease the verbose level (for debug).");
- console.log("-h|--help\t\t\tDisplay the inline help.");
- }
- var optind = 2;
- for(;optind < process.argv.length; optind++){
- var key = process.argv[optind];
- var val = process.argv[optind+1];
- //console.log("key="+key+" val="+val);
- if( key == '-o' || key == "--casti_opts" ){
- cmdline_opts.casti_opts[val] = process.argv[optind+2];
- optind += 2;
- }else if( key == '-u' || key == "--call_url" ){
- // TODO if call_url unspecified, try to autodetect casti on localhost
- cmdline_opts.call_url = val;
- optind += 1;
- }else if( key == '-d' ||key == "--req_timer_delay" ){
- cmdline_opts.req_timer_delay = parseFloat(val)*1000;
- optind += 1;
- }else if( key == '-n' || key == "--no_gracefull_shutdown" ){
- cmdline_opts.no_gracefull_shutdown = true;
- }else if( key == '-v' || key == "--verbose" ){
- cmdline_opts.verbose += 1;
- }else if( key == "-h" || key == "--help" ){
- disp_usage();
- process.exit(0);
- }else{
- // if the option doesnt exist, consider it is the first non-option parameters
- break;
- }
- }
-
- if(false){
- // example of cmdline
- // Start the original stream
- // $ node node-chargen.js
- // tell webpeer to read this stream:
- // $ node casti_ctrl_t.js --call_url http://localhost:4570/neoip_casti_ctrl_wpage_jsrest.js -o mdata_srv_uri http://localhost/~jerome/neoip_html/cgi-bin/cast_mdata_echo_server.fcgi -o cast_name superstream -o cast_privtext supersecret -o scasti_uri http://127.0.0.1:8124 -o scasti_mod raw -o http_peersrc_uri '' -o web2srv_str 'dummyweb2serv_str' -v
- // Read the stream from webpeer
- // curl `node casto_url_builder.js http://127.0.0.1:4560 a761ce3a superstream`
- cmdline_opts.call_url = "http://localhost:4570/neoip_casti_ctrl_wpage_jsrest.js";
- cmdline_opts.casti_opts = {
- mdata_srv_uri : "http://localhost/~jerome/neoip_html/cgi-bin/cast_mdata_echo_server.fcgi",
- cast_name : "superstream",
- cast_privtext : "supersecret",
- scasti_uri : "http://127.0.0.1:8124",
- scasti_mod : "raw",
- http_peersrc_uri: "",
- web2srv_str : "dummyuserdata"
- };
- }
-
- // init casti_ctrl
- var casti_ctrl = casti_ctrl_t.create({
- call_url : cmdline_opts.call_url,
- casti_opts : cmdline_opts.casti_opts,
- event_cb : function(event_type, event_data){
- console.log("event_cb: type="+event_type+" data="+require('sys').inspect(event_data));
- console.log("casti_ctrl: published()="+casti_ctrl.published()+" cast_privhash()="+casti_ctrl.cast_privhash());
- },
- req_timer_delay : cmdline_opts.req_timer_delay || null,
- verbose : cmdline_opts.verbose || 0
- });
-
- // init gracefull_shutdown if not specified otherwise in cmdline
- if( cmdline_opts.no_gracefull_shutdown === false ){
- // trap SIGINT - first = release(), second normal behavior
- process.on('SIGINT', function(){
- console.log("Received sigint, start releasing the stream");
- casti_ctrl.release();
- process.removeListener('SIGINT', arguments.callee);
- });
- }
-}
View
227 obsolete/lib.old/casto_testclient_t.js
@@ -1,227 +0,0 @@
-#!/usr/bin/env node
-
-var http = require('http');
-
-/**
- * it read the stream from stream_url.
- * - it isnt specific to webpeer stream at all
- * - it is mostly a debug tool.
- *
- * opts:
- * - opts.stream_url : url for the stream
- * - opts.notify_unit : the unit to notify recved_data (default to 1024)
- * - opts.event_cb : callback event_cb(event_type, event_data):
- * - "cnx_begin"/null: server connected
- * - "cnx_end"/null: server disconnected
- * - "recved_size"/nunits: when data is received (nunit is the amount of data
- * in 'unit'). it is notified when there is at least one unit to notified.
- * - "idle_timeout"/null: when no data has been received for
-*/
-var casto_testclient_t = function(ctor_opts){
- //////////////////////////////////////////////////////////////////////////
- // class variables //
- //////////////////////////////////////////////////////////////////////////
- // alias 'this' for this object, to self
- var self = this;
- // sanity check - all mandatory fields must be present
- console.assert(ctor_opts.stream_url);
- // copy ctor_opts + set default values if needed
- var stream_url = ctor_opts.stream_url;
- var event_cb = ctor_opts.event_cb || function(event_type, event_data){};
- var notify_unit = ctor_opts.notify_unit || 1024;
- var verbose = ctor_opts.verbose || 0;
- var idle_timer_delay = ctor_opts.idle_timer_delay || 20*1000;
- var max_recved_len = ctor_opts.max_recved_len || null;
-
- //////////////////////////////////////////////////////////////////////////
- // ctor/dtor //
- //////////////////////////////////////////////////////////////////////////
- var ctor = function(){
- client_start();
- }
- var dtor = function(){
- idle_timer_stop();
- client_stop();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // idle_timer //
- //////////////////////////////////////////////////////////////////////////
- var idle_timer_id = null;
- var idle_timer_start = function(){
- if( verbose > 1 ) console.log("launch idle_timer timeout in "+idle_timer_delay+"-msec");
- idle_timer_id = setTimeout(idle_timer_cb, idle_timer_delay);
- }
- var idle_timer_stop = function(){
- if( idle_timer_id !== null ) clearTimeout(idle_timer_id);
- idle_timer_id = null;
- }
- var idle_timer_refresh = function(){
- if( verbose ) console.log("idle_time_refresh");
- idle_timer_stop();
- idle_timer_start();
- }
- var idle_timer_cb = function(){
- if( verbose ) console.log("idle timer expired. next in "+idle_timer_delay+"-msec");
- event_cb("error", "idle timeout after "+idle_timer_delay+"-msec");
- }
-
- //////////////////////////////////////////////////////////////////////////
- // http client //
- //////////////////////////////////////////////////////////////////////////
- var client_req = null;
- var client_start = function(){
- var recved_len = 0;
- var notified_len= 0;
- // create the http client
- var url = require('url').parse(stream_url);
- var client = http.createClient((url.port||80), url.hostname);
- // bind error cases at the socket level
- client.on("error" , function(e){ event_cb("error", e.message); });
- client.on("timeout" , function(e){ event_cb("error", e.message); });
- // create the request
- client_req = client.request('GET', url.pathname, {'host': url.host});
- client_req.on('response', function(client_res){
- // log to debug
- if( verbose ) console.log("Connected to "+stream_url);
- // start the idle_timer
- idle_timer_start();
- // Handle faillure at http level
- if(client_res.statusCode != 200){
- event_cb("error", "statusCode="+client_res.statusCode);
- return
- }
- // notify the caller
- event_cb("cnx_begin", null);
- //client_res.setEncoding('utf8');
- client_res.on('data', function( chunk ){
- // refresh idle_timer
- idle_timer_refresh();
- //console.log("chunk len="+chunk.length);
- // update recved_len
- recved_len += chunk.length;
- // notify the recved_size in notify_unit
- var notified_chunk = Math.floor(notified_len / notify_unit);
- var tonotify_chunk = Math.floor(recved_len / notify_unit);
- var nb_chunks = tonotify_chunk - notified_chunk;
- if(nb_chunks > 0) event_cb("recved_size", nb_chunks);
- // update notified_len
- notified_len = recved_len;
- // notify the caller
- if( max_recved_len && recved_len >= max_recved_len ) event_cb("recved_len_maxed", null);
- });
- client_res.on('end', function(){
- // log the event
- if( verbose ) console.log("Connection ended");
- // notify the caller
- event_cb("cnx_closed", null);
- });
- });
- client_req.end();
- }
- var client_stop = function(){
- client_req.connection.destroy();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // run initialisation //
- //////////////////////////////////////////////////////////////////////////
- // call the contructor
- ctor();
- // return the public properties
- return {
- destroy : dtor
- }
-}
-
-/**
- * Class method to create an object
- * - thus avoid new operator
-*/
-casto_testclient_t.create = function(ctor_opts){
- return new casto_testclient_t(ctor_opts);
-}
-
-// export it via commonjs
-exports.create = casto_testclient_t.create;
-
-//////////////////////////////////////////////////////////////////////////////////
-// main programm //
-//////////////////////////////////////////////////////////////////////////////////
-if( process.argv[1] == __filename ){
- //////////////////////////////////////////////////////////////////////////////////
- // parse cmdline //
- //////////////////////////////////////////////////////////////////////////////////
- // cmdline_opts default
- cmdline_opts = {
- stream_url : {},
- verbose : 0,
- max_recved_len : null,
- notify_unit : null,
- nconcurent_cnx : 1
- };
- var disp_usage = function(prefix){
- if(prefix) console.log(prefix + "\n");
- console.log("usage: casto_testclient [-n unitbyte] [-v [-v]] [-c ncnx] stream_url");
- console.log("");
- console.log("Establish a connection with a http stream.");
- console.log("- intended to test neoip-casto.");
- console.log("");
- console.log("-l|--max_recved_len lbytes\t\tSet the max amount of kbytes to receive.");
- console.log("-n|--notify_unit bytes\t\tSet the amount of bytes to notify");
- console.log("-v|--verbose\t\t\tIncrease the verbose level (for debug).");
- console.log("-h|--help\t\t\tDisplay the inline help.");
- }
- var optind = 2;
- for(;optind < process.argv.length; optind++){
- var key = process.argv[optind];
- var val = process.argv[optind+1];
- //console.log("key="+key+" val="+val);
- if( key == '-l' || key == "--max_recved_len" ){
- cmdline_opts.max_recved_len = parseInt(val);
- optind += 1;
- }else if( key == '-n' || key == "--notify_unit" ){
- cmdline_opts.notify_unit = parseInt(val);
- optind += 1;
- }else if( key == '-c' || key == "--nconcurent_cnx" ){
- cmdline_opts.nconcurent_cnx = parseInt(val);
- optind += 1;
- }else if( key == '-v' || key == "--verbose" ){
- cmdline_opts.verbose += 1;
- }else if( key == "-h" || key == "--help" ){
- disp_usage();
- process.exit(0);
- }else{
- // if the option doesnt exist, consider it is the first non-option parameters
- break;
- }
- }
- // get required options from the rest of the cmdline
- var stream_url = process.argv[optind++];
-
-
- if( false ){
- stream_url = "http://127.0.0.1:8124/";
- cmdline_opts.verbose = 1
- }
- // create casto_client
- for(var i = 0; i < cmdline_opts.nconcurent_cnx; i++ ){
- var casto_client = casto_testclient_t.create({
- stream_url : stream_url,
- event_cb : function(event_type, event_data){
- if( cmdline_opts.verbose ) console.log("event_type="+event_type+" event_data="+event_data);
- if( event_type == "recved_size" ){
- var nb_unit = event_data;
- for(var i = 0; i < nb_unit; i++){
- require("sys").print('.');
- }
- }else if(event_type == "recved_len_maxed"){
- casto_client.destroy();
- }
- },
- max_recved_len : cmdline_opts.max_recved_len || null,
- notify_unit : cmdline_opts.notify_unit || null,
- verbose : cmdline_opts.verbose || 0
- });
- }
-}
View
164 obsolete/lib.old/casto_url_builder.js
@@ -1,164 +0,0 @@
-#!/usr/bin/env node
-
-
-//////////////////////////////////////////////////////////////////////////////////
-// Man Page //
-//////////////////////////////////////////////////////////////////////////////////
-
-/* Man page in perlpod format. to view with "pod2man thisfile | man -l -"
-=pod
-
-=head1 NAME
-
-neoip-url-stream - build a url for neoip-casto
-
-=head1 SYNOPSIS
-
-B<neoip-url-stream> [-s mdata_srv_uri] base_url cast_privhash cast_name
-
-=head1 DESCRIPTION
-
-Build an url for neoip-casto. This url will point on a normal http stream.
-Thus the client may be any client which understand http, it doesnt have to modified
-to use this url.
-
-=over
-
-=item I<base_url>
-
-The base_url is the neoip-casto base url. It is not autodetected.
-TODO make it autodetectable (likely with a neoip-appdetect applications
-or by simply make a dependancy in the code)
-
-=item I<cast_privhash>
-
-This is the hash of the broadcast password (aka casti_privtext). This is used
-to ensure the http client got the permission to read the broadcast.
-
-=item I<cast_name>
-
-cast_name is the name of the broadcast. This name is unique inside the I<mdata_srv_uri>.
-
-=back
-
-=head1 OPTIONS
-
-The following options are available:
-
-=over
-
-=item B<-s|--mdata_srv_uri> I<url>
-
-Use to set the url for the metadata server. This server got the metadata information
-about the broadcast. (OPTIONAL)
-
-=back
-
-=head1 EXAMPLES
-
-=over
-
-=item B<basic usage>
-
-$ neoip-url-stream http://localhost:4560 a761ce3a superstream
-
-This will display the following in stdout
-
-http://localhost:4560/a761ce3a/superstream
-
-=item B<specifying mdata_srv_uri>
-
-$ neoip-url-stream -s http://example.com http://localhost:4560 a761ce3a superstream
-
-This will display the following in stdout
-
-http://localhost:4560/a761ce3a/superstream?mdata_srv_uri=http%3A//example.com
-
-=cut
-
-
-*/
-
-/**
- * Create an url for neoip-casto
- * - opts.base_url : casto base_url (REQUIRED)
- * - opts.cast_privhash : cast_privhash (REQUIRED)
- * - opts.cast_name : cast_name (REQUIRED)
- * - opts.mdata_srv_uri : url of the nameserver (OPTIONAL)
- *
- * - NOTE: no detection of the neoip-casto apps is done
- *
- * @return the url for the stream out of neoip-casto
- * @type String
-*/
-var create = function(opts){
- // sanity check - all mandatory fields MUST be present
- console.assert(opts.base_url);
- console.assert(opts.cast_privhash);
- console.assert(opts.cast_name);
- // build the url
- var url = opts.base_url + "/" + opts.cast_privhash + "/" + opts.cast_name;
- // add mdata_srv_uri if any
- if( opts.mdata_srv_uri ) url += "?mdata_srv_uri=" + escape(opts.mdata_srv_uri);
- // return the just built url
- return url;
-}
-
-// export it via commonjs
-exports.create = create;
-
-//////////////////////////////////////////////////////////////////////////////////
-// main programm //
-//////////////////////////////////////////////////////////////////////////////////
-if( process.argv[1] == __filename ){
- opts = {
- base_url : null,
- cast_privhash : null,
- cast_name : null,
- mdata_srv_uri : null
- };
-
- //////////////////////////////////////////////////////////////////////////////////
- // parse cmdline //
- //////////////////////////////////////////////////////////////////////////////////
- var disp_usage = function(prefix){
- if(prefix) console.log(prefix + "\n");
- console.log("usage: neoip-url-stream [-s url] base_url cast_privhash cast_name");
- console.log("");
- console.log("Build an url for neoip-casto");
- console.log("");
- console.log("-s|--mdata_srv_uri\n\t\tSet url for the mdata_srv.");
- console.log("-h|--help\tDisplay the inline help.");
- }
- var optind = 2;
- for(;optind < process.argv.length; optind++){
- var key = process.argv[optind];
- var val = process.argv[optind+1];
- //console.log("key="+key+" val="+val);
- if( key == "-s" || key == "--mdata_srv_uri" ){
- opts.mdata_srv_uri = val;
- optind += 1;
- }else if( key == "-h" || key == "--help" ){
- disp_usage();
- process.exit(0);
- }else{
- // if the option doesnt exist, consider it is the first non-option parameters
- break;
- }
- }
- // check there are at least 3 parameters remaining in the cmdline
- if( process.argv.length - optind < 3 ){
- disp_usage("missing parameters to buidl the url");
- process.exit(0);
- }
-
- // get required options from the rest of the cmdline
- opts.base_url = process.argv[optind++];
- opts.cast_privhash = process.argv[optind++];
- opts.cast_name = process.argv[optind++];
-
- // create the url
- var url = create(opts);
- // output the url on stdout
- console.log(url);
-}
View
105 obsolete/lib.old/collection.js
@@ -1,105 +0,0 @@
-var collection = function(){
- // define private variables
- var _map = {}
-
- var _parse_key = function(key, non_exist_callback){
- // parse the key into parts
- var key_parts = key.split("/");
- // goto the proper submap (and create it if needed)
- var submap = _map;
- var subkey = key_parts[0]
- for(var i = 0; i < key_parts.length - 1; i++){
- // if this subkey is not present in submap, notify an exception
- if( typeof submap[subkey] == 'undefined' ) non_exist_callback(submap, subkey);
- // goto the next submap
- submap = submap[subkey];
- subkey = key_parts[i+1];
- }
- // return the result
- return {
- 'submap': submap,
- 'subkey': subkey
- };
- };
-
- /**
- * Set the variable namespace/key to the value val
- */
- var set = function(key, val) {
- // parse the key
- var parsed_key = _parse_key(key, function(submap, subkey){
- // if this subkey is not present in submap, create an empty object
- submap[subkey] = {}
- });
- // set this value in the last submap
- parsed_key.submap[parsed_key.subkey] = val;
- }
- /**
- * Return the value of the variable namespace/key (note: it MUST be defined)
- */
- var get = function(key) {
- // sanity check - the key MUST be present
- console.assert( has(key) );
- // parse the key
- var parsed_key = _parse_key(key, function(submap, subkey){
- // if this subkey is not present in submap, notify an exception
- throw new Error('subkey '+subkey+' (from key '+key+') doesnt exist');
- });
- // get this value in the last submap
- var val = parsed_key.submap[parsed_key.subkey];
- // return this val
- return val;
- }
- var get_dfl = function(key, dfl){ return has(key) ? get(key) : dfl; }
-
-
- /**
- * delete this key (note: it MUST be defined)
- */
- var del = function(key) {
- // sanity check - the key MUST be present
- console.assert( has(key) );
- // parse the key
- var parsed_key = _parse_key(key, function(submap, subkey){
- // if this subkey is not present in submap, notify an exception
- throw new Error('subkey '+subkey+' (from key '+key+') doesnt exist');
- });
- // get this value in the last submap
- var val = parsed_key.submap[parsed_key.subkey];
- // delete in the last submap
- delete parsed_key.submap[parsed_key.subkey];
- }
-
- /**
- * Return true if this variable is defined, false otherwize
- */
- var has = function(key) {
- // parse the key
- var parsed_key = null;
- // TODO i could avoid the exception by doing closure on parsed_key ?
- try {
- parsed_key = _parse_key(key, function(submap, subkey){
- // if this subkey is not present in submap, notify an exception
- throw new Error('subkey '+subkey+' (from key '+key+') doesnt exist');
- });
- }catch(error) {
- // return false now, if the key cant be parsed
- return false;
- }
- // if this subkey is not present in submap, notify an exception
- if( typeof parsed_key.submap[parsed_key.subkey] == 'undefined' ) return false;
- // if all previous tests passed, return true
- return true;
- }
-
- return {
- "set" : set,
- "get" : get,
- "get_dfl" : get_dfl,
- "del" : del,
- "has" : has
- }
-};
-
-// export it via commonjs
-exports.collection = collection;
View
27 obsolete/lib.old/collection_test.js
@@ -1,27 +0,0 @@
-var collection = require('./collection').collection;
-var test = function(testname, test_cb){
- console.log("Test "+testname+" Started");
- test_cb();
- console.log("Test "+testname+" Done");
-}
-
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-// tests //
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-
-
-console.log("Testing collection Started");
-var key = "foo";
-var val = "bar"
-var col = new collection();
-console.assert( ! col.has(key) );
-console.assert( col.get_dfl(key) == undefined );
-console.assert( col.get_dfl(key, "bar2") == "bar2" );
-col.set(key, val);
-console.assert( col.has(key) );
-console.assert( col.get(key) == val );
-col.del(key);
-console.assert( ! col.has(key) );
-console.log("Testing collection Done");
View
189 obsolete/lib.old/neoip_app_detect.js
@@ -1,189 +0,0 @@
-var sys = require('sys');
-var neoip_rpc = require('./neoip_rpc_node');
-(function(){ // module closure begining
-
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-// module start //
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-
-var verbose = 0;
-
-/**
- * Constant informations about applications
-*/
-var app_infos = {
- "oload": {
- "port_beg": 4550,
- "port_end": 4553
- },
- "casto": {
- "port_beg": 4560,
- "port_end": 4563
- },
- "casti": {
- "port_beg": 4570,
- "port_end": 4573
- }
-};
-
-
-var disc_app_cache = {};
-var disc_app_cache_contain = function(app_suffix){ return app_suffix in disc_app_cache_contain; }
-var disc_app_cache_clear = function(app_suffix){ disc_app_cache = {}; }
-exports.disc_app_cache = disc_app_cache;
-
-/**
- * Discover an neoip application
- *
- * @param {String} app_suffix the neoip application suffix
- * @param {function} success_cb notified if app is found success_cb(root_url, version)
- * @param {function} failure_cb notified if app is not found failure_cb(reason)
-*/
-var discover_app = function(app_suffix, success_cb, failure_cb){
- // sanity check
- console.assert(success_cb);
- console.assert(app_suffix == "oload" || app_suffix == "casti" || app_suffix == "casto");
- // if callback are not specified, use a dummy one
- if(!failure_cb) failure_cb = function(){};
- // handle cache
- if(app_suffix in disc_app_cache){
- var cache_item = disc_app_cache[app_suffix];
- if( cache_item.version === false ){
- setTimeout(function(){failure_cb(true);}, 0);
- }else{
- setTimeout(function(){success_cb(cache_item.root_url, cache_item.version)}, 0);
- }
- return;
- }
- // get info from app_infos
- var port_beg = app_infos[app_suffix]["port_beg"];
- var port_end = app_infos[app_suffix]["port_end"];
- var port_cur = port_beg;
- // define the callbacks
- var probe_succ_cb = function(version){
- if( verbose ) console.log("found "+app_suffix+" version "+version+" at port "+port_cur);
- var root_url = "http://127.0.0.1:"+port_cur;
- // cache the result
- disc_app_cache[app_suffix] = {
- "root_url" : root_url,
- "version" : version
- };
- // notify the caller
- success_cb(root_url, version);
- };
- var probe_fail_cb = function(had_error){
- if( verbose ) console.log(app_suffix+' not found port_cur='+port_cur);
- if(port_cur == port_end){
- // cache the result
- disc_app_cache[app_suffix] = { "version" : false };
- // report "not found" when all port has been tested
- failure_cb("not found");
- }else{
- // test the next port
- port_cur++;
- probe_launch();
- }
- };
- var probe_launch = function(){
- neoip_rpc.rpc_call.create({
- call_url : "http://127.0.0.1:"+port_cur+"/neoip_"+app_suffix+"_appdetect_jsrest.js",
- method_name : 'probe_apps',
- method_args : [],
- success_cb : probe_succ_cb,
- failure_cb : probe_fail_cb
- });
- }
- // start the probbing
- probe_launch();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-// Webpack
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Compare version ala memcmp. format is major.minor.patch
- * - used in discover_webpack()
-*/
-var version_compare = function(version1, version2){
- // parse the versions
- var matches1 = version1.match(/(\d+).(\d+).(\d+)/);
- var matches2 = version2.match(/(\d+).(\d+).(\d+)/);
- // compare the major
- var major1 = parseInt(matches1[1], 10);
- var major2 = parseInt(matches2[1], 10);
- if( major1 > major2 ) return +1;
- if( major1 < major2 ) return -1;
- // compare the minor
- var minor1 = parseInt(matches1[2], 10);
- var minor2 = parseInt(matches2[2], 10);
- if( minor1 > minor2 ) return +1;
- if( minor1 < minor2 ) return -1;
- // compare the patch
- var patch1 = parseInt(matches1[3], 10);
- var patch2 = parseInt(matches2[3], 10);
- if( patch1 > patch2 ) return +1;
- if( patch1 < patch2 ) return -1;
- // return 0, they are considered equal
- return 0;
-}
-
-/**
- * Discover webpack on localhost and notify the result
- *
- * @param callback {Function} callback notified "toinstall", "toupgrade", "installed"
-*/
-var discover_webpack = function(callback){
- // defined the minimal version for each apps
- var versions_min = {
- "oload" : "0.0.1",
- "casto" : "0.0.1",
- "casti" : "0.0.2"
- };
- var completed_cb = function(){
- // test if all the apps got probed
- for(var app_suffix in versions_min){
- if( !(app_suffix in disc_app_cache) ) return;
- }
- // test if all the apps got probed
- for(var app_suffix in versions_min){
- var version = disc_app_cache[app_suffix].version;
- if( version === false ){
- callback("toinstall");
- return;
- }
- }
- // test if all the apps got probed
- for(var app_suffix in versions_min){
- var version_cur = disc_app_cache[app_suffix].version;
- var version_min = versions_min[app_suffix];
- if( version_compare(version_cur, version_min) < 0 ){
- callback("toupgrade");
- return;
- }
- }
- // notify the caller
- callback("installed");
- }
- // launch the discovery of each app
- for(var app_suffix in versions_min){
- discover_app(app_suffix, completed_cb, completed_cb);
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-// module end //
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-
-// exports public functions
-exports.discover_app = discover_app;
-exports.discover_webpack = discover_webpack;
-
-})(); // end of the module closure
-
View
234 obsolete/lib.old/neoip_app_detect_exe.js
@@ -1,234 +0,0 @@
-#!/usr/bin/env node
-
-//////////////////////////////////////////////////////////////////////////////////
-// Man Page //
-//////////////////////////////////////////////////////////////////////////////////
-
-/* Man page in perlpod format. to view with "pod2man thisfile | man -l -"
-=pod
-
-=head1 NAME
-
-neoip-detect - Detect neoip applications
-
-=head1 SYNOPSIS
-
-B<neoip-detect> [options] [appname [output_type]]
-
-=head1 DESCRIPTION
-
-B<neoip-detect> detect neoip-applications presence and related informations, like
-version or api's root_url.
-
-=over
-
-=item I<appname>
-
-Valid appnames are in 'oload', 'casti', 'casto' and 'webpack'.
-It is optionnal and defaults to 'presence'.
-
-=item I<output_type>
-
-Determine the type of output to use. Valid output_type are : 'root_url', 'version' and 'presence'.
-It is optionnal and defaults to 'presence'.
-
-B<Note>: if I<appname> is 'webpack', the only valid type is 'presence'
-
-=over
-
-=item I<root_url>
-
-It will output in stdout the API's root url for this application.
-
-=item I<version>
-
-It will output in stdout version this application.
-
-=item I<presence>
-
-It will display a human readable message on stdout. This option is interesting
-mainly for its statuscode returned by the executable.
-
-=back
-
-=back
-
-=head1 OPTIONS
-
-The following options are available:
-
-=over
-
-=item B<--c|--continue>
-
-It will continue looping for ever.
-By default, it does only one iteration.
-
-=item B<--d|--delay sec>
-
-It will set the delay between each loop iteration.
-This option is valid only with B<--continue>.
-By default, it is 1-sec. Fractional seconds is supported.
-
-=item B<-v|--verbose>
-
-Increase the verbose level. It may be used multiple times.
-
-=back
-
-=head1 EXAMPLES
-
-=over
-
-=item B<version display>
-
-$ neoip-detect oload version
-
-This will display the following in stdout
-
-0.0.1
-
-=item B<detecting presence>
-
-$ neoip-detect webpack && echo "detected" || echo "not detected"
-
-This will display I<detected> in stdout if neoip-webpack is detected
-and I<not detected> otherwise.
-
-=cut
-
-*/
-
-//////////////////////////////////////////////////////////////////////////////////
-// Main code //
-//////////////////////////////////////////////////////////////////////////////////
-
-var app_detect = require('./neoip_app_detect');
-
-//////////////////////////////////////////////////////////////////////////////////
-// parse cmdline //
-//////////////////////////////////////////////////////////////////////////////////
-// cmdline_opts default
-cmdline_opts = {
- loop_4ever : false,
- loop_delay : 1*1000,
- verbose : 0
-};
-var disp_usage = function(prefix){
- if(prefix) console.log(prefix + "\n");
- console.log("usage: neoip-detect [options] appname [output_type]");
- console.log("");
- console.log("Discover neoip-apps.");
- console.log("Valid appnames are in 'oload', 'casti', 'casto' and 'webpack'.");
- console.log("appname is optionnal and defaults to 'webpack'.");
- console.log("Valid output_type are : 'root_url', 'version' and 'presence'.");
- console.log("output_type is optionnal and defaults to 'presence'.");
- console.log("if appname is 'webpack', 'presence' is the only valid output_type.");
- console.log("");
- console.log("-c|--continue\tContinue for ever, instead of only 1 iteration.");
- console.log("-d|--delay num\tSet the loop delay (valid only with --continue).");
- console.log("-v|--verbose\tIncrease the verbose level (for debug).");
- console.log("-h|--help\tDisplay the inline help.");
-}
-var optind = 2;
-for(;optind < process.argv.length; optind++){
- var key = process.argv[optind];
- var val = process.argv[optind+1];
- //console.log("key="+key+" val="+val);
- if( key == '-c' || key == "--continue" ){
- cmdline_opts.loop_4ever = true;
- }else if( key == '-d' || key == "--delay" ){
- cmdline_opts.loop_delay = parseFloat(val)*1000;
- optind++;
- }else if( key == '-v' || key == "--verbose" ){
- cmdline_opts.verbose += 1;
- }else if( key == "-h" || key == "--help" ){
- disp_usage();
- process.exit(0);
- }else{
- // if the option doesnt exist, consider it is the first non-option parameters
- break;
- }
-}
-
-// get required options from the rest of the cmdline
-var app_name = process.argv[optind++] || 'webpack';
-var output_type = process.argv[optind++] || 'presence';
-
-var loop_4ever = cmdline_opts.loop_4ever;
-var loop_delay = cmdline_opts.loop_delay;
-var verbose = cmdline_opts.verbose;
-
-// sanity check - app_name MUST be in valid_names
-var valid_names = ['oload', 'casti', 'casto', 'webpack'];
-if( valid_names.indexOf(app_name) == -1 ){
- console.log("app_name '"+app_name+"' is not possible.");
- console.log("Valid names are ", valid_names);
- process.exit(-1);
-}
-
-// sanity check - app_name MUST be in valid_names
-var valid_types = ['root_url', 'version', 'presence'];
-if( valid_types.indexOf(output_type) == -1 ){
- console.log("output_type '"+output_type+"' is not possible.");
- console.log("Valid types are "+require('sys').inspect(valid_names));
- process.exit(-1);
-}
-if( app_name == 'webpack' && output_type != 'presence' ){
- console.log("with 'webpack' apps name, 'presence' is the only valid output_type");
- process.exit(-1);
-}
-
-// trace for the user
-if( verbose ) console.log("discovering '"+app_name+"' for "+output_type);
-
-//////////////////////////////////////////////////////////////////////////
-// do actual discovery //
-//////////////////////////////////////////////////////////////////////////
-var one_iter = function(completed_cb){
- if( app_name != 'webpack' ){
- // discover neoip-oload and act depending on its presence or not
- app_detect.discover_app(app_name, function(root_url, version){
- //console.log("root_url="+root_url+ " version="+version);
- if( output_type == 'root_url' ) console.log(root_url);
- else if( output_type == 'version' ) console.log(version);
- else if( output_type == 'presence' ) console.log("present ("+version+")");
- completed_cb(0);
- }, function(reason){
- if( verbose ) console.log("Failed due to "+reason);
- if( output_type == 'presence' ) console.log("not present");
- completed_cb(-1);
- })
- }else if( app_name == 'webpack' && output_type == 'presence' ){
- app_detect.discover_webpack(function(status){
- if( verbose ) console.log("webpack status="+status);
- if( status == "installed" ) console.log("webpack is installed and uptodate.");
- else if( status == "toupgrade" ) console.log("webpack is installed and needs upgrade.");
- else if( status == "toinstall" ) console.log("webpack is not installed.");
- else console.assert(false);
- // return the proper statuscode
- if( status == "toinstall" ) completed_cb(-1);
- else completed_cb(0);
- });
- }
-}
-
-if( loop_4ever == false ){
- one_iter(function(statuscode){
- process.exit(statuscode);
- })
-}else{
- // trap SIGINT - exit with error
- process.on('SIGINT', function(){
- process.exit(-1);
- });
- var endless_loop = function(){
- one_iter(function(statuscode){
- // clear the cache - force to get fresh result
- app_detect.cache_clear();
- setTimeout(endless_loop, loop_delay);
- })
- }
- endless_loop();
-}
-
View
115 obsolete/lib.old/neoip_rpc_node.js
@@ -1,115 +0,0 @@
-#!/usr/bin/env node
-
-var http = require('http');
-
-/**
- * do a rpc call to a neoip application
-*/
-var rpc_call = function(ctor_opts){
- //////////////////////////////////////////////////////////////////////////
- // class variables //
- //////////////////////////////////////////////////////////////////////////
- // alias 'this' for this object, to self
- var self = this;
- // copy ctor_opts + set default values if needed
- var call_url = ctor_opts.call_url || console.assert(ctor_opts.call_url);
- var method_name = ctor_opts.method_name || console.assert(ctor_opts.method_name);
- var method_args = ctor_opts.method_args || [];
- var success_cb = ctor_opts.success_cb || function(){};
- var failure_cb = ctor_opts.failure_cb || function(){};
- var verbose = ctor_opts.verbose || 0;
-
- //////////////////////////////////////////////////////////////////////////
- // ctor/dtor //
- //////////////////////////////////////////////////////////////////////////
- var ctor = function(){
- client_start();
- }
- var dtor = function(){
- //console.log("Stop neoip rpc call");
- client_stop();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // http client //
- //////////////////////////////////////////////////////////////////////////
- var client_req = null;
- var client_start = function(){
- var url = require('url').parse(call_url);
- // build url_path
- var url_path = url.pathname + "?method_name=" + method_name;
- for(var i = 0; i < method_args.length; i++){
- url_path += "&arg"+i+"=" + escape(method_args[i]);
- }
- // create the request
- var client = http.createClient((url.port||80), url.hostname);
- // bind error cases at the socket level
- client.on("error" , function(e){ failure_cb({code: -1, string: e.message});});
- client.on("timeout" , function(e){ failure_cb({code: -1, string: e.message});});
- // create the request
- client_req = client.request('GET', url_path, {'host': url.host});
- client_req.on('response', function(client_res){
- // log to debug
- if( verbose ) console.log('STATUS: ' + client_res.statusCode);
- if( verbose ) console.log('HEADERS: ' + JSON.stringify(client_res.headers));
- // Handle faillure at http level
- if(client_res.statusCode != 200)
- return failure_cb(new Error("http statuscode="+client_res.statuscode));
- client_res.setEncoding('utf8');
- client_res.on('data', function( reply_json ){
- if( verbose ) console.log('BODY: ' + reply_json);
- // convert reply_json to native data
- var reply_data = JSON.parse(reply_json);
- // handle faillure/success_cb at the call level
- if( reply_data['fault'] ){
- if( verbose > 1 ) console.dir(reply_data);
- failure_cb(reply_data['fault']); // TODO what about the error itself
- }else{
- var returned_val= reply_data['returned_val'];
- success_cb(returned_val);
- }
- });
- return undefined;
- });
- client_req.end();
- }
- var client_stop = function(){
- client_req.connection.destroy();
- }
-
- //////////////////////////////////////////////////////////////////////////
- // run initialisation //
- //////////////////////////////////////////////////////////////////////////
- // call the contructor
- ctor();
- // return the public properties
- return {
- destroy : dtor
- }
-};
-
-/**
- * Class method to create an object
- * - thus avoid new operator
-*/
-rpc_call.create = function(ctor_opts){ return new rpc_call(ctor_opts); }
-
-// export it via commonjs
-exports.rpc_call = rpc_call;
-
-//////////////////////////////////////////////////////////////////////////////////
-// main programm //
-//////////////////////////////////////////////////////////////////////////////////
-if( process.argv[1] == __filename ){
- var rpc_call = rpc_call.create({
- call_url : 'http://localhost:4550/neoip_oload_appdetect_jsrest.js',
- method_name : 'probe_apps',
- success_cb : function(returned_val){
- console.log("succeed");
- console.dir(returned_val);
- },
- failure_cb : function(){
- console.log('failed');
- }
- });
-}
View
204 obsolete/lib.old/nested_uri_exe.js
@@ -1,204 +0,0 @@
-/*
- * This tool is used to build neoip-oload url
- * - step 1: discover if oload is present
- * - potentially cache the result for speed ?
- * - step 2: if not present, return the normal url
- * - step 3: if present, build the nested url
- *
- * output the resulting url to stdout
- * - thus it is possible to do : mplayer `neoip-url-static http://example.org/movie.mp4`
-*/
-
-
-//////////////////////////////////////////////////////////////////////////////////
-// Man Page //
-//////////////////////////////////////////////////////////////////////////////////
-
-/* Man page in perlpod format. to view with "pod2man thisfile | man -l -"
-=pod
-
-=head1 NAME
-
-neoip-url-static - Helps build url for neoip-webpack
-
-=head1 SYNOPSIS
-
-B<neoip-url-static> [options] url
-
-=head1 DESCRIPTION
-
-B<neoip-url-static> Discover neoip-webpack presence and generate the url for it. If
-not present, it fallbacks on the original url. The generated url is outputed on STDOUT.
-
-=head1 OPTIONS
-
-The following options are available:
-
-=over
-
-=item B<--outter_var KEY=VAL, -o KEY=VAL>
-
-Set an outter_var.
-
-=item B<--minner_var KEY=VAL, -o KEY=VAL>
-
-Set an minner_var.
-
-=item B<--dupuri URI, -d URI>
-
-Set this URI as a duplicate uri from the main uri. More just
-an alias for 'outter_var/dupuri', as it handle gory details of
-dupuri index for you.
-
-=item B<--mode STR, -m STR>
-
-Set the modification. Possible values are 'raw' and 'flv', it
-defaults to 'raw'. just an alias for 'outter_var/mod'
-
-=item B<--type STR, -t STR>
-
-Set the type of the file pointed by the url. Possible values
-are 'static', 'torrent' and 'metalink'. It defaults
-to 'static'. 'static' are for http static file, 'torrent' is for
-bittorrent files and 'metalink' for metalink files(beta).
-
-=item B<--path STR, -p STR>
-
-Used to select a given file when the uri points is a multi-file
-metafile (torrent or metalink).
-
-=item B<-v>
-
-Increase the verbose level. It may be used multiple times.
-
-=back
-
-=head1 EXAMPLES
-
-=over
-
-=item B<basic url building>
-
-$ neoip-url-static http://example.com/mystaticfile
-
-Display the url for mystaticfile. Which gonna go thru neoip-webpack
-if it is present.
-
-=item B<Coupling with other tools>
-
-$ mplayer `neoip-url-static http://example.com/video.mp4`
-
-Will generate the neoip url for this file and mplayer will directly
-read the video from neoip-webpack. This means you can read a video
-directly from a torrent!
-
-=cut
-
-*/
-
-//////////////////////////////////////////////////////////////////////////////////
-// Main code //
-//////////////////////////////////////////////////////////////////////////////////
-
-var app_detect = require('./neoip_app_detect');
-var nested_uri_t= require('./nested_uri_t').nested_uri_t;
-
-/**
- * Display the cmdline usage
-*/
-var disp_usage = function(){
- console.log('Usage: neoip-url-static [options] uri')
- console.log('');
- console.log('Discover neoip-webpack presence and generate the url for it. If it');
- console.log("is not present, it fallbacks on the normal. The generated url is ");
- console.log("outputed on STDOUT.");
- console.log('');
- console.log('Options: for advanced usage only');
- console.log('--outter_var KEY=VAL, -o KEY=VAL');
- console.log('\tSet an outter_var.');
- console.log('--minner_var KEY=VAL, -o KEY=VAL');
- console.log('\tSet an minner_var.');
- console.log('--dupuri URI, -d URI');
- console.log("\tSet this URI as a duplicate uri from the main uri. More just");
- console.log("\tan alias for 'outter_var/dupuri', as it handle gory details of");
- console.log("\tdupuri index for you.");
- console.log('--mode STR, -m STR');
- console.log("\tSet the modification. Possible values are 'raw' and 'flv', it");
- console.log("\tdefaults to 'raw'. just an alias for 'outter_var/mod'");
- console.log('--type STR, -t STR');
- console.log("\tSet the type of the file pointed by the url. Possible values");
- console.log("\tare 'static', 'torrent' and 'metalink'. It defaults");
- console.log("\tto 'static'. 'static' are for http static file, 'torrent' is for ");
- console.log("\tbittorrent files and 'metalink' for metalink files(beta).")
- console.log('--path STR, -p STR');
- console.log("\tUsed to select a given file when the uri points is a multi-file");
- console.log("\tmetafile (torrent or metalink).");
- console.log('');
- console.log('Examples:');
- console.log('neoip-url http://example.com/mystaticfile');
- console.log("\tDisplay the url for mystaticfile. Which gonna go thru neoip-webpack");
- console.log('\tif it is present.')
- console.log('mplayer `neoip-url http://example.com/video.mp4`');
- console.log("\tWill generate the neoip url for this file and mplayer will directly");
- console.log("\tread the video from neoip-webpack. This means you can read a video");
- console.log("\tdirectly from a torrent!");
-}
-
-
-
-// build the nested_uri depending on the cmdline argv
-var nested_uri = new nested_uri_t();
-for(var arg_idx = 2; arg_idx < process.argv.length; ){
- var arg = process.argv[arg_idx];
- if( arg == "--outter_var" || arg == "-o" ){
- var keyval = process.argv[arg_idx+1];
- var keyval_arr = keyval.split('=', 2)
- var key = keyval_arr[0];
- var val = keyval_arr[1];
- nested_uri.set("outter_var/"+key, val);
- arg_idx += 2;
- }else if( arg == "--minner_var" || arg == "-o" ){
- var keyval = process.argv[arg_idx+1];
- var keyval_arr = keyval.split('=', 2)
- var key = keyval_arr[0];
- var val = keyval_arr[1];
- nested_uri.set("minner_var/"+key, val);
- arg_idx += 2;
- }else if( arg == "--dupuri" || arg == "-d" ){
- var val = process.argv[arg_idx+1];
- nested_uri.dupuri(val);
- arg_idx += 2;
- }else if( arg == "--mode" || arg == "-m" ){
- var val = process.argv[arg_idx+1];
- nested_uri.set("outter_var/mod", val);
- arg_idx += 2;
- }else if( arg == "--path" || arg == "-p" ){
- var val = process.argv[arg_idx+1];
- nested_uri.set("outter_var/subfile_path", val);
- arg_idx += 2;
- }else if( arg == "--type" || arg == "-t" ){
- var val = process.argv[arg_idx+1];
- nested_uri.set("outter_var/link_type", val);
- arg_idx += 2;
- }else if( arg == "--help" || arg == "-h" ){
- disp_usage();
- process.exit();
- }else{
- nested_uri.set("inner_uri", arg)
- arg_idx += 1;
- }
-}
-
-
-// discover neoip-oload and act depending on its presence or not
-app_detect.discover_app("oload", function(root_url, version){
- // if oload is present, output nested_uri
- nested_uri.set('outter_uri', root_url);
- console.log(nested_uri.to_string());
-}, function(error){
- // if oload is not present, output plain inner_uri
- var inner_uri = nested_uri.get('inner_uri');
- console.log(inner_uri)
-})
-
-
View
262 obsolete/lib.old/nested_uri_t.js
@@ -1,262 +0,0 @@
-var collection = require('./collection').collection;
-var base64 = require('./base64').base64;
-
-var nested_uri_t = function(nested_uri_str){
- var _col = new collection();
-
- var outter_uri = function(val){ _col.set('outter_uri' , val); }
- var inner_uri = function(val){ _col.set('inner_uri' , val); }
- var outter_var = function(key, val){ return _col.set('outter_var/'+key, val); }
- var minner_var = function(key, val){ return _col.set('minner_var/'+key, val); }
- var dupuri = function(val){
- for(var i = 0; ; i++){
- var key = "outter_var/dupuri/"+i;
- if( _col.has(key) ) continue;
- _col.set(key, val);
- break;
- }
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- // Checker function
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
-
- /** \brief throw an exception is this object is not considered sane
- */
- var _is_sane_internal = function() {
- if( !_col.has("outter_uri") ) throw new Error("No outter_uri");
- if( !_col.has("inner_uri") ) throw new Error("No inner_uri");
-
- // TODO do all the sanity check here
- // - if subfile_level exist, a subfile_path MUST too
- // - subfile_path MUST always start with '/'
- // - if 'type' check the value is a legal one
- // - if 'mod' check the value is a legal one
- // - for dupuri and http_peersrc_uri, it MUST start by 'http://'
- }
-
- /** \brief If this object is considered sane, return true. false otherwise
- */
- var is_sane = function(){
- try {
- // call the version with exception
- _is_sane_internal();
- }catch(error) {
- console.log("nested_uri_t not sane due to " + error);
- return false;
- }
- // if all previous tests passed, this is considered sane
- return true;
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- // to_string() function
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
-
- /** \brief return a string of the nested_uri
- */
- var to_string = function(){
- // some functions pointer for configuration
- //var url_encode_safe = neoip_base64.encode_safe;
- var _url_encode_safe = base64.encode_safe;
- var _url_decode_safe = base64.decode_safe;
- //var url_doscramble = neoip.core.doscramble_uri;
- var _url_doscamble = function(url){ return url; }
- // define local variables
- var result = "";
- // sanity check - the object MUST be sane
- console.assert( is_sane() );
-// neoip-url inner_uri
-// outter_uri = discovered
-// inner_uri = from cmdline
-// --outter_var/-o key=val
-// --minner_var/-i key=val
-//------------------
-// --mode/-m alias for outter_var/mod
-// --dupuri/-d alias for outter_var/dupuri
-// --path/-p alias for outter_var/subfile_path
-// --type/-t alias for outter_var/link_type
-
-// {{outter_uri}}/{{mod}}/(*{{outter_var_key}}*{{outter_var_val}}/)*
-// /{{inner_uri}}(?@)neoip_metavar_{{minner_var_key}}=#{{minner_var_val}}
-
- // start building the nested_uri
- result += _col.get('outter_uri') + "/";
-
- // put the 'mod' variable first
- if( _col.has('outter_var/mod') ) result += _col.get('outter_var/mod') + "/";
-
- // put all the outter variables
- for(var key in _col.get_dfl('outter_var', {}) ){
- // skip key equal to dupuri/subfile_path, they are handled separatly
- if( key == 'dupuri' ) continue;
- if( key == 'subfile_path' ) continue;
- if( key == 'mod' ) continue;
- // put the key of the variable
- result += "*" + key + "*";
- // get the value
- var val = _col.get('outter_var/'+key);
- // http_peersrc_uri is specific - values are encoded in base64-urlsafe
- if( key == "http_peersrc_uri" ) val = url_encode_safe(val)
- // put the values according to the keys
- result += val;
- // add the separator
- result += "/";
- }
-
- // handle outter_var/subfile_path, aka insert the dynamic outter_var subfile_level
- if( _col.has('outter_var/subfile_path') ){
- var subfile_path = _col.get('outter_var/subfile_path');
- var subfile_level = subfile_path.split("/").length - 1; // put the key of the variable
- // add the subfile_level as outter_var in result
- result += "*subfile_level*"+subfile_level+'/';
- }
-
- // put all the dupuri with value in base64-urlsafe encoding
- for(var dupuri_idx in _col.get_dfl('outter_var/dupuri', {})){
- result += "*dupuri*";
- result += _url_encode_safe(_col.get('outter_var/dupuri/'+dupuri_idx));
- result += "/";
- }
-
- // put the inner_uri at the end
- // - made complex by the need to put the m_subfile_path between the
- // path and the query part of the inner_uri
- var inner_uri = _col.get('inner_uri');
- var has_subfile = _col.has('outter_var/subfile_path')
- var subfile_path= _col.get_dfl("outter_var/subfile_path", null);
- var query_pos = inner_uri.indexOf("?");
- if( query_pos != -1 ) result += inner_uri.substr(0, query_pos);
- else result += inner_uri;
- if( subfile_path ) result += subfile_path
- if( query_pos != -1 ) result += inner_uri.substr(query_pos, inner_uri.length);
-
- // put all the inner variables aka "neoip_metavar_"
- for(var key in _col.get_dfl('minner_var', {}) ){
- // put the variable separator
- result += result.indexOf('?') == -1 ? "?" : "&";
- // put the key of the variable
- result += 'neoip_metavar_' + key + "=" + escape(_col.get('minner_var/'+key));
- }
-
- // scramble the result
- result = _url_doscamble(result);
- // return the just built nested_uri
- return result;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- // from_string() function
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- /**
- * Parse a string and set _col with it
- */
- var from_string = function(from_str){
- // some functions pointer for configuration
- //var url_decode_safe = neoip_base64.decode_safe;
- var _url_decode_safe = base64.decode_safe;
- // initialisation of nleft_str/nright_str from nested_str
- var nested_str = from_str;
- var nleft_str = nested_str.substr(0, from_str.indexOf('/http:/'));
- var nright_str = nested_str.substr(from_str.indexOf('/http:/')+1);
- // Process outter_var: consume all the outter_var in nleft_str (outter_var/mod included)
- while( true ){
- // extract last_level from nleft_str
- var last_level = nleft_str.substr(nleft_str.lastIndexOf('/')+1);
- // if last_level is a normally encoded outter_var
- if( last_level.substr(0, 1) == '*' ){
- var matches = last_level.match(/\*(.+)\*(.+)$/);
- var key = matches[1];
- var val = matches[2];
- if( key != "dupuri" ) _col.set('outter_var/'+key, val);
- else dupuri(_url_decode_safe(val));
- }else if( last_level == "raw" || last_level == "flv" ){
- // if last_level is a outter_var/mod
- _col.set('outter_var/mod', last_level)
- }else {
- // if last_level is not recognized, leave the loop
- break;
- }
- // consume in nleft_str
- nleft_str = nleft_str.substr(0, nleft_str.lastIndexOf('/'));
- }
- // set "outter_uri" - what remains in nleft_str is 'outter_uri'
- _col.set("outter_uri", nleft_str);
- // declare the 'actual inner uri variables' array
- var ainner_vars = [];
- // if the right part contains variables, process them to extract minner_vars
- if( nright_str.lastIndexOf('?') != -1 ){
- var search_str = nright_str.substr(nright_str.lastIndexOf('?')+1);
- var keyval_arr = search_str.split("&");
- // go thru each variable
- for(var i = 0; i < keyval_arr.length; i++ ){
- var keyval = keyval_arr[i].split("=");
- var key = keyval[0];
- var val = keyval[1];
- // if this key is not a minner_var, simply copy it in ainner_vars
- if( key.indexOf("neoip_metavar_") != 0 ){
- ainner_vars.push(keyval_arr[i]);
- continue
- }
- var minner_key = key.substr("neoip_metavar_".length);
- _col.set("minner_var/"+minner_key, val);
- }
- // consume the query part of the nright_str
- nright_str = nright_str.substr(0, nright_str.lastIndexOf('?'));
- }
- // if outter_var/subfile_level is present, handle it here
- if( _col.has('outter_var/subfile_level') ){
- var subfile_level = _col.get('outter_var/subfile_level');
- // find the begining of the subfile_path
- var pos = null;
- for(var i = 0; i < subfile_level; i++){
- if( pos ) pos = nright_str.lastIndexOf('/', pos-1);
- else pos = nright_str.lastIndexOf('/');
- }
- // extract the subfile_path
- var subfile_path = nright_str.substr(pos);
- _col.set("outter_var/subfile_path" , subfile_path);
- // delete outter_var/subfile_level
- _col.del("outter_var/subfile_level");
- // consume the subfile_path
- nright_str = nright_str.substr(0, pos);
- }
- // generate the inner_uri
- var inner_uri = nright_str;
- // append actual inner variables, if there is any
- if( ainner_vars.length > 0 ) inner_uri += '?' + ainner_vars.join('&');
- // set inner_uri
- _col.set('inner_uri' , inner_uri);
- }
-
-
- // if nested_uri_str is defined, use it for building the uri
- if( nested_uri_str !== undefined ) from_string(nested_uri_str);
-
- return {
- "outter_uri" : outter_uri,
- "inner_uri" : inner_uri,
- "outter_var" : outter_var,
- "minner_var" : minner_var,
- "dupuri" : dupuri,
- "set" : _col.set,
- "get" : _col.get,
- "get_dfl" : _col.get_dfl,
- "del" : _col.del,
- "has" : _col.has,
- "is_sane" : is_sane,
- "to_string" : to_string,
- "from_string" : from_string
- }
-}
-
-
-// export it via commonjs
-exports.nested_uri_t = nested_uri_t;
View
119 obsolete/lib.old/nested_uri_test.js
@@ -1,119 +0,0 @@
-var nested_uri_t = require('./nested_uri_t').nested_uri_t;
-var assert = {
- equal : function(result, expected, msg){
- if( result == expected ) return;
- console.log("Error: "+msg+" (result:"+JSON.stringify(result)+" expected:"+JSON.stringify(expected)+")");
- }
-}
-var test = function(testname, test_cb){
- console.log("Test "+testname+" Started");
- test_cb();
- console.log("Test "+testname+" Done");
-}
-
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-// tests //
-//////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////
-
-
-// one test
-test("test get/set/has/del consistency", function(){
- // create the initial object
- var nested_uri = new nested_uri_t()
- // define all the values to test
- var testvals = [
- [ 'outter_uri' , "http://localhost:4550" ],
- [ 'inner_uri' , "http://example.com/file.flv?bla=gou" ],
- [ 'outter_var/mod' , 'flv' ],
- [ 'outter_var/dupuri/0' , 'http://jetienne.fr' ],
- ];
- // test all values
- for(var i = 0; i < testvals.length; i++ ){
- var testval = testvals[i];
- var key = testval[0];
- var val = testval[1];
- assert.equal(nested_uri.has(key), false , key+" not present as expected");
- nested_uri.set(key , val);
- assert.equal(nested_uri.has(key), true , key+" present as expected");
- assert.equal(nested_uri.get(key), val , key+" is properly set");
- nested_uri.del(key);
- assert.equal(nested_uri.has(key), false , key+" no more present after delete as expected");
- }
-});
-
-// one test
-test("build most basic uri", function(){
- var nested_uri = new nested_uri_t()
- nested_uri.outter_uri("http://localhost:4550");
- nested_uri.inner_uri("http://example.com/file.flv?bla=gou");
- assert.equal(nested_uri.is_sane(), true , "most basic nested_uri verified as sane");
- // test to_string() produces what is expected
- var result = nested_uri.to_string();
- var expected = "http://localhost:4550/http://example.com/file.flv?bla=gou";
- assert.equal(result, expected, "most basic properly built");
-});
-
-// one test
-test("build with subfile_path", function(){
- var nested_uri = new nested_uri_t()
- nested_uri.outter_uri ("http://localhost:4550");
- nested_uri.inner_uri ("http://example.com/file.flv?bla=gou");
- nested_uri.set ("outter_var/subfile_path" , "/test/file");
- var result = nested_uri.to_string();
- var expected = "http://localhost:4550/*subfile_level*2/http://example.com/file.flv/test/file?bla=gou";
- assert.equal(result, expected, "properly built");
-});
-
-test("build with dupuri", function(){
- // create the initial object
- var nested_uri = new nested_uri_t()
- // define all the values to test
- var keys = [
- [ 'outter_uri' , "http://localhost:4550" ],
- [ 'inner_uri' , "http://example.com/file.flv?bla=gou" ],
- [ 'outter_var/mod' , 'flv' ],
- [ 'outter_var/dupuri/0' , 'http://jetienne.fr' ],
- ];
- var expected = "http://localhost:4550/flv/*dupuri*aHR0cDovL2pldGllbm5lLmZy/http://example.com/file.flv?bla=gou"
- // test all values
- for(var i = 0; i < keys.length; i++ ) nested_uri.set(keys[i][0], keys[i][1]);
- var result = nested_uri.to_string();
- var expected = "http://localhost:4550/flv/*dupuri*aHR0cDovL2pldGllbm5lLmZy/http://example.com/file.flv?bla=gou"
- assert.equal(result, expected, "properly built");
- // test self consistency parse/build
- var result = (new nested_uri_t(result)).to_string();
- assert.equal(result, expected, "parse/build self consistent with dupuri");
-});
-
-
-// one test
-test("build with outter_var/mod", function(){
- var nested_uri = new nested_uri_t()
- nested_uri.outter_uri ("http://localhost:4550");
- nested_uri.inner_uri ("http://example.com/file.flv?bla=gou");
- nested_uri.set ("outter_var/mod" , "flv");
- console.log("nested_uri="+nested_uri.to_string());
- var result = nested_uri.to_string();
- var expected = "http://localhost:4550/flv/http://example.com/file.flv?bla=gou";
- assert.equal(result, expected, "properly built");
-});
-
-
-/**
- * parse/build consistency
-*/
-test('parse/build consistency', function(){
- // define all the values to test
- var testvals = [
- "http://localhost:4550/flv/*subfile_level*2/http://example.com/file.flv/test/file?bla=gou",
- "http://localhost:4550/raw/http://example.com/file?bla=gou&foo=bar&neoip_metavar_prout=slota",
- ];
- for(var i = 0; i < testvals.length; i ++){
- var expected = testvals[i];
- var nested_uri = new nested_uri_t(expected);
- var result = nested_uri.to_string();
- assert.equal(result, expected, "self consistant nested uri "+expected);
- }
-});
View
5 obsolete/neoip-url
@@ -1,5 +0,0 @@
-#!/usr/bin/env node
-// - during dev, NODE_PATH=.:~/.node_libraries/ node neoip-url http://localhost
-// - this add . in the library path
-
-require('../lib/oload_url_builder');
View
196 obsolete/neoip.js
@@ -1,196 +0,0 @@
-var sys = require('sys');
-var http = require('http');
-var assert = require('assert');
-
-/**
- * Probe an application
-*/
-var probe_app = function(apps_suffix, host, port, method_name, success_cb, failure_cb){
- var path = "/neoip_"+apps_suffix+"_appdetect_jsrest.js?method_name="+method_name;
- var client = http.createClient(port, host);
- // if callback are not specified, use a dummy one
- if(!success_cb) success_cb = function(){};
- if(!failure_cb) failure_cb = function(){};
- // bind error cases at the socket level
- client.addListener("error" , failure_cb);
- client.addListener("timeout" , failure_cb);
- // create the request
- var request = client.request('GET', path, {'host': host});
- request.addListener('response', function(response){
- //sys.puts('STATUS: ' + response.statusCode);
- //sys.puts('HEADERS: ' + JSON.stringify(response.headers));
- // Handle faillure at http level
- if(response.statusCode != 200){
- failure_cb(new Error("http statuscode="+response.statuscode));
- return
- }
- response.setEncoding('utf8');
- response.addListener('data', function( reply_json ){
- //sys.puts('BODY: ' + reply_json);
- // REPORT: JSON.parse(' {};'); hangs in node-console
- // get data from the chunk
- var reply_data = JSON.parse(reply_json);
- var returned_val= reply_data['returned_val'];
- success_cb(returned_val);
- });
- });
- request.end();
-};
-
-/**
- * Constant informations about applications
-*/
-var app_infos = {
- "oload": {
- "port_beg": 4550,
- "port_end": 4553
- },
- "casto": {
- "port_beg": 4560,
- "port_end": 4563
- },
- "casti": {
- "port_beg": 4570,
- "port_end": 4573
- }
-};
-
-
-var disc_app_cache = {};
-var disc_app_cache_contain = function(app_suffix){ return app_suffix in disc_app_cache_contain; }
-exports.disc_app_cache = disc_app_cache;
-
-/**
- * Discover an neoip application
- *
- * @param {String} app_suffix the neoip application suffix
- * @param {function} success_cb notified if app is found success_cb(root_url, version)
- * @param {function} failure_cb notified if app is not found failure_cb(reason)
-*/
-var discover_app = function(app_suffix, success_cb, failure_cb){
- // sanity check
- assert.ok(success_cb);
- assert.ok(app_suffix == "oload" || app_suffix == "casti" || app_suffix == "casto");
- // if callback are not specified, use a dummy one
- if(!failure_cb) failure_cb = function(){};
- // handle cache
- if(app_suffix in disc_app_cache){
- var cache_item = disc_app_cache[app_suffix];
- if( cache_item.version === false ){
- setTimeout(function(){failure_cb(true);}, 0);
- }else{
- setTimeout(function(){success_cb(cache_item.root_url, cache_item.version)}, 0);
- }
- return;
- }
- // get info from app_infos
- var port_beg = app_infos[app_suffix]["port_beg"];
- var port_end = app_infos[app_suffix]["port_end"];
- var port_cur = port_beg;
- // define the callbacks
- var probe_succ_cb = function(version){
- //sys.puts("found version "+version+" port_cur="+port_cur);
- var root_url = "http://127.0.0.1:"+port_cur;
- // cache the result
- disc_app_cache[app_suffix] = {
- "root_url" : root_url,
- "version" : version
- };
- // notify the caller
- success_cb(root_url, version);
- };
- var probe_fail_cb = function(had_error){
- //sys.puts('not found port_cur='+port_cur);
- if(port_cur == port_end){
- // cache the result
- disc_app_cache[app_suffix] = { "version" : false };
- // report "not found" when all port has been tested
- failure_cb("not found");
- }else{
- // test the next port
- port_cur++;
- probe_app(app_suffix, "127.0.0.1", port_cur, "probe_apps", probe_succ_cb, probe_fail_cb);
- }
- };
- // start the probbing
- probe_app(app_suffix, "127.0.0.1", port_cur, "probe_apps", probe_succ_cb, probe_fail_cb);
-}
-
-exports.discover_app = discover_app;
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-// Webpack
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Compare version ala memcmp
- * - used in discover_webpack()
-*/
-var version_compare = function(version1, version2){
- // parse the versions
- var matches1 = version1.match(/(\d+).(\d+).(\d+)/);
- var matches2 = version2.match(/(\d+).(\d+).(\d+)/);
- // compare the major
- var major1 = parseInt(matches1[1], 10);
- var major2 = parseInt(matches2[1], 10);
- if( major1 > major2 ) return +1;
- if( major1 < major2 ) return -1;
- // compare the minor
- var minor1 = parseInt(matches1[2], 10);
- var minor2 = parseInt(matches2[2], 10);
- if( minor1 > minor2 ) return +1;
- if( minor1 < minor2 ) return -1;
- // compare the patch
- var patch1 = parseInt(matches1[3], 10);
- var patch2 = parseInt(matches2[3], 10);