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