File: stripper.pike

package info (click to toggle)
libroxen-stripper 1.8-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 28 kB
  • sloc: makefile: 36
file content (89 lines) | stat: -rw-r--r-- 2,007 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Filter module that strips away unnecessary whitespace.
 *
 * $Log: stripper.pike,v $
 * Revision 1.8  2000/12/01 15:09:42  gibreel
 * Better checking for null values.
 *
 * Revision 1.7  2000/08/17 11:00:08  gibreel
 * Returns a NULL value instead of barfing if a NULL value is passed to
 * the filter function (404 and such).
 *
 * Revision 1.6  2000/07/24 13:34:27  gibreel
 * Loginfo test.
 *
 * Revision 1.5  2000/07/24 13:32:49  gibreel
 * Loginfo test.
 *
 * Revision 1.4  2000/07/24 13:31:27  gibreel
 * Loginfo test.
 *
 * Revision 1.3  2000/07/24 13:22:39  gibreel
 * Loginfo test.
 *
 * Revision 1.2  2000/07/24 13:20:58  gibreel
 * Fortsatt i ferd med  bli opprettet.
 */

// This is for debug output
//#define RETURN_ERROR(x) http_string_answer(x)
#define RETURN_ERROR(x) 0

constant cvs_version = "$Id: stripper.pike,v 1.8 2000/12/01 15:09:42 gibreel Exp $";
int thread_safe=1;

#include <module.h>
inherit "module";
inherit "roxenlib";

int usecount;

string starttime = ctime(time());

string status()
{
   return "Called " + usecount + " times since " + starttime;
}

array register_module()
{
  return ({ MODULE_FILTER,
	    "Whitespace stripper",
	    "Strips away unnecessary whitespace from HTML code to be delivered to browsers.",
	    ({ }),
	    1
         });
}

void create()
{
    defvar("types", ({ "text/html" }), "Handled MIME types", TYPE_STRING_LIST,
	   "The MIME types to be handled by this filter. This will mostly only be text/html.");
}

mixed strip_whitespace(mixed s)
{
    array f,r = ({});
    int i;
    string t;
    
    if (!stringp(s)) return s;
    
    f = s / "\n";
    f = f - ({""});
    for (i=0;i<sizeof(f);i++) {
	sscanf(f[i],"%*[ \t]%s",t);
	if (strlen(t))
	    r += ({t});
    }
    return r * "\n";
}

mixed filter(mapping response, object id)
{
    if (!response) return response;
    if (search(query("types")-({""}),response["type"]) == -1)
	return response;
    response["data"] = strip_whitespace(response["data"]);
    return response;
}