zipruby 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of zipruby might be problematic. Click here for more details.

Files changed (4) hide show
  1. data/ext/zipruby.h +1 -1
  2. data/ext/zipruby_archive.c +28 -8
  3. data/zipruby.c +28 -8
  4. metadata +2 -2
data/ext/zipruby.h CHANGED
@@ -1,7 +1,7 @@
1
1
  #ifndef __ZIPRUBY_H__
2
2
  #define __ZIPRUBY_H__
3
3
 
4
- #define VERSION "0.2.4"
4
+ #define VERSION "0.2.5"
5
5
  #define ERRSTR_BUFSIZE 256
6
6
  #define DATA_BUFSIZE 8192
7
7
 
@@ -323,14 +323,24 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
323
323
  static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source) {
324
324
  struct zipruby_archive *p_archive;
325
325
  struct zip_source *zsource;
326
+ int i_index;
326
327
  char *data;
327
328
  off_t len;
328
329
 
329
- Check_Type(index, T_FIXNUM);
330
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
331
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
332
+ }
333
+
330
334
  Check_Type(source, T_STRING);
331
335
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
332
336
  Check_Archive(p_archive);
333
337
 
338
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
339
+ i_index = NUM2INT(index);
340
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
341
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
342
+ }
343
+
334
344
  len = RSTRING(source)->len;
335
345
 
336
346
  if ((data = malloc(len)) == NULL) {
@@ -341,14 +351,14 @@ static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE sourc
341
351
 
342
352
  if ((zsource = zip_source_buffer(p_archive->archive, data, len, 1)) == NULL) {
343
353
  free(data);
344
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
354
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
345
355
  }
346
356
 
347
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
357
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
348
358
  zip_source_free(zsource);
349
359
  zip_unchange_all(p_archive->archive);
350
360
  zip_unchange_archive(p_archive->archive);
351
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
361
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
352
362
  }
353
363
 
354
364
  return Qnil;
@@ -413,21 +423,31 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
413
423
  static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname) {
414
424
  struct zipruby_archive *p_archive;
415
425
  struct zip_source *zsource;
426
+ int i_index;
427
+
428
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
429
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
430
+ }
416
431
 
417
- Check_Type(index, T_FIXNUM);
418
432
  Check_Type(fname, T_STRING);
419
433
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
420
434
  Check_Archive(p_archive);
421
435
 
436
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
437
+ i_index = NUM2INT(index);
438
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
439
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
440
+ }
441
+
422
442
  if ((zsource = zip_source_file(p_archive->archive, StringValuePtr(fname), 0, -1)) == NULL) {
423
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
443
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
424
444
  }
425
445
 
426
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
446
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
427
447
  zip_source_free(zsource);
428
448
  zip_unchange_all(p_archive->archive);
429
449
  zip_unchange_archive(p_archive->archive);
430
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
450
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
431
451
  }
432
452
 
433
453
  return Qnil;
data/zipruby.c CHANGED
@@ -342,14 +342,24 @@ static VALUE zipruby_archive_add_buffer(VALUE self, VALUE name, VALUE source) {
342
342
  static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE source) {
343
343
  struct zipruby_archive *p_archive;
344
344
  struct zip_source *zsource;
345
+ int i_index;
345
346
  char *data;
346
347
  off_t len;
347
348
 
348
- Check_Type(index, T_FIXNUM);
349
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
350
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
351
+ }
352
+
349
353
  Check_Type(source, T_STRING);
350
354
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
351
355
  Check_Archive(p_archive);
352
356
 
357
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
358
+ i_index = NUM2INT(index);
359
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
360
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
361
+ }
362
+
353
363
  len = RSTRING(source)->len;
354
364
 
355
365
  if ((data = malloc(len)) == NULL) {
@@ -360,14 +370,14 @@ static VALUE zipruby_archive_replace_buffer(VALUE self, VALUE index, VALUE sourc
360
370
 
361
371
  if ((zsource = zip_source_buffer(p_archive->archive, data, len, 1)) == NULL) {
362
372
  free(data);
363
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
373
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
364
374
  }
365
375
 
366
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
376
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
367
377
  zip_source_free(zsource);
368
378
  zip_unchange_all(p_archive->archive);
369
379
  zip_unchange_archive(p_archive->archive);
370
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
380
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
371
381
  }
372
382
 
373
383
  return Qnil;
@@ -432,21 +442,31 @@ static VALUE zipruby_archive_add_file(int argc, VALUE *argv, VALUE self) {
432
442
  static VALUE zipruby_archive_replace_file(VALUE self, VALUE index, VALUE fname) {
433
443
  struct zipruby_archive *p_archive;
434
444
  struct zip_source *zsource;
445
+ int i_index;
446
+
447
+ if (!rb_obj_is_instance_of(index, rb_cString) && !rb_obj_is_instance_of(index, rb_cFixnum)) {
448
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or String)", rb_class2name(CLASS_OF(index)));
449
+ }
435
450
 
436
- Check_Type(index, T_FIXNUM);
437
451
  Check_Type(fname, T_STRING);
438
452
  Data_Get_Struct(self, struct zipruby_archive, p_archive);
439
453
  Check_Archive(p_archive);
440
454
 
455
+ if (rb_obj_is_instance_of(index, rb_cFixnum)) {
456
+ i_index = NUM2INT(index);
457
+ } else if ((i_index = zip_name_locate(p_archive->archive, StringValuePtr(index), ZIP_FL_NOCASE)) == -1) {
458
+ rb_raise(Error, "Replace file failed - %s: Archive does not contain a file", StringValuePtr(index));
459
+ }
460
+
441
461
  if ((zsource = zip_source_file(p_archive->archive, StringValuePtr(fname), 0, -1)) == NULL) {
442
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
462
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
443
463
  }
444
464
 
445
- if (zip_replace(p_archive->archive, NUM2INT(index), zsource) == -1) {
465
+ if (zip_replace(p_archive->archive, i_index, zsource) == -1) {
446
466
  zip_source_free(zsource);
447
467
  zip_unchange_all(p_archive->archive);
448
468
  zip_unchange_archive(p_archive->archive);
449
- rb_raise(Error, "Replace file failed at %d: %s", NUM2INT(index), zip_strerror(p_archive->archive));
469
+ rb_raise(Error, "Replace file failed at %d: %s", i_index, zip_strerror(p_archive->archive));
450
470
  }
451
471
 
452
472
  return Qnil;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-01 00:00:00 +09:00
12
+ date: 2008-05-05 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15