zipruby 0.2.9 → 0.3.0

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.

data/LICENSE.libzip ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 1999-2008 Dieter Baron and Thomas Klausner
2
+ The authors can be contacted at <libzip@nih.at>
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in
11
+ the documentation and/or other materials provided with the
12
+ distribution.
13
+ 3. The names of the authors may not be used to endorse or promote
14
+ products derived from this software without specific prior
15
+ written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
18
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
21
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25
+ IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
+ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.txt CHANGED
@@ -155,14 +155,14 @@ https://rubyforge.org/frs/?group_id=6124
155
155
  Zip::Archive.encrypt('filename.zip', 'password')
156
156
  # or
157
157
  # Zip::Archive.encrypt('filename.zip') do |ar|
158
- # ar.encrypt('filename.zip', 'password')
158
+ # ar.encrypt('password')
159
159
  # end
160
160
 
161
161
  # decrypt
162
162
  Zip::Archive.decrypt('filename.zip', 'password')
163
163
  # or
164
164
  # Zip::Archive.decrypt('filename.zip') do |ar|
165
- # ar.decrypt('filename.zip', 'password')
165
+ # ar.decrypt('password')
166
166
  # end
167
167
 
168
168
  === modifying zip data in memory
@@ -199,7 +199,7 @@ https://rubyforge.org/frs/?group_id=6124
199
199
  end
200
200
 
201
201
  == License
202
- Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
202
+ Copyright (c) 2008,2009 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
203
203
  All rights reserved.
204
204
 
205
205
  Redistribution and use in source and binary forms, with or without modification,
