]>
Commit | Line | Data |
---|---|---|
d8f935c9 | 1 | diff -ur lighttpd-1.2.7-orig/config.h.in lighttpd-1.2.7-xattr/config.h.in |
2 | --- lighttpd-1.2.7-orig/config.h.in 2004-08-29 04:03:44.000000000 -0600 | |
3 | +++ lighttpd-1.2.7-xattr/config.h.in 2004-08-29 21:02:37.604255730 -0600 | |
dbd0725c | 4 | @@ -356,3 +356,10 @@ |
5 | ||
6 | /* Define as `fork' if `vfork' does not work. */ | |
7 | #undef vfork | |
8 | + | |
9 | +/* Define to 1 if you have <attr/attributes.h> */ | |
10 | +#undef HAVE_ATTR_ATTRIBUTES_H | |
11 | + | |
12 | +/* Whether to enable xattr support */ | |
13 | +#undef HAVE_XATTR | |
14 | + | |
d8f935c9 | 15 | diff -ur lighttpd-1.2.7-orig/configure.in lighttpd-1.2.7-xattr/configure.in |
16 | --- lighttpd-1.2.7-orig/configure.in 2004-08-29 04:03:07.000000000 -0600 | |
17 | +++ lighttpd-1.2.7-xattr/configure.in 2004-08-29 21:02:37.604255730 -0600 | |
dbd0725c | 18 | @@ -164,9 +164,22 @@ |
19 | AC_DEFINE([HAVE_LIBLDAP], [1], [libldap]) | |
20 | AC_DEFINE([HAVE_LDAP_H], [1]) | |
21 | ]) | |
22 | + ]) | |
23 | ]) | |
24 | AC_SUBST(LDAP_LIB) | |
25 | ||
26 | +AC_MSG_CHECKING(for extended attributes support) | |
27 | +AC_ARG_WITH(attr, AC_HELP_STRING([--with-attr],[enable extended attribute support]), | |
28 | +[AC_MSG_RESULT(yes) | |
29 | + AC_CHECK_LIB(attr, attr_get, [ | |
30 | + AC_CHECK_HEADERS([attr/attributes.h],[ | |
31 | + ATTR_LIB=-lattr | |
32 | + AC_DEFINE([HAVE_XATTR], [1], [libattr]) | |
33 | + AC_DEFINE([HAVE_ATTR_ATTRIBUTES_H], [1]) | |
34 | + ]) | |
35 | +]) | |
36 | +AC_SUBST(ATTR_LIB) | |
37 | + | |
38 | AC_CHECK_LIB(lber, ber_printf, [ | |
39 | AC_CHECK_HEADERS([lber.h],[ | |
40 | LBER_LIB=-llber | |
d8f935c9 | 41 | diff -ur lighttpd-1.2.7-orig/doc/lighttpd.conf lighttpd-1.2.7-xattr/doc/lighttpd.conf |
42 | --- lighttpd-1.2.7-orig/doc/lighttpd.conf 2004-08-29 03:44:53.000000000 -0600 | |
43 | +++ lighttpd-1.2.7-xattr/doc/lighttpd.conf 2004-08-29 21:02:37.605255591 -0600 | |
a70011c2 | 44 | @@ -82,6 +82,9 @@ |
dbd0725c | 45 | ".wmv" => "video/x-ms-wmv" |
46 | ) | |
47 | ||
48 | +# Use the "Content-Type" extended attribute to obtain mime type if possible | |
49 | +# mimetypes.use-xattr = "enable" | |
50 | + | |
51 | #### accesslog module | |
52 | accesslog.filename = "/www/logs/access.log" | |
53 | ||
d8f935c9 | 54 | diff -ur lighttpd-1.2.7-orig/src/base.h lighttpd-1.2.7-xattr/src/base.h |
55 | --- lighttpd-1.2.7-orig/src/base.h 2004-08-29 02:51:53.000000000 -0600 | |
56 | +++ lighttpd-1.2.7-xattr/src/base.h 2004-08-29 21:23:21.977559690 -0600 | |
57 | @@ -163,6 +163,7 @@ | |
a70011c2 | 58 | size_t is_dirty; |
dbd0725c | 59 | |
a70011c2 | 60 | time_t stat_ts; |
61 | + buffer *content_type; | |
62 | } file_cache_entry; | |
63 | ||
64 | typedef struct { | |
d8f935c9 | 65 | @@ -199,6 +200,9 @@ |
a70011c2 | 66 | unsigned short max_keep_alive_idle; |
67 | unsigned short max_read_idle; | |
68 | unsigned short max_write_idle; | |
dbd0725c | 69 | +#ifdef HAVE_XATTR |
70 | + unsigned short use_xattr; | |
71 | +#endif | |
a70011c2 | 72 | |
dbd0725c | 73 | } specific_config; |
74 | ||
d8f935c9 | 75 | Only in lighttpd-1.2.7-xattr/src: base.h~ |
76 | diff -ur lighttpd-1.2.7-orig/src/config.c lighttpd-1.2.7-xattr/src/config.c | |
77 | --- lighttpd-1.2.7-orig/src/config.c 2004-08-29 02:54:27.000000000 -0600 | |
78 | +++ lighttpd-1.2.7-xattr/src/config.c 2004-08-29 21:02:37.606255451 -0600 | |
a70011c2 | 79 | @@ -163,8 +163,9 @@ |
80 | { "server.max-keep-alive-requests", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 21 */ | |
dbd0725c | 81 | { "server.name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 22 */ |
a70011c2 | 82 | { "server.max-keep-alive-idle", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 23 */ |
83 | - { "server.max-read-idle", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 23 */ | |
84 | - { "server.max-write-idle", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 23 */ | |
85 | + { "server.max-read-idle", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 24 */ | |
86 | + { "server.max-write-idle", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 25 */ | |
87 | + { "mimetype.use-xattr", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 26 */ | |
dbd0725c | 88 | |
89 | { "server.host", "use server.bind instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, | |
a70011c2 | 90 | { "server.docroot", "use server.document-root instead", T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_UNSET }, |
91 | @@ -214,6 +215,7 @@ | |
92 | s->max_keep_alive_idle = 30; | |
93 | s->max_read_idle = 60; | |
94 | s->max_write_idle = 360; | |
95 | + s->use_xattr = 0; | |
dbd0725c | 96 | |
97 | cv[17].destination = s->document_root; | |
98 | cv[18].destination = &(s->dir_listing); | |
a70011c2 | 99 | @@ -225,6 +227,7 @@ |
100 | cv[23].destination = &(s->max_keep_alive_idle); | |
101 | cv[24].destination = &(s->max_read_idle); | |
102 | cv[25].destination = &(s->max_write_idle); | |
103 | + cv[26].destination = &(s->use_xattr); | |
dbd0725c | 104 | |
105 | srv->config_storage[i] = s; | |
106 | srv->config = ((data_config *)srv->config_context->data[i])->value; | |
a70011c2 | 107 | @@ -305,6 +308,7 @@ |
108 | PATCH(max_keep_alive_idle); | |
109 | PATCH(max_read_idle); | |
110 | PATCH(max_write_idle); | |
dbd0725c | 111 | + PATCH(use_xattr); |
112 | buffer_copy_string_buffer(con->server_name, s->server_name); | |
113 | ||
114 | return 0; | |
a70011c2 | 115 | @@ -344,6 +348,8 @@ |
116 | PATCH(max_write_idle); | |
117 | } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.max-read-idle"))) { | |
118 | PATCH(max_read_idle); | |
dbd0725c | 119 | + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("mimetype.use-xattr"))) { |
120 | + PATCH(use_xattr); | |
121 | } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.name"))) { | |
122 | buffer_copy_string_buffer(con->server_name, s->server_name); | |
123 | } | |
d8f935c9 | 124 | diff -ur lighttpd-1.2.7-orig/src/file_cache.c lighttpd-1.2.7-xattr/src/file_cache.c |
125 | --- lighttpd-1.2.7-orig/src/file_cache.c 2004-06-05 13:20:22.000000000 -0600 | |
126 | +++ lighttpd-1.2.7-xattr/src/file_cache.c 2004-08-29 21:29:03.890833672 -0600 | |
a70011c2 | 127 | @@ -17,6 +17,10 @@ |
128 | #include "fdevent.h" | |
129 | #include "etag.h" | |
130 | ||
131 | +#ifdef HAVE_ATTR_ATTRIBUTES_H | |
132 | +#include <attr/attributes.h> | |
133 | +#endif | |
134 | + | |
135 | #ifndef O_LARGEFILE | |
136 | # define O_LARGEFILE 0 | |
137 | #endif | |
138 | @@ -40,6 +44,9 @@ | |
139 | fce->fde_ndx = -1; | |
140 | fce->name = buffer_init(); | |
141 | fce->etag = buffer_init(); | |
142 | +#ifdef HAVE_XATTR | |
143 | + fce->content_type = buffer_init(); | |
144 | +#endif | |
145 | ||
146 | return fce; | |
147 | } | |
148 | @@ -51,6 +58,7 @@ | |
149 | ||
150 | buffer_free(fce->etag); | |
151 | buffer_free(fce->name); | |
152 | + buffer_free(fce->content_type); | |
153 | ||
154 | if (fce->mmap_p) munmap(fce->mmap_p, fce->mmap_length); | |
155 | ||
d8f935c9 | 156 | @@ -91,6 +99,20 @@ |
a70011c2 | 157 | |
d8f935c9 | 158 | } |
159 | ||
160 | +#ifdef HAVE_XATTR | |
161 | +int fce_attr_get(buffer *buf, char *name) { | |
162 | + int attrlen; | |
163 | + int ret; | |
164 | + attrlen = 1024; | |
165 | + buffer_prepare_copy(buf, attrlen); | |
166 | + if(0 == (ret = attr_get(name, "Content-Type", buf->ptr, &attrlen, 0))) { | |
167 | + buf->used = attrlen + 1; | |
168 | + buf->ptr[attrlen] = '\0'; | |
169 | + } | |
170 | + return ret; | |
171 | +} | |
172 | +#endif | |
173 | + | |
174 | file_cache_entry * file_cache_get_entry(server *srv, connection *con, buffer *name, file_cache_entry *o_fce) { | |
175 | file_cache_entry *fce = NULL; | |
176 | file_cache *fc = srv->file_cache; | |
177 | @@ -136,6 +158,10 @@ | |
a70011c2 | 178 | return NULL; |
179 | } | |
180 | fce->stat_ts = srv->cur_ts; | |
181 | + | |
182 | +#ifdef HAVE_XATTR | |
d8f935c9 | 183 | + fce_attr_get(fce->content_type, name); |
a70011c2 | 184 | +#endif |
185 | ||
186 | etag_create(srv->file_cache_etag, &(fce->st)); | |
187 | ||
d8f935c9 | 188 | @@ -222,6 +248,10 @@ |
189 | return NULL; | |
190 | } | |
191 | ||
192 | +#ifdef HAVE_XATTR | |
193 | + fce_attr_get(fce->content_type, name->ptr); | |
194 | +#endif | |
195 | + | |
196 | etag_create(fce->etag, &(fce->st)); | |
197 | } else if (S_ISDIR(fce->st.st_mode)) { | |
198 | #ifdef USE_LINUX_SIGIO | |
199 | Only in lighttpd-1.2.7-xattr/src: file_cache.c~ | |
200 | diff -ur lighttpd-1.2.7-orig/src/Makefile.am lighttpd-1.2.7-xattr/src/Makefile.am | |
201 | --- lighttpd-1.2.7-orig/src/Makefile.am 2004-08-03 05:26:31.000000000 -0600 | |
202 | +++ lighttpd-1.2.7-xattr/src/Makefile.am 2004-08-29 21:02:37.607255312 -0600 | |
a70011c2 | 203 | @@ -152,7 +152,7 @@ |
204 | DEFS= @DEFS@ -DLIBRARY_DIR="\"$(libdir)\"" | |
205 | ||
206 | lighttpd_SOURCES = $(src) | |
207 | -lighttpd_LDADD = $(PCRE_LIB) $(DL_LIB) $(SENDFILE_LIB) | |
208 | +lighttpd_LDADD = $(PCRE_LIB) $(DL_LIB) $(SENDFILE_LIB) $(ATTR_LIB) | |
209 | lighttpd_LDFLAGS = -export-dynamic | |
210 | lighttpd_CCPFLAGS = $(MYSQL_INCLUDES) | |
211 | ||
d8f935c9 | 212 | diff -ur lighttpd-1.2.7-orig/src/response.c lighttpd-1.2.7-xattr/src/response.c |
213 | --- lighttpd-1.2.7-orig/src/response.c 2004-08-29 02:52:01.000000000 -0600 | |
214 | +++ lighttpd-1.2.7-xattr/src/response.c 2004-08-29 21:22:28.477027570 -0600 | |
dbd0725c | 215 | @@ -31,6 +31,9 @@ |
216 | ||
217 | #include "plugin.h" | |
218 | ||
219 | +#ifdef HAVE_ATTR_ATTRIBUTES_H | |
220 | +#include <attr/attributes.h> | |
221 | +#endif | |
222 | ||
223 | /* | |
224 | * This was 'borrowed' from tcpdump. | |
a70011c2 | 225 | @@ -659,27 +662,44 @@ |
226 | if (S_ISDIR(st.st_mode)) { | |
dbd0725c | 227 | buffer_append_string_rfill(b, "directory", 28); |
228 | } else { | |
dbd0725c | 229 | +#ifdef HAVE_XATTR |
230 | + char attrval[128]; | |
231 | + int attrlen; | |
232 | +#endif | |
a70011c2 | 233 | size_t k; |
dbd0725c | 234 | + unsigned short have_content_type; |
235 | + have_content_type = 0; | |
236 | + | |
237 | +#ifdef HAVE_XATTR | |
238 | + attrlen = 127; | |
239 | + if(con->conf.use_xattr && 0 == attr_get(srv->tmp_buf->ptr, "Content-Type", attrval, &attrlen, 0)) { | |
240 | + attrval[attrlen] = 0; | |
241 | + buffer_append_string_rfill(b, attrval, 28); | |
242 | + have_content_type = 1; | |
243 | + } | |
244 | +#endif | |
245 | ||
246 | - for (k = 0; k < con->conf.mimetypes->used; k++) { | |
247 | - data_string *ds = (data_string *)con->conf.mimetypes->data[k]; | |
248 | - size_t ct_len; | |
249 | - | |
250 | - if (ds->key->used == 0) continue; | |
251 | - | |
252 | - ct_len = ds->key->used - 1; | |
253 | - | |
254 | - if (s_len < ct_len) continue; | |
255 | + if(!have_content_type) { | |
256 | + for (k = 0; k < con->conf.mimetypes->used; k++) { | |
257 | + data_string *ds = (data_string *)con->conf.mimetypes->data[k]; | |
258 | + size_t ct_len; | |
259 | + | |
260 | + if (ds->key->used == 0) continue; | |
261 | + | |
262 | + ct_len = ds->key->used - 1; | |
263 | + | |
264 | + if (s_len < ct_len) continue; | |
265 | + | |
266 | + if (0 == strncmp(sb->ptr[i] + s_len - ct_len, ds->key->ptr, ct_len)) { | |
267 | + buffer_append_string_rfill(b, ds->value->ptr, 28); | |
268 | + break; | |
269 | + } | |
270 | + } | |
271 | ||
272 | - if (0 == strncmp(sb->ptr[i] + s_len - ct_len, ds->key->ptr, ct_len)) { | |
273 | - buffer_append_string_rfill(b, ds->value->ptr, 28); | |
274 | - break; | |
275 | + if (k == con->conf.mimetypes->used) { | |
a70011c2 | 276 | + buffer_append_string_rfill(b, "application/octet-stream", 28); |
dbd0725c | 277 | } |
278 | } | |
279 | - | |
280 | - if (k == con->conf.mimetypes->used) { | |
281 | - buffer_append_string_rfill(b, "application/octet-type", 28); | |
282 | - } | |
283 | } | |
284 | ||
285 | /* URL */ | |
a70011c2 | 286 | @@ -1117,24 +1137,41 @@ |
dbd0725c | 287 | |
288 | /* set response content-type */ | |
289 | s_len = con->physical.path->used - 1; | |
290 | + | |
291 | +#ifdef HAVE_XATTR | |
a70011c2 | 292 | + if(con->conf.use_xattr && (NULL != (con->fce = file_cache_get_entry(srv, con, con->physical.path, con->fce))) && con->fce->content_type->used) { |
293 | + response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), con->fce->content_type->ptr, con->fce->content_type->used); | |
294 | + } else { | |
dbd0725c | 295 | +#endif |
296 | ||
297 | - for (k = 0; k < con->conf.mimetypes->used; k++) { | |
298 | - data_string *ds = (data_string *)con->conf.mimetypes->data[k]; | |
299 | - | |
300 | - if (buffer_is_equal_right_len(con->physical.path, ds->key, ds->key->used - 1)) { | |
301 | - if (con->http_status == 200) { | |
302 | - response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(ds->value)); | |
303 | - } | |
dbd0725c | 304 | + for (k = 0; k < con->conf.mimetypes->used; k++) { |
305 | + data_string *ds = (data_string *)con->conf.mimetypes->data[k]; | |
306 | + size_t ct_len; | |
307 | ||
308 | - break; | |
309 | + if (ds->key->used == 0) continue; | |
310 | + | |
311 | + ct_len = ds->key->used - 1; | |
312 | + | |
313 | + if (s_len < ct_len) continue; | |
314 | + | |
315 | + if (0 == strncmp(con->physical.path->ptr + s_len - ct_len, ds->key->ptr, ct_len)) { | |
316 | + if (con->http_status == 200) { | |
317 | + response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(ds->value)); | |
318 | + } | |
319 | + | |
320 | + break; | |
321 | + } | |
322 | } | |
323 | - } | |
324 | ||
325 | - if (k == con->conf.mimetypes->used) { | |
326 | - /* not found, set a default */ | |
327 | - | |
328 | - response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/octet-stream")); | |
329 | + if (k == con->conf.mimetypes->used) { | |
330 | + /* not found, set a default */ | |
331 | + | |
332 | + response_header_insert(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/octet-stream")); | |
333 | + } | |
a70011c2 | 334 | +#ifdef HAVE_XATTR |
dbd0725c | 335 | } |
a70011c2 | 336 | +#endif |
dbd0725c | 337 | + |
338 | ||
339 | /* generate e-tag */ | |
340 | etag_mutate(con->physical.etag, con->fce->etag); |