835c6c | 2001-06-17 | Martin Nilsson | |
|
b655bf | 2004-06-30 | Martin Stjernholm | |
|
7a475b | 2005-05-11 | Marcus Wellhardh | |
|
c20c87 | 2000-02-16 | Per Hedbor | |
#include <module_constants.h>
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
|
c5e096 | 1999-10-04 | Per Hedbor | | #include <request_trace.h>
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
c08904 | 2001-06-11 | Per Hedbor | | constant __pragma_save_parent__ = 1;
|
a59d25 | 2000-07-04 | Per Hedbor | | inherit "basic_defvar";
|
9d9b9b | 1999-11-17 | Per Hedbor | | mapping(string:array(int)) error_log=([]);
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
9d9b9b | 1999-11-17 | Per Hedbor | | constant is_module = 1;
|
a730c2 | 2001-01-19 | Per Hedbor | |
constant module_unique = 1;
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
a59d25 | 2000-07-04 | Per Hedbor | |
|
721137 | 2001-06-29 | Martin Stjernholm | | private Configuration _my_configuration;
|
0aa37d | 2001-08-23 | Martin Stjernholm | | private string _module_local_identifier;
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | private string _module_identifier =
|
721137 | 2001-06-29 | Martin Stjernholm | | lambda() {
|
3557f5 | 2001-06-30 | Martin Stjernholm | | mixed init_info = roxen->bootstrap_info->get();
if (arrayp (init_info)) {
|
0aa37d | 2001-08-23 | Martin Stjernholm | | [_my_configuration, _module_local_identifier] = init_info;
return _my_configuration->name + "/" + _module_local_identifier;
|
721137 | 2001-06-29 | Martin Stjernholm | | }
}();
|
a59d25 | 2000-07-04 | Per Hedbor | | static mapping _api_functions = ([]);
string|array(string) module_creator;
string module_url;
RXML.TagSet module_tag_set;
|
c20c87 | 2000-02-16 | Per Hedbor | | |
b7eaa2 | 2001-08-09 | Martin Stjernholm | | * solution is not really all that beautiful, but it works. :-)
|
c20c87 | 2000-02-16 | Per Hedbor | | */
void report_fatal( mixed ... args ) { predef::report_fatal( @args ); }
void report_error( mixed ... args ) { predef::report_error( @args ); }
void report_notice( mixed ... args ) { predef::report_notice( @args ); }
void report_debug( mixed ... args ) { predef::report_debug( @args ); }
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | string module_identifier()
|
0aa37d | 2001-08-23 | Martin Stjernholm | |
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | {
|
4246ca | 2001-06-28 | Martin Stjernholm | | #if 1
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | return _module_identifier;
|
4246ca | 2001-06-28 | Martin Stjernholm | | #else
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | if (!_module_identifier) {
|
225c8e | 2001-01-31 | Marcus Comstedt | | string|mapping name = this_object()->register_module()[1];
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | if (mappingp (name)) name = name->standard;
|
8d4919 | 2000-03-18 | Martin Stjernholm | | string cname = sprintf ("%O", my_configuration());
if (sscanf (cname, "Configuration(%s", cname) == 1 &&
sizeof (cname) && cname[-1] == ')')
cname = cname[..sizeof (cname) - 2];
|
55a866 | 2000-11-20 | Per Hedbor | | _module_identifier = sprintf ("%s,%s",
|
ad5607 | 2001-01-29 | Per Hedbor | | name||this_object()->module_name, cname);
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | }
return _module_identifier;
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | #endif
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | }
|
0aa37d | 2001-08-23 | Martin Stjernholm | | string module_local_id()
{
return _module_local_identifier;
}
|
298be1 | 2001-08-13 | Per Hedbor | | RoxenModule this_module()
{
return this_object();
}
|
b6fb05 | 1999-11-02 | Per Hedbor | | string _sprintf()
{
|
b7eaa2 | 2001-08-09 | Martin Stjernholm | | return sprintf ("RoxenModule(%s)", _module_identifier || "?");
|
b6fb05 | 1999-11-02 | Per Hedbor | | }
|
c5e096 | 1999-10-04 | Per Hedbor | | array register_module()
{
return ({
|
a730c2 | 2001-01-19 | Per Hedbor | | this_object()->module_type,
|
ad5607 | 2001-01-29 | Per Hedbor | | this_object()->module_name,
this_object()->module_doc,
|
c5e096 | 1999-10-04 | Per Hedbor | | 0,
module_unique,
|
5b8112 | 2002-02-26 | Marcus Wellhardh | | this_object()->module_locked,
|
c5e096 | 1999-10-04 | Per Hedbor | | });
}
|
2a2a5b | 1996-12-01 | Per Hedbor | | string fix_cvs(string from)
{
|
fd0b6f | 1996-12-02 | Per Hedbor | | from = replace(from, ({ "$", "Id: "," Exp $" }), ({"","",""}));
|
2a2a5b | 1996-12-01 | Per Hedbor | | sscanf(from, "%*s,v %s", from);
|
00730e | 1999-11-18 | Per Hedbor | | return replace(from,"/","-");
|
2a2a5b | 1996-12-01 | Per Hedbor | | }
|
72ac57 | 2000-01-31 | Per Hedbor | | int module_dependencies(Configuration configuration,
|
f5a274 | 1999-10-18 | Per Hedbor | | array (string) modules,
int|void now)
|
facee7 | 2000-07-18 | Johan Sundström | |
|
cb9c22 | 2000-09-06 | Martin Stjernholm | |
|
edb506 | 1997-08-25 | Peter Bortas | | {
|
cb9c22 | 2000-09-06 | Martin Stjernholm | | modules = map (modules,
lambda (string modname) {
sscanf ((modname / "/")[-1], "%[^#]", modname);
return modname;
});
Configuration conf = configuration || my_configuration();
if (!conf)
report_warning ("Configuration not resolved; module(s) %s that %s "
"depend on weren't added.", String.implode_nicely (modules),
|
4246ca | 2001-06-28 | Martin Stjernholm | | module_identifier());
|
cb9c22 | 2000-09-06 | Martin Stjernholm | | else
conf->add_modules( modules, now );
|
edb506 | 1997-08-25 | Peter Bortas | | return 1;
}
|
2a2a5b | 1996-12-01 | Per Hedbor | | string file_name_and_stuff()
{
|
a59d25 | 2000-07-04 | Per Hedbor | | return ("<b>Loaded from:</b> "+(roxen->filename(this_object()))+"<br>"+
(this_object()->cvs_version?
|
80cd68 | 2003-11-17 | Anders Johansson | | "<b>CVS Version:</b> "+
|
a59d25 | 2000-07-04 | Per Hedbor | | fix_cvs(this_object()->cvs_version)+"\n":""));
|
2a2a5b | 1996-12-01 | Per Hedbor | | }
|
5839c3 | 1999-01-22 | Marcus Comstedt | |
|
9f2a97 | 1999-11-29 | Per Hedbor | | Configuration my_configuration()
|
facee7 | 2000-07-18 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | return _my_configuration;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
7fb7f5 | 1999-11-29 | Per Hedbor | | nomask void set_configuration(Configuration c)
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
if(_my_configuration && _my_configuration != c)
error("set_configuration() called twice.\n");
_my_configuration = c;
}
|
48679b | 2000-02-03 | Johan Sundström | | void set_module_creator(string|array(string) c)
|
facee7 | 2000-07-18 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
module_creator = c;
}
void set_module_url(string to)
|
facee7 | 2000-07-18 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
module_url = to;
}
void free_some_sockets_please(){}
|
7fb7f5 | 1999-11-29 | Per Hedbor | | void start(void|int num, void|Configuration conf) {}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
a59d25 | 2000-07-04 | Per Hedbor | | string status() {}
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
7fb7f5 | 1999-11-29 | Per Hedbor | | string info(Configuration conf)
|
72ac57 | 2000-01-31 | Per Hedbor | | {
|
facee7 | 2000-07-18 | Johan Sundström | | return (this_object()->register_module()[2]);
|
df6cd1 | 1998-10-13 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
a730c2 | 2001-01-19 | Per Hedbor | | string sname( )
{
|
4a5018 | 2001-01-30 | Per Hedbor | | return my_configuration()->otomod[ this_object() ];
|
a730c2 | 2001-01-19 | Per Hedbor | | }
|
2f4ac1 | 2000-11-02 | Per Hedbor | | ModuleInfo my_moduleinfo( )
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
2f4ac1 | 2000-11-02 | Per Hedbor | | {
|
a730c2 | 2001-01-19 | Per Hedbor | | string f = sname();
|
2f4ac1 | 2000-11-02 | Per Hedbor | | if( f ) return roxen.find_module( (f/"#")[0] );
}
|
2c13a8 | 1999-11-10 | Per Hedbor | | void save_me()
|
e7e603 | 1999-11-05 | Per Hedbor | | {
my_configuration()->save_one( this_object() );
|
2f4ac1 | 2000-11-02 | Per Hedbor | | my_configuration()->module_changed( my_moduleinfo(), this_object() );
|
e7e603 | 1999-11-05 | Per Hedbor | | }
|
1e9a1b | 2001-02-21 | Per Hedbor | | void save() { save_me(); }
string comment() { return ""; }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | | string query_internal_location()
|
facee7 | 2000-07-18 | Johan Sundström | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
if(!_my_configuration)
error("Please do not call this function from create()!\n");
return _my_configuration->query_internal_location(this_object());
}
|
525f72 | 2000-12-05 | Martin Nilsson | | string query_absolute_internal_location(RequestID id)
{
return (id->misc->site_prefix_path || "") + query_internal_location();
}
|
b7c45e | 1997-01-27 | Per Hedbor | | string query_location()
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
b7c45e | 1997-01-27 | Per Hedbor | | {
string s;
catch{s = query("location");};
return s;
}
|
162bd5 | 2000-02-20 | Martin Stjernholm | | array(string) location_urls()
|
facee7 | 2000-07-18 | Johan Sundström | |
|
162bd5 | 2000-02-20 | Martin Stjernholm | | {
string loc = query_location();
if (!loc) return ({});
if(!_my_configuration)
error("Please do not call this function from create()!\n");
|
3adf20 | 2000-03-06 | Jonas Wallden | | array(string) urls = copy_value(_my_configuration->query("URLs"));
|
7984d6 | 2000-10-06 | Martin Stjernholm | | string hostname;
if (string world_url = _my_configuration->query ("MyWorldLocation"))
sscanf (world_url, "%*s://%s%*[:/]", hostname);
if (!hostname) hostname = gethostname();
for (int i = 0; i < sizeof (urls); i++)
|
21182a | 2001-10-05 | Per Hedbor | | {
urls[i] = (urls[i]/"#")[0];
|
7984d6 | 2000-10-06 | Martin Stjernholm | | if (sizeof (urls[i]/"*") == 2)
|
162bd5 | 2000-02-20 | Martin Stjernholm | | urls[i] = replace(urls[i], "*", hostname);
|
21182a | 2001-10-05 | Per Hedbor | | }
|
162bd5 | 2000-02-20 | Martin Stjernholm | | return map (urls, `+, loc[1..]);
}
|
342343 | 2005-04-22 | Marcus Wellhardh | | string location_url()
{
string short_array(array a)
{
return "({ " + (map(a, lambda(object o) {
return sprintf("%O", o);
})*", ") + " })";
};
string loc = query_location();
if(!loc) return 0;
if(!_my_configuration)
error("Please do not call this function from create()!\n");
string hostname;
string world_url = _my_configuration->query("MyWorldLocation");
if(world_url)
sscanf(world_url, "%*s://%s%*[:/]", hostname);
if(!hostname)
hostname = gethostname();
#ifdef LOCATION_URL_DEBUG
werror(" Hostname: %O\n", hostname);
#endif
Standards.URI candidate_uri;
array(string) urls =
filter(_my_configuration->registered_urls, has_prefix, "http:") +
filter(_my_configuration->registered_urls, has_prefix, "https:");
foreach(urls, string url)
{
#ifdef LOCATION_URL_DEBUG
werror(" URL: %s\n", url);
#endif
mapping url_info = roxen.urls[url];
if(!url_info || !url_info->port || url_info->conf != _my_configuration)
continue;
Protocol p = url_info->port;
#ifdef LOCATION_URL_DEBUG
werror(" Protocol: %s\n", p);
#endif
Standards.URI uri = Standards.URI(url);
|
7a475b | 2005-05-11 | Marcus Wellhardh | | uri->fragment = "ip="+(p->ip? p->ip: "127.0.0.1");
|
342343 | 2005-04-22 | Marcus Wellhardh | | if(has_value(uri->host, "*") || has_value(uri->host, "?"))
if(glob(uri->host, hostname))
uri->host = hostname;
else {
if(!candidate_uri) {
candidate_uri = uri;
candidate_uri->host = hostname;
}
continue;
}
return (string)uri + loc[1..];
}
if(candidate_uri) {
report_warning("Warning: Could not find any suitable ports, continuing anyway. "
"Please make sure that your Primary Server URL matches "
"at least one port. Primary Server URL: %O, URLs: %s.\n",
world_url, short_array(urls));
return (string)candidate_uri + loc[1..];
}
return 0;
}
|
ae32d0 | 1998-03-23 | David Hedbor | |
|
ea5df5 | 2005-02-25 | Henrik Grubbström (Grubba) | | multiset(string) query_provides() { return 0; }
|
b7c45e | 1997-01-27 | Per Hedbor | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | | function(RequestID:int|mapping) query_seclevels()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
a59d25 | 2000-07-04 | Per Hedbor | | if(catch(query("_seclevels")) || (query("_seclevels") == 0))
|
bc0fa0 | 2001-03-08 | Per Hedbor | | return 0;
return roxen.compile_security_pattern(query("_seclevels"),this_object());
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | void set_status_for_path (string path, RequestID id, int status_code,
string|void message, mixed... args)
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
{
if (sizeof (args)) message = sprintf (message, @args);
id->set_status_for_path (query_location() + path, status_code, message);
}
|
8b8ecf | 2000-08-28 | Johan Sundström | | Stat stat_file(string f, RequestID id){}
array(string) find_dir(string f, RequestID id){}
mapping(string:Stat) find_dir_stat(string f, RequestID id)
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(this, "find_dir_stat(): %O", f);
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | array(string) files = find_dir(f, id);
|
8b8ecf | 2000-08-28 | Johan Sundström | | mapping(string:Stat) res = ([]);
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | |
|
0c8b9a | 1997-10-22 | Henrik Grubbström (Grubba) | | foreach(files || ({}), string fname) {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(this, "stat()'ing %O", f + "/" + fname);
|
c0f454 | 2001-02-19 | Jonas Wallden | | Stat st = stat_file(replace(f + "/" + fname, "//", "/"), id);
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | if (st) {
|
0c8b9a | 1997-10-22 | Henrik Grubbström (Grubba) | | res[fname] = st;
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("OK");
} else {
TRACE_LEAVE("No stat info");
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | }
}
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | |
TRACE_LEAVE("");
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | return(res);
}
|
a59d25 | 2000-07-04 | Per Hedbor | |
|
d35dfd | 2004-04-20 | Martin Stjernholm | | class DefaultPropertySet
{
inherit PropertySet;
|
7c8387 | 2004-04-28 | Martin Stjernholm | | static Stat stat;
|
2ece72 | 2004-05-06 | Henrik Grubbström (Grubba) | | static void create (string path, string abs_path, RequestID id, Stat stat)
|
7c8387 | 2004-04-28 | Martin Stjernholm | | {
|
2ece72 | 2004-05-06 | Henrik Grubbström (Grubba) | | ::create (path, abs_path, id);
|
7c8387 | 2004-04-28 | Martin Stjernholm | | this_program::stat = stat;
}
Stat get_stat() {return stat;}
|
d35dfd | 2004-04-20 | Martin Stjernholm | | static mapping(string:string) response_headers;
mapping(string:string) get_response_headers()
{
if (!response_headers) {
if (!id->misc->common)
id->misc->common = ([]);
RequestID sub_id = id->clone_me();
sub_id->misc->common = id->misc->common;
sub_id->not_query = query_location() + path;
sub_id->raw_url = replace (id->raw_url, id->not_query, sub_id->not_query);
sub_id->method = "HEAD";
|
7ff760 | 2004-04-28 | Martin Stjernholm | | mapping(string:mixed)|int(-1..0)|object res = find_file (path, sub_id);
|
d35dfd | 2004-04-20 | Martin Stjernholm | | if (res == -1) res = ([]);
else if (objectp (res)) {
string ext;
if(stringp(sub_id->extension)) {
sub_id->not_query += sub_id->extension;
ext = lower_case(Roxen.extension(sub_id->not_query, sub_id));
}
array(string) tmp=sub_id->conf->type_from_filename(sub_id->not_query, 1, ext);
if(tmp)
res = ([ "file":res, "type":tmp[0], "encoding":tmp[1] ]);
else
res = (["file": res]);
}
response_headers = sub_id->make_response_headers (res);
destruct (sub_id);
}
return response_headers;
}
}
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
b64c12 | 2003-08-26 | Henrik Grubbström (Grubba) | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
b64c12 | 2003-08-26 | Henrik Grubbström (Grubba) | |
|
aecff1 | 2004-03-23 | Martin Stjernholm | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
ea5df5 | 2005-02-25 | Henrik Grubbström (Grubba) | |
|
ac173b | 2004-05-10 | Martin Stjernholm | | PropertySet|mapping(string:mixed) query_property_set(string path, RequestID id)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Querying properties on %O", path);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | Stat st = stat_file(path, id);
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | if (!st) {
SIMPLE_TRACE_LEAVE ("No such file or dir");
return 0;
}
|
2ece72 | 2004-05-06 | Henrik Grubbström (Grubba) | | PropertySet res = DefaultPropertySet(path, query_location()+path, id, st);
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("");
return res;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
ea5df5 | 2005-02-25 | Henrik Grubbström (Grubba) | |
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | string|array(Parser.XML.Tree.SimpleNode)|mapping(string:mixed)
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | query_property(string path, string prop_name, RequestID id)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_property_set(path, id);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | if (!properties) {
return Roxen.http_status(Protocols.HTTP.HTTP_NOT_FOUND,
"No such file or directory.");
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
aecff1 | 2004-03-23 | Martin Stjernholm | | if (mappingp (properties))
return properties;
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | return properties->query_property(prop_name) ||
Roxen.http_status(Protocols.HTTP.HTTP_NOT_FOUND, "No such property.");
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
762b93 | 2004-03-03 | Martin Stjernholm | |
|
ea5df5 | 2005-02-25 | Henrik Grubbström (Grubba) | |
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | mapping(string:mixed) recurse_find_properties(string path, string mode,
int depth, RequestID id,
multiset(string)|void filt)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | MultiStatus.Prefixed result =
id->get_multi_status()->prefix (id->url_base() + query_location()[1..]);
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | mapping(string:mixed) recurse (string path, int depth) {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "%s for %O, depth %d",
mode == "DAV:propname" ? "Listing property names" :
mode == "DAV:allprop" ? "Retrieving all properties" :
mode == "DAV:prop" ? "Retrieving specific properties" :
"Finding properties with mode " + mode,
path, depth);
mapping(string:mixed)|PropertySet properties = query_property_set(path, id);
if (!properties) {
SIMPLE_TRACE_LEAVE ("No such file or dir");
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | return 0;
|
762b93 | 2004-03-03 | Martin Stjernholm | | }
|
ca28e8 | 2004-03-23 | Martin Stjernholm | |
|
113fa1 | 2004-05-10 | Martin Stjernholm | | {
mapping(string:mixed) ret = mappingp (properties) ?
properties : properties->find_properties(mode, result, filt);
if (ret) {
SIMPLE_TRACE_LEAVE ("Got status %d: %O", ret->error, ret->rettext);
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | return ret;
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | |
if (properties->get_stat()->isdir) {
if (depth <= 0) {
SIMPLE_TRACE_LEAVE ("Not recursing due to depth limit");
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | return 0;
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
depth--;
foreach(find_dir(path, id) || ({}), string filename) {
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | filename = combine_path_unix(path, filename);
if (mapping(string:mixed) sub_res = recurse(filename, depth))
if (sizeof (sub_res))
result->add_status (filename, sub_res->error, sub_res->rettext);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("");
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | return ([]);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | };
|
e9ceb9 | 2004-06-02 | Martin Stjernholm | | return recurse (path, depth);
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | | mapping(string:mixed) patch_properties(string path,
array(PatchPropertyCommand) instructions,
|
113fa1 | 2004-05-10 | Martin Stjernholm | | RequestID id)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Patching properties for %O", path);
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_property_set(path, id);
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | |
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | if (!properties) {
SIMPLE_TRACE_LEAVE ("No such file or dir");
return 0;
}
if (mappingp (properties)) {
|
ac173b | 2004-05-10 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("Got error %d from query_property_set: %O",
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | properties->error, properties->rettext);
return properties;
}
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | |
|
0dbbfd | 2004-05-10 | Henrik Grubbström (Grubba) | | mapping(string:mixed) errcode;
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
0dbbfd | 2004-05-10 | Henrik Grubbström (Grubba) | | if (errcode = write_access(path, 0, id)) {
SIMPLE_TRACE_LEAVE("Patching denied by write_access().");
return errcode;
}
if (errcode = properties->start()) {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("Got error %d from PropertySet.start: %O",
errcode->error, errcode->rettext);
return errcode;
}
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | array(mapping(string:mixed)) results;
mixed err = catch {
|
df0424 | 2004-03-16 | Henrik Grubbström (Grubba) | | results = instructions->execute(properties);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | };
if (err) {
properties->unroll();
throw (err);
} else {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | MultiStatus.Prefixed result =
id->get_multi_status()->prefix (id->url_base() + query_location()[1..] + path);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | int any_failed;
foreach(results, mapping(string:mixed) answer) {
if (any_failed = (answer && (answer->error >= 300))) {
break;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | | }
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | if (any_failed) {
int i;
mapping(string:mixed) answer =
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | Roxen.http_status (Protocols.HTTP.DAV_FAILED_DEP);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | for(i = 0; i < sizeof(results); i++) {
if (!results[i] || results[i]->error < 300) {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | result->add_property("", instructions[i]->property_name,
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | answer);
} else {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | result->add_property("", instructions[i]->property_name,
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | results[i]);
}
}
properties->unroll();
} else {
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | int i;
for(i = 0; i < sizeof(results); i++) {
|
113fa1 | 2004-05-10 | Martin Stjernholm | | result->add_property("", instructions[i]->property_name,
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | results[i]);
}
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | properties->commit();
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
}
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("");
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | | return 0;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
aecff1 | 2004-03-23 | Martin Stjernholm | |
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed) set_property (string path, string prop_name,
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | string|array(Parser.XML.Tree.SimpleNode) value,
|
aecff1 | 2004-03-23 | Martin Stjernholm | | RequestID id)
|
25ceaf | 2004-03-01 | Martin Stjernholm | | {
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_property_set(path, id);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | if (!properties) return Roxen.http_status(Protocols.HTTP.HTTP_NOT_FOUND,
"File not found.");
|
aecff1 | 2004-03-23 | Martin Stjernholm | | if (mappingp (properties)) return properties;
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | mapping(string:mixed) result = properties->start();
if (result) return result;
result = properties->set_property(prop_name, value);
|
aecff1 | 2004-03-23 | Martin Stjernholm | | if (result && result->error >= 300) {
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | properties->unroll();
|
aecff1 | 2004-03-23 | Martin Stjernholm | | return result;
}
properties->commit();
return 0;
|
25ceaf | 2004-03-01 | Martin Stjernholm | | }
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed) remove_property (string path, string prop_name,
RequestID id)
|
25ceaf | 2004-03-01 | Martin Stjernholm | | {
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_property_set(path, id);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | if (!properties) return Roxen.http_status(Protocols.HTTP.HTTP_NOT_FOUND,
"File not found.");
|
aecff1 | 2004-03-23 | Martin Stjernholm | | if (mappingp (properties)) return properties;
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
mapping(string:mixed) result = properties->start();
if (result) return result;
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | result = properties->remove_property(prop_name);
|
aecff1 | 2004-03-23 | Martin Stjernholm | | if (result && result->error >= 300) {
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | properties->unroll();
|
aecff1 | 2004-03-23 | Martin Stjernholm | | return result;
}
properties->commit();
return 0;
|
25ceaf | 2004-03-01 | Martin Stjernholm | | }
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | | string resource_id (string path, RequestID|int(0..0) id)
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
de070f | 2004-05-04 | Martin Stjernholm | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | | {
return has_suffix (path, "/") ? path : path + "/";
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
de070f | 2004-05-04 | Martin Stjernholm | | string|int authenticated_user_id (string path, RequestID id)
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
de070f | 2004-05-04 | Martin Stjernholm | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | | {
User uid = my_configuration()->authenticate (id);
return uid && uid->name();
}
static mapping(string:mapping(mixed:DAVLock)) file_locks = ([]);
static mapping(string:mapping(mixed:DAVLock)) prefix_locks = ([]);
#define LOOP_OVER_BOTH(PATH, LOCKS, CODE) \
do { \
foreach (file_locks; PATH; LOCKS) {CODE;} \
foreach (prefix_locks; PATH; LOCKS) {CODE;} \
} while (0)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
47fa21 | 2004-05-03 | Martin Stjernholm | | multiset(DAVLock) find_locks(string path,
int(0..1) recursive,
int(0..1) exclude_shared,
RequestID id)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
if (!sizeof(file_locks) && !sizeof(prefix_locks)) return 0;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | TRACE_ENTER(sprintf("find_locks(%O, %O, %O, X)",
path, recursive, exclude_shared), this);
|
87c772 | 2004-05-14 | Martin Stjernholm | | string rsc = resource_id (path, id);
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | multiset(DAVLock) locks = (<>);
|
0ddcae | 2004-05-04 | Martin Stjernholm | | function(mapping(mixed:DAVLock):void) add_locks;
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
if (exclude_shared) {
|
de070f | 2004-05-04 | Martin Stjernholm | | mixed auth_user = authenticated_user_id (path, id);
|
0ddcae | 2004-05-04 | Martin Stjernholm | | add_locks = lambda (mapping(mixed:DAVLock) sub_locks) {
|
47fa21 | 2004-05-03 | Martin Stjernholm | | foreach (sub_locks; string user; DAVLock lock)
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | if (user == auth_user ||
lock->lockscope == "DAV:exclusive")
|
47fa21 | 2004-05-03 | Martin Stjernholm | | locks[lock] = 1;
};
}
else
|
0ddcae | 2004-05-04 | Martin Stjernholm | | add_locks = lambda (mapping(mixed:DAVLock) sub_locks) {
|
47fa21 | 2004-05-03 | Martin Stjernholm | | locks |= mkmultiset (values (sub_locks));
};
|
87c772 | 2004-05-14 | Martin Stjernholm | | if (file_locks[rsc]) {
add_locks (file_locks[rsc]);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | foreach(prefix_locks;
|
0ddcae | 2004-05-04 | Martin Stjernholm | | string prefix; mapping(mixed:DAVLock) sub_locks) {
|
87c772 | 2004-05-14 | Martin Stjernholm | | if (has_prefix(rsc, prefix)) {
|
47fa21 | 2004-05-03 | Martin Stjernholm | | add_locks (sub_locks);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | break;
}
}
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (recursive) {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | LOOP_OVER_BOTH (string prefix, mapping(mixed:DAVLock) sub_locks, {
|
87c772 | 2004-05-14 | Martin Stjernholm | | if (has_prefix(prefix, rsc)) {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | add_locks (sub_locks);
}
});
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
a1f011 | 2004-05-04 | Henrik Grubbström (Grubba) | | add_locks = 0;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | TRACE_LEAVE(sprintf("Done, found %d locks.", sizeof(locks)));
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | return sizeof(locks) && locks;
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | DAVLock|LockFlag check_locks(string path,
int(0..1) recursive,
RequestID id)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | TRACE_ENTER(sprintf("check_locks(%O, %d, X)", path, recursive), this);
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
if (!sizeof(file_locks) && !sizeof(prefix_locks)) {
TRACE_LEAVE ("Got no locks");
return 0;
}
|
de070f | 2004-05-04 | Martin Stjernholm | | mixed auth_user = authenticated_user_id (path, id);
|
87c772 | 2004-05-14 | Martin Stjernholm | | path = resource_id (path, id);
|
490832 | 2004-04-29 | Martin Stjernholm | |
if (DAVLock lock =
file_locks[path] && file_locks[path][auth_user] ||
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | prefix_locks[path] && prefix_locks[path][auth_user]) {
|
abefea | 2004-05-17 | Martin Stjernholm | | TRACE_LEAVE(sprintf("Found own lock %O.", lock->locktoken));
|
490832 | 2004-04-29 | Martin Stjernholm | | return lock;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
LockFlag shared;
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | | if (mapping(mixed:DAVLock) locks = file_locks[path]) {
|
490832 | 2004-04-29 | Martin Stjernholm | | foreach(locks;; DAVLock lock) {
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | if (lock->lockscope == "DAV:exclusive") {
TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.",
lock->locktoken));
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | return LOCK_EXCL_AT;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | shared = LOCK_SHARED_AT;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | break;
}
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
foreach(prefix_locks;
|
0ddcae | 2004-05-04 | Martin Stjernholm | | string prefix; mapping(mixed:DAVLock) locks) {
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (has_prefix(path, prefix)) {
|
abefea | 2004-05-17 | Martin Stjernholm | | if (DAVLock lock = locks[auth_user]) {
SIMPLE_TRACE_LEAVE ("Found own lock %O on %O.", lock->locktoken, prefix);
return lock;
}
|
490832 | 2004-04-29 | Martin Stjernholm | | if (!shared)
|
0ddcae | 2004-05-04 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | | foreach(locks;; DAVLock lock) {
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | if (lock->lockscope == "DAV:exclusive") {
TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.",
lock->locktoken));
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | return LOCK_EXCL_AT;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | shared = LOCK_SHARED_AT;
|
490832 | 2004-04-29 | Martin Stjernholm | | break;
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | if (!recursive) {
|
aa30fc | 2004-05-14 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE("Returning %O.", shared);
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | return shared;
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | | int(0..1) locked_by_auth_user;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
0ddcae | 2004-05-04 | Martin Stjernholm | | LOOP_OVER_BOTH (string prefix, mapping(mixed:DAVLock) locks, {
if (has_prefix(prefix, path)) {
if (locks[auth_user])
locked_by_auth_user = 1;
else
foreach(locks;; DAVLock lock) {
if (lock->lockscope == "DAV:exclusive") {
TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.",
lock->locktoken));
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | return LOCK_EXCL_BELOW;
|
0ddcae | 2004-05-04 | Martin Stjernholm | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | if (!shared) shared = LOCK_SHARED_BELOW;
|
0ddcae | 2004-05-04 | Martin Stjernholm | | break;
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | }
|
0ddcae | 2004-05-04 | Martin Stjernholm | | }
});
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE("Returning %O.", locked_by_auth_user ? LOCK_OWN_BELOW : shared);
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | return locked_by_auth_user ? LOCK_OWN_BELOW : shared;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
static void register_lock(string path, DAVLock lock, RequestID id)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
|
51c8d1 | 2004-05-05 | Martin Stjernholm | | TRACE_ENTER(sprintf("register_lock(%O, lock(%O), X).", path, lock->locktoken),
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | this);
|
51c8d1 | 2004-05-05 | Martin Stjernholm | | ASSERT_IF_DEBUG (lock->locktype == "DAV:write");
|
de070f | 2004-05-04 | Martin Stjernholm | | mixed auth_user = authenticated_user_id (path, id);
|
87c772 | 2004-05-14 | Martin Stjernholm | | path = resource_id (path, id);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (lock->recursive) {
if (prefix_locks[path]) {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | prefix_locks[path][auth_user] = lock;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | } else {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | prefix_locks[path] = ([ auth_user:lock ]);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
} else {
if (file_locks[path]) {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | file_locks[path][auth_user] = lock;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | } else {
|
0ddcae | 2004-05-04 | Martin Stjernholm | | file_locks[path] = ([ auth_user:lock ]);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
|
090cdd | 2004-05-04 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Ok.");
|
51c8d1 | 2004-05-05 | Martin Stjernholm | | }
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | |
static void unregister_lock (string path, DAVLock lock, RequestID|int(0..0) id)
|
aa30fc | 2004-05-14 | Martin Stjernholm | | {
TRACE_ENTER(sprintf("unregister_lock(%O, lock(%O), X).", path, lock->locktoken),
this);
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | | mixed auth_user = id && authenticated_user_id (path, id);
|
aa30fc | 2004-05-14 | Martin Stjernholm | | path = resource_id (path, id);
DAVLock removed_lock;
if (lock->recursive) {
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | | if (id) {
removed_lock = m_delete(prefix_locks[path], auth_user);
} else {
foreach(prefix_locks[path]; mixed user; DAVLock l) {
if (l == lock) {
removed_lock = m_delete(prefix_locks[path], user);
}
}
}
|
aa30fc | 2004-05-14 | Martin Stjernholm | | if (!sizeof (prefix_locks[path])) m_delete (prefix_locks, path);
}
else if (file_locks[path]) {
|
864980 | 2004-05-15 | Henrik Grubbström (Grubba) | | if (id) {
removed_lock = m_delete (file_locks[path], auth_user);
} else {
foreach(file_locks[path]; mixed user; DAVLock l) {
if (l == lock) {
removed_lock = m_delete(file_locks[path], user);
}
}
}
|
aa30fc | 2004-05-14 | Martin Stjernholm | | if (!sizeof (file_locks[path])) m_delete (file_locks, path);
}
ASSERT_IF_DEBUG (lock == removed_lock , lock, removed_lock);
TRACE_LEAVE("Ok.");
return 0;
}
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | | mapping(string:mixed) lock_file(string path,
DAVLock lock,
RequestID id)
{
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | return 0;
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | | mapping(string:mixed) unlock_file (string path,
DAVLock lock,
|
aa30fc | 2004-05-14 | Martin Stjernholm | | RequestID|int(0..0) id);
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
28c81a | 2004-05-12 | Martin Stjernholm | |
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
93686e | 2004-05-07 | Martin Stjernholm | |
|
28c81a | 2004-05-12 | Martin Stjernholm | | mapping(string:mixed)|int(0..1) check_if_header(string relative_path,
int(0..1) recursive,
RequestID id)
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | {
|
28c81a | 2004-05-12 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(this, "Checking \"If\" header for %O",
relative_path);
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | |
|
d914dd | 2004-05-10 | Henrik Grubbström (Grubba) | | int|DAVLock lock = check_locks(relative_path, recursive, id);
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | |
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | int(0..1) got_sublocks;
|
93686e | 2004-05-07 | Martin Stjernholm | | if (lock && intp(lock)) {
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | if (lock & 1) {
TRACE_LEAVE("Locked by other user.");
return Roxen.http_status(Protocols.HTTP.DAV_LOCKED);
}
|
93686e | 2004-05-07 | Martin Stjernholm | | else if (recursive)
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | got_sublocks = 1;
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | | }
|
51c8d1 | 2004-05-05 | Martin Stjernholm | |
|
d914dd | 2004-05-10 | Henrik Grubbström (Grubba) | | string path = relative_path;
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | if (!has_suffix (path, "/")) path += "/";
|
51c8d1 | 2004-05-05 | Martin Stjernholm | | path = query_location() + path;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | |
mapping(string:array(array(array(string)))) if_data = id->get_if_data();
array(array(array(string))) condition;
if (!if_data || !sizeof(condition = if_data[path] || if_data[0])) {
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | | if (lock) {
TRACE_LEAVE("Locked, no if header.");
return Roxen.http_status(Protocols.HTTP.DAV_LOCKED);
}
|
93686e | 2004-05-07 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE("No lock and no if header - ok%s.",
got_sublocks ? " (this level only)" : "");
|
c6ce73 | 2004-05-07 | Martin Stjernholm | | return got_sublocks;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
d914dd | 2004-05-10 | Henrik Grubbström (Grubba) | | string|int(-1..0) etag;
|
09006d | 2004-05-17 | Martin Stjernholm | | int(0..1) locked_fail = !!lock;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | next_condition:
foreach(condition, array(array(string)) sub_cond) {
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_ENTER(this,
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | "Trying condition ( %{%s:%O %})...", sub_cond);
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | int negate;
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | DAVLock locked = lock;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | foreach(sub_cond, array(string) token) {
switch(token[0]) {
case "not":
negate = !negate;
break;
case "etag":
|
d914dd | 2004-05-10 | Henrik Grubbström (Grubba) | | if (!etag) {
if (!stringp(etag = query_property(relative_path,
"DAV:getetag", id))) {
etag = -1;
}
}
if (etag != token[1]) {
if (!negate) {
TRACE_LEAVE("Etag mismatch.");
continue next_condition;
}
} else if (negate) {
TRACE_LEAVE("Matched negated etag.");
continue next_condition;
}
negate = 0;
break;
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | case "key":
|
e66d2a | 2004-05-10 | Henrik Grubbström (Grubba) | |
|
09006d | 2004-05-17 | Martin Stjernholm | | locked_fail = 0;
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | if (negate) {
if (lock && lock->locktoken == token[1]) {
TRACE_LEAVE("Matched negated lock.");
continue next_condition;
}
} else if (!lock || lock->locktoken != token[1]) {
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | |
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Lock mismatch.");
|
8668a8 | 2004-05-05 | Henrik Grubbström (Grubba) | | continue next_condition;
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | } else {
locked = 0;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | }
negate = 0;
break;
}
}
|
27e1b4 | 2004-05-07 | Henrik Grubbström (Grubba) | | if (!locked) {
TRACE_LEAVE("Found match.");
SIMPLE_TRACE_LEAVE("Ok%s.",
got_sublocks ? " (this level only)" : "");
return got_sublocks;
}
SIMPLE_TRACE_LEAVE("Conditional ok, but still locked (locktoken: %O).",
lock->locktoken);
|
09006d | 2004-05-17 | Martin Stjernholm | | locked_fail = 1;
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | }
|
c6ce73 | 2004-05-07 | Martin Stjernholm | |
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Failed.");
|
09006d | 2004-05-17 | Martin Stjernholm | | return Roxen.http_status(locked_fail ?
Protocols.HTTP.DAV_LOCKED :
Protocols.HTTP.HTTP_PRECOND_FAILED);
|
daf03e | 2004-05-05 | Henrik Grubbström (Grubba) | | }
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
28c81a | 2004-05-12 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
28c81a | 2004-05-12 | Martin Stjernholm | |
static mapping(string:mixed)|int(0..1) write_access(string relative_path,
int(0..1) recursive,
RequestID id)
{
return check_if_header (relative_path, recursive, id);
}
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | mapping(string:mixed)|int(-1..0)|Stdio.File find_file(string path,
RequestID id);
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
08666d | 2004-05-12 | Martin Stjernholm | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | |
|
740610 | 2004-05-13 | Martin Stjernholm | | static mapping(string:mixed) delete_file(string path, RequestID id)
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | {
|
2ece72 | 2004-05-06 | Henrik Grubbström (Grubba) | | RequestID tmp_id = id->clone_me();
|
d35dfd | 2004-04-20 | Martin Stjernholm | | tmp_id->not_query = query_location() + path;
|
2ece72 | 2004-05-06 | Henrik Grubbström (Grubba) | | tmp_id->method = "DELETE";
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | |
|
d5c319 | 2004-05-10 | Henrik Grubbström (Grubba) | | return find_file(path, tmp_id) ||
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | tmp_id->misc->error_code && Roxen.http_status (tmp_id->misc->error_code);
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | }
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | |
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
|
1642dc | 2004-05-07 | Henrik Grubbström (Grubba) | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
0dbbfd | 2004-05-10 | Henrik Grubbström (Grubba) | | mapping(string:mixed) recurse_delete_files(string path,
|
113fa1 | 2004-05-10 | Martin Stjernholm | | RequestID id,
void|MultiStatus.Prefixed stat)
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | {
|
08666d | 2004-05-12 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Deleting %O recursively", path);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | if (!stat)
|
70f385 | 2004-05-13 | Henrik Grubbström (Grubba) | | stat = id->get_multi_status()->prefix (id->url_base() +
query_location()[1..]);
|
113fa1 | 2004-05-10 | Martin Stjernholm | |
|
08666d | 2004-05-12 | Martin Stjernholm | | Stat st = stat_file(path, id);
if (!st) {
SIMPLE_TRACE_LEAVE ("No such file or directory");
return 0;
}
mapping(string:mixed) recurse (string path, Stat st)
|
113fa1 | 2004-05-10 | Martin Stjernholm | | {
|
08666d | 2004-05-12 | Martin Stjernholm | |
|
113fa1 | 2004-05-10 | Martin Stjernholm | | if (st->isdir) {
|
0dbbfd | 2004-05-10 | Henrik Grubbström (Grubba) | |
|
113fa1 | 2004-05-10 | Martin Stjernholm | |
int fail;
if (!has_suffix(path, "/")) path += "/";
foreach(find_dir(path, id) || ({}), string fname) {
|
08666d | 2004-05-12 | Martin Stjernholm | | fname = path + fname;
if (Stat sub_stat = stat_file (fname, id)) {
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Deleting %O", fname);
|
d17487 | 2004-05-12 | Martin Stjernholm | | if (mapping(string:mixed) sub_res = recurse(fname, sub_stat)) {
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | if (sizeof (sub_res) && sub_res->error != 204) {
|
d17487 | 2004-05-12 | Martin Stjernholm | | stat->add_status(fname, sub_res->error, sub_res->rettext);
}
|
4ba29a | 2004-05-13 | Martin Stjernholm | | if (!sizeof (sub_res) || sub_res->error >= 300) fail = 1;
|
08666d | 2004-05-12 | Martin Stjernholm | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
|
0dbbfd | 2004-05-10 | Henrik Grubbström (Grubba) | | }
|
08666d | 2004-05-12 | Martin Stjernholm | | if (fail) {
SIMPLE_TRACE_LEAVE ("Partial failure");
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | return ([]);
|
08666d | 2004-05-12 | Martin Stjernholm | | }
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | }
|
08666d | 2004-05-12 | Martin Stjernholm | |
SIMPLE_TRACE_LEAVE ("");
|
900184 | 2004-05-12 | Martin Stjernholm | | return delete_file (path, id);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | };
|
900184 | 2004-05-12 | Martin Stjernholm | | return recurse(path, st) || Roxen.http_status(204);
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | }
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed) make_collection(string path, RequestID id)
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | {
RequestID tmp_id = id->clone_me();
tmp_id->not_query = query_location() + path;
tmp_id->method = "MKCOL";
|
689b41 | 2004-05-10 | Martin Stjernholm | | return find_file(path, tmp_id);
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
|
345234 | 2004-05-13 | Martin Stjernholm | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
aa30fc | 2004-05-14 | Martin Stjernholm | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
345234 | 2004-05-13 | Martin Stjernholm | | static mapping(string:mixed) copy_properties(string source, string destination,
PropertyBehavior behavior, RequestID id)
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | {
SIMPLE_TRACE_ENTER(this, "copy_properties(%O, %O, %O, %O)",
source, destination, behavior, id);
|
ac173b | 2004-05-10 | Martin Stjernholm | | PropertySet source_properties = query_property_set(source, id);
PropertySet destination_properties = query_property_set(destination, id);
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | |
multiset(string) property_set = source_properties->query_all_properties();
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed) res;
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | foreach(property_set; string property_name;) {
SIMPLE_TRACE_ENTER(this, "Copying the property %O.", property_name);
string|array(Parser.XML.Tree.SimpleNode)|mapping(string:mixed) source_val =
source_properties->query_property(property_name);
if (mappingp(source_val)) {
TRACE_LEAVE("Reading of property failed. Skipped.");
continue;
}
string|array(Parser.XML.Tree.SimpleNode)|mapping(string:mixed) dest_val =
destination_properties->query_property(property_name);
if (dest_val == source_val) {
TRACE_LEAVE("Destination already has the correct value.");
continue;
}
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed) subres =
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | destination_properties->set_property(property_name, source_val);
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | if (!behavior) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Omit verify.");
continue;
}
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | if ((intp(behavior) || behavior[property_name]) && (subres->error < 300)) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | |
}
|
ac173b | 2004-05-10 | Martin Stjernholm | | if ((subres->error < 300) ||
(subres->error == Protocols.HTTP.HTTP_CONFLICT)) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | |
TRACE_LEAVE("Copy ok or read-only property.");
continue;
}
|
ac173b | 2004-05-10 | Martin Stjernholm | | if (!subres) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | |
res = Roxen.http_status(Protocols.HTTP.HTTP_PRECOND_FAILED);
}
TRACE_LEAVE("Copy failed.");
}
TRACE_LEAVE(res?"Failed.":"Ok.");
return res;
}
|
4ba29a | 2004-05-13 | Martin Stjernholm | |
|
113fa1 | 2004-05-10 | Martin Stjernholm | | static mapping(string:mixed) copy_collection(string source,
string destination,
PropertyBehavior behavior,
Overwrite overwrite,
MultiStatus.Prefixed result,
RequestID id)
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_ENTER(this, "copy_collection(%O, %O, %O, %O, %O, %O).",
source, destination, behavior, overwrite, result, id);
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | Stat st = stat_file(destination, id);
if (st) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | switch(overwrite) {
case DO_OVERWRITE:
TRACE_ENTER("Destination exists and overwrite is on.", this);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed) res = recurse_delete_files(destination, id, result);
|
e9ca9f | 2004-05-12 | Martin Stjernholm | | if (res && (!sizeof (res) || res->error >= 300)) {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | |
TRACE_LEAVE("Deletion failed.");
TRACE_LEAVE("Copy collection failed.");
|
e9ca9f | 2004-05-12 | Martin Stjernholm | |
#if 0
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | return Roxen.http_status(Protocols.HTTP.HTTP_PRECOND_FAILED);
|
e9ca9f | 2004-05-12 | Martin Stjernholm | | #else
if (sizeof (res)) {
|
7fe7b0 | 2004-05-12 | Martin Stjernholm | | result->add_status (destination, res->error, res->rettext);
|
e9ca9f | 2004-05-12 | Martin Stjernholm | | }
return ([]);
#endif
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Deletion ok.");
break;
case NEVER_OVERWRITE:
TRACE_LEAVE("Destination already exists.");
return Roxen.http_status(Protocols.HTTP.HTTP_PRECOND_FAILED);
case MAYBE_OVERWRITE:
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | |
if (st->isdir) {
TRACE_LEAVE("Destination exists and is a directory.");
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | return copy_properties(source, destination, behavior, id);
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
TRACE_LEAVE("Destination exists and is not a directory.");
return Roxen.http_status(Protocols.HTTP.HTTP_PRECOND_FAILED);
}
}
TRACE_LEAVE("Make a new collection.");
|
ac173b | 2004-05-10 | Martin Stjernholm | | mapping(string:mixed) res = make_collection(destination, id);
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | if (res && res->error >= 300) return res;
return copy_properties(source, destination, behavior, id) || res;
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
|
740610 | 2004-05-13 | Martin Stjernholm | |
static mapping(string:mixed) copy_file(string source, string destination,
PropertyBehavior behavior,
Overwrite overwrite, RequestID id)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
5da76f | 2004-05-10 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_ENTER(this, "copy_file(%O, %O, %O, %O, %O)\n",
|
113fa1 | 2004-05-10 | Martin Stjernholm | | source, destination, behavior, overwrite, id);
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | TRACE_LEAVE("Not implemented.");
|
762b93 | 2004-03-03 | Martin Stjernholm | | return Roxen.http_status (Protocols.HTTP.HTTP_NOT_IMPL);
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | }
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
mapping(string:mixed) recurse_copy_files(string source, string destination,
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | PropertyBehavior behavior,
|
113fa1 | 2004-05-10 | Martin Stjernholm | | Overwrite overwrite, RequestID id)
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | {
|
740610 | 2004-05-13 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(this, "Recursive copy from %O to %O (%s)",
source, destination,
overwrite == DO_OVERWRITE ? "replace" :
overwrite == NEVER_OVERWRITE ? "no overwrite" :
"overlay");
|
e66d2a | 2004-05-10 | Henrik Grubbström (Grubba) | | string src_tmp = has_suffix(source, "/")?source:(source+"/");
string dst_tmp = has_suffix(destination, "/")?destination:(destination+"/");
if ((src_tmp == dst_tmp) ||
has_prefix(src_tmp, dst_tmp) ||
has_prefix(dst_tmp, src_tmp)) {
|
a9f4fc | 2004-05-10 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Source and destination overlap.");
return Roxen.http_status(403, "Source and destination overlap.");
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | |
string loc = query_location();
MultiStatus.Prefixed result =
id->get_multi_status()->prefix (id->url_base() + loc[1..]);
|
740610 | 2004-05-13 | Martin Stjernholm | | mapping(string:mixed) recurse(string source, string destination) {
|
113fa1 | 2004-05-10 | Martin Stjernholm | |
Stat st = stat_file(source, id);
if (!st) {
TRACE_LEAVE("Source not found.");
|
740610 | 2004-05-13 | Martin Stjernholm | | return 0;
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
if (st->isdir) {
mapping(string:mixed) res =
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | copy_collection(source, destination, behavior, overwrite, result, id);
|
4ba29a | 2004-05-13 | Martin Stjernholm | | if (res && (!sizeof (res) || res->error >= 300)) {
|
0c5a85 | 2004-05-12 | Martin Stjernholm | |
TRACE_LEAVE("Copy of collection failed.");
return res;
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
foreach(find_dir(source, id), string filename) {
string subsrc = combine_path_unix(source, filename);
string subdst = combine_path_unix(destination, filename);
|
740610 | 2004-05-13 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(this, "Copy from %O to %O\n", subsrc, subdst);
mapping(string:mixed) sub_res = recurse(subsrc, subdst);
if (sub_res && !(<0, 201, 204>)[sub_res->error]) {
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | result->add_status(subdst, sub_res->error, sub_res->rettext);
|
113fa1 | 2004-05-10 | Martin Stjernholm | | }
|
235118 | 2004-05-08 | Henrik Grubbström (Grubba) | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | | TRACE_LEAVE("");
return res;
} else {
TRACE_LEAVE("");
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | return copy_file(source, destination, behavior, overwrite, id);
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | }
|
113fa1 | 2004-05-10 | Martin Stjernholm | | };
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | int start_ms_size = id->multi_status_size();
|
740610 | 2004-05-13 | Martin Stjernholm | | mapping(string:mixed) res = recurse (source, destination);
|
0c5a85 | 2004-05-12 | Martin Stjernholm | | if (res && res->error != 204 && res->error != 201)
return res;
else if (id->multi_status_size() != start_ms_size)
return ([]);
else
return res;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
4ba29a | 2004-05-13 | Martin Stjernholm | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | static mapping(string:mixed) move_file(string source, string destination,
PropertyBehavior behavior,
Overwrite overwrite, RequestID id)
{
RequestID tmp_id = id->clone_me();
tmp_id->not_query = query_location() + source;
tmp_id->misc["new-uri"] = query_location() + destination;
tmp_id->request_headers->destination =
id->url_base() + query_location()[1..] + destination;
tmp_id->method = "MOVE";
mapping(string:mixed) res = find_file(source, tmp_id);
if (!res || res->error != 501) return res;
res = copy_file(source, destination, behavior, overwrite, id);
if (res && res->error >= 300) {
return res;
}
return delete_file(source, id);
}
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
4ba29a | 2004-05-13 | Martin Stjernholm | |
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | static mapping(string:mixed) move_collection(string source, string destination,
PropertyBehavior behavior,
Overwrite overwrite, RequestID id)
{
RequestID tmp_id = id->clone_me();
tmp_id->not_query = query_location() + source;
tmp_id->misc["new-uri"] = query_location() + destination;
tmp_id->request_headers->destination =
id->url_base() + query_location()[1..] + destination;
tmp_id->method = "MOVE";
mapping(string:mixed) res = find_file(source, tmp_id);
if (!res || res->error != 501) return res;
MultiStatus.Prefixed result =
id->get_multi_status()->prefix (id->url_base() + query_location()[1..]);
res = copy_collection(source, destination, behavior, overwrite, result, id);
if (res && (res->error >= 300 || !sizeof(res))) {
return res;
}
int fail;
foreach(find_dir(source, id), string filename) {
string subsrc = combine_path_unix(source, filename);
string subdst = combine_path_unix(destination, filename);
SIMPLE_TRACE_ENTER(this, "Recursive move from %O to %O\n",
subsrc, subdst);
|
4ba29a | 2004-05-13 | Martin Stjernholm | | if (mapping(string:mixed) sub_res =
recurse_move_files(subsrc, subdst, behavior, overwrite, id)) {
if (!(<0, 201, 204>)[sub_res->error]) {
result->add_status(subdst, sub_res->error, sub_res->rettext);
}
if (!sizeof (sub_res) || sub_res->error >= 300) {
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | |
fail = 1;
}
|
4ba29a | 2004-05-13 | Martin Stjernholm | | }
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | }
if (fail) return ([]);
return delete_file(source, id);
}
|
740610 | 2004-05-13 | Martin Stjernholm | |
|
7d1c8e | 2004-05-13 | Henrik Grubbström (Grubba) | | mapping(string:mixed) recurse_move_files(string source, string destination,
PropertyBehavior behavior,
Overwrite overwrite, RequestID id)
|
ba42f4 | 2004-05-13 | Henrik Grubbström (Grubba) | | {
Stat st = stat_file(source, id);
if (!st) return 0;
if (st->isdir) {
return move_collection(source, destination, behavior, overwrite, id);
}
return move_file(source, destination, behavior, overwrite, id);
}
|
8b8ecf | 2000-08-28 | Johan Sundström | | string real_file(string f, RequestID id){}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
4f4bc1 | 1998-02-04 | Per Hedbor | | void add_api_function( string name, function f, void|array(string) types)
{
_api_functions[name] = ({ f, types });
}
mapping api_functions()
{
return _api_functions;
}
|
60b81c | 2001-01-04 | Martin Nilsson | | #if ROXEN_COMPAT <= 1.4
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:function) query_tag_callers()
|
facee7 | 2000-07-18 | Johan Sundström | |
|
48ca16 | 1999-05-18 | Per Hedbor | | {
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:function) m = ([]);
|
48ca16 | 1999-05-18 | Per Hedbor | | foreach(glob("tag_*", indices( this_object())), string q)
if(functionp( this_object()[q] ))
m[replace(q[4..], "_", "-")] = this_object()[q];
return m;
}
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:function) query_container_callers()
|
48ca16 | 1999-05-18 | Per Hedbor | | {
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:function) m = ([]);
|
48ca16 | 1999-05-18 | Per Hedbor | | foreach(glob("container_*", indices( this_object())), string q)
if(functionp( this_object()[q] ))
m[replace(q[10..], "_", "-")] = this_object()[q];
return m;
}
|
60b81c | 2001-01-04 | Martin Nilsson | | #endif
|
48ca16 | 1999-05-18 | Per Hedbor | |
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:array(int|function)) query_simpletag_callers()
|
7d2a5d | 2000-01-31 | Martin Nilsson | | {
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:array(int|function)) m = ([]);
|
7d2a5d | 2000-01-31 | Martin Nilsson | | foreach(glob("simpletag_*", indices(this_object())), string q)
if(functionp(this_object()[q]))
|
d6b20a | 2000-02-08 | Martin Stjernholm | | m[replace(q[10..],"_","-")] =
({ intp (this_object()[q + "_flags"]) && this_object()[q + "_flags"],
this_object()[q] });
|
7d2a5d | 2000-01-31 | Martin Nilsson | | return m;
|
48ca16 | 1999-05-18 | Per Hedbor | | }
|
ea062e | 1999-11-21 | Martin Nilsson | |
|
9ed3ea | 2000-08-06 | Martin Stjernholm | | mapping(string:array(int|function)) query_simple_pi_tag_callers()
{
mapping(string:array(int|function)) m = ([]);
foreach (glob ("simple_pi_tag_*", indices (this_object())), string q)
if (functionp (this_object()[q]))
m[replace (q[sizeof ("simple_pi_tag_")..], "_", "-")] =
({(intp (this_object()[q + "_flags"]) && this_object()[q + "_flags"]) |
RXML.FLAG_PROC_INSTR, this_object()[q]});
return m;
}
|
1b2b75 | 2000-01-07 | Martin Stjernholm | | RXML.TagSet query_tag_set()
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | {
|
395e46 | 2000-01-18 | Martin Stjernholm | | if (!module_tag_set) {
array(function|program|object) tags =
filter (rows (this_object(),
glob ("Tag*", indices (this_object()))),
|
d6b0f8 | 2003-01-15 | Henrik Grubbström (Grubba) | | lambda(mixed x) { return functionp(x)||programp(x); });
|
395e46 | 2000-01-18 | Martin Stjernholm | | for (int i = 0; i < sizeof (tags); i++)
if (programp (tags[i]))
if (!tags[i]->is_RXML_Tag) tags[i] = 0;
else tags[i] = tags[i]();
else {
tags[i] = tags[i]();
if (!tags[i]->is_RXML_Tag) tags[i] = 0;
}
tags -= ({0});
module_tag_set =
|
dd9a41 | 2001-08-24 | Martin Stjernholm | | (this_object()->ModuleTagSet || RXML.TagSet) (this_object(), "", tags);
|
395e46 | 2000-01-18 | Martin Stjernholm | | }
return module_tag_set;
|
b9ec25 | 2000-01-05 | Martin Stjernholm | | }
|
12e79e | 1999-12-07 | Martin Nilsson | | mixed get_value_from_file(string path, string index, void|string pre)
|
ea062e | 1999-11-21 | Martin Nilsson | | {
|
7fb7f5 | 1999-11-29 | Per Hedbor | | Stdio.File file=Stdio.File();
|
ea062e | 1999-11-21 | Martin Nilsson | | if(!file->open(path,"r")) return 0;
|
e4baad | 2003-08-07 | Jonas Wallden | | if(has_suffix(index, "()"))
index = index[..sizeof(index) - 3];
return compile_string((pre || "") + file->read(), path)[index];
|
ea062e | 1999-11-21 | Martin Nilsson | | }
|
a730c2 | 2001-01-19 | Per Hedbor | |
|
2be198 | 2001-08-01 | Per Hedbor | | static private mapping __my_tables = ([]);
|
246612 | 2001-08-01 | Per Hedbor | | array(mapping(string:mixed)) sql_query( string query, mixed ... args )
|
2be198 | 2001-08-01 | Per Hedbor | |
{
return get_my_sql()->query( replace( query, __my_tables ), @args );
}
|
246612 | 2001-08-01 | Per Hedbor | | object sql_big_query( string query, mixed ... args )
|
2be198 | 2001-08-01 | Per Hedbor | |
{
return get_my_sql()->big_query( replace( query, __my_tables ), @args );
}
|
246612 | 2001-08-01 | Per Hedbor | | array(mapping(string:mixed)) sql_query_ro( string query, mixed ... args )
{
return get_my_sql(1)->query( replace( query, __my_tables ), @args );
}
object sql_big_query_ro( string query, mixed ... args )
{
return get_my_sql(1)->big_query( replace( query, __my_tables ), @args );
}
|
6d22f9 | 2003-04-23 | Martin Stjernholm | | static int create_sql_tables( mapping(string:array(string)) definitions,
|
3a7e56 | 2001-08-23 | Per Hedbor | | string|void comment,
int|void no_unique_names )
|
2be198 | 2001-08-01 | Per Hedbor | |
|
3a7e56 | 2001-08-23 | Per Hedbor | |
|
2be198 | 2001-08-01 | Per Hedbor | | {
|
3a7e56 | 2001-08-23 | Per Hedbor | | int ddc;
|
59ccd8 | 2001-08-14 | Per Hedbor | | if( !no_unique_names )
|
6d22f9 | 2003-04-23 | Martin Stjernholm | | foreach( indices( definitions ), string t )
ddc+=get_my_table( t, definitions[t], comment, 1 );
|
59ccd8 | 2001-08-14 | Per Hedbor | | else
{
Sql.Sql sql = get_my_sql();
|
6d22f9 | 2003-04-23 | Martin Stjernholm | | foreach( indices( definitions ), string t )
|
59ccd8 | 2001-08-14 | Per Hedbor | | {
|
3a7e56 | 2001-08-23 | Per Hedbor | | if( !catch {
|
6d22f9 | 2003-04-23 | Martin Stjernholm | | sql->query("CREATE TABLE "+t+" ("+definitions[t]*","+")" );
|
3a7e56 | 2001-08-23 | Per Hedbor | | } )
ddc++;
|
59ccd8 | 2001-08-14 | Per Hedbor | | DBManager.is_module_table( this_object(), my_db, t, comment );
}
}
|
3a7e56 | 2001-08-23 | Per Hedbor | | return ddc;
|
2be198 | 2001-08-01 | Per Hedbor | | }
|
246612 | 2001-08-01 | Per Hedbor | | static string sql_table_exists( string name )
|
298be1 | 2001-08-13 | Per Hedbor | |
|
246612 | 2001-08-01 | Per Hedbor | | {
if(strlen(name))
name = "_"+name;
string res = hash(_my_configuration->name)->digits(36)
+ "_" + replace(sname(),"#","_") + name;
|
8214e6 | 2001-08-01 | Per Hedbor | | return catch(get_my_sql()->query( "SELECT * FROM "+res+" LIMIT 1" ))?0:res;
|
246612 | 2001-08-01 | Per Hedbor | | }
|
3a7e56 | 2001-08-23 | Per Hedbor | | static string|int get_my_table( string|array(string) name,
|
c76ebd | 2004-03-23 | Martin Stjernholm | | void|array(string)|string definition,
|
3a7e56 | 2001-08-23 | Per Hedbor | | string|void comment,
int|void flag )
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
2be198 | 2001-08-01 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
3a7e56 | 2001-08-23 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
6d22f9 | 2003-04-23 | Martin Stjernholm | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
3a7e56 | 2001-08-23 | Per Hedbor | |
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | | {
|
2be198 | 2001-08-01 | Per Hedbor | | string oname;
|
3a7e56 | 2001-08-23 | Per Hedbor | | int ddc;
|
c76ebd | 2004-03-23 | Martin Stjernholm | | if( !definition )
|
1e9a1b | 2001-02-21 | Per Hedbor | | {
|
c76ebd | 2004-03-23 | Martin Stjernholm | | definition = name;
|
2be198 | 2001-08-01 | Per Hedbor | | oname = name = "";
|
1e9a1b | 2001-02-21 | Per Hedbor | | }
else if(strlen(name))
|
2be198 | 2001-08-01 | Per Hedbor | | name = "_"+(oname = name);
|
a730c2 | 2001-01-19 | Per Hedbor | |
|
a66538 | 2001-01-29 | Per Hedbor | | Sql.Sql sql = get_my_sql();
|
246612 | 2001-08-01 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | | string res = hash(_my_configuration->name)->digits(36)
+ "_" + replace(sname(),"#","_") + name;
|
a66538 | 2001-01-29 | Per Hedbor | | if( !sql )
{
report_error("Failed to get SQL handle, permission denied for "+my_db+"\n");
return 0;
}
|
c76ebd | 2004-03-23 | Martin Stjernholm | | if( arrayp( definition ) )
definition *= ", ";
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
a66538 | 2001-01-29 | Per Hedbor | | if( catch(sql->query( "SELECT * FROM "+res+" LIMIT 1" )) )
|
1e9a1b | 2001-02-21 | Per Hedbor | | {
|
3a7e56 | 2001-08-23 | Per Hedbor | | ddc++;
|
1e9a1b | 2001-02-21 | Per Hedbor | | mixed error =
catch
{
|
c76ebd | 2004-03-23 | Martin Stjernholm | | get_my_sql()->query( "CREATE TABLE "+res+" ("+definition+")" );
|
298be1 | 2001-08-13 | Per Hedbor | | DBManager.is_module_table( this_object(), my_db, res,
oname+"\0"+comment );
|
1e9a1b | 2001-02-21 | Per Hedbor | | };
if( error )
{
if( strlen( name ) )
name = " "+name;
|
246612 | 2001-08-01 | Per Hedbor | | report_error( "Failed to create table"+name+": "+
describe_error( error ) );
|
1e9a1b | 2001-02-21 | Per Hedbor | | return 0;
}
|
3a7e56 | 2001-08-23 | Per Hedbor | | if( flag )
{
__my_tables[ "&"+oname+";" ] = res;
return ddc;
}
|
2be198 | 2001-08-01 | Per Hedbor | | return __my_tables[ "&"+oname+";" ] = res;
|
1e9a1b | 2001-02-21 | Per Hedbor | | }
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
c76ebd | 2004-03-23 | Martin Stjernholm | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
3a7e56 | 2001-08-23 | Per Hedbor | | if( flag )
{
__my_tables[ "&"+oname+";" ] = res;
return ddc;
}
|
2be198 | 2001-08-01 | Per Hedbor | | return __my_tables[ "&"+oname+";" ] = res;
|
a730c2 | 2001-01-19 | Per Hedbor | | }
|
e08221 | 2001-08-28 | Per Hedbor | | static string my_db = "local";
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
2be198 | 2001-08-01 | Per Hedbor | | static void set_my_db( string to )
|
1e9a1b | 2001-02-21 | Per Hedbor | |
{
my_db = to;
}
|
246612 | 2001-08-01 | Per Hedbor | | Sql.Sql get_my_sql( int|void read_only )
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
a730c2 | 2001-01-19 | Per Hedbor | | {
|
2be198 | 2001-08-01 | Per Hedbor | | return DBManager.cached_get( my_db, _my_configuration, read_only );
|
a730c2 | 2001-01-19 | Per Hedbor | | }
|