data/ext/tmpfile.c CHANGED
@@ -1,173 +1,175 @@
1
- #include <stdio.h>
2
- #include <stdlib.h>
3
- #include <string.h>
4
- #include <sys/types.h>
5
- #include <sys/stat.h>
6
-
7
- #ifdef _WIN32
8
- #include <windows.h>
9
- #include <io.h>
10
- #include <fcntl.h>
11
- #include <share.h>
12
- #endif
13
-
14
- #include "tmpfile.h"
15
- #include "ruby.h"
16
-
17
- #ifndef _WIN32
18
- #ifndef HAVE_MKSTEMP
19
- int _zip_mkstemp(char *);
20
- #define mkstemp _zip_mkstemp
21
- #endif
22
- #endif
23
-
24
- static int write_from_proc(VALUE proc, int fd);
25
- static VALUE proc_call(VALUE proc);
26
-
27
- char *zipruby_tmpnam(void *data, int len) {
28
- char *filnam;
29
-
30
- #ifdef _WIN32
31
- int fd;
32
- char tmpdirnam[_MAX_PATH];
33
- char tmpfilnam[_MAX_PATH];
34
- int namlen;
35
-
36
- memset(tmpdirnam, 0, _MAX_PATH);
37
-
38
- if (GetTempPathA(_MAX_PATH, tmpdirnam) == 0) {
39
- return NULL;
40
- }
41
-
42
- memset(tmpfilnam, 0, _MAX_PATH);
43
-
44
- if (GetTempFileNameA(tmpdirnam, "zrb", 0, tmpfilnam) == 0) {
45
- return NULL;
46
- }
47
-
48
- namlen = strlen(tmpfilnam) + 1;
49
-
50
- if ((filnam = calloc(namlen, sizeof(char))) == NULL) {
51
- return NULL;
52
- }
53
-
54
- if (strcpy_s(filnam, namlen, tmpfilnam) != 0) {
55
- free(filnam);
56
- return NULL;
57
- }
58
-
59
- if (data) {
60
- if ((_sopen_s(&fd, filnam, _O_WRONLY | _O_BINARY, _SH_DENYRD, _S_IWRITE)) != 0) {
61
- free(filnam);
62
- return NULL;
63
- }
64
-
65
- if (len < 0) {
66
- if (write_from_proc((VALUE) data, fd) == -1) {
67
- free(filnam);
68
- return NULL;
69
- }
70
- } else {
71
- if (_write(fd, data, len) == -1) {
72
- free(filnam);
73
- return NULL;
74
- }
75
- }
76
-
77
- if (_close(fd) == -1) {
78
- free(filnam);
79
- return NULL;
80
- }
81
- }
82
- #else
83
- int fd;
84
- #ifdef P_tmpdir
85
- int namlen = 16 + strlen(P_tmpdir);
86
- char *dirnam = P_tmpdir;
87
- #else
88
- int namlen = 20;
89
- char *dirnam = "/tmp";
90
- #endif
91
-
92
- if ((filnam = calloc(namlen, sizeof(char))) == NULL) {
93
- return NULL;
94
- }
95
-
96
- strcpy(filnam, dirnam);
97
- strcat(filnam, "/zipruby.XXXXXX");
98
-
99
- if ((fd = mkstemp(filnam)) == -1) {
100
- free(filnam);
101
- return NULL;
102
- }
103
-
104
- if (data) {
105
- if (len < 0) {
106
- if (write_from_proc((VALUE) data, fd) == -1) {
107
- free(filnam);
108
- return NULL;
109
- }
110
- } else {
111
- if (write(fd, data, len) == -1) {
112
- free(filnam);
113
- return NULL;
114
- }
115
- }
116
- }
117
-
118
- if (close(fd) == -1) {
119
- free(filnam);
120
- return NULL;
121
- }
122
- #endif
123
-
124
- return filnam;
125
- }
126
-
127
- void zipruby_rmtmp(const char *tmpfilnam) {
128
- struct stat st;
129
-
130
- if (!tmpfilnam) {
131
- return;
132
- }
133
-
134
- if (stat(tmpfilnam, &st) != 0) {
135
- return;
136
- }
137
-
138
- #ifdef _WIN32
139
- _unlink(tmpfilnam);
140
- #else
141
- unlink(tmpfilnam);
142
- #endif
143
- }
144
-
145
- static int write_from_proc(VALUE proc, int fd) {
146
- while (1) {
147
- VALUE src = rb_protect(proc_call, proc, NULL);
148
-
149
- if (TYPE(src) != T_STRING) {
150
- break;
151
- }
152
-
153
- if (RSTRING_LEN(src) < 1) {
154
- break;
155
- }
156
-
157
- #ifdef _WIN32
158
- if (_write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
159
- return -1;
160
- }
161
- #else
162
- if (write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
163
- return -1;
164
- }
165
- #endif
166
- }
167
-
168
- return 0;
169
- }
170
-
171
- static VALUE proc_call(VALUE proc) {
172
- return rb_funcall(proc, rb_intern("call"), 0);
173
- }
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+ #include <sys/types.h>
5
+ #include <sys/stat.h>
6
+
7
+ #ifdef _WIN32
8
+ #if RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8
9
+ #include <windows.h>
10
+ #endif
11
+ #include <io.h>
12
+ #include <fcntl.h>
13
+ #include <share.h>
14
+ #endif
15
+
16
+ #include "tmpfile.h"
17
+ #include "ruby.h"
18
+
19
+ #ifndef _WIN32
20
+ #ifndef HAVE_MKSTEMP
21
+ int _zip_mkstemp(char *);
22
+ #define mkstemp _zip_mkstemp
23
+ #endif
24
+ #endif
25
+
26
+ static int write_from_proc(VALUE proc, int fd);
27
+ static VALUE proc_call(VALUE proc);
28
+
29
+ char *zipruby_tmpnam(void *data, int len) {
30
+ char *filnam;
31
+
32
+ #ifdef _WIN32
33
+ int fd;
34
+ char tmpdirnam[_MAX_PATH];
35
+ char tmpfilnam[_MAX_PATH];
36
+ int namlen;
37
+
38
+ memset(tmpdirnam, 0, _MAX_PATH);
39
+
40
+ if (GetTempPathA(_MAX_PATH, tmpdirnam) == 0) {
41
+ return NULL;
42
+ }
43
+
44
+ memset(tmpfilnam, 0, _MAX_PATH);
45
+
46
+ if (GetTempFileNameA(tmpdirnam, "zrb", 0, tmpfilnam) == 0) {
47
+ return NULL;
48
+ }
49
+
50
+ namlen = strlen(tmpfilnam) + 1;
51
+
52
+ if ((filnam = calloc(namlen, sizeof(char))) == NULL) {
53
+ return NULL;
54
+ }
55
+
56
+ if (strcpy_s(filnam, namlen, tmpfilnam) != 0) {
57
+ free(filnam);
58
+ return NULL;
59
+ }
60
+
61
+ if (data) {
62
+ if ((_sopen_s(&fd, filnam, _O_WRONLY | _O_BINARY, _SH_DENYRD, _S_IWRITE)) != 0) {
63
+ free(filnam);
64
+ return NULL;
65
+ }
66
+
67
+ if (len < 0) {
68
+ if (write_from_proc((VALUE) data, fd) == -1) {
69
+ free(filnam);
70
+ return NULL;
71
+ }
72
+ } else {
73
+ if (_write(fd, data, len) == -1) {
74
+ free(filnam);
75
+ return NULL;
76
+ }
77
+ }
78
+
79
+ if (_close(fd) == -1) {
80
+ free(filnam);
81
+ return NULL;
82
+ }
83
+ }
84
+ #else
85
+ int fd;
86
+ #ifdef P_tmpdir
87
+ int namlen = 16 + strlen(P_tmpdir);
88
+ char *dirnam = P_tmpdir;
89
+ #else
90
+ int namlen = 20;
91
+ char *dirnam = "/tmp";
92
+ #endif
93
+
94
+ if ((filnam = calloc(namlen, sizeof(char))) == NULL) {
95
+ return NULL;
96
+ }
97
+
98
+ strcpy(filnam, dirnam);
99
+ strcat(filnam, "/zipruby.XXXXXX");
100
+
101
+ if ((fd = mkstemp(filnam)) == -1) {
102
+ free(filnam);
103
+ return NULL;
104
+ }
105
+
106
+ if (data) {
107
+ if (len < 0) {
108
+ if (write_from_proc((VALUE) data, fd) == -1) {
109
+ free(filnam);
110
+ return NULL;
111
+ }
112
+ } else {
113
+ if (write(fd, data, len) == -1) {
114
+ free(filnam);
115
+ return NULL;
116
+ }
117
+ }
118
+ }
119
+
120
+ if (close(fd) == -1) {
121
+ free(filnam);
122
+ return NULL;
123
+ }
124
+ #endif
125
+
126
+ return filnam;
127
+ }
128
+
129
+ void zipruby_rmtmp(const char *tmpfilnam) {
130
+ struct stat st;
131
+
132
+ if (!tmpfilnam) {
133
+ return;
134
+ }
135
+
136
+ if (stat(tmpfilnam, &st) != 0) {
137
+ return;
138
+ }
139
+
140
+ #ifdef _WIN32
141
+ _unlink(tmpfilnam);
142
+ #else
143
+ unlink(tmpfilnam);
144
+ #endif
145
+ }
146
+
147
+ static int write_from_proc(VALUE proc, int fd) {
148
+ while (1) {
149
+ VALUE src = rb_protect(proc_call, proc, NULL);
150
+
151
+ if (TYPE(src) != T_STRING) {
152
+ break;
153
+ }
154
+
155
+ if (RSTRING_LEN(src) < 1) {
156
+ break;
157
+ }
158
+
159
+ #ifdef _WIN32
160
+ if (_write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
161
+ return -1;
162
+ }
163
+ #else
164
+ if (write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
165
+ return -1;
166
+ }
167
+ #endif
168
+ }
169
+
170
+ return 0;
171
+ }
172
+
173
+ static VALUE proc_call(VALUE proc) {
174
+ return rb_funcall(proc, rb_intern("call"), 0);
175
+ }
data/ext/tmpfile.h CHANGED
@@ -1,9 +1,9 @@
1
- #ifndef __TMPFILE_H__
2
- #define __TMPFILE_H__
3
-
4
- #include <stdio.h>
5
-
6
- char *zipruby_tmpnam(void *data, int len);
7
- void zipruby_rmtmp(const char *tmpfilnam);
8
-
9
- #endif
1
+ #ifndef __TMPFILE_H__
2
+ #define __TMPFILE_H__
3
+
4
+ #include <stdio.h>
5
+
6
+ char *zipruby_tmpnam(void *data, int len);
7
+ void zipruby_rmtmp(const char *tmpfilnam);
8
+
9
+ #endif
data/ext/zip.h CHANGED
@@ -46,7 +46,7 @@ extern "C" {
46
46
  #include <stdio.h>
47
47
  #include <time.h>
48
48
 
49
- #ifdef _WIN32
49
+ #if defined(_WIN32) && !defined(ssize_t)
50
50
  typedef int ssize_t;
51
51
  #endif
52
52
 
@@ -41,6 +41,8 @@
41
41
  #include <string.h>
42
42
 
43
43
  #ifdef _WIN32
44
+ #define snprintf(s, n, f, ...) _snprintf((s), (n), (f), __VA_ARGS__)
45
+ #else
44
46
  #define snprintf _snprintf
45
47
  #endif
46
48
 
data/ext/zipint.h CHANGED
@@ -40,7 +40,7 @@
40
40
 
41
41
  #include "zip.h"
42
42
  #ifndef _WIN32
43
- #include "config.h"
43
+ //#include "config.h"
44
44
  #endif
45
45
 
46
46
  #ifndef HAVE_MKSTEMP
data/ext/zipruby.c CHANGED
@@ -1,18 +1,18 @@
1
- #ifdef _WIN32
2
- __declspec(dllexport) void Init_zipruby(void);
3
- #endif
4
-
5
- #include "zipruby.h"
6
- #include "zipruby_zip.h"
7
- #include "zipruby_archive.h"
8
- #include "zipruby_file.h"
9
- #include "zipruby_stat.h"
10
- #include "zipruby_error.h"
11
-
12
- void Init_zipruby() {
13
- Init_zipruby_zip();
14
- Init_zipruby_archive();
15
- Init_zipruby_file();
16
- Init_zipruby_stat();
17
- Init_zipruby_error();
18
- }
1
+ #ifdef _WIN32
2
+ __declspec(dllexport) void Init_zipruby(void);
3
+ #endif
4
+
5
+ #include "zipruby.h"
6
+ #include "zipruby_zip.h"
7
+ #include "zipruby_archive.h"
8
+ #include "zipruby_file.h"
9
+ #include "zipruby_stat.h"
10
+ #include "zipruby_error.h"
11
+
12
+ void Init_zipruby() {
13
+ Init_zipruby_zip();
14
+ Init_zipruby_archive();
15
+ Init_zipruby_file();
16
+ Init_zipruby_stat();
17
+ Init_zipruby_error();
18
+ }
data/ext/zipruby.h CHANGED
@@ -1,25 +1,28 @@
1
- #ifndef __ZIPRUBY_H__
2
- #define __ZIPRUBY_H__
3
-
4
- #include "ruby.h"
5
-
6
- #ifndef RSTRING_PTR
7
- #define RSTRING_PTR(s) (RSTRING(s)->ptr)
8
- #endif
9
- #ifndef RSTRING_LEN
10
- #define RSTRING_LEN(s) (RSTRING(s)->len)
11
- #endif
12
-
13
- #define Check_IO(x) do { \
14
- if (!rb_obj_is_instance_of((x), rb_cIO)) { \
15
- rb_raise(rb_eTypeError, "wrong argument type %s (expected IO)", rb_class2name(CLASS_OF(x))); \
16
- } \
17
- } while(0)
18
-
19
- #define VERSION "0.2.9"
20
- #define ERRSTR_BUFSIZE 256
21
- #define DATA_BUFSIZE 8192
22
-
23
- void Init_zipruby();
24
-
25
- #endif
1
+ #ifndef __ZIPRUBY_H__
2
+ #define __ZIPRUBY_H__
3
+
4
+ #include "ruby.h"
5
+
6
+ #ifndef RSTRING_PTR
7
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
8
+ #endif
9
+ #ifndef RSTRING_LEN
10
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
11
+ #endif
12
+
13
+ #define Check_IO(x) do { \
14
+ const char *classname = rb_class2name(CLASS_OF(x)); \
15
+ if (rb_obj_is_kind_of((x), rb_cIO)) { \
16
+ rb_io_binmode(x); \
17
+ } else if (strcmp(classname, "StringIO") != 0) { \
18
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected IO or StringIO)", classname); \
19
+ } \
20
+ } while(0)
21
+
22
+ #define VERSION "0.3.0"
23
+ #define ERRSTR_BUFSIZE 256
24
+ #define DATA_BUFSIZE 8192
25
+
26
+ void Init_zipruby();
27
+
28
+ #endif