net-smb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ Ruby Net::SMB - SMB/CIFS client class for Ruby
2
+ ======================================================================
3
+
4
+ Synopsis
5
+ ----------------------------------------------------------------------
6
+
7
+ This is a Samba libsmbclient binding, i.e., SMB/CIFS client class
8
+ for Ruby.
9
+
10
+ Requirement
11
+ ----------------------------------------------------------------------
12
+
13
+ * Ruby 1.9.3+
14
+ * Samba 3.5+ (libsmbclient)
15
+ * C compiler
16
+
17
+ Development Resources
18
+ ----------------------------------------------------------------------
19
+
20
+ * Source: https://github.com/fumiyas/ruby-net-smb
21
+ * Issues: https://github.com/fumiyas/ruby-net-smb/issues
22
+
23
+ Copyright
24
+ ----------------------------------------------------------------------
25
+
26
+ Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
27
+
28
+ Licensed under the GNU General Public License version 3
29
+
data/Rakefile CHANGED
@@ -9,18 +9,15 @@ rescue LoadError => e
9
9
  end
10
10
 
11
11
  require 'rake/clean'
12
+ require 'rake/extensiontask'
12
13
  require 'rake/testtask'
13
14
 
14
- Rake::TestTask.new
15
+ GEMSPEC = eval(File.read(File.dirname(__FILE__) + '/net-smb.gemspec'))
15
16
 
16
- CLEAN.include('ext/**/*.{log,o,so}')
17
- CLEAN.include('ext/**/Makefile')
18
- CLEAN.include('lib/**/*.so')
19
- CLOBBER.include('pkg/*')
20
- CLOBBER.include('test/log')
21
- CLOBBER.include('test/log.[0-9]')
17
+ Rake::ExtensionTask.new("net_smb", GEMSPEC)
18
+ Rake::TestTask.new
22
19
 
23
- EXT_PATH = 'net/smb'
20
+ EXT_PATH = 'net_smb'
24
21
 
25
22
  file "lib/#{EXT_PATH}.so" => Dir.glob("ext/#{EXT_PATH}/*.{rb,c,h}") do
26
23
  Dir.chdir("ext/#{EXT_PATH}") do
@@ -32,3 +29,10 @@ end
32
29
 
33
30
  task :test => "lib/#{EXT_PATH}.so"
34
31
 
32
+ CLEAN.include('ext/**/*.{log,o,so}')
33
+ CLEAN.include('ext/**/Makefile')
34
+ CLEAN.include('lib/**/*.so')
35
+ CLOBBER.include('pkg/*')
36
+ CLOBBER.include('test/log')
37
+ CLOBBER.include('test/log.[0-9]')
38
+
File without changes
@@ -14,7 +14,7 @@ $CFLAGS += " " + ENV["CFLAGS"] if ENV["CFLAGS"]
14
14
  $CPPFLAGS += " " + ENV["CPPFLAGS"] if ENV["CPPFLAGS"]
15
15
  $LDFLAGS += " " + ENV["LDFLAGS"] if ENV["LDFLAGS"]
16
16
 
17
- dir_config "smb"
17
+ dir_config "net_smb"
18
18
 
19
19
  h = have_header("libsmbclient.h")
20
20
  l = have_library("smbclient", "smbc_new_context")
@@ -32,5 +32,5 @@ if try_link(<<-'EOS')
32
32
  $defs << "-DHAVE_SMBC_ALLOWDEBUGCHANGE"
33
33
  end
34
34
 
35
- create_makefile "smb"
35
+ create_makefile "net_smb"
36
36
 
@@ -50,8 +50,15 @@
50
50
 
51
51
  #define RB_SMBFILE_BUFFER_SIZE 8192
52
52
 
53
- typedef struct rb_smb_data RB_SMB_DATA;
54
- typedef struct rb_smbfile_data RB_SMBFILE_DATA;
53
+ typedef struct rb_smb_data RB_SMB_DATA;
54
+ typedef struct rb_smbfile_data RB_SMBFILE_DATA;
55
+
56
+ struct rb_smb_data {
57
+ rb_encoding *enc;
58
+ SMBCCTX *smbcctx;
59
+ VALUE auth_callback;
60
+ RB_SMBFILE_DATA *smbfile_data_list;
61
+ };
55
62
 
56
63
  struct rb_smbfile_data {
57
64
  rb_encoding *enc;
@@ -71,13 +78,6 @@ struct rb_smbfile_data {
71
78
  RB_SMBFILE_DATA *next, *prev;
72
79
  };
73
80
 
74
- struct rb_smb_data {
75
- rb_encoding *enc;
76
- SMBCCTX *smbcctx;
77
- VALUE auth_callback;
78
- RB_SMBFILE_DATA *smbfile_data_list;
79
- };
80
-
81
81
  #define RB_SMB_DATA_FROM_OBJ(obj, data) \
82
82
  RB_SMB_DATA *data; \
83
83
  Data_Get_Struct(obj, RB_SMB_DATA, data);
@@ -89,10 +89,12 @@ struct rb_smb_data {
89
89
  extern VALUE rb_cSMB;
90
90
  extern VALUE rb_eSMBError;
91
91
  extern VALUE rb_cSMBDir;
92
+ extern VALUE rb_cSMBDirEntry;
92
93
  extern VALUE rb_cSMBFile;
93
94
 
94
- void Init_smbdir(void);
95
- void Init_smbfile(void);
95
+ void Init_net_smbdir(void);
96
+ void Init_net_smbdirentry(void);
97
+ void Init_net_smbfile(void);
96
98
 
97
99
  #define _RB_SMB_H_
98
100
 
@@ -50,12 +50,14 @@ static void smbcctx_auth_fn(SMBCCTX *smbcctx,
50
50
  if (TYPE(cred_obj) != T_ARRAY) {
51
51
  rb_raise(rb_eTypeError,
52
52
  RB_SMB_NAME
53
- "#on_auth proc must return an array of username, passsword, and optional workgroup name");
53
+ "#auth_callback must return an array of username, "
54
+ "passsword, and optional workgroup name");
54
55
  }
55
56
  if (RARRAY_LEN(cred_obj) < 2 || RARRAY_LEN(cred_obj) > 3) {
56
57
  rb_raise(rb_eArgError,
57
58
  RB_SMB_NAME
58
- "#on_auth proc must return an array of username, passsword, and optional workgroup name");
59
+ "#auth_callback must return an array of username, "
60
+ "passsword, and optional workgroup name");
59
61
  }
60
62
 
61
63
  username_obj = RARRAY_PTR(cred_obj)[0];
@@ -197,7 +199,7 @@ static VALUE rb_smb_use_kerberos_set(VALUE self, VALUE flag)
197
199
  return flag;
198
200
  }
199
201
 
200
- static VALUE rb_smb_on_auth(int argc, VALUE* argv, VALUE self)
202
+ static VALUE rb_smb_auth_callback(int argc, VALUE* argv, VALUE self)
201
203
  {
202
204
  RB_SMB_DATA_FROM_OBJ(self, data);
203
205
 
@@ -257,7 +259,7 @@ static VALUE rb_smb_open(int argc, VALUE *argv, VALUE self)
257
259
 
258
260
  /* ====================================================================== */
259
261
 
260
- void Init_smb(void)
262
+ void Init_net_smb(void)
261
263
  {
262
264
  VALUE rb_mNet = rb_define_module("Net");
263
265
 
@@ -269,8 +271,8 @@ void Init_smb(void)
269
271
  rb_define_method(rb_cSMB, "debug=", rb_smb_debug_set, 1);
270
272
  rb_define_method(rb_cSMB, "use_kerberos", rb_smb_use_kerberos_get, 0);
271
273
  rb_define_method(rb_cSMB, "use_kerberos=", rb_smb_use_kerberos_set, 1);
272
- rb_define_method(rb_cSMB, "on_auth", rb_smb_on_auth, -1);
273
- rb_define_alias(rb_cSMB, "on_authentication", "on_auth");
274
+ rb_define_method(rb_cSMB, "auth_callback", rb_smb_auth_callback, -1);
275
+ rb_define_alias(rb_cSMB, "auth", "auth_callback");
274
276
  rb_define_method(rb_cSMB, "opendir", rb_smb_opendir, 1);
275
277
  rb_define_method(rb_cSMB, "open", rb_smb_open, -1);
276
278
 
@@ -304,7 +306,8 @@ void Init_smb(void)
304
306
  smbc_init_context(smbcctx);
305
307
  }
306
308
 
307
- Init_smbdir();
308
- Init_smbfile();
309
+ Init_net_smbdir();
310
+ Init_net_smbdirentry();
311
+ Init_net_smbfile();
309
312
  }
310
313
 
@@ -200,13 +200,25 @@ static VALUE rb_smbdir_read(VALUE self)
200
200
  return Qnil;
201
201
  }
202
202
 
203
- return rb_external_str_new_with_enc(smbcdent->name, strlen(smbcdent->name), data->enc);
203
+ VALUE args[4];
204
+ args[0] = rb_external_str_new_with_enc(smbcdent->name,
205
+ strlen(smbcdent->name), data->enc);
206
+ args[1] = INT2NUM(smbcdent->smbc_type);
207
+ args[2] = rb_str_new2(data->url);
208
+ rb_str_cat2(args[2], "/"); /* FIXME: Unless if the last char is not "/" */
209
+ rb_str_cat2(args[2], smbcdent->name); /* FIXME: Must be URL encoding */
210
+ args[3] = rb_str_new(smbcdent->comment, smbcdent->commentlen);
211
+ VALUE entry_obj = rb_class_new_instance(4, args, rb_cSMBDirEntry);
212
+
213
+ return entry_obj;
204
214
  }
205
215
 
206
216
  static VALUE rb_smbdir_each(VALUE self)
207
217
  {
208
218
  VALUE name;
209
219
 
220
+ rb_smbdir_rewind(self);
221
+
210
222
  RETURN_ENUMERATOR(self, 0, 0);
211
223
 
212
224
  while (!NIL_P(name = rb_smbdir_read(self))) {
@@ -218,10 +230,11 @@ static VALUE rb_smbdir_each(VALUE self)
218
230
 
219
231
  /* ====================================================================== */
220
232
 
221
- void Init_smbdir(void)
233
+ void Init_net_smbdir(void)
222
234
  {
223
235
  rb_cSMBDir = rb_define_class_under(rb_cSMB, "Dir", rb_cObject);
224
236
  rb_define_alloc_func(rb_cSMBDir, rb_smbdir_data_alloc);
237
+ rb_include_module(rb_cSMBDir, rb_mEnumerable);
225
238
  rb_define_method(rb_cSMBDir, "initialize", rb_smbdir_initialize, 2);
226
239
  rb_define_method(rb_cSMBDir, "smb", rb_smbdir_smb, 0);
227
240
  rb_define_method(rb_cSMBDir, "url", rb_smbdir_url, 0);
@@ -232,5 +245,15 @@ void Init_smbdir(void)
232
245
  rb_define_method(rb_cSMBDir, "rewind", rb_smbdir_rewind, 0);
233
246
  rb_define_method(rb_cSMBDir, "read", rb_smbdir_read, 0);
234
247
  rb_define_method(rb_cSMBDir, "each", rb_smbdir_each, 0);
248
+
249
+ rb_define_const(rb_cSMB, "SMBC_WORKGROUP", INT2FIX(SMBC_WORKGROUP));
250
+ rb_define_const(rb_cSMB, "SMBC_SERVER", INT2FIX(SMBC_SERVER));
251
+ rb_define_const(rb_cSMB, "SMBC_FILE_SHARE", INT2FIX(SMBC_FILE_SHARE));
252
+ rb_define_const(rb_cSMB, "SMBC_PRINTER_SHARE", INT2FIX(SMBC_PRINTER_SHARE));
253
+ rb_define_const(rb_cSMB, "SMBC_COMMS_SHARE", INT2FIX(SMBC_COMMS_SHARE));
254
+ rb_define_const(rb_cSMB, "SMBC_IPC_SHARE", INT2FIX(SMBC_IPC_SHARE));
255
+ rb_define_const(rb_cSMB, "SMBC_DIR", INT2FIX(SMBC_DIR));
256
+ rb_define_const(rb_cSMB, "SMBC_FILE", INT2FIX(SMBC_FILE));
257
+ rb_define_const(rb_cSMB, "SMBC_LINK", INT2FIX(SMBC_LINK));
235
258
  }
236
259
 
@@ -0,0 +1,145 @@
1
+ /*
2
+ * Ruby/Net::SMB - SMB/CIFS client (Samba libsmbclient binding) for Ruby
3
+ * Net::SMB::DirEntry class
4
+ * Copyright (C) 2012 SATOH Fumiyas @ OSS Technology Corp., Japan
5
+ *
6
+ * This program is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ #include "rb_smb.h"
21
+
22
+ VALUE rb_cSMBDirEntry;
23
+
24
+ VALUE sym_name;
25
+ VALUE sym_type;
26
+ VALUE sym_url;
27
+ VALUE sym_comment;
28
+
29
+ /* ====================================================================== */
30
+
31
+ static VALUE rb_smbdirentry_initialize(VALUE self,
32
+ VALUE name_obj, VALUE type_obj, VALUE url_obj, VALUE comment_obj)
33
+ {
34
+ rb_call_super(0, 0);
35
+
36
+ rb_hash_aset(self, sym_name, name_obj);
37
+ rb_hash_aset(self, sym_type, type_obj);
38
+ rb_hash_aset(self, sym_url, comment_obj);
39
+ rb_hash_aset(self, sym_comment, comment_obj);
40
+
41
+ return self;
42
+ }
43
+
44
+ static VALUE rb_smbdirentry_name(VALUE self)
45
+ {
46
+ return rb_hash_lookup(self, sym_name);
47
+ }
48
+
49
+ static VALUE rb_smbdirentry_type(VALUE self)
50
+ {
51
+ return rb_hash_lookup(self, sym_type);
52
+ }
53
+
54
+ static VALUE rb_smbdirentry_url(VALUE self)
55
+ {
56
+ return rb_hash_lookup(self, sym_url);
57
+ }
58
+
59
+ static VALUE rb_smbdirentry_comment(VALUE self)
60
+ {
61
+ return rb_hash_lookup(self, sym_comment);
62
+ }
63
+
64
+ static VALUE rb_smbdirentry_workgroup_p(VALUE self)
65
+ {
66
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_WORKGROUP) ?
67
+ Qtrue : Qfalse;
68
+ }
69
+
70
+ static VALUE rb_smbdirentry_server_p(VALUE self)
71
+ {
72
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_SERVER) ?
73
+ Qtrue : Qfalse;
74
+ }
75
+
76
+ static VALUE rb_smbdirentry_file_share_p(VALUE self)
77
+ {
78
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_FILE_SHARE) ?
79
+ Qtrue : Qfalse;
80
+ }
81
+
82
+ static VALUE rb_smbdirentry_printer_share_p(VALUE self)
83
+ {
84
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_PRINTER_SHARE) ?
85
+ Qtrue : Qfalse;
86
+ }
87
+
88
+ static VALUE rb_smbdirentry_comms_share_p(VALUE self)
89
+ {
90
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_COMMS_SHARE) ?
91
+ Qtrue : Qfalse;
92
+ }
93
+
94
+ static VALUE rb_smbdirentry_ipc_share_p(VALUE self)
95
+ {
96
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_IPC_SHARE) ?
97
+ Qtrue : Qfalse;
98
+ }
99
+
100
+ static VALUE rb_smbdirentry_dir_p(VALUE self)
101
+ {
102
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_DIR) ?
103
+ Qtrue : Qfalse;
104
+ }
105
+
106
+ static VALUE rb_smbdirentry_file_p(VALUE self)
107
+ {
108
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_FILE) ?
109
+ Qtrue : Qfalse;
110
+ }
111
+
112
+ static VALUE rb_smbdirentry_link_p(VALUE self)
113
+ {
114
+ return rb_hash_lookup(self, sym_type) == INT2FIX(SMBC_LINK) ?
115
+ Qtrue : Qfalse;
116
+ }
117
+
118
+ /* ====================================================================== */
119
+
120
+ void Init_net_smbdirentry(void)
121
+ {
122
+ rb_cSMBDirEntry = rb_define_class_under(rb_cSMB, "DirEntry", rb_cHash);
123
+ rb_define_method(rb_cSMBDirEntry, "initialize", rb_smbdirentry_initialize, 4);
124
+ rb_define_method(rb_cSMBDirEntry, "name", rb_smbdirentry_name, 0);
125
+ rb_define_alias(rb_cSMBDirEntry, "to_s", "name");
126
+ rb_define_method(rb_cSMBDirEntry, "type", rb_smbdirentry_type, 0);
127
+ rb_define_method(rb_cSMBDirEntry, "url", rb_smbdirentry_url, 0);
128
+ rb_define_method(rb_cSMBDirEntry, "comment", rb_smbdirentry_comment, 0);
129
+ rb_define_method(rb_cSMBDirEntry, "workgroup?", rb_smbdirentry_workgroup_p, 0);
130
+ rb_define_method(rb_cSMBDirEntry, "server?", rb_smbdirentry_server_p, 0);
131
+ rb_define_method(rb_cSMBDirEntry, "file_share?", rb_smbdirentry_file_share_p, 0);
132
+ rb_define_method(rb_cSMBDirEntry, "printer_share?", rb_smbdirentry_printer_share_p, 0);
133
+ rb_define_method(rb_cSMBDirEntry, "comms_share?", rb_smbdirentry_comms_share_p, 0);
134
+ rb_define_method(rb_cSMBDirEntry, "ipc_share?", rb_smbdirentry_ipc_share_p, 0);
135
+ rb_define_method(rb_cSMBDirEntry, "directory?", rb_smbdirentry_dir_p, 0);
136
+ rb_define_alias(rb_cSMBDirEntry, "dir?", "directory?");
137
+ rb_define_method(rb_cSMBDirEntry, "file?", rb_smbdirentry_file_p, 0);
138
+ rb_define_method(rb_cSMBDirEntry, "link?", rb_smbdirentry_link_p, 0);
139
+
140
+ sym_name = ID2SYM(rb_intern("name"));
141
+ sym_type = ID2SYM(rb_intern("type"));
142
+ sym_url = ID2SYM(rb_intern("url"));
143
+ sym_comment = ID2SYM(rb_intern("comment"));
144
+ }
145
+
@@ -202,6 +202,11 @@ static VALUE rb_smbfile_url(VALUE self)
202
202
  return rb_str_new2(data->url);
203
203
  }
204
204
 
205
+ static VALUE rb_smbfile_read_buffer_size(VALUE self)
206
+ {
207
+ return INT2NUM(RB_SMBFILE_BUFFER_SIZE);
208
+ }
209
+
205
210
  static VALUE rb_smbfile_close(VALUE self)
206
211
  {
207
212
  RB_SMBFILE_DATA_FROM_OBJ(self, data);
@@ -336,13 +341,14 @@ static VALUE rb_smbfile_read(int argc, VALUE *argv, VALUE self)
336
341
 
337
342
  /* ====================================================================== */
338
343
 
339
- void Init_smbfile(void)
344
+ void Init_net_smbfile(void)
340
345
  {
341
346
  rb_cSMBFile = rb_define_class_under(rb_cSMB, "File", rb_cObject);
342
347
  rb_define_alloc_func(rb_cSMBFile, rb_smbfile_data_alloc);
343
348
  rb_define_method(rb_cSMBFile, "initialize", rb_smbfile_initialize, -1);
344
349
  rb_define_method(rb_cSMBFile, "smb", rb_smbfile_smb, 0);
345
350
  rb_define_method(rb_cSMBFile, "url", rb_smbfile_url, 0);
351
+ rb_define_method(rb_cSMBFile, "read_buffer_size", rb_smbfile_read_buffer_size, 0);
346
352
  rb_define_method(rb_cSMBFile, "close", rb_smbfile_close, 0);
347
353
  rb_define_method(rb_cSMBFile, "tell", rb_smbfile_tell, 0);
348
354
  rb_define_alias(rb_cSMBFile, "pos", "tell");
@@ -1,5 +1,5 @@
1
1
  module Net #:nodoc:
2
- module SMB #:nodoc:
3
- VERSION = "0.0.2" #:nodoc:
2
+ class SMB #:nodoc:
3
+ VERSION = "0.0.3" #:nodoc:
4
4
  end
5
5
  end
data/lib/net/smb.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "net/smb/version"
2
+ require "net_smb"
3
+
data/net-smb.gemspec CHANGED
@@ -16,5 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.extensions = `git ls-files -- ext/*.rb`.split("\n")
18
18
  s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency 'rake-compiler'
19
21
  end
20
22
 
data/test/test_net_smb.rb CHANGED
@@ -32,7 +32,7 @@ class SMBTest < Test::Unit::TestCase
32
32
  @dirs_readable = [@dir_readable]
33
33
  @dir_noaccess = "dir.noaccess"
34
34
  @dirs_noaccess = [@dir_noaccess]
35
- @dirs = @dirs_readable + @dirs_writeable + @dirs_noaccess
35
+ @dirs = [".", ".."] + @dirs_readable + @dirs_writeable + @dirs_noaccess
36
36
  @file_noexist = "file.noexist"
37
37
  @file_writeable = "file.writeable"
38
38
  @file_writeable_m = "ファイル.writeable"
@@ -128,9 +128,18 @@ class SMBTest < Test::Unit::TestCase
128
128
  return smbstatus_r
129
129
  end
130
130
 
131
+ def smb
132
+ smb = Net::SMB.new
133
+ smb.auth_callback {|server, share|
134
+ [@username, @password]
135
+ }
136
+
137
+ return smb
138
+ end
139
+
131
140
  def test_auth
132
141
  smb = Net::SMB.new
133
- smb.on_auth {|server, share|
142
+ smb.auth_callback {|server, share|
134
143
  [@username, @password]
135
144
  }
136
145
  assert_nothing_raised do
@@ -139,7 +148,7 @@ class SMBTest < Test::Unit::TestCase
139
148
  end
140
149
 
141
150
  smb = Net::SMB.new
142
- smb.on_auth {|server, share|
151
+ smb.auth_callback {|server, share|
143
152
  [@username, 'invalid-password']
144
153
  }
145
154
  assert_raise(Errno::EPERM) do
@@ -147,7 +156,7 @@ class SMBTest < Test::Unit::TestCase
147
156
  end
148
157
 
149
158
  smb = Net::SMB.new
150
- smb.on_auth {|server, share|
159
+ smb.auth_callback {|server, share|
151
160
  ['invalid-user', @password]
152
161
  }
153
162
  assert_raise(Errno::EACCES) do
@@ -155,7 +164,7 @@ class SMBTest < Test::Unit::TestCase
155
164
  end
156
165
 
157
166
  smb = Net::SMB.new
158
- smb.on_auth {|server, share|
167
+ smb.auth_callback {|server, share|
159
168
  'blah-blah'
160
169
  }
161
170
  assert_raise(TypeError) do
@@ -163,7 +172,7 @@ class SMBTest < Test::Unit::TestCase
163
172
  end
164
173
 
165
174
  smb = Net::SMB.new
166
- smb.on_auth {|server, share|
175
+ smb.auth_callback {|server, share|
167
176
  [@username]
168
177
  }
169
178
  assert_raise(ArgumentError) do
@@ -172,10 +181,7 @@ class SMBTest < Test::Unit::TestCase
172
181
  end
173
182
 
174
183
  def test_dir_open_close
175
- smb = Net::SMB.new
176
- smb.on_auth {|server, share|
177
- [@username, @password]
178
- }
184
+ smb = self.smb
179
185
 
180
186
  smbdir = smb.opendir(@share_public)
181
187
  assert_equal(smb.object_id, smbdir.smb.object_id)
@@ -199,66 +205,123 @@ class SMBTest < Test::Unit::TestCase
199
205
  end ## test_dir_open_close
200
206
 
201
207
  def test_dir_read
202
- dents_all = [".", "..", *@dirs, *@files]
208
+ smb = self.smb
209
+ dent_names_all = [*@dirs, *@files]
203
210
 
204
- smb = Net::SMB.new
205
- smb.on_auth {|server, share|
206
- [@username, @password]
207
- }
211
+ smbdir = smb.opendir(@share_private)
212
+ dent_names = dent_names_all.clone
213
+ while dent = smbdir.read
214
+ assert_equal(dent.name, dent_names.delete(dent.name),
215
+ "Unexpected directory entry: #{dent.name}")
216
+ if @dirs.include?(dent.name)
217
+ assert(dent.dir?)
218
+ elsif @files.include?(dent.name)
219
+ assert(dent.file?)
220
+ end
221
+ end
222
+ assert_empty(dent_names)
223
+ smbdir.close
224
+
225
+ smb.opendir(@share_public) do |smbdir|
226
+ dent_names = dent_names_all.clone
227
+ while dent = smbdir.read
228
+ assert_equal(dent.name, dent_names.delete(dent.name),
229
+ "Unexpected directory entry: #{dent.name}")
230
+ end
231
+ assert_empty(dent_names)
232
+ end
233
+ end ## test_dir_read
234
+
235
+ def test_dir_seek
236
+ smb = self.smb
237
+ dent_names_all = [*@dirs, *@files]
208
238
 
209
239
  smbdir = smb.opendir(@share_private)
210
- smbdir_pos = [smbdir.pos]
211
- dents = dents_all.clone
212
- while fname = smbdir.read
213
- smbdir_pos << smbdir.pos
214
- assert_equal(fname, dents.delete(fname), "Unexpected directory entry: #{fname}")
240
+
241
+ smbdir_pos_all = Array.new
242
+ fname_by_pos = Hash.new
243
+ loop do
244
+ pos = smbdir.pos
245
+ smbdir_pos_all << pos
246
+ dent = smbdir.read
247
+ fname_by_pos[pos] = dent ? dent.name : nil;
248
+ break unless dent
215
249
  end
216
- assert_empty(dents)
217
250
 
218
251
  smbdir.rewind
219
- assert_equal(smbdir_pos.shift, smbdir.tell)
220
- dents = dents_all.clone
221
- while fname = smbdir.read
222
- assert_equal(smbdir_pos.shift, smbdir.tell)
223
- assert_equal(fname, dents.delete(fname), "Unexpected directory entry: #{fname}")
252
+ dent_names = dent_names_all.clone
253
+ smbdir_pos = smbdir_pos_all.clone
254
+ loop do
255
+ pos = smbdir.pos
256
+ assert_equal(smbdir_pos.shift, pos)
257
+ unless dent = smbdir.read
258
+ break
259
+ end
260
+ assert_equal(dent.name, dent_names.delete(dent.name),
261
+ "Unexpected directory entry: #{dent.name}")
262
+ assert_equal(fname_by_pos[pos], dent.name,
263
+ "Unexpected directory entry: #{dent.name} #{pos}")
264
+ end
265
+ assert_empty(dent_names)
266
+
267
+ smbdir_pos_all.each do |pos|
268
+ smbdir.seek(pos)
269
+ dent = smbdir.read
270
+ dent_name = dent ? dent.name : nil;
271
+ assert_equal(fname_by_pos[pos], dent_name,
272
+ "Unexpected directory entry: #{dent_name} #{pos}")
273
+ end
274
+
275
+ smbdir_pos_all.reverse.each do |pos|
276
+ smbdir.seek(pos)
277
+ dent = smbdir.read
278
+ dent_name = dent ? dent.name : nil;
279
+ assert_equal(fname_by_pos[pos], dent_name,
280
+ "Unexpected directory entry: #{dent_name} #{pos}")
224
281
  end
225
- assert_empty(dents)
226
282
 
227
283
  smbdir.close
284
+ end ## test_dir_seek
228
285
 
229
- smb.opendir(@share_public) do |smbdir|
230
- dents = dents_all.clone
231
- while fname = smbdir.read
232
- assert_equal(fname, dents.delete(fname), "Unexpected directory entry: #{fname}")
233
- end
234
- assert_empty(dents)
286
+ def test_dir_enum
287
+ smb = self.smb
288
+ dent_names_all = [*@dirs, *@files]
289
+
290
+ smbdir = smb.opendir(@share_private)
291
+ dent_names = dent_names_all.clone
292
+ smbdir.each do |dent|
293
+ assert(dent_names.delete(dent.name) != nil)
235
294
  end
295
+ assert_empty(dent_names)
296
+ smbdir.close
236
297
 
237
298
  smbdir = smb.opendir(@share_private)
238
- dents = dents_all.clone
239
- smbdir.each do |fname|
240
- assert(dents.delete(fname) != nil)
299
+ dent_names = dent_names_all.clone
300
+ smbdir.read
301
+ smbdir.read
302
+ smbdir.each do |dent|
303
+ assert(dent_names.delete(dent.name) != nil)
241
304
  end
242
- assert_empty(dents)
305
+ assert_empty(dent_names)
306
+ smbdir.close
243
307
 
244
308
  smbdir = smb.opendir(@share_private)
245
- dents = dents_all.clone
309
+ dent_names = dent_names_all.clone
246
310
  smbdir_enum = smbdir.each
247
- dents.size.times do |n|
248
- fname = smbdir_enum.next
249
- assert_equal(fname, dents.delete(fname), "Unexpected directory entry: #{fname}")
311
+ dent_names.size.times do |n|
312
+ dent = smbdir_enum.next
313
+ assert_equal(dent.name, dent_names.delete(dent.name),
314
+ "Unexpected directory entry: #{dent.name}")
250
315
  end
251
316
  assert_raise(StopIteration) do
252
317
  smbdir_enum.next
253
318
  end
254
- assert_empty(dents)
255
- end ## test_dir_read
319
+ assert_empty(dent_names)
320
+ smbdir.close
321
+ end ## test_dir_enum
256
322
 
257
323
  def test_file_open_read_close
258
- smb = Net::SMB.new
259
- smb.on_auth {|server, share|
260
- [@username, @password]
261
- }
324
+ smb = self.smb
262
325
 
263
326
  @files_readable.each do |filename|
264
327
  url = @share_public + '/' + filename
@@ -280,34 +343,36 @@ class SMBTest < Test::Unit::TestCase
280
343
  end
281
344
  end ## test_file_open_read_close
282
345
 
283
- def test_file_read
284
- smb = Net::SMB.new
285
- smb.on_auth {|server, share|
286
- [@username, @password]
287
- }
346
+ def test_file_read_sequential
347
+ smb = self.smb
288
348
 
289
349
  file = File.open(@share_dir + '/' + @file_large)
290
350
  smbfile = smb.open(@share_public + '/' + @file_large)
291
351
 
292
- buffer_size = 8192
293
- 1.upto(buffer_size * 4) do |read_size|
352
+ buffer_size = smbfile.read_buffer_size
353
+ [
354
+ 1..16,
355
+ (buffer_size/3-16)..(buffer_size/3+16),
356
+ (buffer_size/2-16)..(buffer_size/2+16),
357
+ (buffer_size -16)..(buffer_size +16),
358
+ (buffer_size*2-16)..(buffer_size*2+16),
359
+ (buffer_size*3-16)..(buffer_size*3+16),
360
+ ].each do |read_size_range| read_size_range.each do |read_size|
294
361
  file.rewind
295
362
  smbfile.rewind
296
- (buffer_size / read_size * 3).times do |n|
363
+ (buffer_size / read_size * 4).times do |n|
297
364
  file_data = file.read(read_size)
298
365
  smbfile_data = smbfile.read(read_size)
299
366
  assert_equal(file_data, smbfile_data, "read_size #{read_size}, n=#{n}")
367
+ assert_equal(file.pos, smbfile.pos, "read_size #{read_size}, n=#{n}")
300
368
  end
301
- end
369
+ end end
302
370
 
303
371
  smbfile.close
304
- end ## test_file_read
372
+ end ## test_file_read_sequential
305
373
 
306
374
  def test_file_read_eof
307
- smb = Net::SMB.new
308
- smb.on_auth {|server, share|
309
- [@username, @password]
310
- }
375
+ smb = self.smb
311
376
 
312
377
  smbfile = smb.open(@share_public + '/' + @file_readable)
313
378
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-smb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,27 +9,46 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: SMB/CIFS client (Samba libsmbclient binding)
15
31
  email:
16
32
  - fumiyas@osstech.co.jp
17
33
  executables: []
18
34
  extensions:
19
- - ext/net/smb/extconf.rb
35
+ - ext/net_smb/extconf.rb
20
36
  extra_rdoc_files: []
21
37
  files:
22
38
  - .gitignore
23
39
  - Gemfile
24
40
  - Makefile
41
+ - README.md
25
42
  - Rakefile
26
43
  - Rakefile.local.example
27
- - ext/net/smb/dlinklist.h
28
- - ext/net/smb/extconf.rb
29
- - ext/net/smb/rb_smb.h
30
- - ext/net/smb/smb.c
31
- - ext/net/smb/smbdir.c
32
- - ext/net/smb/smbfile.c
44
+ - ext/net_smb/dlinklist.h
45
+ - ext/net_smb/extconf.rb
46
+ - ext/net_smb/rb_smb.h
47
+ - ext/net_smb/smb.c
48
+ - ext/net_smb/smbdir.c
49
+ - ext/net_smb/smbdirentry.c
50
+ - ext/net_smb/smbfile.c
51
+ - lib/net/smb.rb
33
52
  - lib/net/smb/version.rb
34
53
  - net-smb.gemspec
35
54
  - test/bin/smbd.wrapper