From c174f20109543c0a0bc999369784a8ee52f7141c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 24 Mar 2004 21:15:21 +0000 Subject: initial commit git-svn-id: file:///home/lennart/svn/public/mod_mime_xattr/trunk@3 f01872de-66d6-0310-9185-fc3b30f50adc --- LICENSE | 202 ++++++++++++++++++++++++++++++++++++ Makefile.am | 38 +++++++ NOTICE | 1 + bootstrap.sh | 43 ++++++++ configure.ac | 67 ++++++++++++ doc/Makefile.am | 34 +++++++ doc/README.html.in | 283 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.in | 64 ++++++++++++ src/mod_mime_xattr.c | 227 +++++++++++++++++++++++++++++++++++++++++ 9 files changed, 959 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile.am create mode 100644 NOTICE create mode 100755 bootstrap.sh create mode 100644 configure.ac create mode 100644 doc/Makefile.am create mode 100644 doc/README.html.in create mode 100644 src/Makefile.in create mode 100644 src/mod_mime_xattr.c diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + 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. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..d45b20d --- /dev/null +++ b/Makefile.am @@ -0,0 +1,38 @@ +# $Id$ + +# Copyright 2004 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 +# may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +EXTRA_DIST=bootstrap.sh README LICENSE NOTICE +SUBDIRS=src doc + +MAINTAINERCLEANFILES = README +noinst_DATA = README NOTICE LICENSE + +README: + rm -f README + $(MAKE) -C doc README + cd $(srcdir) && ln -s doc/README README + +homepage: all dist + test -d $$HOME/homepage/private + 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 + +distcleancheck: + @: + +.PHONY: homepage distcleancheck diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..9dffac5 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +This software was developed by Lennart Poettering, 2004 diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..f843d46 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# $Id$ + +# Copyright 2004 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 +# may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +run_versioned() { + local P + type -p "$1-$2" &> /dev/null && P="$1-$2" || local P="$1" + + shift 2 + "$P" "$@" +} + +if [ "x$1" = "xam" ] ; then + set -ex + run_versioned automake 1.7 -a -c + ./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 "$@" + + make clean +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..e770276 --- /dev/null +++ b/configure.ac @@ -0,0 +1,67 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +# $Id$ + +# Copyright 2004 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 +# may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +AC_PREREQ(2.59) +AC_INIT([mod_mime_xattr],[0.1],[mzzvzrkngge (at) 0pointer (dot) de]) +AC_CONFIG_SRCDIR([src/mod_mime_xattr.c]) +AC_CONFIG_HEADERS([config.h]) +AM_INIT_AUTOMAKE([foreign -Wall]) + +AC_SUBST(PACKAGE_URL, [http://0pointer.de/lennart/projects/mod_mime_xattr/]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_MAKE_SET + +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")]) + +if test "x$APXS" = "xnotfound" ; then + AC_MSG_ERROR([*** Sorry, could not find apxs ***]) +fi + +# 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 ***])]) + +# LYNX documentation generation +AC_ARG_ENABLE(lynx, + AS_HELP_STRING(--disable-lynx,Turn off lynx usage for documentation generation), +[case "${enableval}" in + yes) lynx=yes ;; + no) lynx=no ;; + *) AC_MSG_ERROR(bad value ${enableval} for --disable-lynx) ;; +esac],[lynx=yes]) + +if test x$lynx = xyes ; then + AC_CHECK_PROG(have_lynx, lynx, yes, no) + + if test x$have_lynx = xno ; then + AC_MSG_ERROR([*** Sorry, you have to install lynx or use --disable-lynx ***]) + fi +fi + +AM_CONDITIONAL([USE_LYNX], [test "x$lynx" = xyes]) + +AC_CONFIG_FILES([src/Makefile Makefile doc/Makefile doc/README.html]) +AC_OUTPUT diff --git a/doc/Makefile.am b/doc/Makefile.am new file mode 100644 index 0000000..f21e42c --- /dev/null +++ b/doc/Makefile.am @@ -0,0 +1,34 @@ +# $Id$ + +# Copyright 2004 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 +# may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +noinst_DATA = README.html README +EXTRA_DIST = $(noinst_DATA) style.css README.html.in + +MAINTAINERCLEANFILES = README README.html +CLEANFILES = + +if USE_LYNX +README: README.html + lynx --dump $^ | sed 's,file://localhost/.*/doc/README.html,README,' > $@ + +CLEANFILES += README +endif + +tidy: README.html + tidy -e < README.html + +.PHONY: tidy + diff --git a/doc/README.html.in b/doc/README.html.in new file mode 100644 index 0000000..7e97387 --- /dev/null +++ b/doc/README.html.in @@ -0,0 +1,283 @@ + + + + + +ifplugd @PACKAGE_VERSION@ + + + + +

