content_type 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/ext/content_type.c +17 -8
  3. data/ext/extconf.rb +3 -0
  4. metadata +2 -2
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Spec::Rake::SpecTask.new(:spec) do |t|
19
19
  end
20
20
 
21
21
  task :clean do
22
- `rm -r *.o *.so *.bundle conftest.dSYM 2>/dev/null`
22
+ `rm -r ext/*.o ext/*.so ext/*.bundle ext/conftest.dSYM 2>/dev/null`
23
23
  end
24
24
 
25
25
  require 'jeweler'
@@ -93,20 +93,21 @@ content_type_file_ext(VALUE self, char *ext)
93
93
  filepath = RSTRING_PTR(rb_iv_get(self, "@filepath"));
94
94
 
95
95
  j = 0;
96
- for (i = RSTRING_LEN(rb_iv_get(self, "@filepath")) - 1; i > 0 && j < MAX_EXT_LEN; i--) {
96
+ for (i = RSTRING_LEN(rb_iv_get(self, "@filepath")) - 1;
97
+ i > 0 && j < MAX_EXT_LEN; i--) {
97
98
  if (filepath[i] == '.') {
98
99
  for (k = 0; k < j/2 ; k++) {
99
100
  t = ext[j - 1 - k];
100
101
  ext[j - 1 - k] = ext[k];
101
102
  ext[k] = t;
102
103
  }
103
- return ext;
104
+ return true;
104
105
  }
105
106
  ext[j] = filepath[i];
106
107
  j++;
107
108
  }
108
109
 
109
- return NULL;
110
+ return false;
110
111
  }
111
112
 
112
113
  VALUE
@@ -115,16 +116,24 @@ content_type_content_type(VALUE self)
115
116
  VALUE ct;
116
117
  struct magic_set *mh;
117
118
  const char *mime;
119
+ char *o_ext, *o_mime;
118
120
  char ext[MAX_EXT_LEN]; // TODO dynamicly sized
119
121
  int i;
120
122
 
121
123
  if (content_type_file_ext(self, ext))
122
- for (i = sizeof(content_type_ext_overrides) / sizeof(char *) / 2 - 1; i >= 0; i--)
123
- if ((memcmp(ext, content_type_ext_overrides[i][0], strlen(content_type_ext_overrides[i][0]))) == 0) {
124
- rb_iv_set(self, "@content_type", rb_str_new2(content_type_ext_overrides[i][1]));
124
+ for (i = sizeof(content_type_ext_overrides) / sizeof(char *) / 2 - 1;
125
+ i >= 0; i--) {
126
+
127
+ o_ext = (char *)content_type_ext_overrides[i][0];
128
+ o_mime = (char *)content_type_ext_overrides[i][1];
129
+
130
+ if ((memcmp(ext, o_ext, strlen(o_ext))) == 0) {
131
+ ct = rb_str_new2(o_mime);
132
+ rb_iv_set(self, "@content_type", ct);
125
133
  rb_iv_set(self, "@processed", Qtrue);
126
- return rb_iv_get(self, "@content_type");
134
+ return ct;
127
135
  }
136
+ }
128
137
 
129
138
  if (rb_iv_get(self, "@processed"))
130
139
  return rb_iv_get(self, "@content_type");
@@ -149,7 +158,7 @@ content_type_content_type(VALUE self)
149
158
  VALUE
150
159
  file_content_type_wrap(VALUE self, VALUE path)
151
160
  {
152
- VALUE ct, mime, args[1];
161
+ VALUE ct, args[1];
153
162
 
154
163
  SafeStringValue(path);
155
164
  args[0] = path;
@@ -1,8 +1,11 @@
1
1
  require 'mkmf'
2
+
2
3
  extension_name = 'content_type'
3
4
  dir_config(extension_name)
4
5
 
5
6
  find_header('magic.h', '/opt/local/include')
6
7
  find_library('magic', 'magic_open', '/opt/local/lib')
7
8
 
9
+ $CFLAGS += '-Werror -Wall'
10
+
8
11
  create_makefile(extension_name)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 1
8
- - 0
9
- version: 2.1.0
8
+ - 1
9
+ version: 2.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Turnbull