835c6c | 2001-06-17 | Martin Nilsson | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | |
|
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..]);
}
|
ae32d0 | 1998-03-23 | David Hedbor | |
|
72ac57 | 2000-01-31 | Per Hedbor | | 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 | | }
|
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;
static void create (string path, RequestID id, Stat stat)
{
::create (path, id);
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) | |
|
aecff1 | 2004-03-23 | Martin Stjernholm | | PropertySet|mapping(string:mixed) query_properties(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;
}
|
7c8387 | 2004-04-28 | Martin Stjernholm | | PropertySet res = DefaultPropertySet(path, id, st);
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("");
return res;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
string|array(Parser.XML.Tree.Node)|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) | | {
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_properties(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 | |
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | | void recurse_find_properties(string path, string mode,
int depth, MultiStatus result,
RequestID id,
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | multiset(string)|void filt)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
ca28e8 | 2004-03-23 | 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);
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_properties(path, id);
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | if (!properties) {
SIMPLE_TRACE_LEAVE ("No such file or dir");
return;
}
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | |
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | {
mapping(string:mixed) ret = mappingp (properties) ?
properties : properties->find_properties(mode, result, filt);
if (ret) {
result->add_response(path, XMLStatusNode(ret->error, ret->rettext));
if (ret->rettext) {
Parser.XML.Tree.ElementNode descr =
Parser.XML.Tree.ElementNode ("DAV:responsedescription", ([]));
descr->add_child (Parser.XML.Tree.TextNode (ret->rettext));
result->add_response (path, descr);
}
SIMPLE_TRACE_LEAVE ("Got status %d: %O", ret->error, ret->rettext);
return;
|
762b93 | 2004-03-03 | Martin Stjernholm | | }
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | | }
|
ca28e8 | 2004-03-23 | Martin Stjernholm | |
|
7c8387 | 2004-04-28 | Martin Stjernholm | | if (properties->get_stat()->isdir) {
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | if (depth <= 0) {
SIMPLE_TRACE_LEAVE ("Not recursing due to depth limit");
return;
}
depth--;
foreach(find_dir(path, id) || ({}), string filename) {
recurse_find_properties(combine_path(path, filename), mode, depth,
result, id, filt);
}
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
|
ca28e8 | 2004-03-23 | Martin Stjernholm | |
SIMPLE_TRACE_LEAVE ("");
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | | return;
|
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,
MultiStatus result, 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);
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_properties(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)) {
SIMPLE_TRACE_LEAVE ("Got error %d from query_properties: %O",
properties->error, properties->rettext);
return properties;
}
|
a98f75 | 2004-03-03 | Henrik Grubbström (Grubba) | |
|
c5dd9f | 2004-03-16 | Henrik Grubbström (Grubba) | | mapping(string:mixed) errcode = properties->start();
|
0cb4c4 | 2004-03-15 | Martin Stjernholm | |
|
ca28e8 | 2004-03-23 | Martin Stjernholm | | if (errcode) {
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 {
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 =
Roxen.http_status (Protocols.HTTP.DAV_FAILED_DEP, "Failed dependency.");
for(i = 0; i < sizeof(results); i++) {
if (!results[i] || results[i]->error < 300) {
result->add_property(path, instructions[i]->property_name,
answer);
} else {
result->add_property(path, instructions[i]->property_name,
results[i]);
}
}
properties->unroll();
} else {
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | int i;
for(i = 0; i < sizeof(results); i++) {
result->add_property(path, instructions[i]->property_name,
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,
string|array(Parser.XML.Tree.Node) value,
RequestID id)
|
25ceaf | 2004-03-01 | Martin Stjernholm | | {
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_properties(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 | | {
|
aecff1 | 2004-03-23 | Martin Stjernholm | | mapping(string:mixed)|PropertySet properties = query_properties(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 | | }
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | static mapping(string:mapping(string:DAVLock)) file_locks = ([]);
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | static mapping(string:mapping(string:DAVLock)) prefix_locks = ([]);
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
9a91eb | 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;
multiset(DAVLock) locks = (<>);
|
47fa21 | 2004-05-03 | Martin Stjernholm | | function(mapping(string:DAVLock):void) add_locks;
if (exclude_shared) {
User uid = id->conf->authenticate (id);
string auth_user = uid && uid->name();
add_locks = lambda (mapping(string:DAVLock) sub_locks) {
foreach (sub_locks; string user; DAVLock lock)
if (user == auth_user || lock->lockscope == "DAV:exclusive")
locks[lock] = 1;
};
}
else
add_locks = lambda (mapping(string:DAVLock) sub_locks) {
locks |= mkmultiset (values (sub_locks));
};
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (file_locks[path]) {
|
47fa21 | 2004-05-03 | Martin Stjernholm | | add_locks (file_locks[path]);
|
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;
string prefix; mapping(string:DAVLock) sub_locks) {
if (has_prefix(path, 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) {
foreach(file_locks|prefix_locks;
string prefix; mapping(string:DAVLock) sub_locks) {
if (has_prefix(prefix, path)) {
|
47fa21 | 2004-05-03 | Martin Stjernholm | | add_locks (sub_locks);
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
}
|
47fa21 | 2004-05-03 | Martin Stjernholm | |
|
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) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
9a91eb | 2004-05-04 | 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 | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | | DAVLock|int(0..3) check_locks(string path,
int(0..1) recursive,
RequestID id)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
if (!sizeof(file_locks) && !sizeof(prefix_locks)) return 0;
|
490832 | 2004-04-29 | Martin Stjernholm | | User uid = id->conf->authenticate (id);
string auth_user = uid && uid->name();
if (DAVLock lock =
file_locks[path] && file_locks[path][auth_user] ||
prefix_locks[path] && prefix_locks[path][auth_user])
return lock;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | int(0..1) shared;
|
490832 | 2004-04-29 | Martin Stjernholm | |
if (mapping(string:DAVLock) locks = file_locks[path]) {
foreach(locks;; DAVLock lock) {
|
9a91eb | 2004-05-04 | Martin Stjernholm | | if (lock->lockscope == "DAV:exclusive") return 3;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | shared = 1;
break;
}
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
foreach(prefix_locks;
string prefix; mapping(string:DAVLock) locks) {
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (has_prefix(path, prefix)) {
|
490832 | 2004-04-29 | Martin Stjernholm | | if (DAVLock lock = locks[auth_user]) return lock;
if (!shared)
foreach(locks;; DAVLock lock) {
|
9a91eb | 2004-05-04 | Martin Stjernholm | | if (lock->lockscope == "DAV:exclusive") return 3;
|
490832 | 2004-04-29 | Martin Stjernholm | | shared = 1;
break;
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
|
490832 | 2004-04-29 | Martin Stjernholm | | if (!recursive) 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) | |
|
490832 | 2004-04-29 | Martin Stjernholm | | foreach(file_locks|prefix_locks;
string prefix; mapping(string:DAVLock) locks) {
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (has_prefix(prefix, path)) {
|
490832 | 2004-04-29 | Martin Stjernholm | | if (locks[auth_user])
locked_by_auth_user = 1;
else
foreach(locks;; DAVLock lock) {
|
9a91eb | 2004-05-04 | Martin Stjernholm | | if (lock->lockscope == "DAV:exclusive") return 3;
|
490832 | 2004-04-29 | Martin Stjernholm | | shared = 1;
break;
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
9a91eb | 2004-05-04 | Martin Stjernholm | | return locked_by_auth_user ? 2 : shared;
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
085061 | 2004-05-03 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
085061 | 2004-05-03 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
085061 | 2004-05-03 | Martin Stjernholm | |
|
490832 | 2004-04-29 | Martin Stjernholm | |
|
085061 | 2004-05-03 | Martin Stjernholm | |
mapping(string:mixed) lock_file(string path,
DAVLock lock,
RequestID id)
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
|
490832 | 2004-04-29 | Martin Stjernholm | | ASSERT_IF_DEBUG (lock->locktype == "DAV:write");
User uid = id->conf->authenticate (id);
string user = uid && uid->name();
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | | if (lock->recursive) {
if (prefix_locks[path]) {
prefix_locks[path][user] = lock;
} else {
prefix_locks[path] = ([ user:lock ]);
}
} else {
if (file_locks[path]) {
file_locks[path][user] = lock;
} else {
file_locks[path] = ([ user:lock ]);
}
}
return 0;
}
|
490832 | 2004-04-29 | Martin Stjernholm | |
mapping(string:mixed) unlock_file (string path,
DAVLock lock,
RequestID id)
{
User uid = id->conf->authenticate (id);
string user = uid && uid->name();
DAVLock removed_lock;
if (lock->recursive) {
removed_lock = m_delete (prefix_locks[path], user);
if (!sizeof (prefix_locks[path])) m_delete (prefix_locks, path);
}
else {
removed_lock = m_delete (file_locks[path], user);
if (!sizeof (file_locks[path])) m_delete (file_locks, path);
}
ASSERT_IF_DEBUG (lock == removed_lock , lock, removed_lock);
return 0;
}
|
12cfc5 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | mapping(string:mixed)|int(-1..0)|Stdio.File find_file(string path,
RequestID id);
mapping(string:mixed) delete_file(string path, RequestID id)
{
RequestID tmp_id = id->close_me();
|
d35dfd | 2004-04-20 | Martin Stjernholm | | tmp_id->not_query = query_location() + path;
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | tmp_id->method = "DELELE";
|
781037 | 2004-03-04 | Henrik Grubbström (Grubba) | | return find_file(path, id) || Roxen.http_status(404);
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | }
int(0..1) recurse_delete_files(string path, MultiStatus stat, RequestID id)
{
Stat st = stat_file(path, id);
|
781037 | 2004-03-04 | Henrik Grubbström (Grubba) | | if (!st) return 0;
|
d396ad | 2004-03-03 | Henrik Grubbström (Grubba) | | if (st->isdir) {
int(0..1) fail;
foreach(find_dir(path, id) || ({}), string fname) {
fail |= recurse_delete_files(path+"/"+fname, stat, id);
}
if (fail) return fail;
}
mapping ret = delete_file(path, id);
if (ret->code != 204) {
stat->add_response(path, XMLStatusNode(ret->code));
}
return ret->code >= 300;
}
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | mapping copy_file(string path, string dest, int(-1..1) behavior, RequestID id)
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | {
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | werror("copy_file(%O, %O, %O, %O)\n",
path, dest, behavior, id);
|
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) | |
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | void recurse_copy_files(string path, int depth, string dest_prefix,
string dest_suffix,
mapping(string:int(-1..1)) behavior,
MultiStatus result, RequestID id)
{
Stat st = stat_file(path, id);
if (!st) return;
if (!dest_prefix) {
Standards.URI dest_uri = Standards.URI(result->href_prefix);
Configuration c = roxen->find_configuration_for_url(dest_uri, id->conf);
if (!c ||
!has_prefix(dest_uri->path||"/", query_location())) {
result->add_response(dest_suffix, XMLStatusNode(502));
return;
}
dest_prefix = (dest_uri->path||"/")[sizeof(query_location())..];
Stat dest_st;
if (!(dest_st = stat_file(combine_path(dest_prefix, ".."), id)) ||
!(dest_st->isdir)) {
result->add_response("", XMLStatusNode(409));
return;
}
if (combine_path(dest_prefix, dest_suffix, ".") ==
combine_path(path, ".")) {
result->add_response(dest_suffix, XMLStatusNode(403, "Source and destination are the same."));
return;
}
}
werror("recurse_copy_files(%O, %O, %O, %O, %O, %O, %O)\n",
path, depth, dest_prefix, dest_suffix, behavior, result, id);
mapping res = copy_file(path, dest_prefix + dest_suffix,
behavior[dest_prefix + dest_suffix]||behavior[0],
id);
result->add_response(dest_suffix, XMLStatusNode(res->error, res->data));
if (res->error >= 300) {
return;
}
if ((depth <= 0) || !st->isdir) return;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | depth--;
foreach(find_dir(path, id), string filename) {
|
641323 | 2004-03-01 | Henrik Grubbström (Grubba) | | recurse_copy_files(combine_path(path, filename), depth,
dest_prefix, combine_path(dest_suffix, filename),
behavior, result, id);
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | }
}
|
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 | | }
|