rbkb 0.6.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/History.txt +74 -0
  2. data/README.rdoc +149 -0
  3. data/Rakefile +47 -0
  4. data/bin/b64 +5 -0
  5. data/bin/bgrep +5 -0
  6. data/bin/blit +5 -0
  7. data/bin/c +5 -0
  8. data/bin/crc32 +5 -0
  9. data/bin/d64 +5 -0
  10. data/bin/dedump +5 -0
  11. data/bin/feed +5 -0
  12. data/bin/hexify +5 -0
  13. data/bin/len +5 -0
  14. data/bin/plugsrv +271 -0
  15. data/bin/rex +10 -0
  16. data/bin/rstrings +5 -0
  17. data/bin/slice +5 -0
  18. data/bin/telson +5 -0
  19. data/bin/unhexify +5 -0
  20. data/bin/urldec +5 -0
  21. data/bin/urlenc +5 -0
  22. data/bin/xor +5 -0
  23. data/cli_usage.rdoc +285 -0
  24. data/doctor-bag.jpg +0 -0
  25. data/lib/rbkb.rb +51 -0
  26. data/lib/rbkb/cli.rb +219 -0
  27. data/lib/rbkb/cli/b64.rb +35 -0
  28. data/lib/rbkb/cli/bgrep.rb +86 -0
  29. data/lib/rbkb/cli/blit.rb +89 -0
  30. data/lib/rbkb/cli/chars.rb +24 -0
  31. data/lib/rbkb/cli/crc32.rb +35 -0
  32. data/lib/rbkb/cli/d64.rb +28 -0
  33. data/lib/rbkb/cli/dedump.rb +52 -0
  34. data/lib/rbkb/cli/feed.rb +229 -0
  35. data/lib/rbkb/cli/hexify.rb +65 -0
  36. data/lib/rbkb/cli/len.rb +76 -0
  37. data/lib/rbkb/cli/rstrings.rb +108 -0
  38. data/lib/rbkb/cli/slice.rb +47 -0
  39. data/lib/rbkb/cli/telson.rb +87 -0
  40. data/lib/rbkb/cli/unhexify.rb +50 -0
  41. data/lib/rbkb/cli/urldec.rb +35 -0
  42. data/lib/rbkb/cli/urlenc.rb +35 -0
  43. data/lib/rbkb/cli/xor.rb +43 -0
  44. data/lib/rbkb/extends.rb +725 -0
  45. data/lib/rbkb/http.rb +21 -0
  46. data/lib/rbkb/http/base.rb +172 -0
  47. data/lib/rbkb/http/body.rb +214 -0
  48. data/lib/rbkb/http/common.rb +74 -0
  49. data/lib/rbkb/http/headers.rb +370 -0
  50. data/lib/rbkb/http/parameters.rb +104 -0
  51. data/lib/rbkb/http/request.rb +58 -0
  52. data/lib/rbkb/http/response.rb +86 -0
  53. data/lib/rbkb/plug.rb +9 -0
  54. data/lib/rbkb/plug/blit.rb +222 -0
  55. data/lib/rbkb/plug/cli.rb +83 -0
  56. data/lib/rbkb/plug/feed_import.rb +74 -0
  57. data/lib/rbkb/plug/peer.rb +67 -0
  58. data/lib/rbkb/plug/plug.rb +215 -0
  59. data/lib/rbkb/plug/proxy.rb +26 -0
  60. data/lib/rbkb/plug/unix_domain.rb +75 -0
  61. data/lib_usage.rdoc +176 -0
  62. data/rbkb.gemspec +38 -0
  63. data/spec/rbkb_spec.rb +7 -0
  64. data/spec/spec_helper.rb +16 -0
  65. data/tasks/ann.rake +80 -0
  66. data/tasks/bones.rake +20 -0
  67. data/tasks/gem.rake +201 -0
  68. data/tasks/git.rake +40 -0
  69. data/tasks/notes.rake +27 -0
  70. data/tasks/post_load.rake +34 -0
  71. data/tasks/rdoc.rake +51 -0
  72. data/tasks/rubyforge.rake +55 -0
  73. data/tasks/setup.rb +292 -0
  74. data/tasks/spec.rake +54 -0
  75. data/tasks/svn.rake +47 -0
  76. data/tasks/test.rake +40 -0
  77. data/test/test_cli_b64.rb +35 -0
  78. data/test/test_cli_bgrep.rb +137 -0
  79. data/test/test_cli_blit.rb +11 -0
  80. data/test/test_cli_chars.rb +21 -0
  81. data/test/test_cli_crc32.rb +108 -0
  82. data/test/test_cli_d64.rb +22 -0
  83. data/test/test_cli_dedump.rb +118 -0
  84. data/test/test_cli_feed.rb +11 -0
  85. data/test/test_cli_helper.rb +96 -0
  86. data/test/test_cli_hexify.rb +63 -0
  87. data/test/test_cli_len.rb +96 -0
  88. data/test/test_cli_rstrings.rb +15 -0
  89. data/test/test_cli_slice.rb +73 -0
  90. data/test/test_cli_telson.rb +11 -0
  91. data/test/test_cli_unhexify.rb +43 -0
  92. data/test/test_cli_urldec.rb +50 -0
  93. data/test/test_cli_urlenc.rb +44 -0
  94. data/test/test_cli_xor.rb +71 -0
  95. data/test/test_helper.rb +5 -0
  96. data/test/test_http.rb +27 -0
  97. data/test/test_http_helper.rb +60 -0
  98. data/test/test_http_request.rb +136 -0
  99. data/test/test_http_response.rb +222 -0
  100. data/test/test_rbkb.rb +19 -0
  101. metadata +238 -0
