1$NetBSD: rfilter.2,v 1.4 2020/03/22 23:24:08 gutteridge Exp $ 2 3Advanced rfilter usage: the strip key, and cmd:// notation 4 5 61. The strip key 7 8All examples so far have had a match field of foo/, and have 9subsequently stripped out foo/ from the path before calling the 10designated program. This example shows how to not strip, if 11desired. 12 13Remember that the third parameter in a configuration specifies 14the leading pathname component to strip (the ``strip key'' in my 15nomenclature). This must match the leading characters in the 16path, otherwise no stripping is done. To see the difference 17between stripping and no stripping, use the following 18configuration (or rfilter.2.conf): 19 20 echo/ rfilter echo/ echo %s 21 echo_nostrip/ rfilter no_strip echo %s 22 23Mount, and try a few things: 24 25 % mkdir portal 26 27 % mount_portal /usr/share/examples/mount_portal/rfilter.2.conf `pwd`/portal 28 29 % cat portal/echo/"Hello there." 30 Hello there. 31 32 % cat portal/echo_nostrip/"Hello there." 33 echo_nostrip/Hello there. 34 35Notice that in the second case, the full path name (after 36removing the mountpoint) was substituted for %s, and not just the 37portion beyond the match key. 38 39 402. cmd://, and how it can cause problems 41 42With the proliferation of the web, URLs like 43http://host/path/path and ftp://host/path/path, 44gopher://host/path, etc. have become common. We can provide web 45access through the file system by parsing such names, and 46treating them appropriately. Use rfilter.2.conf, in particular, 47the following lines: 48 49 ftp:// rfilter nostrip ftp -Vo - %s 50 http:// rfilter nostrip ftp -Vo - %s 51 52Now, access the web! 53 54 % mount_portal /usr/share/examples/mount_portal/rfilter.2.conf `pwd`/portal 55 56 % cksum portal/http://www.NetBSD.org/ 57 362001418 6920 portal/http://www.NetBSD.org/ 58 59 % more portal/http://www.NetBSD.org/ 60 <html> 61 <head> 62 <!-- Copyright (c) 1996, 1997, 1998, 1999 63 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED. --> 64 ... 65 66Similarly, we can access ftp sites via ftp:// 67 68 % cat portal/ftp://ftp.NetBSD.org/pub/NetBSD/.message 69 GIVEN THE NATURE OF THE SOFTWARE MADE AVAILABLE UNDER THIS PROGRAM 70 IT IS HEREBY NOTED THAT ALL SOFTWARE, WITH THE EXCEPTION ... 71 72 73The difficulty with the URL format becomes clear if we try to tar 74a file from ftp://...: 75 76 % tar tzf portal/ftp://ftp.NetBSD.org/pub/NetBSD-current/tar_files/doc.tar.gz 77 portal/ftp: Unknown host 78 tar (child): can't open archive portal/ftp://ftp.NetBSD.org/pub/NetBSD-current/tar_files/doc.tar.gz : Input/output error 79 80The problem is, when tar sees a file of the form A:B, it assumes 81A is a hostname. In this case, A is "portal/ftp", which is 82obviously not a hostname. 83 84If we want to avoid this problem, there are at least two 85solutions: 86 1. cat portal/ftp://ftp.NetBSD.org/pub/NetBSD-current/tar_files/doc.tar.gz | tar tzf - 87 88 2. Use ftp%// in the configuration file: 89 90 ftp%// rfilter ftp%// ftp -Vo - ftp://%s 91 92 % tar tzf portal/ftp%//ftp.NetBSD.org/pub/NetBSD-current/tar_files/doc.tar.gz 93 94Note that in this case, we strip out ftp%//, and prepend ftp:// 95to the path argument to ftp. 96 97tar is not the only application which treats a colon specially -- 98some others include dump, restore, and rcp/scp. For this reason, 99it is recommended to use %, rather than :, for URL-like cmd%// 100portal configurations. 101 102 1033. Guru usage 104 105We conclude this file with an outlandish example showing the full 106utility of the rfilter portal. Assume we want a single command 107that can extract files from a bzip2'd tar archive that is on 108an ftp site. Currently, tar does not understand bzip2 format, so 109it requires at least 3 commands: 110 1. fetch from ftp site 111 2. bunzip2 the file 112 3. extract. 113 114With appropriate portal configurations, the following single command 115would also work. 116 117tar xf portal/bzcat%//`pwd`/portal/ftp%//FTP.SITE.NET/path/path/tar.bz2 118