content_type 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/ext/content_type.c +17 -8
- data/ext/extconf.rb +3 -0
- metadata +2 -2
data/Rakefile
CHANGED
data/ext/content_type.c
CHANGED
|
@@ -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;
|
|
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
|
|
104
|
+
return true;
|
|
104
105
|
}
|
|
105
106
|
ext[j] = filepath[i];
|
|
106
107
|
j++;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
return
|
|
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;
|
|
123
|
-
|
|
124
|
-
|
|
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
|
|
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,
|
|
161
|
+
VALUE ct, args[1];
|
|
153
162
|
|
|
154
163
|
SafeStringValue(path);
|
|
155
164
|
args[0] = path;
|
data/ext/extconf.rb
CHANGED