ifplugd @PACKAGE_VERSION@

+ +

Copyright 2002-2004 Lennart Poettering <@PACKAGE_BUGREPORT@>

+ + + +

License

+ +

Copyright 2004 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 may +obtain a copy of the License at

+ +

    http://www.apache.org/licenses/LICENSE-2.0

+ +

Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +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.

+ +

News

+ +
Mon July 7 2003:

Version +0.14 released, changes include: autoconf usage, new dependency libdaemon, wireless LAN support, support for +suspending/resuming, many fixes

+ +

Overview

+ +

ifplugd is a Linux daemon which will automatically +configure your ethernet device when a cable is plugged in and +automatically unconfigure it if the cable is pulled. This is useful on +laptops with onboard network adapters, since it will only configure +the interface when a cable is really connected.

+ +

ifplugd ifplugd interfaces with your distribution's native network + configuration utilities.

+ +

Some features:

+ + + +

Status

+ +

Version @PACKAGE_VERSION@ is stable and has all the sensible features its users could think of.

+ +

Documentation

+ +

Have a look on the man pages ifplugd(8), ifplugstatus(8), ifplugd.conf(5). (An XSLT capable browser is required)

+ +

Configuration

+ +

Edit /etc/ifplugd/ifplugd.conf for configuration +changes. This file is a bourne shell script sourced by the init script +and used to start ifplugd with appropriate arguments. You may specify more than +one ethernet interface in INTERFACES. For each interface a +seperate instance of ifplugd is spawned. The arguments specified in +ARGS are append to ifplugd's command line. Have a look on +ifplugd -h or man ifplugd for further information +about the available options.

+ +

The network interface which is controlled by ifplugd +should not be configured automatically by your distribution's network +subsystem, since ifplugd will do this for you if needed.

+ +

On Debian systems, any interfaces named in ifplugd's +INTERFACES environment variable should not also be listed in +an "auto" stanza in /etc/network/interfaces.

+ +

Troubleshooting

+ +

When you are using the hotplug subsystem (Debian package +hotplug) you may notice that the network device is configured +even when it is not listed on an auto line in +/etc/network/interface. This may be due to hotplug +being configured to ifup the network interface when it +becomes available. This was the default behavior in the Debian +hotplug package prior to release 0.0.20030117-1, for +example. To prevent this you should either upgrade your +hotplug package or comment out the ifup call in +/etc/hotplug/net.agent.

+ +

When using ifplugd together with APM (and probably ACPI) +suspends, strange things may happen: some network devices fail to +detect the network cable for a short period of time before and after +the suspend. When using the -f switch, this will be treated +as "no link beat", thus the network is shutdown after a +timeout. During this timeout the machine changes to suspended +state. When it is resumed again, the timeout period will have expired +and so the network is deconfigured, however, as the next cable +detection succeeds, the network is configured again immediately. To +fix this problem, ifplugd should be disabled before the APM +suspend and enabled back after the suspend. This may be done by using +apmd and adding a script to +/etc/apm/{suspend,resume}.d which simply calls +/etc/init.d/ifplugd suspend, resp. /etc/init.d/ifplugd +resume. It might even be a good idea to shut down the network +completely during suspend, this may be achieved by calling +/etc/init.d/ifplugd stop and /etc/init.d/ifplugd +start in the appropriate places. I strongly urge the packagers of +this software for the Linux distributions to add such scripts to their +packages.

+ +

FAQ

