pcapr-local 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +64 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/bin/pcap2par +49 -0
- data/bin/startpcapr +40 -0
- data/bin/stoppcapr +33 -0
- data/bin/xtractr +5 -0
- data/lib/environment.rb +106 -0
- data/lib/exe/xtractr +0 -0
- data/lib/mu/pcap.rb +110 -0
- data/lib/mu/pcap/ethernet.rb +148 -0
- data/lib/mu/pcap/header.rb +75 -0
- data/lib/mu/pcap/io_pair.rb +67 -0
- data/lib/mu/pcap/io_wrapper.rb +76 -0
- data/lib/mu/pcap/ip.rb +61 -0
- data/lib/mu/pcap/ipv4.rb +257 -0
- data/lib/mu/pcap/ipv6.rb +148 -0
- data/lib/mu/pcap/packet.rb +104 -0
- data/lib/mu/pcap/pkthdr.rb +155 -0
- data/lib/mu/pcap/reader.rb +61 -0
- data/lib/mu/pcap/reader/http_family.rb +170 -0
- data/lib/mu/pcap/sctp.rb +367 -0
- data/lib/mu/pcap/sctp/chunk.rb +123 -0
- data/lib/mu/pcap/sctp/chunk/data.rb +134 -0
- data/lib/mu/pcap/sctp/chunk/init.rb +100 -0
- data/lib/mu/pcap/sctp/chunk/init_ack.rb +68 -0
- data/lib/mu/pcap/sctp/parameter.rb +110 -0
- data/lib/mu/pcap/sctp/parameter/ip_address.rb +48 -0
- data/lib/mu/pcap/stream_packetizer.rb +72 -0
- data/lib/mu/pcap/tcp.rb +505 -0
- data/lib/mu/pcap/udp.rb +69 -0
- data/lib/mu/scenario/pcap.rb +164 -0
- data/lib/mu/scenario/pcap/fields.rb +50 -0
- data/lib/mu/scenario/pcap/rtp.rb +71 -0
- data/lib/pcapr_local.rb +159 -0
- data/lib/pcapr_local/config.rb +336 -0
- data/lib/pcapr_local/db.rb +197 -0
- data/lib/pcapr_local/scanner.rb +250 -0
- data/lib/pcapr_local/server.rb +178 -0
- data/lib/pcapr_local/www/favicon.ico +0 -0
- data/lib/pcapr_local/www/favicon.png +0 -0
- data/lib/pcapr_local/www/home/index.html +138 -0
- data/lib/pcapr_local/www/static/image/16x16/Cancel.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Cancel.png.1 +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Download.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Folder3.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Full Size.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Minus.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Plus.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/Search.png +0 -0
- data/lib/pcapr_local/www/static/image/16x16/User.png +0 -0
- data/lib/pcapr_local/www/static/image/48x48/Phone.png +0 -0
- data/lib/pcapr_local/www/static/image/48x48/Video.png +0 -0
- data/lib/pcapr_local/www/static/image/bar-orange.gif +0 -0
- data/lib/pcapr_local/www/static/image/beta.png +0 -0
- data/lib/pcapr_local/www/static/image/bg.png +0 -0
- data/lib/pcapr_local/www/static/image/blockquote.png +0 -0
- data/lib/pcapr_local/www/static/image/body-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/body-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl1-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl1-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl1-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl2-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl2-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl2-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl3-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl3-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl3-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl4-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl4-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl4-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl5-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl6-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl7-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-hl8-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/body-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/bottom-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/bottom-l.png +0 -0
- data/lib/pcapr_local/www/static/image/bottom-r.png +0 -0
- data/lib/pcapr_local/www/static/image/btn-search.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-1.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-2.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-3.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-4.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-5.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-6.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-7.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-hl1.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-hl2.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-hl3.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-hl4.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-pathway.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-section1.png +0 -0
- data/lib/pcapr_local/www/static/image/bullet-section2.png +0 -0
- data/lib/pcapr_local/www/static/image/collapsed.gif +0 -0
- data/lib/pcapr_local/www/static/image/crosslink.png +0 -0
- data/lib/pcapr_local/www/static/image/expanded.gif +0 -0
- data/lib/pcapr_local/www/static/image/favicon.ico +0 -0
- data/lib/pcapr_local/www/static/image/favicon.png +0 -0
- data/lib/pcapr_local/www/static/image/icon-author.png +0 -0
- data/lib/pcapr_local/www/static/image/icon-created.png +0 -0
- data/lib/pcapr_local/www/static/image/p-expand.gif +0 -0
- data/lib/pcapr_local/www/static/image/pcapr-logo.png +0 -0
- data/lib/pcapr_local/www/static/image/powered-by.png +0 -0
- data/lib/pcapr_local/www/static/image/section1-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/section1-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/section1-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/section2-bg.png +0 -0
- data/lib/pcapr_local/www/static/image/section2-h3.png +0 -0
- data/lib/pcapr_local/www/static/image/section2-readmore.png +0 -0
- data/lib/pcapr_local/www/static/image/status-alert.png +0 -0
- data/lib/pcapr_local/www/static/image/status-download.png +0 -0
- data/lib/pcapr_local/www/static/image/status-info.png +0 -0
- data/lib/pcapr_local/www/static/image/status-note.png +0 -0
- data/lib/pcapr_local/www/static/image/tab-round.png +0 -0
- data/lib/pcapr_local/www/static/image/throbber.gif +0 -0
- data/lib/pcapr_local/www/static/image/user.jpg +0 -0
- data/lib/pcapr_local/www/static/script/closet/async.js +421 -0
- data/lib/pcapr_local/www/static/script/closet/closet.api.js +241 -0
- data/lib/pcapr_local/www/static/script/closet/closet.folders.js +94 -0
- data/lib/pcapr_local/www/static/script/closet/closet.js +187 -0
- data/lib/pcapr_local/www/static/script/closet/closet.mr.js +219 -0
- data/lib/pcapr_local/www/static/script/closet/closet.options.js +359 -0
- data/lib/pcapr_local/www/static/script/closet/closet.quantity.js +73 -0
- data/lib/pcapr_local/www/static/script/closet/closet.render.js +205 -0
- data/lib/pcapr_local/www/static/script/closet/closet.report.js +86 -0
- data/lib/pcapr_local/www/static/script/closet/closet.reports.http.js +135 -0
- data/lib/pcapr_local/www/static/script/closet/closet.reports.overview.js +163 -0
- data/lib/pcapr_local/www/static/script/closet/closet.reports.sip.js +159 -0
- data/lib/pcapr_local/www/static/script/closet/closet.reports.tcp.js +72 -0
- data/lib/pcapr_local/www/static/script/closet/closet.reports.visualize.js +263 -0
- data/lib/pcapr_local/www/static/script/closet/closet.util.js +40 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery-1.4.2.min.js +154 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery-ui.js +10921 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.flot.js +2123 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.flot.selection.js +184 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.flot.stack.js +184 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.form.js +643 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.jsonp.min.js +3 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.menu.js +142 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.suggest.js +308 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.ui.core.js +203 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.ui.slider.js +629 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.ui.sortable.js +1055 -0
- data/lib/pcapr_local/www/static/script/jquery/jquery.ui.widget.js +236 -0
- data/lib/pcapr_local/www/static/script/json2.js +481 -0
- data/lib/pcapr_local/www/static/script/sammy/plugins/sammy.cache.js +115 -0
- data/lib/pcapr_local/www/static/script/sammy/plugins/sammy.template.js +117 -0
- data/lib/pcapr_local/www/static/script/sammy/sammy.js +1696 -0
- data/lib/pcapr_local/www/static/script/tipsy/jquery.tipsy.js +104 -0
- data/lib/pcapr_local/www/static/style/c3p0.css +116 -0
- data/lib/pcapr_local/www/static/style/jquery.suggest.css +27 -0
- data/lib/pcapr_local/www/static/style/page.css +1113 -0
- data/lib/pcapr_local/www/static/style/tipsy.css +7 -0
- data/lib/pcapr_local/www/templates/browse.services.template +10 -0
- data/lib/pcapr_local/www/templates/browse.template +77 -0
- data/lib/pcapr_local/www/templates/flows.template +38 -0
- data/lib/pcapr_local/www/templates/pcap.template +63 -0
- data/lib/pcapr_local/www/templates/sip.calls.template +35 -0
- data/lib/pcapr_local/www/templates/statistics.template +6 -0
- data/lib/pcapr_local/xtractr.rb +179 -0
- data/lib/pcapr_local/xtractr/instance.rb +172 -0
- data/pcapr-local.gemspec +297 -0
- data/test/mu/pcap/reader/tc_http_family.rb +251 -0
- data/test/mu/pcap/tc_ethernet.rb +71 -0
- data/test/mu/pcap/tc_header.rb +56 -0
- data/test/mu/pcap/tc_ipv4.rb +103 -0
- data/test/mu/pcap/tc_ipv6.rb +83 -0
- data/test/mu/pcap/tc_packet.rb +44 -0
- data/test/mu/pcap/tc_pair.rb +58 -0
- data/test/mu/pcap/tc_pkthdr.rb +33 -0
- data/test/mu/pcap/tc_reader.rb +76 -0
- data/test/mu/pcap/tc_tcp.rb +426 -0
- data/test/mu/pcap/tc_udp.rb +33 -0
- data/test/mu/pcap/tc_wrapper.rb +80 -0
- data/test/mu/scenario/pcap/tc_fields.rb +67 -0
- data/test/mu/scenario/pcap/tc_rtp.rb +135 -0
- data/test/mu/scenario/sip_signalled_call_1.pcap +0 -0
- data/test/mu/scenario/tc_pcap.rb +190 -0
- data/test/mu/scenario/test_data/arp.pcap +0 -0
- data/test/mu/scenario/test_data/dns.pcap +0 -0
- data/test/mu/scenario/test_data/http-v6.pcap +0 -0
- data/test/mu/scenario/test_data/http.pcap +0 -0
- data/test/mu/scenario/test_data/http_chunked.pcap +0 -0
- data/test/mu/scenario/test_data/http_deflate.pcap +0 -0
- data/test/mu/scenario/test_data/httpauth3.pcap +0 -0
- data/test/mu/scenario/test_data/icmp.pcap +0 -0
- data/test/mu/scenario/test_data/sip_signalled_call_1.pcap +0 -0
- data/test/mu/tc_pcap.rb +39 -0
- data/test/mu/testcase.rb +86 -0
- data/test/pcapr_local/arp.pcap +0 -0
- data/test/pcapr_local/data.js +3 -0
- data/test/pcapr_local/http_chunked.pcap +0 -0
- data/test/pcapr_local/tc_api.rb +181 -0
- data/test/pcapr_local/test.tgz +0 -0
- data/test/pcapr_local/test_scanner.rb +241 -0
- data/test/pcapr_local/test_xtractr.rb +219 -0
- data/test/pcapr_local/testcase.rb +107 -0
- data/test/test_export_to_scenario.sh +25 -0
- data/test/test_pcapr_local.rb +29 -0
- metadata +450 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
(function(){
|
|
2
|
+
|
|
3
|
+
var async = {};
|
|
4
|
+
|
|
5
|
+
// global on the server, window in the browser
|
|
6
|
+
var root = this;
|
|
7
|
+
var previous_async = root.async;
|
|
8
|
+
|
|
9
|
+
if(typeof module !== 'undefined' && module.exports) module.exports = async;
|
|
10
|
+
else root.async = async;
|
|
11
|
+
|
|
12
|
+
async.noConflict = function(){
|
|
13
|
+
root.async = previous_async;
|
|
14
|
+
return async;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//// cross-browser compatiblity functions ////
|
|
18
|
+
|
|
19
|
+
var _forEach = function(arr, iterator){
|
|
20
|
+
if(arr.forEach) return arr.forEach(iterator);
|
|
21
|
+
for(var i=0; i<arr.length; i++){
|
|
22
|
+
iterator(arr[i], i, arr);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var _map = function(arr, iterator){
|
|
27
|
+
if(arr.map) return arr.map(iterator);
|
|
28
|
+
var results = [];
|
|
29
|
+
_forEach(arr, function(x, i, a){
|
|
30
|
+
results.push(iterator(x, i, a));
|
|
31
|
+
})
|
|
32
|
+
return results;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var _reduce = function(arr, iterator, memo){
|
|
36
|
+
if(arr.reduce) return arr.reduce(iterator, memo);
|
|
37
|
+
_forEach(arr, function(x, i, a){
|
|
38
|
+
memo = iterator(memo, x, i, a);
|
|
39
|
+
});
|
|
40
|
+
return memo;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var _keys = function(obj){
|
|
44
|
+
if(Object.keys) return Object.keys(obj);
|
|
45
|
+
var keys = [];
|
|
46
|
+
for(var k in obj){
|
|
47
|
+
if(obj.hasOwnProperty(k)) keys.push(k);
|
|
48
|
+
}
|
|
49
|
+
return keys;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var _indexOf = function(arr, item){
|
|
53
|
+
if(arr.indexOf) return arr.indexOf(item);
|
|
54
|
+
for(var i=0; i<arr.length; i++){
|
|
55
|
+
if(arr[i] === item) return i;
|
|
56
|
+
}
|
|
57
|
+
return -1;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//// exported async module functions ////
|
|
61
|
+
|
|
62
|
+
//// nextTick implementation with browser-compatible fallback ////
|
|
63
|
+
async.nextTick = function(fn){
|
|
64
|
+
if(typeof process == 'undefined' || !(process.nextTick)){
|
|
65
|
+
setTimeout(fn, 0);
|
|
66
|
+
}
|
|
67
|
+
else process.nextTick(fn);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
async.forEach = function(arr, iterator, callback){
|
|
71
|
+
if(!arr.length) return callback();
|
|
72
|
+
var completed = 0;
|
|
73
|
+
_forEach(arr, function(x){
|
|
74
|
+
iterator(x, function(err){
|
|
75
|
+
if(err){
|
|
76
|
+
callback(err);
|
|
77
|
+
callback = function(){};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
completed++;
|
|
81
|
+
if(completed == arr.length) callback();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
async.forEachSeries = function(arr, iterator, callback){
|
|
88
|
+
if(!arr.length) return callback();
|
|
89
|
+
var completed = 0;
|
|
90
|
+
var iterate = function(){
|
|
91
|
+
iterator(arr[completed], function(err){
|
|
92
|
+
if(err){
|
|
93
|
+
callback(err);
|
|
94
|
+
callback = function(){};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
completed++;
|
|
98
|
+
if(completed == arr.length) callback();
|
|
99
|
+
else iterate();
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
iterate();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
var doParallel = function(fn){
|
|
108
|
+
return function(){
|
|
109
|
+
var args = Array.prototype.slice.call(arguments);
|
|
110
|
+
return fn.apply(null, [async.forEach].concat(args));
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
var doSeries = function(fn){
|
|
114
|
+
return function(){
|
|
115
|
+
var args = Array.prototype.slice.call(arguments);
|
|
116
|
+
return fn.apply(null, [async.forEachSeries].concat(args));
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
var _asyncMap = function(eachfn, arr, iterator, callback){
|
|
122
|
+
var results = [];
|
|
123
|
+
arr = _map(arr, function(x, i){
|
|
124
|
+
return {index: i, value: x};
|
|
125
|
+
});
|
|
126
|
+
eachfn(arr, function(x, callback){
|
|
127
|
+
iterator(x.value, function(err, v){
|
|
128
|
+
results[x.index] = v;
|
|
129
|
+
callback(err);
|
|
130
|
+
});
|
|
131
|
+
}, function(err){
|
|
132
|
+
callback(err, results);
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
async.map = doParallel(_asyncMap);
|
|
136
|
+
async.mapSeries = doSeries(_asyncMap);
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// reduce only has a series version, as doing reduce in parallel won't
|
|
140
|
+
// work in many situations.
|
|
141
|
+
async.reduce = function(arr, memo, iterator, callback){
|
|
142
|
+
async.forEachSeries(arr, function(x, callback){
|
|
143
|
+
iterator(memo, x, function(err, v){
|
|
144
|
+
memo = v;
|
|
145
|
+
callback(err);
|
|
146
|
+
});
|
|
147
|
+
}, function(err){
|
|
148
|
+
callback(err, memo);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
// inject alias
|
|
152
|
+
async.inject = async.reduce;
|
|
153
|
+
// foldl alias
|
|
154
|
+
async.foldl = async.reduce;
|
|
155
|
+
|
|
156
|
+
async.reduceRight = function(arr, memo, iterator, callback){
|
|
157
|
+
var reversed = _map(arr, function(x){return x;}).reverse();
|
|
158
|
+
async.reduce(reversed, memo, iterator, callback);
|
|
159
|
+
};
|
|
160
|
+
// foldr alias
|
|
161
|
+
async.foldr = async.reduceRight;
|
|
162
|
+
|
|
163
|
+
var _filter = function(eachfn, arr, iterator, callback){
|
|
164
|
+
var results = [];
|
|
165
|
+
arr = _map(arr, function(x, i){
|
|
166
|
+
return {index: i, value: x};
|
|
167
|
+
});
|
|
168
|
+
eachfn(arr, function(x, callback){
|
|
169
|
+
iterator(x.value, function(v){
|
|
170
|
+
if(v) results.push(x);
|
|
171
|
+
callback();
|
|
172
|
+
});
|
|
173
|
+
}, function(err){
|
|
174
|
+
callback(_map(results.sort(function(a,b){
|
|
175
|
+
return a.index - b.index;
|
|
176
|
+
}), function(x){
|
|
177
|
+
return x.value;
|
|
178
|
+
}));
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
async.filter = doParallel(_filter);
|
|
182
|
+
async.filterSeries = doSeries(_filter);
|
|
183
|
+
// select alias
|
|
184
|
+
async.select = async.filter;
|
|
185
|
+
async.selectSeries = async.filterSeries;
|
|
186
|
+
|
|
187
|
+
var _reject = function(eachfn, arr, iterator, callback){
|
|
188
|
+
var results = [];
|
|
189
|
+
arr = _map(arr, function(x, i){
|
|
190
|
+
return {index: i, value: x};
|
|
191
|
+
});
|
|
192
|
+
eachfn(arr, function(x, callback){
|
|
193
|
+
iterator(x.value, function(v){
|
|
194
|
+
if(!v) results.push(x);
|
|
195
|
+
callback();
|
|
196
|
+
});
|
|
197
|
+
}, function(err){
|
|
198
|
+
callback(_map(results.sort(function(a,b){
|
|
199
|
+
return a.index - b.index;
|
|
200
|
+
}), function(x){
|
|
201
|
+
return x.value;
|
|
202
|
+
}));
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
async.reject = doParallel(_reject);
|
|
206
|
+
async.rejectSeries = doSeries(_reject);
|
|
207
|
+
|
|
208
|
+
var _detect = function(eachfn, arr, iterator, main_callback){
|
|
209
|
+
eachfn(arr, function(x, callback){
|
|
210
|
+
iterator(x, function(result){
|
|
211
|
+
if(result) main_callback(x);
|
|
212
|
+
else callback();
|
|
213
|
+
});
|
|
214
|
+
}, function(err){
|
|
215
|
+
main_callback();
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
async.detect = doParallel(_detect);
|
|
219
|
+
async.detectSeries = doSeries(_detect);
|
|
220
|
+
|
|
221
|
+
async.some = function(arr, iterator, main_callback){
|
|
222
|
+
async.forEach(arr, function(x, callback){
|
|
223
|
+
iterator(x, function(v){
|
|
224
|
+
if(v){
|
|
225
|
+
main_callback(true);
|
|
226
|
+
main_callback = function(){};
|
|
227
|
+
}
|
|
228
|
+
callback();
|
|
229
|
+
});
|
|
230
|
+
}, function(err){
|
|
231
|
+
main_callback(false);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
// any alias
|
|
235
|
+
async.any = async.some;
|
|
236
|
+
|
|
237
|
+
async.every = function(arr, iterator, main_callback){
|
|
238
|
+
async.forEach(arr, function(x, callback){
|
|
239
|
+
iterator(x, function(v){
|
|
240
|
+
if(!v){
|
|
241
|
+
main_callback(false);
|
|
242
|
+
main_callback = function(){};
|
|
243
|
+
}
|
|
244
|
+
callback();
|
|
245
|
+
});
|
|
246
|
+
}, function(err){
|
|
247
|
+
main_callback(true);
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
// all alias
|
|
251
|
+
async.all = async.every;
|
|
252
|
+
|
|
253
|
+
async.sortBy = function(arr, iterator, callback){
|
|
254
|
+
async.map(arr, function(x, callback){
|
|
255
|
+
iterator(x, function(err, criteria){
|
|
256
|
+
if(err) callback(err);
|
|
257
|
+
else callback(null, {value: x, criteria: criteria});
|
|
258
|
+
});
|
|
259
|
+
}, function(err, results){
|
|
260
|
+
if(err) return callback(err);
|
|
261
|
+
else callback(null, _map(results.sort(function(left, right){
|
|
262
|
+
var a = left.criteria, b = right.criteria;
|
|
263
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
264
|
+
}), function(x){return x.value;}));
|
|
265
|
+
})
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
async.auto = function(tasks, callback){
|
|
269
|
+
callback = callback || function(){};
|
|
270
|
+
var keys = _keys(tasks);
|
|
271
|
+
if(!keys.length) return callback(null);
|
|
272
|
+
|
|
273
|
+
var completed = [];
|
|
274
|
+
|
|
275
|
+
var listeners = [];
|
|
276
|
+
var addListener = function(fn){
|
|
277
|
+
listeners.unshift(fn);
|
|
278
|
+
};
|
|
279
|
+
var removeListener = function(fn){
|
|
280
|
+
for(var i=0; i<listeners.length; i++){
|
|
281
|
+
if(listeners[i] === fn){
|
|
282
|
+
listeners.splice(i, 1);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var taskComplete = function(){
|
|
288
|
+
_forEach(listeners, function(fn){fn();});
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
addListener(function(){
|
|
292
|
+
if(completed.length == keys.length){
|
|
293
|
+
callback(null);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
_forEach(keys, function(k){
|
|
298
|
+
var task = (tasks[k] instanceof Function)? [tasks[k]]: tasks[k];
|
|
299
|
+
var taskCallback = function(err){
|
|
300
|
+
if(err){
|
|
301
|
+
callback(err);
|
|
302
|
+
// stop subsequent errors hitting callback multiple times
|
|
303
|
+
callback = function(){};
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
completed.push(k);
|
|
307
|
+
taskComplete();
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
var requires = task.slice(0, Math.abs(task.length-1)) || [];
|
|
311
|
+
var ready = function(){
|
|
312
|
+
return _reduce(requires, function(a,x){
|
|
313
|
+
return (a && _indexOf(completed, x) != -1);
|
|
314
|
+
}, true);
|
|
315
|
+
};
|
|
316
|
+
if(ready()) task[task.length-1](taskCallback);
|
|
317
|
+
else {
|
|
318
|
+
var listener = function(){
|
|
319
|
+
if(ready()){
|
|
320
|
+
removeListener(listener);
|
|
321
|
+
task[task.length-1](taskCallback);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
addListener(listener);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
async.waterfall = function(tasks, callback){
|
|
330
|
+
if(!tasks.length) return callback();
|
|
331
|
+
callback = callback || function(){};
|
|
332
|
+
var wrapIterator = function(iterator){
|
|
333
|
+
return function(err){
|
|
334
|
+
if(err){
|
|
335
|
+
callback(err);
|
|
336
|
+
callback = function(){};
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
340
|
+
var next = iterator.next();
|
|
341
|
+
if(next) args.push(wrapIterator(next));
|
|
342
|
+
else args.push(callback);
|
|
343
|
+
async.nextTick(function(){iterator.apply(null, args);});
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
wrapIterator(async.iterator(tasks))();
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
async.parallel = function(tasks, callback){
|
|
351
|
+
callback = callback || function(){};
|
|
352
|
+
async.map(tasks, function(fn, callback){
|
|
353
|
+
if(fn){
|
|
354
|
+
fn(function(err){
|
|
355
|
+
var args = Array.prototype.slice.call(arguments,1);
|
|
356
|
+
if(args.length <= 1) args = args[0];
|
|
357
|
+
callback.call(null, err, args || null);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}, callback);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
async.series = function(tasks, callback){
|
|
364
|
+
callback = callback || function(){};
|
|
365
|
+
async.mapSeries(tasks, function(fn, callback){
|
|
366
|
+
if(fn){
|
|
367
|
+
fn(function(err){
|
|
368
|
+
var args = Array.prototype.slice.call(arguments,1);
|
|
369
|
+
if(args.length <= 1) args = args[0];
|
|
370
|
+
callback.call(null, err, args || null);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}, callback);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
async.iterator = function(tasks){
|
|
377
|
+
var makeCallback = function(index){
|
|
378
|
+
var fn = function(){
|
|
379
|
+
if(tasks.length) tasks[index].apply(null, arguments);
|
|
380
|
+
return fn.next();
|
|
381
|
+
};
|
|
382
|
+
fn.next = function(){
|
|
383
|
+
return (index < tasks.length-1)? makeCallback(index+1): null;
|
|
384
|
+
};
|
|
385
|
+
return fn;
|
|
386
|
+
};
|
|
387
|
+
return makeCallback(0);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
async.apply = function(fn){
|
|
391
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
392
|
+
return function(){
|
|
393
|
+
return fn.apply(
|
|
394
|
+
null, args.concat(Array.prototype.slice.call(arguments))
|
|
395
|
+
);
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
var _console_fn = function(name){
|
|
400
|
+
return function(fn){
|
|
401
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
402
|
+
fn.apply(null, args.concat([function(err){
|
|
403
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
404
|
+
if(typeof console != 'undefined'){
|
|
405
|
+
if(err){
|
|
406
|
+
if(console.error) console.error(err);
|
|
407
|
+
}
|
|
408
|
+
else if(console[name]){
|
|
409
|
+
_forEach(args, function(x){console[name](x);});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}]));
|
|
413
|
+
};
|
|
414
|
+
};
|
|
415
|
+
async.log = _console_fn('log');
|
|
416
|
+
async.dir = _console_fn('dir');
|
|
417
|
+
/*async.info = _console_fn('info');
|
|
418
|
+
async.warn = _console_fn('warn');
|
|
419
|
+
async.error = _console_fn('error');*/
|
|
420
|
+
|
|
421
|
+
})();
|