From da7d8e3763c39ff6217b0d4f8328b64849bcb416 Mon Sep 17 00:00:00 2001 From: Daplie Date: Fri, 13 Jan 2017 19:04:27 -0700 Subject: [PATCH] adding new files --- README.md | 53 ++ cloud-respond.js | 105 +++ howto.md | 4 + ip.js | 19 + listen.js | 44 + node_modules/assert-plus/AUTHORS | 6 + node_modules/assert-plus/CHANGES.md | 14 + node_modules/assert-plus/README.md | 162 ++++ node_modules/assert-plus/assert.js | 211 +++++ node_modules/assert-plus/package.json | 115 +++ node_modules/binaryheap/.npmignore | 3 + node_modules/binaryheap/README.md | 43 + node_modules/binaryheap/binaryheap.js | 313 +++++++ node_modules/binaryheap/example.js | 15 + node_modules/binaryheap/package.json | 91 ++ node_modules/binaryheap/test.js | 96 +++ node_modules/buffercursor/README.md | 47 ++ node_modules/buffercursor/buffercursor.js | 388 +++++++++ node_modules/buffercursor/package.json | 85 ++ node_modules/core-util-is/LICENSE | 19 + node_modules/core-util-is/README.md | 3 + node_modules/core-util-is/float.patch | 604 ++++++++++++++ node_modules/core-util-is/lib/util.js | 107 +++ node_modules/core-util-is/package.json | 94 +++ node_modules/core-util-is/test.js | 68 ++ node_modules/debug/.coveralls.yml | 1 + node_modules/debug/.eslintrc | 11 + node_modules/debug/.jshintrc | 3 + node_modules/debug/.npmignore | 7 + node_modules/debug/.travis.yml | 14 + node_modules/debug/CHANGELOG.md | 228 +++++ node_modules/debug/LICENSE | 19 + node_modules/debug/Makefile | 37 + node_modules/debug/README.md | 238 ++++++ node_modules/debug/Readme.md | 199 +++++ node_modules/debug/bower.json | 29 + node_modules/debug/browser.js | 175 ++++ node_modules/debug/component.json | 19 + node_modules/debug/debug.js | 200 +++++ node_modules/debug/index.js | 10 + node_modules/debug/karma.conf.js | 70 ++ node_modules/debug/node.js | 213 +++++ node_modules/debug/package.json | 122 +++ node_modules/debug/src/browser.js | 182 ++++ node_modules/debug/src/debug.js | 199 +++++ node_modules/debug/src/index.js | 10 + node_modules/debug/src/node.js | 240 ++++++ node_modules/dns-js/.eslintignore | 1 + node_modules/dns-js/.eslintrc | 23 + node_modules/dns-js/.npmignore | 4 + node_modules/dns-js/.travis.yml | 4 + node_modules/dns-js/LICENSE | 19 + node_modules/dns-js/README.md | 49 ++ node_modules/dns-js/doc/edns.md | 49 ++ node_modules/dns-js/doc/rcode.md | 35 + node_modules/dns-js/doc/records.md | 58 ++ .../dns-js/examples/resolveaddress.js | 47 ++ node_modules/dns-js/examples/resolvename.js | 64 ++ node_modules/dns-js/index.js | 2 + node_modules/dns-js/lib/.dnspacket.js.swp | Bin 0 -> 16384 bytes node_modules/dns-js/lib/bufferconsumer.js | 169 ++++ node_modules/dns-js/lib/bufferwriter.js | 138 ++++ node_modules/dns-js/lib/dnspacket.js | 260 ++++++ node_modules/dns-js/lib/dnsrecord.js | 353 ++++++++ node_modules/dns-js/lib/errors.js | 11 + node_modules/dns-js/lib/index.js | 8 + node_modules/dns-js/package.json | 92 +++ node_modules/dns-js/test/consumer.test.js | 83 ++ .../dns-js/test/fixtures/chromecast.bin | Bin 0 -> 259 bytes .../dns-js/test/fixtures/chromecast.js | 45 + .../dns-js/test/fixtures/dns-resolvename.bin | Bin 0 -> 38 bytes .../dns-js/test/fixtures/dns-resolvename.js | 26 + .../test/fixtures/dns-reverseresponse.bin | Bin 0 -> 82 bytes .../test/fixtures/dns-reverseresponse.js | 35 + node_modules/dns-js/test/fixtures/dns-soa.bin | Bin 0 -> 82 bytes node_modules/dns-js/test/fixtures/dns-soa.js | 41 + .../dns-js/test/fixtures/exploits/zlip-1.bin | Bin 0 -> 77 bytes .../dns-js/test/fixtures/exploits/zlip-2.bin | Bin 0 -> 77 bytes .../dns-js/test/fixtures/exploits/zlip-3.bin | Bin 0 -> 147 bytes .../test/fixtures/malformed/mdns-unifi1.bin | Bin 0 -> 130 bytes .../dns-js/test/fixtures/mdns-_http.bin | Bin 0 -> 158 bytes .../dns-js/test/fixtures/mdns-_http.js | 41 + .../fixtures/mdns-additional-dottname1.bin | Bin 0 -> 239 bytes .../fixtures/mdns-additional-dottname1.js | 72 ++ .../test/fixtures/mdns-googlecast-phone.bin | Bin 0 -> 304 bytes .../test/fixtures/mdns-googlecast-phone.js | 72 ++ .../test/fixtures/mdns-googlecast-type47.bin | Bin 0 -> 279 bytes .../test/fixtures/mdns-googlecast-type47.js | 85 ++ .../fixtures/mdns-inbound-apple-mobdev.bin | Bin 0 -> 124 bytes .../fixtures/mdns-inbound-apple-mobdev.js | 57 ++ .../test/fixtures/mdns-inbound-appletv1.bin | Bin 0 -> 140 bytes .../test/fixtures/mdns-inbound-appletv1.js | 34 + .../test/fixtures/mdns-inbound-appletv2.bin | Bin 0 -> 90 bytes .../test/fixtures/mdns-inbound-appletv2.js | 30 + .../test/fixtures/mdns-inbound-appletv3.bin | Bin 0 -> 90 bytes .../test/fixtures/mdns-inbound-appletv3.js | 30 + .../mdns-inbound-linux_workstation.bin | Bin 0 -> 104 bytes .../mdns-inbound-linux_workstation.js | 28 + .../test/fixtures/mdns-inbound-pr20-l0112.bin | Bin 0 -> 194 bytes .../test/fixtures/mdns-inbound-pr20-l0112.js | 80 ++ .../test/fixtures/mdns-inbound-pr20-l0300.bin | Bin 0 -> 104 bytes .../test/fixtures/mdns-inbound-pr20-l0300.js | 44 + .../test/fixtures/mdns-inbound-pr20-l0473.bin | Bin 0 -> 332 bytes .../test/fixtures/mdns-inbound-pr20-l0473.js | 117 +++ .../test/fixtures/mdns-inbound-pr20-l0758.bin | Bin 0 -> 198 bytes .../test/fixtures/mdns-inbound-pr20-l0758.js | 86 ++ .../test/fixtures/mdns-inbound-pr20-l1200.bin | Bin 0 -> 396 bytes .../test/fixtures/mdns-inbound-pr20-l1200.js | 172 ++++ .../test/fixtures/mdns-inbound-pr20-l1752.bin | Bin 0 -> 140 bytes .../test/fixtures/mdns-inbound-pr20-l1752.js | 52 ++ .../test/fixtures/mdns-inbound-pr20-l2086.bin | Bin 0 -> 90 bytes .../test/fixtures/mdns-inbound-pr20-l2086.js | 52 ++ .../test/fixtures/mdns-inbound-sample1.bin | Bin 0 -> 190 bytes .../test/fixtures/mdns-inbound-sample1.js | 48 ++ .../test/fixtures/mdns-inbound-sample2.bin | Bin 0 -> 167 bytes .../test/fixtures/mdns-inbound-sample2.js | 43 + .../test/fixtures/mdns-inbound-sample3.bin | Bin 0 -> 101 bytes .../test/fixtures/mdns-inbound-sample3.js | 28 + .../test/fixtures/mdns-inbound-sample4.bin | Bin 0 -> 104 bytes .../test/fixtures/mdns-inbound-sample4.js | 28 + .../test/fixtures/mdns-inbound-sample5.bin | Bin 0 -> 136 bytes .../test/fixtures/mdns-inbound-sample5.js | 38 + .../test/fixtures/mdns-inbound-sample6.bin | Bin 0 -> 200 bytes .../test/fixtures/mdns-inbound-sample6.js | 53 ++ .../test/fixtures/mdns-inbound-sample7.bin | Bin 0 -> 360 bytes .../test/fixtures/mdns-inbound-sample7.js | 83 ++ .../test/fixtures/mdns-inbound-sample8.bin | Bin 0 -> 292 bytes .../test/fixtures/mdns-inbound-sample8.js | 57 ++ .../test/fixtures/mdns-inbound-sample9.bin | Bin 0 -> 259 bytes .../test/fixtures/mdns-inbound-sample9.js | 45 + .../mdns-inbound-tcp_workstation1.bin | Bin 0 -> 136 bytes .../fixtures/mdns-inbound-tcp_workstation1.js | 41 + .../mdns-inbound-tcp_workstation2.bin | Bin 0 -> 166 bytes .../fixtures/mdns-inbound-tcp_workstation2.js | 46 ++ .../test/fixtures/mdns-inbound-type47.bin | Bin 0 -> 146 bytes .../test/fixtures/mdns-inbound-type47.js | 44 + .../fixtures/mdns-outbound-wildcard-query.bin | Bin 0 -> 46 bytes .../fixtures/mdns-outbound-wildcard-query.js | 26 + .../dns-js/test/fixtures/mdns-readynas.bin | Bin 0 -> 360 bytes .../dns-js/test/fixtures/mdns-readynas.js | 83 ++ .../test/fixtures/www.nodejs.org.cname.bin | Bin 0 -> 46 bytes .../test/fixtures/www.nodejs.org.cname.js | 23 + node_modules/dns-js/test/helper.js | 209 +++++ node_modules/dns-js/test/helper.test.js | 69 ++ node_modules/dns-js/test/packet.test.js | 289 +++++++ node_modules/dns-js/test/packets.json | 23 + .../dns-js/test/record-create.test.js | 112 +++ node_modules/dns-js/test/record-parse.test.js | 73 ++ node_modules/dns-js/test/single.test.js | 12 + node_modules/dns-js/test/writer.test.js | 98 +++ node_modules/extsprintf/.gitmodules | 0 node_modules/extsprintf/.npmignore | 2 + node_modules/extsprintf/LICENSE | 19 + node_modules/extsprintf/Makefile | 24 + node_modules/extsprintf/Makefile.targ | 285 +++++++ node_modules/extsprintf/README.md | 46 ++ node_modules/extsprintf/jsl.node.conf | 137 +++ node_modules/extsprintf/lib/extsprintf.js | 183 ++++ node_modules/extsprintf/package.json | 77 ++ node_modules/ipaddr.js/.npmignore | 2 + node_modules/ipaddr.js/Cakefile | 18 + node_modules/ipaddr.js/LICENSE | 19 + node_modules/ipaddr.js/README.md | 149 ++++ node_modules/ipaddr.js/ipaddr.min.js | 1 + node_modules/ipaddr.js/lib/ipaddr.js | 408 +++++++++ node_modules/ipaddr.js/package.json | 94 +++ node_modules/ipaddr.js/src/ipaddr.coffee | 353 ++++++++ .../ipaddr.js/test/ipaddr.test.coffee | 226 +++++ node_modules/ms/LICENSE.md | 21 + node_modules/ms/README.md | 52 ++ node_modules/ms/index.js | 149 ++++ node_modules/ms/package.json | 108 +++ node_modules/native-dns-cache/README.md | 57 ++ node_modules/native-dns-cache/cache.js | 186 +++++ node_modules/native-dns-cache/index.js | 5 + node_modules/native-dns-cache/lookup.js | 110 +++ node_modules/native-dns-cache/memory.js | 93 +++ node_modules/native-dns-cache/package.json | 87 ++ node_modules/native-dns-packet/.npmignore | 3 + node_modules/native-dns-packet/LICENSE | 19 + node_modules/native-dns-packet/README.md | 51 ++ node_modules/native-dns-packet/consts.js | 168 ++++ node_modules/native-dns-packet/index.js | 2 + node_modules/native-dns-packet/package.json | 98 +++ node_modules/native-dns-packet/packet.js | 779 ++++++++++++++++++ .../fixtures/8.8.8.8.in-addr.arpa.ptr.bin | Bin 0 -> 82 bytes .../test/fixtures/8.8.8.8.in-addr.arpa.ptr.js | 23 + .../fixtures/_443._tcp.fedoraproject.org.bin | Bin 0 -> 103 bytes .../fixtures/_443._tcp.fedoraproject.org.js | 28 + .../_xmpp-server._tcp.gmail.com.srv.bin | Bin 0 -> 285 bytes .../_xmpp-server._tcp.gmail.com.srv.js | 58 ++ .../test/fixtures/aol.com.txt.bin | Bin 0 -> 107 bytes .../test/fixtures/aol.com.txt.js | 28 + ...0.0.0.0.0.3.0.c.3.0.0.6.2.ip6.arpa.ptr.bin | Bin 0 -> 126 bytes ....0.0.0.0.0.3.0.c.3.0.0.6.2.ip6.arpa.ptr.js | 26 + .../test/fixtures/irc6.geo.oftc.net.aaaa.bin | Bin 0 -> 119 bytes .../test/fixtures/irc6.geo.oftc.net.aaaa.js | 33 + .../test/fixtures/linode.com.ns.bin | Bin 0 -> 118 bytes .../test/fixtures/linode.com.ns.js | 43 + .../test/fixtures/microsoft.com.mx.bin | Bin 0 -> 85 bytes .../test/fixtures/microsoft.com.mx.js | 25 + .../test/fixtures/www.google.com.a.bin | Bin 0 -> 112 bytes .../test/fixtures/www.google.com.a.js | 44 + .../test/fixtures/www.linode.com.a.bin | Bin 0 -> 80 bytes .../test/fixtures/www.linode.com.a.js | 33 + .../test/fixtures/www.nodejs.org.cname.bin | Bin 0 -> 46 bytes .../test/fixtures/www.nodejs.org.cname.js | 23 + .../test/fixtures/www.yahoo.com.a.bin | Bin 0 -> 158 bytes .../test/fixtures/www.yahoo.com.a.js | 44 + node_modules/native-dns-packet/test/parse.js | 23 + node_modules/native-dns-packet/test/write.js | 27 + node_modules/native-dns/.npmignore | 3 + node_modules/native-dns/.travis.yml | 9 + node_modules/native-dns/AUTHORS | 1 + node_modules/native-dns/ChangeLog | 123 +++ node_modules/native-dns/LICENSE | 19 + node_modules/native-dns/README.md | 271 ++++++ node_modules/native-dns/benchmark.js | 212 +++++ node_modules/native-dns/dns.js | 103 +++ node_modules/native-dns/examples/client.js | 75 ++ node_modules/native-dns/examples/request.js | 121 +++ node_modules/native-dns/examples/server.js | 70 ++ node_modules/native-dns/lib/client.js | 697 ++++++++++++++++ node_modules/native-dns/lib/packet.js | 53 ++ node_modules/native-dns/lib/pending.js | 257 ++++++ node_modules/native-dns/lib/platform.js | 278 +++++++ node_modules/native-dns/lib/server.js | 121 +++ node_modules/native-dns/lib/utils.js | 199 +++++ node_modules/native-dns/package.json | 104 +++ node_modules/native-dns/test-off/compare.js | 113 +++ node_modules/native-dns/test.js | 2 + node_modules/native-dns/test/client.js | 413 ++++++++++ node_modules/native-dns/test/packet.js | 70 ++ node_modules/native-dns/test/request.js | 219 +++++ node_modules/native-dns/test/server.js | 161 ++++ node_modules/qap/.jshintrc | 70 ++ node_modules/qap/.npmignore | 3 + node_modules/qap/.travis.yml | 14 + node_modules/qap/LICENSE | 19 + node_modules/qap/Readme.md | 189 +++++ .../bench/64K-pattern-memory-usage-bench.js | 18 + .../qap/bench/best-magic-data-rate-bench.js | 47 ++ .../qap/bench/big-pattern-data-rate-bench.js | 72 ++ .../bench/big-pattern-memory-usage-bench.js | 18 + node_modules/qap/bench/run.sh | 9 + .../bench/small-pattern-data-rate-bench.js | 70 ++ node_modules/qap/bench/tables.js | 12 + node_modules/qap/index.js | 2 + node_modules/qap/lib/qap.js | 102 +++ node_modules/qap/package.json | 95 +++ node_modules/qap/test/argument-type-test.js | 28 + .../qap/test/big-buffer-start-index-test.js | 48 ++ .../qap/test/big-random-pattern-test.js | 36 + .../test/buffer-lookup-table-chars-test.js | 39 + .../test/push-parsed-results-to-array-test.js | 34 + .../qap/test/repetitive-big-pattern-test.js | 44 + .../qap/test/repetitive-pattern-test.js | 34 + node_modules/qap/test/run.js | 58 ++ node_modules/qap/test/run.sh | 14 + ...ffer-start-index-and-limit-results-test.js | 51 ++ node_modules/qap/test/string-index-test.js | 25 + node_modules/qap/test/utf-string-test.js | 32 + node_modules/verror/.npmignore | 9 + node_modules/verror/CHANGES.md | 20 + node_modules/verror/CONTRIBUTING.md | 19 + node_modules/verror/LICENSE | 19 + node_modules/verror/README.md | 477 +++++++++++ node_modules/verror/issue-39.js | 25 + node_modules/verror/lib/verror.js | 415 ++++++++++ node_modules/verror/package.json | 87 ++ package.json | 15 + 271 files changed, 19626 insertions(+) create mode 100644 README.md create mode 100644 cloud-respond.js create mode 100644 ip.js create mode 100644 listen.js create mode 100644 node_modules/assert-plus/AUTHORS create mode 100644 node_modules/assert-plus/CHANGES.md create mode 100644 node_modules/assert-plus/README.md create mode 100644 node_modules/assert-plus/assert.js create mode 100644 node_modules/assert-plus/package.json create mode 100644 node_modules/binaryheap/.npmignore create mode 100644 node_modules/binaryheap/README.md create mode 100644 node_modules/binaryheap/binaryheap.js create mode 100644 node_modules/binaryheap/example.js create mode 100644 node_modules/binaryheap/package.json create mode 100644 node_modules/binaryheap/test.js create mode 100644 node_modules/buffercursor/README.md create mode 100644 node_modules/buffercursor/buffercursor.js create mode 100644 node_modules/buffercursor/package.json create mode 100644 node_modules/core-util-is/LICENSE create mode 100644 node_modules/core-util-is/README.md create mode 100644 node_modules/core-util-is/float.patch create mode 100644 node_modules/core-util-is/lib/util.js create mode 100644 node_modules/core-util-is/package.json create mode 100644 node_modules/core-util-is/test.js create mode 100644 node_modules/debug/.coveralls.yml create mode 100644 node_modules/debug/.eslintrc create mode 100644 node_modules/debug/.jshintrc create mode 100644 node_modules/debug/.npmignore create mode 100644 node_modules/debug/.travis.yml create mode 100644 node_modules/debug/CHANGELOG.md create mode 100644 node_modules/debug/LICENSE create mode 100644 node_modules/debug/Makefile create mode 100644 node_modules/debug/README.md create mode 100644 node_modules/debug/Readme.md create mode 100644 node_modules/debug/bower.json create mode 100644 node_modules/debug/browser.js create mode 100644 node_modules/debug/component.json create mode 100644 node_modules/debug/debug.js create mode 100644 node_modules/debug/index.js create mode 100644 node_modules/debug/karma.conf.js create mode 100644 node_modules/debug/node.js create mode 100644 node_modules/debug/package.json create mode 100644 node_modules/debug/src/browser.js create mode 100644 node_modules/debug/src/debug.js create mode 100644 node_modules/debug/src/index.js create mode 100644 node_modules/debug/src/node.js create mode 100644 node_modules/dns-js/.eslintignore create mode 100644 node_modules/dns-js/.eslintrc create mode 100644 node_modules/dns-js/.npmignore create mode 100644 node_modules/dns-js/.travis.yml create mode 100644 node_modules/dns-js/LICENSE create mode 100644 node_modules/dns-js/README.md create mode 100644 node_modules/dns-js/doc/edns.md create mode 100644 node_modules/dns-js/doc/rcode.md create mode 100644 node_modules/dns-js/doc/records.md create mode 100644 node_modules/dns-js/examples/resolveaddress.js create mode 100644 node_modules/dns-js/examples/resolvename.js create mode 100644 node_modules/dns-js/index.js create mode 100644 node_modules/dns-js/lib/.dnspacket.js.swp create mode 100644 node_modules/dns-js/lib/bufferconsumer.js create mode 100644 node_modules/dns-js/lib/bufferwriter.js create mode 100644 node_modules/dns-js/lib/dnspacket.js create mode 100644 node_modules/dns-js/lib/dnsrecord.js create mode 100644 node_modules/dns-js/lib/errors.js create mode 100644 node_modules/dns-js/lib/index.js create mode 100644 node_modules/dns-js/package.json create mode 100644 node_modules/dns-js/test/consumer.test.js create mode 100644 node_modules/dns-js/test/fixtures/chromecast.bin create mode 100644 node_modules/dns-js/test/fixtures/chromecast.js create mode 100644 node_modules/dns-js/test/fixtures/dns-resolvename.bin create mode 100644 node_modules/dns-js/test/fixtures/dns-resolvename.js create mode 100644 node_modules/dns-js/test/fixtures/dns-reverseresponse.bin create mode 100644 node_modules/dns-js/test/fixtures/dns-reverseresponse.js create mode 100644 node_modules/dns-js/test/fixtures/dns-soa.bin create mode 100644 node_modules/dns-js/test/fixtures/dns-soa.js create mode 100644 node_modules/dns-js/test/fixtures/exploits/zlip-1.bin create mode 100644 node_modules/dns-js/test/fixtures/exploits/zlip-2.bin create mode 100644 node_modules/dns-js/test/fixtures/exploits/zlip-3.bin create mode 100644 node_modules/dns-js/test/fixtures/malformed/mdns-unifi1.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-_http.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-_http.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-additional-dottname1.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-additional-dottname1.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-googlecast-phone.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-googlecast-phone.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-googlecast-type47.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-googlecast-type47.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv1.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv1.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv2.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv2.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv3.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-appletv3.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-linux_workstation.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-linux_workstation.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0473.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0473.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0758.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0758.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l1200.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l1200.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l1752.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l1752.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l2086.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l2086.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample1.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample1.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample2.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample2.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample3.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample3.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample4.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample4.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample5.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample5.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample6.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample6.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample7.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample7.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample8.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample8.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample9.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-sample9.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-type47.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-inbound-type47.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.js create mode 100644 node_modules/dns-js/test/fixtures/mdns-readynas.bin create mode 100644 node_modules/dns-js/test/fixtures/mdns-readynas.js create mode 100644 node_modules/dns-js/test/fixtures/www.nodejs.org.cname.bin create mode 100644 node_modules/dns-js/test/fixtures/www.nodejs.org.cname.js create mode 100644 node_modules/dns-js/test/helper.js create mode 100644 node_modules/dns-js/test/helper.test.js create mode 100644 node_modules/dns-js/test/packet.test.js create mode 100644 node_modules/dns-js/test/packets.json create mode 100644 node_modules/dns-js/test/record-create.test.js create mode 100644 node_modules/dns-js/test/record-parse.test.js create mode 100644 node_modules/dns-js/test/single.test.js create mode 100644 node_modules/dns-js/test/writer.test.js create mode 100644 node_modules/extsprintf/.gitmodules create mode 100644 node_modules/extsprintf/.npmignore create mode 100644 node_modules/extsprintf/LICENSE create mode 100644 node_modules/extsprintf/Makefile create mode 100644 node_modules/extsprintf/Makefile.targ create mode 100644 node_modules/extsprintf/README.md create mode 100644 node_modules/extsprintf/jsl.node.conf create mode 100644 node_modules/extsprintf/lib/extsprintf.js create mode 100644 node_modules/extsprintf/package.json create mode 100644 node_modules/ipaddr.js/.npmignore create mode 100644 node_modules/ipaddr.js/Cakefile create mode 100644 node_modules/ipaddr.js/LICENSE create mode 100644 node_modules/ipaddr.js/README.md create mode 100644 node_modules/ipaddr.js/ipaddr.min.js create mode 100644 node_modules/ipaddr.js/lib/ipaddr.js create mode 100644 node_modules/ipaddr.js/package.json create mode 100644 node_modules/ipaddr.js/src/ipaddr.coffee create mode 100644 node_modules/ipaddr.js/test/ipaddr.test.coffee create mode 100644 node_modules/ms/LICENSE.md create mode 100644 node_modules/ms/README.md create mode 100644 node_modules/ms/index.js create mode 100644 node_modules/ms/package.json create mode 100644 node_modules/native-dns-cache/README.md create mode 100644 node_modules/native-dns-cache/cache.js create mode 100644 node_modules/native-dns-cache/index.js create mode 100644 node_modules/native-dns-cache/lookup.js create mode 100644 node_modules/native-dns-cache/memory.js create mode 100644 node_modules/native-dns-cache/package.json create mode 100644 node_modules/native-dns-packet/.npmignore create mode 100644 node_modules/native-dns-packet/LICENSE create mode 100644 node_modules/native-dns-packet/README.md create mode 100644 node_modules/native-dns-packet/consts.js create mode 100644 node_modules/native-dns-packet/index.js create mode 100644 node_modules/native-dns-packet/package.json create mode 100644 node_modules/native-dns-packet/packet.js create mode 100644 node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.js create mode 100644 node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.js create mode 100644 node_modules/native-dns-packet/test/fixtures/_xmpp-server._tcp.gmail.com.srv.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/_xmpp-server._tcp.gmail.com.srv.js create mode 100644 node_modules/native-dns-packet/test/fixtures/aol.com.txt.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/aol.com.txt.js create mode 100644 node_modules/native-dns-packet/test/fixtures/b.8.4.0.6.9.e.f.f.f.1.9.c.3.0.f.0.0.0.0.0.0.0.0.3.0.c.3.0.0.6.2.ip6.arpa.ptr.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/b.8.4.0.6.9.e.f.f.f.1.9.c.3.0.f.0.0.0.0.0.0.0.0.3.0.c.3.0.0.6.2.ip6.arpa.ptr.js create mode 100644 node_modules/native-dns-packet/test/fixtures/irc6.geo.oftc.net.aaaa.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/irc6.geo.oftc.net.aaaa.js create mode 100644 node_modules/native-dns-packet/test/fixtures/linode.com.ns.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/linode.com.ns.js create mode 100644 node_modules/native-dns-packet/test/fixtures/microsoft.com.mx.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/microsoft.com.mx.js create mode 100644 node_modules/native-dns-packet/test/fixtures/www.google.com.a.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/www.google.com.a.js create mode 100644 node_modules/native-dns-packet/test/fixtures/www.linode.com.a.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/www.linode.com.a.js create mode 100644 node_modules/native-dns-packet/test/fixtures/www.nodejs.org.cname.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/www.nodejs.org.cname.js create mode 100644 node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.bin create mode 100644 node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.js create mode 100644 node_modules/native-dns-packet/test/parse.js create mode 100644 node_modules/native-dns-packet/test/write.js create mode 100644 node_modules/native-dns/.npmignore create mode 100644 node_modules/native-dns/.travis.yml create mode 100644 node_modules/native-dns/AUTHORS create mode 100644 node_modules/native-dns/ChangeLog create mode 100644 node_modules/native-dns/LICENSE create mode 100644 node_modules/native-dns/README.md create mode 100644 node_modules/native-dns/benchmark.js create mode 100644 node_modules/native-dns/dns.js create mode 100644 node_modules/native-dns/examples/client.js create mode 100644 node_modules/native-dns/examples/request.js create mode 100644 node_modules/native-dns/examples/server.js create mode 100644 node_modules/native-dns/lib/client.js create mode 100644 node_modules/native-dns/lib/packet.js create mode 100644 node_modules/native-dns/lib/pending.js create mode 100644 node_modules/native-dns/lib/platform.js create mode 100644 node_modules/native-dns/lib/server.js create mode 100644 node_modules/native-dns/lib/utils.js create mode 100644 node_modules/native-dns/package.json create mode 100644 node_modules/native-dns/test-off/compare.js create mode 100644 node_modules/native-dns/test.js create mode 100644 node_modules/native-dns/test/client.js create mode 100644 node_modules/native-dns/test/packet.js create mode 100644 node_modules/native-dns/test/request.js create mode 100644 node_modules/native-dns/test/server.js create mode 100644 node_modules/qap/.jshintrc create mode 100644 node_modules/qap/.npmignore create mode 100644 node_modules/qap/.travis.yml create mode 100644 node_modules/qap/LICENSE create mode 100644 node_modules/qap/Readme.md create mode 100644 node_modules/qap/bench/64K-pattern-memory-usage-bench.js create mode 100644 node_modules/qap/bench/best-magic-data-rate-bench.js create mode 100644 node_modules/qap/bench/big-pattern-data-rate-bench.js create mode 100644 node_modules/qap/bench/big-pattern-memory-usage-bench.js create mode 100755 node_modules/qap/bench/run.sh create mode 100644 node_modules/qap/bench/small-pattern-data-rate-bench.js create mode 100644 node_modules/qap/bench/tables.js create mode 100644 node_modules/qap/index.js create mode 100644 node_modules/qap/lib/qap.js create mode 100644 node_modules/qap/package.json create mode 100644 node_modules/qap/test/argument-type-test.js create mode 100644 node_modules/qap/test/big-buffer-start-index-test.js create mode 100644 node_modules/qap/test/big-random-pattern-test.js create mode 100644 node_modules/qap/test/buffer-lookup-table-chars-test.js create mode 100644 node_modules/qap/test/push-parsed-results-to-array-test.js create mode 100644 node_modules/qap/test/repetitive-big-pattern-test.js create mode 100644 node_modules/qap/test/repetitive-pattern-test.js create mode 100644 node_modules/qap/test/run.js create mode 100755 node_modules/qap/test/run.sh create mode 100644 node_modules/qap/test/small-buffer-start-index-and-limit-results-test.js create mode 100644 node_modules/qap/test/string-index-test.js create mode 100644 node_modules/qap/test/utf-string-test.js create mode 100644 node_modules/verror/.npmignore create mode 100644 node_modules/verror/CHANGES.md create mode 100644 node_modules/verror/CONTRIBUTING.md create mode 100644 node_modules/verror/LICENSE create mode 100644 node_modules/verror/README.md create mode 100644 node_modules/verror/issue-39.js create mode 100644 node_modules/verror/lib/verror.js create mode 100644 node_modules/verror/package.json create mode 100644 package.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..70b4136 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +mDNS Documentation + +What is mDNS? + +mDNS stands for Multicast Domain Name System. It's function is to resolve host names to IP addresses within small networkds that do not include a local name server. It is a zero-configuration service, using essentially the same programming interfaces, packet formats and operating semantics as the unicast Domain Name System (DNS). Although mDNS is designed to be stand-alone capable, it can work in concert with unicast DNS servers. + +Full documentation of the protocol is located at: https://tools.ietf.org/html/rfc6762 + +Other helpful topics and documents: + +- Zero Configuration Networking: https://tools.ietf.org/html/rfc6762#ref-Zeroconf +- Automatic link-local addressing: https://tools.ietf.org/html/rfc3927 + + https://tools.ietf.org/html/rfc4862 + + +DNS-format messages contain a header, a Question Section, then Answer, Authority, and additional Record Sections. The Answer, Authority, and Additional Record Sections all hold resource records. + + +mDNS is a datagram protocal that uses broadcast mode and membership groups. + + + +What does mDNS in the Daplie System? + +We are sending messages back and forth on a network that searches for any other mDNS compatible devices and asks that device if it is connected to a router or WiFi with a Daplie-compatible Cloud device. + +If it is a Daplie-compatible Cloud device, then it will reply to the sender with some sort of confirmation. + + + +Terms: + +TTL - IP Time to Live - located in IP header of the DNS packet and is used effectively as a hop-count limit for the packet, to guard against routing loops + + +"shared" resource record set is where several Multicast DNS responders may have records with the same name, rrtype, and rrclass, and several responders may respond to a particular query + +"unique" resource record set is one where all the records with that name, rrtype, and rrclass are conceptually under the control or ownership of a single responder, and it is expected that at most one responder should respond to a query for that name, rrtype, and rrclass. Before claiming ownership of a unique resource record set, a responder MUST probe to verify that no other responder already claims ownership. (For fault-tolerance and other reasons, sometimes it is permissible to have more than one responder answering for a particular "unique" resource record set, but such cooperating resoinders MUST give answers containing identical rdata for these records. If they do not give answers containing identical rdata, then the probing stop will reject the data as being inconsistent with what is already being advertised on the network for these names.) + + +Multicast DNS Names + +A host that belongs to an organization or individual who has control over some potion of the DNS namespace can be assigned a globally unique name within that portion of th DNS namespace, such as, "chechire.example.com". For those of us who have this luxury, this works very well. However, the mojority of home computer users do not have easy access to any portion of the global DNS namespace within which they have the authoriry to create names. This leaves the majority of home computers effectively anonymous for practical purposes + + + + + + + + + diff --git a/cloud-respond.js b/cloud-respond.js new file mode 100644 index 0000000..97d440d --- /dev/null +++ b/cloud-respond.js @@ -0,0 +1,105 @@ +'use strict'; + +module.exports.respond = function (socket, packets, rinfo) { + var dns = require('dns-js'); + var os = require('os'); + var queryname = '_cloud._tcp.local'; + + console.log(packets); + + packets.forEach(function (packet) { + packet.question.forEach(function (q) { + if (queryname !== q.name) { + return; + } + + console.log('question', q.name, q.typeName, q.className, q.flag, q); + var rpacket = new dns.DNSPacket(); + var ifaces = os.networkInterfaces(); + //var llRe = /^(fe80|169)/i; // link-local + + Object.keys(ifaces).forEach(function (iname) { + var iface = ifaces[iname]; + + iface = iface.filter(function (pface) { + // nix loopback, internal and ipv6 link-local (non-routable) and ipv4 link-local + return !pface.internal;// && !(pface.scopeid > 1) && !llRe.test(pface.address); + }); + + iface.forEach(function (pface) { + rpacket.additional.push({ + name: q.name + , type: ('IPv4' === pface.family ? dns.DNSRecord.Type.A : dns.DNSRecord.Type.AAAA) + , ttl: 10 + , class: dns.DNSRecord.Class.IN + , address: pface.address // '_workstation._tcp.local' + }); + }); + }); + + var myRndId = 'be1af7a'; + rpacket.answer.push({ + name: q.name + , type: dns.DNSRecord.Type.PTR + , ttl: 10 + , class: dns.DNSRecord.Class.IN + , data: myRndId + '.' + queryname + }); + rpacket.question.push(new dns.DNSRecord( + queryname // Name + , dns.DNSRecord.Type.PTR // Type + , dns.DNSRecord.Class.IN // Class + //, null // TTL + )); + rpacket.additional.push({ + name: myRndId + '.' + queryname + , type: dns.DNSRecord.Type.SRV + , ttl: 10 + , class: dns.DNSRecord.Class.IN + , priority: 0 + , weight: 0 + , port: 443 + , target: myRndId + ".local" + }); + rpacket.additional.push({ + name: myRndId + '.' + '_device-info._tcp.local' + , type: dns.DNSRecord.Type.TXT + , ttl: 10 + , class: dns.DNSRecord.Class.IN + , data: ["model=CloudHome1,1", "dappsvers=1"] + }); + rpacket.header.id = packet.header.id; + rpacket.header.aa = 1; + rpacket.header.qr = 1; + rpacket.header.rd = 0; + + console.log(''); + console.log('START JSON PACKET'); + console.log(rpacket); + var buf = dns.DNSPacket.toBuffer(rpacket); + console.log(buf.toString('hex')); + console.log('END JSON PACKET'); + console.log(''); + + console.log(''); + console.log('START DNS PACKET'); + var pkt = dns.DNSPacket.parse(buf); + console.log(pkt); + console.log('END DNS PACKET'); + console.log(''); + socket.send(buf, rinfo.port, rinfo.address); + }); + /* + */ + packet.answer.forEach(function (a) { + console.log('answer', a.name, a.typeName, a.className, a.flag, a); + }); + packet.authority.forEach(function (a) { + console.log('authority', a.name, a.typeName, a.className, a.flag, a); + }); + packet.additional.forEach(function (a) { + console.log('additional', a.name, a.typeName, a.className, a.flag, a); + }); + }); + console.log('\n'); +}; diff --git a/howto.md b/howto.md index 1766704..733cfa2 100644 --- a/howto.md +++ b/howto.md @@ -6,5 +6,9 @@ header npm init + +how to duplicate DNS crash: + + How to print out hex and binary values of the message? diff --git a/ip.js b/ip.js new file mode 100644 index 0000000..1c5d6b0 --- /dev/null +++ b/ip.js @@ -0,0 +1,19 @@ +'use strict'; + +var os = require('os'); + + var ifaces = os.networkInterfaces(); + var llRe = /^(fe80|169)/i; // link-local + + Object.keys(ifaces).forEach(function (iname) { + var iface = ifaces[iname]; + + iface = iface.filter(function (pface) { + // nix loopback, internal and ipv6 link-local (non-routable) and ipv4 link-local + return !pface.internal && !(pface.scopeid > 1) && !llRe.test(pface.address); + }); + + iface.forEach(function (pface) { + console.log(pface); + }); + }); diff --git a/listen.js b/listen.js new file mode 100644 index 0000000..72123c4 --- /dev/null +++ b/listen.js @@ -0,0 +1,44 @@ +'use strict'; + +var dgram = require('dgram'); +var socket = dgram.createSocket({ + type: 'udp4' +, reuseAddr: true +}); +var dns = require('dns-js'); +//var DNSPacket = dns.DNSPacket; + +var broadcast = '224.0.0.251'; // mdns +var port = 5353; // mdns + +socket.on('message', function (message, rinfo) { + console.log('Received %d bytes from %s:%d\n', + message.length, rinfo.address, rinfo.port); + //console.log(msg.toString('utf8')); + + console.log(message.toString('hex')); + var packets; + + try { + packets = dns.DNSPacket.parse(message); + } + catch (er) { + //partial, skip it + console.error(er); + return; + } + + if (!Array.isArray(packets)) { packets = [packets]; } + + require('./cloud-respond.js').respond(socket, packets, rinfo); +}); + +socket.bind(port, function () { + console.log('bound on', port); + console.log('bound on', this.address()); + + socket.setBroadcast(true); + socket.addMembership(broadcast); + + // buf.forEach parseInt(byte.toString('hex'), 16).toString(2); +}); diff --git a/node_modules/assert-plus/AUTHORS b/node_modules/assert-plus/AUTHORS new file mode 100644 index 0000000..1923524 --- /dev/null +++ b/node_modules/assert-plus/AUTHORS @@ -0,0 +1,6 @@ +Dave Eddy +Fred Kuo +Lars-Magnus Skog +Mark Cavage +Patrick Mooney +Rob Gulewich diff --git a/node_modules/assert-plus/CHANGES.md b/node_modules/assert-plus/CHANGES.md new file mode 100644 index 0000000..57d92bf --- /dev/null +++ b/node_modules/assert-plus/CHANGES.md @@ -0,0 +1,14 @@ +# assert-plus Changelog + +## 1.0.0 + +- *BREAKING* assert.number (and derivatives) now accept Infinity as valid input +- Add assert.finite check. Previous assert.number callers should use this if + they expect Infinity inputs to throw. + +## 0.2.0 + +- Fix `assert.object(null)` so it throws +- Fix optional/arrayOf exports for non-type-of asserts +- Add optiona/arrayOf exports for Stream/Date/Regex/uuid +- Add basic unit test coverage diff --git a/node_modules/assert-plus/README.md b/node_modules/assert-plus/README.md new file mode 100644 index 0000000..ec200d1 --- /dev/null +++ b/node_modules/assert-plus/README.md @@ -0,0 +1,162 @@ +# assert-plus + +This library is a super small wrapper over node's assert module that has two +things: (1) the ability to disable assertions with the environment variable +NODE\_NDEBUG, and (2) some API wrappers for argument testing. Like +`assert.string(myArg, 'myArg')`. As a simple example, most of my code looks +like this: + +```javascript + var assert = require('assert-plus'); + + function fooAccount(options, callback) { + assert.object(options, 'options'); + assert.number(options.id, 'options.id'); + assert.bool(options.isManager, 'options.isManager'); + assert.string(options.name, 'options.name'); + assert.arrayOfString(options.email, 'options.email'); + assert.func(callback, 'callback'); + + // Do stuff + callback(null, {}); + } +``` + +# API + +All methods that *aren't* part of node's core assert API are simply assumed to +take an argument, and then a string 'name' that's not a message; `AssertionError` +will be thrown if the assertion fails with a message like: + + AssertionError: foo (string) is required + at test (/home/mark/work/foo/foo.js:3:9) + at Object. (/home/mark/work/foo/foo.js:15:1) + at Module._compile (module.js:446:26) + at Object..js (module.js:464:10) + at Module.load (module.js:353:31) + at Function._load (module.js:311:12) + at Array.0 (module.js:484:10) + at EventEmitter._tickCallback (node.js:190:38) + +from: + +```javascript + function test(foo) { + assert.string(foo, 'foo'); + } +``` + +There you go. You can check that arrays are of a homogeneous type with `Arrayof$Type`: + +```javascript + function test(foo) { + assert.arrayOfString(foo, 'foo'); + } +``` + +You can assert IFF an argument is not `undefined` (i.e., an optional arg): + +```javascript + assert.optionalString(foo, 'foo'); +``` + +Lastly, you can opt-out of assertion checking altogether by setting the +environment variable `NODE_NDEBUG=1`. This is pseudo-useful if you have +lots of assertions, and don't want to pay `typeof ()` taxes to v8 in +production. Be advised: The standard functions re-exported from `assert` are +also disabled in assert-plus if NDEBUG is specified. Using them directly from +the `assert` module avoids this behavior. + +The complete list of APIs is: + +* assert.array +* assert.bool +* assert.buffer +* assert.func +* assert.number +* assert.finite +* assert.object +* assert.string +* assert.stream +* assert.date +* assert.regexp +* assert.uuid +* assert.arrayOfArray +* assert.arrayOfBool +* assert.arrayOfBuffer +* assert.arrayOfFunc +* assert.arrayOfNumber +* assert.arrayOfFinite +* assert.arrayOfObject +* assert.arrayOfString +* assert.arrayOfStream +* assert.arrayOfDate +* assert.arrayOfRegexp +* assert.arrayOfUuid +* assert.optionalArray +* assert.optionalBool +* assert.optionalBuffer +* assert.optionalFunc +* assert.optionalNumber +* assert.optionalFinite +* assert.optionalObject +* assert.optionalString +* assert.optionalStream +* assert.optionalDate +* assert.optionalRegexp +* assert.optionalUuid +* assert.optionalArrayOfArray +* assert.optionalArrayOfBool +* assert.optionalArrayOfBuffer +* assert.optionalArrayOfFunc +* assert.optionalArrayOfNumber +* assert.optionalArrayOfFinite +* assert.optionalArrayOfObject +* assert.optionalArrayOfString +* assert.optionalArrayOfStream +* assert.optionalArrayOfDate +* assert.optionalArrayOfRegexp +* assert.optionalArrayOfUuid +* assert.AssertionError +* assert.fail +* assert.ok +* assert.equal +* assert.notEqual +* assert.deepEqual +* assert.notDeepEqual +* assert.strictEqual +* assert.notStrictEqual +* assert.throws +* assert.doesNotThrow +* assert.ifError + +# Installation + + npm install assert-plus + +## License + +The MIT License (MIT) +Copyright (c) 2012 Mark Cavage + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +## Bugs + +See . diff --git a/node_modules/assert-plus/assert.js b/node_modules/assert-plus/assert.js new file mode 100644 index 0000000..26f944e --- /dev/null +++ b/node_modules/assert-plus/assert.js @@ -0,0 +1,211 @@ +// Copyright (c) 2012, Mark Cavage. All rights reserved. +// Copyright 2015 Joyent, Inc. + +var assert = require('assert'); +var Stream = require('stream').Stream; +var util = require('util'); + + +///--- Globals + +/* JSSTYLED */ +var UUID_REGEXP = /^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/; + + +///--- Internal + +function _capitalize(str) { + return (str.charAt(0).toUpperCase() + str.slice(1)); +} + +function _toss(name, expected, oper, arg, actual) { + throw new assert.AssertionError({ + message: util.format('%s (%s) is required', name, expected), + actual: (actual === undefined) ? typeof (arg) : actual(arg), + expected: expected, + operator: oper || '===', + stackStartFunction: _toss.caller + }); +} + +function _getClass(arg) { + return (Object.prototype.toString.call(arg).slice(8, -1)); +} + +function noop() { + // Why even bother with asserts? +} + + +///--- Exports + +var types = { + bool: { + check: function (arg) { return typeof (arg) === 'boolean'; } + }, + func: { + check: function (arg) { return typeof (arg) === 'function'; } + }, + string: { + check: function (arg) { return typeof (arg) === 'string'; } + }, + object: { + check: function (arg) { + return typeof (arg) === 'object' && arg !== null; + } + }, + number: { + check: function (arg) { + return typeof (arg) === 'number' && !isNaN(arg); + } + }, + finite: { + check: function (arg) { + return typeof (arg) === 'number' && !isNaN(arg) && isFinite(arg); + } + }, + buffer: { + check: function (arg) { return Buffer.isBuffer(arg); }, + operator: 'Buffer.isBuffer' + }, + array: { + check: function (arg) { return Array.isArray(arg); }, + operator: 'Array.isArray' + }, + stream: { + check: function (arg) { return arg instanceof Stream; }, + operator: 'instanceof', + actual: _getClass + }, + date: { + check: function (arg) { return arg instanceof Date; }, + operator: 'instanceof', + actual: _getClass + }, + regexp: { + check: function (arg) { return arg instanceof RegExp; }, + operator: 'instanceof', + actual: _getClass + }, + uuid: { + check: function (arg) { + return typeof (arg) === 'string' && UUID_REGEXP.test(arg); + }, + operator: 'isUUID' + } +}; + +function _setExports(ndebug) { + var keys = Object.keys(types); + var out; + + /* re-export standard assert */ + if (process.env.NODE_NDEBUG) { + out = noop; + } else { + out = function (arg, msg) { + if (!arg) { + _toss(msg, 'true', arg); + } + }; + } + + /* standard checks */ + keys.forEach(function (k) { + if (ndebug) { + out[k] = noop; + return; + } + var type = types[k]; + out[k] = function (arg, msg) { + if (!type.check(arg)) { + _toss(msg, k, type.operator, arg, type.actual); + } + }; + }); + + /* optional checks */ + keys.forEach(function (k) { + var name = 'optional' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + out[name] = function (arg, msg) { + if (arg === undefined || arg === null) { + return; + } + if (!type.check(arg)) { + _toss(msg, k, type.operator, arg, type.actual); + } + }; + }); + + /* arrayOf checks */ + keys.forEach(function (k) { + var name = 'arrayOf' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + var expected = '[' + k + ']'; + out[name] = function (arg, msg) { + if (!Array.isArray(arg)) { + _toss(msg, expected, type.operator, arg, type.actual); + } + var i; + for (i = 0; i < arg.length; i++) { + if (!type.check(arg[i])) { + _toss(msg, expected, type.operator, arg, type.actual); + } + } + }; + }); + + /* optionalArrayOf checks */ + keys.forEach(function (k) { + var name = 'optionalArrayOf' + _capitalize(k); + if (ndebug) { + out[name] = noop; + return; + } + var type = types[k]; + var expected = '[' + k + ']'; + out[name] = function (arg, msg) { + if (arg === undefined || arg === null) { + return; + } + if (!Array.isArray(arg)) { + _toss(msg, expected, type.operator, arg, type.actual); + } + var i; + for (i = 0; i < arg.length; i++) { + if (!type.check(arg[i])) { + _toss(msg, expected, type.operator, arg, type.actual); + } + } + }; + }); + + /* re-export built-in assertions */ + Object.keys(assert).forEach(function (k) { + if (k === 'AssertionError') { + out[k] = assert[k]; + return; + } + if (ndebug) { + out[k] = noop; + return; + } + out[k] = assert[k]; + }); + + /* export ourselves (for unit tests _only_) */ + out._setExports = _setExports; + + return out; +} + +module.exports = _setExports(process.env.NODE_NDEBUG); diff --git a/node_modules/assert-plus/package.json b/node_modules/assert-plus/package.json new file mode 100644 index 0000000..f1086c8 --- /dev/null +++ b/node_modules/assert-plus/package.json @@ -0,0 +1,115 @@ +{ + "_args": [ + [ + { + "raw": "assert-plus@^1.0.0", + "scope": null, + "escapedName": "assert-plus", + "name": "assert-plus", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "/srv/demos/node_modules/verror" + ] + ], + "_from": "assert-plus@>=1.0.0 <2.0.0", + "_id": "assert-plus@1.0.0", + "_inCache": true, + "_location": "/assert-plus", + "_nodeVersion": "0.10.40", + "_npmUser": { + "name": "pfmooney", + "email": "patrick.f.mooney@gmail.com" + }, + "_npmVersion": "3.3.9", + "_phantomChildren": {}, + "_requested": { + "raw": "assert-plus@^1.0.0", + "scope": null, + "escapedName": "assert-plus", + "name": "assert-plus", + "rawSpec": "^1.0.0", + "spec": ">=1.0.0 <2.0.0", + "type": "range" + }, + "_requiredBy": [ + "/verror" + ], + "_resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "_shasum": "f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525", + "_shrinkwrap": null, + "_spec": "assert-plus@^1.0.0", + "_where": "/srv/demos/node_modules/verror", + "author": { + "name": "Mark Cavage", + "email": "mcavage@gmail.com" + }, + "bugs": { + "url": "https://github.com/mcavage/node-assert-plus/issues" + }, + "contributors": [ + { + "name": "Dave Eddy", + "email": "dave@daveeddy.com" + }, + { + "name": "Fred Kuo", + "email": "fred.kuo@joyent.com" + }, + { + "name": "Lars-Magnus Skog", + "email": "ralphtheninja@riseup.net" + }, + { + "name": "Mark Cavage", + "email": "mcavage@gmail.com" + }, + { + "name": "Patrick Mooney", + "email": "pmooney@pfmooney.com" + }, + { + "name": "Rob Gulewich", + "email": "robert.gulewich@joyent.com" + } + ], + "dependencies": {}, + "description": "Extra assertions on top of node's assert module", + "devDependencies": { + "faucet": "0.0.1", + "tape": "4.2.2" + }, + "directories": {}, + "dist": { + "shasum": "f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525", + "tarball": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz" + }, + "engines": { + "node": ">=0.8" + }, + "homepage": "https://github.com/mcavage/node-assert-plus#readme", + "license": "MIT", + "main": "./assert.js", + "maintainers": [ + { + "name": "mcavage", + "email": "mcavage@gmail.com" + }, + { + "name": "pfmooney", + "email": "patrick.f.mooney@gmail.com" + } + ], + "name": "assert-plus", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/mcavage/node-assert-plus.git" + }, + "scripts": { + "test": "tape tests/*.js | ./node_modules/.bin/faucet" + }, + "version": "1.0.0" +} diff --git a/node_modules/binaryheap/.npmignore b/node_modules/binaryheap/.npmignore new file mode 100644 index 0000000..07fabfd --- /dev/null +++ b/node_modules/binaryheap/.npmignore @@ -0,0 +1,3 @@ +*.dot +*.gif +node_modules diff --git a/node_modules/binaryheap/README.md b/node_modules/binaryheap/README.md new file mode 100644 index 0000000..55dcad9 --- /dev/null +++ b/node_modules/binaryheap/README.md @@ -0,0 +1,43 @@ +BinaryHeap +========== + +Basic binary heap tree using linked lists + +Usage +----- + +```javascript +var BinaryHeap = require('binaryheap'); +var heap = new BinaryHeap(); + +var a = [6, 5, 3, 1, 8, 7, 2, 4]; + +a.forEach(function (k) { + heap.insert({ value: k }, k); +}); + +heap.print(); + +while (heap.length) { + console.log('popping', heap.pop().value); +} +``` + +By default it stores as a max-heap, if you pass truthy to the constructor though +it will behave as a min-heap. + +Methods +------- + + * `insert(obj, key)` -- obj can be any new or existing object, and key is any +value that behaves sanely with `>` or `<` + * `pop()` -- removes and returns the maximum or minimum object from the root +of the heap + * `remove(obj)` -- removes a previously inserted object from the heap + * `print()` -- mostly for debugging purposes prints a graphviz dot style +digraph to confirm ordering + +Members +------- + + * `length` -- number of objects currently in the heap diff --git a/node_modules/binaryheap/binaryheap.js b/node_modules/binaryheap/binaryheap.js new file mode 100644 index 0000000..ba38569 --- /dev/null +++ b/node_modules/binaryheap/binaryheap.js @@ -0,0 +1,313 @@ +// Copyright 2012 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +'use strict'; + +var assert = require('assert'); + +var Heap = function(min) { + this.length = 0; + this.root = undefined; + if (min) { + this._comparator = this._smallest; + } else { + this._comparator = this._largest; + } +}; + +Heap.init = function(obj, key) { + obj._parent = null; + obj._left = null; + obj._right = null; + obj._key = key; + return obj; +}; + +Heap.prototype.count = function (node) { + if (!node) return 0; + + var c = 1; + + c += this.count(node._left); + c += this.count(node._right); + + return c; +}; + +Heap.prototype.insert = function(obj, key) { + var insert, node; + + this.length += 1; + + node = Heap.init(obj, key); + + if (!this.root) { + this.root = node; + } else { + insert = this._last(); + + node._parent = insert; + + if (!insert._left) + insert._left = node; + else + insert._right = node; + + this._up(node); + } + + this._head(); + + return node; +}; + +Heap.prototype.pop = function() { + var ret, last; + + if (!this.root) + return null; + + return this.remove(this.root); +}; + +Heap.prototype.remove = function(node) { + var ret, last; + + ret = node; + last = this._last(); + + if (last._right) + last = last._right; + else + last = last._left; + + this.length -= 1; + + if (!last) { + if (ret == this.root) + this.root = null; + return ret; + } + + if (ret == last) { + if (ret._parent._left == node) + ret._parent._left = null; + else + ret._parent._right = null; + last = ret._parent; + ret._parent = null; + } else if (!ret._left && !ret._right) { + // we're trying to remove an element without any children and its not the last + // move the last under its parent and heap-up + if (last._parent._left == last) last._parent._left = null; + else last._parent._right = null; + + if (ret._parent._left == ret) ret._parent._left = last; + else ret._parent._right = last; + + last._parent = ret._parent; + + ret._parent = null; + + // TODO in this case we shouldn't later also do a down, but it should only visit once + this._up(last); + } else { + this._delete_swap(ret, last); + } + + if (ret == this.root) + this.root = last; + + this._down(last); + this._head(); + + return ret; +}; + +// TODO this probably isn't the most efficient way to ensure that we're always +// at the root of the tree, but it works for now +Heap.prototype._head = function() { + if (!this.root) + return; + + var tmp = this.root; + while (tmp._parent) { + tmp = tmp._parent; + } + + this.root = tmp; +}; + +// TODO is there a more efficient way to store this instead of an array? +Heap.prototype._last = function() { + var path, pos, mod, insert; + + pos = this.length; + path = []; + while (pos > 1) { + mod = pos % 2; + pos = Math.floor(pos / 2); + path.push(mod); + } + + insert = this.root; + + while (path.length > 1) { + pos = path.pop(); + if (pos === 0) + insert = insert._left; + else + insert = insert._right; + } + + return insert; +}; + +Heap.prototype._swap = function(a, b) { + var cleft, cright, tparent; + + cleft = b._left; + cright = b._right; + + if (a._parent) { + if (a._parent._left == a) a._parent._left = b; + else a._parent._right = b; + } + + b._parent = a._parent; + a._parent = b; + + // This assumes direct descendents + if (a._left == b) { + b._left = a; + b._right = a._right; + if (b._right) b._right._parent = b; + } else { + b._right = a; + b._left = a._left; + if (b._left) b._left._parent = b; + } + + a._left = cleft; + a._right = cright; + + if (a._left) a._left._parent = a; + if (a._right) a._right._parent = a; + + assert.notEqual(a._parent, a, "A shouldn't refer to itself"); + assert.notEqual(b._parent, b, "B shouldn't refer to itself"); +}; + +Heap.prototype._delete_swap = function(a, b) { + if (a._left != b) b._left = a._left; + if (a._right != b) b._right = a._right; + + if (b._parent._left == b) b._parent._left = null; + else b._parent._right = null; + + if (a._parent) { + if (a._parent._left == a) a._parent._left = b; + else a._parent._right = b; + } + + b._parent = a._parent; + + if (b._left) b._left._parent = b; + if (b._right) b._right._parent = b; + + a._parent = null; + a._left = null; + a._right = null; +}; + +Heap.prototype._smallest = function(heap) { + var small = heap; + + if (heap._left && heap._key > heap._left._key) { + small = heap._left; + } + + if (heap._right && small._key > heap._right._key) { + small = heap._right; + } + + return small; +}; + +Heap.prototype._largest = function(heap) { + var large = heap; + + if (heap._left && heap._key < heap._left._key) { + large = heap._left; + } + + if (heap._right && large._key < heap._right._key) { + large = heap._right; + } + + return large; +}; + +Heap.prototype._up = function(node) { + if (!node || !node._parent) + return; + + var next = this._comparator(node._parent); + + if (next != node._parent) { + this._swap(node._parent, node); + this._up(node); + } +}; + +Heap.prototype._down = function(node) { + if (!node) + return; + + var next = this._comparator(node); + if (next != node) { + this._swap(node, next); + this._down(node); + } +}; + +var util = require('util'); + +Heap.prototype.print = function(stream) { + stream.write('digraph {\n'); + Heap._print(this.root, stream); + stream.write('}\n'); +}; + +Heap._print = function(heap, stream) { + if (!heap) return; + + if (heap._left) { + stream.write(util.format('' + heap._key, '->', heap._left._key, '\n')); + Heap._print(heap._left, stream); + } + + if (heap._right) { + stream.write(util.format('' + heap._key, '->', heap._right._key, '\n')); + Heap._print(heap._right, stream); + } +}; + +module.exports = Heap; diff --git a/node_modules/binaryheap/example.js b/node_modules/binaryheap/example.js new file mode 100644 index 0000000..2c5c598 --- /dev/null +++ b/node_modules/binaryheap/example.js @@ -0,0 +1,15 @@ +var BinaryHeap = require('./binaryheap'); +var heap = new BinaryHeap(); + +var a = [6, 5, 3, 1, 8, 7, 2, 4]; + +a.forEach(function (k) { + heap.insert({ value: k }, k); +}); + +heap.print(process.stdout); + +while (heap.length) { + console.log('popping', heap.pop().value); + heap.print(process.stdout); +} diff --git a/node_modules/binaryheap/package.json b/node_modules/binaryheap/package.json new file mode 100644 index 0000000..0dceb9c --- /dev/null +++ b/node_modules/binaryheap/package.json @@ -0,0 +1,91 @@ +{ + "_args": [ + [ + { + "raw": "binaryheap@>= 0.0.3", + "scope": null, + "escapedName": "binaryheap", + "name": "binaryheap", + "rawSpec": ">= 0.0.3", + "spec": ">=0.0.3", + "type": "range" + }, + "/srv/demos/node_modules/native-dns-cache" + ] + ], + "_from": "binaryheap@>=0.0.3", + "_id": "binaryheap@0.0.3", + "_inCache": true, + "_location": "/binaryheap", + "_npmUser": { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + }, + "_npmVersion": "1.2.14", + "_phantomChildren": {}, + "_requested": { + "raw": "binaryheap@>= 0.0.3", + "scope": null, + "escapedName": "binaryheap", + "name": "binaryheap", + "rawSpec": ">= 0.0.3", + "spec": ">=0.0.3", + "type": "range" + }, + "_requiredBy": [ + "/native-dns-cache" + ], + "_resolved": "https://registry.npmjs.org/binaryheap/-/binaryheap-0.0.3.tgz", + "_shasum": "0d6136c84e9f1a5a90c0b97178c3e00df59820d6", + "_shrinkwrap": null, + "_spec": "binaryheap@>= 0.0.3", + "_where": "/srv/demos/node_modules/native-dns-cache", + "author": { + "name": "Timothy J Fontaine", + "email": "tjfontaine@gmail.com", + "url": "http://atxconsulting.com" + }, + "bugs": { + "url": "http://github.com/tjfontaine/node-binaryheap/issues" + }, + "dependencies": {}, + "description": "A simple binary heap", + "devDependencies": { + "tap": ">= 0.4.0" + }, + "directories": {}, + "dist": { + "shasum": "0d6136c84e9f1a5a90c0b97178c3e00df59820d6", + "tarball": "https://registry.npmjs.org/binaryheap/-/binaryheap-0.0.3.tgz" + }, + "engines": { + "node": ">= 0.6.0" + }, + "homepage": "http://github.com/tjfontaine/node-binaryheap", + "keywords": [ + "balanced", + "binary", + "heap", + "minheap", + "maxheap" + ], + "main": "binaryheap.js", + "maintainers": [ + { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + } + ], + "name": "binaryheap", + "optionalDependencies": {}, + "readme": "BinaryHeap\n==========\n\nBasic binary heap tree using linked lists\n\nUsage\n-----\n\n```javascript\nvar BinaryHeap = require('binaryheap');\nvar heap = new BinaryHeap();\n\nvar a = [6, 5, 3, 1, 8, 7, 2, 4];\n\na.forEach(function (k) {\n heap.insert({ value: k }, k);\n});\n\nheap.print();\n\nwhile (heap.length) {\n console.log('popping', heap.pop().value);\n}\n```\n\nBy default it stores as a max-heap, if you pass truthy to the constructor though\nit will behave as a min-heap.\n\nMethods\n-------\n\n * `insert(obj, key)` -- obj can be any new or existing object, and key is any\nvalue that behaves sanely with `>` or `<`\n * `pop()` -- removes and returns the maximum or minimum object from the root\nof the heap\n * `remove(obj)` -- removes a previously inserted object from the heap\n * `print()` -- mostly for debugging purposes prints a graphviz dot style\ndigraph to confirm ordering\n\nMembers\n-------\n\n * `length` -- number of objects currently in the heap\n", + "readmeFilename": "README.md", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/tjfontaine/node-binaryheap.git" + }, + "scripts": { + "test": "node test" + }, + "version": "0.0.3" +} diff --git a/node_modules/binaryheap/test.js b/node_modules/binaryheap/test.js new file mode 100644 index 0000000..ada3ca6 --- /dev/null +++ b/node_modules/binaryheap/test.js @@ -0,0 +1,96 @@ +var test = require("tap").test; +var Heap = require('./binaryheap'); + +test("check order", function (t) { + var input = [5, 8, 3, 2, 7, 4, 14]; + var output = [2, 3, 4, 5, 7, 8, 14]; + + var heap = new Heap(true); + input.forEach(function (i) { + heap.insert({key: i}, i); + }); + + console.log('foo'); + + t.equal(heap.length, input.length, "heap size matches input"); + + var o = []; + + for (var i = 0; i < input.length; i++) + o.push(heap.pop().key) + + t.equal(o.length, output.length, "heap sorted length matches"); + t.equivalent(o, output, "heap sorted matches expected output"); + + heap = new Heap(false); + output.reverse(); + + input.forEach(function (i) { + heap.insert({key: i}, i); + }); + + t.equal(heap.length, input.length, "heap size matches input"); + + var o = []; + + for (var i = 0; i < input.length; i++) + o.push(heap.pop().key) + + t.equal(o.length, output.length, "heap sorted length matches"); + t.equivalent(o, output, "heap sorted matches expected output"); + + t.end(); +}); + +var tree_count = 9; + +function getDot() { + var tree = require('fs').createWriteStream('tree.'+ ++tree_count + '.dot'); + return tree; +}; + +function printHeap(heap) { + //rm -f *.dot *.gif && node test && for i in $(ls tree.*.dot); do dot -Tgif $i -o $(basename $i .dot).gif; done && gifsicle --delay=100 --loop *.gif > anim.gif + //var ds = getDot(); + //heap.print(ds); + //ds.end(); +}; + + +test("remove arbitrary elements", function (t) { + var heap = new Heap(); + + var elems = { + a: { key: 5 }, + b: { key: 7 }, + c: { key: 3 }, + d: { key: 14 }, + e: { key: 8 }, + f: { key: 30 }, + g: { key: 23 }, + h: { key: 1 }, + }; + + Object.keys(elems).forEach(function (key) { + heap.insert(elems[key], elems[key].key); + printHeap(heap); + }); + + heap.remove(elems.e); + printHeap(heap); + + t.equal(heap.length, heap.count(heap.root), "length and count should match"); + t.equal(heap.length, Object.keys(elems).length - 1, "should only remove one ndoe"); + printHeap(heap); + + heap.remove(elems.a); + t.equal(heap.length, heap.count(heap.root), "length and count should match"); + printHeap(heap); + + + heap.remove(elems.b); + t.equal(heap.length, heap.count(heap.root), "length and count should match"); + printHeap(heap); + + t.end(); +}); diff --git a/node_modules/buffercursor/README.md b/node_modules/buffercursor/README.md new file mode 100644 index 0000000..12c1c2a --- /dev/null +++ b/node_modules/buffercursor/README.md @@ -0,0 +1,47 @@ +BufferCursor +============ + +This is a simple module that allows you to traverse a Buffer iteratively. You +can read and write different types and the cursor's position will update with +the proper size, which you can see through `.tell()` you can also +`.seek()` + +```javascript +var bc = new BufferCursor(buffer); +bc.readUInt16BE(); +bc.readUInt8(); +bc.readUInt32BE(); +console.log(bc.tell()); +``` + +Will output `7` + +Methods +------- + +For the most part `BufferCursor` and `Buffer` share the same methods, there's +just a slight alteration in method signature, none of the methods take an +offset. + +So `.readUInt16LE(10)` in `Buffer` is equivalent to `bs.seek(10); bs.readUInt16LE();` + +All `read[U]Int` and `write[U]Int` methods are reproduced, as are `toString`, +`write`, `fill`, and `slice`. All of these methods will move the cursor through +the stream and do not take an offset parameter, where an `end` parameter would +normaly be used, here you supply a `length`. + +The following are additional methods: + + * `seek(value)` -- Seek to an arbitrary position in the stream + * `tell()` -- Return the current location in the stream + * `eof()` -- Return true if at the end of the stream + * `toByteArray([method])` -- This is a special helper method which will return +the *entire* stream (i.e. from the start) as an array of numbers. + - By default it will use `readUInt8` but you can pass in any +`read[U]Int[8,16,32][LE,BE]` to change what the array is made of + +Properties +---------- + + * `.buffer` -- Access to the raw buffer + * `.length` -- The size of the buffer diff --git a/node_modules/buffercursor/buffercursor.js b/node_modules/buffercursor/buffercursor.js new file mode 100644 index 0000000..8c58349 --- /dev/null +++ b/node_modules/buffercursor/buffercursor.js @@ -0,0 +1,388 @@ +// Copyright 2012 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +var util = require('util'); +var VError = require('verror'); + +var BufferCursor = module.exports = function(buff, noAssert) { + if (!(this instanceof BufferCursor)) + return new BufferCursor(buff, noAssert); + + this._pos = 0; + + this._noAssert = noAssert; + + if (this._noAssert === undefined) + this._noAssert = true; + + this.buffer = buff; + this.length = buff.length; +}; + +var BCO = BufferCursor.BufferCursorOverflow = function(length, pos, size) { + this.kind = 'BufferCursorOverflow'; + this.length = length; + this.position = pos; + this.size = size; + VError.call(this, + 'BufferCursorOverflow: length %d, position %d, size %d', + length, + pos, + size); +}; +util.inherits(BCO, VError); + +BufferCursor.prototype._move = function(step) { + this._checkWrite(step); + this._pos += step; +}; + +BufferCursor.prototype._checkWrite = function(size) { + var shouldThrow = false; + + var length = this.length; + var pos = this._pos; + + if (size > length) + shouldThrow = true; + + if (length - pos < size) + shouldThrow = true; + + if (shouldThrow) { + var bco = new BCO(length, + pos, + size); + throw bco; + } +} + +BufferCursor.prototype.seek = function(pos) { + if (pos < 0) + throw new VError(new RangeError('Cannot seek before start of buffer'), + 'Negative seek values not allowed: %d', pos); + + if (pos > this.length) + throw new VError(new RangeError('Trying to seek beyond buffer'), + 'Requested %d position is beyond length %d', + pos, this.length); + + this._pos = pos; + return this; +}; + +BufferCursor.prototype.eof = function() { + return this._pos == this.length; +}; + +BufferCursor.prototype.toByteArray = function(method) { + var arr = [], i, part, count; + + if (!method) { + method = 'readUInt8'; + part = 1; + } + + if (method.indexOf('16') > 0) + part = 2; + else if (method.indexOf('32') > 0) + part = 4; + + count = this.length / part; + + for (i = 0; i < this.buffer.length; i += part) { + arr.push(this.buffer[method](i)); + } + return arr; +}; + +BufferCursor.prototype.tell = function() { + return this._pos; +}; + +BufferCursor.prototype.slice = function(length) { + var end, b; + + if (length === undefined) { + end = this.length; + } else { + end = this._pos + length; + } + + b = new BufferCursor(this.buffer.slice(this._pos, end)); + this.seek(end); + + return b; +}; + +BufferCursor.prototype.toString = function(encoding, length) { + var end, ret; + + if (length === undefined) { + end = this.length; + } else { + end = this._pos + length; + } + + if (!encoding) { + encoding = 'utf8'; + } + + ret = this.buffer.toString(encoding, this._pos, end); + this.seek(end); + return ret; +}; + +// This method doesn't need to _checkWrite because Buffer implicitly truncates +// to the length of the buffer, it's the only method in Node core that behaves +// this way by default +BufferCursor.prototype.write = function(value, length, encoding) { + var end, ret; + + ret = this.buffer.write(value, this._pos, length, encoding); + this._move(ret); + return this; +}; + +BufferCursor.prototype.fill = function(value, length) { + var end; + + if (length === undefined) { + end = this.length; + } else { + end = this._pos + length; + } + + this._checkWrite(end - this._pos); + + this.buffer.fill(value, this._pos, end); + this.seek(end); + return this; +}; + +// This prototype is not entirely like the upstream Buffer.copy, instead it +// is the target buffer, and accepts the source buffer -- since the target +// buffer knows its starting position +BufferCursor.prototype.copy = function copy(source, sourceStart, sourceEnd) { + var sBC = source instanceof BufferCursor; + + if (isNaN(sourceEnd)) + sourceEnd = source.length; + + if (isNaN(sourceStart)) { + if (sBC) + sourceStart = source._pos; + else + sourceStart = 0; + } + + var length = sourceEnd - sourceStart; + + this._checkWrite(length); + + var buf = sBC ? source.buffer : source; + + buf.copy(this.buffer, this._pos, sourceStart, sourceEnd); + + this._move(length); + return this; +}; + +BufferCursor.prototype.readUInt8 = function() { + var ret = this.buffer.readUInt8(this._pos, this._noAssert); + this._move(1); + return ret; +}; + +BufferCursor.prototype.readInt8 = function() { + var ret = this.buffer.readInt8(this._pos, this._noAssert); + this._move(1); + return ret; +}; + +BufferCursor.prototype.readInt16BE = function() { + var ret = this.buffer.readInt16BE(this._pos, this._noAssert); + this._move(2); + return ret; +}; + +BufferCursor.prototype.readInt16LE = function() { + var ret = this.buffer.readInt16LE(this._pos, this._noAssert); + this._move(2); + return ret; +}; + +BufferCursor.prototype.readUInt16BE = function() { + var ret = this.buffer.readUInt16BE(this._pos, this._noAssert); + this._move(2); + return ret; +}; + +BufferCursor.prototype.readUInt16LE = function() { + var ret = this.buffer.readUInt16LE(this._pos, this._noAssert); + this._move(2); + return ret; +}; + +BufferCursor.prototype.readUInt32LE = function() { + var ret = this.buffer.readUInt32LE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readUInt32BE = function() { + var ret = this.buffer.readUInt32BE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readInt32LE = function() { + var ret = this.buffer.readInt32LE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readInt32BE = function() { + var ret = this.buffer.readInt32BE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readFloatBE = function() { + var ret = this.buffer.readFloatBE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readFloatLE = function() { + var ret = this.buffer.readFloatLE(this._pos, this._noAssert); + this._move(4); + return ret; +}; + +BufferCursor.prototype.readDoubleBE = function() { + var ret = this.buffer.readDoubleBE(this._pos, this._noAssert); + this._move(8); + return ret; +}; + +BufferCursor.prototype.readDoubleLE = function() { + var ret = this.buffer.readDoubleLE(this._pos, this._noAssert); + this._move(8); + return ret; +}; + +BufferCursor.prototype.writeUInt8 = function(value) { + this._checkWrite(1); + this.buffer.writeUInt8(value, this._pos, this._noAssert); + this._move(1); + return this; +}; + +BufferCursor.prototype.writeInt8 = function(value) { + this._checkWrite(1); + this.buffer.writeInt8(value, this._pos, this._noAssert); + this._move(1); + return this; +}; + +BufferCursor.prototype.writeUInt16BE = function(value) { + this._checkWrite(2); + this.buffer.writeUInt16BE(value, this._pos, this._noAssert); + this._move(2); + return this; +}; + +BufferCursor.prototype.writeUInt16LE = function(value) { + this._checkWrite(2); + this.buffer.writeUInt16LE(value, this._pos, this._noAssert); + this._move(2); + return this; +}; + +BufferCursor.prototype.writeInt16BE = function(value) { + this._checkWrite(2); + this.buffer.writeInt16BE(value, this._pos, this._noAssert); + this._move(2); + return this; +}; + +BufferCursor.prototype.writeInt16LE = function(value) { + this._checkWrite(2); + this.buffer.writeInt16LE(value, this._pos, this._noAssert); + this._move(2); + return this; +}; + +BufferCursor.prototype.writeUInt32BE = function(value) { + this._checkWrite(4); + this.buffer.writeUInt32BE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeUInt32LE = function(value) { + this._checkWrite(4); + this.buffer.writeUInt32LE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeInt32BE = function(value) { + this._checkWrite(4); + this.buffer.writeInt32BE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeInt32LE = function(value) { + this._checkWrite(4); + this.buffer.writeInt32LE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeFloatBE = function(value) { + this._checkWrite(4); + this.buffer.writeFloatBE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeFloatLE = function(value) { + this._checkWrite(4); + this.buffer.writeFloatLE(value, this._pos, this._noAssert); + this._move(4); + return this; +}; + +BufferCursor.prototype.writeDoubleBE = function(value) { + this._checkWrite(8); + this.buffer.writeDoubleBE(value, this._pos, this._noAssert); + this._move(8); + return this; +}; + +BufferCursor.prototype.writeDoubleLE = function(value) { + this._checkWrite(8); + this.buffer.writeDoubleLE(value, this._pos, this._noAssert); + this._move(8); + return this; +}; diff --git a/node_modules/buffercursor/package.json b/node_modules/buffercursor/package.json new file mode 100644 index 0000000..3021053 --- /dev/null +++ b/node_modules/buffercursor/package.json @@ -0,0 +1,85 @@ +{ + "_args": [ + [ + { + "raw": "buffercursor@>= 0.0.12", + "scope": null, + "escapedName": "buffercursor", + "name": "buffercursor", + "rawSpec": ">= 0.0.12", + "spec": ">=0.0.12", + "type": "range" + }, + "/srv/demos/node_modules/native-dns-packet" + ] + ], + "_from": "buffercursor@>=0.0.12", + "_id": "buffercursor@0.0.12", + "_inCache": true, + "_location": "/buffercursor", + "_npmUser": { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + }, + "_npmVersion": "1.4.3", + "_phantomChildren": {}, + "_requested": { + "raw": "buffercursor@>= 0.0.12", + "scope": null, + "escapedName": "buffercursor", + "name": "buffercursor", + "rawSpec": ">= 0.0.12", + "spec": ">=0.0.12", + "type": "range" + }, + "_requiredBy": [ + "/native-dns-packet" + ], + "_resolved": "https://registry.npmjs.org/buffercursor/-/buffercursor-0.0.12.tgz", + "_shasum": "78a9a7f4343ae7d820a8999acc80de591e25a779", + "_shrinkwrap": null, + "_spec": "buffercursor@>= 0.0.12", + "_where": "/srv/demos/node_modules/native-dns-packet", + "author": { + "name": "Timothy J Fontaine", + "email": "tjfontaine@gmail.com", + "url": "http://atxconsulting.com" + }, + "bugs": { + "url": "http://github.com/tjfontaine/node-buffercursor/issues" + }, + "dependencies": { + "verror": "^1.4.0" + }, + "description": "A simple way to traverse a Buffer like a cursor, updating position along the way", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "78a9a7f4343ae7d820a8999acc80de591e25a779", + "tarball": "https://registry.npmjs.org/buffercursor/-/buffercursor-0.0.12.tgz" + }, + "engines": { + "node": ">= 0.5.0" + }, + "homepage": "http://github.com/tjfontaine/node-buffercursor", + "keywords": [ + "buffer", + "cursor", + "stream" + ], + "main": "buffercursor.js", + "maintainers": [ + { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + } + ], + "name": "buffercursor", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/tjfontaine/node-buffercursor.git" + }, + "version": "0.0.12" +} diff --git a/node_modules/core-util-is/LICENSE b/node_modules/core-util-is/LICENSE new file mode 100644 index 0000000..d8d7f94 --- /dev/null +++ b/node_modules/core-util-is/LICENSE @@ -0,0 +1,19 @@ +Copyright Node.js contributors. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/node_modules/core-util-is/README.md b/node_modules/core-util-is/README.md new file mode 100644 index 0000000..5a76b41 --- /dev/null +++ b/node_modules/core-util-is/README.md @@ -0,0 +1,3 @@ +# core-util-is + +The `util.is*` functions introduced in Node v0.12. diff --git a/node_modules/core-util-is/float.patch b/node_modules/core-util-is/float.patch new file mode 100644 index 0000000..a06d5c0 --- /dev/null +++ b/node_modules/core-util-is/float.patch @@ -0,0 +1,604 @@ +diff --git a/lib/util.js b/lib/util.js +index a03e874..9074e8e 100644 +--- a/lib/util.js ++++ b/lib/util.js +@@ -19,430 +19,6 @@ + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + +-var formatRegExp = /%[sdj%]/g; +-exports.format = function(f) { +- if (!isString(f)) { +- var objects = []; +- for (var i = 0; i < arguments.length; i++) { +- objects.push(inspect(arguments[i])); +- } +- return objects.join(' '); +- } +- +- var i = 1; +- var args = arguments; +- var len = args.length; +- var str = String(f).replace(formatRegExp, function(x) { +- if (x === '%%') return '%'; +- if (i >= len) return x; +- switch (x) { +- case '%s': return String(args[i++]); +- case '%d': return Number(args[i++]); +- case '%j': +- try { +- return JSON.stringify(args[i++]); +- } catch (_) { +- return '[Circular]'; +- } +- default: +- return x; +- } +- }); +- for (var x = args[i]; i < len; x = args[++i]) { +- if (isNull(x) || !isObject(x)) { +- str += ' ' + x; +- } else { +- str += ' ' + inspect(x); +- } +- } +- return str; +-}; +- +- +-// Mark that a method should not be used. +-// Returns a modified function which warns once by default. +-// If --no-deprecation is set, then it is a no-op. +-exports.deprecate = function(fn, msg) { +- // Allow for deprecating things in the process of starting up. +- if (isUndefined(global.process)) { +- return function() { +- return exports.deprecate(fn, msg).apply(this, arguments); +- }; +- } +- +- if (process.noDeprecation === true) { +- return fn; +- } +- +- var warned = false; +- function deprecated() { +- if (!warned) { +- if (process.throwDeprecation) { +- throw new Error(msg); +- } else if (process.traceDeprecation) { +- console.trace(msg); +- } else { +- console.error(msg); +- } +- warned = true; +- } +- return fn.apply(this, arguments); +- } +- +- return deprecated; +-}; +- +- +-var debugs = {}; +-var debugEnviron; +-exports.debuglog = function(set) { +- if (isUndefined(debugEnviron)) +- debugEnviron = process.env.NODE_DEBUG || ''; +- set = set.toUpperCase(); +- if (!debugs[set]) { +- if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { +- var pid = process.pid; +- debugs[set] = function() { +- var msg = exports.format.apply(exports, arguments); +- console.error('%s %d: %s', set, pid, msg); +- }; +- } else { +- debugs[set] = function() {}; +- } +- } +- return debugs[set]; +-}; +- +- +-/** +- * Echos the value of a value. Trys to print the value out +- * in the best way possible given the different types. +- * +- * @param {Object} obj The object to print out. +- * @param {Object} opts Optional options object that alters the output. +- */ +-/* legacy: obj, showHidden, depth, colors*/ +-function inspect(obj, opts) { +- // default options +- var ctx = { +- seen: [], +- stylize: stylizeNoColor +- }; +- // legacy... +- if (arguments.length >= 3) ctx.depth = arguments[2]; +- if (arguments.length >= 4) ctx.colors = arguments[3]; +- if (isBoolean(opts)) { +- // legacy... +- ctx.showHidden = opts; +- } else if (opts) { +- // got an "options" object +- exports._extend(ctx, opts); +- } +- // set default options +- if (isUndefined(ctx.showHidden)) ctx.showHidden = false; +- if (isUndefined(ctx.depth)) ctx.depth = 2; +- if (isUndefined(ctx.colors)) ctx.colors = false; +- if (isUndefined(ctx.customInspect)) ctx.customInspect = true; +- if (ctx.colors) ctx.stylize = stylizeWithColor; +- return formatValue(ctx, obj, ctx.depth); +-} +-exports.inspect = inspect; +- +- +-// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +-inspect.colors = { +- 'bold' : [1, 22], +- 'italic' : [3, 23], +- 'underline' : [4, 24], +- 'inverse' : [7, 27], +- 'white' : [37, 39], +- 'grey' : [90, 39], +- 'black' : [30, 39], +- 'blue' : [34, 39], +- 'cyan' : [36, 39], +- 'green' : [32, 39], +- 'magenta' : [35, 39], +- 'red' : [31, 39], +- 'yellow' : [33, 39] +-}; +- +-// Don't use 'blue' not visible on cmd.exe +-inspect.styles = { +- 'special': 'cyan', +- 'number': 'yellow', +- 'boolean': 'yellow', +- 'undefined': 'grey', +- 'null': 'bold', +- 'string': 'green', +- 'date': 'magenta', +- // "name": intentionally not styling +- 'regexp': 'red' +-}; +- +- +-function stylizeWithColor(str, styleType) { +- var style = inspect.styles[styleType]; +- +- if (style) { +- return '\u001b[' + inspect.colors[style][0] + 'm' + str + +- '\u001b[' + inspect.colors[style][1] + 'm'; +- } else { +- return str; +- } +-} +- +- +-function stylizeNoColor(str, styleType) { +- return str; +-} +- +- +-function arrayToHash(array) { +- var hash = {}; +- +- array.forEach(function(val, idx) { +- hash[val] = true; +- }); +- +- return hash; +-} +- +- +-function formatValue(ctx, value, recurseTimes) { +- // Provide a hook for user-specified inspect functions. +- // Check that value is an object with an inspect function on it +- if (ctx.customInspect && +- value && +- isFunction(value.inspect) && +- // Filter out the util module, it's inspect function is special +- value.inspect !== exports.inspect && +- // Also filter out any prototype objects using the circular check. +- !(value.constructor && value.constructor.prototype === value)) { +- var ret = value.inspect(recurseTimes, ctx); +- if (!isString(ret)) { +- ret = formatValue(ctx, ret, recurseTimes); +- } +- return ret; +- } +- +- // Primitive types cannot have properties +- var primitive = formatPrimitive(ctx, value); +- if (primitive) { +- return primitive; +- } +- +- // Look up the keys of the object. +- var keys = Object.keys(value); +- var visibleKeys = arrayToHash(keys); +- +- if (ctx.showHidden) { +- keys = Object.getOwnPropertyNames(value); +- } +- +- // Some type of object without properties can be shortcutted. +- if (keys.length === 0) { +- if (isFunction(value)) { +- var name = value.name ? ': ' + value.name : ''; +- return ctx.stylize('[Function' + name + ']', 'special'); +- } +- if (isRegExp(value)) { +- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); +- } +- if (isDate(value)) { +- return ctx.stylize(Date.prototype.toString.call(value), 'date'); +- } +- if (isError(value)) { +- return formatError(value); +- } +- } +- +- var base = '', array = false, braces = ['{', '}']; +- +- // Make Array say that they are Array +- if (isArray(value)) { +- array = true; +- braces = ['[', ']']; +- } +- +- // Make functions say that they are functions +- if (isFunction(value)) { +- var n = value.name ? ': ' + value.name : ''; +- base = ' [Function' + n + ']'; +- } +- +- // Make RegExps say that they are RegExps +- if (isRegExp(value)) { +- base = ' ' + RegExp.prototype.toString.call(value); +- } +- +- // Make dates with properties first say the date +- if (isDate(value)) { +- base = ' ' + Date.prototype.toUTCString.call(value); +- } +- +- // Make error with message first say the error +- if (isError(value)) { +- base = ' ' + formatError(value); +- } +- +- if (keys.length === 0 && (!array || value.length == 0)) { +- return braces[0] + base + braces[1]; +- } +- +- if (recurseTimes < 0) { +- if (isRegExp(value)) { +- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); +- } else { +- return ctx.stylize('[Object]', 'special'); +- } +- } +- +- ctx.seen.push(value); +- +- var output; +- if (array) { +- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); +- } else { +- output = keys.map(function(key) { +- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); +- }); +- } +- +- ctx.seen.pop(); +- +- return reduceToSingleString(output, base, braces); +-} +- +- +-function formatPrimitive(ctx, value) { +- if (isUndefined(value)) +- return ctx.stylize('undefined', 'undefined'); +- if (isString(value)) { +- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') +- .replace(/'/g, "\\'") +- .replace(/\\"/g, '"') + '\''; +- return ctx.stylize(simple, 'string'); +- } +- if (isNumber(value)) { +- // Format -0 as '-0'. Strict equality won't distinguish 0 from -0, +- // so instead we use the fact that 1 / -0 < 0 whereas 1 / 0 > 0 . +- if (value === 0 && 1 / value < 0) +- return ctx.stylize('-0', 'number'); +- return ctx.stylize('' + value, 'number'); +- } +- if (isBoolean(value)) +- return ctx.stylize('' + value, 'boolean'); +- // For some reason typeof null is "object", so special case here. +- if (isNull(value)) +- return ctx.stylize('null', 'null'); +-} +- +- +-function formatError(value) { +- return '[' + Error.prototype.toString.call(value) + ']'; +-} +- +- +-function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { +- var output = []; +- for (var i = 0, l = value.length; i < l; ++i) { +- if (hasOwnProperty(value, String(i))) { +- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, +- String(i), true)); +- } else { +- output.push(''); +- } +- } +- keys.forEach(function(key) { +- if (!key.match(/^\d+$/)) { +- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, +- key, true)); +- } +- }); +- return output; +-} +- +- +-function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { +- var name, str, desc; +- desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; +- if (desc.get) { +- if (desc.set) { +- str = ctx.stylize('[Getter/Setter]', 'special'); +- } else { +- str = ctx.stylize('[Getter]', 'special'); +- } +- } else { +- if (desc.set) { +- str = ctx.stylize('[Setter]', 'special'); +- } +- } +- if (!hasOwnProperty(visibleKeys, key)) { +- name = '[' + key + ']'; +- } +- if (!str) { +- if (ctx.seen.indexOf(desc.value) < 0) { +- if (isNull(recurseTimes)) { +- str = formatValue(ctx, desc.value, null); +- } else { +- str = formatValue(ctx, desc.value, recurseTimes - 1); +- } +- if (str.indexOf('\n') > -1) { +- if (array) { +- str = str.split('\n').map(function(line) { +- return ' ' + line; +- }).join('\n').substr(2); +- } else { +- str = '\n' + str.split('\n').map(function(line) { +- return ' ' + line; +- }).join('\n'); +- } +- } +- } else { +- str = ctx.stylize('[Circular]', 'special'); +- } +- } +- if (isUndefined(name)) { +- if (array && key.match(/^\d+$/)) { +- return str; +- } +- name = JSON.stringify('' + key); +- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { +- name = name.substr(1, name.length - 2); +- name = ctx.stylize(name, 'name'); +- } else { +- name = name.replace(/'/g, "\\'") +- .replace(/\\"/g, '"') +- .replace(/(^"|"$)/g, "'"); +- name = ctx.stylize(name, 'string'); +- } +- } +- +- return name + ': ' + str; +-} +- +- +-function reduceToSingleString(output, base, braces) { +- var numLinesEst = 0; +- var length = output.reduce(function(prev, cur) { +- numLinesEst++; +- if (cur.indexOf('\n') >= 0) numLinesEst++; +- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; +- }, 0); +- +- if (length > 60) { +- return braces[0] + +- (base === '' ? '' : base + '\n ') + +- ' ' + +- output.join(',\n ') + +- ' ' + +- braces[1]; +- } +- +- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +-} +- +- + // NOTE: These type checking functions intentionally don't use `instanceof` + // because it is fragile and can be easily faked with `Object.create()`. + function isArray(ar) { +@@ -522,166 +98,10 @@ function isPrimitive(arg) { + exports.isPrimitive = isPrimitive; + + function isBuffer(arg) { +- return arg instanceof Buffer; ++ return Buffer.isBuffer(arg); + } + exports.isBuffer = isBuffer; + + function objectToString(o) { + return Object.prototype.toString.call(o); +-} +- +- +-function pad(n) { +- return n < 10 ? '0' + n.toString(10) : n.toString(10); +-} +- +- +-var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', +- 'Oct', 'Nov', 'Dec']; +- +-// 26 Feb 16:19:34 +-function timestamp() { +- var d = new Date(); +- var time = [pad(d.getHours()), +- pad(d.getMinutes()), +- pad(d.getSeconds())].join(':'); +- return [d.getDate(), months[d.getMonth()], time].join(' '); +-} +- +- +-// log is just a thin wrapper to console.log that prepends a timestamp +-exports.log = function() { +- console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +-}; +- +- +-/** +- * Inherit the prototype methods from one constructor into another. +- * +- * The Function.prototype.inherits from lang.js rewritten as a standalone +- * function (not on Function.prototype). NOTE: If this file is to be loaded +- * during bootstrapping this function needs to be rewritten using some native +- * functions as prototype setup using normal JavaScript does not work as +- * expected during bootstrapping (see mirror.js in r114903). +- * +- * @param {function} ctor Constructor function which needs to inherit the +- * prototype. +- * @param {function} superCtor Constructor function to inherit prototype from. +- */ +-exports.inherits = function(ctor, superCtor) { +- ctor.super_ = superCtor; +- ctor.prototype = Object.create(superCtor.prototype, { +- constructor: { +- value: ctor, +- enumerable: false, +- writable: true, +- configurable: true +- } +- }); +-}; +- +-exports._extend = function(origin, add) { +- // Don't do anything if add isn't an object +- if (!add || !isObject(add)) return origin; +- +- var keys = Object.keys(add); +- var i = keys.length; +- while (i--) { +- origin[keys[i]] = add[keys[i]]; +- } +- return origin; +-}; +- +-function hasOwnProperty(obj, prop) { +- return Object.prototype.hasOwnProperty.call(obj, prop); +-} +- +- +-// Deprecated old stuff. +- +-exports.p = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- console.error(exports.inspect(arguments[i])); +- } +-}, 'util.p: Use console.error() instead'); +- +- +-exports.exec = exports.deprecate(function() { +- return require('child_process').exec.apply(this, arguments); +-}, 'util.exec is now called `child_process.exec`.'); +- +- +-exports.print = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stdout.write(String(arguments[i])); +- } +-}, 'util.print: Use console.log instead'); +- +- +-exports.puts = exports.deprecate(function() { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stdout.write(arguments[i] + '\n'); +- } +-}, 'util.puts: Use console.log instead'); +- +- +-exports.debug = exports.deprecate(function(x) { +- process.stderr.write('DEBUG: ' + x + '\n'); +-}, 'util.debug: Use console.error instead'); +- +- +-exports.error = exports.deprecate(function(x) { +- for (var i = 0, len = arguments.length; i < len; ++i) { +- process.stderr.write(arguments[i] + '\n'); +- } +-}, 'util.error: Use console.error instead'); +- +- +-exports.pump = exports.deprecate(function(readStream, writeStream, callback) { +- var callbackCalled = false; +- +- function call(a, b, c) { +- if (callback && !callbackCalled) { +- callback(a, b, c); +- callbackCalled = true; +- } +- } +- +- readStream.addListener('data', function(chunk) { +- if (writeStream.write(chunk) === false) readStream.pause(); +- }); +- +- writeStream.addListener('drain', function() { +- readStream.resume(); +- }); +- +- readStream.addListener('end', function() { +- writeStream.end(); +- }); +- +- readStream.addListener('close', function() { +- call(); +- }); +- +- readStream.addListener('error', function(err) { +- writeStream.end(); +- call(err); +- }); +- +- writeStream.addListener('error', function(err) { +- readStream.destroy(); +- call(err); +- }); +-}, 'util.pump(): Use readableStream.pipe() instead'); +- +- +-var uv; +-exports._errnoException = function(err, syscall) { +- if (isUndefined(uv)) uv = process.binding('uv'); +- var errname = uv.errname(err); +- var e = new Error(syscall + ' ' + errname); +- e.code = errname; +- e.errno = errname; +- e.syscall = syscall; +- return e; +-}; ++} \ No newline at end of file diff --git a/node_modules/core-util-is/lib/util.js b/node_modules/core-util-is/lib/util.js new file mode 100644 index 0000000..ff4c851 --- /dev/null +++ b/node_modules/core-util-is/lib/util.js @@ -0,0 +1,107 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. + +function isArray(arg) { + if (Array.isArray) { + return Array.isArray(arg); + } + return objectToString(arg) === '[object Array]'; +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = Buffer.isBuffer; + +function objectToString(o) { + return Object.prototype.toString.call(o); +} diff --git a/node_modules/core-util-is/package.json b/node_modules/core-util-is/package.json new file mode 100644 index 0000000..ecd6501 --- /dev/null +++ b/node_modules/core-util-is/package.json @@ -0,0 +1,94 @@ +{ + "_args": [ + [ + { + "raw": "core-util-is@1.0.2", + "scope": null, + "escapedName": "core-util-is", + "name": "core-util-is", + "rawSpec": "1.0.2", + "spec": "1.0.2", + "type": "version" + }, + "/srv/demos/node_modules/verror" + ] + ], + "_from": "core-util-is@1.0.2", + "_id": "core-util-is@1.0.2", + "_inCache": true, + "_location": "/core-util-is", + "_nodeVersion": "4.0.0", + "_npmUser": { + "name": "isaacs", + "email": "i@izs.me" + }, + "_npmVersion": "3.3.2", + "_phantomChildren": {}, + "_requested": { + "raw": "core-util-is@1.0.2", + "scope": null, + "escapedName": "core-util-is", + "name": "core-util-is", + "rawSpec": "1.0.2", + "spec": "1.0.2", + "type": "version" + }, + "_requiredBy": [ + "/verror" + ], + "_resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "_shasum": "b5fd54220aa2bc5ab57aab7140c940754503c1a7", + "_shrinkwrap": null, + "_spec": "core-util-is@1.0.2", + "_where": "/srv/demos/node_modules/verror", + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "bugs": { + "url": "https://github.com/isaacs/core-util-is/issues" + }, + "dependencies": {}, + "description": "The `util.is*` functions introduced in Node v0.12.", + "devDependencies": { + "tap": "^2.3.0" + }, + "directories": {}, + "dist": { + "shasum": "b5fd54220aa2bc5ab57aab7140c940754503c1a7", + "tarball": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" + }, + "gitHead": "a177da234df5638b363ddc15fa324619a38577c8", + "homepage": "https://github.com/isaacs/core-util-is#readme", + "keywords": [ + "util", + "isBuffer", + "isArray", + "isNumber", + "isString", + "isRegExp", + "isThis", + "isThat", + "polyfill" + ], + "license": "MIT", + "main": "lib/util.js", + "maintainers": [ + { + "name": "isaacs", + "email": "i@izs.me" + } + ], + "name": "core-util-is", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/isaacs/core-util-is.git" + }, + "scripts": { + "test": "tap test.js" + }, + "version": "1.0.2" +} diff --git a/node_modules/core-util-is/test.js b/node_modules/core-util-is/test.js new file mode 100644 index 0000000..1a490c6 --- /dev/null +++ b/node_modules/core-util-is/test.js @@ -0,0 +1,68 @@ +var assert = require('tap'); + +var t = require('./lib/util'); + +assert.equal(t.isArray([]), true); +assert.equal(t.isArray({}), false); + +assert.equal(t.isBoolean(null), false); +assert.equal(t.isBoolean(true), true); +assert.equal(t.isBoolean(false), true); + +assert.equal(t.isNull(null), true); +assert.equal(t.isNull(undefined), false); +assert.equal(t.isNull(false), false); +assert.equal(t.isNull(), false); + +assert.equal(t.isNullOrUndefined(null), true); +assert.equal(t.isNullOrUndefined(undefined), true); +assert.equal(t.isNullOrUndefined(false), false); +assert.equal(t.isNullOrUndefined(), true); + +assert.equal(t.isNumber(null), false); +assert.equal(t.isNumber('1'), false); +assert.equal(t.isNumber(1), true); + +assert.equal(t.isString(null), false); +assert.equal(t.isString('1'), true); +assert.equal(t.isString(1), false); + +assert.equal(t.isSymbol(null), false); +assert.equal(t.isSymbol('1'), false); +assert.equal(t.isSymbol(1), false); +assert.equal(t.isSymbol(Symbol()), true); + +assert.equal(t.isUndefined(null), false); +assert.equal(t.isUndefined(undefined), true); +assert.equal(t.isUndefined(false), false); +assert.equal(t.isUndefined(), true); + +assert.equal(t.isRegExp(null), false); +assert.equal(t.isRegExp('1'), false); +assert.equal(t.isRegExp(new RegExp()), true); + +assert.equal(t.isObject({}), true); +assert.equal(t.isObject([]), true); +assert.equal(t.isObject(new RegExp()), true); +assert.equal(t.isObject(new Date()), true); + +assert.equal(t.isDate(null), false); +assert.equal(t.isDate('1'), false); +assert.equal(t.isDate(new Date()), true); + +assert.equal(t.isError(null), false); +assert.equal(t.isError({ err: true }), false); +assert.equal(t.isError(new Error()), true); + +assert.equal(t.isFunction(null), false); +assert.equal(t.isFunction({ }), false); +assert.equal(t.isFunction(function() {}), true); + +assert.equal(t.isPrimitive(null), true); +assert.equal(t.isPrimitive(''), true); +assert.equal(t.isPrimitive(0), true); +assert.equal(t.isPrimitive(new Date()), false); + +assert.equal(t.isBuffer(null), false); +assert.equal(t.isBuffer({}), false); +assert.equal(t.isBuffer(new Buffer(0)), true); diff --git a/node_modules/debug/.coveralls.yml b/node_modules/debug/.coveralls.yml new file mode 100644 index 0000000..20a7068 --- /dev/null +++ b/node_modules/debug/.coveralls.yml @@ -0,0 +1 @@ +repo_token: SIAeZjKYlHK74rbcFvNHMUzjRiMpflxve diff --git a/node_modules/debug/.eslintrc b/node_modules/debug/.eslintrc new file mode 100644 index 0000000..8a37ae2 --- /dev/null +++ b/node_modules/debug/.eslintrc @@ -0,0 +1,11 @@ +{ + "env": { + "browser": true, + "node": true + }, + "rules": { + "no-console": 0, + "no-empty": [1, { "allowEmptyCatch": true }] + }, + "extends": "eslint:recommended" +} diff --git a/node_modules/debug/.jshintrc b/node_modules/debug/.jshintrc new file mode 100644 index 0000000..299877f --- /dev/null +++ b/node_modules/debug/.jshintrc @@ -0,0 +1,3 @@ +{ + "laxbreak": true +} diff --git a/node_modules/debug/.npmignore b/node_modules/debug/.npmignore new file mode 100644 index 0000000..35b0dc7 --- /dev/null +++ b/node_modules/debug/.npmignore @@ -0,0 +1,7 @@ +support +test +examples +example +*.sock +dist +yarn.lock diff --git a/node_modules/debug/.travis.yml b/node_modules/debug/.travis.yml new file mode 100644 index 0000000..6c6090c --- /dev/null +++ b/node_modules/debug/.travis.yml @@ -0,0 +1,14 @@ + +language: node_js +node_js: + - "6" + - "5" + - "4" + +install: + - make node_modules + +script: + - make lint + - make test + - make coveralls diff --git a/node_modules/debug/CHANGELOG.md b/node_modules/debug/CHANGELOG.md new file mode 100644 index 0000000..d5bb0ac --- /dev/null +++ b/node_modules/debug/CHANGELOG.md @@ -0,0 +1,228 @@ +2.3.2 / 2016-11-09 +================== + + * Fix: be super-safe in index.js as well (@TooTallNate) + * Fix: should check whether process exists (Tom Newby) + +2.3.1 / 2016-11-09 +================== + + * Fix: Added electron compatibility (#324, @paulcbetts) + * Improvement: Added performance optimizations (@tootallnate) + * Readme: Corrected PowerShell environment variable example (#252, @gimre) + * Misc: Removed yarn lock file from source control (#321, @fengmk2) + +2.3.0 / 2016-11-07 +================== + + * Fix: Consistent placement of ms diff at end of output (#215, @gorangajic) + * Fix: Escaping of regex special characters in namespace strings (#250, @zacronos) + * Fix: Fixed bug causing crash on react-native (#282, @vkarpov15) + * Feature: Enabled ES6+ compatible import via default export (#212 @bucaran) + * Feature: Added %O formatter to reflect Chrome's console.log capability (#279, @oncletom) + * Package: Update "ms" to 0.7.2 (#315, @DevSide) + * Package: removed superfluous version property from bower.json (#207 @kkirsche) + * Readme: fix USE_COLORS to DEBUG_COLORS + * Readme: Doc fixes for format string sugar (#269, @mlucool) + * Readme: Updated docs for DEBUG_FD and DEBUG_COLORS environment variables (#232, @mattlyons0) + * Readme: doc fixes for PowerShell (#271 #243, @exoticknight @unreadable) + * Readme: better docs for browser support (#224, @matthewmueller) + * Tooling: Added yarn integration for development (#317, @thebigredgeek) + * Misc: Renamed History.md to CHANGELOG.md (@thebigredgeek) + * Misc: Added license file (#226 #274, @CantemoInternal @sdaitzman) + * Misc: Updated contributors (@thebigredgeek) + +2.2.0 / 2015-05-09 +================== + + * package: update "ms" to v0.7.1 (#202, @dougwilson) + * README: add logging to file example (#193, @DanielOchoa) + * README: fixed a typo (#191, @amir-s) + * browser: expose `storage` (#190, @stephenmathieson) + * Makefile: add a `distclean` target (#189, @stephenmathieson) + +2.1.3 / 2015-03-13 +================== + + * Updated stdout/stderr example (#186) + * Updated example/stdout.js to match debug current behaviour + * Renamed example/stderr.js to stdout.js + * Update Readme.md (#184) + * replace high intensity foreground color for bold (#182, #183) + +2.1.2 / 2015-03-01 +================== + + * dist: recompile + * update "ms" to v0.7.0 + * package: update "browserify" to v9.0.3 + * component: fix "ms.js" repo location + * changed bower package name + * updated documentation about using debug in a browser + * fix: security error on safari (#167, #168, @yields) + +2.1.1 / 2014-12-29 +================== + + * browser: use `typeof` to check for `console` existence + * browser: check for `console.log` truthiness (fix IE 8/9) + * browser: add support for Chrome apps + * Readme: added Windows usage remarks + * Add `bower.json` to properly support bower install + +2.1.0 / 2014-10-15 +================== + + * node: implement `DEBUG_FD` env variable support + * package: update "browserify" to v6.1.0 + * package: add "license" field to package.json (#135, @panuhorsmalahti) + +2.0.0 / 2014-09-01 +================== + + * package: update "browserify" to v5.11.0 + * node: use stderr rather than stdout for logging (#29, @stephenmathieson) + +1.0.4 / 2014-07-15 +================== + + * dist: recompile + * example: remove `console.info()` log usage + * example: add "Content-Type" UTF-8 header to browser example + * browser: place %c marker after the space character + * browser: reset the "content" color via `color: inherit` + * browser: add colors support for Firefox >= v31 + * debug: prefer an instance `log()` function over the global one (#119) + * Readme: update documentation about styled console logs for FF v31 (#116, @wryk) + +1.0.3 / 2014-07-09 +================== + + * Add support for multiple wildcards in namespaces (#122, @seegno) + * browser: fix lint + +1.0.2 / 2014-06-10 +================== + + * browser: update color palette (#113, @gscottolson) + * common: make console logging function configurable (#108, @timoxley) + * node: fix %o colors on old node <= 0.8.x + * Makefile: find node path using shell/which (#109, @timoxley) + +1.0.1 / 2014-06-06 +================== + + * browser: use `removeItem()` to clear localStorage + * browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777) + * package: add "contributors" section + * node: fix comment typo + * README: list authors + +1.0.0 / 2014-06-04 +================== + + * make ms diff be global, not be scope + * debug: ignore empty strings in enable() + * node: make DEBUG_COLORS able to disable coloring + * *: export the `colors` array + * npmignore: don't publish the `dist` dir + * Makefile: refactor to use browserify + * package: add "browserify" as a dev dependency + * Readme: add Web Inspector Colors section + * node: reset terminal color for the debug content + * node: map "%o" to `util.inspect()` + * browser: map "%j" to `JSON.stringify()` + * debug: add custom "formatters" + * debug: use "ms" module for humanizing the diff + * Readme: add "bash" syntax highlighting + * browser: add Firebug color support + * browser: add colors for WebKit browsers + * node: apply log to `console` + * rewrite: abstract common logic for Node & browsers + * add .jshintrc file + +0.8.1 / 2014-04-14 +================== + + * package: re-add the "component" section + +0.8.0 / 2014-03-30 +================== + + * add `enable()` method for nodejs. Closes #27 + * change from stderr to stdout + * remove unnecessary index.js file + +0.7.4 / 2013-11-13 +================== + + * remove "browserify" key from package.json (fixes something in browserify) + +0.7.3 / 2013-10-30 +================== + + * fix: catch localStorage security error when cookies are blocked (Chrome) + * add debug(err) support. Closes #46 + * add .browser prop to package.json. Closes #42 + +0.7.2 / 2013-02-06 +================== + + * fix package.json + * fix: Mobile Safari (private mode) is broken with debug + * fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript + +0.7.1 / 2013-02-05 +================== + + * add repository URL to package.json + * add DEBUG_COLORED to force colored output + * add browserify support + * fix component. Closes #24 + +0.7.0 / 2012-05-04 +================== + + * Added .component to package.json + * Added debug.component.js build + +0.6.0 / 2012-03-16 +================== + + * Added support for "-" prefix in DEBUG [Vinay Pulim] + * Added `.enabled` flag to the node version [TooTallNate] + +0.5.0 / 2012-02-02 +================== + + * Added: humanize diffs. Closes #8 + * Added `debug.disable()` to the CS variant + * Removed padding. Closes #10 + * Fixed: persist client-side variant again. Closes #9 + +0.4.0 / 2012-02-01 +================== + + * Added browser variant support for older browsers [TooTallNate] + * Added `debug.enable('project:*')` to browser variant [TooTallNate] + * Added padding to diff (moved it to the right) + +0.3.0 / 2012-01-26 +================== + + * Added millisecond diff when isatty, otherwise UTC string + +0.2.0 / 2012-01-22 +================== + + * Added wildcard support + +0.1.0 / 2011-12-02 +================== + + * Added: remove colors unless stderr isatty [TooTallNate] + +0.0.1 / 2010-01-03 +================== + + * Initial release diff --git a/node_modules/debug/LICENSE b/node_modules/debug/LICENSE new file mode 100644 index 0000000..658c933 --- /dev/null +++ b/node_modules/debug/LICENSE @@ -0,0 +1,19 @@ +(The MIT License) + +Copyright (c) 2014 TJ Holowaychuk + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the 'Software'), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/node_modules/debug/Makefile b/node_modules/debug/Makefile new file mode 100644 index 0000000..db71caf --- /dev/null +++ b/node_modules/debug/Makefile @@ -0,0 +1,37 @@ + +# get Makefile directory name: http://stackoverflow.com/a/5982798/376773 +THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) +THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) + +# BIN directory +BIN := $(THIS_DIR)/node_modules/.bin + +# applications +NODE ?= $(shell which node) +YARN ?= $(shell which yarn) +PKG ?= $(if $(YARN),$(YARN),$(NODE) $(shell which npm)) +BROWSERIFY ?= $(NODE) $(BIN)/browserify + +all: dist/debug.js + +install: node_modules + +clean: + @rm -rf dist + +dist: + @mkdir -p $@ + +dist/debug.js: node_modules browser.js debug.js dist + @$(BROWSERIFY) \ + --standalone debug \ + . > $@ + +distclean: clean + @rm -rf node_modules + +node_modules: package.json + @NODE_ENV= $(PKG) install + @touch node_modules + +.PHONY: all install clean distclean diff --git a/node_modules/debug/README.md b/node_modules/debug/README.md new file mode 100644 index 0000000..2c57ddf --- /dev/null +++ b/node_modules/debug/README.md @@ -0,0 +1,238 @@ +# debug +[![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) + +A tiny node.js debugging utility modelled after node core's debugging technique. + +**Discussion around the V3 API is under way [here](https://github.com/visionmedia/debug/issues/370)** + +## Installation + +```bash +$ npm install debug +``` + +## Usage + +`debug` exposes a function; simply pass this function the name of your module, and it will return a decorated version of `console.error` for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole. + +Example _app.js_: + +```js +var debug = require('debug')('http') + , http = require('http') + , name = 'My App'; + +// fake app + +debug('booting %s', name); + +http.createServer(function(req, res){ + debug(req.method + ' ' + req.url); + res.end('hello\n'); +}).listen(3000, function(){ + debug('listening'); +}); + +// fake worker of some kind + +require('./worker'); +``` + +Example _worker.js_: + +```js +var debug = require('debug')('worker'); + +setInterval(function(){ + debug('doing some work'); +}, 1000); +``` + + The __DEBUG__ environment variable is then used to enable these based on space or comma-delimited names. Here are some examples: + + ![debug http and worker](http://f.cl.ly/items/18471z1H402O24072r1J/Screenshot.png) + + ![debug worker](http://f.cl.ly/items/1X413v1a3M0d3C2c1E0i/Screenshot.png) + +#### Windows note + + On Windows the environment variable is set using the `set` command. + + ```cmd + set DEBUG=*,-not_this + ``` + + Note that PowerShell uses different syntax to set environment variables. + + ```cmd + $env:DEBUG = "*,-not_this" + ``` + +Then, run the program to be debugged as usual. + +## Millisecond diff + + When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. + + ![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) + + When stdout is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below: + + ![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) + +## Conventions + + If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". + +## Wildcards + + The `*` character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`. + + You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=*,-connect:*` would include all debuggers except those starting with "connect:". + +## Environment Variables + + When running through Node.js, you can set a few environment variables that will + change the behavior of the debug logging: + +| Name | Purpose | +|-----------|-------------------------------------------------| +| `DEBUG` | Enables/disabled specific debugging namespaces. | +| `DEBUG_COLORS`| Whether or not to use colors in the debug output. | +| `DEBUG_DEPTH` | Object inspection depth. | +| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. | + + + __Note:__ The environment variables beginning with `DEBUG_` end up being + converted into an Options object that gets used with `%o`/`%O` formatters. + See the Node.js documentation for + [`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options) + for the complete list. + +## Formatters + + + Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. Below are the officially supported formatters: + +| Formatter | Representation | +|-----------|----------------| +| `%O` | Pretty-print an Object on multiple lines. | +| `%o` | Pretty-print an Object all on a single line. | +| `%s` | String. | +| `%d` | Number (both integer and float). | +| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | +| `%%` | Single percent sign ('%'). This does not consume an argument. | + +### Custom formatters + + You can add custom formatters by extending the `debug.formatters` object. For example, if you wanted to add support for rendering a Buffer as hex with `%h`, you could do something like: + +```js +const createDebug = require('debug') +createDebug.formatters.h = (v) => { + return v.toString('hex') +} + +// …elsewhere +const debug = createDebug('foo') +debug('this is hex: %h', new Buffer('hello world')) +// foo this is hex: 68656c6c6f20776f726c6421 +0ms +``` + +## Browser support + You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify), + or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest), + if you don't want to build it yourself. + + Debug's enable state is currently persisted by `localStorage`. + Consider the situation shown below where you have `worker:a` and `worker:b`, + and wish to debug both. You can enable this using `localStorage.debug`: + +```js +localStorage.debug = 'worker:*' +``` + +And then refresh the page. + +```js +a = debug('worker:a'); +b = debug('worker:b'); + +setInterval(function(){ + a('doing some work'); +}, 1000); + +setInterval(function(){ + b('doing some work'); +}, 1200); +``` + +#### Web Inspector Colors + + Colors are also enabled on "Web Inspectors" that understand the `%c` formatting + option. These are WebKit web inspectors, Firefox ([since version + 31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) + and the Firebug plugin for Firefox (any version). + + Colored output looks something like: + + ![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png) + + +## Output streams + + By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method: + +Example _stdout.js_: + +```js +var debug = require('debug'); +var error = debug('app:error'); + +// by default stderr is used +error('goes to stderr!'); + +var log = debug('app:log'); +// set this namespace to log via console.log +log.log = console.log.bind(console); // don't forget to bind to console! +log('goes to stdout'); +error('still goes to stderr!'); + +// set all output to go via console.info +// overrides all per-namespace log settings +debug.log = console.info.bind(console); +error('now goes to stdout via console.info'); +log('still goes to stdout, but via console.info now'); +``` + + +## Authors + + - TJ Holowaychuk + - Nathan Rajlich + - Andrew Rhyne + +## License + +(The MIT License) + +Copyright (c) 2014-2016 TJ Holowaychuk <tj@vision-media.ca> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/debug/Readme.md b/node_modules/debug/Readme.md new file mode 100644 index 0000000..9e80851 --- /dev/null +++ b/node_modules/debug/Readme.md @@ -0,0 +1,199 @@ +# debug + + tiny node.js debugging utility modelled after node core's debugging technique. + +## Installation + +```bash +$ npm install debug +``` + +## Usage + + With `debug` you simply invoke the exported function to generate your debug function, passing it a name which will determine if a noop function is returned, or a decorated `console.error`, so all of the `console` [format string goodies](https://developer.chrome.com/devtools/docs/console-api#consolelogobject-object) you're used to work fine. A unique color is selected per-function for visibility. + +Example _app.js_: + +```js +var debug = require('debug')('http') + , http = require('http') + , name = 'My App'; + +// fake app + +debug('booting %s', name); + +http.createServer(function(req, res){ + debug(req.method + ' ' + req.url); + res.end('hello\n'); +}).listen(3000, function(){ + debug('listening'); +}); + +// fake worker of some kind + +require('./worker'); +``` + +Example _worker.js_: + +```js +var debug = require('debug')('worker'); + +setInterval(function(){ + debug('doing some work'); +}, 1000); +``` + + The __DEBUG__ environment variable is then used to enable these based on space or comma-delimited names. Here are some examples: + + ![debug http and worker](http://f.cl.ly/items/18471z1H402O24072r1J/Screenshot.png) + + ![debug worker](http://f.cl.ly/items/1X413v1a3M0d3C2c1E0i/Screenshot.png) + +#### Windows note + + On Windows the environment variable is set using the `set` command. + + ```cmd + set DEBUG=*,-not_this + ``` + + Note that PowerShell using different syntax to set environment variables. + + ```cmd + $env:DEBUG = "*,-not_this" + ``` + +Then, run the program to be debugged as usual. + +## Millisecond diff + + When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls. + + ![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png) + + When stdout is not a TTY, `Date#toUTCString()` is used, making it more useful for logging the debug information as shown below: + + ![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png) + +## Conventions + + If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". + +## Wildcards + + The `*` character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`. + + You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=*,-connect:*` would include all debuggers except those starting with "connect:". + +## Browser support + + Debug works in the browser as well, currently persisted by `localStorage`. Consider the situation shown below where you have `worker:a` and `worker:b`, and wish to debug both. You can enable this using `localStorage.debug`: + +```js +localStorage.debug = 'worker:*' +``` + +And then refresh the page. + +```js +a = debug('worker:a'); +b = debug('worker:b'); + +setInterval(function(){ + a('doing some work'); +}, 1000); + +setInterval(function(){ + b('doing some work'); +}, 1200); +``` + +#### Web Inspector Colors + + Colors are also enabled on "Web Inspectors" that understand the `%c` formatting + option. These are WebKit web inspectors, Firefox ([since version + 31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/)) + and the Firebug plugin for Firefox (any version). + + Colored output looks something like: + + ![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png) + +## Output streams + + +### stderr vs stdout + By default `debug` will log to stderr, however this can be changed by setting the environment variable `DEBUG_FD` to `1` for stdout and `2` for stderr (the default value). + +You can also set an alternative logging method per-namespace by overriding the `log` method on a per-namespace or globally: + +Example _stdout.js_: + +```js +var debug = require('debug'); +var error = debug('app:error'); + +// by default stderr is used +error('goes to stderr!'); + +var log = debug('app:log'); +// set this namespace to log via console.log +log.log = console.log.bind(console); // don't forget to bind to console! +log('goes to stdout'); +error('still goes to stderr!'); + +// set all output to go via console.info +// overrides all per-namespace log settings +debug.log = console.info.bind(console); +error('now goes to stdout via console.info'); +log('still goes to stdout, but via console.info now'); +``` + +### Save debug output to a file + +You can save all debug statements to a file by piping them. + +Example: + +```bash +$ DEBUG_FD=3 node your-app.js 3> whatever.log +``` + +### Terminal colors + + By default colors will only be used in a TTY. However this can be overridden by setting the environment variable `DEBUG_COLORS` to `1`. + + Note: Certain IDEs (such as WebStorm) don't support colors on stderr. In these cases you must set `DEBUG_COLORS` to `1` and additionally change `DEBUG_FD` to `1`. + +## Authors + + - TJ Holowaychuk + - Nathan Rajlich + - Andrew Rhyne + +## License + +(The MIT License) + +Copyright (c) 2014-2016 TJ Holowaychuk <tj@vision-media.ca> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/debug/bower.json b/node_modules/debug/bower.json new file mode 100644 index 0000000..7a1a5a8 --- /dev/null +++ b/node_modules/debug/bower.json @@ -0,0 +1,29 @@ +{ + "name": "visionmedia-debug", + "main": "dist/debug.js", + "homepage": "https://github.com/visionmedia/debug", + "authors": [ + "TJ Holowaychuk ", + "Nathan Rajlich (http://n8.io)", + "Andrew Rhyne " + ], + "description": "visionmedia-debug", + "moduleType": [ + "amd", + "es6", + "globals", + "node" + ], + "keywords": [ + "visionmedia", + "debug" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/node_modules/debug/browser.js b/node_modules/debug/browser.js new file mode 100644 index 0000000..095a045 --- /dev/null +++ b/node_modules/debug/browser.js @@ -0,0 +1,175 @@ + +/** + * This is the web browser implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = require('./debug'); +exports.log = log; +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; +exports.storage = 'undefined' != typeof chrome + && 'undefined' != typeof chrome.storage + ? chrome.storage.local + : localstorage(); + +/** + * Colors. + */ + +exports.colors = [ + 'lightseagreen', + 'forestgreen', + 'goldenrod', + 'dodgerblue', + 'darkorchid', + 'crimson' +]; + +/** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ + +function useColors() { + // is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + return (typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style) || + // is firebug? http://stackoverflow.com/a/398120/376773 + (window.console && (console.firebug || (console.exception && console.table))) || + // is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31); +} + +/** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + +exports.formatters.j = function(v) { + return JSON.stringify(v); +}; + + +/** + * Colorize log arguments if enabled. + * + * @api public + */ + +function formatArgs() { + var args = arguments; + var useColors = this.useColors; + + args[0] = (useColors ? '%c' : '') + + this.namespace + + (useColors ? ' %c' : ' ') + + args[0] + + (useColors ? '%c ' : ' ') + + '+' + exports.humanize(this.diff); + + if (!useColors) return args; + + var c = 'color: ' + this.color; + args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1)); + + // the final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + var index = 0; + var lastC = 0; + args[0].replace(/%[a-z%]/g, function(match) { + if ('%%' === match) return; + index++; + if ('%c' === match) { + // we only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + + args.splice(lastC, 0, c); + return args; +} + +/** + * Invokes `console.log()` when available. + * No-op when `console.log` is not a "function". + * + * @api public + */ + +function log() { + // this hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return 'object' === typeof console + && console.log + && Function.prototype.apply.call(console.log, console, arguments); +} + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + +function save(namespaces) { + try { + if (null == namespaces) { + exports.storage.removeItem('debug'); + } else { + exports.storage.debug = namespaces; + } + } catch(e) {} +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + +function load() { + var r; + try { + r = exports.storage.debug; + } catch(e) {} + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if ('env' in (typeof process === 'undefined' ? {} : process)) { + r = process.env.DEBUG; + } + + return r; +} + +/** + * Enable namespaces listed in `localStorage.debug` initially. + */ + +exports.enable(load()); + +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + +function localstorage(){ + try { + return window.localStorage; + } catch (e) {} +} diff --git a/node_modules/debug/component.json b/node_modules/debug/component.json new file mode 100644 index 0000000..eb399b7 --- /dev/null +++ b/node_modules/debug/component.json @@ -0,0 +1,19 @@ +{ + "name": "debug", + "repo": "visionmedia/debug", + "description": "small debugging utility", + "version": "2.3.2", + "keywords": [ + "debug", + "log", + "debugger" + ], + "main": "browser.js", + "scripts": [ + "browser.js", + "debug.js" + ], + "dependencies": { + "rauchg/ms.js": "0.7.1" + } +} diff --git a/node_modules/debug/debug.js b/node_modules/debug/debug.js new file mode 100644 index 0000000..a5992a4 --- /dev/null +++ b/node_modules/debug/debug.js @@ -0,0 +1,200 @@ + +/** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = debug.debug = debug; +exports.coerce = coerce; +exports.disable = disable; +exports.enable = enable; +exports.enabled = enabled; +exports.humanize = require('ms'); + +/** + * The currently active debug mode names, and names to skip. + */ + +exports.names = []; +exports.skips = []; + +/** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lowercased letter, i.e. "n". + */ + +exports.formatters = {}; + +/** + * Previously assigned color. + */ + +var prevColor = 0; + +/** + * Previous log timestamp. + */ + +var prevTime; + +/** + * Select a color. + * + * @return {Number} + * @api private + */ + +function selectColor() { + return exports.colors[prevColor++ % exports.colors.length]; +} + +/** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ + +function debug(namespace) { + + // define the `disabled` version + function disabled() { + } + disabled.enabled = false; + + // define the `enabled` version + function enabled() { + + var self = enabled; + + // set `diff` timestamp + var curr = +new Date(); + var ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + + // add the `color` if not set + if (null == self.useColors) self.useColors = exports.useColors(); + if (null == self.color && self.useColors) self.color = selectColor(); + + var args = new Array(arguments.length); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i]; + } + + args[0] = exports.coerce(args[0]); + + if ('string' !== typeof args[0]) { + // anything else let's inspect with %o + args = ['%o'].concat(args); + } + + // apply any `formatters` transformations + var index = 0; + args[0] = args[0].replace(/%([a-z%])/g, function(match, format) { + // if we encounter an escaped % then don't increase the array index + if (match === '%%') return match; + index++; + var formatter = exports.formatters[format]; + if ('function' === typeof formatter) { + var val = args[index]; + match = formatter.call(self, val); + + // now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + + // apply env-specific formatting + args = exports.formatArgs.apply(self, args); + + var logFn = enabled.log || exports.log || console.log.bind(console); + logFn.apply(self, args); + } + enabled.enabled = true; + + var fn = exports.enabled(namespace) ? enabled : disabled; + + fn.namespace = namespace; + + return fn; +} + +/** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + +function enable(namespaces) { + exports.save(namespaces); + + var split = (namespaces || '').split(/[\s,]+/); + var len = split.length; + + for (var i = 0; i < len; i++) { + if (!split[i]) continue; // ignore empty strings + namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?'); + if (namespaces[0] === '-') { + exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + exports.names.push(new RegExp('^' + namespaces + '$')); + } + } +} + +/** + * Disable debug output. + * + * @api public + */ + +function disable() { + exports.enable(''); +} + +/** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + +function enabled(name) { + var i, len; + for (i = 0, len = exports.skips.length; i < len; i++) { + if (exports.skips[i].test(name)) { + return false; + } + } + for (i = 0, len = exports.names.length; i < len; i++) { + if (exports.names[i].test(name)) { + return true; + } + } + return false; +} + +/** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ + +function coerce(val) { + if (val instanceof Error) return val.stack || val.message; + return val; +} diff --git a/node_modules/debug/index.js b/node_modules/debug/index.js new file mode 100644 index 0000000..8a39392 --- /dev/null +++ b/node_modules/debug/index.js @@ -0,0 +1,10 @@ +/** + * Detect Electron renderer process, which is node, but we should + * treat as a browser. + */ + +if ((typeof process === 'undefined' ? {} : process).type === 'renderer') { + module.exports = require('./browser.js'); +} else { + module.exports = require('./node.js'); +} diff --git a/node_modules/debug/karma.conf.js b/node_modules/debug/karma.conf.js new file mode 100644 index 0000000..103a82d --- /dev/null +++ b/node_modules/debug/karma.conf.js @@ -0,0 +1,70 @@ +// Karma configuration +// Generated on Fri Dec 16 2016 13:09:51 GMT+0000 (UTC) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha', 'chai', 'sinon'], + + + // list of files / patterns to load in the browser + files: [ + 'dist/debug.js', + 'test/*spec.js' + ], + + + // list of files to exclude + exclude: [ + 'src/node.js' + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/node_modules/debug/node.js b/node_modules/debug/node.js new file mode 100644 index 0000000..01e9fad --- /dev/null +++ b/node_modules/debug/node.js @@ -0,0 +1,213 @@ + +/** + * Module dependencies. + */ + +var tty = require('tty'); +var util = require('util'); + +/** + * This is the Node.js implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = require('./debug'); +exports.log = log; +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; + +/** + * Colors. + */ + +exports.colors = [6, 2, 3, 4, 5, 1]; + +/** + * The file descriptor to write the `debug()` calls to. + * Set the `DEBUG_FD` env variable to override with another value. i.e.: + * + * $ DEBUG_FD=3 node script.js 3>debug.log + */ + +var fd = parseInt(process.env.DEBUG_FD, 10) || 2; +var stream = 1 === fd ? process.stdout : + 2 === fd ? process.stderr : + createWritableStdioStream(fd); + +/** + * Is stdout a TTY? Colored output is enabled when `true`. + */ + +function useColors() { + var debugColors = (process.env.DEBUG_COLORS || '').trim().toLowerCase(); + if (0 === debugColors.length) { + return tty.isatty(fd); + } else { + return '0' !== debugColors + && 'no' !== debugColors + && 'false' !== debugColors + && 'disabled' !== debugColors; + } +} + +/** + * Map %o to `util.inspect()`, since Node doesn't do that out of the box. + */ + +var inspect = (4 === util.inspect.length ? + // node <= 0.8.x + function (v, colors) { + return util.inspect(v, void 0, void 0, colors); + } : + // node > 0.8.x + function (v, colors) { + return util.inspect(v, { colors: colors }); + } +); + +exports.formatters.o = exports.formatters.O = function(v) { + return inspect(v, this.useColors) + .replace(/\s*\n\s*/g, ' '); +}; + +/** + * Adds ANSI color escape codes if enabled. + * + * @api public + */ + +function formatArgs() { + var len = arguments.length; + var args = new Array(len); + var useColors = this.useColors; + var name = this.namespace; + for (var i = 0; i < len; i++) { + args[i] = arguments[i]; + } + + if (useColors) { + var c = this.color; + + args[0] = ' \u001b[3' + c + ';1m' + name + ' ' + + '\u001b[0m' + + args[0]; + args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); + } else { + args[0] = new Date().toUTCString() + + ' ' + name + ' ' + args[0]; + } + return args; +} + +/** + * Invokes `console.error()` with the specified arguments. + */ + +function log() { + return stream.write(util.format.apply(this, arguments) + '\n'); +} + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + +function save(namespaces) { + if (null == namespaces) { + // If you set a process.env field to null or undefined, it gets cast to the + // string 'null' or 'undefined'. Just delete instead. + delete process.env.DEBUG; + } else { + process.env.DEBUG = namespaces; + } +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + +function load() { + return process.env.DEBUG; +} + +/** + * Copied from `node/src/node.js`. + * + * XXX: It's lame that node doesn't expose this API out-of-the-box. It also + * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame. + */ + +function createWritableStdioStream (fd) { + var stream; + var tty_wrap = process.binding('tty_wrap'); + + // Note stream._type is used for test-module-load-list.js + + switch (tty_wrap.guessHandleType(fd)) { + case 'TTY': + stream = new tty.WriteStream(fd); + stream._type = 'tty'; + + // Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + case 'FILE': + var fs = require('fs'); + stream = new fs.SyncWriteStream(fd, { autoClose: false }); + stream._type = 'fs'; + break; + + case 'PIPE': + case 'TCP': + var net = require('net'); + stream = new net.Socket({ + fd: fd, + readable: false, + writable: true + }); + + // FIXME Should probably have an option in net.Socket to create a + // stream from an existing fd which is writable only. But for now + // we'll just add this hack and set the `readable` member to false. + // Test: ./node test/fixtures/echo.js < /etc/passwd + stream.readable = false; + stream.read = null; + stream._type = 'pipe'; + + // FIXME Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + default: + // Probably an error on in uv_guess_handle() + throw new Error('Implement me. Unknown stream file type!'); + } + + // For supporting legacy API we put the FD here. + stream.fd = fd; + + stream._isStdio = true; + + return stream; +} + +/** + * Enable namespaces listed in `process.env.DEBUG` initially. + */ + +exports.enable(load()); diff --git a/node_modules/debug/package.json b/node_modules/debug/package.json new file mode 100644 index 0000000..48e6da0 --- /dev/null +++ b/node_modules/debug/package.json @@ -0,0 +1,122 @@ +{ + "_args": [ + [ + { + "raw": "debug@^2.1.0", + "scope": null, + "escapedName": "debug", + "name": "debug", + "rawSpec": "^2.1.0", + "spec": ">=2.1.0 <3.0.0", + "type": "range" + }, + "/srv/demos/node_modules/dns-js" + ] + ], + "_from": "debug@>=2.1.0 <3.0.0", + "_id": "debug@2.3.2", + "_inCache": true, + "_location": "/debug", + "_nodeVersion": "7.0.0", + "_npmOperationalInternal": { + "host": "packages-18-east.internal.npmjs.com", + "tmp": "tmp/debug-2.3.2.tgz_1478759402178_0.8417916153557599" + }, + "_npmUser": { + "name": "tootallnate", + "email": "nathan@tootallnate.net" + }, + "_npmVersion": "3.10.8", + "_phantomChildren": {}, + "_requested": { + "raw": "debug@^2.1.0", + "scope": null, + "escapedName": "debug", + "name": "debug", + "rawSpec": "^2.1.0", + "spec": ">=2.1.0 <3.0.0", + "type": "range" + }, + "_requiredBy": [ + "/dns-js" + ], + "_resolved": "https://registry.npmjs.org/debug/-/debug-2.3.2.tgz", + "_shasum": "94cb466ef7d6d2c7e5245cdd6e4104f2d0d70d30", + "_shrinkwrap": null, + "_spec": "debug@^2.1.0", + "_where": "/srv/demos/node_modules/dns-js", + "author": { + "name": "TJ Holowaychuk", + "email": "tj@vision-media.ca" + }, + "browser": "./browser.js", + "bugs": { + "url": "https://github.com/visionmedia/debug/issues" + }, + "component": { + "scripts": { + "debug/index.js": "browser.js", + "debug/debug.js": "debug.js" + } + }, + "contributors": [ + { + "name": "Nathan Rajlich", + "email": "nathan@tootallnate.net", + "url": "http://n8.io" + }, + { + "name": "Andrew Rhyne", + "email": "rhyneandrew@gmail.com" + } + ], + "dependencies": { + "ms": "0.7.2" + }, + "description": "small debugging utility", + "devDependencies": { + "browserify": "9.0.3", + "mocha": "*" + }, + "directories": {}, + "dist": { + "shasum": "94cb466ef7d6d2c7e5245cdd6e4104f2d0d70d30", + "tarball": "https://registry.npmjs.org/debug/-/debug-2.3.2.tgz" + }, + "gitHead": "1c6f45840d0dba8cb14f9975b4633bb685fda400", + "homepage": "https://github.com/visionmedia/debug#readme", + "keywords": [ + "debug", + "log", + "debugger" + ], + "license": "MIT", + "main": "./index.js", + "maintainers": [ + { + "name": "kolban", + "email": "kolban1@kolban.com" + }, + { + "name": "thebigredgeek", + "email": "rhyneandrew@gmail.com" + }, + { + "name": "tjholowaychuk", + "email": "tj@vision-media.ca" + }, + { + "name": "tootallnate", + "email": "nathan@tootallnate.net" + } + ], + "name": "debug", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/visionmedia/debug.git" + }, + "scripts": {}, + "version": "2.3.2" +} diff --git a/node_modules/debug/src/browser.js b/node_modules/debug/src/browser.js new file mode 100644 index 0000000..38d6391 --- /dev/null +++ b/node_modules/debug/src/browser.js @@ -0,0 +1,182 @@ +/** + * This is the web browser implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = require('./debug'); +exports.log = log; +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; +exports.storage = 'undefined' != typeof chrome + && 'undefined' != typeof chrome.storage + ? chrome.storage.local + : localstorage(); + +/** + * Colors. + */ + +exports.colors = [ + 'lightseagreen', + 'forestgreen', + 'goldenrod', + 'dodgerblue', + 'darkorchid', + 'crimson' +]; + +/** + * Currently only WebKit-based Web Inspectors, Firefox >= v31, + * and the Firebug extension (any Firefox version) are known + * to support "%c" CSS customizations. + * + * TODO: add a `localStorage` variable to explicitly enable/disable colors + */ + +function useColors() { + // NB: In an Electron preload script, document will be defined but not fully + // initialized. Since we know we're in Chrome, we'll just detect this case + // explicitly + if (typeof window !== 'undefined' && window && typeof window.process !== 'undefined' && window.process.type === 'renderer') { + return true; + } + + // is webkit? http://stackoverflow.com/a/16459606/376773 + // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 + return (typeof document !== 'undefined' && document && 'WebkitAppearance' in document.documentElement.style) || + // is firebug? http://stackoverflow.com/a/398120/376773 + (typeof window !== 'undefined' && window && window.console && (console.firebug || (console.exception && console.table))) || + // is firefox >= v31? + // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages + (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || + // double check webkit in userAgent just in case we are in a worker + (typeof navigator !== 'undefined' && navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); +} + +/** + * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. + */ + +exports.formatters.j = function(v) { + try { + return JSON.stringify(v); + } catch (err) { + return '[UnexpectedJSONParseError]: ' + err.message; + } +}; + + +/** + * Colorize log arguments if enabled. + * + * @api public + */ + +function formatArgs(args) { + var useColors = this.useColors; + + args[0] = (useColors ? '%c' : '') + + this.namespace + + (useColors ? ' %c' : ' ') + + args[0] + + (useColors ? '%c ' : ' ') + + '+' + exports.humanize(this.diff); + + if (!useColors) return; + + var c = 'color: ' + this.color; + args.splice(1, 0, c, 'color: inherit') + + // the final "%c" is somewhat tricky, because there could be other + // arguments passed either before or after the %c, so we need to + // figure out the correct index to insert the CSS into + var index = 0; + var lastC = 0; + args[0].replace(/%[a-zA-Z%]/g, function(match) { + if ('%%' === match) return; + index++; + if ('%c' === match) { + // we only are interested in the *last* %c + // (the user may have provided their own) + lastC = index; + } + }); + + args.splice(lastC, 0, c); +} + +/** + * Invokes `console.log()` when available. + * No-op when `console.log` is not a "function". + * + * @api public + */ + +function log() { + // this hackery is required for IE8/9, where + // the `console.log` function doesn't have 'apply' + return 'object' === typeof console + && console.log + && Function.prototype.apply.call(console.log, console, arguments); +} + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + +function save(namespaces) { + try { + if (null == namespaces) { + exports.storage.removeItem('debug'); + } else { + exports.storage.debug = namespaces; + } + } catch(e) {} +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + +function load() { + try { + return exports.storage.debug; + } catch(e) {} + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if (typeof process !== 'undefined' && 'env' in process) { + return process.env.DEBUG; + } +} + +/** + * Enable namespaces listed in `localStorage.debug` initially. + */ + +exports.enable(load()); + +/** + * Localstorage attempts to return the localstorage. + * + * This is necessary because safari throws + * when a user disables cookies/localstorage + * and you attempt to access it. + * + * @return {LocalStorage} + * @api private + */ + +function localstorage() { + try { + return window.localStorage; + } catch (e) {} +} diff --git a/node_modules/debug/src/debug.js b/node_modules/debug/src/debug.js new file mode 100644 index 0000000..4d3c7f2 --- /dev/null +++ b/node_modules/debug/src/debug.js @@ -0,0 +1,199 @@ + +/** + * This is the common logic for both the Node.js and web browser + * implementations of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = createDebug.debug = createDebug.default = createDebug; +exports.coerce = coerce; +exports.disable = disable; +exports.enable = enable; +exports.enabled = enabled; +exports.humanize = require('ms'); + +/** + * The currently active debug mode names, and names to skip. + */ + +exports.names = []; +exports.skips = []; + +/** + * Map of special "%n" handling functions, for the debug "format" argument. + * + * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". + */ + +exports.formatters = {}; + +/** + * Previous log timestamp. + */ + +var prevTime; + +/** + * Select a color. + * @param {String} namespace + * @return {Number} + * @api private + */ + +function selectColor(namespace) { + var hash = 0, i; + + for (i in namespace) { + hash = ((hash << 5) - hash) + namespace.charCodeAt(i); + hash |= 0; // Convert to 32bit integer + } + + return exports.colors[Math.abs(hash) % exports.colors.length]; +} + +/** + * Create a debugger with the given `namespace`. + * + * @param {String} namespace + * @return {Function} + * @api public + */ + +function createDebug(namespace) { + + function debug() { + // disabled? + if (!debug.enabled) return; + + var self = debug; + + // set `diff` timestamp + var curr = +new Date(); + var ms = curr - (prevTime || curr); + self.diff = ms; + self.prev = prevTime; + self.curr = curr; + prevTime = curr; + + // turn the `arguments` into a proper Array + var args = new Array(arguments.length); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i]; + } + + args[0] = exports.coerce(args[0]); + + if ('string' !== typeof args[0]) { + // anything else let's inspect with %O + args.unshift('%O'); + } + + // apply any `formatters` transformations + var index = 0; + args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) { + // if we encounter an escaped % then don't increase the array index + if (match === '%%') return match; + index++; + var formatter = exports.formatters[format]; + if ('function' === typeof formatter) { + var val = args[index]; + match = formatter.call(self, val); + + // now we need to remove `args[index]` since it's inlined in the `format` + args.splice(index, 1); + index--; + } + return match; + }); + + // apply env-specific formatting (colors, etc.) + exports.formatArgs.call(self, args); + + var logFn = debug.log || exports.log || console.log.bind(console); + logFn.apply(self, args); + } + + debug.namespace = namespace; + debug.enabled = exports.enabled(namespace); + debug.useColors = exports.useColors(); + debug.color = selectColor(namespace); + + // env-specific initialization logic for debug instances + if ('function' === typeof exports.init) { + exports.init(debug); + } + + return debug; +} + +/** + * Enables a debug mode by namespaces. This can include modes + * separated by a colon and wildcards. + * + * @param {String} namespaces + * @api public + */ + +function enable(namespaces) { + exports.save(namespaces); + + var split = (namespaces || '').split(/[\s,]+/); + var len = split.length; + + for (var i = 0; i < len; i++) { + if (!split[i]) continue; // ignore empty strings + namespaces = split[i].replace(/\*/g, '.*?'); + if (namespaces[0] === '-') { + exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$')); + } else { + exports.names.push(new RegExp('^' + namespaces + '$')); + } + } +} + +/** + * Disable debug output. + * + * @api public + */ + +function disable() { + exports.enable(''); +} + +/** + * Returns true if the given mode name is enabled, false otherwise. + * + * @param {String} name + * @return {Boolean} + * @api public + */ + +function enabled(name) { + var i, len; + for (i = 0, len = exports.skips.length; i < len; i++) { + if (exports.skips[i].test(name)) { + return false; + } + } + for (i = 0, len = exports.names.length; i < len; i++) { + if (exports.names[i].test(name)) { + return true; + } + } + return false; +} + +/** + * Coerce `val`. + * + * @param {Mixed} val + * @return {Mixed} + * @api private + */ + +function coerce(val) { + if (val instanceof Error) return val.stack || val.message; + return val; +} diff --git a/node_modules/debug/src/index.js b/node_modules/debug/src/index.js new file mode 100644 index 0000000..e12cf4d --- /dev/null +++ b/node_modules/debug/src/index.js @@ -0,0 +1,10 @@ +/** + * Detect Electron renderer process, which is node, but we should + * treat as a browser. + */ + +if (typeof process !== 'undefined' && process.type === 'renderer') { + module.exports = require('./browser.js'); +} else { + module.exports = require('./node.js'); +} diff --git a/node_modules/debug/src/node.js b/node_modules/debug/src/node.js new file mode 100644 index 0000000..ea6a896 --- /dev/null +++ b/node_modules/debug/src/node.js @@ -0,0 +1,240 @@ +/** + * Module dependencies. + */ + +var tty = require('tty'); +var util = require('util'); + +/** + * This is the Node.js implementation of `debug()`. + * + * Expose `debug()` as the module. + */ + +exports = module.exports = require('./debug'); +exports.init = init; +exports.log = log; +exports.formatArgs = formatArgs; +exports.save = save; +exports.load = load; +exports.useColors = useColors; + +/** + * Colors. + */ + +exports.colors = [6, 2, 3, 4, 5, 1]; + +/** + * Build up the default `inspectOpts` object from the environment variables. + * + * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js + */ + +exports.inspectOpts = Object.keys(process.env).filter(function (key) { + return /^debug_/i.test(key); +}).reduce(function (obj, key) { + // camel-case + var prop = key + .substring(6) + .toLowerCase() + .replace(/_([a-z])/, function (_, k) { return k.toUpperCase() }); + + // coerce string value into JS value + var val = process.env[key]; + if (/^(yes|on|true|enabled)$/i.test(val)) val = true; + else if (/^(no|off|false|disabled)$/i.test(val)) val = false; + else if (val === 'null') val = null; + else val = Number(val); + + obj[prop] = val; + return obj; +}, {}); + +/** + * The file descriptor to write the `debug()` calls to. + * Set the `DEBUG_FD` env variable to override with another value. i.e.: + * + * $ DEBUG_FD=3 node script.js 3>debug.log + */ + +if ('DEBUG_FD' in process.env) { + util.deprecate(function(){}, '`DEBUG_FD` is deprecated. Override `debug.log` if you want to use a different log function (https://git.io/vMUyr)')() +} + +var fd = parseInt(process.env.DEBUG_FD, 10) || 2; +var stream = 1 === fd ? process.stdout : + 2 === fd ? process.stderr : + createWritableStdioStream(fd); + +/** + * Is stdout a TTY? Colored output is enabled when `true`. + */ + +function useColors() { + return 'colors' in exports.inspectOpts + ? Boolean(exports.inspectOpts.colors) + : tty.isatty(fd); +} + +/** + * Map %o to `util.inspect()`, all on a single line. + */ + +exports.formatters.o = function(v) { + this.inspectOpts.colors = this.useColors; + return util.inspect(v, this.inspectOpts) + .replace(/\s*\n\s*/g, ' '); +}; + +/** + * Map %o to `util.inspect()`, allowing multiple lines if needed. + */ + +exports.formatters.O = function(v) { + this.inspectOpts.colors = this.useColors; + return util.inspect(v, this.inspectOpts); +}; + +/** + * Adds ANSI color escape codes if enabled. + * + * @api public + */ + +function formatArgs(args) { + var name = this.namespace; + var useColors = this.useColors; + + if (useColors) { + var c = this.color; + var prefix = ' \u001b[3' + c + ';1m' + name + ' ' + '\u001b[0m'; + + args[0] = prefix + args[0].split('\n').join('\n' + prefix); + args.push('\u001b[3' + c + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); + } else { + args[0] = new Date().toUTCString() + + ' ' + name + ' ' + args[0]; + } +} + +/** + * Invokes `util.format()` with the specified arguments and writes to `stream`. + */ + +function log() { + return stream.write(util.format.apply(util, arguments) + '\n'); +} + +/** + * Save `namespaces`. + * + * @param {String} namespaces + * @api private + */ + +function save(namespaces) { + if (null == namespaces) { + // If you set a process.env field to null or undefined, it gets cast to the + // string 'null' or 'undefined'. Just delete instead. + delete process.env.DEBUG; + } else { + process.env.DEBUG = namespaces; + } +} + +/** + * Load `namespaces`. + * + * @return {String} returns the previously persisted debug modes + * @api private + */ + +function load() { + return process.env.DEBUG; +} + +/** + * Copied from `node/src/node.js`. + * + * XXX: It's lame that node doesn't expose this API out-of-the-box. It also + * relies on the undocumented `tty_wrap.guessHandleType()` which is also lame. + */ + +function createWritableStdioStream (fd) { + var stream; + var tty_wrap = process.binding('tty_wrap'); + + // Note stream._type is used for test-module-load-list.js + + switch (tty_wrap.guessHandleType(fd)) { + case 'TTY': + stream = new tty.WriteStream(fd); + stream._type = 'tty'; + + // Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + case 'FILE': + var fs = require('fs'); + stream = new fs.SyncWriteStream(fd, { autoClose: false }); + stream._type = 'fs'; + break; + + case 'PIPE': + case 'TCP': + var net = require('net'); + stream = new net.Socket({ + fd: fd, + readable: false, + writable: true + }); + + // FIXME Should probably have an option in net.Socket to create a + // stream from an existing fd which is writable only. But for now + // we'll just add this hack and set the `readable` member to false. + // Test: ./node test/fixtures/echo.js < /etc/passwd + stream.readable = false; + stream.read = null; + stream._type = 'pipe'; + + // FIXME Hack to have stream not keep the event loop alive. + // See https://github.com/joyent/node/issues/1726 + if (stream._handle && stream._handle.unref) { + stream._handle.unref(); + } + break; + + default: + // Probably an error on in uv_guess_handle() + throw new Error('Implement me. Unknown stream file type!'); + } + + // For supporting legacy API we put the FD here. + stream.fd = fd; + + stream._isStdio = true; + + return stream; +} + +/** + * Init logic for `debug` instances. + * + * Create a new `inspectOpts` object in case `useColors` is set + * differently for a particular `debug` instance. + */ + +function init (debug) { + debug.inspectOpts = util._extend({}, exports.inspectOpts); +} + +/** + * Enable namespaces listed in `process.env.DEBUG` initially. + */ + +exports.enable(load()); diff --git a/node_modules/dns-js/.eslintignore b/node_modules/dns-js/.eslintignore new file mode 100644 index 0000000..a24321e --- /dev/null +++ b/node_modules/dns-js/.eslintignore @@ -0,0 +1 @@ +test/fixtures/*.js \ No newline at end of file diff --git a/node_modules/dns-js/.eslintrc b/node_modules/dns-js/.eslintrc new file mode 100644 index 0000000..1238391 --- /dev/null +++ b/node_modules/dns-js/.eslintrc @@ -0,0 +1,23 @@ +{ + "env": { + "node": true + }, + "rules" : { + "brace-style": [2, "stroustrup", { "allowSingleLine": true }], + "camelcase": [0], + "curly": [2], + "eqeqeq": [2], + "indent": [2, 2, {"SwitchCase": 1}], + "max-len": [2, 120, 4, {"ignoreComments": true, "ignoreUrls": true}], + "no-console": [1], + "no-shadow": [1], + "no-trailing-spaces": [2], + "quotes": [2, "single"], + "semi": [2, "always"], + "space-after-keywords": [2, "always"], + "space-before-blocks": [2], + "space-infix-ops": [2], + "space-unary-ops": [2] + }, + "extends": "eslint:recommended" +} \ No newline at end of file diff --git a/node_modules/dns-js/.npmignore b/node_modules/dns-js/.npmignore new file mode 100644 index 0000000..1b1f386 --- /dev/null +++ b/node_modules/dns-js/.npmignore @@ -0,0 +1,4 @@ +node_modules/ + +private/ +*.log \ No newline at end of file diff --git a/node_modules/dns-js/.travis.yml b/node_modules/dns-js/.travis.yml new file mode 100644 index 0000000..958bf33 --- /dev/null +++ b/node_modules/dns-js/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: + - "4.1" diff --git a/node_modules/dns-js/LICENSE b/node_modules/dns-js/LICENSE new file mode 100644 index 0000000..cb77406 --- /dev/null +++ b/node_modules/dns-js/LICENSE @@ -0,0 +1,19 @@ +Copyright 2014-2016 Peter Magnusson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE diff --git a/node_modules/dns-js/README.md b/node_modules/dns-js/README.md new file mode 100644 index 0000000..9fe3f0d --- /dev/null +++ b/node_modules/dns-js/README.md @@ -0,0 +1,49 @@ +mdns-js-packet +============== + +[![Build Status](https://travis-ci.org/mdns-js/node-dns-js.svg?branch=master)](https://travis-ci.org/mdns-js/node-dns-js) + +DNS packet parser specifically built for mdns-js +[mdns-js](https://github.com/kmpm/node-mdns-js) +but it should be generic enough to do general dns stuff. + +NEW LOCATION + +This project was moved into it's own organisation. Please update any git remotes you might have pointing here. + + git remote set-url origin https://github.com/mdns-js/node-dns-js.git + + + +You probably want to have a look at +[native-dns-packet](https://github.com/tjfontaine/native-dns-packet) +first and if that does do what you need, you might start looking at this. + +mdns-js-packet should produce the same output as native-dns-packet, +it even uses it's test fixtures and borrows some parts of it. + +This was made before i knew about native-dns-packet but since that +still has some bugs in handling some mDNS packets I cant use it. + +example +------- + +```javascript +var dns = require('dns-js'); + +/*some code that will get you a dns message buffer*/ + +var result = dns.DNSPacket.parse(message); + +console.log(result); +``` + +Look at examples/dnsresolver.js for a more detailed example. + +Contribute +---------- +I will gladly accept any contributions as pull requests. +Just run __npm run lint__ on the code first so that the coding style +is kept somewhat consistent. +I miss doing this myself from time to time and I won't go ballistic if anyone +else forget but I would really appreciate it. diff --git a/node_modules/dns-js/doc/edns.md b/node_modules/dns-js/doc/edns.md new file mode 100644 index 0000000..31c3b49 --- /dev/null +++ b/node_modules/dns-js/doc/edns.md @@ -0,0 +1,49 @@ +EDNS +==== +Extension Mechanisms for DNS + +This document will give some hints to litterature about edns +and how it's done in this project. + +* https://tools.ietf.org/html/rfc6891 +* https://en.wikipedia.org/wiki/Extension_mechanisms_for_DNS + + + +OPT RR, 41/0x29 +--------------- +OPT RR MAY be placed anywhere in the additional data section, +it MUST be the only OPT RR in that message. + +###Wireformat +Wireformat is described in section 6.1.2 of RFC6891 + +Fixed part +``` ++------------+--------------+------------------------------+ +| Field Name | Field Type | Description | ++------------+--------------+------------------------------+ +| NAME | domain name | MUST be 0 (root domain) | +| TYPE | u_int16_t | OPT (41) | +| CLASS | u_int16_t | requestor's UDP payload size | +| TTL | u_int32_t | extended RCODE and flags | +| RDLEN | u_int16_t | length of all RDATA | +| RDATA | octet stream | {attribute,value} pairs | ++------------+--------------+------------------------------+ +``` + +Varable part +``` + +0 (MSB) +1 (LSB) + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +0: | OPTION-CODE | + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +2: | OPTION-LENGTH | + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +4: | | + / OPTION-DATA / + / / + +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ +``` + + diff --git a/node_modules/dns-js/doc/rcode.md b/node_modules/dns-js/doc/rcode.md new file mode 100644 index 0000000..f17a4a6 --- /dev/null +++ b/node_modules/dns-js/doc/rcode.md @@ -0,0 +1,35 @@ +RCODE +===== + +http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 + +|rcode | Name | Description | Reference | +|------------|------------|--------------------------------------|-----------------------| +| 0 | NoError | No Error | [RFC1035] | +| 1 | FormErr | Format Error | [RFC1035] | +| 2 | ServFail | Server Failure | [RFC1035] | +| 3 | NXDomain | Non-Existent Domain | [RFC1035] | +| 4 | NotImp | Not Implemented | [RFC1035] | +| 5 | Refused | Query Refused | [RFC1035] | +| 6 | YXDomain | Name Exists when it should not | [RFC2136][RFC6672] | +| 7 | YXRRSet | RR Set Exists when it should not | [RFC2136] | +| 8 | NXRRSet | RR Set that should exist does not | [RFC2136] | +| 9 | NotAuth | Server Not Authoritative for zone | [RFC2136] | +| 9 | NotAuth | Not Authorized | [RFC2845] | +| 10 | NotZone | Name not contained in zone | [RFC2136] | +| 11-15 | Unassigned | | | +| 16 | BADVERS | Bad OPT Version | [RFC6891] | +| 16 | BADSIG | TSIG Signature Failure | [RFC2845] | +| 17 | BADKEY | Key not recognized | [RFC2845] | +| 18 | BADTIME | Signature out of time window | [RFC2845] | +| 19 | BADMODE | Bad TKEY Mode | [RFC2930] | +| 20 | BADNAME | Duplicate key name | [RFC2930] | +| 21 | BADALG | Algorithm not supported | [RFC2930] | +| 22 | BADTRUNC | Bad Truncation | [RFC4635] | +| 23 | BADCOOKIE | Bad/missing server cookie* | | +| 24-3840 | Unassigned | | | +| 3841-4095 | Reserved | for Private Use | [RFC6895] | +| 4096-65534 | Unassigned | | | +| 65535 | Reserved | can be allocated by Standards Action | [RFC6895] | +------------------------------------------------------------------------------------------ +*TEMPORARY - registered 2015-07-26, expires 2016-07-26 [draft-ietf-dnsop-cookies] \ No newline at end of file diff --git a/node_modules/dns-js/doc/records.md b/node_modules/dns-js/doc/records.md new file mode 100644 index 0000000..7b42eca --- /dev/null +++ b/node_modules/dns-js/doc/records.md @@ -0,0 +1,58 @@ + +Record types +============ + +A usefull list of record types can be found at +https://en.wikipedia.org/wiki/List_of_DNS_record_types + +A - 1 +----- +``` +{ name: 'TV i Vardagsrummet.local', + type: 1, + class: 32769, + ttl: 120, + address: '192.168.1.89' } +``` + + +PTR - 12 +-------- +``` +{ name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 4500, + data: 'TV i Vardagsrummet._googlecast._tcp.local' } + +``` + + +SRV - 33 +-------- +``` +{ name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 33, + class: 32769, + ttl: 120, + priority: 0, + weight: 0, + port: 8009, + target: 'TV i Vardagsrummet.local' } +``` + + +TXT - 16 +------- +{ name: 'SkC$rm i GC$strummet._googlecast._tcp.local', + type: 16, + class: 32769, + ttl: 4500, + data: + [ 'id=c3cccef1d09583a377f9613567168f71', + 've=02', + 'md=Chromecast', + 'ic=/setup/icon.png', + 'fn=SkC$rm i GC$strummet', + 'ca=5', + 'st=0' ] } \ No newline at end of file diff --git a/node_modules/dns-js/examples/resolveaddress.js b/node_modules/dns-js/examples/resolveaddress.js new file mode 100644 index 0000000..ac8cde8 --- /dev/null +++ b/node_modules/dns-js/examples/resolveaddress.js @@ -0,0 +1,47 @@ +/*eslint no-console:0*/ +var dns = require('..'); +var dgram = require('dgram'); + +var DNSSERVER = '8.8.8.8'; + +resolveAddress('www.google.com'); + +function resolveAddress(name) { + var packet = new dns.DNSPacket(); + packet.header.rd = 1; //make query recursive + packet.question.push(new dns.DNSRecord( + name, + dns.DNSRecord.Type.A, 1) + ); + + var s = dgram.createSocket('udp4'); + s.bind(); + + s.on('listening', function () { + var buf = dns.DNSPacket.toBuffer(packet); + s.send(buf, 0, buf.length, 53, DNSSERVER, function (err, bytes) { + if (err) { + return console.error('error sending', err); + } + console.log('sent request of %d bytes', bytes); + }); + }); + + s.on('message', function (data) { + console.log('incoming response'); + var response = dns.DNSPacket.parse(data); + response.answer.forEach(function (a) { + console.log('answer type:%s, class:%s, name:%s', + a.typeName, a.className, a.name, a.address); + }); + s.close(); + }); + + s.on('end', function () { + console.log('connection closed'); + }); + + s.on('error', function (err) { + console.error('error', err); + }); +} diff --git a/node_modules/dns-js/examples/resolvename.js b/node_modules/dns-js/examples/resolvename.js new file mode 100644 index 0000000..3d4a2b3 --- /dev/null +++ b/node_modules/dns-js/examples/resolvename.js @@ -0,0 +1,64 @@ +/*eslint no-console:0*/ +var dns = require('..'); +var dgram = require('dgram'); + +var DNSSERVER = '8.8.8.8'; + +resolveName('140.211.167.51'); + +function resolveName(address) { + var packet = new dns.DNSPacket(); + packet.header.rd = 1; //make query recursive + packet.header.id = 4242; + var qname = address.split('.').reverse().join('.') + '.in-addr.arpa.'; + console.log('qname', qname); + packet.question.push(new dns.DNSRecord( + qname, + dns.DNSRecord.Type.PTR, 1) + ); + + var s = dgram.createSocket('udp4'); + s.bind(); + + s.on('listening', function () { + var buf = dns.DNSPacket.toBuffer(packet); + s.send(buf, 0, buf.length, 53, DNSSERVER, function (err, bytes) { + if (err) { + return console.error('error sending', err); + } + console.log('sent request of %d bytes', bytes); + }); + }); + + s.on('message', function (data) { + console.log('incoming response'); + + var response = dns.DNSPacket.parse(data); + if (response.header.rcode === 0) { + response.answer.forEach(function (a) { + console.log('answer type:%s, class:%s, name:%s, data: %s', + a.typeName, a.className, a.name, a.data); + console.log('IP %s have resolved to name %s', address, a.data); + }); + } + else { + console.log('Server responded with error'); + if (response.header.rcode === dns.DNSPacket.RCODE.NXDomain) { + console.log('No such name'); + } + else { + console.log('rcode', response.header.rcode); + } + } + + s.close(); + }); + + s.on('end', function () { + console.log('connection closed'); + }); + + s.on('error', function (err) { + console.error('error', err); + }); +} diff --git a/node_modules/dns-js/index.js b/node_modules/dns-js/index.js new file mode 100644 index 0000000..ce22d97 --- /dev/null +++ b/node_modules/dns-js/index.js @@ -0,0 +1,2 @@ + +module.exports = require('./lib'); diff --git a/node_modules/dns-js/lib/.dnspacket.js.swp b/node_modules/dns-js/lib/.dnspacket.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..d3e4ad089be37fa4d5d641d2d8e3a43c16a2881e GIT binary patch literal 16384 zcmeI2U2GiH6~`x`K)-+%TGWb4TpNX5e`MC{IK*+{D6YK@2K*6!Bv3apvpaX~f$_|G zX4b|ermX}m0Ra!Z(5jV6QQL<;AQ0+Hkt+It)T$pKQ65kQssO1~ix3~BMM0wfbH8?W zy&*w;YCD#G-krPW-h1x3=bn4+-7WVWo0w$#>;VgZpR=r2cRq0Jk)1oOA75lyHIE9< z{TDfLt<0ln^BfflakO4=`Dz#!g3#qltD#%>d0cRVc=v5_!S~Aaw&qlB=ZSq=eD01j ziOd3-1wMuaF0uCX7yGX1>|j@1zVI>XWuln{G7DrD$SjaqAhSSbfy@G#1u_f#FIXU{ z?X*6`Kz4%DV29!Yyq*O2sb{=of0+d`3uG3^ERb0svp{Bn%mSGOG7DrD$SjaqAhW=K zsRbO@vaW*eb94cK@Birz;F-%T>tRp<2f&xXm%xXYTGkox2koU|4EBONxC&efc7P8) zVOej0=fH2l&%uwt{U8RnfMIYD><5Ej0DK-?2;Rko&0FAQ@EhFRs=r>Ve%v9sV1n_ zj1$G2IgO@RH40am6DVP;(A^C!w+>j0P2D^et~y>Y#P;B6jz{a`j^_`t{$4zehtX;& ziiTK`o~A;)5AoF3YZ)!=+0p5-5*ubGEesIj<3Sw?;~#$evPA_Ecib@WH}SqipLs41 z60f@H1rt`ex0KhDl`!&>&6eUI-r!Ml z*&3`zO_0L6{>Vm&t8?uvMx*`W5O{Q6H@|1q67~--h=mKX7SLU zeke8`oW@&M`3=TgF{MsJAgs}xn@`rHXHokes*0|Ju~y(fVvM+XU3a3C(+o5DV=0^8 zQ46DlOj)f56*2hKfYi#Xz}QJtuOwlFRYD8J3wGChr^0P|FkZn{Lf?&H9nP>U6R|4A zVuA_9kFeN8!YWuzWlsHjRgb$Yj9APg&+)xGxhs8_%)Wss?vgwlTbLWKtY?_X zaoN)IuZ6>o(_E+z^ZHXB7umssY@mygNU`rDWcEs#{*RKmPRb0lm2s%2eNtkut%OSw zgIbq%B1wfr_G?wzi8!L4VxLx}os4u2YN}Y2a{I7&+YEj!5<+V1w7{iMBrG}1#ADMm zD9d`Tnv6)z1iVL0u#`Ap8D|ppuNQupmu>YbSz0j`&9q!(j5)qv3F|=ukD8pAT0-cW zo*i47oA_D@VLMMgSYL%l_&iunR#0S067Ku?t}dYz)_`e9E;+_>3jy4mR}${}o2=|D z!{MZ>i~fe#F4tz0UK~?kbrR-tCr(hv%9{y~?VM~US&7087Vr&*pC*P;Y)?9V6=9yc zax=)NyO`YSxrqElp})v7K~_jnbA;&_ubsTwl)TbVD?` zz1YAh*sJ%tl6o`>(X*Iq)kKp^59Lg+(#M6~+M1>ftOW9qktlLD8!jt@m~>EGMQd^X zHS~scejR87oU479EVaLxHKkP6gHDguL;*D2DxX^UqE)r>wU}v6ul*()tAIYtDBg>p zJ>I5Y+E3B5k)ddK=nxwqKW%A_$Ng!^ekr-Ptz`w_IMH7N@TWcP-+5uA1v;#=-;`WBI52QqCACRK3lL_M~ z7s1>#O(P{1BRAc&G*=p(N20kjH8NS6LyL=M4dzbRaDa-F1xvKwg62zTw2IifzWF%;j(e zQLT)S*vMh-;!b5{R27rVJW^65ElLjW>oKwxM1IyuqMdA&Bf)fK8cRC1ZeGI-mK55{ zjRR^&e68+9JfE`*vMdKYN-z!r61;rI1JcqC*ARj2d+J2)b}L+3f1|FOqgFX62JICuzb zfMZ|*41f=Cu74T403HJ&m;^__UT`_s0nXrz|4;B9cpBUfTyQmb184h3K@7UU`#96T z2p$D77zS5@zu{c}3iu;<7Ca12gKq&2mcT9GW-tuS;OzfAcnaJFw!jK-!5G*B`al8L zpc`BUevSKp?|>s<6m)_Pz`&ch3wRow2KRsva8Lp^p!a0A#4dVvN0gtPmT z;0dq=_Jbnm0@r{}@IL04&iDTS?*f|hx55A4pE&o)`w4S!@x2Pq_x0*$m82pPAmbI= zTI02m1Jfy2rJz1DB3a;W{oI z7RF|5eG`?MN`2U?l=I{<(r3wIJF1?K13x=;O1NjTS%Y7|b7iq~ExOduGjpPie;FT? zz39HSEva$Y)v~wFaTiff813r%s!1;-Qi`;|&7x9`)WLF8S5i5t6JwP!X2gk>aXJl> zc(Gsj3p15c9~H$%+{Yawra>KiTdGSL>fAJ`4^q^BzwDJr1fJ}2W?ZS9Qw9_ zF9f%T8-e!rUY27$`aw(ub-OK>v#~7s9n)34e7nTF?8fE7$wq=m3s?)VLib{?)agX8 zNu9b2Q~^7uzP+_;QJ92eVw-BKC;;uZC3G|5(At!lZJBnF;*IO8E1jm1=N@iN2<>@v zwZ#^dX6e*We8k|;%93Hw(t^~$o|E?mTiR%7L&h6Zu(;-)a)MJqe9DPV;5^#Rj_||; zC2^Z9SE61UG+S!tkRMP%(+QN}5}2Fgry{g)3-A}xlk9kK;#`L3ItH&$(l(p#= zGj%2v`;)mfA&1g6F%yeY7v;+E@pIn3klIFZO0t76VWsJDhHc6VD&Zi&tT7~4r*gFA@KRKYA&dT4Gd-L5%!Hg2w^I(Ef(;#eys8&NiJL!-0}C2Tir zD<w};F9Q3}DXjV{H()p)&`TGg)`l2@u~yW)b(7(7J9qUl9NUj#C} z223hPR-uC+&iP0oJapW5fL;&kaG>f^VNZ`9wd&g`huC=#bA*bzMpM#4*+;7$Y6z(u z0^LfV(p#fRTAEJFZT8EQuSn%^>o_C60;4PZk*T@krP*Hf< this.length) { + debug('bad packet', this.buffer.toString('hex')); + throw new Error(util.format('Cannot seek after EOF. %d > %d', + pos, this.length)); + } + this._offset = pos; + return this; +}; + +BufferConsumer.prototype.slice = function (length) { + var v; + if (typeof length === 'undefined') { + v = this.buffer.slice(this._offset); + this._offset = this.length - 1; + return v; + } + else { + if ((this._offset + length) > this.length) { + debug('Buffer owerflow. Slice beyond buffer.', { + offset: this._offset, + length: length, + bufferLength: this.length + }); + debug('so far', this); + throw new Error('Buffer overflow'); + } + v = this.buffer.slice(this._offset, this._offset + length); + this._offset += length; + return v; + } +}; + + +BufferConsumer.prototype.isEOF = function () { + return this._offset >= this.length; +}; + +BufferConsumer.prototype.byte = function () { + this._offset += 1; + return this.buffer.readUInt8(this._offset - 1); +}; + +BufferConsumer.prototype.short = function () { + debug('reading short at %d of %d', this._offset, this.length); + this._offset += 2; + return this.buffer.readUInt16BE(this._offset - 2); +}; + +BufferConsumer.prototype.long = function () { + this._offset += 4; + return this.buffer.readUInt32BE(this._offset - 4); +}; + +BufferConsumer.prototype.string = function (encoding, length) { + var end; + var ret; + + if (length === undefined) { + end = this.buffer.length; + } + else { + end = this.tell() + length; + // if (end > this.length) { + // throw new errors.MalformedPacket( + // 'Trying to read past eof. Start=%d, End=%s, Length=%s', + // this.tell(), end, this.length); + // } + } + + if (!encoding) { + encoding = 'utf8'; + } + ret = this.buffer.toString(encoding, this._offset, end); + debug('got a %s character string:', length, ret); + this.seek(end); + return ret; +}; + + +/** + * Consumes a DNS name, which will either finish with a NULL byte or a suffix + * reference (i.e., 0xc0 ). + */ +BufferConsumer.prototype.name = function (join, endAt) { + debug('.name(join:%s, endAt:%s)', join, endAt); + if (typeof join === 'undefined') { join = true; } + var parts = []; + var ret; + var len; + var pos; + var end; + var comp = false; + len = this.byte(); + debug('name initial len', len); + if (len === 0) { + parts.push(''); + } + while (len !== 0) { + if ((len & LABEL_POINTER) === LABEL_POINTER) { + debug('has label'); + len -= LABEL_POINTER; + len = len << 8; + pos = len + this.byte(); + if (!comp) { + end = this.tell(); + } + this.seek(pos); + len = this.byte(); + comp = true; + continue; + } + debug('no label'); + + // Otherwise, consume a string! + var v = this.string('utf8', len); + if (v.length > 0) { + parts.push(v); + } + + if (endAt && this.tell() >= endAt) { + debug('leaving at', endAt); + break; + } + len = this.byte(); + debug('got len', len); + } + if (!comp) { + end = this.tell(); + } + debug('ended with %d parts at %d', parts.length, end); + this.seek(end); + if (join) { + ret = parts.join('.'); + } + else { + ret = parts; + } + debug('ret', ret); + return ret; +}; + + diff --git a/node_modules/dns-js/lib/bufferwriter.js b/node_modules/dns-js/lib/bufferwriter.js new file mode 100644 index 0000000..92e6343 --- /dev/null +++ b/node_modules/dns-js/lib/bufferwriter.js @@ -0,0 +1,138 @@ +var debug = require('debug')('mdns-packet:lib:dns:bufferwriter'); +var util = require('util'); +var Qap = require('qap'); + +var BufferConsumer = require('./bufferconsumer'); +var BufferWriter = module.exports = function (size) { + this.buf = new Buffer(size || 512); + this.buf.fill(0); + this.offset = 0; +}; + +BufferWriter.prototype.tell = function () { + return this.offset; +}; + +BufferWriter.prototype.buffer = function (v) { + if (typeof v === 'undefined') { + return this; + } + if (v instanceof BufferWriter) { + v = v.dump(); + } + if (!(v instanceof Buffer)) { + throw new Error('VariableError: not a buffer'); + } + if (v.length > 0) { + v.copy(this.buf, this.offset); + this.offset += v.length; + } + return this; +}; + +//4 bytes +BufferWriter.prototype.long = function (v) { + this.buf.writeInt32BE(v, this.offset); + this.offset += 4; + return this; +}; + +//two bytes +BufferWriter.prototype.short = function (v) { + this.buf.writeUInt16BE(v & 0xFFFF, this.offset); + this.offset += 2; + return this; +}; + +BufferWriter.prototype.seek = function (pos) { + debug('seek(%d)', pos); + if (pos < 0) { + throw new Error('Negative pos not allowed'); + } + if (pos > this.buf.length) { + debug('bad packet', this.buffer.toString('hex')); + throw new Error(util.format('Cannot seek after EOF. %d > %d', + pos, this.buf.length)); + } + this.offset = pos; + return this; +}; + +BufferWriter.prototype.byte = function (v) { + this.buf.writeUInt8(v, this.offset); + this.offset += 1; + return this; +}; + +BufferWriter.prototype.slice = function (start, end) { + return this.buf.slice(start, end); +}; + +BufferWriter.prototype.indexOf = function (text) { + var qap = new Qap(text); + return qap.parse(this.buf); +}; + +/** + * Writes a DNS name. If ref is specified, will finish this name with a + * suffix reference (i.e., 0xc0 ). If not, then will terminate with a NULL + * byte. + */ +BufferWriter.prototype.name = function (v) { + var self = this; + debug('#name', v); + var ref; + var i; + var j; + var part; + var parts = v.split('.'); + var parts2 = v.split('.'); + var consumer = new BufferConsumer(self.buf); + var qap = new Qap(''); + var lastPart = parts.length; + if (v.length > 0) { + for (i = 0; i < parts.length; i++) { + if (parts[i].length === 0) { + lastPart = i; + continue; + } + part = new Buffer(parts[i]); + qap.set(Buffer.concat([ new Buffer([ part.length ]), part ])); + var location = qap.parse(self.buf)[0]; + if (location) { + var tr = consumer.seek(location).name(); + if (tr === parts2.join('.')) { + debug('found index: %s, from %s at %d', i, tr, location); + ref = location; + lastPart = i; + break; + } + } + parts2.shift(); + } + } + var out = new BufferWriter(); + debug('lastPart', lastPart, parts); + for (i = 0; i < lastPart; i++) { + part = new Buffer(parts[i]); + debug('writing part', part); + out.byte(part.length); + for (j = 0; j < part.length; ++j) { + out.byte(part[j]); + } + } + + if (ref) { + debug('writing a name ref to %d', ref); + out.byte(0xc0).byte(ref); + } + else { + out.byte(0); + } + this.buffer(out); + return this; +}; + +BufferWriter.prototype.dump = function () { + return this.slice(0, this.tell()); +}; diff --git a/node_modules/dns-js/lib/dnspacket.js b/node_modules/dns-js/lib/dnspacket.js new file mode 100644 index 0000000..a7ba91f --- /dev/null +++ b/node_modules/dns-js/lib/dnspacket.js @@ -0,0 +1,260 @@ +var debug = require('debug')('mdns-packet:lib:dns:dnspacket'); +var BufferWriter = require('./bufferwriter'); +var DataConsumer = require('./bufferconsumer'); +var DNSRecord = require('./dnsrecord'); +var errors = require('./errors'); + +var MIN_RECORD_SIZE = 5; +/** + * This callback is used for "each" methods + * @callback DNSPacket~eachCallback + * @param {DNSRecord} rec - DNSRecord that was found + */ + +var SECTION_NAMES = [ + 'answer', + 'authority', + 'additional' +]; +var ALL_SECTION_NAMES = ['question'].concat(SECTION_NAMES); + +function parseFlags(val, packet) { + packet.header.qr = (val & 0x8000) >> 15; + packet.header.opcode = (val & 0x7800) >> 11; + packet.header.aa = (val & 0x400) >> 10; + packet.header.tc = (val & 0x200) >> 9; + packet.header.rd = (val & 0x100) >> 8; + packet.header.ra = (val & 0x80) >> 7; + packet.header.res1 = (val & 0x40) >> 6; + packet.header.res2 = (val & 0x20) >> 5; + packet.header.res3 = (val & 0x10) >> 4; + packet.header.rcode = (val & 0xF); +} + +function parseHeader(consumer, packet) { + packet.header.id = consumer.short(); + parseFlags(consumer.short(), packet); + + packet.question = new Array(consumer.short()); + packet.answer = new Array(consumer.short()); + packet.authority = new Array(consumer.short()); + packet.additional = new Array(consumer.short()); + debug('packet.header:', packet.header); + debug('question: %d, answer: %d, authority: %d, additional: %d', + packet.question.length, packet.answer.length, packet.authority.length, + packet.additional.length); + var allcount = packet.question.length + packet.answer.length + + packet.authority.length + packet.additional.length; + // allcount * MIN_RECORD_SIZE should be less then consumer.length - consumer.tell() + if (allcount * MIN_RECORD_SIZE > (consumer.length - consumer.tell())) { + throw new errors.MalformedPacket( + 'Unexpectedly big section count: %d. Missing at least %d bytes.', + allcount, + allcount * MIN_RECORD_SIZE - (consumer.length - consumer.tell())); + } +} + +function writeHeader(writer, packet) { + var header = packet.header; + writer.short(header.id); + var val = 0; + val += (header.qr << 15) & 0x8000; + val += (header.opcode << 11) & 0x7800; + val += (header.aa << 10) & 0x400; + val += (header.tc << 9) & 0x200; + val += (header.rd << 8) & 0x100; + val += (header.ra << 7) & 0x80; + val += (header.res1 << 6) & 0x40; + val += (header.res1 << 5) & 0x20; + val += (header.res1 << 4) & 0x10; + val += header.rcode & 0xF; + writer.short(val); +} + +/** + * DNSPacket holds the state of a DNS packet. It can be modified or serialized + * in-place. + * + * @constructor + */ +var DNSPacket = module.exports = function (flags) { + + this.header = { + id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 + }; + if (flags) { + parseFlags(flags, this); + } + this.question = []; + this.answer = []; + this.authority = []; + this.additional = []; + this.edns_options = []; + this.payload = undefined; + +}; + +/** +* Enum identifying DNSPacket flags +* @readonly +* @enum {number} +*/ +DNSPacket.Flag = { + RESPONSE: 0x8000, + AUTHORATIVE: 0x400, + TRUNCATED: 0x200, + RECURSION: 0x100 +}; + + +/** +* Enum identifying DNSPacket rcode flag values +* @readonly +* @enum {number} +*/ +DNSPacket.RCODE = { + NoError: 0, + FormErr: 1, + ServFail: 2, + NXDomain: 3 +}; + + +/** + * Parse a DNSPacket from an Buffer + * @param {Buffer} buffer - A Node.js Buffer instance + * @returns {DNSPacket} Instance of DNSPacket + */ +DNSPacket.parse = function (buffer) { + var consumer = new DataConsumer(buffer); + var packet = new DNSPacket(); + var receivedOpts = 0; + parseHeader(consumer, packet); + + // Parse the QUESTION section. + for (var qi = 0; qi < packet.question.length; qi++) { + debug('doing qd %s', qi); + try { + debug('before question', consumer.tell()); + var part = DNSRecord.parseQuestion(consumer); + packet.question[qi] = part; + } + catch (err) { + debug('consumer', consumer); + throw err; + } + } + + // Parse the ANSWER, AUTHORITY and ADDITIONAL sections. + SECTION_NAMES.forEach(function (sectionName) { + var section = packet[sectionName]; + debug('about to parse section %s', sectionName, section.length); + for (var si = 0; si < section.length; si++) { + debug('doing record %s/%s', si + 1, section.length, consumer.tell()); + var record = DNSRecord.parse(consumer); + debug('parsed type `%d` for section %s', record.type, sectionName); + if (record.type === DNSRecord.Type.OPT) { + if (receivedOpts++ >= 0) { + //TODO: does it only ever be in additonal. + if (sectionName === 'additional') { + packet.edns_version = record.opt.version; + packet.do = record.opt.do; + packet.payload = record.class; + } + } + else { + debug('more than 1 opts'. receivedOpts); + } + } + section[si] = record; + } + }); + + if (!consumer.isEOF()) { + debug('was not EOF on incoming packet. %d bytes in overflow', + consumer.length - consumer.tell()); + var multiple = [packet]; + multiple.push(DNSPacket.parse(consumer.slice())); + + return multiple; + } + debug('packet done', packet); + return packet; +}; + + +/** + * Get records from packet + * @param {DNSPacket.Section} section - record section [qd|an|ns|ar], + * @param {DNSRecord.Type} [filter] - DNSRecord.Type to filter on + * @param {DNSPacket~eachCallback} callback - Function callback + */ +DNSPacket.prototype.each = each; + + +function each(section /*[,filter], callback*/) { + if (ALL_SECTION_NAMES.indexOf(section) === -1) { + throw new Error('Unkown section, ' + section); + } + var filter = false; + var cb; + if (arguments.length === 2) { + cb = arguments[1]; + } + else { + filter = arguments[1]; + cb = arguments[2]; + if (typeof filter === 'undefined') { + throw new Error('Filter given but is undefined'); + } + } + this[section].forEach(function (rec) { + if (!filter || rec.type === filter) { + cb(rec); + } + }); +} + + +/** + * Serialize this DNSPacket into an Buffer for sending over UDP. + * @returns {Buffer} A Node.js Buffer + */ +DNSPacket.toBuffer = function (packet) { + var writer = new BufferWriter(); + var sections = ['question'].concat(SECTION_NAMES); + writeHeader(writer, packet); + + sections.forEach(function (sectionName) { + var section = packet[sectionName]; + debug('%d records in %s', section.length, sectionName); + writer.short(section.length); + }); + + var e = each.bind(packet); + + sections.forEach(function (sectionName) { + e(sectionName, function (rec) { + DNSRecord.write(writer, rec, true); + + if (sectionName !== 'question' && rec.isQD) { + throw new Error('unexpected QD record in non QD section.'); + } + }); + }); + + return writer.slice(0, writer.tell()); +}; + + + diff --git a/node_modules/dns-js/lib/dnsrecord.js b/node_modules/dns-js/lib/dnsrecord.js new file mode 100644 index 0000000..e8b9eae --- /dev/null +++ b/node_modules/dns-js/lib/dnsrecord.js @@ -0,0 +1,353 @@ +var debug = require('debug')('mdns-packet:lib:dns:dnsrecord'); + +var BufferConsumer = require('./bufferconsumer'); +var errors = require('./errors'); + +/** + * DNSRecord is a record inside a DNS packet; e.g. a QUESTION, or an ANSWER, + * AUTHORITY, or ADDITIONAL record. Note that QUESTION records are special, + * and do not have ttl or data. + * @class + * @param {string} name + * @param {number} type + * @param {number} cl - class + * @param {number} [optTTL] - time to live in seconds + */ +var DNSRecord = module.exports = function (name, type, cl, optTTL) { + var self = this; + this.name = name; + this.type = type; + this.class = cl; + + if (type === 0 || typeof type === 'undefined') { + throw new errors.MalformedPacket('Record.type is empty'); + } + + if (cl === 0) { + throw new errors.MalformedPacket('Record.class is empty'); + } + + this.ttl = (typeof optTTL !== 'undefined') ? optTTL : DNSRecord.TTL; + this.isQD = (arguments.length === 3); + debug('new DNSRecord', this); + + + this.__defineGetter__('typeName', function () { + return DNSRecord.TypeName[self.type]; + }); + + this.__defineGetter__('className', function () { + return DNSRecord.ClassName[self.class & 0x7fff]; + }); + + this.__defineGetter__('flag', function () { + return (self.class & 0x8000) >> 15; + }); +}; + +/** + * Enum for record type values + * @readonly + * @enum {number} + */ +DNSRecord.Type = { + A: 0x01, // 1 + NS: 0x02, //2 + CNAME: 0x05, //5 + SOA: 0x06, //6 + PTR: 0x0c, // 12 + MX: 0x0f, //15 + TXT: 0x10, // 16 + AAAA: 28, // 0x16 + SRV: 0x21, // 33 + OPT: 0x29, //41 RFC6981 -needed for EDNS + NSEC: 0x2f, //47 + TLSA: 0x34, //52 RFC6698 - associate TLS server certificate. + ANY: 0xff +}; + +/** +* Enum for record class values +* @readonly +* @enum {number} +*/ +DNSRecord.Class = { + IN: 0x01, + ANY: 0xff, + FLUSH: 0x8000, + IS_QM: 0x8000 +}; + + +DNSRecord.TTL = 3600; // one hour default TTL +DNSRecord.TypeName = {}; +DNSRecord.ClassName = {}; + +var typekey; + +for (typekey in DNSRecord.Type) { + if (DNSRecord.Type.hasOwnProperty(typekey)) { + DNSRecord.TypeName[DNSRecord.Type[typekey]] = typekey; + } +} + + +for (typekey in DNSRecord.Class) { + if (DNSRecord.Class.hasOwnProperty(typekey)) { + DNSRecord.ClassName[DNSRecord.Class[typekey]] = typekey; + } +} + + +DNSRecord.write = function (out, rec, withLength) { + withLength = withLength || false; + debug('#write() type: %s, flag:%d class:%s, withLength:%s', + rec.typeName, rec.flag, + rec.className, withLength); + if (rec.type === 0 || rec.class === 0) { + throw new Error('Bad record with empty type and/or class'); + } + //TODO:if outer and any string in data or name + // can be found there. Do a ref instead. + out.name(rec.name).short(rec.type).short(rec.class); + if (rec.isQD) { + return out; + } + + out.long(rec.ttl); + + var startPos = out.tell(); + out.short(0xffff); //reserve some length + + switch (rec.type) { + case DNSRecord.Type.A: + writeA(out, rec.address); + break; + case DNSRecord.Type.NS: + case DNSRecord.Type.CNAME: + case DNSRecord.Type.PTR: + out.name(rec.data); + break; + case DNSRecord.Type.MX: + //asMx(consumer, rec); + break; + case DNSRecord.Type.TXT: + for (var key in rec.data) { + if (rec.data.hasOwnProperty(key)) { + // properly encode this + out.name(key + '=' + rec.data[key]); + out.offset--; + } + } + break; + case DNSRecord.Type.AAAA: + //asAAAA(consumer, rec); + break; + case DNSRecord.Type.SRV: + out.short(rec.priority & 0xffff).short(rec.weight & 0xffff) + .short(rec.port & 0xffff).name(rec.target); + break; + case DNSRecord.Type.SOA: + out.name(rec.primary).name(rec.admin).long(rec.serial).long(rec.refresh) + .long(rec.retry).long(rec.expiration).long(rec.minimum); + break; + default: + debug('non implemented recordtype of ' + rec.type); + throw new Error('Not implemented recordtype'); + //this.data = new BufferConsumer(consumer.slice(dataSize)); + } + var endPos = out.tell(); + //update with correct size + var correctSize = endPos - startPos - 2; + debug('correct size=%s bytes', correctSize); + out.seek(startPos).short(correctSize).seek(endPos); + + return out; +}; + + + + +function writeA(out, ip) { + var parts = ip.split('.'); + for (var i = 0; i < 4; i++) { + out.byte(parts[i]); + } +} + +DNSRecord.parse = function (consumer) { + if (consumer instanceof Buffer) { + debug('making consumer out of buffer'); + consumer = new BufferConsumer(consumer); + consumer.seek(0); + } + + debug('#parse from %d', consumer.tell()); + var rec = new DNSRecord( + consumer.name(), + consumer.short(), // type + consumer.short(), // class + consumer.long() //ttlgf + ); + + debug('parsing from %d', consumer.tell()); + + var dataSize = consumer.short(); + debug('going for type %s. start: %d, size: %d, end: %d, length: %d', + rec.type, + consumer.tell(), + dataSize, + consumer.tell() + dataSize, + consumer.length + ); + + + switch (rec.type) { + case DNSRecord.Type.A: + asA(consumer, rec); + break; + case DNSRecord.Type.NS: + case DNSRecord.Type.CNAME: + case DNSRecord.Type.PTR: + rec.data = asName(consumer); + break; + case DNSRecord.Type.MX: + asMx(consumer, rec); + break; + case DNSRecord.Type.TXT: + rec.data = asTxt(consumer, consumer.tell() + dataSize); + break; + case DNSRecord.Type.AAAA: + asAAAA(consumer, rec); + break; + case DNSRecord.Type.SRV: + asSrv(consumer, rec); + break; + case DNSRecord.Type.SOA: + asSoa(consumer, rec); + break; + case DNSRecord.Type.OPT: + asOpt(consumer, rec); + break; + case DNSRecord.Type.TLSA: + asTLSA(consumer, rec, dataSize); + break; + default: + debug('non implemented recordtype of ' + rec.type); + rec.data = new BufferConsumer(consumer.slice(dataSize)); + } + debug('record done at %d', consumer.tell(), rec); + return rec; +}; + +DNSRecord.parseQuestion = function (consumer) { + if (consumer instanceof Buffer) { + debug('making consumer out of buffer'); + consumer = new BufferConsumer(consumer); + } + debug('#parseQuestion from %d', consumer.tell()); + var r = new DNSRecord( + consumer.name(), + consumer.short(), // type + consumer.short() // class + ); + debug('record done at %d', consumer.tell(), r); + return r; +}; + + +function asName(consumer) { + return consumer.name(true); +} + + +function asSrv(consumer, record) { + debug('priority: %d', record.priority = consumer.short()); + debug('weight: %d', record.weight = consumer.short()); + debug('port: %d', record.port = consumer.short()); + record.target = consumer.name(); + // debug('priority:%d, weight: %d, port:%d, target:%s', record.priority, + // record.weight, record.port, record.target); + +} + +function asMx(consumer, record) { + record.priority = consumer.short(); + record.exchange = asName(consumer); +} + +function asTxt(consumer, endAt) { + var items = consumer.name(false, endAt); + debug('txt items', items); + //note:disable to have same syntax as native-dns-packet + // if (items.length === 1 && items[0].length > 0) { + // return items[0]; + // } + return items; +} + + +function asA(consumer, record) { + var data = ''; + for (var i = 0; i < 3; i++) { + data += consumer.byte() + '.'; + } + data += consumer.byte(); + record.address = data; +} + + +/* + * Parse data into a IPV6 address string + * @returns {string} + */ +function asAAAA(consumer, packet) { + var data = ''; + for (var i = 0; i < 7; i++) { + data += consumer.short().toString(16) + ':'; + } + data += consumer.short().toString(16); + packet.address = data; +} + +function asSoa(consumer, packet) { + packet.primary = consumer.name(true); + packet.admin = consumer.name(true); + packet.serial = consumer.long(); + packet.refresh = consumer.long(); + packet.retry = consumer.long(); + packet.expiration = consumer.long(); + packet.minimum = consumer.long(); +} + +function asOpt(consumer, packet) { + //if at end of buffer there is no optional data. + var opt = { + code: 0, + data: [], + rcode: 0, + version: 0, + do: 0, + z: 0 + }; + + if (!consumer.isEOF()) { + opt.code = consumer.short(); + opt.data = consumer.slice(consumer.short()); + } + + opt.rcode = (packet.ttl & 0xff000000) >> 24; + opt.version = (packet.ttl & 0x00FF0000) >> 16; + opt.do = (packet.ttl & 0x00008000) >> 15; + opt.z = (packet.ttl & 0x00001FFF); + + debug('asOpt', opt); + packet.opt = opt; +} + +function asTLSA(consumer, packet, dataSize) { + packet.usage = consumer.byte(); + packet.selector = consumer.byte(); + packet.matchingtype = consumer.byte(); + packet.buff = consumer.slice(dataSize - 3); //size - 3 because of 3 bytes above +} diff --git a/node_modules/dns-js/lib/errors.js b/node_modules/dns-js/lib/errors.js new file mode 100644 index 0000000..373aa0b --- /dev/null +++ b/node_modules/dns-js/lib/errors.js @@ -0,0 +1,11 @@ +var util = require('util'); + + +function MalformedPacket(/*message*/) { + Error.call(this); + this.message = util.format.apply(null, arguments); +} + +util.inherits(MalformedPacket, Error); + +module.exports.MalformedPacket = MalformedPacket; diff --git a/node_modules/dns-js/lib/index.js b/node_modules/dns-js/lib/index.js new file mode 100644 index 0000000..44c9d4f --- /dev/null +++ b/node_modules/dns-js/lib/index.js @@ -0,0 +1,8 @@ + + + +exports.DNSPacket = require('./dnspacket'); +exports.DNSRecord = require('./dnsrecord'); +exports.errors = require('./errors'); +exports.parse = exports.DNSPacket.parse; + diff --git a/node_modules/dns-js/package.json b/node_modules/dns-js/package.json new file mode 100644 index 0000000..c7d835f --- /dev/null +++ b/node_modules/dns-js/package.json @@ -0,0 +1,92 @@ +{ + "_args": [ + [ + { + "raw": "dns-js", + "scope": null, + "escapedName": "dns-js", + "name": "dns-js", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "/srv/demos" + ] + ], + "_from": "dns-js@latest", + "_id": "dns-js@0.2.1", + "_inCache": true, + "_location": "/dns-js", + "_nodeVersion": "4.2.2", + "_npmUser": { + "name": "kmpm", + "email": "peter@birchroad.net" + }, + "_npmVersion": "2.14.7", + "_phantomChildren": {}, + "_requested": { + "raw": "dns-js", + "scope": null, + "escapedName": "dns-js", + "name": "dns-js", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER" + ], + "_resolved": "https://registry.npmjs.org/dns-js/-/dns-js-0.2.1.tgz", + "_shasum": "5d66629b3c0e6a5eb0e14f0ae701d05f6ea46673", + "_shrinkwrap": null, + "_spec": "dns-js", + "_where": "/srv/demos", + "author": { + "name": "Peter Magnusson", + "email": "peter@birchroad.net" + }, + "bugs": { + "url": "https://github.com/mdns-js/node-dns-js/issues" + }, + "dependencies": { + "debug": "^2.1.0", + "qap": "^3.1.2" + }, + "description": "DNS Packet handling in pure javascript", + "devDependencies": { + "code": "*", + "eslint": "*", + "lab": "*", + "native-dns-packet": "0.1.1" + }, + "directories": {}, + "dist": { + "shasum": "5d66629b3c0e6a5eb0e14f0ae701d05f6ea46673", + "tarball": "https://registry.npmjs.org/dns-js/-/dns-js-0.2.1.tgz" + }, + "engines": { + "node": ">= 4.1.0" + }, + "gitHead": "ba92d56656a7671753153904bcba72458892b7d9", + "homepage": "https://github.com/mdns-js/node-dns-js", + "license": "MIT", + "main": "index.js", + "maintainers": [ + { + "name": "kmpm", + "email": "peter@birchroad.net" + } + ], + "name": "dns-js", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/mdns-js/node-dns-js.git" + }, + "scripts": { + "lint": "eslint .", + "test": "lab --coverage --flat" + }, + "version": "0.2.1" +} diff --git a/node_modules/dns-js/test/consumer.test.js b/node_modules/dns-js/test/consumer.test.js new file mode 100644 index 0000000..2baaecc --- /dev/null +++ b/node_modules/dns-js/test/consumer.test.js @@ -0,0 +1,83 @@ +var Code = require('code'); // assertion library +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var expect = Code.expect; + +var BufferConsumer = require('../lib/bufferconsumer'); +var BufferWriter = require('../lib/bufferwriter'); + + +describe('BufferConsumer', function () { + + it('throw if no buffer as argument', function (done) { + var throws = function () { + return (new BufferConsumer()); + }; + + expect(throws).to.throw(Error, 'Expected instance of Buffer'); + done(); + }); + + it('throw if seek before 0', function (done) { + var throws = function () { + var b = new Buffer(512); + var consumer = new BufferConsumer(b); + consumer.seek(-1); + }; + + expect(throws).to.throw(Error, 'Negative pos not allowed'); + done(); + }); + + it('throw if seek after end', function (done) { + var throws = function () { + var b = new Buffer(512); + var consumer = new BufferConsumer(b); + consumer.seek(515); + }; + + expect(throws).to.throw(Error, 'Cannot seek after EOF. 515 > 512'); + done(); + }); + + it('thow if slice after end', function (done) { + var throws = function () { + var b = new Buffer(512); + var consumer = new BufferConsumer(b); + consumer.seek(500); + consumer.slice(100); + }; + + expect(throws).to.throw(Error, 'Buffer overflow'); + done(); + }); + + it('#string with length', function (done) { + var b = new Buffer('qwertasdfg'); + var consumer = new BufferConsumer(b); + var s = consumer.string('utf8', 3); + expect(s).to.equal('qwe'); + s = consumer.string(); + expect(s).to.equal('rtasdfg'); + done(); + }); + +}); + + +describe('BufferWriter', function () { + it('#name on empty buffer', function (done) { + var out = new BufferWriter(); + out.name(''); + out.dump(); + var consumer = new BufferConsumer(out.dump()); + var s = consumer.name(); + expect(s).to.equal(''); + done(); + }); +}); diff --git a/node_modules/dns-js/test/fixtures/chromecast.bin b/node_modules/dns-js/test/fixtures/chromecast.bin new file mode 100644 index 0000000000000000000000000000000000000000..afefc39caf3c6a05f98a0d1e4945a32db9856356 GIT binary patch literal 259 zcmZQz00K@1CJ@CPpPrweo|BrKSX{yqUy@wFnvprN%4GPn!{ gE5L53EJzp7Sv(AkKu@h@U^<`y=dENA$F7M700LxF&Hw-a literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/chromecast.js b/node_modules/dns-js/test/fixtures/chromecast.js new file mode 100644 index 0000000..37ee552 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/chromecast.js @@ -0,0 +1,45 @@ +{ header: + { id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_googlecast._tcp.local', type: 12, class: 32769 }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 33, + class: 32769 }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 16, + class: 32769 }, + { name: 'Skärm i Gästrummet._googlecast._tcp.local', + type: 33, + class: 32769 }, + { name: 'Skärm i Gästrummet._googlecast._tcp.local', + type: 16, + class: 32769 }, + { name: 'TV i Vardagsrummet.local', type: 1, class: 32769 }, + { name: 'TV i Vardagsrummet.local', type: 28, class: 32769 }, + { name: 'Skärm i Gästrummet.local', type: 1, class: 32769 }, + { name: 'Skärm i Gästrummet.local', type: 28, class: 32769 } ], + answer: + [ { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 2477, + data: 'TV i Vardagsrummet._googlecast._tcp.local' }, + { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 2473, + data: 'Skärm i Gästrummet._googlecast._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/dns-resolvename.bin b/node_modules/dns-js/test/fixtures/dns-resolvename.bin new file mode 100644 index 0000000000000000000000000000000000000000..be5d4d64e755ffde918068f893ad744c4ba4eb73 GIT binary patch literal 38 kcmdN|#>l_`L?FOu0fFq9dAf-yDMc)aMFoir3_J{s0AtSv5&!@I literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/dns-resolvename.js b/node_modules/dns-js/test/fixtures/dns-resolvename.js new file mode 100644 index 0000000..896f69d --- /dev/null +++ b/node_modules/dns-js/test/fixtures/dns-resolvename.js @@ -0,0 +1,26 @@ +{ header: + { id: 10918, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '8.8.8.8.in-addr.arpa', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: [], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/dns-reverseresponse.bin b/node_modules/dns-js/test/fixtures/dns-reverseresponse.bin new file mode 100644 index 0000000000000000000000000000000000000000..234116ca7ad191954ee9591a4a05f08eb8d6e6e4 GIT binary patch literal 82 zcmdN|*4V(n2!ueuXaRxjnR&X2DJexPiA4p83=BLBj0bo?Bm+Z8JcEL8dVYR-PO5G} XX;MyRvTjOVv2G$8M2tB(KbHXjymb@6 literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/dns-reverseresponse.js b/node_modules/dns-js/test/fixtures/dns-reverseresponse.js new file mode 100644 index 0000000..9d13667 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/dns-reverseresponse.js @@ -0,0 +1,35 @@ +{ header: + { id: 10918, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '8.8.8.8.in-addr.arpa', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: + [ { name: '8.8.8.8.in-addr.arpa', + type: 12, + class: 1, + ttl: 21599, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: 'google-public-dns-a.google.com' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/dns-soa.bin b/node_modules/dns-js/test/fixtures/dns-soa.bin new file mode 100644 index 0000000000000000000000000000000000000000..783d65e3361830d0bf39c6a17a20d46b9cfc4955 GIT binary patch literal 82 zcmZQzXl!6$WMBYc=JN7#w)Fh`^qf@YHRilx!vg}GDS5@Z bi7C06c|bV{UZ7SP1qKFo4hEr8kTE&{j!6#F literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/dns-soa.js b/node_modules/dns-js/test/fixtures/dns-soa.js new file mode 100644 index 0000000..63eea79 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/dns-soa.js @@ -0,0 +1,41 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: 'www.google.com', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: [], + authority: + [ { name: 'google.com', + type: 6, + class: 1, + ttl: 59, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + primary: 'ns1.google.com', + admin: 'dns-admin.google.com', + serial: 1576192, + refresh: 7200, + retry: 1800, + expiration: 1209600, + minimum: 300 } ], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/exploits/zlip-1.bin b/node_modules/dns-js/test/fixtures/exploits/zlip-1.bin new file mode 100644 index 0000000000000000000000000000000000000000..a84dea6a802c462a5d3981ad9c0218c9904bc994 GIT binary patch literal 77 zcmZQbnDRPQpW%Ri_WTDN46Y0e_ST&Y3=V>A6=6UEh0rdk02mYT2iZL=U0ssgf6SM#T literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/exploits/zlip-3.bin b/node_modules/dns-js/test/fixtures/exploits/zlip-3.bin new file mode 100644 index 0000000000000000000000000000000000000000..156651f0d6ac3761815749e424a84a1423a40d5e GIT binary patch literal 147 zcmZQbnDRPQpW%Ri_WTDN46Y0et+t&E3=V=VMqCUGjFUoSB3Kw0Oc^*d(*K`k0Ez%H z5ZIMuWESV7rk3OvmlS2@rI%;si literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/malformed/mdns-unifi1.bin b/node_modules/dns-js/test/fixtures/malformed/mdns-unifi1.bin new file mode 100644 index 0000000000000000000000000000000000000000..32d6ba817eae0c1f552288230cc792e0217c0adf GIT binary patch literal 130 zcmZQzXkh>X77)Q2pHWg$z!G1QT)>)>pPZP(z`(=6$iToSz#uIVnwRO8soX77)Q2pHWg$z!G1QT)>)>pPZP(z`(=6$iToSz#z?$TUnf1RF+zVspx

aGq^KSb8_-+%kztJQVxUy NRY7cIsb^qd1OO~IC1wBs literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-_http.js b/node_modules/dns-js/test/fixtures/mdns-_http.js new file mode 100644 index 0000000..d55e77f --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-_http.js @@ -0,0 +1,41 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [], + answer: + [ { name: '_http._tcp.local', + type: 12, + class: 1, + ttl: 3600, + data: 'myserver._http._tcp.local' }, + { name: 'myserver._http._tcp.local', + type: 33, + class: 1, + ttl: 3600, + priority: 0, + weight: 0, + port: 8080, + target: 'myserver1.local' }, + { name: 'myserver._http._tcp.local', + type: 16, + class: 1, + ttl: 3600, + data: [ 'dept=deustotech', 'hello=world' ] }, + { name: 'myserver1.local', + type: 1, + class: 1, + ttl: 3600, + address: '127.0.0.1' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-additional-dottname1.bin b/node_modules/dns-js/test/fixtures/mdns-additional-dottname1.bin new file mode 100644 index 0000000000000000000000000000000000000000..1c9ef5604a3ce0e7f7daeaf6edd24199358883ea GIT binary patch literal 239 zcmYk$PYQxS6bA4o>BbDga2XNpbx?wx&vow`qJb0V$ z$9o^Z9l$aJFqximrSeiR+V%FSXN^-TMoRz>EbYCwQ7#1j{@kkS!@`~5tx}ctbPDSM zEDVFy!5x`ins`3MmrcP*l5v)%5>ts}!g(r_Euu*lbBr*Om^(K?P&}(R8L#*SBT*;% iYZDbr)nQZTfvo?)uZ_(p!FJaZq>tw5x3;Yx*7F5hUO#F8 literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-additional-dottname1.js b/node_modules/dns-js/test/fixtures/mdns-additional-dottname1.js new file mode 100644 index 0000000..10437e6 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-additional-dottname1.js @@ -0,0 +1,72 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: + [ { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: 'Chromecast.Bedroom._googlecast._tcp.local' } ], + authority: [], + additional: + [ { name: 'Chromecast.Bedroom._googlecast._tcp.local', + type: 33, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + priority: 0, + weight: 0, + port: 8009, + target: 'Chromecast.local' }, + { name: 'Chromecast.Bedroom._googlecast._tcp.local', + type: 16, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: + [ 'id=39dc44f5af0f3dd4f370a392d5050f5d', + 've=02', + 'md=Chromecast', + 'ic=/setup/icon.png', + 'fn=Chromecast.Bedroom', + 'ca=5', + 'st=0' ] }, + { name: 'Chromecast.local', + type: 1, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + address: '192.168.1.222' } ], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-googlecast-phone.bin b/node_modules/dns-js/test/fixtures/mdns-googlecast-phone.bin new file mode 100644 index 0000000000000000000000000000000000000000..e6fe451dbe615236456efab5bb20f4da2a022b29 GIT binary patch literal 304 zcmZusyAFat5L}Y85)&n%GDMBNyachh%F5o5SefJQKq7Di4r;%_ukbVYG{M-(7Q4x0 zW@iSV9|h2Grnf|hB;%CS65S*%Cz+rm15iQf)L{cGUZ882aGkD0QZbU$Rg>pjcIqey zn`f_q7M8>R)p?9$jDaf52W9W}*rp7}b{y?}*Y*z)XI|v7qvbNk@dKYw*A3{T<=Ap& vIm4%WCGu|rEv4A3xok=^rJ~rCMWV+A{?Cpm!5*q5w#Jeep!_XMj&S8j!)0ePtQqBPAo2Ai7!bmV9m)-PRwCo-~q`CPGJxg3JFulR0vBf zN=ZyFE-KB, + length: 9, + _offset: 0 } }, + { name: 'TV i Vardagsrummet.local', + type: 47, + class: 32769, + ttl: 120, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: { buffer: , length: 5, _offset: 0 } } ], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.bin new file mode 100644 index 0000000000000000000000000000000000000000..7bb74fb7ee3d119b4f8ce0a0ffe54609588b3124 GIT binary patch literal 124 zcmZQz00L$Z!NABHpIA_kld7AWpOlhX#u8tWT)>)>pPZP(z`(=6$YElZY-C_+V!{$% zT$;p(qSoku6i5kAd~r@{YJqM+QGP`wOMGcc!2x-YI0J(w>jDM_!6`rv3j+rO5UDd< G*#ZD6{~d$? literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.js b/node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.js new file mode 100644 index 0000000..9b70d24 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-apple-mobdev.js @@ -0,0 +1,57 @@ +{ header: + { id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_apple-mobdev._tcp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] }, + { name: '46c20544._sub._apple-mobdev2._tcp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] }, + { name: '_sleep-proxy._udp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: [], + authority: [], + additional: + [ { name: '', + type: 41, + class: 1440, + ttl: 4500, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + opt: + { code: 4, + data: , + rcode: 0, + version: 0, + do: 0, + z: 4500 } } ], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-appletv1.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-appletv1.bin new file mode 100644 index 0000000000000000000000000000000000000000..3496b9710e3996981d99e68785745e2e14bcb1a0 GIT binary patch literal 140 zcmZQz00JfmW;9?lXS8HYVl-h)WlUr=2J%yYq&b*nz-S2MHnG-NbjGBjY%%+pOwNhxAUEGkH3VEEs_cz_2=@-Q$0RaYHnG-NbjGBjY%%+pOwNhxAUEGkH3VEEs_cz_2=@-Q$0RaY{b2-QpCM_|lXD)|~w0#2f|&9tOq(JRlON rl#4-xC%!ztD7&~Mu_QA;k0rh&x!`~@k~|+bP;X{&Hqe;jj05ff;eHwL literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-linux_workstation.js b/node_modules/dns-js/test/fixtures/mdns-inbound-linux_workstation.js new file mode 100644 index 0000000..5368193 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-linux_workstation.js @@ -0,0 +1,28 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_services._dns-sd._udp.local', type: 12, class: 1 } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_workstation._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_udisks-ssh._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.bin new file mode 100644 index 0000000000000000000000000000000000000000..85f6a40a511f197da992da852a2a50dadbdfd528 GIT binary patch literal 194 zcmY+6K?=e!5JjiZYHNey1>CsKnT8>WPzcR1Q;XSqupG@6T%>>T7w>&Oz!#u_6Kok! zgRGMadPYC1Ro~*t>)RaxHvA)N{&6! eB%EX^SmC}yp~MIFpGL|Dd>xTqoYo-wH~s+d$u3C% literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.js b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.js new file mode 100644 index 0000000..cc9b40d --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0112.js @@ -0,0 +1,80 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_sleep-proxy._udp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_acp-sync._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_airport._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_raop._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_airplay._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_afpovertcp._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.bin new file mode 100644 index 0000000000000000000000000000000000000000..8561e19b8b945b56a84ad6964d24fa4817559bdd GIT binary patch literal 104 zcmZQzXklPrWME{b2-QpCM_|lXD)|~w0#2f|&9tOq(JRlON rl#4-xC%!ztD7&~Mu_QA;k0rh&x!`~@k~|+bP;X{&Hqe;jj05ff;eHwL literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.js b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.js new file mode 100644 index 0000000..2c9d7cc --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0300.js @@ -0,0 +1,44 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: [Getter], + className: [Getter], + flag: [Getter] } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_workstation._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + isQD: false, + typeName: [Getter], + className: [Getter], + flag: [Getter], + data: '_udisks-ssh._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0473.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0473.bin new file mode 100644 index 0000000000000000000000000000000000000000..bd8e84bad348dbf3b52ba701162bbb727fc23937 GIT binary patch literal 332 zcmZQzXkh>X79eKlj4w_tD$7hxEoP5T$t%_^PGN~JO(|f_$xlwqVPN24U}RtroWdZ? z9iLcGkds, length: 4, _offset: 0 } } ], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0758.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-pr20-l0758.bin new file mode 100644 index 0000000000000000000000000000000000000000..04332b4e7d175c75a331f2115957a8215b9171a7 GIT binary patch literal 198 zcmZQz00I^WW;9?lXS8HYVl-h)WlUr=2J%yYq&b*nz-S2MHnG-NbjGBjY%%+pOwNhxAUEGkH3VEEs_cz_2=@-Q$0RaYofE}QM8_0D? zF8#c5)SzAIO;+L8#(D{6TmUpwSr?V)9iAGukY?hMeOMK;iTQQ%AH8%v&GLq(Je(Ze bVc5!&OBdcK{BXRWw#JG7Sl>#$P@9JXmbonH literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample1.js b/node_modules/dns-js/test/fixtures/mdns-inbound-sample1.js new file mode 100644 index 0000000..83fe03c --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-sample1.js @@ -0,0 +1,48 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_services._dns-sd._udp.local', type: 12, class: 1 } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_workstation._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_udisks-ssh._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_owserver._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_ftp._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_http._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_owhttpd._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample2.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-sample2.bin new file mode 100644 index 0000000000000000000000000000000000000000..b66d7993b875136e84141a4530da2aafef8be7bc GIT binary patch literal 167 zcmY+4F%H5o5Ck`ptq`!N_yINV$TLpHHX{b2-QpCM_|lXD)|~w0#2f|&9tOq(JRlON ql#4-}KfWL(M>i$0B(b=pC^a#cCB7uN;D9oc5)Rh*jFOUq16}}>To`Qt literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample3.js b/node_modules/dns-js/test/fixtures/mdns-inbound-sample3.js new file mode 100644 index 0000000..25a1a8a --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-sample3.js @@ -0,0 +1,28 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_services._dns-sd._udp.local', type: 12, class: 1 } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_pdl-datastream._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_http._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample4.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-sample4.bin new file mode 100644 index 0000000000000000000000000000000000000000..8561e19b8b945b56a84ad6964d24fa4817559bdd GIT binary patch literal 104 zcmZQzXklPrWME{b2-QpCM_|lXD)|~w0#2f|&9tOq(JRlON rl#4-xC%!ztD7&~Mu_QA;k0rh&x!`~@k~|+bP;X{&Hqe;jj05ff;eHwL literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample4.js b/node_modules/dns-js/test/fixtures/mdns-inbound-sample4.js new file mode 100644 index 0000000..5368193 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-sample4.js @@ -0,0 +1,28 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_services._dns-sd._udp.local', type: 12, class: 1 } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_workstation._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_udisks-ssh._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample5.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-sample5.bin new file mode 100644 index 0000000000000000000000000000000000000000..14467f43557f99a4ff4f57d760004d44a12caaff GIT binary patch literal 136 zcmZQzXklPrWME+c0?zp2)S|M?{b2-QpCM_|lXD)|~w0#2f|&9tOq(JRlON zl#4-xC%!ztD7&~Mu_QA;k0rh&x!`~@k~}+0d|qkE0e2)J4%YaLl9B=xF`%;I+@u5U E07I!B*#H0l literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample5.js b/node_modules/dns-js/test/fixtures/mdns-inbound-sample5.js new file mode 100644 index 0000000..cef443c --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-sample5.js @@ -0,0 +1,38 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_services._dns-sd._udp.local', type: 12, class: 1 } ], + answer: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_workstation._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_nut._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_http._tcp.local' }, + { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 10, + data: '_smb._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample6.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-sample6.bin new file mode 100644 index 0000000000000000000000000000000000000000..0608eaeb750480f36b58e0598c6db3703ddcd179 GIT binary patch literal 200 zcmZ9E!3~2j5Cj*=;DG$31K!j@87E>Bfgsr8E=dC^%%#QTg?x{F%+4P01qx`StBI%M zz1WF0xt)7OP8*>2e+71T7d|(=?oh89*mM7&HMtqLC#^h zQY7OaU2P~qJyJx`oc!d(90mp+2F3$CAQGsAi-DabH8-i? z0M7wK21Te4FHnL(Iszgg1(XngO2ly%Wu(}e>KW*n3#X+fmXsEy7TX$B7#bKD7+I#J zNu{KgWhSR)rq~)9SeY1DxfxqInp>HprN%4GPn!{ gE5L53EJzp7Sv(AkKu@h@U^<`y=dENA$F7M700LxF&Hw-a literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-sample9.js b/node_modules/dns-js/test/fixtures/mdns-inbound-sample9.js new file mode 100644 index 0000000..37ee552 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-sample9.js @@ -0,0 +1,45 @@ +{ header: + { id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_googlecast._tcp.local', type: 12, class: 32769 }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 33, + class: 32769 }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 16, + class: 32769 }, + { name: 'Skärm i Gästrummet._googlecast._tcp.local', + type: 33, + class: 32769 }, + { name: 'Skärm i Gästrummet._googlecast._tcp.local', + type: 16, + class: 32769 }, + { name: 'TV i Vardagsrummet.local', type: 1, class: 32769 }, + { name: 'TV i Vardagsrummet.local', type: 28, class: 32769 }, + { name: 'Skärm i Gästrummet.local', type: 1, class: 32769 }, + { name: 'Skärm i Gästrummet.local', type: 28, class: 32769 } ], + answer: + [ { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 2477, + data: 'TV i Vardagsrummet._googlecast._tcp.local' }, + { name: '_googlecast._tcp.local', + type: 12, + class: 1, + ttl: 2473, + data: 'Skärm i Gästrummet._googlecast._tcp.local' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.bin new file mode 100644 index 0000000000000000000000000000000000000000..5aac54261ede6cf62ebca2f2a1c0083495ba5733 GIT binary patch literal 136 zcmZQzXklPrWME+c0-pHt{G#mQlEjkC{5+QUlH>x`oc!d(9H0yX;{hHJ2~@?!AR}3n znx2`b5N&K=WnyM!nP`<{WR+wABx4Wo957`NfU09;0CE(e96pc@44kZBtq0@|6ad8` L#<6gvFxUbBgS;8Z literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.js b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.js new file mode 100644 index 0000000..2fbed21 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation1.js @@ -0,0 +1,41 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_workstation._tcp.local', type: 12, class: 1 } ], + answer: + [ { name: '_workstation._tcp.local', + type: 12, + class: 1, + ttl: 10, + data: 'regin [30:46:9a:b2:b8:b2]._workstation._tcp.local' }, + { name: 'regin [30:46:9a:b2:b8:b2]._workstation._tcp.local', + type: 16, + class: 1, + ttl: 10, + data: [ '' ] }, + { name: 'regin [30:46:9a:b2:b8:b2]._workstation._tcp.local', + type: 33, + class: 1, + ttl: 10, + priority: 0, + weight: 0, + port: 9, + target: 'regin.local' }, + { name: 'regin.local', + type: 1, + class: 1, + ttl: 10, + address: '10.100.0.61' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.bin new file mode 100644 index 0000000000000000000000000000000000000000..bf514cd37a09061917d075e96ce0a25d6f191edb GIT binary patch literal 166 zcmZQzXklPrWME|g0-pHt{G#mQlEjkC{5+QUlH>x`oc!d(9H0yX;{hHJ2~@?!AS+dt zT3k|;sSs^sVU=uVWsz!SY+{uJWE;mG;5lH*AOKa!$N=OhLOJ{(D;PN0AbJnT9Vldw ffl3MdYXD0!XdUbO|IcK{VW1o%RE~u!g&`RLa=#-Z literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.js b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.js new file mode 100644 index 0000000..da03db5 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-tcp_workstation2.js @@ -0,0 +1,46 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '_workstation._tcp.local', type: 12, class: 1 } ], + answer: + [ { name: '_workstation._tcp.local', + type: 12, + class: 1, + ttl: 10, + data: 'vestri [28:c6:8e:34:b8:c3]._workstation._tcp.local' }, + { name: 'vestri [28:c6:8e:34:b8:c3]._workstation._tcp.local', + type: 16, + class: 1, + ttl: 10, + data: [ '' ] }, + { name: 'vestri [28:c6:8e:34:b8:c3]._workstation._tcp.local', + type: 33, + class: 1, + ttl: 10, + priority: 0, + weight: 0, + port: 9, + target: 'vestri.local' }, + { name: 'vestri.local', + type: 28, + class: 1, + ttl: 10, + address: 'fe80:0:0:0:2ac6:8eff:fe34:b8c3' }, + { name: 'vestri.local', + type: 1, + class: 1, + ttl: 10, + address: '10.100.0.99' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-type47.bin b/node_modules/dns-js/test/fixtures/mdns-inbound-type47.bin new file mode 100644 index 0000000000000000000000000000000000000000..c13effdfddf4d86edf0f34ad8492c00abd803cb7 GIT binary patch literal 146 zcmZQzXkh>XCJ+`12~)^a2umzVNlY&;D$UJJEn&^cPfpBXU|?)u1gfZDU^%dYF%pY9 z?)dcl{PdjE#qQ4hKx&0-QiLD+5CV Gg98ANZ6iDY literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-inbound-type47.js b/node_modules/dns-js/test/fixtures/mdns-inbound-type47.js new file mode 100644 index 0000000..022edea --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-inbound-type47.js @@ -0,0 +1,44 @@ +{ header: + { id: 0, + qr: 1, + opcode: 0, + aa: 1, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [], + answer: + [ { name: 'TV i Vardagsrummet.local', + type: 1, + class: 32769, + ttl: 120, + address: '192.168.1.89' }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 33, + class: 32769, + ttl: 120, + priority: 0, + weight: 0, + port: 8009, + target: 'TV i Vardagsrummet.local' } ], + authority: [], + additional: + [ { name: 'TV i Vardagsrummet.local', + type: 47, + class: 32769, + ttl: 120, + data: { buffer: , length: 5, _offset: 0 } }, + { name: 'TV i Vardagsrummet._googlecast._tcp.local', + type: 47, + class: 32769, + ttl: 120, + data: + { buffer: , + length: 9, + _offset: 0 } } ], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.bin b/node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.bin new file mode 100644 index 0000000000000000000000000000000000000000..8221eae080c00056a2baaa895b41ccc9ad2f3dd5 GIT binary patch literal 46 xcmZQz00Kr3!N9;7Uz}Q0mYJMd%pRYTSFBr{!V+JaQox#%pPZP(z`(=62ms5l3Pu0` literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.js b/node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.js new file mode 100644 index 0000000..06327f1 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/mdns-outbound-wildcard-query.js @@ -0,0 +1,26 @@ +{ header: + { id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 0, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: + [ { name: '_services._dns-sd._udp.local', + type: 12, + class: 1, + ttl: 3600, + isQD: true, + typeName: undefined, + className: undefined, + flag: undefined } ], + answer: [], + authority: [], + additional: [], + edns_options: [], + payload: undefined } \ No newline at end of file diff --git a/node_modules/dns-js/test/fixtures/mdns-readynas.bin b/node_modules/dns-js/test/fixtures/mdns-readynas.bin new file mode 100644 index 0000000000000000000000000000000000000000..1c848dfaf03a6946533ff0067971841b7d934d36 GIT binary patch literal 360 zcmZ9IK@Ng25JkrXL?S|>OP8*>2e+71T7d|(=?oh89*mM7&HMtqLC#^h zQY7OaU2P~qJyJb)7Zek2!ueuTwY$zmY1KBnpMo4UzEk literal 0 HcmV?d00001 diff --git a/node_modules/dns-js/test/fixtures/www.nodejs.org.cname.js b/node_modules/dns-js/test/fixtures/www.nodejs.org.cname.js new file mode 100644 index 0000000..07cd9c4 --- /dev/null +++ b/node_modules/dns-js/test/fixtures/www.nodejs.org.cname.js @@ -0,0 +1,23 @@ +{ header: + { id: 32764, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: 'www.nodejs.org', type: 5, class: 1 } ], + answer: + [ { name: 'www.nodejs.org', + type: 5, + class: 1, + ttl: 3600, + data: 'nodejs.org' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } diff --git a/node_modules/dns-js/test/helper.js b/node_modules/dns-js/test/helper.js new file mode 100644 index 0000000..906c62d --- /dev/null +++ b/node_modules/dns-js/test/helper.js @@ -0,0 +1,209 @@ +/*eslint no-console: 0*/ +var debug = require('debug')('mdns-packet:test:helper'); +var Code = require('code'); // assertion library +var expect = Code.expect; + +var fs = require('fs'); +var vm = require('vm'); +var util = require('util'); +var path = require('path'); + +var dns = require('../'); + + + +exports.createJs = function (obj) { + // var j = JSON.stringify(obj); + // obj = JSON.parse(j); + return util.inspect(obj, {depth: null}); +}; + +exports.writeBin = function (filename, buf) { + var ws = fs.createWriteStream(filename); + ws.write(buf); + ws.end(); +}; + +var writeJs = exports.writeJs = function (filename, obj) { + fs.writeFileSync(filename, exports.createJs(obj)); +}; + + +var readBin = exports.readBin = function (filename) { + return fs.readFileSync(filename); +}; + +exports.prepareJs = function (text) { + //replace with new Buffer("aabb", "hex") + var matches = text.match(/()/g); + if (matches) { + debug('matches', matches); + matches.forEach(function (m) { + var bytes = m.match(/ ([a-f0-9]{2})/g); + var str = ''; + if (bytes !== null) { + str = bytes.join(''); + str = str.replace(/ /g, ''); + str = str.replace(/\./g, ''); + } + var r = 'new Buffer("' + str + '", "hex")'; + text = text.replace(m, r); + }); + } + //[Getter] + text = text.replace(/\[Getter\]/g, 'undefined'); + return text; +}; + +var readJs = exports.readJs = function (filename) { + if (!fs.existsSync(filename)) { + return false; + } + var js = exports.prepareJs('foo = ' + fs.readFileSync(filename, 'utf8')); + var sandbox = { + Buffer: Buffer + }; + return vm.runInNewContext(js, sandbox, filename); +}; + +exports.equalJs = function (expected, actual) { + var e = exports.createJs(expected); + var a = exports.createJs(actual); + expect(a, 'Objects are not the same').to.equal(e); +}; + +exports.equalBuffer = function (expected, actual, start) { + start = start || 0; + for (var i = start; i < expected.length; i++) { + var e = expected.toString('hex', i, i + 1); + var a = actual.toString('hex', i, i + 1); + var msg = util.format('offset %s', i.toString(16)); + expect(a, msg).to.equal(e); + } +}; + +var equalDeep = exports.equalDeep = function (expected, actual, objpath) { + + var np = objpath || 'root'; + function dp (a, b) { + return a + '.' + b; + } + + for (var key in expected) { + if (expected.hasOwnProperty(key)) { + debug('looking at key `%s` in `%s`', key, objpath); + if (key === 'payload') { + debug('payload is deprecated!!!'); + continue; + } + if (actual instanceof Array) { + expect(actual[key]).to.exist(); + } + else { + debug('actual value `%j`. expecting it to include key:`%s`...', actual, key); + expect(actual, objpath).to.include(key); + debug('...it did'); + } + var a = actual[key]; + var e = expected[key]; + var prop; + try { + prop = Object.getOwnPropertyDescriptor(actual, key); + } + catch (err) { + console.error('key:`%s`, actual:`%s` of type `%s` got an error', key, actual, typeof actual, err); + throw err; + } + if (e instanceof Buffer) { + expect(a, 'not matching length of ' + dp(np, key)) + .to.have.length(e.length); + + expect(a.toString('hex'), 'buffer not same in ' + dp(np, key)) + .to.equal(e.toString('hex')); + } + else if (typeof e === 'object') { + debug('expected is an `object` and actual is `%s`', typeof a); + expect(typeof a).not.to.equal('string'); + equalDeep(e, a, dp(np, key)); + } + else { + debug('it is not a Buffer or object that we are expecting'); + if (key !== 'name') { + var atype = typeof a; + if (atype === 'undefined') { + expect(atype, util.format('type of key `%s` as unexpected', key)).to.equal(typeof e); + } + else { + //don't test getters + if (!prop.get) { + expect(a, util.format('%s (%s) is not as expected', + dp(np, key), atype)).to.equal(e); + } + } + } + else { + expect(a, util.format('wrong length of %s', dp(np, key))) + .to.have.length(e.length); + debug('actual: %s, expected: %s', a, e); + } + } + } + } +}; + + +exports.createWritingTests = function (lab, testFolder) { + //var describe = lab.describe; + var it = lab.it; + + var files = fs.readdirSync(testFolder).filter(function (f) { return /\.js$/.test(f); }); + files.forEach(function (file) { + it('can write ' + file, function (done) { + var js = readJs(path.join(testFolder, file)); + expect(js).to.exist(); + var buff = dns.DNSPacket.toBuffer(js); + var binFile = path.join(testFolder, file.replace(/\.js$/, '.bin')); + var bin = readBin(binFile); + var rtrip = dns.DNSPacket.parse(buff); + expect(buff).to.have.length(bin.length); + expect(buff).to.be.deep.equal(bin); + equalDeep(js, rtrip); + done(); + }); + }); +}; + +exports.createParsingTests = function (lab, testFolder) { + //var describe = lab.describe; + var files = fs.readdirSync(testFolder).filter(function (f) { return /\.bin$/.test(f); }); + files.forEach(function (file) { + exports.createFileParsingTest(lab, path.join(testFolder, file)); + }); +}; + + +exports.createFileParsingTest = function (lab, binFile, withRoundtrip) { + var it = lab.it; + + it('can parse ' + binFile, function (done) { + var bin = readBin(binFile); + var jsfile = binFile.replace(/\.bin$/, '.js'); + var js = readJs(jsfile); + var ret = dns.DNSPacket.parse(bin); + debug(binFile, ret); + if (!js) { + writeJs(jsfile, ret); + } + else { + equalDeep(js, ret); + //equalJs(js, ret); + } + // //roundtrip + if (withRoundtrip) { + debug('roundtrip. js to bin'); + var newbin = dns.DNSPacket.toBuffer(ret); + expect(newbin).to.deep.equal(bin); + } + done(); + }); +}; diff --git a/node_modules/dns-js/test/helper.test.js b/node_modules/dns-js/test/helper.test.js new file mode 100644 index 0000000..49595b7 --- /dev/null +++ b/node_modules/dns-js/test/helper.test.js @@ -0,0 +1,69 @@ +var Code = require('code'); // assertion library +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var expect = Code.expect; + +var path = require('path'); +var helper = require('./helper'); +var fs = require('fs'); + +var Packet = require('..').DNSPacket; +//var fixtureDir = path.join(__dirname, 'fixtures'); +var packets = require('./packets.json'); + +// var TestObj = function () { +// this.subprop = { +// a: 1, +// b: 2 +// }; +// this.__defineGetter__('getMe', function () { +// return 'got it'; +// }); +// }; + + +describe('helper', function () { + + it('prepareJs', function (done) { + //this is a tricky one + var filename = path.join(__dirname, 'fixtures', 'mdns-inbound-type47.js'); + var text = fs.readFileSync(filename, 'utf8'); + var js = helper.prepareJs(text); + expect(js).to.be.a.string(); + expect(js).to.match(/new Buffer\(/); + done(); + }); + + it('readJs', function (done) { + var filename = path.join(__dirname, 'fixtures', 'mdns-inbound-type47.js'); + var js = helper.readJs(filename); + expect(js).to.exist(); + expect(js).to.include('header'); + done(); + }); + + it('readBin', function (done) { + var filename = path.join(__dirname, 'fixtures', 'mdns-readynas.bin'); + var b = helper.readBin(filename); + expect(b).to.be.instanceOf(Buffer); + done(); + }); + + describe('from buffer', function () { + var b = new Buffer(packets.in.sample10, 'hex'); + it('writeJs', function (done) { + helper.writeBin(path.join('./', 'test.bin.log'), b); + done(); + }); + it('writeJs', function (done) { + helper.writeJs(path.join('./', 'test.js.log'), Packet.parse(b)); + done(); + }); + }); + +}); diff --git a/node_modules/dns-js/test/packet.test.js b/node_modules/dns-js/test/packet.test.js new file mode 100644 index 0000000..34e850d --- /dev/null +++ b/node_modules/dns-js/test/packet.test.js @@ -0,0 +1,289 @@ +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var Code = require('code'); // assertion library +var expect = Code.expect; + +//var debug = require('debug')('mdns-packet:test:dns'); +var path = require('path'); +//var fs = require('fs'); + +var helper = require('./helper'); +var dns = require('../'); +var DNSRecord = dns.DNSRecord; +var DNSPacket = dns.DNSPacket; + +var fixtureDir = path.join(__dirname, 'fixtures'); +var nativeFixtureDir = path.join(__dirname, '..', 'node_modules', + 'native-dns-packet', 'test', 'fixtures'); + +var NativePacket = require('native-dns-packet'); + + +describe('DNSPacket', function () { + + it('should be able to create a wildcard query', function (done) { + var packet = new dns.DNSPacket(); + packet.header.rd = 0; + var query = new dns.DNSRecord( + '_services._dns-sd._udp.local', + dns.DNSRecord.Type.PTR, + 1 + ); + packet.question.push(query); + var buf = dns.DNSPacket.toBuffer(packet); + + //compare fixture + expect(buf.toString('hex'), 'Not as from fixture').to.equal( + helper.readBin( + path.join(fixtureDir, 'mdns-outbound-wildcard-query.bin') + ).toString('hex')); + + var np = new NativePacket(); + np.header.rd = 0; + np.question.push(query); + var nb = new Buffer(4096); + var written = NativePacket.write(nb, np); + nb = nb.slice(0, written); + + expect(buf.toString('hex'), 'Not as from native').to.equal( + nb.toString('hex')); + + done(); + }); + + it('should be able to create PTR answer', function (done) { + var packet = new dns.DNSPacket(); + packet.header.rd = 0; + packet.header.qr = 1; + packet.header.aa = 1; + //query + var query = new dns.DNSRecord( + '_services._dns-sd._udp.local', + dns.DNSRecord.Type.PTR, + 1 + ); + packet.question.push(query); + + //answer + packet.answer.push({ + name: '_services._dns-sd._udp.local', //reference to first record name + type: dns.DNSRecord.Type.PTR, + class: 1, + ttl: 10, + data: '_workstation._tcp.local' + }); + + packet.answer.push({ + name: '_services._dns-sd._udp.local', //reference to first record name + type: dns.DNSRecord.Type.PTR, + class: 1, + ttl: 10, + data: '_udisks-ssh._tcp.local' + }); + + var buf = dns.DNSPacket.toBuffer(packet); + + var pr = dns.DNSPacket.parse(buf); + var fixture = helper.readBin( + path.join(fixtureDir, 'mdns-inbound-linux_workstation.bin') + ); + + helper.equalDeep(pr, dns.DNSPacket.parse(fixture)); + + //helper.equalBuffer(fixture, buf, 8); + // //expect(buf.toString('hex')).to.equal(fixStr); + // var parsed = dns.DNSPacket.parse(buf); + done(); + }); + + + it('new packet with flags as input', function (done) { + var p = new dns.DNSPacket(0x40); + expect(p.header.res1).to.equal(1); + done(); + }); + + + it('should parse SOA', function (done) { + var inbound = helper.readBin('test/fixtures/dns-soa.bin'); + var packet = dns.DNSPacket.parse(inbound); + expect(packet.authority).to.have.length(1); + + var auth = packet.authority[0]; + + expect(auth.type).to.equal(6); + expect(auth.typeName).to.equal('SOA'); + + expect(auth.primary).to.equal('ns1.google.com'); + expect(auth.admin).to.equal('dns-admin.google.com'); + expect(auth.serial).to.equal(1576192); + expect(auth.refresh).to.equal(7200); + expect(auth.retry).to.equal(1800); + expect(auth.expiration).to.equal(1209600); + expect(auth.minimum).to.equal(300); + + done(); + }); + + it('throw when question does not exist', function (done) { + var buf = new Buffer('0000840000010000000000000000000000', 'hex'); + expect(fn).to.throw(dns.errors.MalformedPacket, 'Record.type is empty'); + + buf = new Buffer('0000840000010000000000000001000000', 'hex'); + expect(fn).to.throw(dns.errors.MalformedPacket, 'Record.class is empty'); + + done(); + function fn() { + dns.parse(buf); + } + }); + + it('should create reverse lookup', function (done) { + var expected = '2aa601000001000000000000013801380138013807696e2d61646472046172706100000c0001'; + var packet = new dns.DNSPacket(); + packet.header.id = 0x2aa6; + packet.question.push(new dns.DNSRecord( + '8.8.8.8.in-addr.arpa', + dns.DNSRecord.Type.PTR, + dns.DNSRecord.Class.IN)); + var buf = dns.DNSPacket.toBuffer(packet); + expect(buf.toString('hex')).to.equal(expected); + packet = dns.DNSPacket.parse(buf); + done(); + }); + + it('should create another reverse lookup', function (done) { + var expected = '10920100000100000000000002353103313637033231310331343007696e2d61646472046172706100000c0001'; + var packet = new dns.DNSPacket(); + packet.header.id = 4242; + packet.question.push(new dns.DNSRecord( + '51.167.211.140.in-addr.arpa.', + dns.DNSRecord.Type.PTR, + dns.DNSRecord.Class.IN) + ); + expect(packet.question[0].type).to.equal(dns.DNSRecord.Type.PTR); + + var buf = dns.DNSPacket.toBuffer(packet); + expect(buf.toString('hex')).to.equal(expected); + //roundtrpip + packet = dns.DNSPacket.parse(buf); + done(); + }); + + it('same regardless of id', function (done) { + var expected1 = '10920100000100000000000002353103313637033231310331343007696e2d61646472046172706100000c0001'; + var expected2 = '00000100000100000000000002353103313637033231310331343007696e2d61646472046172706100000c0001'; + // 00000100000100000000000002353103313637033231310331343007696e2d6164647204617270610000000c0001; + + var r = new DNSRecord( + '51.167.211.140.in-addr.arpa.', + DNSRecord.Type.PTR, + DNSRecord.Class.IN); + + //packet with id + var p1 = new DNSPacket(); + p1.header.id = 4242; + p1.question.push(r); + // console.log('with'); + var buf1 = DNSPacket.toBuffer(p1); + expect(buf1.toString('hex'), 'buf1').to.equal(expected1); + + //packet without id + var p2 = new DNSPacket(); + p2.question.push(r); + // console.log('without'); + var buf2 = DNSPacket.toBuffer(p2); + expect(buf2.toString('hex'), 'buf2').to.equal(expected2); + + done(); + }); + + + + + describe('parsing fixtures', function () { + + describe('basic tests', function () { + helper.createParsingTests(lab, fixtureDir); + }); + + // it('should do edns OPT RR', {only: true}, function (done) { + // var bin = helper.readBin('test/fixtures/mdns-inbound-apple-mobdev.bin'); + // var p = dns.parse(bin); + // //check for opt + // expect(p.additional).to.have.length(1); + // var opt = p.additional[0].opt; + // expect(opt).to.include(['code', 'z', 'version', 'rcode', 'data', 'do']); + // expect(opt.code, 'code').to.equal(4); + // expect(opt.z, 'z').to.equal(4500); + // done(); + // }); + + }); + + describe('parsing fixtures with roundtrip', function () { + helper.createFileParsingTest(lab, + 'test/fixtures/www.nodejs.org.cname.bin', true); + + helper.createFileParsingTest(lab, + 'test/fixtures/dns-soa.bin', true); + }); + + // describe('create fixtures', {skip:true}, function () { + // helper.createWritingTests(lab, fixtureDir); + // }); + + describe('parsing exploits', function () { + it('zlip-1', function (done) { + var bin = helper.readBin('test/fixtures/exploits/zlip-1.bin'); + expect(fn).to.throw(dns.errors.MalformedPacket, + 'Unexpectedly big section count: 83258. Missing at least 416225 bytes.' + ); + done(); + function fn() { + dns.parse(bin); + done('should fail'); + } + }); + + it('zlip-2', function (done) { + var bin = helper.readBin('test/fixtures/exploits/zlip-2.bin'); + expect(fn).to.throw(dns.errors.MalformedPacket, + 'Unexpectedly big section count: 83258. Missing at least 416225 bytes.' + ); + done(); + function fn() { + dns.parse(bin); + done('should fail'); + } + }); + + it('zlip-3', function (done) { + var bin = helper.readBin('test/fixtures/exploits/zlip-3.bin'); + expect(fn).to.throw(dns.errors.MalformedPacket, + 'Unexpectedly big section count: 83258. Missing at least 416155 bytes.' + ); + done(); + function fn() { + dns.parse(bin); + done('should fail'); + } + }); + });//exploits + + // describe('create fixtures', {skip: true}, function () { + // helper.createWritingTests(lab, fixtureDir); + // }); + + describe('fixtures from native-dns-packet', function () { + describe('parsing', function () { + helper.createParsingTests(lab, nativeFixtureDir); + }); + }); + +}); diff --git a/node_modules/dns-js/test/packets.json b/node_modules/dns-js/test/packets.json new file mode 100644 index 0000000..975c2a0 --- /dev/null +++ b/node_modules/dns-js/test/packets.json @@ -0,0 +1,23 @@ +{ + "in": { + "sample1": "000084000001000600000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f756469736b732d737368c047c00c000c00010000000a000c095f6f77736572766572c047c00c000c00010000000a0007045f667470c047c00c000c00010000000a0008055f68747470c047c00c000c00010000000a000b085f6f776874747064c047", + "sample2": "000084000001000500000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f6166706f766572746370c047c00c000c00010000000a000c095f72656164796e6173c047c00c000c00010000000a0008055f68747470c047c00c000c00010000000a0007045f736d62c047", + "sample3": "000084000001000200000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00170f5f70646c2d6461746173747265616d045f746370c023c00c000c00010000000a0008055f68747470c04a", + "sample4": "000084000001000200000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f756469736b732d737368c047", + "sample5": "000084000001000400000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a0007045f6e7574c047c00c000c00010000000a0008055f68747470c047c00c000c00010000000a0007045f736d62c047", + "sample6": "000084000001000700000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000c095f736674702d737368c047c00c000c00010000000a0007045f736d62c047c00c000c00010000000a0007045f667470c047c00c000c00010000000a0007045f737368c047c00c000c00010000000a0008055f68747470c047c00c000c00010000000a0009065f6874747073c047", + "linux_workstation": "000084000001000200000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001c00c000c00010000000a00140c5f776f726b73746174696f6e045f746370c023c00c000c00010000000a000e0b5f756469736b732d737368c047", + "tcp_workstation1": "0000840000010004000000000c5f776f726b73746174696f6e045f746370056c6f63616c00000c0001c00c000c00010000000a001c19726567696e205b33303a34363a39613a62323a62383a62325dc00cc035001000010000000a000100c035002100010000000a000e00000000000905726567696ec01ec070000100010000000a00040a64003d", + "tcp_workstation2": "0000840000010005000000000c5f776f726b73746174696f6e045f746370056c6f63616c00000c0001c00c000c00010000000a001d1a766573747269205b32383a63363a38653a33343a62383a63335dc00cc035001000010000000a000100c035002100010000000a000f00000000000906766573747269c01ec071001c00010000000a0010fe800000000000002ac68efffe34b8c3c071000100010000000a00040a640063", + "sample7": "000084000000000d00000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c000100000e0f001b135f7472616e736d697373696f6e736572766572045f746370c023c00c000c000100000e0f0007045f737368c048c00c000c000100000e0f0009065f6874747073c048c00c000c000100000e0f000f0c5f776f726b73746174696f6ec048c00c000c000100000e0f000e0b5f6166706f766572746370c048c00c000c000100000e0f000c095f72656164796e6173c048c00c000c000100000e0f0007045f667470c048c00c000c000100000e0f00120f5f70646c2d6461746173747265616dc048c00c000c000100000e0f000c095f736674702d737368c048c00c000c000100000e0f000e0b5f676f6f676c6563617374c048c00c000c000100000e0f0007045f736d62c048c00c000c000100000e0f000e0b5f756469736b732d737368c048c00c000c000100000e0f0008055f68747470c048", + "sample8": "000084000001000100000005085f616972706c6179045f746370056c6f63616c00000c0001c00c000c00010000000a000704656d6270c00cc031002100010000000a000d000000001b5804656d6270c01ac031001000010000000a005e097268643d352e302e371366656174757265733d307831303030323966661a64657669636569643d31303a34303a46333a41373a36443a4241106d6f64656c3d4170706c655456332c320476763d310e737263766572733d3135302e333304656d62700c5f6465766963652d696e666fc015001000010000000a001f136d6f64656c3d4d6163426f6f6b50726f382c310a6f7378766572733d3133c04a001c00010000000a0010fe800000000000001240f3fffea76dbac04a000100010000000a00040a000105", + "sample9": "0000000000090002000000000b5f676f6f676c6563617374045f746370056c6f63616c00000c80011254562069205661726461677372756d6d6574c00c00218001c0280010800114536bc3a4726d20692047c3a4737472756d6d6574c00c0021800114536bc3a4726d20692047c3a4737472756d6d6574c00c001080011254562069205661726461677372756d6d6574c01d00018001c07d001c800114536bc3a4726d20692047c3a4737472756d6d6574c01d0001800114536bc3a4726d20692047c3a4737472756d6d6574c01d001c8001c00c000c0001000009ad0002c028c00c000c0001000009a9001714536bc3a4726d20692047c3a4737472756d6d6574c00c", + "sample10": "0000840000000002000000021254562069205661726461677372756d6d6574056c6f63616c0000018001000000780004c0a801591254562069205661726461677372756d6d65740b5f676f6f676c6563617374045f746370c01f00218001000000780008000000001f49c00cc00c002f8001000000780005c00c000140c034002f8001000000780009c03400050000800040", + "sample11": "0000840000010001000000030b5f676f6f676c6563617374045f746370056c6f63616c00000c0001c00c000c00010000000a001e1b4368726f6d65636173743330393720c386c3b8c3a5c3b6c3a4c593c00cc034002100010000000a0024000000001f491b4368726f6d65636173743330393720c386c3b8c3a5c3b6c3a4c593c01dc034001000010000000a00742369643d33396463343466356166306633646434663337306133393264353035306635640576653d30320d6d643d4368726f6d65636173741269633d2f73657475702f69636f6e2e706e671e666e3d4368726f6d65636173743330393720c386c3b8c3a5c3b6c3a4c5930463613d350473743d30c064000100010000000a0004c0a801de" + }, + "out": { + "wildcard": "000000000001000000000000095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001" + } + +} + diff --git a/node_modules/dns-js/test/record-create.test.js b/node_modules/dns-js/test/record-create.test.js new file mode 100644 index 0000000..10f4b23 --- /dev/null +++ b/node_modules/dns-js/test/record-create.test.js @@ -0,0 +1,112 @@ +var Code = require('code'); // assertion library +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var expect = Code.expect; + +var DNSRecord = require('../lib/dnsrecord'); +var BufferWriter = require('../lib/bufferwriter'); +//var helper = require('./helper'); + + +describe('DNSRecord (Create)', function () { + + it('create query', function (done) { + var bw = new BufferWriter(); + var r = new DNSRecord('_services._dns-sd._udp.local', + DNSRecord.Type.PTR, 1); + expect(r).to.include(['name', 'type', 'class', 'ttl']); + expect(r.ttl).to.equal(DNSRecord.TTL); + var b = DNSRecord.write(bw, r).dump(); + expect(b.toString('hex')).to.equal( + '095f7365727669636573075f646e732d7364045f756470056c6f63616c00000c0001'); + + //roundtrip + var pr = DNSRecord.parseQuestion(b); + expect(pr).to.deep.include(r); + + done(); + }); + + it('SRV', function (done) { + var bw = new BufferWriter(); + var alias = 'regin [30:46:9a:b2:b8:b2]._workstation._tcp.local'; + + var r = { + name: alias, + type: DNSRecord.Type.SRV, + class: DNSRecord.Class.IN, + ttl: 10, + priority: 1, + weight: 2, + port: 9, + target: 'regin.local' + }; + + var b = DNSRecord.write(bw, r, true).dump(); + var recStr = b.toString('hex'); + + expect(recStr, 'type, class, ttl').to.include('002100010000000a'); + expect(recStr, 'srv data').to.include('00010002000905726567696e'); + //002100010000000a0013000000010002000905726567696e056c6f63616c00 + //roundtrip + var pr = DNSRecord.parse(b); + expect(pr).to.include(['port', 'target', 'weight', 'priority']); + + //expect(pr.priority, 'priority').to.equal(priority); + expect(pr.port, 'port').to.equal(r.port); + expect(pr.weight, 'weight').to.equal(r.weight); + expect(pr.target, 'target').to.equal(r.target); + //expect(pr).to.deep.equal(r); + + done(); + }); + + it('PTR', function (done) { + var writer = new BufferWriter(); + var r = new DNSRecord( + '_services._dns-sd._udp.local', + DNSRecord.Type.PTR, + 1, + 10); + r.data = '_workstation._tcp.local'; + DNSRecord.write(writer, r, true); + done(); + }); + + it('reverse lookup', function (done) { + + var rec = '013801380138013807696e2d61646472046172706100000c0001'; + var r = new DNSRecord( + '8.8.8.8.in-addr.arpa', + DNSRecord.Type.PTR, + DNSRecord.Class.IN); + var bw = new BufferWriter(); + var b = DNSRecord.write(bw, r, true).dump(); + var recStr = b.toString('hex'); + expect(recStr).to.equal(rec); + done(); + }); + + it('reverse lookup 2', function (done) { + var expected = '02353103313637033231310331343007696e2d61646472046172706100000c0001'; + // '02353103313637033231310331343007696e2d616464720461727061 00000c0001' + // 5 1 1 6 7 2 1 1 1 3 0 i n - a d d r a r p a + var r = new DNSRecord( + '51.167.211.140.in-addr.arpa.', + DNSRecord.Type.PTR, + DNSRecord.Class.IN); + + var bw = new BufferWriter(); + var buf = DNSRecord.write(bw, r, true).dump(); + expect(buf.toString('hex')).to.equal(expected); + var r2 = DNSRecord.parseQuestion(buf); + expect(r2.type).to.equal(DNSRecord.Type.PTR); + done(); + }); + +}); diff --git a/node_modules/dns-js/test/record-parse.test.js b/node_modules/dns-js/test/record-parse.test.js new file mode 100644 index 0000000..683cd6d --- /dev/null +++ b/node_modules/dns-js/test/record-parse.test.js @@ -0,0 +1,73 @@ +var Code = require('code'); // assertion library +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var expect = Code.expect; + +var DNSRecord = require('../lib/dnsrecord'); +//var BufferConsumer = require('../lib/bufferconsumer'); +//var helper = require('./helper'); + + +describe('DNSRecord (Parse)', function () { + describe('OPT', function () { + it('parse OPT', function (done) { + var buf = new Buffer('00002905a000001194000c00040008000008002700d4b4', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r).to.include('opt'); + expect(r.opt).to.include(['rcode', 'z', 'version', 'code', 'data', 'do']); + expect(r.opt.z, 'z').to.equal(0x1194); + done(); + }); + + it('parse OPT rcode', function (done) { + var buf = new Buffer('00002905a00F001194000c00040008000008002700d4b4', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r.opt.rcode, 'rcode').to.equal(0x0f); + done(); + }); + + it('parse OPT version', function (done) { + var buf = new Buffer('00002905a0001f1194000c00040008000008002700d4b4', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r.opt.version, 'version').to.equal(0x1f); + done(); + }); + + it('parse OPT do', function (done) { + var buf = new Buffer('00002905a000009194000c00040008000008002700d4b4', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r.opt.do, 'do').to.equal(1); + done(); + }); + });//OPT + + + describe('A - TTL', function () { + it('parse A TTL=0', function (done) { + var buf = new Buffer('00000180010000000000040a500a22', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r.type).to.equal(DNSRecord.Type.A); + expect(r.ttl).to.equal(0); + done(); + }); + + it('parse A TTL=20', function (done) { + var buf = new Buffer('00000180010000001400040a500a22', + 'hex'); + var r = DNSRecord.parse(buf); + expect(r.type).to.equal(DNSRecord.Type.A); + expect(r.ttl).to.equal(20); + done(); + }); + });//A-TTL +}); diff --git a/node_modules/dns-js/test/single.test.js b/node_modules/dns-js/test/single.test.js new file mode 100644 index 0000000..6930104 --- /dev/null +++ b/node_modules/dns-js/test/single.test.js @@ -0,0 +1,12 @@ +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); +var describe = lab.describe; +var helper = require('./helper'); + +describe('single', function () { + if (process.env.SINGLE) { + describe('parsing', function () { + helper.createFileParsingTest(lab, process.env.SINGLE, true); + }); + } +}); diff --git a/node_modules/dns-js/test/writer.test.js b/node_modules/dns-js/test/writer.test.js new file mode 100644 index 0000000..4d9d795 --- /dev/null +++ b/node_modules/dns-js/test/writer.test.js @@ -0,0 +1,98 @@ +var Code = require('code'); // assertion library +var Lab = require('lab'); +var lab = exports.lab = Lab.script(); + +var describe = lab.describe; +var it = lab.it; +//var before = lab.before; +//var after = lab.after; +var expect = Code.expect; + +var BufferWriter = require('../lib/bufferwriter'); + + +describe('BufferWriter', function () { + + it('should default to a 512 byte buffer', function (done) { + var out = new BufferWriter(); + expect(out.buf).to.have.length(512); + done(); + }); + + it('should default to a 512 byte buffer', function (done) { + var out = new BufferWriter(10); + expect(out.buf).to.have.length(10); + done(); + }); + + + it('#buffer with undefined should return writer', function (done) { + var out = new BufferWriter(10); + var o = out.buffer(); + expect(o).to.be.instanceof(BufferWriter); + done(); + }); + + it('#buffer should accept buffer as input', function (done) { + var out = new BufferWriter(10); + var o = out.buffer(new Buffer('abc')); + expect(o).to.be.instanceof(BufferWriter); + expect(o.buf.toString('utf8', 0, 3)).to.equal('abc'); + done(); + }); + + it('#buffer should not move forward on empty buffer', function (done) { + var out = new BufferWriter(10); + var o = out.buffer(new Buffer(0)); + expect(o).to.be.instanceof(BufferWriter); + expect(out.tell()).to.equal(0); + done(); + }); + + + it('#buffer throw if input is not writer or buffer', function (done) { + var throws = function () { + var out = new BufferWriter(10); + out.buffer('asdf'); + }; + expect(throws).to.throw(Error, 'VariableError: not a buffer'); + done(); + }); + + + it('#seek should throw on negative', function (done) { + var throws = function () { + var out = new BufferWriter(10); + out.seek(-1); + }; + expect(throws).to.throw(Error, 'Negative pos not allowed'); + + done(); + }); + + it('#seek should throw after length', function (done) { + var throws = function () { + var out = new BufferWriter(10); + out.seek(12); + }; + expect(throws).to.throw(Error, 'Cannot seek after EOF. 12 > 10'); + + done(); + }); + + it('#indexOf should return array with all occurances', function (done) { + var out = new BufferWriter(); + out.buffer(new Buffer('helloworldfoobarfoo')); + var r = out.indexOf('foo'); + expect(r).to.include([10, 16]); + done(); + }); + + // it('#name withLength', function (done) { + // var out = new BufferWriter(); + // out.name('hello', true); + // expect(o.tell()).to.equal(6); + // done(); + // }); + +}); diff --git a/node_modules/extsprintf/.gitmodules b/node_modules/extsprintf/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/node_modules/extsprintf/.npmignore b/node_modules/extsprintf/.npmignore new file mode 100644 index 0000000..6ed1ae9 --- /dev/null +++ b/node_modules/extsprintf/.npmignore @@ -0,0 +1,2 @@ +/deps +/examples diff --git a/node_modules/extsprintf/LICENSE b/node_modules/extsprintf/LICENSE new file mode 100644 index 0000000..cbc0bb3 --- /dev/null +++ b/node_modules/extsprintf/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012, Joyent, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE diff --git a/node_modules/extsprintf/Makefile b/node_modules/extsprintf/Makefile new file mode 100644 index 0000000..db84518 --- /dev/null +++ b/node_modules/extsprintf/Makefile @@ -0,0 +1,24 @@ +# +# Copyright (c) 2012, Joyent, Inc. All rights reserved. +# +# Makefile: top-level Makefile +# +# This Makefile contains only repo-specific logic and uses included makefiles +# to supply common targets (javascriptlint, jsstyle, restdown, etc.), which are +# used by other repos as well. +# + +# +# Files +# +JSL = jsl +JSSTYLE = jsstyle +JS_FILES := $(shell find examples lib -name '*.js') +JSL_FILES_NODE = $(JS_FILES) +JSSTYLE_FILES = $(JS_FILES) +JSL_CONF_NODE = jsl.node.conf + +# Default target is "check" +check: + +include ./Makefile.targ diff --git a/node_modules/extsprintf/Makefile.targ b/node_modules/extsprintf/Makefile.targ new file mode 100644 index 0000000..2a64fe7 --- /dev/null +++ b/node_modules/extsprintf/Makefile.targ @@ -0,0 +1,285 @@ +# -*- mode: makefile -*- +# +# Copyright (c) 2012, Joyent, Inc. All rights reserved. +# +# Makefile.targ: common targets. +# +# NOTE: This makefile comes from the "eng" repo. It's designed to be dropped +# into other repos as-is without requiring any modifications. If you find +# yourself changing this file, you should instead update the original copy in +# eng.git and then update your repo to use the new version. +# +# This Makefile defines several useful targets and rules. You can use it by +# including it from a Makefile that specifies some of the variables below. +# +# Targets defined in this Makefile: +# +# check Checks JavaScript files for lint and style +# Checks bash scripts for syntax +# Checks SMF manifests for validity against the SMF DTD +# +# clean Removes built files +# +# docs Builds restdown documentation in docs/ +# +# prepush Depends on "check" and "test" +# +# test Does nothing (you should override this) +# +# xref Generates cscope (source cross-reference index) +# +# For details on what these targets are supposed to do, see the Joyent +# Engineering Guide. +# +# To make use of these targets, you'll need to set some of these variables. Any +# variables left unset will simply not be used. +# +# BASH_FILES Bash scripts to check for syntax +# (paths relative to top-level Makefile) +# +# CLEAN_FILES Files to remove as part of the "clean" target. Note +# that files generated by targets in this Makefile are +# automatically included in CLEAN_FILES. These include +# restdown-generated HTML and JSON files. +# +# DOC_FILES Restdown (documentation source) files. These are +# assumed to be contained in "docs/", and must NOT +# contain the "docs/" prefix. +# +# JSL_CONF_NODE Specify JavaScriptLint configuration files +# JSL_CONF_WEB (paths relative to top-level Makefile) +# +# Node.js and Web configuration files are separate +# because you'll usually want different global variable +# configurations. If no file is specified, none is given +# to jsl, which causes it to use a default configuration, +# which probably isn't what you want. +# +# JSL_FILES_NODE JavaScript files to check with Node config file. +# JSL_FILES_WEB JavaScript files to check with Web config file. +# +# You can also override these variables: +# +# BASH Path to bash (default: bash) +# +# CSCOPE_DIRS Directories to search for source files for the cscope +# index. (default: ".") +# +# JSL Path to JavaScriptLint (default: "jsl") +# +# JSL_FLAGS_NODE Additional flags to pass through to JSL +# JSL_FLAGS_WEB +# JSL_FLAGS +# +# JSSTYLE Path to jsstyle (default: jsstyle) +# +# JSSTYLE_FLAGS Additional flags to pass through to jsstyle +# + +# +# Defaults for the various tools we use. +# +BASH ?= bash +BASHSTYLE ?= tools/bashstyle +CP ?= cp +CSCOPE ?= cscope +CSCOPE_DIRS ?= . +JSL ?= jsl +JSSTYLE ?= jsstyle +MKDIR ?= mkdir -p +MV ?= mv +RESTDOWN_FLAGS ?= +RMTREE ?= rm -rf +JSL_FLAGS ?= --nologo --nosummary + +ifeq ($(shell uname -s),SunOS) + TAR ?= gtar +else + TAR ?= tar +endif + + +# +# Defaults for other fixed values. +# +BUILD = build +DISTCLEAN_FILES += $(BUILD) +DOC_BUILD = $(BUILD)/docs/public + +# +# Configure JSL_FLAGS_{NODE,WEB} based on JSL_CONF_{NODE,WEB}. +# +ifneq ($(origin JSL_CONF_NODE), undefined) + JSL_FLAGS_NODE += --conf=$(JSL_CONF_NODE) +endif + +ifneq ($(origin JSL_CONF_WEB), undefined) + JSL_FLAGS_WEB += --conf=$(JSL_CONF_WEB) +endif + +# +# Targets. For descriptions on what these are supposed to do, see the +# Joyent Engineering Guide. +# + +# +# Instruct make to keep around temporary files. We have rules below that +# automatically update git submodules as needed, but they employ a deps/*/.git +# temporary file. Without this directive, make tries to remove these .git +# directories after the build has completed. +# +.SECONDARY: $($(wildcard deps/*):%=%/.git) + +# +# This rule enables other rules that use files from a git submodule to have +# those files depend on deps/module/.git and have "make" automatically check +# out the submodule as needed. +# +deps/%/.git: + git submodule update --init deps/$* + +# +# These recipes make heavy use of dynamically-created phony targets. The parent +# Makefile defines a list of input files like BASH_FILES. We then say that each +# of these files depends on a fake target called filename.bashchk, and then we +# define a pattern rule for those targets that runs bash in check-syntax-only +# mode. This mechanism has the nice properties that if you specify zero files, +# the rule becomes a noop (unlike a single rule to check all bash files, which +# would invoke bash with zero files), and you can check individual files from +# the command line with "make filename.bashchk". +# +.PHONY: check-bash +check-bash: $(BASH_FILES:%=%.bashchk) $(BASH_FILES:%=%.bashstyle) + +%.bashchk: % + $(BASH) -n $^ + +%.bashstyle: % + $(BASHSTYLE) $^ + +.PHONY: check-jsl check-jsl-node check-jsl-web +check-jsl: check-jsl-node check-jsl-web + +check-jsl-node: $(JSL_FILES_NODE:%=%.jslnodechk) + +check-jsl-web: $(JSL_FILES_WEB:%=%.jslwebchk) + +%.jslnodechk: % $(JSL_EXEC) + $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_NODE) $< + +%.jslwebchk: % $(JSL_EXEC) + $(JSL) $(JSL_FLAGS) $(JSL_FLAGS_WEB) $< + +.PHONY: check-jsstyle +check-jsstyle: $(JSSTYLE_FILES:%=%.jsstylechk) + +%.jsstylechk: % $(JSSTYLE_EXEC) + $(JSSTYLE) $(JSSTYLE_FLAGS) $< + +.PHONY: check +check: check-jsl check-jsstyle check-bash + @echo check ok + +.PHONY: clean +clean:: + -$(RMTREE) $(CLEAN_FILES) + +.PHONY: distclean +distclean:: clean + -$(RMTREE) $(DISTCLEAN_FILES) + +CSCOPE_FILES = cscope.in.out cscope.out cscope.po.out +CLEAN_FILES += $(CSCOPE_FILES) + +.PHONY: xref +xref: cscope.files + $(CSCOPE) -bqR + +.PHONY: cscope.files +cscope.files: + find $(CSCOPE_DIRS) -name '*.c' -o -name '*.h' -o -name '*.cc' \ + -o -name '*.js' -o -name '*.s' -o -name '*.cpp' > $@ + +# +# The "docs" target is complicated because we do several things here: +# +# (1) Use restdown to build HTML and JSON files from each of DOC_FILES. +# +# (2) Copy these files into $(DOC_BUILD) (build/docs/public), which +# functions as a complete copy of the documentation that could be +# mirrored or served over HTTP. +# +# (3) Then copy any directories and media from docs/media into +# $(DOC_BUILD)/media. This allows projects to include their own media, +# including files that will override same-named files provided by +# restdown. +# +# Step (3) is the surprisingly complex part: in order to do this, we need to +# identify the subdirectories in docs/media, recreate them in +# $(DOC_BUILD)/media, then do the same with the files. +# +DOC_MEDIA_DIRS := $(shell find docs/media -type d 2>/dev/null | grep -v "^docs/media$$") +DOC_MEDIA_DIRS := $(DOC_MEDIA_DIRS:docs/media/%=%) +DOC_MEDIA_DIRS_BUILD := $(DOC_MEDIA_DIRS:%=$(DOC_BUILD)/media/%) + +DOC_MEDIA_FILES := $(shell find docs/media -type f 2>/dev/null) +DOC_MEDIA_FILES := $(DOC_MEDIA_FILES:docs/media/%=%) +DOC_MEDIA_FILES_BUILD := $(DOC_MEDIA_FILES:%=$(DOC_BUILD)/media/%) + +# +# Like the other targets, "docs" just depends on the final files we want to +# create in $(DOC_BUILD), leveraging other targets and recipes to define how +# to get there. +# +.PHONY: docs +docs: \ + $(DOC_FILES:%.restdown=$(DOC_BUILD)/%.html) \ + $(DOC_FILES:%.restdown=$(DOC_BUILD)/%.json) \ + $(DOC_MEDIA_FILES_BUILD) + +# +# We keep the intermediate files so that the next build can see whether the +# files in DOC_BUILD are up to date. +# +.PRECIOUS: \ + $(DOC_FILES:%.restdown=docs/%.html) \ + $(DOC_FILES:%.restdown=docs/%json) + +# +# We do clean those intermediate files, as well as all of DOC_BUILD. +# +CLEAN_FILES += \ + $(DOC_BUILD) \ + $(DOC_FILES:%.restdown=docs/%.html) \ + $(DOC_FILES:%.restdown=docs/%.json) + +# +# Before installing the files, we must make sure the directories exist. The | +# syntax tells make that the dependency need only exist, not be up to date. +# Otherwise, it might try to rebuild spuriously because the directory itself +# appears out of date. +# +$(DOC_MEDIA_FILES_BUILD): | $(DOC_MEDIA_DIRS_BUILD) + +$(DOC_BUILD)/%: docs/% | $(DOC_BUILD) + $(CP) $< $@ + +docs/%.json docs/%.html: docs/%.restdown | $(DOC_BUILD) $(RESTDOWN_EXEC) + $(RESTDOWN) $(RESTDOWN_FLAGS) -m $(DOC_BUILD) $< + +$(DOC_BUILD): + $(MKDIR) $@ + +$(DOC_MEDIA_DIRS_BUILD): + $(MKDIR) $@ + +# +# The default "test" target does nothing. This should usually be overridden by +# the parent Makefile. It's included here so we can define "prepush" without +# requiring the repo to define "test". +# +.PHONY: test +test: + +.PHONY: prepush +prepush: check test diff --git a/node_modules/extsprintf/README.md b/node_modules/extsprintf/README.md new file mode 100644 index 0000000..b22998d --- /dev/null +++ b/node_modules/extsprintf/README.md @@ -0,0 +1,46 @@ +# extsprintf: extended POSIX-style sprintf + +Stripped down version of s[n]printf(3c). We make a best effort to throw an +exception when given a format string we don't understand, rather than ignoring +it, so that we won't break existing programs if/when we go implement the rest +of this. + +This implementation currently supports specifying + +* field alignment ('-' flag), +* zero-pad ('0' flag) +* always show numeric sign ('+' flag), +* field width +* conversions for strings, decimal integers, and floats (numbers). +* argument size specifiers. These are all accepted but ignored, since + Javascript has no notion of the physical size of an argument. + +Everything else is currently unsupported, most notably: precision, unsigned +numbers, non-decimal numbers, and characters. + +Besides the usual POSIX conversions, this implementation supports: + +* `%j`: pretty-print a JSON object (using node's "inspect") +* `%r`: pretty-print an Error object + +# Example + +First, install it: + + # npm install extsprintf + +Now, use it: + + var mod_extsprintf = require('extsprintf'); + console.log(mod_extsprintf.sprintf('hello %25s', 'world')); + +outputs: + + hello world + +# Also supported + +**printf**: same args as sprintf, but prints the result to stdout + +**fprintf**: same args as sprintf, preceded by a Node stream. Prints the result +to the given stream. diff --git a/node_modules/extsprintf/jsl.node.conf b/node_modules/extsprintf/jsl.node.conf new file mode 100644 index 0000000..03f787f --- /dev/null +++ b/node_modules/extsprintf/jsl.node.conf @@ -0,0 +1,137 @@ +# +# Configuration File for JavaScript Lint +# +# This configuration file can be used to lint a collection of scripts, or to enable +# or disable warnings for scripts that are linted via the command line. +# + +### Warnings +# Enable or disable warnings based on requirements. +# Use "+WarningName" to display or "-WarningName" to suppress. +# ++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent ++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity ++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement ++anon_no_return_value # anonymous function does not always return value ++assign_to_function_call # assignment to a function call +-block_without_braces # block statement without curly braces ++comma_separated_stmts # multiple statements separated by commas (use semicolons?) ++comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) ++default_not_at_end # the default case is not at the end of the switch statement ++dup_option_explicit # duplicate "option explicit" control comment ++duplicate_case_in_switch # duplicate case in switch statement ++duplicate_formal # duplicate formal argument {name} ++empty_statement # empty statement or extra semicolon ++identifier_hides_another # identifer {name} hides an identifier in a parent scope +-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement ++incorrect_version # Expected /*jsl:content-type*/ control comment. The script was parsed with the wrong version. ++invalid_fallthru # unexpected "fallthru" control comment ++invalid_pass # unexpected "pass" control comment ++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax ++leading_decimal_point # leading decimal point may indicate a number or an object member ++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax ++meaningless_block # meaningless block; curly braces have no impact ++mismatch_ctrl_comments # mismatched control comment; "ignore" and "end" control comments must have a one-to-one correspondence ++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma ++missing_break # missing break statement ++missing_break_for_last_case # missing break statement for last case in switch ++missing_default_case # missing default case in switch statement ++missing_option_explicit # the "option explicit" control comment is missing ++missing_semicolon # missing semicolon ++missing_semicolon_for_lambda # missing semicolon for lambda assignment ++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs ++nested_comment # nested comment ++no_return_value # function {name} does not always return a value ++octal_number # leading zeros make an octal number ++parseint_missing_radix # parseInt missing radix parameter ++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag ++redeclared_var # redeclaration of {name} ++trailing_comma_in_array # extra comma is not recommended in array initializers ++trailing_decimal_point # trailing decimal point may indicate a number or an object member ++undeclared_identifier # undeclared identifier: {name} ++unreachable_code # unreachable code +-unreferenced_argument # argument declared but never referenced: {name} +-unreferenced_function # function is declared but never referenced: {name} ++unreferenced_variable # variable is declared but never referenced: {name} ++unsupported_version # JavaScript {version} is not supported ++use_of_label # use of label ++useless_assign # useless assignment ++useless_comparison # useless comparison; comparing identical expressions +-useless_quotes # the quotation marks are unnecessary ++useless_void # use of the void type may be unnecessary (void is always undefined) ++var_hides_arg # variable {name} hides argument ++want_assign_or_call # expected an assignment or function call ++with_statement # with statement hides undeclared variables; use temporary variable instead + + +### Output format +# Customize the format of the error message. +# __FILE__ indicates current file path +# __FILENAME__ indicates current file name +# __LINE__ indicates current line +# __COL__ indicates current column +# __ERROR__ indicates error message (__ERROR_PREFIX__: __ERROR_MSG__) +# __ERROR_NAME__ indicates error name (used in configuration file) +# __ERROR_PREFIX__ indicates error prefix +# __ERROR_MSG__ indicates error message +# +# For machine-friendly output, the output format can be prefixed with +# "encode:". If specified, all items will be encoded with C-slashes. +# +# Visual Studio syntax (default): ++output-format __FILE__(__LINE__): __ERROR__ +# Alternative syntax: +#+output-format __FILE__:__LINE__: __ERROR__ + + +### Context +# Show the in-line position of the error. +# Use "+context" to display or "-context" to suppress. +# ++context + + +### Control Comments +# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for +# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is +# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason, +# although legacy control comments are enabled by default for backward compatibility. +# +-legacy_control_comments + + +### Defining identifiers +# By default, "option explicit" is enabled on a per-file basis. +# To enable this for all files, use "+always_use_option_explicit" +-always_use_option_explicit + +# Define certain identifiers of which the lint is not aware. +# (Use this in conjunction with the "undeclared identifier" warning.) +# +# Common uses for webpages might be: ++define __dirname ++define clearInterval ++define clearTimeout ++define console ++define exports ++define global ++define process ++define require ++define setInterval ++define setTimeout ++define Buffer ++define JSON ++define Math + +### JavaScript Version +# To change the default JavaScript version: +#+default-type text/javascript;version=1.5 +#+default-type text/javascript;e4x=1 + +### Files +# Specify which files to lint +# Use "+recurse" to enable recursion (disabled by default). +# To add a set of files, use "+process FileName", "+process Folder\Path\*.js", +# or "+process Folder\Path\*.htm". +# + diff --git a/node_modules/extsprintf/lib/extsprintf.js b/node_modules/extsprintf/lib/extsprintf.js new file mode 100644 index 0000000..ed883d3 --- /dev/null +++ b/node_modules/extsprintf/lib/extsprintf.js @@ -0,0 +1,183 @@ +/* + * extsprintf.js: extended POSIX-style sprintf + */ + +var mod_assert = require('assert'); +var mod_util = require('util'); + +/* + * Public interface + */ +exports.sprintf = jsSprintf; +exports.printf = jsPrintf; +exports.fprintf = jsFprintf; + +/* + * Stripped down version of s[n]printf(3c). We make a best effort to throw an + * exception when given a format string we don't understand, rather than + * ignoring it, so that we won't break existing programs if/when we go implement + * the rest of this. + * + * This implementation currently supports specifying + * - field alignment ('-' flag), + * - zero-pad ('0' flag) + * - always show numeric sign ('+' flag), + * - field width + * - conversions for strings, decimal integers, and floats (numbers). + * - argument size specifiers. These are all accepted but ignored, since + * Javascript has no notion of the physical size of an argument. + * + * Everything else is currently unsupported, most notably precision, unsigned + * numbers, non-decimal numbers, and characters. + */ +function jsSprintf(fmt) +{ + var regex = [ + '([^%]*)', /* normal text */ + '%', /* start of format */ + '([\'\\-+ #0]*?)', /* flags (optional) */ + '([1-9]\\d*)?', /* width (optional) */ + '(\\.([1-9]\\d*))?', /* precision (optional) */ + '[lhjztL]*?', /* length mods (ignored) */ + '([diouxXfFeEgGaAcCsSp%jr])' /* conversion */ + ].join(''); + + var re = new RegExp(regex); + var args = Array.prototype.slice.call(arguments, 1); + var flags, width, precision, conversion; + var left, pad, sign, arg, match; + var ret = ''; + var argn = 1; + + mod_assert.equal('string', typeof (fmt)); + + while ((match = re.exec(fmt)) !== null) { + ret += match[1]; + fmt = fmt.substring(match[0].length); + + flags = match[2] || ''; + width = match[3] || 0; + precision = match[4] || ''; + conversion = match[6]; + left = false; + sign = false; + pad = ' '; + + if (conversion == '%') { + ret += '%'; + continue; + } + + if (args.length === 0) + throw (new Error('too few args to sprintf')); + + arg = args.shift(); + argn++; + + if (flags.match(/[\' #]/)) + throw (new Error( + 'unsupported flags: ' + flags)); + + if (precision.length > 0) + throw (new Error( + 'non-zero precision not supported')); + + if (flags.match(/-/)) + left = true; + + if (flags.match(/0/)) + pad = '0'; + + if (flags.match(/\+/)) + sign = true; + + switch (conversion) { + case 's': + if (arg === undefined || arg === null) + throw (new Error('argument ' + argn + + ': attempted to print undefined or null ' + + 'as a string')); + ret += doPad(pad, width, left, arg.toString()); + break; + + case 'd': + arg = Math.floor(arg); + /*jsl:fallthru*/ + case 'f': + sign = sign && arg > 0 ? '+' : ''; + ret += sign + doPad(pad, width, left, + arg.toString()); + break; + + case 'x': + ret += doPad(pad, width, left, arg.toString(16)); + break; + + case 'j': /* non-standard */ + if (width === 0) + width = 10; + ret += mod_util.inspect(arg, false, width); + break; + + case 'r': /* non-standard */ + ret += dumpException(arg); + break; + + default: + throw (new Error('unsupported conversion: ' + + conversion)); + } + } + + ret += fmt; + return (ret); +} + +function jsPrintf() { + var args = Array.prototype.slice.call(arguments); + args.unshift(process.stdout); + jsFprintf.apply(null, args); +} + +function jsFprintf(stream) { + var args = Array.prototype.slice.call(arguments, 1); + return (stream.write(jsSprintf.apply(this, args))); +} + +function doPad(chr, width, left, str) +{ + var ret = str; + + while (ret.length < width) { + if (left) + ret += chr; + else + ret = chr + ret; + } + + return (ret); +} + +/* + * This function dumps long stack traces for exceptions having a cause() method. + * See node-verror for an example. + */ +function dumpException(ex) +{ + var ret; + + if (!(ex instanceof Error)) + throw (new Error(jsSprintf('invalid type for %%r: %j', ex))); + + /* Note that V8 prepends "ex.stack" with ex.toString(). */ + ret = 'EXCEPTION: ' + ex.constructor.name + ': ' + ex.stack; + + if (ex.cause && typeof (ex.cause) === 'function') { + var cex = ex.cause(); + if (cex) { + ret += '\nCaused by: ' + dumpException(cex); + } + } + + return (ret); +} diff --git a/node_modules/extsprintf/package.json b/node_modules/extsprintf/package.json new file mode 100644 index 0000000..7fd6f23 --- /dev/null +++ b/node_modules/extsprintf/package.json @@ -0,0 +1,77 @@ +{ + "_args": [ + [ + { + "raw": "extsprintf@^1.2.0", + "scope": null, + "escapedName": "extsprintf", + "name": "extsprintf", + "rawSpec": "^1.2.0", + "spec": ">=1.2.0 <2.0.0", + "type": "range" + }, + "/srv/demos/node_modules/verror" + ] + ], + "_from": "extsprintf@>=1.2.0 <2.0.0", + "_id": "extsprintf@1.3.0", + "_inCache": true, + "_location": "/extsprintf", + "_nodeVersion": "0.12.0", + "_npmUser": { + "name": "dap", + "email": "dap@cs.brown.edu" + }, + "_npmVersion": "2.5.1", + "_phantomChildren": {}, + "_requested": { + "raw": "extsprintf@^1.2.0", + "scope": null, + "escapedName": "extsprintf", + "name": "extsprintf", + "rawSpec": "^1.2.0", + "spec": ">=1.2.0 <2.0.0", + "type": "range" + }, + "_requiredBy": [ + "/verror" + ], + "_resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "_shasum": "96918440e3041a7a414f8c52e3c574eb3c3e1e05", + "_shrinkwrap": null, + "_spec": "extsprintf@^1.2.0", + "_where": "/srv/demos/node_modules/verror", + "bugs": { + "url": "https://github.com/davepacheco/node-extsprintf/issues" + }, + "dependencies": {}, + "description": "extended POSIX-style sprintf", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "96918440e3041a7a414f8c52e3c574eb3c3e1e05", + "tarball": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz" + }, + "engines": [ + "node >=0.6.0" + ], + "gitHead": "accc9f2774189a416f294546ed03b626eec3f80c", + "homepage": "https://github.com/davepacheco/node-extsprintf", + "license": "MIT", + "main": "./lib/extsprintf.js", + "maintainers": [ + { + "name": "dap", + "email": "dap@cs.brown.edu" + } + ], + "name": "extsprintf", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/davepacheco/node-extsprintf.git" + }, + "scripts": {}, + "version": "1.3.0" +} diff --git a/node_modules/ipaddr.js/.npmignore b/node_modules/ipaddr.js/.npmignore new file mode 100644 index 0000000..7a1537b --- /dev/null +++ b/node_modules/ipaddr.js/.npmignore @@ -0,0 +1,2 @@ +.idea +node_modules diff --git a/node_modules/ipaddr.js/Cakefile b/node_modules/ipaddr.js/Cakefile new file mode 100644 index 0000000..7fd355a --- /dev/null +++ b/node_modules/ipaddr.js/Cakefile @@ -0,0 +1,18 @@ +fs = require 'fs' +CoffeeScript = require 'coffee-script' +nodeunit = require 'nodeunit' +UglifyJS = require 'uglify-js' + +task 'build', 'build the JavaScript files from CoffeeScript source', build = (cb) -> + source = fs.readFileSync 'src/ipaddr.coffee' + fs.writeFileSync 'lib/ipaddr.js', CoffeeScript.compile source.toString() + + invoke 'test' + invoke 'compress' + +task 'test', 'run the bundled tests', (cb) -> + nodeunit.reporters.default.run ['test'] + +task 'compress', 'uglify the resulting javascript', (cb) -> + result = UglifyJS.minify('lib/ipaddr.js') + fs.writeFileSync('ipaddr.min.js', result.code) diff --git a/node_modules/ipaddr.js/LICENSE b/node_modules/ipaddr.js/LICENSE new file mode 100644 index 0000000..3493f0d --- /dev/null +++ b/node_modules/ipaddr.js/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2011 Peter Zotov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/node_modules/ipaddr.js/README.md b/node_modules/ipaddr.js/README.md new file mode 100644 index 0000000..a816672 --- /dev/null +++ b/node_modules/ipaddr.js/README.md @@ -0,0 +1,149 @@ +# ipaddr.js — an IPv6 and IPv4 address manipulation library + +ipaddr.js is a small (1.9K minified and gzipped) library for manipulating +IP addresses in JavaScript environments. It runs on both CommonJS runtimes +(e.g. [nodejs]) and in a web browser. + +ipaddr.js allows you to verify and parse string representation of an IP +address, match it against a CIDR range or range list, determine if it falls +into some reserved ranges (examples include loopback and private ranges), +and convert between IPv4 and IPv4-mapped IPv6 addresses. + +[nodejs]: http://nodejs.org + +## Installation + +`npm install ipaddr.js` + +## API + +ipaddr.js defines one object in the global scope: `ipaddr`. In CommonJS, +it is exported from the module: + +```js +var ipaddr = require('ipaddr.js'); +``` + +The API consists of several global methods and two classes: ipaddr.IPv6 and ipaddr.IPv4. + +### Global methods + +There are three global methods defined: `ipaddr.isValid`, `ipaddr.parse` and +`ipaddr.process`. All of them receive a string as a single parameter. + +The `ipaddr.isValid` method returns `true` if the address is a valid IPv4 or +IPv6 address, and `false` otherwise. It does not throw any exceptions. + +The `ipaddr.parse` method returns an object representing the IP address, +or throws an `Error` if the passed string is not a valid representation of an +IP address. + +The `ipaddr.process` method works just like the `ipaddr.parse` one, but it +automatically converts IPv4-mapped IPv6 addresses to their IPv4 couterparts +before returning. It is useful when you have a Node.js instance listening +on an IPv6 socket, and the `net.ivp6.bindv6only` sysctl parameter (or its +equivalent on non-Linux OS) is set to 0. In this case, you can accept IPv4 +connections on your IPv6-only socket, but the remote address will be mangled. +Use `ipaddr.process` method to automatically demangle it. + +### Object representation + +Parsing methods return an object which descends from `ipaddr.IPv6` or +`ipaddr.IPv4`. These objects share some properties, but most of them differ. + +#### Shared properties + +One can determine the type of address by calling `addr.kind()`. It will return +either `"ipv6"` or `"ipv4"`. + +An address can be converted back to its string representation with `addr.toString()`. +Note that this method: + * does not return the original string used to create the object (in fact, there is + no way of getting that string) + * returns a compact representation (when it is applicable) + +A `match(range, bits)` method can be used to check if the address falls into a +certain CIDR range. +Note that an address can be (obviously) matched only against an address of the same type. + +For example: + +```js +var addr = ipaddr.parse("2001:db8:1234::1"); +var range = ipaddr.parse("2001:db8::"); + +addr.match(range, 32); // => true +``` + +A `range()` method returns one of predefined names for several special ranges defined +by IP protocols. The exact names (and their respective CIDR ranges) can be looked up +in the source: [IPv6 ranges] and [IPv4 ranges]. Some common ones include `"unicast"` +(the default one) and `"reserved"`. + +You can match against your own range list by using +`ipaddr.subnetMatch(address, rangeList, defaultName)` method. It can work with both +IPv6 and IPv4 addresses, and accepts a name-to-subnet map as the range list. For example: + +```js +var rangeList = { + documentationOnly: [ ipaddr.parse('2001:db8::'), 32 ], + tunnelProviders: [ + [ ipaddr.parse('2001:470::'), 32 ], // he.net + [ ipaddr.parse('2001:5c0::'), 32 ] // freenet6 + ] +}; +ipaddr.subnetMatch(ipaddr.parse('2001:470:8:66::1'), rangeList, 'unknown'); // => "he.net" +``` + +The addresses can be converted to their byte representation with `toByteArray()`. +(Actually, JavaScript mostly does not know about byte buffers. They are emulated with +arrays of numbers, each in range of 0..255.) + +```js +var bytes = ipaddr.parse('2a00:1450:8007::68').toByteArray(); // ipv6.google.com +bytes // => [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, , 0x00, 0x68 ] +``` + +The `ipaddr.IPv4` and `ipaddr.IPv6` objects have some methods defined, too. All of them +have the same interface for both protocols, and are similar to global methods. + +`ipaddr.IPvX.isValid(string)` can be used to check if the string is a valid address +for particular protocol, and `ipaddr.IPvX.parse(string)` is the error-throwing parser. + +[IPv6 ranges]: https://github.com/whitequark/ipaddr.js/blob/master/src/ipaddr.coffee#L186 +[IPv4 ranges]: https://github.com/whitequark/ipaddr.js/blob/master/src/ipaddr.coffee#L71 + +#### IPv6 properties + +Sometimes you will want to convert IPv6 not to a compact string representation (with +the `::` substitution); the `toNormalizedString()` method will return an address where +all zeroes are explicit. + +For example: + +```js +var addr = ipaddr.parse("2001:0db8::0001"); +addr.toString(); // => "2001:db8::1" +addr.toNormalizedString(); // => "2001:db8:0:0:0:0:0:1" +``` + +The `isIPv4MappedAddress()` method will return `true` if this address is an IPv4-mapped +one, and `toIPv4Address()` will return an IPv4 object address. + +To access the underlying binary representation of the address, use `addr.parts`. + +```js +var addr = ipaddr.parse("2001:db8:10::1234:DEAD"); +addr.parts // => [0x2001, 0xdb8, 0x10, 0, 0, 0, 0x1234, 0xdead] +``` + +#### IPv4 properties + +`toIPv4MappedAddress()` will return a corresponding IPv4-mapped IPv6 address. + +To access the underlying representation of the address, use `addr.octets`. + +```js +var addr = ipaddr.parse("192.168.1.1"); +addr.octets // => [192, 168, 1, 1] +``` diff --git a/node_modules/ipaddr.js/ipaddr.min.js b/node_modules/ipaddr.js/ipaddr.min.js new file mode 100644 index 0000000..59634ff --- /dev/null +++ b/node_modules/ipaddr.js/ipaddr.min.js @@ -0,0 +1 @@ +(function(){var t,r,n,e,i,o,a,s;r={},s=this,"undefined"!=typeof module&&null!==module&&module.exports?module.exports=r:s.ipaddr=r,a=function(t,r,n,e){var i,o;if(t.length!==r.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");for(i=0;e>0;){if(o=n-e,0>o&&(o=0),t[i]>>o!==r[i]>>o)return!1;e-=n,i+=1}return!0},r.subnetMatch=function(t,r,n){var e,i,o,a,s;null==n&&(n="unicast");for(e in r)for(i=r[e],"[object Array]"!==toString.call(i[0])&&(i=[i]),a=0,s=i.length;s>a;a++)if(o=i[a],t.match.apply(t,o))return e;return n},r.IPv4=function(){function t(t){var r,n,e;if(4!==t.length)throw new Error("ipaddr: ipv4 octet count should be 4");for(n=0,e=t.length;e>n;n++)if(r=t[n],!(r>=0&&255>=r))throw new Error("ipaddr: ipv4 octet is a byte");this.octets=t}return t.prototype.kind=function(){return"ipv4"},t.prototype.toString=function(){return this.octets.join(".")},t.prototype.toByteArray=function(){return this.octets.slice(0)},t.prototype.match=function(t,r){if("ipv4"!==t.kind())throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return a(this.octets,t.octets,8,r)},t.prototype.SpecialRanges={unspecified:[[new t([0,0,0,0]),8]],broadcast:[[new t([255,255,255,255]),32]],multicast:[[new t([224,0,0,0]),4]],linkLocal:[[new t([169,254,0,0]),16]],loopback:[[new t([127,0,0,0]),8]],"private":[[new t([10,0,0,0]),8],[new t([172,16,0,0]),12],[new t([192,168,0,0]),16]],reserved:[[new t([192,0,0,0]),24],[new t([192,0,2,0]),24],[new t([192,88,99,0]),24],[new t([198,51,100,0]),24],[new t([203,0,113,0]),24],[new t([240,0,0,0]),4]]},t.prototype.range=function(){return r.subnetMatch(this,this.SpecialRanges)},t.prototype.toIPv4MappedAddress=function(){return r.IPv6.parse("::ffff:"+this.toString())},t}(),n="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:new RegExp("^"+n+"\\."+n+"\\."+n+"\\."+n+"$","i"),longValue:new RegExp("^"+n+"$","i")},r.IPv4.parser=function(t){var r,n,i,o,a;if(n=function(t){return"0"===t[0]&&"x"!==t[1]?parseInt(t,8):parseInt(t)},r=t.match(e.fourOctet))return function(){var t,e,o,a;for(o=r.slice(1,6),a=[],t=0,e=o.length;e>t;t++)i=o[t],a.push(n(i));return a}();if(r=t.match(e.longValue)){if(a=n(r[1]),a>4294967295||0>a)throw new Error("ipaddr: address outside defined range");return function(){var t,r;for(r=[],o=t=0;24>=t;o=t+=8)r.push(a>>o&255);return r}().reverse()}return null},r.IPv6=function(){function t(t){var r,n,e;if(8!==t.length)throw new Error("ipaddr: ipv6 part count should be 8");for(n=0,e=t.length;e>n;n++)if(r=t[n],!(r>=0&&65535>=r))throw new Error("ipaddr: ipv6 part should fit to two octets");this.parts=t}return t.prototype.kind=function(){return"ipv6"},t.prototype.toString=function(){var t,r,n,e,i,o,a;for(i=function(){var t,n,e,i;for(e=this.parts,i=[],t=0,n=e.length;n>t;t++)r=e[t],i.push(r.toString(16));return i}.call(this),t=[],n=function(r){return t.push(r)},e=0,o=0,a=i.length;a>o;o++)switch(r=i[o],e){case 0:n("0"===r?"":r),e=1;break;case 1:"0"===r?e=2:n(r);break;case 2:"0"!==r&&(n(""),n(r),e=3);break;case 3:n(r)}return 2===e&&(n(""),n("")),t.join(":")},t.prototype.toByteArray=function(){var t,r,n,e,i;for(t=[],i=this.parts,n=0,e=i.length;e>n;n++)r=i[n],t.push(r>>8),t.push(255&r);return t},t.prototype.toNormalizedString=function(){var t;return function(){var r,n,e,i;for(e=this.parts,i=[],r=0,n=e.length;n>r;r++)t=e[r],i.push(t.toString(16));return i}.call(this).join(":")},t.prototype.match=function(t,r){if("ipv6"!==t.kind())throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return a(this.parts,t.parts,16,r)},t.prototype.SpecialRanges={unspecified:[new t([0,0,0,0,0,0,0,0]),128],linkLocal:[new t([65152,0,0,0,0,0,0,0]),10],multicast:[new t([65280,0,0,0,0,0,0,0]),8],loopback:[new t([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new t([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new t([0,0,0,0,0,65535,0,0]),96],rfc6145:[new t([0,0,0,0,65535,0,0,0]),96],rfc6052:[new t([100,65435,0,0,0,0,0,0]),96],"6to4":[new t([8194,0,0,0,0,0,0,0]),16],teredo:[new t([8193,0,0,0,0,0,0,0]),32],reserved:[[new t([8193,3512,0,0,0,0,0,0]),32]]},t.prototype.range=function(){return r.subnetMatch(this,this.SpecialRanges)},t.prototype.isIPv4MappedAddress=function(){return"ipv4Mapped"===this.range()},t.prototype.toIPv4Address=function(){var t,n,e;if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");return e=this.parts.slice(-2),t=e[0],n=e[1],new r.IPv4([t>>8,255&t,n>>8,255&n])},t}(),i="(?:[0-9a-f]+::?)+",o={"native":new RegExp("^(::)?("+i+")?([0-9a-f]+)?(::)?$","i"),transitional:new RegExp("^((?:"+i+")|(?:::)(?:"+i+")?)"+(""+n+"\\."+n+"\\."+n+"\\."+n+"$"),"i")},t=function(t,r){var n,e,i,o,a;if(t.indexOf("::")!==t.lastIndexOf("::"))return null;for(n=0,e=-1;(e=t.indexOf(":",e+1))>=0;)n++;if(":"===t[0]&&n--,":"===t[t.length-1]&&n--,n>r)return null;for(a=r-n,o=":";a--;)o+="0:";return t=t.replace("::",o),":"===t[0]&&(t=t.slice(1)),":"===t[t.length-1]&&(t=t.slice(0,-1)),function(){var r,n,e,o;for(e=t.split(":"),o=[],r=0,n=e.length;n>r;r++)i=e[r],o.push(parseInt(i,16));return o}()},r.IPv6.parser=function(r){var n,e;return r.match(o["native"])?t(r,8):(n=r.match(o.transitional))&&(e=t(n[1].slice(0,-1),6))?(e.push(parseInt(n[2])<<8|parseInt(n[3])),e.push(parseInt(n[4])<<8|parseInt(n[5])),e):null},r.IPv4.isIPv4=r.IPv6.isIPv6=function(t){return null!==this.parser(t)},r.IPv4.isValid=r.IPv6.isValid=function(t){var r;try{return new this(this.parser(t)),!0}catch(n){return r=n,!1}},r.IPv4.parse=r.IPv6.parse=function(t){var r;if(r=this.parser(t),null===r)throw new Error("ipaddr: string is not formatted like ip address");return new this(r)},r.isValid=function(t){return r.IPv6.isValid(t)||r.IPv4.isValid(t)},r.parse=function(t){if(r.IPv6.isValid(t))return r.IPv6.parse(t);if(r.IPv4.isValid(t))return r.IPv4.parse(t);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},r.process=function(t){var r;return r=this.parse(t),"ipv6"===r.kind()&&r.isIPv4MappedAddress()?r.toIPv4Address():r}}).call(this); \ No newline at end of file diff --git a/node_modules/ipaddr.js/lib/ipaddr.js b/node_modules/ipaddr.js/lib/ipaddr.js new file mode 100644 index 0000000..00620a8 --- /dev/null +++ b/node_modules/ipaddr.js/lib/ipaddr.js @@ -0,0 +1,408 @@ +(function() { + var expandIPv6, ipaddr, ipv4Part, ipv4Regexes, ipv6Part, ipv6Regexes, matchCIDR, root; + + ipaddr = {}; + + root = this; + + if ((typeof module !== "undefined" && module !== null) && module.exports) { + module.exports = ipaddr; + } else { + root['ipaddr'] = ipaddr; + } + + matchCIDR = function(first, second, partSize, cidrBits) { + var part, shift; + if (first.length !== second.length) { + throw new Error("ipaddr: cannot match CIDR for objects with different lengths"); + } + part = 0; + while (cidrBits > 0) { + shift = partSize - cidrBits; + if (shift < 0) { + shift = 0; + } + if (first[part] >> shift !== second[part] >> shift) { + return false; + } + cidrBits -= partSize; + part += 1; + } + return true; + }; + + ipaddr.subnetMatch = function(address, rangeList, defaultName) { + var rangeName, rangeSubnets, subnet, _i, _len; + if (defaultName == null) { + defaultName = 'unicast'; + } + for (rangeName in rangeList) { + rangeSubnets = rangeList[rangeName]; + if (toString.call(rangeSubnets[0]) !== '[object Array]') { + rangeSubnets = [rangeSubnets]; + } + for (_i = 0, _len = rangeSubnets.length; _i < _len; _i++) { + subnet = rangeSubnets[_i]; + if (address.match.apply(address, subnet)) { + return rangeName; + } + } + } + return defaultName; + }; + + ipaddr.IPv4 = (function() { + function IPv4(octets) { + var octet, _i, _len; + if (octets.length !== 4) { + throw new Error("ipaddr: ipv4 octet count should be 4"); + } + for (_i = 0, _len = octets.length; _i < _len; _i++) { + octet = octets[_i]; + if (!((0 <= octet && octet <= 255))) { + throw new Error("ipaddr: ipv4 octet is a byte"); + } + } + this.octets = octets; + } + + IPv4.prototype.kind = function() { + return 'ipv4'; + }; + + IPv4.prototype.toString = function() { + return this.octets.join("."); + }; + + IPv4.prototype.toByteArray = function() { + return this.octets.slice(0); + }; + + IPv4.prototype.match = function(other, cidrRange) { + if (other.kind() !== 'ipv4') { + throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one"); + } + return matchCIDR(this.octets, other.octets, 8, cidrRange); + }; + + IPv4.prototype.SpecialRanges = { + unspecified: [[new IPv4([0, 0, 0, 0]), 8]], + broadcast: [[new IPv4([255, 255, 255, 255]), 32]], + multicast: [[new IPv4([224, 0, 0, 0]), 4]], + linkLocal: [[new IPv4([169, 254, 0, 0]), 16]], + loopback: [[new IPv4([127, 0, 0, 0]), 8]], + "private": [[new IPv4([10, 0, 0, 0]), 8], [new IPv4([172, 16, 0, 0]), 12], [new IPv4([192, 168, 0, 0]), 16]], + reserved: [[new IPv4([192, 0, 0, 0]), 24], [new IPv4([192, 0, 2, 0]), 24], [new IPv4([192, 88, 99, 0]), 24], [new IPv4([198, 51, 100, 0]), 24], [new IPv4([203, 0, 113, 0]), 24], [new IPv4([240, 0, 0, 0]), 4]] + }; + + IPv4.prototype.range = function() { + return ipaddr.subnetMatch(this, this.SpecialRanges); + }; + + IPv4.prototype.toIPv4MappedAddress = function() { + return ipaddr.IPv6.parse("::ffff:" + (this.toString())); + }; + + return IPv4; + + })(); + + ipv4Part = "(0?\\d+|0x[a-f0-9]+)"; + + ipv4Regexes = { + fourOctet: new RegExp("^" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$", 'i'), + longValue: new RegExp("^" + ipv4Part + "$", 'i') + }; + + ipaddr.IPv4.parser = function(string) { + var match, parseIntAuto, part, shift, value; + parseIntAuto = function(string) { + if (string[0] === "0" && string[1] !== "x") { + return parseInt(string, 8); + } else { + return parseInt(string); + } + }; + if (match = string.match(ipv4Regexes.fourOctet)) { + return (function() { + var _i, _len, _ref, _results; + _ref = match.slice(1, 6); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + part = _ref[_i]; + _results.push(parseIntAuto(part)); + } + return _results; + })(); + } else if (match = string.match(ipv4Regexes.longValue)) { + value = parseIntAuto(match[1]); + if (value > 0xffffffff || value < 0) { + throw new Error("ipaddr: address outside defined range"); + } + return ((function() { + var _i, _results; + _results = []; + for (shift = _i = 0; _i <= 24; shift = _i += 8) { + _results.push((value >> shift) & 0xff); + } + return _results; + })()).reverse(); + } else { + return null; + } + }; + + ipaddr.IPv6 = (function() { + function IPv6(parts) { + var part, _i, _len; + if (parts.length !== 8) { + throw new Error("ipaddr: ipv6 part count should be 8"); + } + for (_i = 0, _len = parts.length; _i < _len; _i++) { + part = parts[_i]; + if (!((0 <= part && part <= 0xffff))) { + throw new Error("ipaddr: ipv6 part should fit to two octets"); + } + } + this.parts = parts; + } + + IPv6.prototype.kind = function() { + return 'ipv6'; + }; + + IPv6.prototype.toString = function() { + var compactStringParts, part, pushPart, state, stringParts, _i, _len; + stringParts = (function() { + var _i, _len, _ref, _results; + _ref = this.parts; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + part = _ref[_i]; + _results.push(part.toString(16)); + } + return _results; + }).call(this); + compactStringParts = []; + pushPart = function(part) { + return compactStringParts.push(part); + }; + state = 0; + for (_i = 0, _len = stringParts.length; _i < _len; _i++) { + part = stringParts[_i]; + switch (state) { + case 0: + if (part === '0') { + pushPart(''); + } else { + pushPart(part); + } + state = 1; + break; + case 1: + if (part === '0') { + state = 2; + } else { + pushPart(part); + } + break; + case 2: + if (part !== '0') { + pushPart(''); + pushPart(part); + state = 3; + } + break; + case 3: + pushPart(part); + } + } + if (state === 2) { + pushPart(''); + pushPart(''); + } + return compactStringParts.join(":"); + }; + + IPv6.prototype.toByteArray = function() { + var bytes, part, _i, _len, _ref; + bytes = []; + _ref = this.parts; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + part = _ref[_i]; + bytes.push(part >> 8); + bytes.push(part & 0xff); + } + return bytes; + }; + + IPv6.prototype.toNormalizedString = function() { + var part; + return ((function() { + var _i, _len, _ref, _results; + _ref = this.parts; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + part = _ref[_i]; + _results.push(part.toString(16)); + } + return _results; + }).call(this)).join(":"); + }; + + IPv6.prototype.match = function(other, cidrRange) { + if (other.kind() !== 'ipv6') { + throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one"); + } + return matchCIDR(this.parts, other.parts, 16, cidrRange); + }; + + IPv6.prototype.SpecialRanges = { + unspecified: [new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128], + linkLocal: [new IPv6([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 10], + multicast: [new IPv6([0xff00, 0, 0, 0, 0, 0, 0, 0]), 8], + loopback: [new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128], + uniqueLocal: [new IPv6([0xfc00, 0, 0, 0, 0, 0, 0, 0]), 7], + ipv4Mapped: [new IPv6([0, 0, 0, 0, 0, 0xffff, 0, 0]), 96], + rfc6145: [new IPv6([0, 0, 0, 0, 0xffff, 0, 0, 0]), 96], + rfc6052: [new IPv6([0x64, 0xff9b, 0, 0, 0, 0, 0, 0]), 96], + '6to4': [new IPv6([0x2002, 0, 0, 0, 0, 0, 0, 0]), 16], + teredo: [new IPv6([0x2001, 0, 0, 0, 0, 0, 0, 0]), 32], + reserved: [[new IPv6([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]), 32]] + }; + + IPv6.prototype.range = function() { + return ipaddr.subnetMatch(this, this.SpecialRanges); + }; + + IPv6.prototype.isIPv4MappedAddress = function() { + return this.range() === 'ipv4Mapped'; + }; + + IPv6.prototype.toIPv4Address = function() { + var high, low, _ref; + if (!this.isIPv4MappedAddress()) { + throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4"); + } + _ref = this.parts.slice(-2), high = _ref[0], low = _ref[1]; + return new ipaddr.IPv4([high >> 8, high & 0xff, low >> 8, low & 0xff]); + }; + + return IPv6; + + })(); + + ipv6Part = "(?:[0-9a-f]+::?)+"; + + ipv6Regexes = { + "native": new RegExp("^(::)?(" + ipv6Part + ")?([0-9a-f]+)?(::)?$", 'i'), + transitional: new RegExp(("^((?:" + ipv6Part + ")|(?:::)(?:" + ipv6Part + ")?)") + ("" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$"), 'i') + }; + + expandIPv6 = function(string, parts) { + var colonCount, lastColon, part, replacement, replacementCount; + if (string.indexOf('::') !== string.lastIndexOf('::')) { + return null; + } + colonCount = 0; + lastColon = -1; + while ((lastColon = string.indexOf(':', lastColon + 1)) >= 0) { + colonCount++; + } + if (string[0] === ':') { + colonCount--; + } + if (string[string.length - 1] === ':') { + colonCount--; + } + if (colonCount > parts) { + return null; + } + replacementCount = parts - colonCount; + replacement = ':'; + while (replacementCount--) { + replacement += '0:'; + } + string = string.replace('::', replacement); + if (string[0] === ':') { + string = string.slice(1); + } + if (string[string.length - 1] === ':') { + string = string.slice(0, -1); + } + return (function() { + var _i, _len, _ref, _results; + _ref = string.split(":"); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + part = _ref[_i]; + _results.push(parseInt(part, 16)); + } + return _results; + })(); + }; + + ipaddr.IPv6.parser = function(string) { + var match, parts; + if (string.match(ipv6Regexes['native'])) { + return expandIPv6(string, 8); + } else if (match = string.match(ipv6Regexes['transitional'])) { + parts = expandIPv6(match[1].slice(0, -1), 6); + if (parts) { + parts.push(parseInt(match[2]) << 8 | parseInt(match[3])); + parts.push(parseInt(match[4]) << 8 | parseInt(match[5])); + return parts; + } + } + return null; + }; + + ipaddr.IPv4.isIPv4 = ipaddr.IPv6.isIPv6 = function(string) { + return this.parser(string) !== null; + }; + + ipaddr.IPv4.isValid = ipaddr.IPv6.isValid = function(string) { + var e; + try { + new this(this.parser(string)); + return true; + } catch (_error) { + e = _error; + return false; + } + }; + + ipaddr.IPv4.parse = ipaddr.IPv6.parse = function(string) { + var parts; + parts = this.parser(string); + if (parts === null) { + throw new Error("ipaddr: string is not formatted like ip address"); + } + return new this(parts); + }; + + ipaddr.isValid = function(string) { + return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string); + }; + + ipaddr.parse = function(string) { + if (ipaddr.IPv6.isValid(string)) { + return ipaddr.IPv6.parse(string); + } else if (ipaddr.IPv4.isValid(string)) { + return ipaddr.IPv4.parse(string); + } else { + throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format"); + } + }; + + ipaddr.process = function(string) { + var addr; + addr = this.parse(string); + if (addr.kind() === 'ipv6' && addr.isIPv4MappedAddress()) { + return addr.toIPv4Address(); + } else { + return addr; + } + }; + +}).call(this); diff --git a/node_modules/ipaddr.js/package.json b/node_modules/ipaddr.js/package.json new file mode 100644 index 0000000..442e58e --- /dev/null +++ b/node_modules/ipaddr.js/package.json @@ -0,0 +1,94 @@ +{ + "_args": [ + [ + { + "raw": "ipaddr.js@~0.1.3", + "scope": null, + "escapedName": "ipaddr.js", + "name": "ipaddr.js", + "rawSpec": "~0.1.3", + "spec": ">=0.1.3 <0.2.0", + "type": "range" + }, + "/srv/demos/node_modules/native-dns" + ] + ], + "_from": "ipaddr.js@>=0.1.3 <0.2.0", + "_id": "ipaddr.js@0.1.9", + "_inCache": true, + "_location": "/ipaddr.js", + "_npmUser": { + "name": "whitequark", + "email": "whitequark@whitequark.org" + }, + "_npmVersion": "1.4.21", + "_phantomChildren": {}, + "_requested": { + "raw": "ipaddr.js@~0.1.3", + "scope": null, + "escapedName": "ipaddr.js", + "name": "ipaddr.js", + "rawSpec": "~0.1.3", + "spec": ">=0.1.3 <0.2.0", + "type": "range" + }, + "_requiredBy": [ + "/native-dns", + "/native-dns-packet" + ], + "_resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-0.1.9.tgz", + "_shasum": "a9c78ccc12dc9010f296ab9aef2f61f432d69efa", + "_shrinkwrap": null, + "_spec": "ipaddr.js@~0.1.3", + "_where": "/srv/demos/node_modules/native-dns", + "author": { + "name": "Peter Zotov", + "email": "whitequark@whitequark.org" + }, + "bugs": { + "url": "https://github.com/whitequark/ipaddr.js/issues" + }, + "dependencies": {}, + "description": "A library for manipulating IPv4 and IPv6 addresses in JavaScript.", + "devDependencies": { + "coffee-script": "~1.6", + "nodeunit": "~0.5.3", + "uglify-js": "latest" + }, + "directories": { + "lib": "./lib" + }, + "dist": { + "shasum": "a9c78ccc12dc9010f296ab9aef2f61f432d69efa", + "tarball": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-0.1.9.tgz" + }, + "engines": { + "node": ">= 0.2.5" + }, + "gitHead": "d51df7aa41ef1875215ae4ffbd324c486f8c2799", + "homepage": "https://github.com/whitequark/ipaddr.js#readme", + "keywords": [ + "ip", + "ipv4", + "ipv6" + ], + "license": "MIT", + "main": "./lib/ipaddr", + "maintainers": [ + { + "name": "whitequark", + "email": "whitequark@whitequark.org" + } + ], + "name": "ipaddr.js", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git://github.com/whitequark/ipaddr.js.git" + }, + "scripts": { + "test": "cake build test" + }, + "version": "0.1.9" +} diff --git a/node_modules/ipaddr.js/src/ipaddr.coffee b/node_modules/ipaddr.js/src/ipaddr.coffee new file mode 100644 index 0000000..a6d358e --- /dev/null +++ b/node_modules/ipaddr.js/src/ipaddr.coffee @@ -0,0 +1,353 @@ +# Define the main object +ipaddr = {} + +root = this + +# Export for both the CommonJS and browser-like environment +if module? && module.exports + module.exports = ipaddr +else + root['ipaddr'] = ipaddr + +# A generic CIDR (Classless Inter-Domain Routing) RFC1518 range matcher. +matchCIDR = (first, second, partSize, cidrBits) -> + if first.length != second.length + throw new Error "ipaddr: cannot match CIDR for objects with different lengths" + + part = 0 + while cidrBits > 0 + shift = partSize - cidrBits + shift = 0 if shift < 0 + + if first[part] >> shift != second[part] >> shift + return false + + cidrBits -= partSize + part += 1 + + return true + +# An utility function to ease named range matching. See examples below. +ipaddr.subnetMatch = (address, rangeList, defaultName='unicast') -> + for rangeName, rangeSubnets of rangeList + # ECMA5 Array.isArray isn't available everywhere + if toString.call(rangeSubnets[0]) != '[object Array]' + rangeSubnets = [ rangeSubnets ] + + for subnet in rangeSubnets + return rangeName if address.match.apply(address, subnet) + + return defaultName + +# An IPv4 address (RFC791). +class ipaddr.IPv4 + # Constructs a new IPv4 address from an array of four octets. + # Verifies the input. + constructor: (octets) -> + if octets.length != 4 + throw new Error "ipaddr: ipv4 octet count should be 4" + + for octet in octets + if !(0 <= octet <= 255) + throw new Error "ipaddr: ipv4 octet is a byte" + + @octets = octets + + # The 'kind' method exists on both IPv4 and IPv6 classes. + kind: -> + return 'ipv4' + + # Returns the address in convenient, decimal-dotted format. + toString: -> + return @octets.join "." + + # Returns an array of byte-sized values in network order + toByteArray: -> + return @octets.slice(0) # octets.clone + + # Checks if this address matches other one within given CIDR range. + match: (other, cidrRange) -> + if other.kind() != 'ipv4' + throw new Error "ipaddr: cannot match ipv4 address with non-ipv4 one" + + return matchCIDR(this.octets, other.octets, 8, cidrRange) + + # Special IPv4 address ranges. + SpecialRanges: + unspecified: [ + [ new IPv4([0, 0, 0, 0]), 8 ] + ] + broadcast: [ + [ new IPv4([255, 255, 255, 255]), 32 ] + ] + multicast: [ # RFC3171 + [ new IPv4([224, 0, 0, 0]), 4 ] + ] + linkLocal: [ # RFC3927 + [ new IPv4([169, 254, 0, 0]), 16 ] + ] + loopback: [ # RFC5735 + [ new IPv4([127, 0, 0, 0]), 8 ] + ] + private: [ # RFC1918 + [ new IPv4([10, 0, 0, 0]), 8 ] + [ new IPv4([172, 16, 0, 0]), 12 ] + [ new IPv4([192, 168, 0, 0]), 16 ] + ] + reserved: [ # Reserved and testing-only ranges; RFCs 5735, 5737, 2544, 1700 + [ new IPv4([192, 0, 0, 0]), 24 ] + [ new IPv4([192, 0, 2, 0]), 24 ] + [ new IPv4([192, 88, 99, 0]), 24 ] + [ new IPv4([198, 51, 100, 0]), 24 ] + [ new IPv4([203, 0, 113, 0]), 24 ] + [ new IPv4([240, 0, 0, 0]), 4 ] + ] + + # Checks if the address corresponds to one of the special ranges. + range: -> + return ipaddr.subnetMatch(this, @SpecialRanges) + + # Convrets this IPv4 address to an IPv4-mapped IPv6 address. + toIPv4MappedAddress: -> + return ipaddr.IPv6.parse "::ffff:#{@toString()}" + +# A list of regular expressions that match arbitrary IPv4 addresses, +# for which a number of weird notations exist. +# Note that an address like 0010.0xa5.1.1 is considered legal. +ipv4Part = "(0?\\d+|0x[a-f0-9]+)" +ipv4Regexes = + fourOctet: new RegExp "^#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}$", 'i' + longValue: new RegExp "^#{ipv4Part}$", 'i' + +# Classful variants (like a.b, where a is an octet, and b is a 24-bit +# value representing last three octets; this corresponds to a class C +# address) are omitted due to classless nature of modern Internet. +ipaddr.IPv4.parser = (string) -> + parseIntAuto = (string) -> + if string[0] == "0" && string[1] != "x" + parseInt(string, 8) + else + parseInt(string) + + # parseInt recognizes all that octal & hexadecimal weirdness for us + if match = string.match(ipv4Regexes.fourOctet) + return (parseIntAuto(part) for part in match[1..5]) + else if match = string.match(ipv4Regexes.longValue) + value = parseIntAuto(match[1]) + if value > 0xffffffff || value < 0 + throw new Error "ipaddr: address outside defined range" + return ((value >> shift) & 0xff for shift in [0..24] by 8).reverse() + else + return null + +# An IPv6 address (RFC2460) +class ipaddr.IPv6 + # Constructs an IPv6 address from an array of eight 16-bit parts. + # Throws an error if the input is invalid. + constructor: (parts) -> + if parts.length != 8 + throw new Error "ipaddr: ipv6 part count should be 8" + + for part in parts + if !(0 <= part <= 0xffff) + throw new Error "ipaddr: ipv6 part should fit to two octets" + + @parts = parts + + # The 'kind' method exists on both IPv4 and IPv6 classes. + kind: -> + return 'ipv6' + + # Returns the address in compact, human-readable format like + # 2001:db8:8:66::1 + toString: -> + stringParts = (part.toString(16) for part in @parts) + + compactStringParts = [] + pushPart = (part) -> compactStringParts.push part + + state = 0 + for part in stringParts + switch state + when 0 + if part == '0' + pushPart('') + else + pushPart(part) + + state = 1 + when 1 + if part == '0' + state = 2 + else + pushPart(part) + when 2 + unless part == '0' + pushPart('') + pushPart(part) + state = 3 + when 3 + pushPart(part) + + if state == 2 + pushPart('') + pushPart('') + + return compactStringParts.join ":" + + # Returns an array of byte-sized values in network order + toByteArray: -> + bytes = [] + for part in @parts + bytes.push(part >> 8) + bytes.push(part & 0xff) + + return bytes + + # Returns the address in expanded format with all zeroes included, like + # 2001:db8:8:66:0:0:0:1 + toNormalizedString: -> + return (part.toString(16) for part in @parts).join ":" + + # Checks if this address matches other one within given CIDR range. + match: (other, cidrRange) -> + if other.kind() != 'ipv6' + throw new Error "ipaddr: cannot match ipv6 address with non-ipv6 one" + + return matchCIDR(this.parts, other.parts, 16, cidrRange) + + # Special IPv6 ranges + SpecialRanges: + unspecified: [ new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128 ] # RFC4291, here and after + linkLocal: [ new IPv6([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 10 ] + multicast: [ new IPv6([0xff00, 0, 0, 0, 0, 0, 0, 0]), 8 ] + loopback: [ new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128 ] + uniqueLocal: [ new IPv6([0xfc00, 0, 0, 0, 0, 0, 0, 0]), 7 ] + ipv4Mapped: [ new IPv6([0, 0, 0, 0, 0, 0xffff, 0, 0]), 96 ] + rfc6145: [ new IPv6([0, 0, 0, 0, 0xffff, 0, 0, 0]), 96 ] # RFC6145 + rfc6052: [ new IPv6([0x64, 0xff9b, 0, 0, 0, 0, 0, 0]), 96 ] # RFC6052 + '6to4': [ new IPv6([0x2002, 0, 0, 0, 0, 0, 0, 0]), 16 ] # RFC3056 + teredo: [ new IPv6([0x2001, 0, 0, 0, 0, 0, 0, 0]), 32 ] # RFC6052, RFC6146 + reserved: [ + [ new IPv6([ 0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]), 32 ] # RFC4291 + ] + + # Checks if the address corresponds to one of the special ranges. + range: -> + return ipaddr.subnetMatch(this, @SpecialRanges) + + # Checks if this address is an IPv4-mapped IPv6 address. + isIPv4MappedAddress: -> + return @range() == 'ipv4Mapped' + + # Converts this address to IPv4 address if it is an IPv4-mapped IPv6 address. + # Throws an error otherwise. + toIPv4Address: -> + unless @isIPv4MappedAddress() + throw new Error "ipaddr: trying to convert a generic ipv6 address to ipv4" + + [high, low] = @parts[-2..-1] + + return new ipaddr.IPv4([high >> 8, high & 0xff, low >> 8, low & 0xff]) + +# IPv6-matching regular expressions. +# For IPv6, the task is simpler: it is enough to match the colon-delimited +# hexadecimal IPv6 and a transitional variant with dotted-decimal IPv4 at +# the end. +ipv6Part = "(?:[0-9a-f]+::?)+" +ipv6Regexes = + native: new RegExp "^(::)?(#{ipv6Part})?([0-9a-f]+)?(::)?$", 'i' + transitional: new RegExp "^((?:#{ipv6Part})|(?:::)(?:#{ipv6Part})?)" + + "#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}$", 'i' + +# Expand :: in an IPv6 address or address part consisting of `parts` groups. +expandIPv6 = (string, parts) -> + # More than one '::' means invalid adddress + if string.indexOf('::') != string.lastIndexOf('::') + return null + + # How many parts do we already have? + colonCount = 0 + lastColon = -1 + while (lastColon = string.indexOf(':', lastColon + 1)) >= 0 + colonCount++ + + # 0::0 is two parts more than :: + colonCount-- if string[0] == ':' + colonCount-- if string[string.length-1] == ':' + + # The following loop would hang if colonCount > parts + if colonCount > parts + return null + + # replacement = ':' + '0:' * (parts - colonCount) + replacementCount = parts - colonCount + replacement = ':' + while replacementCount-- + replacement += '0:' + + # Insert the missing zeroes + string = string.replace('::', replacement) + + # Trim any garbage which may be hanging around if :: was at the edge in + # the source string + string = string[1..-1] if string[0] == ':' + string = string[0..-2] if string[string.length-1] == ':' + + return (parseInt(part, 16) for part in string.split(":")) + +# Parse an IPv6 address. +ipaddr.IPv6.parser = (string) -> + if string.match(ipv6Regexes['native']) + return expandIPv6(string, 8) + + else if match = string.match(ipv6Regexes['transitional']) + parts = expandIPv6(match[1][0..-2], 6) + if parts + parts.push(parseInt(match[2]) << 8 | parseInt(match[3])) + parts.push(parseInt(match[4]) << 8 | parseInt(match[5])) + return parts + + return null + +# Checks if a given string is formatted like IPv4/IPv6 address. +ipaddr.IPv4.isIPv4 = ipaddr.IPv6.isIPv6 = (string) -> + return @parser(string) != null + +# Checks if a given string is a valid IPv4/IPv6 address. +ipaddr.IPv4.isValid = ipaddr.IPv6.isValid = (string) -> + try + new this(@parser(string)) + return true + catch e + return false + +# Tries to parse and validate a string with IPv4/IPv6 address. +# Throws an error if it fails. +ipaddr.IPv4.parse = ipaddr.IPv6.parse = (string) -> + parts = @parser(string) + if parts == null + throw new Error "ipaddr: string is not formatted like ip address" + + return new this(parts) + +# Checks if the address is valid IP address +ipaddr.isValid = (string) -> + return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string) + +# Try to parse an address and throw an error if it is impossible +ipaddr.parse = (string) -> + if ipaddr.IPv6.isValid(string) + return ipaddr.IPv6.parse(string) + else if ipaddr.IPv4.isValid(string) + return ipaddr.IPv4.parse(string) + else + throw new Error "ipaddr: the address has neither IPv6 nor IPv4 format" + +# Parse an address and return plain IPv4 address if it is an IPv4-mapped address +ipaddr.process = (string) -> + addr = @parse(string) + if addr.kind() == 'ipv6' && addr.isIPv4MappedAddress() + return addr.toIPv4Address() + else + return addr diff --git a/node_modules/ipaddr.js/test/ipaddr.test.coffee b/node_modules/ipaddr.js/test/ipaddr.test.coffee new file mode 100644 index 0000000..627503d --- /dev/null +++ b/node_modules/ipaddr.js/test/ipaddr.test.coffee @@ -0,0 +1,226 @@ +ipaddr = require '../lib/ipaddr' + +module.exports = + 'should define main classes': (test) -> + test.ok(ipaddr.IPv4?, 'defines IPv4 class') + test.ok(ipaddr.IPv6?, 'defines IPv6 class') + test.done() + + 'can construct IPv4 from octets': (test) -> + test.doesNotThrow -> + new ipaddr.IPv4([192, 168, 1, 2]) + test.done() + + 'refuses to construct invalid IPv4': (test) -> + test.throws -> + new ipaddr.IPv4([300, 1, 2, 3]) + test.throws -> + new ipaddr.IPv4([8, 8, 8]) + test.done() + + 'converts IPv4 to string correctly': (test) -> + addr = new ipaddr.IPv4([192, 168, 1, 1]) + test.equal(addr.toString(), '192.168.1.1') + test.done() + + 'returns correct kind for IPv4': (test) -> + addr = new ipaddr.IPv4([1, 2, 3, 4]) + test.equal(addr.kind(), 'ipv4') + test.done() + + 'allows to access IPv4 octets': (test) -> + addr = new ipaddr.IPv4([42, 0, 0, 0]) + test.equal(addr.octets[0], 42) + test.done() + + 'checks IPv4 address format': (test) -> + test.equal(ipaddr.IPv4.isIPv4('192.168.007.0xa'), true) + test.equal(ipaddr.IPv4.isIPv4('1024.0.0.1'), true) + test.equal(ipaddr.IPv4.isIPv4('8.0xa.wtf.6'), false) + test.done() + + 'validates IPv4 addresses': (test) -> + test.equal(ipaddr.IPv4.isValid('192.168.007.0xa'), true) + test.equal(ipaddr.IPv4.isValid('1024.0.0.1'), false) + test.equal(ipaddr.IPv4.isValid('8.0xa.wtf.6'), false) + test.done() + + 'parses IPv4 in several weird formats': (test) -> + test.deepEqual(ipaddr.IPv4.parse('192.168.1.1').octets, [192, 168, 1, 1]) + test.deepEqual(ipaddr.IPv4.parse('0xc0.168.1.1').octets, [192, 168, 1, 1]) + test.deepEqual(ipaddr.IPv4.parse('192.0250.1.1').octets, [192, 168, 1, 1]) + test.deepEqual(ipaddr.IPv4.parse('0xc0a80101').octets, [192, 168, 1, 1]) + test.deepEqual(ipaddr.IPv4.parse('030052000401').octets, [192, 168, 1, 1]) + test.deepEqual(ipaddr.IPv4.parse('3232235777').octets, [192, 168, 1, 1]) + test.done() + + 'barfs at invalid IPv4': (test) -> + test.throws -> + ipaddr.IPv4.parse('10.0.0.wtf') + test.done() + + 'matches IPv4 CIDR correctly': (test) -> + addr = new ipaddr.IPv4([10, 5, 0, 1]) + test.equal(addr.match(ipaddr.IPv4.parse('0.0.0.0'), 0), true) + test.equal(addr.match(ipaddr.IPv4.parse('11.0.0.0'), 8), false) + test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.0'), 8), true) + test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.1'), 8), true) + test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.10'), 8), true) + test.equal(addr.match(ipaddr.IPv4.parse('10.5.5.0'), 16), true) + test.equal(addr.match(ipaddr.IPv4.parse('10.4.5.0'), 16), false) + test.equal(addr.match(ipaddr.IPv4.parse('10.4.5.0'), 15), true) + test.equal(addr.match(ipaddr.IPv4.parse('10.5.0.2'), 32), false) + test.equal(addr.match(addr, 32), true) + test.done() + + 'detects reserved IPv4 networks': (test) -> + test.equal(ipaddr.IPv4.parse('0.0.0.0').range(), 'unspecified') + test.equal(ipaddr.IPv4.parse('0.1.0.0').range(), 'unspecified') + test.equal(ipaddr.IPv4.parse('10.1.0.1').range(), 'private') + test.equal(ipaddr.IPv4.parse('192.168.2.1').range(), 'private') + test.equal(ipaddr.IPv4.parse('224.100.0.1').range(), 'multicast') + test.equal(ipaddr.IPv4.parse('169.254.15.0').range(), 'linkLocal') + test.equal(ipaddr.IPv4.parse('127.1.1.1').range(), 'loopback') + test.equal(ipaddr.IPv4.parse('255.255.255.255').range(), 'broadcast') + test.equal(ipaddr.IPv4.parse('240.1.2.3').range(), 'reserved') + test.equal(ipaddr.IPv4.parse('8.8.8.8').range(), 'unicast') + test.done() + + 'can construct IPv6 from parts': (test) -> + test.doesNotThrow -> + new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1]) + test.done() + + 'refuses to construct invalid IPv6': (test) -> + test.throws -> + new ipaddr.IPv6([0xfffff, 0, 0, 0, 0, 0, 0, 1]) + test.throws -> + new ipaddr.IPv6([0xfffff, 0, 0, 0, 0, 0, 1]) + test.done() + + 'converts IPv6 to string correctly': (test) -> + addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1]) + test.equal(addr.toNormalizedString(), '2001:db8:f53a:0:0:0:0:1') + test.equal(addr.toString(), '2001:db8:f53a::1') + test.equal(new ipaddr.IPv6([0, 0, 0, 0, 0, 0, 0, 1]).toString(), '::1') + test.equal(new ipaddr.IPv6([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]).toString(), '2001:db8::') + test.done() + + 'returns correct kind for IPv6': (test) -> + addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1]) + test.equal(addr.kind(), 'ipv6') + test.done() + + 'allows to access IPv6 address parts': (test) -> + addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 42, 0, 1]) + test.equal(addr.parts[5], 42) + test.done() + + 'checks IPv6 address format': (test) -> + test.equal(ipaddr.IPv6.isIPv6('2001:db8:F53A::1'), true) + test.equal(ipaddr.IPv6.isIPv6('200001::1'), true) + test.equal(ipaddr.IPv6.isIPv6('::ffff:192.168.1.1'), true) + test.equal(ipaddr.IPv6.isIPv6('::ffff:300.168.1.1'), true) + test.equal(ipaddr.IPv6.isIPv6('::ffff:300.168.1.1:0'), false) + test.equal(ipaddr.IPv6.isIPv6('fe80::wtf'), false) + test.done() + + 'validates IPv6 addresses': (test) -> + test.equal(ipaddr.IPv6.isValid('2001:db8:F53A::1'), true) + test.equal(ipaddr.IPv6.isValid('200001::1'), false) + test.equal(ipaddr.IPv6.isValid('::ffff:192.168.1.1'), true) + test.equal(ipaddr.IPv6.isValid('::ffff:300.168.1.1'), false) + test.equal(ipaddr.IPv6.isValid('::ffff:300.168.1.1:0'), false) + test.equal(ipaddr.IPv6.isValid('2001:db8::F53A::1'), false) + test.equal(ipaddr.IPv6.isValid('fe80::wtf'), false) + test.done() + + 'parses IPv6 in different formats': (test) -> + test.deepEqual(ipaddr.IPv6.parse('2001:db8:F53A:0:0:0:0:1').parts, [0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1]) + test.deepEqual(ipaddr.IPv6.parse('fe80::10').parts, [0xfe80, 0, 0, 0, 0, 0, 0, 0x10]) + test.deepEqual(ipaddr.IPv6.parse('2001:db8:F53A::').parts, [0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 0]) + test.deepEqual(ipaddr.IPv6.parse('::1').parts, [0, 0, 0, 0, 0, 0, 0, 1]) + test.deepEqual(ipaddr.IPv6.parse('::').parts, [0, 0, 0, 0, 0, 0, 0, 0]) + test.done() + + 'barfs at invalid IPv6': (test) -> + test.throws -> + ipaddr.IPv6.parse('fe80::0::1') + test.done() + + 'matches IPv6 CIDR correctly': (test) -> + addr = ipaddr.IPv6.parse('2001:db8:f53a::1') + test.equal(addr.match(ipaddr.IPv6.parse('::'), 0), true) + test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f53a::1:1'), 64), true) + test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f53b::1:1'), 48), false) + test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f531::1:1'), 44), true) + test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f500::1'), 40), true) + test.equal(addr.match(ipaddr.IPv6.parse('2001:db9:f500::1'), 40), false) + test.equal(addr.match(addr, 128), true) + test.done() + + 'converts between IPv4-mapped IPv6 addresses and IPv4 addresses': (test) -> + addr = ipaddr.IPv4.parse('77.88.21.11') + mapped = addr.toIPv4MappedAddress() + test.deepEqual(mapped.parts, [0, 0, 0, 0, 0, 0xffff, 0x4d58, 0x150b]) + test.deepEqual(mapped.toIPv4Address().octets, addr.octets) + test.done() + + 'refuses to convert non-IPv4-mapped IPv6 address to IPv4 address': (test) -> + test.throws -> + ipaddr.IPv6.parse('2001:db8::1').toIPv4Address() + test.done() + + 'detects reserved IPv6 networks': (test) -> + test.equal(ipaddr.IPv6.parse('::').range(), 'unspecified') + test.equal(ipaddr.IPv6.parse('fe80::1234:5678:abcd:0123').range(), 'linkLocal') + test.equal(ipaddr.IPv6.parse('ff00::1234').range(), 'multicast') + test.equal(ipaddr.IPv6.parse('::1').range(), 'loopback') + test.equal(ipaddr.IPv6.parse('fc00::').range(), 'uniqueLocal') + test.equal(ipaddr.IPv6.parse('::ffff:192.168.1.10').range(), 'ipv4Mapped') + test.equal(ipaddr.IPv6.parse('::ffff:0:192.168.1.10').range(), 'rfc6145') + test.equal(ipaddr.IPv6.parse('64:ff9b::1234').range(), 'rfc6052') + test.equal(ipaddr.IPv6.parse('2002:1f63:45e8::1').range(), '6to4') + test.equal(ipaddr.IPv6.parse('2001::4242').range(), 'teredo') + test.equal(ipaddr.IPv6.parse('2001:db8::3210').range(), 'reserved') + test.equal(ipaddr.IPv6.parse('2001:470:8:66::1').range(), 'unicast') + test.done() + + 'is able to determine IP address type': (test) -> + test.equal(ipaddr.parse('8.8.8.8').kind(), 'ipv4') + test.equal(ipaddr.parse('2001:db8:3312::1').kind(), 'ipv6') + test.done() + + 'throws an error if tried to parse an invalid address': (test) -> + test.throws -> + ipaddr.parse('::some.nonsense') + test.done() + + 'correctly processes IPv4-mapped addresses': (test) -> + test.equal(ipaddr.process('8.8.8.8').kind(), 'ipv4') + test.equal(ipaddr.process('2001:db8:3312::1').kind(), 'ipv6') + test.equal(ipaddr.process('::ffff:192.168.1.1').kind(), 'ipv4') + test.done() + + 'correctly converts IPv6 and IPv4 addresses to byte arrays': (test) -> + test.deepEqual(ipaddr.parse('1.2.3.4').toByteArray(), + [0x1, 0x2, 0x3, 0x4]); + # Fuck yeah. The first byte of Google's IPv6 address is 42. 42! + test.deepEqual(ipaddr.parse('2a00:1450:8007::68').toByteArray(), + [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68 ]) + test.done() + + 'correctly parses 1 as an IPv4 address': (test) -> + test.equal(ipaddr.IPv6.isValid('1'), false) + test.equal(ipaddr.IPv4.isValid('1'), true) + test.deepEqual(new ipaddr.IPv4([0, 0, 0, 1]), ipaddr.parse('1')) + test.done() + + 'does not consider a very large or very small number a valid IP address': (test) -> + test.equal(ipaddr.isValid('4999999999'), false) + test.equal(ipaddr.isValid('-1'), false) + test.done() + + 'does not hang on ::8:8:8:8:8:8:8:8:8': (test) -> + test.equal(ipaddr.IPv6.isValid('::8:8:8:8:8:8:8:8:8'), false) + test.done() diff --git a/node_modules/ms/LICENSE.md b/node_modules/ms/LICENSE.md new file mode 100644 index 0000000..69b6125 --- /dev/null +++ b/node_modules/ms/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Zeit, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/ms/README.md b/node_modules/ms/README.md new file mode 100644 index 0000000..5b47570 --- /dev/null +++ b/node_modules/ms/README.md @@ -0,0 +1,52 @@ +# ms + +[![Build Status](https://travis-ci.org/zeit/ms.svg?branch=master)](https://travis-ci.org/zeit/ms) +[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) +[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat/) + +Use this package to easily convert various time formats to milliseconds. + +## Examples + +```js +ms('2 days') // 172800000 +ms('1d') // 86400000 +ms('10h') // 36000000 +ms('2.5 hrs') // 9000000 +ms('2h') // 7200000 +ms('1m') // 60000 +ms('5s') // 5000 +ms('1y') // 31557600000 +ms('100') // 100 +``` + +### Convert from milliseconds + +```js +ms(60000) // "1m" +ms(2 * 60000) // "2m" +ms(ms('10 hours')) // "10h" +``` + +### Time format written-out + +```js +ms(60000, { long: true }) // "1 minute" +ms(2 * 60000, { long: true }) // "2 minutes" +ms(ms('10 hours'), { long: true }) // "10 hours" +``` + +## Features + +- Works both in [node](https://nodejs.org) and in the browser. +- If a number is supplied to `ms`, a string with a unit is returned. +- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`). +- If you pass a string with a number and a valid unit, the number of equivalent ms is returned. + +## Caught a bug? + +1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device +2. Link the package to the global module directory: `npm link` +3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, node will now use your clone of ms! + +As always, you can run the tests using: `npm test` diff --git a/node_modules/ms/index.js b/node_modules/ms/index.js new file mode 100644 index 0000000..824b37e --- /dev/null +++ b/node_modules/ms/index.js @@ -0,0 +1,149 @@ +/** + * Helpers. + */ + +var s = 1000 +var m = s * 60 +var h = m * 60 +var d = h * 24 +var y = d * 365.25 + +/** + * Parse or format the given `val`. + * + * Options: + * + * - `long` verbose formatting [false] + * + * @param {String|Number} val + * @param {Object} options + * @throws {Error} throw an error if val is not a non-empty string or a number + * @return {String|Number} + * @api public + */ + +module.exports = function (val, options) { + options = options || {} + var type = typeof val + if (type === 'string' && val.length > 0) { + return parse(val) + } else if (type === 'number' && isNaN(val) === false) { + return options.long ? + fmtLong(val) : + fmtShort(val) + } + throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val)) +} + +/** + * Parse the given `str` and return milliseconds. + * + * @param {String} str + * @return {Number} + * @api private + */ + +function parse(str) { + str = String(str) + if (str.length > 10000) { + return + } + var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str) + if (!match) { + return + } + var n = parseFloat(match[1]) + var type = (match[2] || 'ms').toLowerCase() + switch (type) { + case 'years': + case 'year': + case 'yrs': + case 'yr': + case 'y': + return n * y + case 'days': + case 'day': + case 'd': + return n * d + case 'hours': + case 'hour': + case 'hrs': + case 'hr': + case 'h': + return n * h + case 'minutes': + case 'minute': + case 'mins': + case 'min': + case 'm': + return n * m + case 'seconds': + case 'second': + case 'secs': + case 'sec': + case 's': + return n * s + case 'milliseconds': + case 'millisecond': + case 'msecs': + case 'msec': + case 'ms': + return n + default: + return undefined + } +} + +/** + * Short format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtShort(ms) { + if (ms >= d) { + return Math.round(ms / d) + 'd' + } + if (ms >= h) { + return Math.round(ms / h) + 'h' + } + if (ms >= m) { + return Math.round(ms / m) + 'm' + } + if (ms >= s) { + return Math.round(ms / s) + 's' + } + return ms + 'ms' +} + +/** + * Long format for `ms`. + * + * @param {Number} ms + * @return {String} + * @api private + */ + +function fmtLong(ms) { + return plural(ms, d, 'day') || + plural(ms, h, 'hour') || + plural(ms, m, 'minute') || + plural(ms, s, 'second') || + ms + ' ms' +} + +/** + * Pluralization helper. + */ + +function plural(ms, n, name) { + if (ms < n) { + return + } + if (ms < n * 1.5) { + return Math.floor(ms / n) + ' ' + name + } + return Math.ceil(ms / n) + ' ' + name + 's' +} diff --git a/node_modules/ms/package.json b/node_modules/ms/package.json new file mode 100644 index 0000000..c07a8ae --- /dev/null +++ b/node_modules/ms/package.json @@ -0,0 +1,108 @@ +{ + "_args": [ + [ + { + "raw": "ms@0.7.2", + "scope": null, + "escapedName": "ms", + "name": "ms", + "rawSpec": "0.7.2", + "spec": "0.7.2", + "type": "version" + }, + "/srv/demos/node_modules/debug" + ] + ], + "_from": "ms@0.7.2", + "_id": "ms@0.7.2", + "_inCache": true, + "_location": "/ms", + "_nodeVersion": "6.8.0", + "_npmOperationalInternal": { + "host": "packages-18-east.internal.npmjs.com", + "tmp": "tmp/ms-0.7.2.tgz_1477383407940_0.4743474116548896" + }, + "_npmUser": { + "name": "leo", + "email": "leo@zeit.co" + }, + "_npmVersion": "3.10.8", + "_phantomChildren": {}, + "_requested": { + "raw": "ms@0.7.2", + "scope": null, + "escapedName": "ms", + "name": "ms", + "rawSpec": "0.7.2", + "spec": "0.7.2", + "type": "version" + }, + "_requiredBy": [ + "/debug" + ], + "_resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz", + "_shasum": "ae25cf2512b3885a1d95d7f037868d8431124765", + "_shrinkwrap": null, + "_spec": "ms@0.7.2", + "_where": "/srv/demos/node_modules/debug", + "bugs": { + "url": "https://github.com/zeit/ms/issues" + }, + "component": { + "scripts": { + "ms/index.js": "index.js" + } + }, + "dependencies": {}, + "description": "Tiny milisecond conversion utility", + "devDependencies": { + "expect.js": "^0.3.1", + "mocha": "^3.0.2", + "serve": "^1.4.0", + "xo": "^0.17.0" + }, + "directories": {}, + "dist": { + "shasum": "ae25cf2512b3885a1d95d7f037868d8431124765", + "tarball": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz" + }, + "files": [ + "index.js" + ], + "gitHead": "ac92a7e0790ba2622a74d9d60690ca0d2c070a45", + "homepage": "https://github.com/zeit/ms#readme", + "license": "MIT", + "main": "./index", + "maintainers": [ + { + "name": "leo", + "email": "leo@zeit.co" + }, + { + "name": "rauchg", + "email": "rauchg@gmail.com" + } + ], + "name": "ms", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+https://github.com/zeit/ms.git" + }, + "scripts": { + "test": "xo && mocha test/index.js", + "test-browser": "serve ./test" + }, + "version": "0.7.2", + "xo": { + "space": true, + "semicolon": false, + "envs": [ + "mocha" + ], + "rules": { + "complexity": 0 + } + } +} diff --git a/node_modules/native-dns-cache/README.md b/node_modules/native-dns-cache/README.md new file mode 100644 index 0000000..6e633bc --- /dev/null +++ b/node_modules/native-dns-cache/README.md @@ -0,0 +1,57 @@ +Cache +----- + +If you perform a query on an A or AAAA type and it doesn't exist, the cache +will attempt to lookup a CNAME and then resolve that. + +The constructor takes an optional object with the following properties: + + * `store` -- implements the cache store model (optional, default MemoryStore) + +Methods: + + * `lookup(question, cb)` -- for a given question check the cache store for +existence + * `store(packet)` -- iterates over the resource records in a packet and sends +them to the cache store + * `purge()` -- clears the cache store of all entries + +MemoryStore / Cache store model +------------------------------- + +`MemoryStore(opts)` -- An in memory store based on a js object + +Methods: + + * `get(domain, key, cb)` + - `domain` is the holder under which keys will be applied, +`key` is the subdomain that is being queried for. +If you `get('example.com', 'www', cb)` you are really asking for `www.example.com`. + - `cb(err, results)` -- results is an object of types and array of answers + * `{ 1: [{address: '127.0.0.1', ttl: 300, type: 1, class: 1}] }` + * `set(domain, key, data, cb)` + - `domain` is the parent under which this key is stored. +`key` is the subdomain we are storing, `data` is an object of types with an array of answers. + * `set('example.com', 'www', {1: [{class:1, type:1, ttl:300, address:'127.0.0.1'}]}, cb)` + - `cb(err, data)` -- cb merely returns the data that was passed. + * `delete(domain[, key[, type]], cb)` -- delete all from a domain, a domain and key, +or a domain a key and a type. + +Lookup +------ + +Is a mechanism that given a store performs the common resolution pattern. + +Given `example.com` previous added to a store: + + * `www.example.com CNAME foo.bar.example.com.` + * `*.example.com A 127.0.0.1` + +A `Lookup(store, 'example.com', {name:'www.example.com', type:1}, cb)` +will resolve `www` to the CNAME and then search for `foo.bar.example.com` which +will return no results, and then search for `*.bar.example.com` which will also +return no results, and ultimately searches for `*.example.com` which will return +the desired record. + +Callback will be called with `(err, results)` where results is an array suitable +for use in `Packet.answer` diff --git a/node_modules/native-dns-cache/cache.js b/node_modules/native-dns-cache/cache.js new file mode 100644 index 0000000..6f46b7c --- /dev/null +++ b/node_modules/native-dns-cache/cache.js @@ -0,0 +1,186 @@ +// Copyright 2012 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +'use strict'; + +var MemoryStore = require('./memory').MemoryStore; +var utils = require('./lookup'); +var Lookup = utils.Lookup; +var util = require('util'); +var Heap = require('binaryheap'); + +var MemoryStoreExpire = function (store, zone, opts) { + opts = opts || {}; + this._store = store; + this._zone = zone; + this._max_keys = opts.max_keys; + this._ttl = new Heap(true); +}; + +MemoryStoreExpire.prototype.get = function (domain, key, cb) { + var self = this; + this._store.get(domain, key, function (err, results) { + var i, j, type, record; + var nresults = {}; + var now = Date.now(); + + for (i in results) { + type = results[i]; + for (j in type) { + record = type[j]; + record.ttl = Math.round((record._ttl_expires - now) / 1000) + if (record.ttl > 0) { + if (!nresults[i]) { + nresults[i] = []; + } + nresults[i].push(record); + } else { + self._ttl.remove(record); + self._store.delete(self._zone, record.name, record.type, function () {}); + } + } + } + + cb(err, nresults); + }); +}; + +MemoryStoreExpire.prototype.set = function (domain, key, data, cb) { + var i, j, type, record, expires; + var self = this; + var now = Date.now(); + + key = utils.ensure_absolute(key); + + for (i in data) { + type = data[i]; + for (j in type) { + record = type[j]; + expires = (record.ttl * 1000) + now; + record._ttl_expires = expires; + self._ttl.insert(record, expires); + } + } + + while (this._ttl.length > this._max_keys) { + var record = this._ttl.pop(); + this._store.delete(this._zone, record.name, record.type); + } + + this._store.set(domain, key, data, function (err, results) { + if (cb) + cb(err, results); + }); +}; + +MemoryStoreExpire.prototype.delete = function (domain, key, type, cb) { + if (!cb) { + cb = type; + type = undefined; + } + + var self = this; + + this._store.get(domain, utils.ensure_absolute(key), function (gerr, gresults) { + var i, j, ktype, record; + + for (i in gresults) { + ktype = gresults[i]; + for (j in ktype) { + record = ktype[j]; + self._ttl.remove(record); + } + } + + if (!gresults) { + if (cb) + cb(gerr, gresults); + return; + } + + self._store.delete(domain, key, type, function (err, results) { + if (cb) + cb(err, results); + }); + }); +}; + +var Cache = module.exports = function (opts) { + opts = opts || {}; + this._zone = '.' || opts.zone; + this._store = undefined; + this.purge = function () { + this._store = new MemoryStoreExpire(opts.store || new MemoryStore(), this._zone, opts); + } + this.purge(); +}; + +Cache.prototype.store = function (packet) { + var self = this; + var c = {}; + + function each(record) { + var r = c[record.name.toLowerCase()]; + var t; + + if (!r) + r = c[record.name.toLowerCase()] = {}; + + t = r[record.type]; + + if (!t) + t = r[record.type] = []; + + t.push(record); + } + + packet.answer.forEach(each); + packet.authority.forEach(each); + packet.additional.forEach(each); + + Object.keys(c).forEach(function (key) { + self._store.set(self._zone, utils.ensure_absolute(key), c[key]); + }); +}; + +Cache.prototype.lookup = function (question, cb) { + var self = this; + Lookup(this._store, this._zone, question, function (err, results) { + var i, record, found = false; + + for (i in results) { + record = results[i]; + if (record.type == question.type) { + found = true; + break; + } + } + + if (results && !found) { + self._store.delete(self._zone, utils.ensure_absolute(question.name)); + results.forEach(function (rr) { + self._store.delete(self._zone, utils.ensure_absolute(rr.name)); + }); + results = null; + } + + cb(results); + }); +}; diff --git a/node_modules/native-dns-cache/index.js b/node_modules/native-dns-cache/index.js new file mode 100644 index 0000000..84a1a48 --- /dev/null +++ b/node_modules/native-dns-cache/index.js @@ -0,0 +1,5 @@ +module.exports = require('./cache'); +module.exports.MemoryStore = require('./memory').MemoryStore; +module.exports.Lookup = require('./lookup').Lookup; +module.exports.is_absolute = require('./lookup').is_absolute; +module.exports.ensure_absolute = require('./lookup').ensure_absolute; diff --git a/node_modules/native-dns-cache/lookup.js b/node_modules/native-dns-cache/lookup.js new file mode 100644 index 0000000..05b8ecd --- /dev/null +++ b/node_modules/native-dns-cache/lookup.js @@ -0,0 +1,110 @@ +// Copyright 2012 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +var dgram = require('dgram'), + EventEmitter = require('events').EventEmitter, + net = require('net'), + util = require('util'); + +var is_absolute = exports.is_absolute = function (f) { + return f && /\.$/.test(f); +}; + +var ensure_absolute = exports.ensure_absolute = function (f) { + if (!is_absolute(f)) + return f += '.'; + return f; +}; + +var CNAME = require('native-dns-packet').consts.NAME_TO_QTYPE.CNAME; + +var Lookup = exports.Lookup = function (store, zone, question, cb) { + if (!(this instanceof Lookup)) + return new Lookup(store, zone, question, cb); + + this.store = store; + this.zone = zone; + this.cb = cb; + this.question = question; + this.results = []; + this.wildcard = undefined; + + this.name = ensure_absolute(question.name); + + this.store.get(this.zone, this.name, this.lookup.bind(this)); +}; + +Lookup.prototype.send = function (err) { + this.cb(err, this.results); +}; + +Lookup.prototype.lookup = function (err, results) { + var type, ret, name, self = this; + + if (err) + return this.send(err); + + if (!results) { + if (!this.wildcard) + this.wildcard = this.question.name; + + if (this.wildcard.toLowerCase() == this.zone.toLowerCase()) + return this.send(); + + name = this.wildcard = this.wildcard.split('.').splice(1).join('.'); + + // 'com.'.split('.').splice(1) will return empty string, we're at the end + if (!this.wildcard) + return this.send(); + + name = '*.' + name; + } else if (results[this.question.type]) { + type = this.question.type; + ret = results; + } else if (results[CNAME]) { + type = CNAME; + ret = results; + this.name = name = results[CNAME][0].data + } + + if (ret) { + ret = ret[type]; + ret.forEach(function (r) { + var rr, k; + + if (self.wildcard && /^\*/.test(r.name)) { + rr = {}; + for (k in r) { + rr[k] = r[k]; + } + rr.name = self.name; + } else { + rr = r; + } + + self.results.push(rr); + }); + } + + if (name) + this.store.get(this.zone, ensure_absolute(name), this.lookup.bind(this)); + else + this.send(); +}; diff --git a/node_modules/native-dns-cache/memory.js b/node_modules/native-dns-cache/memory.js new file mode 100644 index 0000000..8694de2 --- /dev/null +++ b/node_modules/native-dns-cache/memory.js @@ -0,0 +1,93 @@ +// Copyright 2012 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + +'use strict'; + +var MemoryStore = exports.MemoryStore = function (opts) { + this._store = {}; +}; + +MemoryStore.prototype.get = function (domain, key, cb) { + var d = domain.toLowerCase(); + var k = key.toLowerCase(); + var result = this._store[d]; + + if (result) + result = result[k]; + + process.nextTick(function () { + cb(null, result); + }); +}; + +MemoryStore.prototype.set = function (domain, key, data, cb) { + var d = domain.toLowerCase(); + var k = key.toLowerCase(); + var result_domain = this._store[d]; + + if (!result_domain) + result_domain = this._store[d] = {}; + + result_domain[k] = data; + + if (cb) { + process.nextTick(function () { + cb(null, data); + }); + } +}; + +MemoryStore.prototype.delete = function (domain, key, type, cb) { + var d, k; + + if (!cb) { + cb = type; + type = undefined; + } + + if (!cb) { + cb = key; + type = undefined; + } + + d = this._store[domain.toLowerCase()]; + + if (d && key) + k = d[key.toLowerCase()]; + + if (domain && key && type) { + if (d && k) { + delete k[type]; + } + } else if (domain && key) { + if (d) { + delete d[k]; + } + } else if (domain) { + if (d) { + delete this._store[domain.toLowerCase()]; + } + } + + if (cb) { + process.nextTick(function () { + cb(null, domain); + }); + } +}; diff --git a/node_modules/native-dns-cache/package.json b/node_modules/native-dns-cache/package.json new file mode 100644 index 0000000..37ad125 --- /dev/null +++ b/node_modules/native-dns-cache/package.json @@ -0,0 +1,87 @@ +{ + "_args": [ + [ + { + "raw": "native-dns-cache@~0.0.2", + "scope": null, + "escapedName": "native-dns-cache", + "name": "native-dns-cache", + "rawSpec": "~0.0.2", + "spec": ">=0.0.2 <0.1.0", + "type": "range" + }, + "/srv/demos/node_modules/native-dns" + ] + ], + "_from": "native-dns-cache@>=0.0.2 <0.1.0", + "_id": "native-dns-cache@0.0.2", + "_inCache": true, + "_location": "/native-dns-cache", + "_npmUser": { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + }, + "_npmVersion": "1.2.14", + "_phantomChildren": {}, + "_requested": { + "raw": "native-dns-cache@~0.0.2", + "scope": null, + "escapedName": "native-dns-cache", + "name": "native-dns-cache", + "rawSpec": "~0.0.2", + "spec": ">=0.0.2 <0.1.0", + "type": "range" + }, + "_requiredBy": [ + "/native-dns" + ], + "_resolved": "https://registry.npmjs.org/native-dns-cache/-/native-dns-cache-0.0.2.tgz", + "_shasum": "ce0998f7fdf6c7990970a33190624b0e98ee959b", + "_shrinkwrap": null, + "_spec": "native-dns-cache@~0.0.2", + "_where": "/srv/demos/node_modules/native-dns", + "author": { + "name": "Timothy J Fontaine", + "email": "tjfontaine@gmail.com", + "url": "http://atxconsulting.com" + }, + "bugs": { + "url": "http://github.com/tjfontaine/native-dns-cache/issues" + }, + "dependencies": { + "binaryheap": ">= 0.0.3", + "native-dns-packet": ">= 0.0.1" + }, + "description": "DNS Caching Library", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "ce0998f7fdf6c7990970a33190624b0e98ee959b", + "tarball": "https://registry.npmjs.org/native-dns-cache/-/native-dns-cache-0.0.2.tgz" + }, + "engines": { + "node": ">= 0.5.0" + }, + "homepage": "http://github.com/tjfontaine/native-dns-cache", + "keywords": [ + "dns", + "caching" + ], + "main": "index.js", + "maintainers": [ + { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + } + ], + "name": "native-dns-cache", + "optionalDependencies": {}, + "readme": "Cache\n-----\n\nIf you perform a query on an A or AAAA type and it doesn't exist, the cache\nwill attempt to lookup a CNAME and then resolve that.\n\nThe constructor takes an optional object with the following properties:\n\n * `store` -- implements the cache store model (optional, default MemoryStore)\n\nMethods:\n\n * `lookup(question, cb)` -- for a given question check the cache store for\nexistence\n * `store(packet)` -- iterates over the resource records in a packet and sends\nthem to the cache store\n * `purge()` -- clears the cache store of all entries\n\nMemoryStore / Cache store model\n-------------------------------\n\n`MemoryStore(opts)` -- An in memory store based on a js object\n\nMethods:\n\n * `get(domain, key, cb)`\n - `domain` is the holder under which keys will be applied,\n`key` is the subdomain that is being queried for.\nIf you `get('example.com', 'www', cb)` you are really asking for `www.example.com`.\n - `cb(err, results)` -- results is an object of types and array of answers\n * `{ 1: [{address: '127.0.0.1', ttl: 300, type: 1, class: 1}] }`\n * `set(domain, key, data, cb)`\n - `domain` is the parent under which this key is stored.\n`key` is the subdomain we are storing, `data` is an object of types with an array of answers.\n * `set('example.com', 'www', {1: [{class:1, type:1, ttl:300, address:'127.0.0.1'}]}, cb)`\n - `cb(err, data)` -- cb merely returns the data that was passed.\n * `delete(domain[, key[, type]], cb)` -- delete all from a domain, a domain and key,\nor a domain a key and a type.\n\nLookup\n------\n\nIs a mechanism that given a store performs the common resolution pattern.\n\nGiven `example.com` previous added to a store:\n\n * `www.example.com CNAME foo.bar.example.com.`\n * `*.example.com A 127.0.0.1`\n\nA `Lookup(store, 'example.com', {name:'www.example.com', type:1}, cb)`\nwill resolve `www` to the CNAME and then search for `foo.bar.example.com` which\nwill return no results, and then search for `*.bar.example.com` which will also\nreturn no results, and ultimately searches for `*.example.com` which will return\nthe desired record.\n\nCallback will be called with `(err, results)` where results is an array suitable\nfor use in `Packet.answer`\n", + "readmeFilename": "README.md", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/tjfontaine/native-dns-cache.git" + }, + "scripts": {}, + "version": "0.0.2" +} diff --git a/node_modules/native-dns-packet/.npmignore b/node_modules/native-dns-packet/.npmignore new file mode 100644 index 0000000..10ae3a3 --- /dev/null +++ b/node_modules/native-dns-packet/.npmignore @@ -0,0 +1,3 @@ +node_modules* +v8.log +*.swp diff --git a/node_modules/native-dns-packet/LICENSE b/node_modules/native-dns-packet/LICENSE new file mode 100644 index 0000000..6639691 --- /dev/null +++ b/node_modules/native-dns-packet/LICENSE @@ -0,0 +1,19 @@ +Copyright 2011 Timothy J Fontaine + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the 'Software'), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE diff --git a/node_modules/native-dns-packet/README.md b/node_modules/native-dns-packet/README.md new file mode 100644 index 0000000..429254a --- /dev/null +++ b/node_modules/native-dns-packet/README.md @@ -0,0 +1,51 @@ +native-dns-packet +----------------- + + * `Packet.parse(buffer)` returns an instance of `Packet` + * `Packet.write(buffer, packet)` writes the given packet into the buffer, +truncating where appropriate + +```javascript +var Packet = function () { + this.header = { + id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 + }; + this.question = []; + this.answer = []; + this.authority = []; + this.additional = []; + this.edns_options = []; + this.payload = undefined; +}; +``` + +## History + +###### 0.1.1 - October 5, 2014 + +- Fixing NPM tagging issue... + +###### 0.1.0 - October 2, 2014 + +- Added TLSA support +- Fixed EDNS & NAPTR support + deprecates some EDNS fields on Packet +- Now includes support for forwarding EDNS responses (Packet.edns) +- Added many TODOs with suggested improvements +- Added many links to GH issues and RFCs +- Cleaned up code a bit to better please linters +- Added deprecation notices (see parseOpt) +- Handle unhandled RRs on writing packet instead of throwing exception. +- edns/opt should use BufferCursor.copy (Fixes #11) +- Updated `package.json` to include all authors +- Merged tj's `master` branch to add License info +- Updated README to include history of changes diff --git a/node_modules/native-dns-packet/consts.js b/node_modules/native-dns-packet/consts.js new file mode 100644 index 0000000..5c47377 --- /dev/null +++ b/node_modules/native-dns-packet/consts.js @@ -0,0 +1,168 @@ +// Copyright 2011 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +'use strict'; + +function reverse_map(src) { + var dst = {}, + k; + + for (k in src) { + if (src.hasOwnProperty(k)) { + dst[src[k]] = k; + } + } + return dst; +} + +/* http://www.iana.org/assignments/dns-parameters */ +var NAME_TO_QTYPE = exports.NAME_TO_QTYPE = { + A: 1, + NS: 2, + MD: 3, + MF: 4, + CNAME: 5, + SOA: 6, + MB: 7, + MG: 8, + MR: 9, + 'NULL': 10, + WKS: 11, + PTR: 12, + HINFO: 13, + MINFO: 14, + MX: 15, + TXT: 16, + RP: 17, + AFSDB: 18, + X25: 19, + ISDN: 20, + RT: 21, + NSAP: 22, + 'NSAP-PTR': 23, + SIG: 24, + KEY: 25, + PX: 26, + GPOS: 27, + AAAA: 28, + LOC: 29, + NXT: 30, + EID: 31, + NIMLOC: 32, + SRV: 33, + ATMA: 34, + NAPTR: 35, + KX: 36, + CERT: 37, + A6: 38, + DNAME: 39, + SINK: 40, + OPT: 41, + APL: 42, + DS: 43, + SSHFP: 44, + IPSECKEY: 45, + RRSIG: 46, + NSEC: 47, + DNSKEY: 48, + DHCID: 49, + NSEC3: 50, + NSEC3PARAM: 51, + TLSA: 52, + HIP: 55, + NINFO: 56, + RKEY: 57, + TALINK: 58, + CDS: 59, + SPF: 99, + UINFO: 100, + UID: 101, + GID: 102, + UNSPEC: 103, + TKEY: 249, + TSIG: 250, + IXFR: 251, + AXFR: 252, + MAILB: 253, + MAILA: 254, + ANY: 255, + URI: 256, + CAA: 257, + TA: 32768, + DLV: 32769 +}; +exports.QTYPE_TO_NAME = reverse_map(NAME_TO_QTYPE); + +exports.nameToQtype = function(n) { + return NAME_TO_QTYPE[n.toUpperCase()]; +}; + +exports.qtypeToName = function(t) { + return exports.QTYPE_TO_NAME[t]; +}; + +var NAME_TO_QCLASS = exports.NAME_TO_QCLASS = { + IN: 1 +}; +exports.QCLASS_TO_NAME = reverse_map(NAME_TO_QCLASS); + +exports.FAMILY_TO_QTYPE = { + 4: NAME_TO_QTYPE.A, + 6: NAME_TO_QTYPE.AAAA +}; +exports.QTYPE_TO_FAMILY = {}; +exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.A] = 4; +exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.AAAA] = 6; + +exports.NAME_TO_RCODE = { + NOERROR: 0, + FORMERR: 1, + SERVFAIL: 2, + NOTFOUND: 3, + NOTIMP: 4, + REFUSED: 5, + YXDOMAIN: 6, //Name Exists when it should not + YXRRSET: 7, //RR Set Exists when it should not + NXRRSET: 8, //RR Set that should exist does not + NOTAUTH: 9, + NOTZONE: 10, + BADVERS: 16, + BADSIG: 16, // really? + BADKEY: 17, + BADTIME: 18, + BADMODE: 19, + BADNAME: 20, + BADALG: 21, + BADTRUNC: 22 +}; +exports.RCODE_TO_NAME = reverse_map(exports.NAME_TO_RCODE); + +exports.BADNAME = 'EBADNAME'; +exports.BADRESP = 'EBADRESP'; +exports.CONNREFUSED = 'ECONNREFUSED'; +exports.DESTRUCTION = 'EDESTRUCTION'; +exports.REFUSED = 'EREFUSED'; +exports.FORMERR = 'EFORMERR'; +exports.NODATA = 'ENODATA'; +exports.NOMEM = 'ENOMEM'; +exports.NOTFOUND = 'ENOTFOUND'; +exports.NOTIMP = 'ENOTIMP'; +exports.SERVFAIL = 'ESERVFAIL'; +exports.TIMEOUT = 'ETIMEOUT'; diff --git a/node_modules/native-dns-packet/index.js b/node_modules/native-dns-packet/index.js new file mode 100644 index 0000000..a7c5d23 --- /dev/null +++ b/node_modules/native-dns-packet/index.js @@ -0,0 +1,2 @@ +module.exports = require('./packet'); +module.exports.consts = require('./consts'); diff --git a/node_modules/native-dns-packet/package.json b/node_modules/native-dns-packet/package.json new file mode 100644 index 0000000..f3cc0f2 --- /dev/null +++ b/node_modules/native-dns-packet/package.json @@ -0,0 +1,98 @@ +{ + "_args": [ + [ + { + "raw": "native-dns-packet", + "scope": null, + "escapedName": "native-dns-packet", + "name": "native-dns-packet", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "/srv/demos" + ] + ], + "_from": "native-dns-packet@latest", + "_id": "native-dns-packet@0.1.1", + "_inCache": true, + "_location": "/native-dns-packet", + "_npmUser": { + "name": "taoeffect", + "email": "contact@taoeffect.com" + }, + "_npmVersion": "1.4.26", + "_phantomChildren": {}, + "_requested": { + "raw": "native-dns-packet", + "scope": null, + "escapedName": "native-dns-packet", + "name": "native-dns-packet", + "rawSpec": "", + "spec": "latest", + "type": "tag" + }, + "_requiredBy": [ + "#USER", + "/native-dns", + "/native-dns-cache" + ], + "_resolved": "https://registry.npmjs.org/native-dns-packet/-/native-dns-packet-0.1.1.tgz", + "_shasum": "97da90570b8438a00194701ce24d011fd3cc109a", + "_shrinkwrap": null, + "_spec": "native-dns-packet", + "_where": "/srv/demos", + "authors": [ + "Timothy J Fontaine (http://atxconsulting.com)", + "Greg Slepak (https://twitter.com/taoeffect)", + "Matthieu Rakotojaona" + ], + "bugs": { + "url": "http://github.com/tjfontaine/native-dns-packet/issues" + }, + "dependencies": { + "buffercursor": ">= 0.0.12", + "ipaddr.js": ">= 0.1.1" + }, + "description": "Raw DNS Packet Parsing and Writing", + "devDependencies": { + "tap": ">= 0.4.3" + }, + "directories": {}, + "dist": { + "shasum": "97da90570b8438a00194701ce24d011fd3cc109a", + "tarball": "https://registry.npmjs.org/native-dns-packet/-/native-dns-packet-0.1.1.tgz" + }, + "engines": { + "node": ">= 0.5.0" + }, + "gitHead": "296bfe5337b57e93a605838a4da48924e8d46e4b", + "homepage": "http://github.com/tjfontaine/native-dns-packet", + "keywords": [ + "dns", + "parsing" + ], + "license": "MIT", + "main": "index.js", + "maintainers": [ + { + "name": "tjfontaine", + "email": "tjfontaine@gmail.com" + }, + { + "name": "taoeffect", + "email": "contact@taoeffect.com" + } + ], + "name": "native-dns-packet", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/tjfontaine/native-dns-packet.git" + }, + "scripts": { + "test": "tap ./test/*.js" + }, + "version": "0.1.1" +} diff --git a/node_modules/native-dns-packet/packet.js b/node_modules/native-dns-packet/packet.js new file mode 100644 index 0000000..56b17d9 --- /dev/null +++ b/node_modules/native-dns-packet/packet.js @@ -0,0 +1,779 @@ +// Copyright 2011 Timothy J Fontaine +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the 'Software'), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE + +// TODO: change the default UDP packet size that node-dns sends +// from 4096 to conform to these: +// - [requestor's payload size](https://tools.ietf.org/html/rfc6891#section-6.2.3) +// - [responders's payload size](https://tools.ietf.org/html/rfc6891#section-6.2.4) + +'use strict'; + +var consts = require('./consts'), + BufferCursor = require('buffercursor'), + BufferCursorOverflow = BufferCursor.BufferCursorOverflow, + ipaddr = require('ipaddr.js'), + assert = require('assert'), + util = require('util'); + +function assertUndefined(val, msg) { + assert(typeof val != 'undefined', msg); +} + +var Packet = module.exports = function() { + this.header = { + id: 0, + qr: 0, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 0, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 + }; + this.question = []; + this.answer = []; + this.authority = []; + this.additional = []; + this.edns_options = []; // TODO: DEPRECATED! Use `.edns.options` instead! + this.payload = undefined; // TODO: DEPRECATED! Use `.edns.payload` instead! +}; + +var LABEL_POINTER = 0xC0; + +var isPointer = function(len) { + return (len & LABEL_POINTER) === LABEL_POINTER; +}; + +function nameUnpack(buff) { + var len, comp, end, pos, part, combine = ''; + + len = buff.readUInt8(); + comp = false; + end = buff.tell(); + + while (len !== 0) { + if (isPointer(len)) { + len -= LABEL_POINTER; + len = len << 8; + pos = len + buff.readUInt8(); + if (!comp) + end = buff.tell(); + buff.seek(pos); + len = buff.readUInt8(); + comp = true; + continue; + } + + part = buff.toString('ascii', len); + + if (combine.length) + combine = combine + '.' + part; + else + combine = part; + + len = buff.readUInt8(); + + if (!comp) + end = buff.tell(); + } + + buff.seek(end); + + return combine; +} + +function namePack(str, buff, index) { + var offset, dot, part; + + while (str) { + if (index[str]) { + offset = (LABEL_POINTER << 8) + index[str]; + buff.writeUInt16BE(offset); + break; + } else { + index[str] = buff.tell(); + dot = str.indexOf('.'); + if (dot > -1) { + part = str.slice(0, dot); + str = str.slice(dot + 1); + } else { + part = str; + str = undefined; + } + buff.writeUInt8(part.length); + buff.write(part, part.length, 'ascii'); + } + } + + if (!str) { + buff.writeUInt8(0); + } +} + +var + WRITE_HEADER = 100001, + WRITE_TRUNCATE = 100002, + WRITE_QUESTION = 100003, + WRITE_RESOURCE_RECORD = 100004, + WRITE_RESOURCE_WRITE = 100005, + WRITE_RESOURCE_DONE = 100006, + WRITE_RESOURCE_END = 100007, + WRITE_EDNS = 100008, + WRITE_END = 100009, + WRITE_A = consts.NAME_TO_QTYPE.A, + WRITE_AAAA = consts.NAME_TO_QTYPE.AAAA, + WRITE_NS = consts.NAME_TO_QTYPE.NS, + WRITE_CNAME = consts.NAME_TO_QTYPE.CNAME, + WRITE_PTR = consts.NAME_TO_QTYPE.PTR, + WRITE_SPF = consts.NAME_TO_QTYPE.SPF, + WRITE_MX = consts.NAME_TO_QTYPE.MX, + WRITE_SRV = consts.NAME_TO_QTYPE.SRV, + WRITE_TXT = consts.NAME_TO_QTYPE.TXT, + WRITE_SOA = consts.NAME_TO_QTYPE.SOA, + WRITE_OPT = consts.NAME_TO_QTYPE.OPT, + WRITE_NAPTR = consts.NAME_TO_QTYPE.NAPTR, + WRITE_TLSA = consts.NAME_TO_QTYPE.TLSA; + +function writeHeader(buff, packet) { + assert(packet.header, 'Packet requires "header"'); + buff.writeUInt16BE(packet.header.id & 0xFFFF); + var val = 0; + val += (packet.header.qr << 15) & 0x8000; + val += (packet.header.opcode << 11) & 0x7800; + val += (packet.header.aa << 10) & 0x400; + val += (packet.header.tc << 9) & 0x200; + val += (packet.header.rd << 8) & 0x100; + val += (packet.header.ra << 7) & 0x80; + val += (packet.header.res1 << 6) & 0x40; + val += (packet.header.res2 << 5) & 0x20; + val += (packet.header.res3 << 4) & 0x10; + val += packet.header.rcode & 0xF; + buff.writeUInt16BE(val & 0xFFFF); + assert(packet.question.length == 1, 'DNS requires one question'); + // aren't used + buff.writeUInt16BE(1); + // answer offset 6 + buff.writeUInt16BE(packet.answer.length & 0xFFFF); + // authority offset 8 + buff.writeUInt16BE(packet.authority.length & 0xFFFF); + // additional offset 10 + buff.writeUInt16BE(packet.additional.length & 0xFFFF); + return WRITE_QUESTION; +} + +function writeTruncate(buff, packet, section, val) { + // XXX FIXME TODO truncation is currently done wrong. + // Quote rfc2181 section 9 + // The TC bit should not be set merely because some extra information + // could have been included, but there was insufficient room. This + // includes the results of additional section processing. In such cases + // the entire RRSet that will not fit in the response should be omitted, + // and the reply sent as is, with the TC bit clear. If the recipient of + // the reply needs the omitted data, it can construct a query for that + // data and send that separately. + // + // TODO IOW only set TC if we hit it in ANSWERS otherwise make sure an + // entire RRSet is removed during a truncation. + var pos; + + buff.seek(2); + val = buff.readUInt16BE(); + val |= (1 << 9) & 0x200; + buff.seek(2); + buff.writeUInt16BE(val); + switch (section) { + case 'answer': + pos = 6; + // seek to authority and clear it and additional out + buff.seek(8); + buff.writeUInt16BE(0); + buff.writeUInt16BE(0); + break; + case 'authority': + pos = 8; + // seek to additional and clear it out + buff.seek(10); + buff.writeUInt16BE(0); + break; + case 'additional': + pos = 10; + break; + } + buff.seek(pos); + buff.writeUInt16BE(count - 1); // TODO: count not defined! + buff.seek(last_resource); // TODO: last_resource not defined! + return WRITE_END; +} + +function writeQuestion(buff, val, label_index) { + assert(val, 'Packet requires a question'); + assertUndefined(val.name, 'Question requires a "name"'); + assertUndefined(val.type, 'Question requires a "type"'); + assertUndefined(val.class, 'Questionn requires a "class"'); + namePack(val.name, buff, label_index); + buff.writeUInt16BE(val.type & 0xFFFF); + buff.writeUInt16BE(val.class & 0xFFFF); + return WRITE_RESOURCE_RECORD; +} + +function writeResource(buff, val, label_index, rdata) { + assert(val, 'Resource must be defined'); + assertUndefined(val.name, 'Resource record requires "name"'); + assertUndefined(val.type, 'Resource record requires "type"'); + assertUndefined(val.class, 'Resource record requires "class"'); + assertUndefined(val.ttl, 'Resource record requires "ttl"'); + namePack(val.name, buff, label_index); + buff.writeUInt16BE(val.type & 0xFFFF); + buff.writeUInt16BE(val.class & 0xFFFF); + buff.writeUInt32BE(val.ttl & 0xFFFFFFFF); + rdata.pos = buff.tell(); + buff.writeUInt16BE(0); // if there is rdata, then this value will be updated + // to the correct value by 'writeResourceDone' + return val.type; +} + +function writeResourceDone(buff, rdata) { + var pos = buff.tell(); + buff.seek(rdata.pos); + buff.writeUInt16BE(pos - rdata.pos - 2); + buff.seek(pos); + return WRITE_RESOURCE_RECORD; +} + +function writeIp(buff, val) { + //TODO XXX FIXME -- assert that address is of proper type + assertUndefined(val.address, 'A/AAAA record requires "address"'); + val = ipaddr.parse(val.address).toByteArray(); + val.forEach(function(b) { + buff.writeUInt8(b); + }); + return WRITE_RESOURCE_DONE; +} + +function writeCname(buff, val, label_index) { + assertUndefined(val.data, 'NS/CNAME/PTR record requires "data"'); + namePack(val.data, buff, label_index); + return WRITE_RESOURCE_DONE; +} + +// For see: http://tools.ietf.org/html/rfc1035#section-3.3 +// For TXT: http://tools.ietf.org/html/rfc1035#section-3.3.14 +function writeTxt(buff, val) { + //TODO XXX FIXME -- split on max char string and loop + assertUndefined(val.data, 'TXT record requires "data"'); + for (var i=0,len=val.data.length; i> 15; + packet.header.opcode = (val & 0x7800) >> 11; + packet.header.aa = (val & 0x400) >> 10; + packet.header.tc = (val & 0x200) >> 9; + packet.header.rd = (val & 0x100) >> 8; + packet.header.ra = (val & 0x80) >> 7; + packet.header.res1 = (val & 0x40) >> 6; + packet.header.res2 = (val & 0x20) >> 5; + packet.header.res3 = (val & 0x10) >> 4; + packet.header.rcode = (val & 0xF); + packet.question = new Array(msg.readUInt16BE()); + packet.answer = new Array(msg.readUInt16BE()); + packet.authority = new Array(msg.readUInt16BE()); + packet.additional = new Array(msg.readUInt16BE()); + return PARSE_QUESTION; +} + +function parseQuestion(msg, packet) { + var val = {}; + val.name = nameUnpack(msg); + val.type = msg.readUInt16BE(); + val.class = msg.readUInt16BE(); + packet.question[0] = val; + assert(packet.question.length === 1); + // TODO handle qdcount > 1 in practice no one sends this + return PARSE_RESOURCE_RECORD; +} + +function parseRR(msg, val, rdata) { + val.name = nameUnpack(msg); + val.type = msg.readUInt16BE(); + val.class = msg.readUInt16BE(); + val.ttl = msg.readUInt32BE(); + rdata.len = msg.readUInt16BE(); + return val.type; +} + +function parseA(val, msg) { + var address = '' + + msg.readUInt8() + + '.' + msg.readUInt8() + + '.' + msg.readUInt8() + + '.' + msg.readUInt8(); + val.address = address; + return PARSE_RESOURCE_DONE; +} + +function parseAAAA(val, msg) { + var address = ''; + var compressed = false; + + for (var i = 0; i < 8; i++) { + if (i > 0) address += ':'; + // TODO zero compression + address += msg.readUInt16BE().toString(16); + } + val.address = address; + return PARSE_RESOURCE_DONE; +} + +function parseCname(val, msg) { + val.data = nameUnpack(msg); + return PARSE_RESOURCE_DONE; +} + +function parseTxt(val, msg, rdata) { + val.data = []; + var end = msg.tell() + rdata.len; + while (msg.tell() != end) { + var len = msg.readUInt8(); + val.data.push(msg.toString('utf8', len)); + } + return PARSE_RESOURCE_DONE; +} + +function parseMx(val, msg, rdata) { + val.priority = msg.readUInt16BE(); + val.exchange = nameUnpack(msg); + return PARSE_RESOURCE_DONE; +} + +// TODO: SRV fixture failing for '_xmpp-server._tcp.gmail.com.srv.js' +// https://tools.ietf.org/html/rfc2782 +function parseSrv(val, msg) { + val.priority = msg.readUInt16BE(); + val.weight = msg.readUInt16BE(); + val.port = msg.readUInt16BE(); + val.target = nameUnpack(msg); + return PARSE_RESOURCE_DONE; +} + +function parseSoa(val, msg) { + val.primary = nameUnpack(msg); + val.admin = nameUnpack(msg); + val.serial = msg.readUInt32BE(); + val.refresh = msg.readInt32BE(); + val.retry = msg.readInt32BE(); + val.expiration = msg.readInt32BE(); + val.minimum = msg.readInt32BE(); + return PARSE_RESOURCE_DONE; +} + +// http://tools.ietf.org/html/rfc3403#section-4.1 +function parseNaptr(val, msg) { + val.order = msg.readUInt16BE(); + val.preference = msg.readUInt16BE(); + var len = msg.readUInt8(); + val.flags = msg.toString('ascii', len); + len = msg.readUInt8(); + val.service = msg.toString('ascii', len); + len = msg.readUInt8(); + val.regexp = msg.toString('ascii', len); + val.replacement = nameUnpack(msg); + return PARSE_RESOURCE_DONE; +} + +function parseTlsa(val, msg, rdata) { + val.usage = msg.readUInt8(); + val.selector = msg.readUInt8(); + val.matchingtype = msg.readUInt8(); + val.buff = msg.slice(rdata.len - 3).buffer; // 3 because of the 3 UInt8s above. + return PARSE_RESOURCE_DONE; +} + +// https://tools.ietf.org/html/rfc6891#section-6.1.2 +// https://tools.ietf.org/html/rfc2671#section-4.4 +// - [payload size selection](https://tools.ietf.org/html/rfc6891#section-6.2.5) +function parseOpt(val, msg, rdata, packet) { + // assert first entry in additional + rdata.buf = msg.slice(rdata.len); + + val.rcode = ((val.ttl & 0xFF000000) >> 20) + packet.header.rcode; + val.version = (val.ttl >> 16) & 0xFF; + val.do = (val.ttl >> 15) & 1; + val.z = val.ttl & 0x7F; + val.options = []; + + packet.edns = val; + packet.edns_version = val.version; // TODO: return BADVERS for unsupported version! (Section 6.1.3) + + // !! BEGIN DEPRECATION NOTICE !! + // THESE FIELDS MAY BE REMOVED IN THE FUTURE! + packet.edns_options = val.options; + packet.payload = val.class; + // !! END DEPRECATION NOTICE !! + + while (!rdata.buf.eof()) { + val.options.push({ + code: rdata.buf.readUInt16BE(), + data: rdata.buf.slice(rdata.buf.readUInt16BE()).buffer + }); + } + return PARSE_RESOURCE_DONE; +} + +var + PARSE_HEADER = 100000, + PARSE_QUESTION = 100001, + PARSE_RESOURCE_RECORD = 100002, + PARSE_RR_UNPACK = 100003, + PARSE_RESOURCE_DONE = 100004, + PARSE_END = 100005, + PARSE_A = consts.NAME_TO_QTYPE.A, + PARSE_NS = consts.NAME_TO_QTYPE.NS, + PARSE_CNAME = consts.NAME_TO_QTYPE.CNAME, + PARSE_SOA = consts.NAME_TO_QTYPE.SOA, + PARSE_PTR = consts.NAME_TO_QTYPE.PTR, + PARSE_MX = consts.NAME_TO_QTYPE.MX, + PARSE_TXT = consts.NAME_TO_QTYPE.TXT, + PARSE_AAAA = consts.NAME_TO_QTYPE.AAAA, + PARSE_SRV = consts.NAME_TO_QTYPE.SRV, + PARSE_NAPTR = consts.NAME_TO_QTYPE.NAPTR, + PARSE_OPT = consts.NAME_TO_QTYPE.OPT, + PARSE_SPF = consts.NAME_TO_QTYPE.SPF, + PARSE_TLSA = consts.NAME_TO_QTYPE.TLSA; + + +Packet.parse = function(msg) { + var state, + pos, + val, + rdata, + section, + count; + + var packet = new Packet(); + + pos = 0; + state = PARSE_HEADER; + + msg = new BufferCursor(msg); + + while (true) { + switch (state) { + case PARSE_HEADER: + state = parseHeader(msg, packet); + break; + case PARSE_QUESTION: + state = parseQuestion(msg, packet); + section = 'answer'; + count = 0; + break; + case PARSE_RESOURCE_RECORD: + // console.log('PARSE_RESOURCE_RECORD: count = %d, %s.len = %d', count, section, packet[section].length); + if (count === packet[section].length) { + switch (section) { + case 'answer': + section = 'authority'; + count = 0; + break; + case 'authority': + section = 'additional'; + count = 0; + break; + case 'additional': + state = PARSE_END; + break; + } + } else { + state = PARSE_RR_UNPACK; + } + break; + case PARSE_RR_UNPACK: + val = {}; + rdata = {}; + state = parseRR(msg, val, rdata); + break; + case PARSE_RESOURCE_DONE: + packet[section][count++] = val; + state = PARSE_RESOURCE_RECORD; + break; + case PARSE_A: + state = parseA(val, msg); + break; + case PARSE_AAAA: + state = parseAAAA(val, msg); + break; + case PARSE_NS: + case PARSE_CNAME: + case PARSE_PTR: + state = parseCname(val, msg); + break; + case PARSE_SPF: + case PARSE_TXT: + state = parseTxt(val, msg, rdata); + break; + case PARSE_MX: + state = parseMx(val, msg); + break; + case PARSE_SRV: + state = parseSrv(val, msg); + break; + case PARSE_SOA: + state = parseSoa(val, msg); + break; + case PARSE_OPT: + state = parseOpt(val, msg, rdata, packet); + break; + case PARSE_NAPTR: + state = parseNaptr(val, msg); + break; + case PARSE_TLSA: + state = parseTlsa(val, msg, rdata); + break; + case PARSE_END: + return packet; + default: + //console.log(state, val); + val.data = msg.slice(rdata.len); + state = PARSE_RESOURCE_DONE; + break; + } + } +}; diff --git a/node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.bin b/node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.bin new file mode 100644 index 0000000000000000000000000000000000000000..af108f2cf073d33846f55efda6caacf6c879ac64 GIT binary patch literal 82 zcmbQE)7Zek2!ueuXaRxjo_@NHE-pbVjzIyA3=BLBj0bo?Bm+Z89D{;zdVYR-PO5G} XX;MyRvTjOVv2G$8M2tB(KbHXjbsQ3R literal 0 HcmV?d00001 diff --git a/node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.js b/node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.js new file mode 100644 index 0000000..e0eb675 --- /dev/null +++ b/node_modules/native-dns-packet/test/fixtures/8.8.8.8.in-addr.arpa.ptr.js @@ -0,0 +1,23 @@ +{ header: + { id: 39980, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: '8.8.8.8.IN-ADDR.ARPA', type: 12, class: 1 } ], + answer: + [ { name: '8.8.8.8.IN-ADDR.ARPA', + type: 12, + class: 1, + ttl: 21598, + data: 'google-public-dns-a.google.com' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } diff --git a/node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.bin b/node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.bin new file mode 100644 index 0000000000000000000000000000000000000000..feb7d1497477a88fbca970ed18b94b8f36cb4467 GIT binary patch literal 103 zcmew~r*Q!TBM>q$FtWs(m>9Ffmn0YPrlqFj7bO-H?5S{ix_FbNwa;22BB=xgY=l8WJC2 literal 0 HcmV?d00001 diff --git a/node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.js b/node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.js new file mode 100644 index 0000000..0090e26 --- /dev/null +++ b/node_modules/native-dns-packet/test/fixtures/_443._tcp.fedoraproject.org.js @@ -0,0 +1,28 @@ +{ header: + { id: 62108, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 1, + res3: 0, + rcode: 0 }, + question: [ { name: '_443._tcp.fedoraproject.org', type: 52, class: 1 } ], + answer: + [ { name: '_443._tcp.fedoraproject.org', + type: 52, + class: 1, + ttl: 268, + usage: 0, + selector: 0, + matchingtype: 1, + buff: new Buffer([0xd4, 0xc4, 0xc9, 0x98, 0x19, 0xf3, 0xa5, 0xf2, 0xc6, 0x26, 0x1c, 0x94, 0x44, 0xc6, 0x2a, 0x8b, 0x26, 0x3b, 0x39, 0xbc, 0x6a, 0xcc, 0xe3, 0x5c, 0xdc, 0xab, 0xe2, 0x72, 0xd5, 0x03, 0x7f, 0xb2]) } ], + authority: [], + additional: [], + edns_options: [], + payload: 4096, + edns_version: 0, + do: 0} diff --git a/node_modules/native-dns-packet/test/fixtures/_xmpp-server._tcp.gmail.com.srv.bin b/node_modules/native-dns-packet/test/fixtures/_xmpp-server._tcp.gmail.com.srv.bin new file mode 100644 index 0000000000000000000000000000000000000000..f206e3d96b2a9654a306c4a9759497c05924ca29 GIT binary patch literal 285 zcmZ3stFeKBk%5%~2zcTvatjJ{i&KlrQj1vPOOgv%({mFubC{F!a~T*E85j@nfJg=g z<`xD8kQR}t+(=|Ij w;usX*$iTqEz<7WML^3dh#4$(+CFW$7l;otA=U0=nJmYz0!=1c}BWH|*!#~n;eysw=Y82GW|pUc3&&%k(q2SftpjxuO5aPh(w=mHh6b)7Zek2!ueuTwY$zmY1KBnpMo4UzEk literal 0 HcmV?d00001 diff --git a/node_modules/native-dns-packet/test/fixtures/www.nodejs.org.cname.js b/node_modules/native-dns-packet/test/fixtures/www.nodejs.org.cname.js new file mode 100644 index 0000000..07cd9c4 --- /dev/null +++ b/node_modules/native-dns-packet/test/fixtures/www.nodejs.org.cname.js @@ -0,0 +1,23 @@ +{ header: + { id: 32764, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: 'www.nodejs.org', type: 5, class: 1 } ], + answer: + [ { name: 'www.nodejs.org', + type: 5, + class: 1, + ttl: 3600, + data: 'nodejs.org' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined } diff --git a/node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.bin b/node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.bin new file mode 100644 index 0000000000000000000000000000000000000000..e5d4da328911e225301883f750f3fa394960dd71 GIT binary patch literal 158 zcma!A(b&Mi$iT_~1kB~-<*b#78Tt9l$@#eqKw-uMJU}T%AXA2cpDis#H?6>!xjfyF zG3kK70d1(1ECVN7N-;?4fYAXrh#-S5gD4+RFfp$ZB%zy=mc(41Xn4TvKr~#J5I>TF YqSVBk16c=ZK$ZfXqRYT?Zl8)S0CRpLs{jB1 literal 0 HcmV?d00001 diff --git a/node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.js b/node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.js new file mode 100644 index 0000000..5a89d68 --- /dev/null +++ b/node_modules/native-dns-packet/test/fixtures/www.yahoo.com.a.js @@ -0,0 +1,44 @@ +{ header: + { id: 23208, + qr: 1, + opcode: 0, + aa: 0, + tc: 0, + rd: 1, + ra: 1, + res1: 0, + res2: 0, + res3: 0, + rcode: 0 }, + question: [ { name: 'www.yahoo.com', type: 1, class: 1 } ], + answer: + [ { name: 'www.yahoo.com', + type: 5, + class: 1, + ttl: 284, + data: 'fd-fp3.wg1.b.yahoo.com' }, + { name: 'fd-fp3.wg1.b.yahoo.com', + type: 5, + class: 1, + ttl: 285, + data: 'ds-fp3.wg1.b.yahoo.com' }, + { name: 'ds-fp3.wg1.b.yahoo.com', + type: 5, + class: 1, + ttl: 45, + data: 'ds-any-fp3-lfb.wa1.b.yahoo.com' }, + { name: 'ds-any-fp3-lfb.wa1.b.yahoo.com', + type: 5, + class: 1, + ttl: 285, + data: 'ds-any-fp3-real.wa1.b.yahoo.com' }, + { name: 'ds-any-fp3-real.wa1.b.yahoo.com', + type: 1, + class: 1, + ttl: 45, + address: '206.190.36.45' } ], + authority: [], + additional: [], + edns_options: [], + payload: undefined, +} diff --git a/node_modules/native-dns-packet/test/parse.js b/node_modules/native-dns-packet/test/parse.js new file mode 100644 index 0000000..13ffde5 --- /dev/null +++ b/node_modules/native-dns-packet/test/parse.js @@ -0,0 +1,23 @@ +var fs = require('fs'); +var path = require('path'); +var vm = require('vm'); + +var Packet = require('../packet'); + +var test = require('tap').test; + +var fixtureDir = path.join(__dirname, 'fixtures'); + +var files = fs.readdirSync(fixtureDir).filter(function (f) { return /\.bin$/.test(f); }); + +files.forEach(function (file) { + test('can parse ' + file, function (t) { + var bin = fs.readFileSync(path.join(fixtureDir, file)); + var jsFile = path.join(fixtureDir, file.replace(/\.bin$/, '.js')); + var js = 'foo = ' + fs.readFileSync(jsFile, 'utf8'); + js = vm.runInThisContext(js, jsFile); + var ret = Packet.parse(bin); + t.equivalent(ret, js); + t.end(); + }); +}); diff --git a/node_modules/native-dns-packet/test/write.js b/node_modules/native-dns-packet/test/write.js new file mode 100644 index 0000000..48e1441 --- /dev/null +++ b/node_modules/native-dns-packet/test/write.js @@ -0,0 +1,27 @@ +var fs = require('fs'); +var path = require('path'); +var vm = require('vm'); + +var Packet = require('../packet'); + +var test = require('tap').test; + +var fixtureDir = path.join(__dirname, 'fixtures'); + +var files = fs.readdirSync(fixtureDir).filter(function (f) { return /\.js$/.test(f); }); + +files.forEach(function (file) { + test('can parse ' + file, function (t) { + var js = 'foo = ' + fs.readFileSync(path.join(fixtureDir, file), 'utf8'); + js = vm.runInThisContext(js, file); + var buff = new Buffer(4096); + var written = Packet.write(buff, js); + var binFile = path.join(fixtureDir, file.replace(/\.js$/, '.bin')); + var bin = fs.readFileSync(binFile); + var rtrip = Packet.parse(buff.slice(0, written)); + t.equivalent(written, bin.length, null, {testMsgLen: file}); + t.equivalent(buff.slice(0, written), bin, null, {testBin: file}); + t.equivalent(rtrip, js, null, {testObj: file}); + t.end(); + }); +}); diff --git a/node_modules/native-dns/.npmignore b/node_modules/native-dns/.npmignore new file mode 100644 index 0000000..3e2a88d --- /dev/null +++ b/node_modules/native-dns/.npmignore @@ -0,0 +1,3 @@ +node_modules +profile +v8.log diff --git a/node_modules/native-dns/.travis.yml b/node_modules/native-dns/.travis.yml new file mode 100644 index 0000000..11e9db1 --- /dev/null +++ b/node_modules/native-dns/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 0.6 + - 0.8 + - 0.9 +notifications: + irc: + channels: + - "irc.oftc.net#native-dns" diff --git a/node_modules/native-dns/AUTHORS b/node_modules/native-dns/AUTHORS new file mode 100644 index 0000000..980473f --- /dev/null +++ b/node_modules/native-dns/AUTHORS @@ -0,0 +1 @@ +Timothy J Fontaine diff --git a/node_modules/native-dns/ChangeLog b/node_modules/native-dns/ChangeLog new file mode 100644 index 0000000..a9cf7b9 --- /dev/null +++ b/node_modules/native-dns/ChangeLog @@ -0,0 +1,123 @@ +0.7.0: 2014-08-05 Greg Slepak + * `native-dns-packet` 0.0.4 -> 0.1.1 + * `native-dns-cache` 0.0.1 -> 0.0.2 + * `ipaddr.js` 0.1.1 -> 0.1.3 + * Updated authors in `package.json` + * Fixed specification of dependency versions in `package.json` + * See changes from `native-dns-packet` for what's new + + TLDR: many bug fixes, performance improvements. + better EDNS support, TLSA support, fixed TXT. + * Merged `tjfontaine/master` (adds LICENSE file) + +2013-03-23 Timothy J Fontaine + * Add SPF record type, same as TXT + * Emit platform ready on windows (Oleg Elifantiev) + * Split packet parsing into its own library + * Split caching into its own library + +2013-03-03 Timothy J Fontaine + * Assert missing fields + * Truncate integer fields + +2013-02-14 Timothy J Fontaine + * Bump to v0.4.1 + * Disable caching for now + * Fix AAAA packing of records + +2013-01-09 Timothy J Fontaine + * Bump to v0.4.0 + * Fix TCPServer + * Split dependencies out of package + * Refactor Cache and MemoryStore + * Export Lookup function + +2012-12-23 Timothy J Fontaine + * Bump to v0.3.4 + * Update buffercursor to 0.0.5 + * Allow creation of NAPTR records + +2012-12-07 Timothy J Fontaine + * Bump to v0.3.3 + * Make cache layer more generic + +2012-12-06 Timothy J Fontaine + * Bump to v0.3.2 + * Revamp benchmark script + * Properly set EDNS0 options + * Don't overrite `type` and `class` fields of a record + +2012-09-25 Timothy J Fontaine + * Bump to v0.3.1 + * Fix win32 to set the actual hostsfiel + +2012-09-17 Timothy J Fontaine + * Bump to v0.3.0 + * Add more tests and benchmark + * More compatible with c-ares + * Add rudimentary in-memory cache + * Add NAPTR record type + * On > 0.8 make sockets be unref for faster destructing + +2012-07-22 Timothy J Fontaine + * Bump to v0.2.0 + * Rewrite outbound queue to be simpler + +2012-07-08 Timothy J Fontaine + * Bump to v0.1.0 + * State machine to encode and decode packets + +2012-03-20 Timothy J Fontaine + * Bump to v0.0.7 + * Ignore requests/responses less than the minimal size of a query [server, client] + * Remove clone dependency [module] + * Embed ipaddr.js [module] + * Fix label parsing [client, server] + * Long query names should result in ENOTFOUND [client] + * resolve(..., 'PTR') should use reverse, reverse should check hosts [client] + * Autopromote should work for eDNS packets as well [client, server] + * Fix server socket assignment [server] + * toString to various types to produce dig like output [client, server] + * Conosolidate various sources files into logical groups [module] + * Lint to match upstream's style [module] + +2012-03-06 Timothy J Fontaine + * Bump to v0.0.6 + * Split TCP/UDP Server, expose as createTCPServer/createUDPServer [server, module] + * Request server may just be an string of an ip address [client] + * Question type may be a string of record type [client] + * Don't watch for resolve/hosts changes by default [client] + * Add mechanism to forcibly reload the platform [client] + * Add unready event that is fired when reinitializing platform [client] + * Expose platform [module] + +2012-03-01 Timothy J Fontaine + * Bump to v0.0.5 + * Add test suite [module] (issue #12) + * Add qtypeToName/nameToQtype for convenience [module] + * Add Request mechanism to cusotmize queries [module] + * Add field name, buffer, and position to [un]pack errors [module] + * Add PendingRequests.autopromote to always promote ResourceRecords [module] + * Fix Platform.search_path it should be an array [client] + +2012-02-25 Timothy J Fontaine + * Bump to v0.0.4 + * Add clone dependency (it's used in client) [module] + * Don't instantiate fields for every question [client, server] (issue #8) + * Allocate only the size Buffer needed for Packet [client, server] + +2012-02-24 Timothy J Fontaine + * Bump to v0.0.3 + * Considerable performance increase [client, server] (issue #8) + * Label compression is case sensitive [client, server] + * Remove dependency on clone and pystruct [client, server] + * Consolidate TCP logic [client, server] (issue #3) + +2012-02-14 Timothy J Fontaine + * Bump to v0.0.2 + * Add rudimentary TCP support [client, server] + * Rate limit queries to name servers [client] + * Single buffer creation for message packing [client, server] + * Label compression [client, server] + * Expose consts for use by servers [module] + * Specify specific server for querying against [client] + * Remove dependency on bufferjs [module] diff --git a/node_modules/native-dns/LICENSE b/node_modules/native-dns/LICENSE new file mode 100644 index 0000000..eba57b9 --- /dev/null +++ b/node_modules/native-dns/LICENSE @@ -0,0 +1,19 @@ +Copyright 2011 Timothy J Fontaine + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE diff --git a/node_modules/native-dns/README.md b/node_modules/native-dns/README.md new file mode 100644 index 0000000..fa526c8 --- /dev/null +++ b/node_modules/native-dns/README.md @@ -0,0 +1,271 @@ +[![Build Status](https://secure.travis-ci.org/tjfontaine/node-dns.png)](http://travis-ci.org/tjfontaine/node-dns) + +native-dns -- A replacement DNS stack for node.js +================================================= + +Installation +------------ + +`npm install native-dns` and then `var dns = require('native-dns');` + +Client +------ + +native-dns exports what should be a 1:1 mapping of the upstream node.js dns +module. That is to say if it's listed in the [docs](http://nodejs.org/docs/latest/api/dns.html) +it should behave similarly. If it doesn't please file an [issue](https://github.com/tjfontaine/node-dns/issues/new) + +Request +------- + +Beyond matching the upstream module, native-dns also provides a method for +customizing queries. + +```javascript +var dns = require('../dns'), + util = require('util'); + +var question = dns.Question({ + name: 'www.google.com', + type: 'A', +}); + +var start = Date.now(); + +var req = dns.Request({ + question: question, + server: { address: '8.8.8.8', port: 53, type: 'udp' }, + timeout: 1000, +}); + +req.on('timeout', function () { + console.log('Timeout in making request'); +}); + +req.on('message', function (err, answer) { + answer.answer.forEach(function (a) { + console.log(a.address); + }); +}); + +req.on('end', function () { + var delta = (Date.now()) - start; + console.log('Finished processing request: ' + delta.toString() + 'ms'); +}); + +req.send(); +``` + +Request creation takes an object with the following fields + + * `question` -- an instance of Question (required) + * `server` -- defines the remote end point (required) + - as an object it should be + * `address` -- a string ip address (required) + * `port` -- a number for the remote port (optional, default 53) + * `type` -- a string indicating `udp` or `tcp` (optional, default `udp`) +You do not need to indicate ipv4 or ipv6, the backend will handle that + - a string ip address + * `timeout` -- a number in milliseconds indicating how long to wait for the +request to finish. (optional, default 4000) + * `try_edns` -- a boolean indicating whether to use an `EDNSPacket` (optional) + * `cache` -- can be false to disable caching, or implement the cache model, or +an instance of Cache but with a different store (optional, default +platform.cache) + +There are only two methods + + * `send` -- sends the actual request to the remote endpoint + * `cancel` -- cancels the request and ignores any responses + +Request emits the following events + + * `message` -- This is where you get a response, passes `(err, answer)` where +answer is an instance of `Packet` + * `timeout` -- Fired when the timeout is reached + * `cancelled` -- Fired if the request is cancelled + * `end` -- Always fired after a request finished, regardless of disposition + +Platform +-------- + +If you want to customize all `resolve` or `lookup`s with the replacement client +stack you can modify the platform settings accessible in the top level `platform` +object. + +Methods: + + * `reload` -- Re-read system configuration files to populate name servers and +hosts + +Properties: + + * `ready` -- Boolean whether requests are safe to transit, true after hosts +and name servers are filled + * `watching` -- Boolean indicating if system configuration files are watched +for changes, default to false (currently can only be enabled on !win32) + * `name_servers` -- An array of servers used for resolving queries against + - Each entry is an object of `{ address: , port: 53 }` + - On win32 this is hard coded to be google dns until there's a sane way to get +the data + * `search_path` -- An array of domains to try and append after a failed lookup + * `attempts` -- The number of retries for a failed lookup/timeout (default: 5) + * `timeout` -- The time each query is allowed to take before trying another +server. (in milliseconds, default: 5000 (5 seconds)) + * `edns` -- Whether to try and send edns queries first (default: false) + * `cache` -- The system wide cache used by default for `lookup` and `resolve`, +set this to false to disable caching + +Events: + + * `ready` -- Emitted after hosts and name servers have been loaded + * `unready` -- Emitted when hosts and name servers configuration is being +reloaded. + +Server +------ + +There is also a rudimentary server implementation + +```javascript +var dns = require('../dns'), + server = dns.createServer(); + +server.on('request', function (request, response) { + //console.log(request) + response.answer.push(dns.A({ + name: request.question[0].name, + address: '127.0.0.1', + ttl: 600, + })); + response.answer.push(dns.A({ + name: request.question[0].name, + address: '127.0.0.2', + ttl: 600, + })); + response.additional.push(dns.A({ + name: 'hostA.example.org', + address: '127.0.0.3', + ttl: 600, + })); + response.send(); +}); + +server.on('error', function (err, buff, req, res) { + console.log(err.stack); +}); + +server.serve(15353); +``` + +Server creation + + * `createServer` and `createUDPServer` -- both create a `UDP` based server, +they accept an optional object for configuration, + - `{ dgram_type: 'udp4' }` is the default option, the other is `udp6` + * `createTCPServer` -- creates a TCP based server + +Server methods + + * `serve(port, [address])` -- specify which port and optional address to listen +on + * `close()` -- stop the server/close sockets. + +Server events + + * `listening` -- emitted when underlying socket is listening + * `close` -- emitted when the underlying socket is closed + * `request` -- emitted when a dns message is received, and the packet was +successfully unpacked, passes `(request, response)` + - Both `request` and `response` are instances of `Packet` when you're finished +creating the response, you merely need to call `.send()` and the packet will +DoTheRightThing + * `error` -- emitted when unable to properly unpack the packet, passed `(err, msg, response)` + * `socketError` -- remap of the underlying socket for the server, passes `(err, socket)` + +Packet +------ + +Properties: + + * `header` + - `id` -- request id + - `qdcount` -- the number of questions (inferred from array size) + - `ancount` -- the number of questions (inferred from array size) + - `nscount` -- the number of questions (inferred from array size) + - `arcount` -- the number of questions (inferred from array size) + - `qr` -- is a query response + - `opcode` + - `aa` -- Authoritative Answer + - `tc` -- Truncation bit + - `rd` -- Recursion Desired + - `ra` -- Recursion Available + - `res1` -- Reserved field + - `res2` -- Reserved field + - `res3` -- Reserved field + - `rcode` -- Response Code (see `consts.NAME_TO_RCODE`) + * `question` -- array of `Question`s + * `answer` -- array of `ResourceRecord`s + * `authority` -- array of `ResourceRecord`s + * `additional` -- array of `ResourceRecord`s + +Methods: + + * `send()` -- Handles sending the packet to the right end point + +Question +-------- + +A `Question` is instantiated by passing an object like: + + * `name` -- i.e. 'www.google.com' (required) + * `type` -- Either the string representation of the record type, or the integer +value, see `consts.NAME_TO_QTYPE` (default: 'A') + * `class` -- The class of service, default to 1 meaning internet + +ResourceRecord +-------------- + +ResourceRecords are what populate `answer`, `authority`, and `additional`. +This is a generic type, and each derived type inherits the following properties: + + * `name` -- The name of the resource + * `type` -- The numerical representation of the resource record type + * `class` -- The numerical representation of the class of service (usually 1 for internet) + * `ttl` -- The Time To Live for the record, in seconds + +Available Types: + + * `SOA` + - `primary` -- string + - `admin` -- string + - `serial` -- number + - `refresh` -- number + - `retry` -- number + - `expiration` -- number + - `minimum` -- number + * `A` and `AAAA` + - `address` -- string + * `MX` + - `priority` -- number + - `exchange` -- string + * `TXT` + - `data` -- string + * `SRV` + - `priority` -- number + - `weight` -- number + - `port` -- number + - `target` -- string + * `NS` + - `data` -- string + * `CNAME` + - `data` -- string + * `PTR` + - `data` -- string + * `NAPTR` + - `order` -- number + - `preference` -- number + - `flags` -- string + - `service` -- string + - `regexp` -- string + - `replacement` -- string diff --git a/node_modules/native-dns/benchmark.js b/node_modules/native-dns/benchmark.js new file mode 100644 index 0000000..f104c6b --- /dev/null +++ b/node_modules/native-dns/benchmark.js @@ -0,0 +1,212 @@ +'use strict'; + +var assert = require('assert'); +var EventEmitter = require('events').EventEmitter; +var util = require('util'); + +/* +Does ramping up "concurrency" test our ability to keep track of +multiple queries in flight, or does it just benchmark process.nextTick? + +output format: