smb 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ smb-ruby
2
+ ========
3
+
4
+ Even more half-finished libsmbclient bindings for ruby
5
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ gem 'rake-compiler'
3
+ require 'rake/extensiontask'
4
+ BASE_DIR = Dir.pwd
5
+ require 'rubygems/package_task'
6
+ require 'rake/testtask'
7
+
8
+ exts = []
9
+
10
+ namespace :prepare do
11
+ FileList["ext/*/*.cr"].each do |cr|
12
+ dir = File.dirname(cr)
13
+ name = File.basename(dir)
14
+ desc "Generate source for #{name}"
15
+ task(name.intern) do
16
+ sh 'rubber-generate', '--build-dir', dir, cr
17
+ end
18
+ end
19
+ end
20
+
21
+ $: << File.dirname(__FILE__)+"/lib"
22
+ require 'smb/version'
23
+ spec = Gem::Specification.new do |s|
24
+ s.name = "smb"
25
+ s.author = "Geoff Youngs"
26
+ s.email = "git@intersect-uk.co.uk"
27
+ s.version = SMB::VERSION
28
+ s.homepage = "http://github.com/geoffyoungs/smb-ruby"
29
+ s.summary = "libsmbclient bindings for ruby"
30
+ s.add_dependency("rubber-generate", ">= 0.0.17")
31
+ s.platform = Gem::Platform::RUBY
32
+ s.extensions = FileList["ext/*/extconf.rb"]
33
+ s.files = FileList['ext/*/*.{c,h,cr,rd}'] + ['Rakefile', 'README.md'] + FileList['lib/**/*.rb']
34
+ s.description = <<-EOF
35
+ smb
36
+ EOF
37
+ end
38
+ Gem::PackageTask.new(spec) do |pkg|
39
+ pkg.need_tar = true
40
+ end
41
+ Rake::ExtensionTask.new("smb", spec)
42
+
43
+ Rake::TestTask.new do |t|
44
+ t.test_files = FileList['test/*_test.rb']
45
+ end
46
+
47
+ task :default, :compile
48
+
@@ -0,0 +1,104 @@
1
+ require 'mkmf'
2
+ use_gems = false
3
+ begin
4
+ require 'mkmf-gnome2'
5
+ rescue LoadError
6
+ use_gems = true
7
+ end
8
+
9
+ if use_gems or Object.const_defined?('Gem')
10
+ require 'rubygems'
11
+ gem 'glib2'
12
+ require 'mkmf-gnome2'
13
+ %w[rbglib.h rbgtk.h rbpango.h rbatk.h].each do |header|
14
+ Gem.find_files(header).each do |f|
15
+ $CFLAGS += " '-I#{File.dirname(f)}'"
16
+ end
17
+ end
18
+ end
19
+ # Look for headers in {gem_root}/ext/{package}
20
+ if use_gems
21
+ %w[
22
+ gdk_pixbuf2 atk gtk2 ].each do |package|
23
+ require package
24
+ $CFLAGS += " -I"+Gem.loaded_specs[package].full_gem_path+"/ext/"+package
25
+ end
26
+ end
27
+ if RbConfig::CONFIG.has_key?('rubyhdrdir')
28
+ $CFLAGS += " -I" + RbConfig::CONFIG['rubyhdrdir']+'/ruby'
29
+ end
30
+
31
+ $CFLAGS += " -I."
32
+ have_func("rb_errinfo")
33
+ have_header("libsmbclient.h") or exit(-1)
34
+ have_header("ruby.h") or exit(-1)
35
+ have_library("smbclient") or exit(-1)
36
+ $LIBS += " -lsmbclient"
37
+
38
+ STDOUT.print("checking for new allocation framework... ") # for ruby-1.7
39
+ if Object.respond_to? :allocate
40
+ STDOUT.print "yes
41
+ "
42
+ $defs << "-DHAVE_OBJECT_ALLOCATE"
43
+ else
44
+ STDOUT.print "no
45
+ "
46
+ end
47
+
48
+ top = File.expand_path(File.dirname(__FILE__) + '/..') # XXX
49
+ $CFLAGS += " " + ['glib/src'].map{|d|
50
+ "-I" + File.join(top, d)
51
+ }.join(" ")
52
+
53
+ have_func("rb_define_alloc_func") # for ruby-1.8
54
+
55
+ #set_output_lib('libruby-smb.a')
56
+ if /cygwin|mingw/ =~ RUBY_PLATFORM
57
+ top = "../.."
58
+ [
59
+ ["glib/src", "ruby-glib2"],
60
+ ].each{|d,l|
61
+ $LDFLAGS << sprintf(" -L%s/%s", top, d)
62
+ $libs << sprintf(" -l%s", l)
63
+ }
64
+ end
65
+ begin
66
+ srcdir = File.expand_path(File.dirname($0))
67
+
68
+ begin
69
+
70
+ obj_ext = "."+$OBJEXT
71
+
72
+ $libs = $libs.split(/ /).uniq.join(' ')
73
+ $source_files = Dir.glob(sprintf("%s/*.c", srcdir)).map{|fname|
74
+ fname[0, srcdir.length+1] = ''
75
+ fname
76
+ }
77
+ $objs = $source_files.collect do |item|
78
+ item.gsub(/.c$/, obj_ext)
79
+ end
80
+
81
+ #
82
+ # create Makefile
83
+ #
84
+ $defs << "-DRUBY_SMB_COMPILATION"
85
+ # $CFLAGS << $defs.join(' ')
86
+ create_makefile("smb", srcdir)
87
+ raise Interrupt if not FileTest.exist? "Makefile"
88
+
89
+ File.open("Makefile", "a") do |mfile|
90
+ $source_files.each do |e|
91
+ mfile.print sprintf("%s: %s
92
+ ", e.gsub(/.c$/, obj_ext), e)
93
+ end
94
+ end
95
+ ensure
96
+ #Dir.chdir ".."
97
+ end
98
+
99
+ #create_top_makefile()
100
+ rescue Interrupt
101
+ print " [error] " + $!.to_s + "
102
+ "
103
+ end
104
+
data/ext/smb/smb.c ADDED
@@ -0,0 +1,1019 @@
1
+ #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
2
+ /* Includes */
3
+ #include <ruby.h>
4
+ #include <stdlib.h>
5
+ #include <stdio.h>
6
+ #include <string.h>
7
+ #include "libsmbclient.h"
8
+ #include "ruby.h"
9
+
10
+ /* Setup types */
11
+ /* Try not to clash with other definitions of bool... */
12
+ typedef int rubber_bool;
13
+ #define bool rubber_bool
14
+
15
+ /* Prototypes */
16
+ static VALUE _gcpool_Credentials = Qnil;
17
+ static void __gcpool_Credentials_add(VALUE val);
18
+ static void __gcpool_Credentials_del(VALUE val);
19
+ #define CREDENTIALS_ADD(val) __gcpool_Credentials_add(val)
20
+ #define CREDENTIALS_DEL(val) __gcpool_Credentials_del(val)
21
+ static VALUE mSMB;
22
+ static VALUE
23
+ SMB_CLASS_init(int __p_argc, VALUE *__p_argv, VALUE self);
24
+ static VALUE enumType;
25
+
26
+
27
+ static VALUE enumBaseClass;
28
+
29
+ typedef struct {
30
+ int value;
31
+ char *name;
32
+ char *fullname;
33
+ } EnumData;
34
+
35
+ static VALUE make_enum_value(VALUE klass, int value, char *name, char *fullname)
36
+ {
37
+ EnumData *data = NULL;
38
+
39
+ data = ALLOC(EnumData);
40
+ data->value = value;
41
+ data->name = name;
42
+ data->fullname = fullname;
43
+
44
+ return Data_Wrap_Struct(klass, NULL, free, data);
45
+ }
46
+ static int enum_value_to_int(VALUE value, VALUE klass)
47
+ {
48
+ switch (TYPE(value))
49
+ {
50
+ case T_FIXNUM:
51
+ case T_FLOAT:
52
+ return NUM2INT(value);
53
+ break;
54
+ case T_DATA:
55
+ if (rb_obj_is_kind_of(value, enumBaseClass))
56
+ {
57
+ EnumData *data = NULL;
58
+
59
+ if ((klass != Qnil) && (!rb_obj_is_kind_of(value, klass)))
60
+ {
61
+ rb_raise(rb_eTypeError, "Wrong type of enum %s (%s required)", rb_obj_classname(value), rb_class2name(klass));
62
+ }
63
+
64
+ Data_Get_Struct(value, EnumData, data);
65
+ return data->value;
66
+ }
67
+ break;
68
+ }
69
+ return 0;
70
+
71
+ }
72
+
73
+ static VALUE rubber_enum_inspect(VALUE value)
74
+ {
75
+ EnumData *data = NULL;
76
+ volatile VALUE str = rb_str_new("#<", 2);
77
+ char number[16] = "";
78
+
79
+ Data_Get_Struct(value, EnumData, data);
80
+
81
+ rb_str_cat2(str, rb_obj_classname(value));
82
+ rb_str_cat2(str, " - ");
83
+ rb_str_cat2(str, data->name);
84
+ rb_str_cat2(str, "(");
85
+ sprintf(number, "%i", data->value);
86
+ rb_str_cat2(str, number);
87
+ rb_str_cat2(str, ")>");
88
+
89
+ return str;
90
+ }
91
+
92
+ static VALUE rubber_enum_to_s(VALUE value)
93
+ {
94
+ EnumData *data = NULL;
95
+
96
+ Data_Get_Struct(value, EnumData, data);
97
+
98
+ return rb_str_new2(data->fullname);
99
+ }
100
+ static VALUE rubber_enum_name(VALUE value)
101
+ {
102
+ EnumData *data = NULL;
103
+
104
+ Data_Get_Struct(value, EnumData, data);
105
+
106
+ return rb_str_new2(data->name);
107
+ }
108
+
109
+ static VALUE rubber_enum_cmp(VALUE value, VALUE other)
110
+ {
111
+ VALUE a,b;
112
+ a = rb_funcall(value, rb_intern("to_i"), 0);
113
+ b = rb_funcall(other, rb_intern("to_i"), 0);
114
+ return rb_num_coerce_cmp(a, b);
115
+ }
116
+
117
+ static VALUE rubber_enum_to_i(VALUE value)
118
+ {
119
+ EnumData *data = NULL;
120
+
121
+ Data_Get_Struct(value, EnumData, data);
122
+
123
+ return INT2FIX(data->value);
124
+ }
125
+
126
+ static VALUE rubber_enum_coerce(VALUE value, VALUE other)
127
+ {
128
+ EnumData *data = NULL;
129
+
130
+ Data_Get_Struct(value, EnumData, data);
131
+
132
+ switch(TYPE(other))
133
+ {
134
+ case T_FIXNUM:
135
+ case T_BIGNUM:
136
+ return INT2FIX(data->value);
137
+ case T_FLOAT:
138
+ return rb_float_new(data->value);
139
+ default:
140
+ return Qnil;
141
+ }
142
+ }
143
+
144
+ static VALUE enumType_SMBC_WORKGROUP = Qnil;
145
+ static VALUE enumType_SMBC_SERVER = Qnil;
146
+ static VALUE enumType_SMBC_FILE_SHARE = Qnil;
147
+ static VALUE enumType_SMBC_PRINTER_SHARE = Qnil;
148
+ static VALUE enumType_SMBC_COMMS_SHARE = Qnil;
149
+ static VALUE enumType_SMBC_IPC_SHARE = Qnil;
150
+ static VALUE enumType_SMBC_DIR = Qnil;
151
+ static VALUE enumType_SMBC_FILE = Qnil;
152
+ static VALUE enumType_SMBC_LINK = Qnil;
153
+ typedef int Type;
154
+ #ifdef __GNUC__
155
+ // No point in declaring these unless we're using GCC
156
+ // They're ahead of any code that uses them anyway.
157
+ static VALUE enum_Type_to_ruby(int value)
158
+ __attribute__ ((unused))
159
+ ;
160
+ static int enum_ruby_to_Type(VALUE val)
161
+ __attribute__ ((unused))
162
+ ;
163
+ #endif
164
+
165
+ static VALUE enum_Type_to_ruby(int value) { switch(value) {
166
+ case SMBC_WORKGROUP: return enumType_SMBC_WORKGROUP;
167
+ case SMBC_SERVER: return enumType_SMBC_SERVER;
168
+ case SMBC_FILE_SHARE: return enumType_SMBC_FILE_SHARE;
169
+ case SMBC_PRINTER_SHARE: return enumType_SMBC_PRINTER_SHARE;
170
+ case SMBC_COMMS_SHARE: return enumType_SMBC_COMMS_SHARE;
171
+ case SMBC_IPC_SHARE: return enumType_SMBC_IPC_SHARE;
172
+ case SMBC_DIR: return enumType_SMBC_DIR;
173
+ case SMBC_FILE: return enumType_SMBC_FILE;
174
+ case SMBC_LINK: return enumType_SMBC_LINK;
175
+ }; return Qnil; }
176
+ static int enum_ruby_to_Type(VALUE val) { return enum_value_to_int(val, enumType); }
177
+ static VALUE cCTX;
178
+ static VALUE
179
+ CTX_CLASS_default(VALUE self);
180
+ static VALUE
181
+ CTX_CLASS___alloc__(VALUE self);
182
+ static VALUE
183
+ CTX_initialize(VALUE self);
184
+ static VALUE
185
+ CTX_file_creat(int __p_argc, VALUE *__p_argv, VALUE self);
186
+ static VALUE
187
+ CTX_file_open(int __p_argc, VALUE *__p_argv, VALUE self);
188
+ static VALUE
189
+ CTX_file_write(VALUE self, VALUE sfile, VALUE data);
190
+ static VALUE
191
+ CTX_file_close(VALUE self, VALUE sfile);
192
+ static VALUE cSmbFile;
193
+ static VALUE structDirEntry;
194
+ static VALUE cDir;
195
+ static VALUE
196
+ Dir_CLASS_new(VALUE self, VALUE __v_url);
197
+ static VALUE
198
+ Dir_CLASS_rmdir(VALUE self, VALUE __v_url);
199
+ static VALUE
200
+ Dir_CLASS_mkdir(VALUE self, VALUE __v_url, VALUE __v_mode);
201
+ static VALUE
202
+ Dir_initialize(VALUE self);
203
+ static VALUE
204
+ Dir_read_entry(VALUE self);
205
+ static VALUE
206
+ Dir_read(VALUE self);
207
+ static VALUE
208
+ Dir_tell(VALUE self);
209
+ static VALUE
210
+ Dir_url(VALUE self);
211
+ static VALUE
212
+ Dir_close(VALUE self);
213
+ static VALUE cFile;
214
+ static VALUE
215
+ File_CLASS_new(VALUE self, VALUE __v_url, VALUE __v_flags, VALUE __v_mode);
216
+ static VALUE
217
+ File_CLASS_create(VALUE self, VALUE __v_url, VALUE __v_mode);
218
+ static VALUE
219
+ File_CLASS_unlink(VALUE self, VALUE __v_url);
220
+ static VALUE
221
+ File_CLASS_rename(VALUE self, VALUE __v_ourl, VALUE __v_nurl);
222
+ static VALUE
223
+ File_CLASS_stat(VALUE self, VALUE __v_url);
224
+ static VALUE
225
+ File_initialize(VALUE self);
226
+ static VALUE
227
+ File_stat(VALUE self);
228
+ static VALUE
229
+ File_url(VALUE self);
230
+ static VALUE
231
+ File_seek(VALUE self, VALUE __v_offset, VALUE __v_whence);
232
+ static VALUE
233
+ File_read(int __p_argc, VALUE *__p_argv, VALUE self);
234
+ static VALUE
235
+ File_write(VALUE self, VALUE buf);
236
+ static VALUE
237
+ File_close(VALUE self);
238
+ static VALUE
239
+ File_CLASS_read(VALUE self, VALUE __v_url);
240
+
241
+ /* Inline C code */
242
+
243
+
244
+ #define TO_STRING(v) ((v) ? rb_str_new2((v)) : Qnil)
245
+
246
+ static volatile VALUE auth_block = Qnil;
247
+
248
+ static void smbc_get_auth_data(const char *srv, const char *shr,
249
+ char *wg, int wglen,
250
+ char *un, int unlen,
251
+ char *pw, int pwlen)
252
+ {
253
+ volatile VALUE ret= Qnil;
254
+
255
+
256
+ ret = rb_funcall(auth_block, rb_intern("call"), 5, TO_STRING(srv), TO_STRING(shr),
257
+ TO_STRING(wg), TO_STRING(un), TO_STRING(pw));
258
+
259
+ if(TYPE(ret) == T_ARRAY && RARRAY_LEN(ret) == 3)
260
+ {
261
+ char * tmp;
262
+ volatile VALUE tmpv;
263
+
264
+ tmpv = RARRAY_PTR(ret)[0];
265
+ tmp = StringValuePtr(tmpv);
266
+ strncpy(wg, tmp, wglen);
267
+
268
+ tmpv = RARRAY_PTR(ret)[1];
269
+ tmp = StringValuePtr(tmpv);
270
+ strncpy(un, tmp, unlen);
271
+
272
+ tmpv = RARRAY_PTR(ret)[2];
273
+ tmp = StringValuePtr(tmpv);
274
+ strncpy(pw, tmp, pwlen);
275
+
276
+ CREDENTIALS_ADD(ret);
277
+ }
278
+ }
279
+
280
+ /*static VALUE rb_cStat;*/
281
+
282
+ typedef struct rb_smbprivate {
283
+ int handle;
284
+ char *url;
285
+ } rb_smbprivate;
286
+
287
+ static void smbprivate_free(rb_smbprivate *p)
288
+ {
289
+ if (p) {
290
+ if(p->url)
291
+ free(p->url);
292
+ free(p);
293
+ }
294
+ }
295
+
296
+ static VALUE stat_new(struct stat *st)
297
+ {
298
+ struct stat *nst = 0;
299
+
300
+ if (st) {
301
+ nst = ALLOC(struct stat);
302
+ *nst = *st;
303
+ }
304
+ return Data_Wrap_Struct(rb_cStat, NULL, free, nst);
305
+ }
306
+
307
+
308
+ /* Code */
309
+ static void __gcpool_Credentials_add(VALUE val)
310
+ {
311
+ if (_gcpool_Credentials == Qnil)
312
+ {
313
+ _gcpool_Credentials = rb_ary_new3(1, val);
314
+ }
315
+ else
316
+ {
317
+ rb_ary_push(_gcpool_Credentials, val);
318
+ }
319
+ }
320
+
321
+ static void __gcpool_Credentials_del(VALUE val)
322
+ {
323
+ if (_gcpool_Credentials == Qnil)
324
+ {
325
+ rb_warn("Trying to remove object from empty GC queue Credentials");
326
+ return;
327
+ }
328
+ rb_ary_delete(_gcpool_Credentials, val);
329
+ // If nothing is referenced, don't keep an empty array in the pool...
330
+ if (RARRAY_LEN(_gcpool_Credentials) == 0)
331
+ _gcpool_Credentials = Qnil;
332
+ }
333
+
334
+ static VALUE
335
+ SMB_CLASS_init(int __p_argc, VALUE *__p_argv, VALUE self)
336
+ {
337
+ VALUE __v_debug = Qnil;
338
+ int debug; int __orig_debug;
339
+ VALUE block = rb_block_proc();
340
+
341
+ /* Scan arguments */
342
+ rb_scan_args(__p_argc, __p_argv, "01&",&__v_debug, &block);
343
+
344
+ /* Set defaults */
345
+ if (__p_argc > 0)
346
+ __orig_debug = debug = NUM2INT(__v_debug);
347
+ else
348
+ debug = 0;
349
+
350
+
351
+ #line 130 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
352
+ auth_block = block;
353
+ rb_gc_register_address(&auth_block);
354
+ if (smbc_init(smbc_get_auth_data, debug) < 0) { rb_sys_fail("smbc_init failed");
355
+ }
356
+ return Qnil;
357
+ }
358
+
359
+ static VALUE
360
+ CTX_CLASS_default(VALUE self)
361
+ {
362
+ VALUE __p_retval = Qnil;
363
+
364
+ #line 90 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
365
+ do { __p_retval = Data_Wrap_Struct(self, NULL, smbc_free_context, smbc_set_context(NULL)); goto out; } while(0);
366
+ out:
367
+ return __p_retval;
368
+ }
369
+
370
+ static VALUE
371
+ CTX_CLASS___alloc__(VALUE self)
372
+ {
373
+ VALUE __p_retval = Qnil;
374
+
375
+ #line 93 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
376
+
377
+ do {
378
+ SMBCCTX * ctx =
379
+ smbc_new_context();
380
+ volatile VALUE obj ;
381
+ rb_p(self);
382
+ obj = Data_Wrap_Struct(self, NULL, smbc_free_context, ctx);
383
+ do { __p_retval = obj; goto out; } while(0);
384
+
385
+ } while(0);
386
+
387
+ out:
388
+ return __p_retval;
389
+ }
390
+
391
+ static VALUE
392
+ CTX_initialize(VALUE self)
393
+ {
394
+ SMBCCTX *ctx; Data_Get_Struct(self, SMBCCTX, ctx);
395
+
396
+ #line 100 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
397
+ smbc_init_context(ctx);
398
+
399
+ return Qnil;
400
+ }
401
+
402
+ static VALUE
403
+ CTX_file_creat(int __p_argc, VALUE *__p_argv, VALUE self)
404
+ {
405
+ VALUE __p_retval = Qnil;
406
+ VALUE __v_url = Qnil;
407
+ char * url; char * __orig_url;
408
+ VALUE __v_mode = Qnil;
409
+ int mode; int __orig_mode;
410
+ SMBCCTX *ctx; Data_Get_Struct(self, SMBCCTX, ctx);
411
+
412
+ /* Scan arguments */
413
+ rb_scan_args(__p_argc, __p_argv, "11",&__v_url, &__v_mode);
414
+
415
+ /* Set defaults */
416
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
417
+
418
+ if (__p_argc > 1)
419
+ __orig_mode = mode = NUM2INT(__v_mode);
420
+ else
421
+ mode = 0666;
422
+
423
+
424
+ #line 106 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
425
+
426
+ do {
427
+ volatile VALUE rfile ;
428
+ SMBCFILE * file =
429
+ (smbc_getFunctionCreat(ctx))(ctx, url, mode);
430
+ rfile = Data_Wrap_Struct(cSmbFile, NULL, NULL, file);
431
+ do { __p_retval = rfile; goto out; } while(0);
432
+
433
+ } while(0);
434
+
435
+ out:
436
+ return __p_retval;
437
+ }
438
+
439
+ static VALUE
440
+ CTX_file_open(int __p_argc, VALUE *__p_argv, VALUE self)
441
+ {
442
+ VALUE __p_retval = Qnil;
443
+ VALUE __v_url = Qnil;
444
+ char * url; char * __orig_url;
445
+ VALUE __v_flags = Qnil;
446
+ int flags; int __orig_flags;
447
+ VALUE __v_mode = Qnil;
448
+ int mode; int __orig_mode;
449
+ SMBCCTX *ctx; Data_Get_Struct(self, SMBCCTX, ctx);
450
+
451
+ /* Scan arguments */
452
+ rb_scan_args(__p_argc, __p_argv, "12",&__v_url, &__v_flags, &__v_mode);
453
+
454
+ /* Set defaults */
455
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
456
+
457
+ if (__p_argc > 1)
458
+ __orig_flags = flags = NUM2INT(__v_flags);
459
+ else
460
+ flags = O_RDONLY;
461
+
462
+ if (__p_argc > 2)
463
+ __orig_mode = mode = NUM2INT(__v_mode);
464
+ else
465
+ mode = 0666;
466
+
467
+
468
+ #line 112 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
469
+
470
+ do {
471
+ volatile VALUE rfile ;
472
+ SMBCFILE * file =
473
+ ctx->open(ctx, url, flags, mode);
474
+ rfile = Data_Wrap_Struct(cSmbFile, NULL, NULL, file);
475
+ do { __p_retval = rfile; goto out; } while(0);
476
+
477
+ } while(0);
478
+
479
+ out:
480
+ return __p_retval;
481
+ }
482
+
483
+ static VALUE
484
+ CTX_file_write(VALUE self, VALUE sfile, VALUE data)
485
+ {
486
+ VALUE __p_retval = Qnil;
487
+ SMBCCTX *ctx; Data_Get_Struct(self, SMBCCTX, ctx);
488
+ Check_Type(sfile, T_DATA);
489
+ Check_Type(data, T_STRING);
490
+
491
+ #line 118 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
492
+
493
+ do {
494
+ SMBCFILE * file ;
495
+ Data_Get_Struct(sfile, SMBCFILE, file);
496
+ StringValue(data);
497
+ do { __p_retval = LONG2NUM(ctx->write(ctx, file, RSTRING_PTR(data), RSTRING_LEN(data))); goto out; } while(0);
498
+
499
+ } while(0);
500
+
501
+ out:
502
+ return __p_retval;
503
+ }
504
+
505
+ static VALUE
506
+ CTX_file_close(VALUE self, VALUE sfile)
507
+ {
508
+ SMBCCTX *ctx; Data_Get_Struct(self, SMBCCTX, ctx);
509
+ Check_Type(sfile, T_DATA);
510
+
511
+ #line 123 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
512
+
513
+ do {
514
+ SMBCFILE * file ;
515
+ Data_Get_Struct(sfile, SMBCFILE, file);
516
+ ctx->close_fn(ctx, file);
517
+
518
+
519
+ } while(0);
520
+
521
+ return Qnil;
522
+ }
523
+
524
+ static VALUE
525
+ Dir_CLASS_new(VALUE self, VALUE __v_url)
526
+ {
527
+ VALUE __p_retval = Qnil;
528
+ char * url; char * __orig_url;
529
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
530
+
531
+ #line 145 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
532
+
533
+ do {
534
+ volatile VALUE val ;
535
+ struct rb_smbprivate * dir ;
536
+ int handle ;
537
+ if((handle = smbc_opendir(url)) < 0) { rb_sys_fail("Unable to open dir URL");
538
+ } val = Data_Make_Struct(self, struct rb_smbprivate, 0, smbprivate_free, dir);
539
+ dir->handle = handle;
540
+ rb_obj_call_init(val, 0, NULL);
541
+ do { __p_retval = val; goto out; } while(0);
542
+
543
+ } while(0);
544
+
545
+ out:
546
+ return __p_retval;
547
+ }
548
+
549
+ static VALUE
550
+ Dir_CLASS_rmdir(VALUE self, VALUE __v_url)
551
+ {
552
+ char * url; char * __orig_url;
553
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
554
+
555
+ #line 161 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
556
+ if (smbc_rmdir(url) < 0) rb_sys_fail(url);
557
+
558
+ return Qnil;
559
+ }
560
+
561
+ static VALUE
562
+ Dir_CLASS_mkdir(VALUE self, VALUE __v_url, VALUE __v_mode)
563
+ {
564
+ char * url; char * __orig_url;
565
+ int mode; int __orig_mode;
566
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
567
+ __orig_mode = mode = NUM2INT(__v_mode);
568
+
569
+ #line 165 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
570
+ if (smbc_mkdir(url, mode) < 0) rb_sys_fail(url);
571
+
572
+ return Qnil;
573
+ }
574
+
575
+ static VALUE
576
+ Dir_initialize(VALUE self)
577
+ {
578
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
579
+
580
+ #line 172 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
581
+
582
+ return Qnil;
583
+ }
584
+
585
+ static VALUE
586
+ Dir_read_entry(VALUE self)
587
+ {
588
+ VALUE __p_retval = Qnil;
589
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
590
+
591
+ #line 174 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
592
+
593
+ do {
594
+ struct smbc_dirent* de ;
595
+ de = smbc_readdir(dir->handle);
596
+ if(de) { do { __p_retval = rb_struct_new(structDirEntry, INT2NUM(de->smbc_type), rb_str_new2(de->comment), rb_str_new2(de->name)); goto out; } while(0); }
597
+
598
+ } while(0);
599
+
600
+ out:
601
+ return __p_retval;
602
+ }
603
+
604
+ static VALUE
605
+ Dir_read(VALUE self)
606
+ {
607
+ VALUE __p_retval = Qnil;
608
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
609
+
610
+ #line 185 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
611
+
612
+ do {
613
+ struct smbc_dirent* de ;
614
+ de = smbc_readdir(dir->handle);
615
+ if(de) do { __p_retval = rb_str_new2(de->name); goto out; } while(0);
616
+
617
+ } while(0);
618
+
619
+ out:
620
+ return __p_retval;
621
+ }
622
+
623
+ static VALUE
624
+ Dir_tell(VALUE self)
625
+ {
626
+ VALUE __p_retval = Qnil;
627
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
628
+
629
+ #line 191 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
630
+ do { __p_retval = INT2NUM(smbc_telldir(dir->handle)); goto out; } while(0);
631
+ out:
632
+ return __p_retval;
633
+ }
634
+
635
+ static VALUE
636
+ Dir_url(VALUE self)
637
+ {
638
+ VALUE __p_retval = Qnil;
639
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
640
+
641
+ #line 194 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
642
+ do { __p_retval = rb_str_new2(dir->url); goto out; } while(0);
643
+ out:
644
+ return __p_retval;
645
+ }
646
+
647
+ static VALUE
648
+ Dir_close(VALUE self)
649
+ {
650
+ rb_smbprivate *dir; Data_Get_Struct(self, rb_smbprivate, dir);
651
+
652
+ #line 197 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
653
+ smbc_closedir(dir->handle);
654
+ dir->handle = 0;
655
+
656
+ return Qnil;
657
+ }
658
+
659
+ static VALUE
660
+ File_CLASS_new(VALUE self, VALUE __v_url, VALUE __v_flags, VALUE __v_mode)
661
+ {
662
+ VALUE __p_retval = Qnil;
663
+ char * url; char * __orig_url;
664
+ int flags; int __orig_flags;
665
+ int mode; int __orig_mode;
666
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
667
+ __orig_flags = flags = NUM2INT(__v_flags);
668
+ __orig_mode = mode = NUM2INT(__v_mode);
669
+
670
+ #line 204 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
671
+
672
+ do {
673
+ volatile VALUE val ;
674
+ struct rb_smbprivate * file ;
675
+ int handle =
676
+ 0;
677
+ if ((handle = smbc_open(url, flags, mode)) < 0) { rb_sys_fail(url);
678
+ } val = Data_Make_Struct(self, struct rb_smbprivate, 0, smbprivate_free, file);
679
+ file->handle = handle;
680
+ file->url = strdup(url);
681
+ rb_obj_call_init(val, 0, NULL);
682
+ do { __p_retval = val; goto out; } while(0);
683
+
684
+ } while(0);
685
+
686
+ out:
687
+ return __p_retval;
688
+ }
689
+
690
+ static VALUE
691
+ File_CLASS_create(VALUE self, VALUE __v_url, VALUE __v_mode)
692
+ {
693
+ VALUE __p_retval = Qnil;
694
+ char * url; char * __orig_url;
695
+ int mode; int __orig_mode;
696
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
697
+ __orig_mode = mode = NUM2INT(__v_mode);
698
+
699
+ #line 222 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
700
+
701
+ do {
702
+ volatile VALUE val ;
703
+ struct rb_smbprivate * file ;
704
+ int handle =
705
+ 0;
706
+ if ((handle = smbc_creat(url, mode)) < 0) { rb_sys_fail(url);
707
+ } val = Data_Make_Struct(self, struct rb_smbprivate, 0, smbprivate_free, file);
708
+ file->handle = handle;
709
+ file->url = strdup(url);
710
+ rb_obj_call_init(val, 0, NULL);
711
+ do { __p_retval = val; goto out; } while(0);
712
+
713
+ } while(0);
714
+
715
+ out:
716
+ return __p_retval;
717
+ }
718
+
719
+ static VALUE
720
+ File_CLASS_unlink(VALUE self, VALUE __v_url)
721
+ {
722
+ char * url; char * __orig_url;
723
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
724
+
725
+ #line 240 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
726
+ if (smbc_unlink(url) < 0) rb_sys_fail(url);
727
+
728
+ return Qnil;
729
+ }
730
+
731
+ static VALUE
732
+ File_CLASS_rename(VALUE self, VALUE __v_ourl, VALUE __v_nurl)
733
+ {
734
+ char * ourl; char * __orig_ourl;
735
+ char * nurl; char * __orig_nurl;
736
+ __orig_ourl = ourl = ( NIL_P(__v_ourl) ? NULL : StringValuePtr(__v_ourl) );
737
+ __orig_nurl = nurl = ( NIL_P(__v_nurl) ? NULL : StringValuePtr(__v_nurl) );
738
+
739
+ #line 244 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
740
+ if (smbc_rename(ourl, nurl) < 0) rb_sys_fail(ourl);
741
+
742
+ return Qnil;
743
+ }
744
+
745
+ static VALUE
746
+ File_CLASS_stat(VALUE self, VALUE __v_url)
747
+ {
748
+ VALUE __p_retval = Qnil;
749
+ char * url; char * __orig_url;
750
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
751
+
752
+ #line 248 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
753
+
754
+ do {
755
+ struct stat s ;
756
+ if (smbc_stat(url, &s) < 0) rb_sys_fail(url);
757
+ do { __p_retval = stat_new(&s); goto out; } while(0);
758
+
759
+ } while(0);
760
+
761
+ out:
762
+ return __p_retval;
763
+ }
764
+
765
+ static VALUE
766
+ File_initialize(VALUE self)
767
+ {
768
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
769
+
770
+ #line 257 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
771
+
772
+ return Qnil;
773
+ }
774
+
775
+ static VALUE
776
+ File_stat(VALUE self)
777
+ {
778
+ VALUE __p_retval = Qnil;
779
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
780
+
781
+ #line 259 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
782
+
783
+ do {
784
+ struct stat s ;
785
+ if (smbc_fstat(file->handle, &s) < 0) rb_sys_fail(file->url);
786
+ do { __p_retval = stat_new(&s); goto out; } while(0);
787
+
788
+ } while(0);
789
+
790
+ out:
791
+ return __p_retval;
792
+ }
793
+
794
+ static VALUE
795
+ File_url(VALUE self)
796
+ {
797
+ VALUE __p_retval = Qnil;
798
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
799
+
800
+ #line 265 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
801
+ do { __p_retval = rb_str_new2(file->url); goto out; } while(0);
802
+ out:
803
+ return __p_retval;
804
+ }
805
+
806
+ static VALUE
807
+ File_seek(VALUE self, VALUE __v_offset, VALUE __v_whence)
808
+ {
809
+ VALUE __p_retval = Qnil;
810
+ off_t offset; off_t __orig_offset;
811
+ int whence; int __orig_whence;
812
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
813
+ __orig_offset = offset = NUM2OFFT(__v_offset);
814
+ __orig_whence = whence = NUM2INT(__v_whence);
815
+
816
+ #line 268 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
817
+ do { __p_retval = INT2NUM(smbc_lseek(file->handle, offset, whence)); goto out; } while(0);
818
+ out:
819
+ ;
820
+ return __p_retval;
821
+ }
822
+
823
+ static VALUE
824
+ File_read(int __p_argc, VALUE *__p_argv, VALUE self)
825
+ {
826
+ VALUE __p_retval = Qnil;
827
+ VALUE __v_bytes_to_read = Qnil;
828
+ int bytes_to_read; int __orig_bytes_to_read;
829
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
830
+
831
+ /* Scan arguments */
832
+ rb_scan_args(__p_argc, __p_argv, "01",&__v_bytes_to_read);
833
+
834
+ /* Set defaults */
835
+ if (__p_argc > 0)
836
+ __orig_bytes_to_read = bytes_to_read = NUM2INT(__v_bytes_to_read);
837
+ else
838
+ bytes_to_read = -1;
839
+
840
+
841
+ #line 271 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
842
+
843
+ do {
844
+ size_t read ;
845
+ struct stat s ;
846
+ char buf [4096] ;
847
+ volatile VALUE str =
848
+ Qnil;
849
+ int next_read = 0;
850
+ if(bytes_to_read == -1) { if (smbc_fstat(file->handle, &s) < 0) rb_sys_fail(file->url);
851
+ bytes_to_read = s.st_size;
852
+ } if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
853
+ else next_read = bytes_to_read;
854
+ while((read = smbc_read(file->handle, buf, next_read))!=0) { if(str == Qnil) str = rb_str_new("",0);
855
+ rb_str_cat(str, buf, read);
856
+ bytes_to_read -= read;
857
+ if(bytes_to_read == 0) break;
858
+ if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
859
+ else next_read = bytes_to_read;
860
+ } do { __p_retval = str; goto out; } while(0);
861
+
862
+ } while(0);
863
+
864
+ out:
865
+ return __p_retval;
866
+ }
867
+
868
+ static VALUE
869
+ File_write(VALUE self, VALUE buf)
870
+ {
871
+ VALUE __p_retval = Qnil;
872
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
873
+ Check_Type(buf, T_STRING);
874
+
875
+ #line 308 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
876
+
877
+ do {
878
+ int i ;
879
+ StringValue(buf);
880
+ i = smbc_write(file->handle, RSTRING_PTR(buf), RSTRING_LEN(buf));
881
+ if (i < 0) rb_sys_fail("write");
882
+ do { __p_retval = LONG2NUM(i); goto out; } while(0);
883
+
884
+ } while(0);
885
+
886
+ out:
887
+ return __p_retval;
888
+ }
889
+
890
+ static VALUE
891
+ File_close(VALUE self)
892
+ {
893
+ rb_smbprivate *file; Data_Get_Struct(self, rb_smbprivate, file);
894
+
895
+ #line 316 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
896
+ smbc_close(file->handle);
897
+ file->handle = 0;
898
+
899
+ return Qnil;
900
+ }
901
+
902
+ static VALUE
903
+ File_CLASS_read(VALUE self, VALUE __v_url)
904
+ {
905
+ VALUE __p_retval = Qnil;
906
+ char * url; char * __orig_url;
907
+ __orig_url = url = ( NIL_P(__v_url) ? NULL : StringValuePtr(__v_url) );
908
+
909
+ #line 321 "/home/geoff/Projects/smb-ruby/ext/smb/smb.cr"
910
+
911
+ do {
912
+ size_t read ;
913
+ struct stat s ;
914
+ char buf [4096] ;
915
+ volatile VALUE str ;
916
+ int next_read = 0, handle, bytes_to_read;
917
+ if ((handle = smbc_open(url, O_RDONLY, 0)) < 0) rb_sys_fail(url);
918
+ if (smbc_fstat(handle, &s) < 0) rb_sys_fail(url);
919
+ bytes_to_read = s.st_size;
920
+ if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
921
+ else next_read = bytes_to_read;
922
+ str = rb_str_new("",0);
923
+ while((read = smbc_read(handle, buf, next_read))!=0) { rb_str_cat(str, buf, read);
924
+ bytes_to_read -= read;
925
+ if(bytes_to_read == 0) break;
926
+ if(bytes_to_read > sizeof(buf)) next_read = sizeof(buf);
927
+ else next_read = bytes_to_read;
928
+ } smbc_close(handle);
929
+ do { __p_retval = str; goto out; } while(0);
930
+
931
+ } while(0);
932
+
933
+ out:
934
+ return __p_retval;
935
+ }
936
+
937
+ /* Init */
938
+ void
939
+ Init_smb(void)
940
+ {
941
+
942
+ /* rb_cStat = rb_eval_string("File::Stat");*/
943
+ rb_gc_register_address(&_gcpool_Credentials);
944
+ mSMB = rb_define_module("SMB");
945
+ rb_define_singleton_method(mSMB, "init", SMB_CLASS_init, -1);
946
+ enumBaseClass = rb_define_class("Enum", rb_cObject);
947
+ rb_define_method(enumBaseClass, "inspect", rubber_enum_inspect, 0);
948
+ rb_define_method(enumBaseClass, "to_i", rubber_enum_to_i, 0);
949
+ rb_define_method(enumBaseClass, "coerce", rubber_enum_coerce, 1);
950
+ rb_define_method(enumBaseClass, "to_s", rubber_enum_to_s, 0);
951
+ rb_define_method(enumBaseClass, "to_str", rubber_enum_to_s, 0);
952
+ rb_define_method(enumBaseClass, "fullname", rubber_enum_to_s, 0);
953
+ rb_define_method(enumBaseClass, "name", rubber_enum_name, 0);
954
+ rb_define_method(enumBaseClass, "<=>", rubber_enum_cmp, 0);
955
+
956
+ enumType = rb_define_class_under(mSMB, "Type", enumBaseClass);
957
+ enumType_SMBC_WORKGROUP = make_enum_value(enumType, SMBC_WORKGROUP, "workgroup", "SMBC_WORKGROUP");
958
+ rb_obj_freeze(enumType_SMBC_WORKGROUP);
959
+ rb_define_const(enumType, "WORKGROUP", enumType_SMBC_WORKGROUP);
960
+ enumType_SMBC_SERVER = make_enum_value(enumType, SMBC_SERVER, "server", "SMBC_SERVER");
961
+ rb_obj_freeze(enumType_SMBC_SERVER);
962
+ rb_define_const(enumType, "SERVER", enumType_SMBC_SERVER);
963
+ enumType_SMBC_FILE_SHARE = make_enum_value(enumType, SMBC_FILE_SHARE, "file-share", "SMBC_FILE_SHARE");
964
+ rb_obj_freeze(enumType_SMBC_FILE_SHARE);
965
+ rb_define_const(enumType, "FILE_SHARE", enumType_SMBC_FILE_SHARE);
966
+ enumType_SMBC_PRINTER_SHARE = make_enum_value(enumType, SMBC_PRINTER_SHARE, "printer-share", "SMBC_PRINTER_SHARE");
967
+ rb_obj_freeze(enumType_SMBC_PRINTER_SHARE);
968
+ rb_define_const(enumType, "PRINTER_SHARE", enumType_SMBC_PRINTER_SHARE);
969
+ enumType_SMBC_COMMS_SHARE = make_enum_value(enumType, SMBC_COMMS_SHARE, "comms-share", "SMBC_COMMS_SHARE");
970
+ rb_obj_freeze(enumType_SMBC_COMMS_SHARE);
971
+ rb_define_const(enumType, "COMMS_SHARE", enumType_SMBC_COMMS_SHARE);
972
+ enumType_SMBC_IPC_SHARE = make_enum_value(enumType, SMBC_IPC_SHARE, "ipc-share", "SMBC_IPC_SHARE");
973
+ rb_obj_freeze(enumType_SMBC_IPC_SHARE);
974
+ rb_define_const(enumType, "IPC_SHARE", enumType_SMBC_IPC_SHARE);
975
+ enumType_SMBC_DIR = make_enum_value(enumType, SMBC_DIR, "dir", "SMBC_DIR");
976
+ rb_obj_freeze(enumType_SMBC_DIR);
977
+ rb_define_const(enumType, "DIR", enumType_SMBC_DIR);
978
+ enumType_SMBC_FILE = make_enum_value(enumType, SMBC_FILE, "file", "SMBC_FILE");
979
+ rb_obj_freeze(enumType_SMBC_FILE);
980
+ rb_define_const(enumType, "FILE", enumType_SMBC_FILE);
981
+ enumType_SMBC_LINK = make_enum_value(enumType, SMBC_LINK, "link", "SMBC_LINK");
982
+ rb_obj_freeze(enumType_SMBC_LINK);
983
+ rb_define_const(enumType, "LINK", enumType_SMBC_LINK);
984
+ cCTX = rb_define_class_under(mSMB, "CTX", rb_cObject);
985
+ rb_define_singleton_method(cCTX, "default", CTX_CLASS_default, 0);
986
+ rb_define_alloc_func(cCTX, CTX_CLASS___alloc__);
987
+ rb_define_method(cCTX, "initialize", CTX_initialize, 0);
988
+ rb_define_method(cCTX, "file_creat", CTX_file_creat, -1);
989
+ rb_define_method(cCTX, "file_open", CTX_file_open, -1);
990
+ rb_define_method(cCTX, "file_write", CTX_file_write, 2);
991
+ rb_define_method(cCTX, "file_close", CTX_file_close, 1);
992
+ cSmbFile = rb_define_class_under(cCTX, "SmbFile", rb_cObject);
993
+ structDirEntry = rb_struct_define("DirEntry", "type", "comment", "name", NULL);
994
+ rb_define_const(mSMB, "DirEntry", structDirEntry);
995
+ cDir = rb_define_class_under(mSMB, "Dir", rb_cObject);
996
+ rb_define_singleton_method(cDir, "new", Dir_CLASS_new, 1);
997
+ rb_define_singleton_method(cDir, "rmdir", Dir_CLASS_rmdir, 1);
998
+ rb_define_singleton_method(cDir, "mkdir", Dir_CLASS_mkdir, 2);
999
+ rb_define_method(cDir, "initialize", Dir_initialize, 0);
1000
+ rb_define_method(cDir, "read_entry", Dir_read_entry, 0);
1001
+ rb_define_method(cDir, "read", Dir_read, 0);
1002
+ rb_define_method(cDir, "tell", Dir_tell, 0);
1003
+ rb_define_method(cDir, "url", Dir_url, 0);
1004
+ rb_define_method(cDir, "close", Dir_close, 0);
1005
+ cFile = rb_define_class_under(mSMB, "File", rb_cObject);
1006
+ rb_define_singleton_method(cFile, "new", File_CLASS_new, 3);
1007
+ rb_define_singleton_method(cFile, "create", File_CLASS_create, 2);
1008
+ rb_define_singleton_method(cFile, "unlink", File_CLASS_unlink, 1);
1009
+ rb_define_singleton_method(cFile, "rename", File_CLASS_rename, 2);
1010
+ rb_define_singleton_method(cFile, "stat", File_CLASS_stat, 1);
1011
+ rb_define_method(cFile, "initialize", File_initialize, 0);
1012
+ rb_define_method(cFile, "stat", File_stat, 0);
1013
+ rb_define_method(cFile, "url", File_url, 0);
1014
+ rb_define_method(cFile, "seek", File_seek, 2);
1015
+ rb_define_method(cFile, "read", File_read, -1);
1016
+ rb_define_method(cFile, "write", File_write, 1);
1017
+ rb_define_method(cFile, "close", File_close, 0);
1018
+ rb_define_singleton_method(cFile, "read", File_CLASS_read, 1);
1019
+ }