+ +
    +
  1. Q: I want to use ifplugd with my PCMCIA device, but ifplugd quits + when it doesn't find eth0, when I have not inserted the + card. What can I do?

    + +

    A: Use the -f switch. This is not very clean however, + since modprobe is called on each cable detection query of ifplugd to + load a module for the network device. This is suboptimal. You should + probably run ifplugd only when the card is really inserted.

    +
  2. + +
  3. Q: I am using the -f switch, but the kernel logs are getting filled + with messages like "modprobe: modprobe: Can't locate module + eth0". What can I do?

    + +

    A: Make sure you have a line like alias eth0 off in your /etc/modules.conf

    +
  4. + +
  5. Q: When the cable is unplugged and the interface shut down it is + still available with ifconfig and markes as UP. Why this?

    + +

    A: ifplugd cannot detect the link beat with a shut down interface on + certain (most as of kernel 2.4.19) network drivers. Thus ifplugd + enables the interface before querying the link status. This may + be switched off with -a flag. You might want to use it if you + have a sane network driver (e.g. eepro100). The subdirectory + patches/ in the ifplugd distribution includes a patch for the + 8139too 0.9.26 driver, which makes the driver compatible with + -a. Don't ask me how to apply this patch. If you don't know, you + won't need it.

  6. + +
  7. Q: Does it work with anything else than plain ethernet or wireless LAN?

    + +

    A: Certainly not, since the MII and +ETHTOOL ioctl()s and the wireless extension don't +exist on + other network device types.

  8. + +
  9. Q: I have a Realtek 8139 based network card. Everytime ifplugd + starts on bootup my machine freezes. What can I do?

    + +

    A: This is a bug in the 8139too driver 0.9.25 (at least) shipped + with Linux 2.4.19, please upgrade to 8139too 0.9.26 (Linux 2.4.20 + or seperately at http://www.sourceforge.net/projects/gkernel/).

  10. + + +
  11. Q: There are already laptop-net's ifd and miid, why did you write + your own daemon?

    + +

    A: laptop-net was too integrated with its profile +system and didn't work on my hardware when I had a look on it. It +seemed easier to me to write a simple but feature complete replacement +than using laptop-net without most of the special features disabled. I +didn't know about miid when I wrote + ifplugd, but in any case ifplugd is much better +than miid. For a + comparison of miid and ifplugd, have a look on + + http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=162763&repeatmerged=yes

  12. +
+ + +

Requirements

+ +

A newer Linux Kernel (I think 2.2 is good enough, alltough I tested it +only with 2.4) with a compatible device driver and +ethernet card. Most modern cards and drivers are compatible, like mine +which works with the 8139too driver.

+ +

ifplugd was developed and tested on Debian GNU/Linux +"testing" from July 2003, it should work on most other Linux +distributions (and maybe Unix versions) since it uses GNU autoconf and +GNU libtool for source code configuration and shared library +management.

+ +

The machine used was a Medion 9580-F laptop with a Realtek 8139 +network card and a PRISM1 PCMCIA wireless LAN card.

+ +

ifplugd needs libdaemon.

+ +

Installation

+ +

As this package is made with the GNU autotools you should run +./configure inside the distribution directory for configuring +the source tree. After that you should run make for +compilation and make install (as root) for installation of +ifplugd.

+ +

The installation scripts create an init script in +${sysconfdir}/init.d/ifplugd, however no /etc/rc?.d/ links are created +for it.

+ +

Extensive installation instructions for ifplugd are available at Geoff Ericksson's web site.

+ +

Acknowledgements

+ +

For the developers of mii-diag, ethtool and laptop-net, since I looked +on their source codes for learning how to use the link beat ioctls.

+ +

Oliver Kurth for packaging ifplugd for Debian and ifplugd's +manpage

+ +

Thomas Hood, Asgeir Nilsen, Sean Reifschneider, R. Steve McKown, David Mitchell, Norbert Preining, Herbert Graeber for patches

+ +

Frederic Lepied for integrating ifplugd into Mandrake Linux

+ +

Download

+ +

The newest release is always available from @PACKAGE_URL@

+ +

The current release is @PACKAGE_VERSION@

+ +

Get ifplugd's development sources from the Subversion repository.

+ +

You may find an up to date Debian package of ifplugd on the Debian package repository.

+ +

Packages for Mandrake Linux may be found in the Cooker distribution; Gentoo packages are available as well; SuSE packages are available courtesy of Herbert Graeber.

+ +

If you want to be notified whenever I release a new version of this software use the subscription feature of Freshmeat.

+ +

New! There is a joint ifplugd and waproamd mailing list available.

+ +
+
Lennart Poettering <@PACKAGE_BUGREPORT@>, February 2004
+
$Id$
+ + + diff --git a/src/Makefile.in b/src/Makefile.in new file mode 100644 index 0000000..0311c0d --- /dev/null +++ b/src/Makefile.in @@ -0,0 +1,64 @@ +# $Id$ + +# Copyright 2004 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 +# may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +DISTFILES=Makefile.in mod_mime_xattr.c +APXS=@APXS@ +APACHECTL=apachectl + +# additional user defines, includes and libraries +#DEF=-Dmy_define=my_value +#INC=-Imy/include/dir +#LIB=-Lmy/lib/dir -lc -lmylib +LIB=-lattr + +# the default target +all: mod_mime_xattr.so + +# 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 + +# cleanup +clean: + -rm -f mod_mime_xattr.o mod_mime_xattr.so + +# 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 diff --git a/src/mod_mime_xattr.c b/src/mod_mime_xattr.c new file mode 100644 index 0000000..434de4a --- /dev/null +++ b/src/mod_mime_xattr.c @@ -0,0 +1,227 @@ +/* $Id$ */ + +/*** + + Copyright 2004 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 + may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + 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 +#include +#include + +#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" + +#define XATTR_NAME_MIMETYPE "user.mime-type" +#define XATTR_NAME_ENCODING "user.mime-encoding" +#define XATTR_NAME_CHARSET "user.charset" +#define XATTR_NAME_HANDLER "user.apache-handler" + +module MODULE_VAR_EXPORT mime_xattr_module; + +struct mime_xattr_dir_config { + int enable_mime_type; + int enable_handler; +}; + +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)); + c->enable_mime_type = 0; + c->enable_handler = 0; + 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; + c->enable_mime_type = flag; + 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; + c->enable_handler = flag; + 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) { + 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) + return NULL; + + v[l] = 0; + + return ap_pstrdup(p, v); +} + +static char* validate_charset(char *f) { + char *c; + + for (c = f; *c; c++) { + *c = tolower(*c); + if (!(*c >= 'a' && *c <= 'z') && !(*c >= '0' && *c <= '9') && *c != '-') + return NULL; + } + + return c > f ? f : NULL; +} + +#define validate_encoding(f) validate_charset(f) +#define validate_handler(f) validate_charset(f) + +static char* validate_mime_type(char *f) { + char *c, *slash = NULL; + + for (c = f; *c; c++) { + *c = tolower(*c); + + if (*c == '/') { + if (!slash && c > f) { + slash = c; + continue; + } else + return NULL; + } + + if (!(*c >= 'a' && *c <= 'z') && !(*c >= '0' && *c <= '9') && *c != '-') + return NULL; + } + + return c > f && slash && slash < c-1 ? f : NULL; +} + +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)) + return DECLINED; + + c = (struct mime_xattr_dir_config*) 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); + + if ((mime_type = get_xattr(r->pool, r->filename, XATTR_NAME_MIMETYPE))) { + 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); + else { + if (charset) + mime_type = ap_psprintf(r->pool, "%s; charset=%s", mime_type, charset); + + r->content_type = mime_type; + result = OK; + } + } + + if (charset && !mime_type && r->content_type) { + char *a, *ct = ap_pstrdup(r->pool, r->content_type); + static const char spec[] = "; charset="; + + if ((a = strstr(ct, spec))) { + char *e; + e = a+strlen(spec); + e += strcspn(e, "; "); + + *a = 0; + + r->content_type = ap_psprintf(r->pool, "%s; charset=%s%s", ct, charset, e); + } else + r->content_type = ap_psprintf(r->pool, "%s; charset=%s", ct, charset); + } + + if ((encoding = get_xattr(r->pool, r->filename, XATTR_NAME_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 + r->content_encoding = encoding; + } + } + + if (c->enable_handler) { + char *handler; + + if ((handler = get_xattr(r->pool, r->filename, XATTR_NAME_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); + else { + r->handler = handler; + result = OK; + } + } + } + + return result; +} + +/* Dispatch list for API hooks */ +module MODULE_VAR_EXPORT mime_xattr_module = { + STANDARD_MODULE_STUFF, + NULL, /* module initializer */ + 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 +}; -- cgit