Home | History | Annotate | Download | only in mod_sed
      1  0  jyri Table of contents :
      2  0  jyri 1. Introduction
      3  0  jyri 2. Compilation
      4  0  jyri    2.1 Compilation on Unix platforms
      5  0  jyri    2.2 Compiling on Windows
      6  0  jyri 3. Installation
      7  0  jyri 4. Configuration
      8  0  jyri    4.1 Loading sed module.
      9  0  jyri    4.2 Configuring filter for a directory/location
     10  0  jyri    4.3 Configuring sed scripts
     11  0  jyri 5. Examples
     12  0  jyri    5.1 Adding a output (response) filter
     13  0  jyri    5.2 Adding a input (request) filter
     14  0  jyri       5.2.1 Converting "<" and ">" characters in input data in an HTML form.
     15  0  jyri    5.3 Removing a filter
     16  0  jyri 6. Sed differences.
     17  0  jyri    6.1 a\ and c\ commands
     18  0  jyri 7. About License
     19  0  jyri 
     20  0  jyri 
     21  0  jyri 1. Introduction
     22  0  jyri ---------------
     23  0  jyri    Apache sed filter can be used to filter the input (typically POST data) and
     24  0  jyri    output filter (generated data) using sed commands. Sed code is taken from
     25  0  jyri    Opensolaris sed command (/usr/ucb/sed). Man page for sed is located at
     26  0  jyri    http://docs.sun.com/app/docs/doc/816-5165/sed-1b?a=view
     27  0  jyri 
     28  0  jyri    Functional specification documentation is available at mod_sed_filter.html
     29  0  jyri 
     30  0  jyri 2. Compilation
     31  0  jyri --------------
     32  0  jyri 
     33  0  jyri 2.1 Compilation on Unix platforms
     34  0  jyri ---------------------------------
     35  0  jyri     To compile the mod_sed, use the apxs tool provided by apache :
     36  0  jyri     $ apxs -c mod_sed.c regexp.c sed0.c sed1.c
     37  0  jyri          apxs will typically generate the mod_sed.so in .libs directory.
     38  0  jyri 
     39  0  jyri 2.2 Compiling on Windows
     40  0  jyri ------------------------
     41  0  jyri     Windows apache don't have apxs tool so to compile mod_sed, we need
     42  0  jyri     apache sources (built).
     43  0  jyri     C:> mkdir sed
     44  0  jyri     C:> cd sed
     45  0  jyri     C:> rem Copy sources to sed directory
     46  0  jyri        Now build the sources using mod_sed.mak makefile. Set the APACHE_DIR
     47  0  jyri        to your Apache installation directory in mod_sed.mak file and then 
     48  0  jyri        build.
     49  0  jyri        Make sure you have VC 6 installed and you have sourced vcvars32.bat.
     50  0  jyri     C:> nmake /f mod_sed.mak APACHE_DIR=<path to apache>
     51  0  jyri         If successful then compiled library is located in Release\mod_sed.so 
     52  0  jyri 
     53  0  jyri 
     54  0  jyri 3. Installation
     55  0  jyri ---------------
     56  0  jyri    Copy mod_sed.so in <apache_inst_dir>/modules directory. 
     57  0  jyri 
     58  0  jyri 4. Configuration
     59  0  jyri ----------------
     60  0  jyri 
     61  0  jyri 4.1 Loading sed module.
     62  0  jyri ---------------------------
     63  0  jyri     Load the sed module using LoadModule apache directive in httpd.conf e.g
     64  0  jyri LoadModule sed_module modules/mod_sed.so
     65  0  jyri 
     66  0  jyri 4.2 Configuring filter for a directory/location
     67  0  jyri ------------------------------------------------
     68  0  jyri     Filter can be added using AddOutputFilter apache directive in 
     69  0  jyri     httpd.conf e.g 
     70  0  jyri 
     71  0  jyri        AddOutputFilter Sed html
     72  0  jyri 
     73  0  jyri 4.3 Configuring sed scripts
     74  0  jyri ---------------------------
     75  0  jyri     Sed script/command for output filter is provided by OutputSed and for input
     76  0  jyri     filter, it is provided by InputSed e.g
     77  0  jyri 
     78  0  jyri        OutputSed "s/california/CA/g"
     79  0  jyri 
     80  0  jyri     Multiple sed scripts are provided by multiple OutputSed/InputSed
     81  0  jyri     directives.
     82  0  jyri 
     83  0  jyri 5. Examples
     84  0  jyri -----------
     85  0  jyri 
     86  0  jyri 5.1 Adding a output (response) filter
     87  0  jyri --------------------------
     88  0  jyri <Directory "/opt/sun/apache2/htdocs/testsed">
     89  0  jyri     AddOutputFilter Sed html
     90  0  jyri     OutputSed "s/california/CA/g"
     91  0  jyri     OutputSed "s/washington/WA/g"
     92  0  jyri </Directory>
     93  0  jyri 
     94  0  jyri    The above example will replace the string "california" to "CA" and
     95  0  jyri    "washington" to "WA" in all html docs in testsed directory before sending
     96  0  jyri    to client.
     97  0  jyri 
     98  0  jyri 5.2 Adding a input (request) filter
     99  0  jyri -----------------------------------
    100  0  jyri     Following example adds a input filter to php cgi scripts.  Sed scripts
    101  0  jyri     will be executed for any POST data to php files.
    102  0  jyri <Directory "/opt/sun/apache2/cgi-bin">
    103  0  jyri     AddInputFilter Sed php
    104  0  jyri     InputSed "s/california/CA/g"
    105  0  jyri </Directory>
    106  0  jyri     In the above example, if POST (or even GET in HTTP/1.1) data (not the
    107  0  jyri     headers) contains the string "california" then it is replaced with string
    108  0  jyri     "CA" before the post data is made available to php script.
    109  0  jyri 
    110  0  jyri 5.2.1 Converting "<" and ">" characters in input data in an HTML form.
    111  0  jyri ----------------------------------------------------------------------
    112  0  jyri <Directory "/opt/sun/apache2/cgi-bin">
    113  0  jyri     AddInputFilter Sed php
    114  0  jyri     InputSed "s/</&lt;/g"
    115  0  jyri     InputSed "s/%3c/&lt;/g"
    116  0  jyri     InputSed "s/%3C/&lt;/g"
    117  0  jyri     InputSed "s/>/&gt;/g"
    118  0  jyri     InputSed "s/%3e/&gt;/g"
    119  0  jyri     InputSed "s/%3E/&gt;/g"
    120  0  jyri </Directory>
    121  0  jyri 
    122  0  jyri 5.3 Removing a filter
    123  0  jyri ---------------------
    124  0  jyri     Once a filter is added to a directory, it works for any subdirectory
    125  0  jyri     underneath. To remove a filter for a particular subdirectory
    126  0  jyri     RemoveOutputFilter/RemoveInputFilter apache directives are used. Following
    127  0  jyri     removes the output filter from subdir1.
    128  0  jyri <Directory "/opt/sun/apache2/htdocs/testsed/subdir1">
    129  0  jyri     RemoveOutputFilter Sed html
    130  0  jyri </Directory>
    131  0  jyri 
    132  0  jyri 
    133  0  jyri 
    134  0  jyri 6. Sed differences.
    135  0  jyri ------------------
    136  0  jyri 
    137  0  jyri 6.1 a\ and c\ commands
    138  0  jyri ----------------------
    139  0  jyri     sed allows commands to continue by adding "\" at the e.g.
    140  0  jyri a\
    141  0  jyri ok
    142  0  jyri q
    143  0  jyri 
    144  0  jyri If we specify the equivalent in httpd.conf e.g
    145  0  jyri OutputSed "a\"
    146  0  jyri OutputSed "ok"
    147  0  jyri OutputSed "q"
    148  0  jyri 
    149  0  jyri Since "a\" command expect new line to be followed, httpd.conf provides no
    150  0  jyri means to insert new line (AFAIK) so it doesn't seem possible to use "a\"
    151  0  jyri and "c\" commands.
    152  0  jyri 
    153  0  jyri 7. About License
    154  0  jyri ----------------
    155  0  jyri     The code is available under Apache 2.0 license. While the original sed code
    156  0  jyri from OpenSolaris.org was licensed under CDDL, Sun is dontating this code
    157  0  jyri under Apache license to the benefit of Apache Community.  The code has been
    158  0  jyri derived from 4 files which are published under CDDL license in the ON
    159  0  jyri consolidation. These files are :
    160  0  jyri http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/sed/sed.h
    161  0  jyri http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/sed/sed0.c
    162  0  jyri http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/sed/sed1.c
    163  0  jyri http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbhead/regexp.h
    164  0  jyri 
    165