5a31bd1998-10-02Henrik Grubbström (Grubba) /* * PATH_INFO support for Roxen. * * Henrik Grubbström 1998-10-01 */ #include <module.h>
e793be1999-10-10Per Hedbor #include <stat.h>
5a31bd1998-10-02Henrik Grubbström (Grubba)  inherit "module";
21f14f1999-12-18Martin Nilsson constant cvs_version = "$Id: pathinfo.pike,v 1.7 1999/12/18 14:47:00 nilsson Exp $";
5a31bd1998-10-02Henrik Grubbström (Grubba) constant thread_safe = 1; // #define PATHINFO_DEBUG array register_module() { return ({ MODULE_LAST, "PATH_INFO support", "Support for PATH_INFO style URLs.", 0, 1 }); } mapping|int last_resort(object id) { #ifdef PATHINFO_DEBUG
21f14f1999-12-18Martin Nilsson  werror(sprintf("PATHINFO: Checking %O...\n", id->not_query));
5a31bd1998-10-02Henrik Grubbström (Grubba) #endif /* PATHINFO_DEBUG */ if (id->misc->path_info) { // Already been here... #ifdef PATHINFO_DEBUG
21f14f1999-12-18Martin Nilsson  werror(sprintf("PATHINFO: Been here, done that.\n"));
5a31bd1998-10-02Henrik Grubbström (Grubba) #endif /* PATHINFO_DEBUG */ 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;
e793be1999-10-10Per Hedbor #ifdef PATHINFO_DEBUG
21f14f1999-12-18Martin Nilsson  werror("PATHINFO: Trying: %O (%O)\n", query, pi);
e793be1999-10-10Per Hedbor #endif
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;
e793be1999-10-10Per Hedbor #ifdef PATHINFO_DEBUG
21f14f1999-12-18Martin Nilsson  werror("PATHINFO: Found: %O:%O\n", id->not_query, id->misc->path_info);
e793be1999-10-10Per Hedbor #endif
7ae17d1999-10-04Per Hedbor  return 1; } }
5a31bd1998-10-02Henrik Grubbström (Grubba)  return 0; }