1430c02000-03-16Martin Nilsson // This is a roxen module. Copyright © 1998 - 2000, Roxen IS.
5a31bd1998-10-02Henrik Grubbström (Grubba) inherit "module";
4025092000-03-20Martin Stjernholm constant cvs_version = "$Id: pathinfo.pike,v 1.12 2000/03/20 03:05:56 mast Exp $";
5a31bd1998-10-02Henrik Grubbström (Grubba) constant thread_safe = 1;
29c8dd1999-12-28Martin Nilsson #ifdef PATHINFO_DEBUG # define PATHINFO_WERR(X) werror("PATHINFO: "+X+"\n"); #else # define PATHINFO_WERR(X) #endif
28bb742000-02-10Martin Nilsson constant module_type = MODULE_LAST;
4025092000-03-20Martin Stjernholm constant module_name = "Path info support"; 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.";
5a31bd1998-10-02Henrik Grubbström (Grubba)  mapping|int last_resort(object id) {
29c8dd1999-12-28Martin Nilsson  PATHINFO_WERR(sprintf("Checking %O...", id->not_query));
5a31bd1998-10-02Henrik Grubbström (Grubba)  if (id->misc->path_info) { // Already been here...
29c8dd1999-12-28Martin Nilsson  PATHINFO_WERR(sprintf("Been here, done that."));
5a31bd1998-10-02Henrik Grubbström (Grubba)  return 0; }
b5019b1999-03-25Kadlecsik Jozsi  string query = id->not_query;
7ae17d1999-10-04Per Hedbor  string pi = "";
e793be1999-10-10Per Hedbor  while( (search( query[1..], "/" ) != -1) && strlen( query ) > 0 )
7ae17d1999-10-04Per Hedbor  { query = reverse(query); string add_path_info; sscanf( query, "%[^/]/%s", add_path_info, query ); query = reverse( query );
4025092000-03-20Martin Stjernholm  pi = "/"+reverse( add_path_info )+pi;
7ae17d1999-10-04Per Hedbor  id->misc->path_info = pi;
29c8dd1999-12-28Martin Nilsson  PATHINFO_WERR(sprintf("Trying: %O (%O)", query, pi));
7ae17d1999-10-04Per Hedbor  array st = id->conf->stat_file( query, id );
e793be1999-10-10Per Hedbor  if( st && (st[ ST_SIZE ] > 0))
7ae17d1999-10-04Per Hedbor  { id->not_query = query;
29c8dd1999-12-28Martin Nilsson  PATHINFO_WERR(sprintf("Found: %O:%O", id->not_query, id->misc->path_info));
7ae17d1999-10-04Per Hedbor  return 1; } }
5a31bd1998-10-02Henrik Grubbström (Grubba)  return 0; }