data/tasks/spec.rake ADDED
@@ -0,0 +1,54 @@
1
+
2
+ if HAVE_SPEC_RAKE_SPECTASK and not PROJ.spec.files.to_a.empty?
3
+ require 'spec/rake/verify_rcov'
4
+
5
+ namespace :spec do
6
+
7
+ desc 'Run all specs with basic output'
8
+ Spec::Rake::SpecTask.new(:run) do |t|
9
+ t.ruby_opts = PROJ.ruby_opts
10
+ t.spec_opts = PROJ.spec.opts
11
+ t.spec_files = PROJ.spec.files
12
+ t.libs += PROJ.libs
13
+ end
14
+
15
+ desc 'Run all specs with text output'
16
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
17
+ t.ruby_opts = PROJ.ruby_opts
18
+ t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
19
+ t.spec_files = PROJ.spec.files
20
+ t.libs += PROJ.libs
21
+ end
22
+
23
+ if HAVE_RCOV
24
+ desc 'Run all specs with RCov'
25
+ Spec::Rake::SpecTask.new(:rcov) do |t|
26
+ t.ruby_opts = PROJ.ruby_opts
27
+ t.spec_opts = PROJ.spec.opts
28
+ t.spec_files = PROJ.spec.files
29
+ t.libs += PROJ.libs
30
+ t.rcov = true
31
+ t.rcov_dir = PROJ.rcov.dir
32
+ t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
33
+ end
34
+
35
+ RCov::VerifyTask.new(:verify) do |t|
36
+ t.threshold = PROJ.rcov.threshold
37
+ t.index_html = File.join(PROJ.rcov.dir, 'index.html')
38
+ t.require_exact_threshold = PROJ.rcov.threshold_exact
39
+ end
40
+
41
+ task :verify => :rcov
42
+ remove_desc_for_task %w(spec:clobber_rcov)
43
+ end
44
+
45
+ end # namespace :spec
46
+
47
+ desc 'Alias to spec:run'
48
+ task :spec => 'spec:run'
49
+
50
+ task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
51
+
52
+ end # if HAVE_SPEC_RAKE_SPECTASK
53
+
54
+ # EOF
data/tasks/svn.rake ADDED
@@ -0,0 +1,47 @@
1
+
2
+ if HAVE_SVN
3
+
4
+ unless PROJ.svn.root
5
+ info = %x/svn info ./
6
+ m = %r/^Repository Root:\s+(.*)$/.match(info)
7
+ PROJ.svn.root = (m.nil? ? '' : m[1])
8
+ end
9
+ PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
10
+
11
+ namespace :svn do
12
+
13
+ # A prerequisites task that all other tasks depend upon
14
+ task :prereqs
15
+
16
+ desc 'Show tags from the SVN repository'
17
+ task :show_tags => 'svn:prereqs' do |t|
18
+ tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
19
+ tags.gsub!(%r/\/$/, '')
20
+ tags = tags.split("\n").sort {|a,b| b <=> a}
21
+ puts tags
22
+ end
23
+
24
+ desc 'Create a new tag in the SVN repository'
25
+ task :create_tag => 'svn:prereqs' do |t|
26
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
27
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
28
+
29
+ svn = PROJ.svn
30
+ trunk = File.join(svn.root, svn.trunk)
31
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
32
+ tag = File.join(svn.root, svn.tags, tag)
33
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
34
+
35
+ puts "Creating SVN tag '#{tag}'"
36
+ unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
37
+ abort "Tag creation failed"
38
+ end
39
+ end
40
+
41
+ end # namespace :svn
42
+
43
+ task 'gem:release' => 'svn:create_tag'
44
+
45
+ end # if PROJ.svn.path
46
+
47
+ # EOF
data/tasks/test.rake ADDED
@@ -0,0 +1,40 @@
1
+
2
+ if test(?e, PROJ.test.file) or not PROJ.test.files.to_a.empty?
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
10
+ else PROJ.test.files end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test.opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
21
+ else PROJ.test.files end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+
36
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
+
38
+ end
39
+
40
+ # EOF
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/b64'
3
+
4
+ class TestCliB64 < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::B64
9
+ super()
10
+ end
11
+
12
+ def test_basic_string_arg
13
+ assert_equal 0, run_with_args(%w(fooby))
14
+ assert_equal "Zm9vYnk=\n", @stdout_io.string
15
+ end
16
+
17
+ def test_stdin
18
+ @stdin_io.write("fooby") ; @stdin_io.rewind
19
+ assert_equal 0, run_with_args()
20
+ assert_equal "Zm9vYnk=\n", @stdout_io.string
21
+ end
22
+
23
+
24
+ def test_length_arg
25
+ assert_equal 0, run_with_args(%w(-l 2 fooby))
26
+ assert_equal "Zm\n9v\nYn\nk=\n", @stdout_io.string
27
+ end
28
+
29
+ def test_bad_length_arg
30
+ assert_equal 1, run_with_args(%w(-l -2 fooby))
31
+ assert_match(/length must be > 0/, @stderr_io.string)
32
+ end
33
+
34
+
35
+ end
@@ -0,0 +1,137 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/bgrep'
3
+
4
+ class TestCliBgrep < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Bgrep
9
+ super()
10
+
11
+ @rawdat = (0..255).map {|x| x.chr}.join
12
+ end
13
+
14
+ def test_need_search_arg
15
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
16
+ assert_equal 1, go_with_args()
17
+ assert_match(/need search argument/i, @stderr_io.string)
18
+ end
19
+
20
+ def test_search_arg_exclusive
21
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
22
+ assert_equal 1, go_with_args(%w(-r ABCD -x 41424344))
23
+ assert_match(/are mutually exclusive/i, @stderr_io.string)
24
+ end
25
+
26
+ def test_stdin_str_grep
27
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
28
+ assert_equal 0, go_with_args(%w(-r ABCD))
29
+ assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
30
+ end
31
+
32
+ def test_stdin_regex_grep
33
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
34
+ assert_equal 0, go_with_args(%w(-r A..D))
35
+ assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
36
+ end
37
+
38
+ def test_stdin_hex_grep
39
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
40
+ assert_equal 0, go_with_args(%w(-x 41424344))
41
+ assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
42
+ end
43
+
44
+ def test_alignment_arg
45
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
46
+ assert_equal 0, go_with_args(%w(-a 2 -r BCDE))
47
+ assert_equal %(00000042:00000046:b:"BCDE"\n), @stdout_io.string
48
+ end
49
+
50
+ def test_alignment_arg_not_aligned
51
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
52
+ assert_equal 0, go_with_args(%w(-a 2 -r ABCD))
53
+ assert_equal "", @stdout_io.string
54
+ end
55
+
56
+
57
+ def test_stdin_str_grep_twohits
58
+ @stdin_io.write(@rawdat*2) ; @stdin_io.rewind
59
+ assert_equal 0, go_with_args(%w(-r ABCD))
60
+ assert_equal %(00000041:00000045:b:"ABCD"\n00000141:00000145:b:"ABCD"\n), @stdout_io.string
61
+ end
62
+
63
+ def test_stdin_hex_grep_twohits
64
+ @stdin_io.write(@rawdat*2) ; @stdin_io.rewind
65
+ assert_equal 0, go_with_args(%w(-x 41424344))
66
+ assert_equal( %(00000041:00000045:b:"ABCD"\n)+
67
+ %(00000141:00000145:b:"ABCD"\n),
68
+ @stdout_io.string )
69
+ end
70
+
71
+ def test_file_arg
72
+ with_testfile do |fname, f|
73
+ f.write(@rawdat) ; f.close
74
+ assert_equal 0, go_with_args(%w(-r ABCD) << fname)
75
+ assert_equal %(00000041:00000045:b:"ABCD"\n), @stdout_io.string
76
+ end
77
+ end
78
+
79
+ def test_multi_file_arg
80
+ with_testfile do |fname1, f1|
81
+ f1.write(@rawdat) ; f1.close
82
+
83
+ with_testfile do |fname2, f2|
84
+ f2.write(@rawdat) ; f2.close
85
+ assert_equal 0, go_with_args(["-r", "ABCD", fname1, fname2])
86
+ assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
87
+ %(#{fname2}:00000041:00000045:b:"ABCD"\n),
88
+ @stdout_io.string )
89
+ end
90
+ end
91
+ end
92
+
93
+ def test_multi_file_arg_include_filenames_long
94
+ with_testfile do |fname1, f1|
95
+ f1.write(@rawdat) ; f1.close
96
+
97
+ with_testfile do |fname2, f2|
98
+ f2.write(@rawdat) ; f2.close
99
+ assert_equal 0, go_with_args(%w(--filename -r ABCD) + [fname1, fname2])
100
+ assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
101
+ %(#{fname2}:00000041:00000045:b:"ABCD"\n),
102
+ @stdout_io.string )
103
+ end
104
+ end
105
+ end
106
+
107
+ def test_multi_file_arg_include_filenames_short
108
+ with_testfile do |fname1, f1|
109
+ f1.write(@rawdat) ; f1.close
110
+
111
+ with_testfile do |fname2, f2|
112
+ f2.write(@rawdat) ; f2.close
113
+ assert_equal 0, go_with_args(%w(-n -r ABCD) + [fname1, fname2])
114
+ assert_equal( %(#{fname1}:00000041:00000045:b:"ABCD"\n)+
115
+ %(#{fname2}:00000041:00000045:b:"ABCD"\n),
116
+ @stdout_io.string )
117
+ end
118
+ end
119
+ end
120
+
121
+
122
+ def test_multi_file_arg_suppress_filenames_long
123
+ with_testfile do |fname1, f1|
124
+ f1.write(@rawdat) ; f1.close
125
+
126
+ with_testfile do |fname2, f2|
127
+ f2.write(@rawdat) ; f2.close
128
+ assert_equal 0, go_with_args(%w(--no-filename -r ABCD)+[fname1, fname2])
129
+ assert_equal( %(00000041:00000045:b:"ABCD"\n)+
130
+ %(00000041:00000045:b:"ABCD"\n),
131
+ @stdout_io.string )
132
+ end
133
+ end
134
+ end
135
+
136
+
137
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+
3
+ class TestCliBlit < Test::Unit::TestCase
4
+ include CliTest
5
+
6
+ def setup
7
+ @cli_class = Rbkb::Cli::Blit
8
+ super()
9
+ end
10
+
11
+ end
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+
3
+ class TestCliChars < Test::Unit::TestCase
4
+ include CliTest
5
+
6
+ def setup
7
+ @cli_class = Rbkb::Cli::Chars
8
+ super()
9
+ end
10
+
11
+ def test_chars
12
+ assert_equal 0, go_with_args(%w(1000 A))
13
+ assert_equal "A"*1000, @stdout_io.string
14
+ end
15
+
16
+ def test_bad_arguments
17
+ assert_equal 1, go_with_args(["asdf"])
18
+ assert_match(/bad arguments/i, @stderr_io.string)
19
+ end
20
+
21
+ end
@@ -0,0 +1,108 @@
1
+ require File.join(File.dirname(__FILE__), "test_cli_helper.rb")
2
+ require 'rbkb/cli/crc32'
3
+
4
+ class TestCliCrc32 < Test::Unit::TestCase
5
+ include CliTest
6
+
7
+ def setup
8
+ @cli_class = Rbkb::Cli::Crc32
9
+ super()
10
+ @rawdat = "\306\363\375/l\375\204oK\215o\275\334\037\254\333\276\257\313\267\fr\231\333!\373v|\303W7p\263\307\034X\300~\2671R\252\026\246\263\231\276\314"
11
+ @rawsz = @rawdat.size
12
+ @crc_int = 0xa7641684
13
+ @crc_out ="a7641684\n"
14
+ @stdin_io.write(@rawdat) ; @stdin_io.rewind
15
+ end
16
+
17
+ def test_stdin
18
+ assert_equal 0, go_with_args()
19
+ assert_equal(@crc_out, @stdout_io.string)
20
+ end
21
+
22
+ def test_file_input_arg
23
+ with_testfile do |fname, tf|
24
+ tf.write @rawdat; tf.close
25
+ assert_equal 0, go_with_args([fname])
26
+ assert_equal(@crc_out, @stdout_io.string)
27
+ end
28
+ end
29
+
30
+
31
+ def test_file_input_flag
32
+ with_testfile do |fname, tf|
33
+ tf.write @rawdat; tf.close
34
+ assert_equal 0, go_with_args(["-f", fname])
35
+ assert_equal(@crc_out, @stdout_io.string)
36
+ end
37
+ end
38
+
39
+ def test_start_from_end_zero
40
+ assert_equal 0, go_with_args(%w(-r 48))
41
+ assert_equal("00000000\n", @stdout_io.string)
42
+ end
43
+
44
+ def test_start_from_end_zero_hex
45
+ assert_equal 0, go_with_args(%w(-x 00:30))
46
+ assert_equal(@crc_out, @stdout_io.string)
47
+ end
48
+
49
+ def test_range_zero_start
50
+ assert_equal 0, go_with_args(%w(-r 0:48))
51
+ assert_equal(@crc_out, @stdout_io.string)
52
+ end
53
+
54
+ def test_range
55
+ assert_equal 0, go_with_args(%w{-x 30})
56
+ assert_equal("00000000\n", @stdout_io.string)
57
+ end
58
+
59
+ def test_range_sixteen_thru_end
60
+ assert_equal 0, go_with_args(%w(-r 16))
61
+ assert_equal "de84e464\n", @stdout_io.string
62
+ end
63
+
64
+ def test_range_sixteen_thru_end_hex
65
+ assert_equal 0, go_with_args(%w(-x 10))
66
+ assert_equal "de84e464\n", @stdout_io.string
67
+ end
68
+
69
+ def test_range_last_ten
70
+ assert_equal 0, go_with_args(%w(-r 38:48))
71
+ assert_equal "7d4bb02a\n", @stdout_io.string
72
+ end
73
+
74
+ def test_range_last_ten_hex
75
+ assert_equal 0, go_with_args(%w(-x 26:30))
76
+ assert_equal "7d4bb02a\n", @stdout_io.string
77
+ end
78
+
79
+ def test_invalid_range
80
+ assert_equal 1, go_with_args(%w(-r 38:z48))
81
+ assert_match(/invalid range/, @stderr_io.string)
82
+ end
83
+
84
+ def test_range_last_ten_hex
85
+ assert_equal 1, go_with_args(%w(-x 26:z30))
86
+ assert_match(/invalid range/, @stderr_io.string)
87
+ end
88
+
89
+ def test_range_last_ten_using_negative
90
+ assert_equal 0, go_with_args(%w(-r 38:-1))
91
+ assert_equal "7d4bb02a\n", @stdout_io.string
92
+ end
93
+
94
+ def test_range_last_ten_using_negative_hex
95
+ assert_equal 0, go_with_args(%w(-x 26:-1))
96
+ assert_equal "7d4bb02a\n", @stdout_io.string
97
+ end
98
+
99
+ def test_start_from_end_negative_size
100
+ assert_equal 0, go_with_args(%w(-r -48))
101
+ assert_equal(@crc_out, @stdout_io.string)
102
+ end
103
+
104
+ def test_start_from_end_negative_size_hex
105
+ assert_equal 0, go_with_args(%w(-x -30))
106
+ assert_equal(@crc_out, @stdout_io.string)
107
+ end
108
+ end