1430c02000-03-16Martin Nilsson // This is a roxen module. Copyright © 1998 - 2000, Roxen IS.
5a31bd1998-10-02Henrik Grubbström (Grubba) inherit "module";
1430c02000-03-16Martin Nilsson constant cvs_version = "$Id: pathinfo.pike,v 1.11 2000/03/16 18:57:14 nilsson 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; constant module_name = "PATH_INFO support"; constant module_doc = "Support for PATH_INFO style URLs.";
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 ); if( strlen( pi ) ) pi = "/"+reverse( add_path_info )+pi; else pi = "/"+add_path_info; 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; }