File: Programs.pike

package info (click to toggle)
libroxen-programcache 1.0-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 28 kB
  • sloc: makefile: 36
file content (59 lines) | stat: -rw-r--r-- 1,899 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
/*
 * Programs.pike
 * (C) 1998, 1999 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
 * This program is freely redistributable under the terms of the GNU
 * General Public License, release 2.
 * This program comes with NO WARRANTY OF ANY KIND
 *
 * This is a pikescript for the Roxen webserver, whose purpose is to
 * manage the Pike Programs cache in the Pike Master Object.
 * When a program is loaded, it is cached by the master object. When
 * cloned thereafter, the cached copy will be used. This is not
 * a problem normally (for modules and pikescripts), but it _IS_
 * a problem if, for example, your pikescript inherits from something
 * and you want to reload that something.
 *
 * How to use it: invoke it, you'll be given a list of all the programs
 * in cache. Click on "delete" to delete one. Reload to refresh.
 * Simple, isn't it? What did you expect in 35 lines of code anyways? :-P
 */

inherit "roxenlib";

void delete_programs() {
	master()->programs=([]);
}

void delete_program(string name) {
	m_delete(master()->programs,name);
}

mapping parse (object id) {
	if (search(id->raw_url,"?")<0)
		return http_redirect(id->not_query+"?",id);
	array programs=Array.map(sort(indices(master()->programs)),
			lambda(string s, object id) {
			return sprintf("<A href=%s?delete=%s>delete</A> %s",
					id->not_query,s,s);
				}
				,id
			);
	string retval= replace(programs*"\n", "\n", "<BR>\n");
	if (id->variables->delete) {
		delete_program(id->variables->delete);
		return http_redirect(id->not_query+"?",id);
		}
	if (id->variables->deleteall) {
		delete_programs();
		return http_redirect(id->not_query+"?",id);
	} else {
		retval += "<P><A href=\""+id->not_query+"?deleteall=1\">Cancella tutto</A>";
	}
	return http_string_answer (retval,"text/html");
}

int no_reload (object id) {
	if (id->variables->reload||id->config->reload||id->config->debug)
		return 0;
	return 1;
}