f41b98 | 2009-05-07 | Martin Stjernholm | |
|
1430c0 | 2000-03-16 | Martin Nilsson | |
|
980d53 | 2007-05-16 | Stefan Wallström | | #include <module.h>
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | inherit "module";
|
0917d3 | 2013-03-04 | Anders Johansson | | constant cvs_version = "$Id$";
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | constant thread_safe = 1;
|
29c8dd | 1999-12-28 | Martin Nilsson | | #ifdef PATHINFO_DEBUG
# define PATHINFO_WERR(X) werror("PATHINFO: "+X+"\n");
#else
# define PATHINFO_WERR(X)
#endif
|
28bb74 | 2000-02-10 | Martin Nilsson | | constant module_type = MODULE_LAST;
|
17013c | 2001-05-16 | Per Hedbor | | constant module_name = "Scripting: Path info support";
|
402509 | 2000-03-20 | Martin Stjernholm | | constant module_doc = #"\
Support for \"path info\" style URLs, e.g. URLs that got a path like
<tt>/index.html/a/b</tt>, where <tt>/index.html</tt> is an existing
file, but <tt>/index.html/a</tt> and <tt>/index.html/a/b</tt> aren't.
In this case <tt>/index.html</tt> will be fetched, and the rest,
<tt>/a/b</tt> is made available in the RXML variable page.pathinfo.";
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | |
|
123152 | 2000-06-19 | Henrik Grubbström (Grubba) | |
|
980d53 | 2007-05-16 | Stefan Wallström | | array pathlimit = ({ });
void create(Configuration c) {
defvar("pathlimit", ({ }), "Limit to paths",
TYPE_STRING_LIST,
|
ce64c8 | 2007-05-16 | Jonas Wallden | | "If specified, path info support will only be active for paths matching globs provided in this list.");
|
980d53 | 2007-05-16 | Stefan Wallström | | }
void start() {
pathlimit = query("pathlimit");
}
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | mapping|int last_resort(object id)
{
|
980d53 | 2007-05-16 | Stefan Wallström | | if(sizeof(pathlimit)) {
int found_match = 0;
foreach(pathlimit, string s) {
if(glob(s, id->not_query)) {
found_match = 1;
break;
}
}
if(!found_match)
return 0;
}
|
29c8dd | 1999-12-28 | Martin Nilsson | | PATHINFO_WERR(sprintf("Checking %O...", id->not_query));
|
3b7843 | 2004-04-19 | Martin Stjernholm | |
#if 0
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | if (id->misc->path_info) {
|
29c8dd | 1999-12-28 | Martin Nilsson | | PATHINFO_WERR(sprintf("Been here, done that."));
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | return 0;
}
|
3b7843 | 2004-04-19 | Martin Stjernholm | | #endif
|
b5019b | 1999-03-25 | Kadlecsik Jozsi | |
string query = id->not_query;
|
123152 | 2000-06-19 | Henrik Grubbström (Grubba) | | #ifndef PATHINFO_LINEAR
array(int) offsets = Array.map(query/"/", sizeof);
int sum = 0;
int i;
for (i=0; i < sizeof(offsets); i++) {
sum = (offsets[i] += sum) + 1;
}
int lo = (offsets[0] == 0);
int hi = sizeof(offsets) - 1;
while(lo <= hi) {
int probe = (lo + hi + 1)/2;
string file = query[..offsets[probe]-1];
PATHINFO_WERR(sprintf("Trying %O...", file));
array st = id->conf->stat_file(file, id);
if (st) {
if (st[1] >= 0) {
id->misc->path_info = query[offsets[probe]..];
id->not_query = file;
PATHINFO_WERR(sprintf("Found: %O:%O",
id->not_query, id->misc->path_info));
return 1;
}
PATHINFO_WERR(sprintf("Directory: %O", file));
lo = probe + 1;
} else {
hi = probe - 1;
}
}
#else /* PATHINFO_LINEAR */
|
7ae17d | 1999-10-04 | Per Hedbor | | string pi = "";
|
e793be | 1999-10-10 | Per Hedbor | | while( (search( query[1..], "/" ) != -1) && strlen( query ) > 0 )
|
7ae17d | 1999-10-04 | Per Hedbor | | {
query = reverse(query);
string add_path_info;
sscanf( query, "%[^/]/%s", add_path_info, query );
query = reverse( query );
|
402509 | 2000-03-20 | Martin Stjernholm | | pi = "/"+reverse( add_path_info )+pi;
|
7ae17d | 1999-10-04 | Per Hedbor | | id->misc->path_info = pi;
|
29c8dd | 1999-12-28 | Martin Nilsson | | PATHINFO_WERR(sprintf("Trying: %O (%O)", query, pi));
|
7ae17d | 1999-10-04 | Per Hedbor | | array st = id->conf->stat_file( query, id );
|
e793be | 1999-10-10 | Per Hedbor | | if( st && (st[ ST_SIZE ] > 0))
|
7ae17d | 1999-10-04 | Per Hedbor | | {
id->not_query = query;
|
29c8dd | 1999-12-28 | Martin Nilsson | | PATHINFO_WERR(sprintf("Found: %O:%O",
id->not_query, id->misc->path_info));
|
7ae17d | 1999-10-04 | Per Hedbor | | return 1;
}
}
|
123152 | 2000-06-19 | Henrik Grubbström (Grubba) | | #endif /* !PATHINFO_LINEAR */
|
5a31bd | 1998-10-02 | Henrik Grubbström (Grubba) | | return 0;
}
|