summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-01-23 01:17:14 +0000
committerLennart Poettering <lennart@poettering.net>2006-01-23 01:17:14 +0000
commit5a4d9e05f6cddc0b44915079d31724d6b60ed7f5 (patch)
treed450254f1b82a9d95dc1d32eb97030fa8294c060
parenta7ce05c295d17d46bf6b84426b2c21472588470d (diff)
port to apache 2.0
git-svn-id: file:///home/lennart/svn/public/mod_mime_xattr/trunk@12 f01872de-66d6-0310-9185-fc3b30f50adc
-rw-r--r--Makefile.am8
-rw-r--r--NOTICE1
-rwxr-xr-xbootstrap.sh39
-rw-r--r--configure.ac63
-rw-r--r--doc/Makefile.am2
-rw-r--r--doc/README.html.in52
-rw-r--r--doc/style.css19
-rw-r--r--src/Makefile.in43
-rw-r--r--src/mod_mime_xattr.c198
9 files changed, 257 insertions, 168 deletions
diff --git a/Makefile.am b/Makefile.am
index d45b20d..609829e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
# $Id$
-# Copyright 2004 Lennart Poettering
+# Copyright 2004-2006 Lennart Poettering
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
@@ -14,11 +14,11 @@
# implied. See the License for the specific language governing
# permissions and limitations under the License.
-EXTRA_DIST=bootstrap.sh README LICENSE NOTICE
+EXTRA_DIST=bootstrap.sh README LICENSE src/mod_mime_xattr.c src/Makefile.in
SUBDIRS=src doc
MAINTAINERCLEANFILES = README
-noinst_DATA = README NOTICE LICENSE
+noinst_DATA = README LICENSE
README:
rm -f README
@@ -30,7 +30,7 @@ homepage: all dist
mkdir -p $$HOME/homepage/private/projects/mod_mime_xattr
cp *.tar.gz $$HOME/homepage/private/projects/mod_mime_xattr
cp doc/README.html doc/style.css $$HOME/homepage/private/projects/mod_mime_xattr
- cp $$HOME/homepage/private/projects/mod_mime_xattr/README.html $$HOME/homepage/private/projects/mod_mime_xattr/index.html
+ ln -sf $$HOME/homepage/private/projects/mod_mime_xattr/README.html $$HOME/homepage/private/projects/mod_mime_xattr/index.html
distcleancheck:
@:
diff --git a/NOTICE b/NOTICE
deleted file mode 100644
index 8587606..0000000
--- a/NOTICE
+++ /dev/null
@@ -1 +0,0 @@
-This software has been developed by Lennart Poettering
diff --git a/bootstrap.sh b/bootstrap.sh
index f843d46..19315af 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# $Id$
-# Copyright 2004 Lennart Poettering
+# Copyright 2004-2006 Lennart Poettering
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
@@ -15,29 +15,44 @@
# implied. See the License for the specific language governing
# permissions and limitations under the License.
+VERSION=1.9
+
run_versioned() {
local P
- type -p "$1-$2" &> /dev/null && P="$1-$2" || local P="$1"
+ local V
+
+ V=$(echo "$2" | sed -e 's,\.,,g')
+
+ if [ -e "`which $1$V`" ] ; then
+ P="$1$V"
+ else
+ if [ -e "`which $1-$2`" ] ; then
+ P="$1-$2"
+ else
+ P="$1"
+ fi
+ fi
shift 2
"$P" "$@"
}
+set -ex
+
if [ "x$1" = "xam" ] ; then
- set -ex
- run_versioned automake 1.7 -a -c
+ run_versioned automake "$VERSION" -a -c --foreign
./config.status
else
- set -ex
rm -rf autom4te.cache
rm -f config.cache
- run_versioned aclocal 1.7
- autoheader
- run_versioned automake 1.7 -a -c
- autoconf -Wall
-
- ./configure --sysconfdir=/etc "$@"
+ run_versioned aclocal "$VERSION"
+ run_versioned autoconf 2.59 -Wall
+ run_versioned autoheader 2.59
+ run_versioned automake "$VERSION" -a -c --foreign
- make clean
+ if test "x$NOCONFIGURE" = "x"; then
+ CFLAGS="-g -O0" ./configure --sysconfdir=/etc "$@"
+ make clean
+ fi
fi
diff --git a/configure.ac b/configure.ac
index dd204f4..df981ca 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@
# $Id$
-# Copyright 2004 Lennart Poettering
+# Copyright 2004-2006 Lennart Poettering
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
@@ -17,11 +17,11 @@
# implied. See the License for the specific language governing
# permissions and limitations under the License.
-AC_PREREQ(2.59)
-AC_INIT([mod_mime_xattr],[0.2],[mzzvzrkngge (at) 0pointer (dot) de])
+AC_PREREQ(2.57)
+AC_INIT([mod_mime_xattr],[0.3],[mzzvzrkngge (at) 0pointer (dot) net])
AC_CONFIG_SRCDIR([src/mod_mime_xattr.c])
AC_CONFIG_HEADERS([config.h])
-AM_INIT_AUTOMAKE([foreign -Wall])
+AM_INIT_AUTOMAKE([foreign 1.9 -Wall])
AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/mod_mime_xattr/])
@@ -31,15 +31,66 @@ AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_MAKE_SET
+test_gcc_flag() {
+ AC_LANG_CONFTEST([int main() {}])
+ $CC -c conftest.c $CFLAGS $@ > /dev/null 2> /dev/null
+ ret=$?
+ rm -f conftest.o
+ return $ret
+}
+
+# If using GCC specify some additional parameters
+if test "x$GCC" = "xyes" ; then
+
+ DESIRED_FLAGS="-Wall -W -Wextra -pedantic -pipe -Wformat -Wold-style-definition -Wdeclaration-after-statement -Wfloat-equal -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-noreturn -Wshadow -Wendif-labels -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Winline"
+
+ if test "x$HAVE_NETLINK" = "xyes" ; then
+ # Test whether rtnetlink.h can be included when compiled with -std=c99
+ # some distributions (e.g. archlinux) have broken headers that dont
+ # define __u64 with -std=c99
+ AC_MSG_CHECKING([checking whether rtnetlink.h can be included with -std=c99])
+ OLDCFLAGS="$CFLAGS"
+ CFLAGS="-std=c99"
+ AC_TRY_COMPILE([#include <linux/rtnetlink.h>], [],
+ use_stdc99=yes, use_stdc99=no)
+
+ if test x"$use_stdc99" = xyes; then
+ DESIRED_FLAGS="-std=c99 $DESIRED_FLAGS"
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+
+ CFLAGS="$OLDCFLAGS"
+ else
+ DESIRED_FLAGS="-std=c99 $DESIRED_FLAGS"
+ fi
+
+ for flag in $DESIRED_FLAGS ; do
+ AC_MSG_CHECKING([whether $CC accepts $flag])
+ if test_gcc_flag $flag ; then
+ CFLAGS="$CFLAGS $flag"
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ done
+fi
+
AC_ARG_WITH(apxs,
AS_HELP_STRING(--with-apxs=PATH,/path/to/apxs),
- [ AC_PATH_PROG(APXS, apxs, "notfound", "$withval:$PATH") ],
- [ AC_PATH_PROG(APXS, apxs, "notfound", "/usr/local/apache/bin:/usr/local/bin:/usr/sbin:$PATH")])
+ [ AC_PATH_PROGS(APXS, [apxs2 apxs], "notfound", "$withval:$PATH") ],
+ [ AC_PATH_PROGS(APXS, [apxs2 apxs], "notfound", "/usr/local/apache/bin:/usr/local/bin:/usr/sbin:$PATH")])
if test "x$APXS" = "xnotfound" ; then
AC_MSG_ERROR([*** Sorry, could not find apxs ***])
fi
+AC_ARG_WITH(apachectl,
+ AS_HELP_STRING(--with-apachectl=PATH,/path/to/apachectl),
+ [ AC_PATH_PROGS(APACHECTL, [apache2ctl apachectl], "notfound", "$withval:$PATH") ],
+ [ AC_PATH_PROGS(APACHECTL, [apache2ctl apachectl], "notfound", "/usr/local/apache/bin:/usr/local/bin:/usr/sbin:$PATH")])
+
# Check for libattr
AC_CHECK_LIB([attr], [getxattr],, [AC_MSG_ERROR([*** Sorry, you have to install libattr ***])])
AC_CHECK_HEADER([attr/xattr.h],, [AC_MSG_ERROR([*** Sorry, you have to install the libattr headers ***])])
diff --git a/doc/Makefile.am b/doc/Makefile.am
index f21e42c..50afd4f 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,6 +1,6 @@
# $Id$
-# Copyright 2004 Lennart Poettering
+# Copyright 2004-2006 Lennart Poettering
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
diff --git a/doc/README.html.in b/doc/README.html.in
index 575ffd9..4d69132 100644
--- a/doc/README.html.in
+++ b/doc/README.html.in
@@ -10,7 +10,7 @@
<body>
<h1><a name="top">mod_mime_xattr @PACKAGE_VERSION@</a></h1>
-<p><i>Copyright 2004 Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;</i></p>
+<p><i>Copyright 2004-2006 Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;</i></p>
<ul class="toc">
<li><a href="#license">License</a></li>
@@ -42,6 +42,10 @@ permissions and limitations under the License.</p>
<h2><a name="news">News</a></h2>
+<div class="news-date">Mon Jan 23 2004: </div> <p class="news-text"><a
+href="@PACKAGE_URL@mod_mime_xattr-0.3.tar.gz">Version
+0.3</a> released; changes include: ported to Apache 2.0 - For Apache 1 use versions <= 0.2</p>
+
<div class="news-date">Sun Mar 28 2004: </div> <p class="news-text"><a
href="@PACKAGE_URL@mod_mime_xattr-0.2.tar.gz">Version
0.2</a> released; changes include: look for both <tt>user.mime_type</tt> and <tt>user.mime-type</tt> for compliance with XDG</p>
@@ -53,7 +57,7 @@ href="@PACKAGE_URL@mod_mime_xattr-0.1.tar.gz">Version
<h2><a name="overview">Overview</a></h2>
<p><tt>mod_mime_xattr</tt> is a module for the <a
-href="http://httpd.apache.org/">Apache HTTPD</a> 1.3 which may be used to
+href="http://httpd.apache.org/">Apache HTTPD</a> 2.0 which may be used to
set a range of MIME properties of files served from a document tree with
extended attributes (EAs) as supported by the underlying file
system. The current version of <tt>mod_mime_xattr</tt> has support for
@@ -83,38 +87,38 @@ MIME database specification</a> as published by <a href="http://www.freedesktop.
<p>Enable the module by adding a new <tt>LoadModule</tt> to the Apache configuration files:</p>
<pre>
-LoadModule config_log_module /usr/lib/apache/1.3/mod_log_config.so
-LoadModule mime_module /usr/lib/apache/1.3/mod_mime.so
-<b>LoadModule mime_xattr_module /usr/lib/apache/1.3/mod_mime_xattr.so</b>
-LoadModule negotiation_module /usr/lib/apache/1.3/mod_negotiation.so
+...
+LoadModule mime_xattr_module /usr/lib/apache2/modules/mod_mime_xattr.so
+...
</pre>
-<p>If you add the new line before <tt>mod_mime</tt>, the latter will
-overwrite the MIME type settings <tt>mod_mime_xattr</tt>
-detected. Thus the extension of a file is more important than the EA <tt>user.mime_type</tt>. If specified in the opposite
-order (which is recommended), the values set in the EAs take
-precedence.</p>
-
<p>When enabled in the Apache configuration files,
<tt>mod_mime_xattr</tt> introduces two new directory dependent
configuration directives:</p>
<ul>
- <li><tt>XAttrMimeType [On/Off]</tt>; Enable or disable the use of the <tt>user.mime_type</tt>, <tt>user.charset</tt> and <tt>user.mime_encoding</tt> EAs.</li>
- <li><tt>XAttrHandler [On/Off]</tt>; Enable or disable the use of the <tt>user.apache_handler</tt> EA</li>
+ <li><tt>XAttrMimeType [On/Off]</tt>; Enable or disable the interpretation of the <tt>user.mime_type</tt>, <tt>user.charset</tt> and <tt>user.mime_encoding</tt> EAs.</li>
+ <li><tt>XAttrHandler [On/Off]</tt>; Enable or disable the interpretation of the <tt>user.apache_handler</tt> EA</li>
</ul>
-<p>A simple usage example:</p>
+<p>A simple example:</p>
<pre>...
&lt;Directory /var/www&gt;
XAttrMimeType On
XAttrHandler On
&lt;/Directory&gt;
-...
-</pre>
+...</pre>
-<h2>Usage</h2>
+<p>In case you want to enable support for extended attributes for the entire server, use something like this:</p>
+
+<pre>...
+&lt;Directory /&gt;
+ XAttrMimeType On
+&lt;/Directory&gt;
+...</pre>
+
+<h3>Usage</h3>
<p>You may get/set an extended attribute for a file with the Linux command line utilities <tt>getfattr</tt>/<tt>setfattr</tt>:</p>
@@ -127,7 +131,7 @@ check if an EA is set for the symlink itself, and second for the file
the link points to. The <tt>user.charset</tt> EA is only used when the
<tt>user.mime_type</tt> EA is set as well.</p>
-<h2>CGI and PHP scripts</h2>
+<h3>CGI and PHP scripts</h3>
<p>You may use the <tt>user.apache_handler</tt> EA to mark a file as CGI script:</p>
@@ -149,7 +153,7 @@ executable CGI or PHP scripts with the technique described above.</p>
<h2><a name="requirements">Requirements</a></h2>
-<p>A current release of Apache 1.3 with <tt>apxs</tt>, the development
+<p>A current release of Apache 2.0 (2.2 probably works, too) with <tt>apxs</tt>, the development
headers and libraries installed. You need to install <tt>libattr</tt>
and its development package.</p>
@@ -157,7 +161,7 @@ and its development package.</p>
easy to do, however. Feel free to send me patches!</p>
<p><tt>mod_mime_xattr</tt> was developed and tested on Debian GNU/Linux
-"testing" from March 2004, it should work on most other Linux
+"testing" from January 2006, it should work on most other Linux
distributions since it uses GNU autoconf source code configuration.</p>
<h2><a name="installation">Installation</a></h2>
@@ -178,12 +182,14 @@ compilation and <tt>make install</tt> (as root) for installation of
<p>The current release is <a href="@PACKAGE_URL@mod_mime_xattr-@PACKAGE_VERSION@.tar.gz">@PACKAGE_VERSION@</a></p>
-<p>Get <tt>mod_mime_xattr</tt>'s development sources from the <a href="http://subversion.tigris.org/">Subversion</a> <a href="https://seth.intheinter.net:8081/svn/mod_mime_xattr/">repository</a>.</p>
+<p>Get <tt>mod_mime_xattr</tt>'s development sources from the <a href="http://subversion.tigris.org/">Subversion</a> <a href="svn://svn.0pointer.net/mod_mime_xattr">repository</a> (<a href="http://0pointer.net/cgi-bin/viewcvs.cgi/?root=mod_mime_xattr">viewcvs</a>): </p>
+
+<pre>svn checkout svn://svn.0pointer.net/mod_mime_xattr/trunk mod_mime_xattr</pre>
<p>If you want to be notified whenever I release a new version of this software use the subscription feature of <a href="http://freshmeat.net/projects/mod_mime_xattr/">Freshmeat</a>.</p>
<hr/>
-<address class="grey">Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, March 2004</address>
+<address class="grey">Lennart Poettering &lt;@PACKAGE_BUGREPORT@&gt;, January 2006</address>
<div class="grey"><i>$Id$</i></div>
</body>
diff --git a/doc/style.css b/doc/style.css
index 3499640..7d7eb75 100644
--- a/doc/style.css
+++ b/doc/style.css
@@ -1,8 +1,7 @@
/* $Id$ */
/***
-
- Copyright 2004 Lennart Poettering
+ Copyright 2004-2006 Lennart Poettering
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You
@@ -15,18 +14,10 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
-
***/
-body { color: black; background-color: white; margin: 0.5cm; }
+body { color: black; background-color: white; }
a:link, a:visited { color: #900000; }
-p { margin-left: 0.5cm; margin-right: 0.5cm; }
-div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; }
-p.news-text { margin-left: 1cm; }
-h1 { color: #00009F; }
-h2 { color: #00009F; }
-h3 { color: #00004F; margin-left: 0.5cm; }
-ul { margin-left: .5cm; }
-ol { margin-left: .5cm; }
-pre { margin-left: .5cm; background-color: #f0f0f0; padding: 0.4cm;}
-.grey { color: #afafaf; }
+div.news-date { font-size: 80%; font-style: italic; }
+pre { background-color: #f0f0f0; padding: 0.4cm; }
+.grey { color: #8f8f8f; font-size: 80%; }
diff --git a/src/Makefile.in b/src/Makefile.in
index 0311c0d..92d3ec5 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,6 +1,6 @@
# $Id$
-# Copyright 2004 Lennart Poettering
+# Copyright 2004-2006 Lennart Poettering
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
@@ -14,51 +14,40 @@
# implied. See the License for the specific language governing
# permissions and limitations under the License.
-DISTFILES=Makefile.in mod_mime_xattr.c
APXS=@APXS@
-APACHECTL=apachectl
+APACHECTL=@APACHECTL@
+LIBS=-Wl,"@LIBS@"
+CFLAGS=-Wc,"@CFLAGS@"
-# additional user defines, includes and libraries
-#DEF=-Dmy_define=my_value
-#INC=-Imy/include/dir
-#LIB=-Lmy/lib/dir -lc -lmylib
-LIB=-lattr
+all: mod_mime_xattr.la
-# the default target
-all: mod_mime_xattr.so
+mod_mime_xattr.la: @srcdir@/mod_mime_xattr.c
+ $(APXS) -c $(CFLAGS) $(LIBS) @srcdir@/mod_mime_xattr.c
-# compile the DSO file
-mod_mime_xattr.so: mod_mime_xattr.c
- $(APXS) -c $(DEF) $(INC) $(LIB) mod_mime_xattr.c
-
-# install the DSO file into the Apache installation
-# and activate it in the Apache configuration
install: all
- $(APXS) -i -a -n 'mime_xattr' mod_mime_xattr.so
+ $(APXS) -i -a mod_mime_xattr.la
-# cleanup
clean:
- -rm -f mod_mime_xattr.o mod_mime_xattr.so
+ rm -rf *.o *.so *.loT .deps/ *.la *.lo *.slo .libs/
-# reload the module by installing and restarting Apache
reload: install restart
-# the general Apache start/restart/stop procedures
start:
$(APACHECTL) start
+
restart:
$(APACHECTL) restart
+
stop:
$(APACHECTL) stop
-distdir:
- mkdir -p $(distdir)
- cp -p $(DISTFILES) $(distdir)
-
mostlyclean: clean
distclean: clean
-
maintainer-clean: clean
rm -f Makefile
-.PHONY: all clean maintainer-clean mostlyclean distclean distdir install reload start stop restart
+Makefile: @srcdir@/Makefile.in
+ (cd .. && ./config.status )
+
+
+.PHONY: all install clean reload start restart stop mostlyclean distclean maintainer-clean
diff --git a/src/mod_mime_xattr.c b/src/mod_mime_xattr.c
index 3a18b1e..a08fb4d 100644
--- a/src/mod_mime_xattr.c
+++ b/src/mod_mime_xattr.c
@@ -1,8 +1,7 @@
/* $Id$ */
/***
-
- Copyright 2004 Lennart Poettering
+ Copyright 2004-2006 Lennart Poettering
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You
@@ -15,21 +14,32 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
-
***/
+#include <httpd.h>
+#include <http_config.h>
+#include <http_protocol.h>
+#include <http_core.h>
+#include <http_log.h>
+#include <http_main.h>
+#include <http_request.h>
+#include <apr_lib.h>
+#include <ap_config.h>
+#include <apr_strings.h>
+#include <unixd.h>
+#include <apr_signal.h>
+#include <mpm_common.h>
+
#include <sys/types.h>
#include <attr/xattr.h>
#include <ctype.h>
-#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
-#include "http_log.h"
-#include "http_main.h"
-#include "http_protocol.h"
-#include "http_request.h"
-#include "ap_config.h"
+#ifdef __GNUC__
+#define __unused __attribute__ ((unused))
+#else
+#define __unused
+#endif
+
#define XATTR_NAME_MIMETYPE "user.mime_type"
#define XATTR_NAME_MIMETYPE2 "user.mime-type"
@@ -39,61 +49,68 @@
#define XATTR_NAME_HANDLER "user.apache_handler"
#define XATTR_NAME_HANDLER2 "user.apache-handler"
-module MODULE_VAR_EXPORT mime_xattr_module;
+module AP_MODULE_DECLARE_DATA mime_xattr_module;
struct mime_xattr_dir_config {
int enable_mime_type;
+ int enable_mime_type_set;
int enable_handler;
+ int enable_handler_set;
};
-static void* create_mime_xattr_dir_config(pool *p, char*dummy) {
- struct mime_xattr_dir_config *c = (struct mime_xattr_dir_config*) ap_palloc(p, sizeof(struct mime_xattr_dir_config));
+static void* create_mime_xattr_dir_config(apr_pool_t *p, __unused char *dummy) {
+ struct mime_xattr_dir_config *c = apr_palloc(p, sizeof(struct mime_xattr_dir_config));
+
c->enable_mime_type = 0;
+ c->enable_mime_type_set = 0;
c->enable_handler = 0;
+ c->enable_handler_set = 0;
+
+ return c;
+}
+
+static void *merge_mime_xattr_dir_config(apr_pool_t *p, void *basev, void *overridesv) {
+ struct mime_xattr_dir_config *base = basev, *override = overridesv, *c;
+
+ c = apr_palloc(p, sizeof(struct mime_xattr_dir_config));
+
+ c->enable_mime_type = override->enable_mime_type_set ? override->enable_mime_type : base->enable_mime_type;
+ c->enable_mime_type_set = override->enable_mime_type_set || base->enable_mime_type_set;
+ c->enable_handler = override->enable_handler_set ? override->enable_handler : base->enable_handler;
+ c->enable_handler_set = override->enable_handler_set || base->enable_handler_set;
+
return c;
}
-static const char *enable_xattr_mime_type(cmd_parms *parms, void *mconfig, int flag) {
- struct mime_xattr_dir_config *c = (struct mime_xattr_dir_config*) mconfig;
+static const char *enable_xattr_mime_type(__unused cmd_parms *parms, void *mconfig, int flag) {
+ struct mime_xattr_dir_config *c = mconfig;
+
c->enable_mime_type = flag;
+ c->enable_mime_type_set = 1;
+
return NULL;
}
-static const char *enable_xattr_handler(cmd_parms *parms, void *mconfig, int flag) {
- struct mime_xattr_dir_config *c = (struct mime_xattr_dir_config*) mconfig;
+static const char *enable_xattr_handler(__unused cmd_parms *parms, void *mconfig, int flag) {
+ struct mime_xattr_dir_config *c = mconfig;
+
c->enable_handler = flag;
+ c->enable_handler_set = 1;
+
return NULL;
}
-static const command_rec mime_xattr_cmds[] = {
- {"XAttrMimeType",
- enable_xattr_mime_type,
- NULL,
- OR_FILEINFO,
- FLAG,
- "Requires 'On' or 'Off' for enabling resp. disabling usage of file system extended attribute data for MIME type detection." },
-
- {"XAttrHandler",
- enable_xattr_handler,
- NULL,
- OR_FILEINFO,
- FLAG,
- "Requires 'On' or 'Off' for enabling resp. disabling usage of file system extended attribute data for handler detection." },
-
- { NULL }
-};
-
-static char* get_xattr(pool *p, const char *fn, const char *attr) {
+static char* get_xattr(apr_pool_t *p, const char *fn, const char *attr) {
char v[256];
ssize_t l;
- if ((l = lgetxattr(fn, attr, v, sizeof(v)-1)) < 0)
- if ((l = getxattr(fn, attr, v, sizeof(v)-1)) < 0)
+ if ((l = lgetxattr(fn, attr, v, sizeof(v)-1)) <= 0)
+ if ((l = getxattr(fn, attr, v, sizeof(v)-1)) <= 0)
return NULL;
v[l] = 0;
- return ap_pstrdup(p, v);
+ return apr_pstrdup(p, v);
}
static char* validate_charset(char *f) {
@@ -101,7 +118,9 @@ static char* validate_charset(char *f) {
for (c = f; *c; c++) {
*c = tolower(*c);
- if (!(*c >= 'a' && *c <= 'z') && !(*c >= '0' && *c <= '9') && *c != '-')
+ if (!(*c >= 'a' && *c <= 'z') &&
+ !(*c >= '0' && *c <= '9') &&
+ *c != '-')
return NULL;
}
@@ -125,7 +144,9 @@ static char* validate_mime_type(char *f) {
return NULL;
}
- if (!(*c >= 'a' && *c <= 'z') && !(*c >= '0' && *c <= '9') && *c != '-')
+ if (!(*c >= 'a' && *c <= 'z') &&
+ !(*c >= '0' && *c <= '9') &&
+ *c != '-')
return NULL;
}
@@ -135,28 +156,28 @@ static char* validate_mime_type(char *f) {
static int find_ct(request_rec *r) {
int result = DECLINED;
struct mime_xattr_dir_config* c;
-
- if (r->finfo.st_mode == 0 || !r->filename || !S_ISREG(r->finfo.st_mode))
+
+ if (!(r->finfo.valid & APR_FINFO_TYPE) || !r->filename || r->finfo.filetype != APR_REG)
return DECLINED;
- c = (struct mime_xattr_dir_config*) ap_get_module_config(r->per_dir_config, &mime_xattr_module);
+ c = ap_get_module_config(r->per_dir_config, &mime_xattr_module);
if (c->enable_mime_type) {
char *mime_type, *charset, *encoding;
if ((charset = get_xattr(r->pool, r->filename, XATTR_NAME_CHARSET)))
if (!(charset = validate_charset(charset)))
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, "mod_mime_xattr: bad charset specification on file <%s>", r->filename);
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server, "Bad charset specification on file '%s'", r->filename);
if (!(mime_type = get_xattr(r->pool, r->filename, XATTR_NAME_MIMETYPE)))
mime_type = get_xattr(r->pool, r->filename, XATTR_NAME_MIMETYPE2);
if (mime_type) {
if (!(mime_type = validate_mime_type(mime_type)))
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, "mod_mime_xattr: bad mime type specification on file <%s>", r->filename);
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server, "Bad MIME type specification on file '%s'", r->filename);
else {
if (charset)
- mime_type = ap_psprintf(r->pool, "%s; charset=%s", mime_type, charset);
+ mime_type = apr_psprintf(r->pool, "%s; charset=%s", mime_type, charset);
r->content_type = mime_type;
result = OK;
@@ -164,7 +185,7 @@ static int find_ct(request_rec *r) {
}
if (charset && !mime_type && r->content_type) {
- char *a, *ct = ap_pstrdup(r->pool, r->content_type);
+ char *a, *ct = apr_pstrdup(r->pool, r->content_type);
static const char spec[] = "; charset=";
if ((a = strstr(ct, spec))) {
@@ -174,9 +195,9 @@ static int find_ct(request_rec *r) {
*a = 0;
- r->content_type = ap_psprintf(r->pool, "%s; charset=%s%s", ct, charset, e);
+ r->content_type = apr_psprintf(r->pool, "%s; charset=%s%s", ct, charset, e);
} else
- r->content_type = ap_psprintf(r->pool, "%s; charset=%s", ct, charset);
+ r->content_type = apr_psprintf(r->pool, "%s; charset=%s", ct, charset);
}
if (!(encoding = get_xattr(r->pool, r->filename, XATTR_NAME_ENCODING)))
@@ -184,9 +205,11 @@ static int find_ct(request_rec *r) {
if (encoding) {
if (!(encoding = validate_encoding(encoding)))
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, "mod_mime_xattr: bad encoding specification on file <%s>", r->filename);
- else
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Bad encoding specification on file '%s'", r->filename);
+ else {
r->content_encoding = encoding;
+ result = OK;
+ }
}
}
@@ -198,7 +221,7 @@ static int find_ct(request_rec *r) {
if (handler) {
if (!(handler = validate_handler(handler)))
- ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, "mod_mime_xattr: bad apache handler specification on file <%s>", r->filename);
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "Bad apache handler specification on file <%s>", r->filename);
else {
r->handler = handler;
result = OK;
@@ -209,31 +232,46 @@ static int find_ct(request_rec *r) {
return result;
}
-/* Dispatch list for API hooks */
-module MODULE_VAR_EXPORT mime_xattr_module = {
- STANDARD_MODULE_STUFF,
- NULL, /* module initializer */
+static void register_hooks(__unused apr_pool_t *p){
+ static const char * const pre[] = {
+ "mod_rewrite.c",
+ NULL
+ };
+
+ static const char * const post[] = {
+ "mod_mime.c",
+ "mod_mime_magic.c",
+ NULL
+ };
+
+ ap_hook_type_checker(find_ct, pre, post, APR_HOOK_MIDDLE);
+}
+
+static const command_rec commands[] = {
+
+ AP_INIT_FLAG(
+ "XAttrMimeType",
+ enable_xattr_mime_type,
+ NULL,
+ OR_FILEINFO,
+ "Takes 'On' or 'Off' for enabling resp. disabling usage of file system extended attribute data for MIME type detection."),
+
+ AP_INIT_FLAG(
+ "XAttrHandler",
+ enable_xattr_handler,
+ NULL,
+ OR_FILEINFO,
+ "Takes 'On' or 'Off' for enabling resp. disabling usage of file system extended attribute data for handler detection."),
+
+ { NULL }
+};
+
+module AP_MODULE_DECLARE_DATA mime_xattr_module = {
+ STANDARD20_MODULE_STUFF,
create_mime_xattr_dir_config, /* create per-dir config structures */
- NULL, /* merge per-dir config structures */
- NULL, /* create per-server config structures */
- NULL, /* merge per-server config structures */
- mime_xattr_cmds, /* table of config file commands */
- NULL, /* [#8] MIME-typed-dispatched handlers */
- NULL, /* [#1] URI to filename translation */
- NULL, /* [#4] validate user id from request */
- NULL, /* [#5] check if the user is ok _here_ */
- NULL, /* [#3] check access by host address */
- find_ct, /* [#6] determine MIME type */
- NULL, /* [#7] pre-run fixups */
- NULL, /* [#9] log a transaction */
- NULL, /* [#2] header parser */
- NULL, /* child_init */
- NULL, /* child_exit */
- NULL /* [#0] post read-request */
-#ifdef EAPI
- ,NULL, /* EAPI: add_module */
- NULL, /* EAPI: remove_module */
- NULL, /* EAPI: rewrite_command */
- NULL /* EAPI: new_connection */
-#endif
+ merge_mime_xattr_dir_config, /* merge per-dir config structures */
+ NULL, /* create per-server config structures */
+ NULL, /* merge per-server config structures */
+ commands, /* table of config file commands */
+ register_hooks /* register hooks */
};