eaaea5 | 2016-05-31 | Martin Karlgren | | #include <module.h>
inherit "module";
constant module_type = MODULE_LOCATION;
|
eefa61 | 2016-09-27 | Anders Johansson | |
#define LOCALE(X,Y) _STR_LOCALE("mod_fs_proxy",X,Y)
|
eaaea5 | 2016-05-31 | Martin Karlgren | | #define DLOCALE(X,Y) _DEF_LOCALE("mod_fs_proxy",X,Y)
LocaleString module_name = DLOCALE(0, "File systems: Proxy File System");
LocaleString module_doc =
|
eefa61 | 2016-09-27 | Anders Johansson | | DLOCALE(0, "This module can be used to proxy requests to a path in a site to"
" a filesystem module in another site. Can be useful if a module "
"needs to handle the root path for a port, but that module needs to "
"be loaded in a configuration where it cannot be mounted on the "
"root path.");
|
eaaea5 | 2016-05-31 | Martin Karlgren | |
class LocationModuleChoice
{
inherit Variable.StringChoice;
array(string) get_choice_list()
{
return Array.flatten (map (roxen->configurations,
lambda (Configuration conf)
{
return map (conf->location_modules(),
lambda (array entry)
{
string loc = entry[0];
function ff = entry[1];
RoxenModule mod =
Roxen.get_owning_module (ff);
return conf->name + ": " +
mod->module_local_id();
});
}));
}
protected void create(string default_value, void|int flags,
void|LocaleString std_name, void|LocaleString std_doc)
{
::create(default_value, ({}), flags, std_name, std_doc);
}
}
protected void create (Configuration conf)
{
defvar ("location",
Variable.Location ("/", 0,
"Location",
"The virtual mountpoint for the module."));
defvar ("location_module",
LocationModuleChoice ("", 0,
"Destination Module",
"The module to forward requests to."));
}
protected Configuration get_conf (string conf_name)
{
mapping(string:Configuration) configurations =
mkmapping (map (roxen->configurations->name, lower_case),
roxen->configurations);
return configurations[lower_case (conf_name)];
}
protected RoxenModule get_mod()
{
array(string) segments = query ("location_module") / ":";
|
d80971 | 2016-05-31 | Martin Karlgren | | if (sizeof (segments) != 2)
return 0;
|
eaaea5 | 2016-05-31 | Martin Karlgren | | string conf_name = String.trim_all_whites (segments[0]);
string mod_id = String.trim_all_whites (segments[1]);
Configuration conf = get_conf (conf_name);
|
d80971 | 2016-05-31 | Martin Karlgren | | return conf && conf->find_module (mod_id);
|
eaaea5 | 2016-05-31 | Martin Karlgren | | }
mapping(string:mixed)|int(-1..0)|Stdio.File find_file(string path,
RequestID id)
{
|
d80971 | 2016-05-31 | Martin Karlgren | | RoxenModule mod = get_mod();
return mod && mod->find_file (path, id);
|
eaaea5 | 2016-05-31 | Martin Karlgren | | }
Stat stat_file(string f, RequestID id)
{
|
d80971 | 2016-05-31 | Martin Karlgren | | RoxenModule mod = get_mod();
return mod && mod->stat_file (f, id);
|
eaaea5 | 2016-05-31 | Martin Karlgren | | }
array(string) find_dir (string f, RequestID id)
{
|
d80971 | 2016-05-31 | Martin Karlgren | | RoxenModule mod = get_mod();
return mod && mod->find_dir (f, id);
|
eaaea5 | 2016-05-31 | Martin Karlgren | | }
|