835c6c | 2001-06-17 | Martin Nilsson | |
|
6c0928 | 2003-06-11 | Henrik Grubbström (Grubba) | |
|
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?
|
00730e | 1999-11-18 | Per Hedbor | | "<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) | | {
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_ENTER("find_dir_stat(): \""+f+"\"", 0);
|
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) {
|
b27587 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_ENTER("stat()'ing "+ f + "/" + fname, 0);
|
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 | |
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | |
static string iso8601_date_time(int ts)
{
mapping(string:int) gmt = gmtime(ts);
return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
1900 + gmt->year, gmt->mon, gmt->mday,
gmt->hour, gmt->min, gmt->sec);
}
multiset(string) query_all_properties(string path, RequestID id)
{
Stat st = stat_file(path, id);
if (!st) return (<>);
multiset(string) res = (<
"DAV:creationdate",
"DAV:displayname",
"DAV:getlastmodified",
|
6c0928 | 2003-06-11 | Henrik Grubbström (Grubba) | | "DAV:resourcetype",
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | >);
if (st->isreg) {
res += (<
"DAV:getcontentlength",
"DAV:getcontenttype",
>);
}
return res;
}
string|array(Parser.XML.Tree.Node)|mapping(string:mixed)
query_property(string path, string prop_name, RequestID id)
{
Stat st = stat_file(path, id);
if (!st) return 0;
switch(prop_name) {
case "DAV:creationdate":
return iso8601_date_time(st->ctime);
case "DAV:displayname":
return combine_path(query_location(), path);
case "DAV:getcontentlength":
if (st->isreg) {
return (string)st->size;
}
break;
case "DAV:getcontenttype":
if (st->isreg) {
return id->conf->
type_from_filename(path, 0,
lower_case(Roxen.extension(path, id)));
}
break;
case "DAV:getlastmodified":
return iso8601_date_time(st->mtime);
|
6c0928 | 2003-06-11 | Henrik Grubbström (Grubba) | | case "DAV:resourcetype":
if (st->isdir) {
return ({ Parser.XML.Tree.Node(Parser.XML.Tree.XML_ELEMENT,
"DAV:collection", ([]), 0,
"DAV:collection") });
}
return "";
case "DAV:collection":
if (st->isdir) {
return "";
}
break;
|
265ca4 | 2003-06-02 | Henrik Grubbström (Grubba) | | default:
break;
}
return 0;
}
mapping(string:mixed) set_property(string path, string prop_name,
string|array(Parser.XML.Tree.Node) value,
RequestID id)
{
switch(prop_name) {
case "DAV:creationdate":
case "DAV:displayname":
case "DAV:getcontentlength":
case "DAV:getcontenttype":
case "DAV:getlastmodified":
return Roxen.http_low_answer(409,
"Attempt to set read-only property.");
}
return set_dead_property(path, prop_name, value, id);
}
mapping(string:mixed) set_dead_property(string path, string prop_name,
array(Parser.XML.Tree.Node) value,
RequestID id)
{
return Roxen.http_low_answer(405,
"Setting of dead properties is not supported.");
}
mapping(string:mixed) remove_property(string path, string prop_name,
RequestID id)
{
switch(prop_name) {
case "DAV:creationdate":
case "DAV:displayname":
case "DAV:getcontentlength":
case "DAV:getcontenttype":
case "DAV:getlastmodified":
return Roxen.http_low_answer(409,
"Attempt to remove a read-only property.");
}
return Roxen.http_low_answer(404,
"Attempt to remove an unknown property.");
}
void find_properties(string path, string mode, MultiStatus result,
RequestID id, multiset(string)|void filt)
{
Stat st = stat_file(path, id);
if (!st) return;
switch(mode) {
case "DAV:propname":
foreach(indices(query_all_properties(path, id)), string prop_name) {
result->add_property(path, prop_name, "");
}
return;
case "DAV:allprop":
filt = query_all_properties(path, id);
case "DAV:prop":
foreach(indices(filt), string prop_name) {
result->add_property(path, prop_name,
query_property(path, prop_name, id));
}
return;
}
return;
}
void recurse_find_properties(string path, string mode, int depth,
MultiStatus result,
RequestID id, multiset(string)|void filt)
{
Stat st = stat_file(path, id);
if (!st) return;
find_properties(path, mode, result, id, filt);
if ((depth <= 0) || !st->isdir) return;
depth--;
foreach(find_dir(path, id), string filename) {
recurse_find_properties(combine_path(path, filename), mode, depth,
result, id, filt);
}
}
void patch_property_start(string path, RequestID id)
{
}
void patch_property_unroll(string path, RequestID id)
{
}
void patch_property_commit(string path, RequestID id)
{
}
void patch_properties(string path, array(PatchPropertyCommand) instructions,
MultiStatus result, RequestID id)
{
patch_property_start(path, id);
array(mapping(string:mixed)) results;
mixed err = catch {
results = instructions->execute(path, this_object(), id);
};
if (err) {
report_debug("patch_properties() failed:\n"
"%s\n",
describe_backtrace(err));
mapping(string:mixed) answer =
Roxen.http_low_answer(500, "Internal Server Error.");
foreach(instructions, PatchPropertyCommand instr) {
result->add_property(path, instr->property_name, answer);
}
patch_property_unroll(path, id);
} else {
int any_failed;
foreach(results, mapping(string:mixed) answer) {
if (any_failed = (answer && (answer->error >= 300))) {
break;
}
}
if (any_failed) {
int i;
mapping(string:mixed) answer =
Roxen.http_low_answer(424, "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]);
}
}
patch_property_unroll(path, id);
} else {
int i;
for(i = 0; i < sizeof(results); i++) {
result->add_property(path, instructions[i]->property_name,
results[i]);
}
patch_property_commit(path, id);
}
}
}
void recurse_patch_properties(string path, int depth,
array(PatchPropertyCommand) instructions,
MultiStatus result, RequestID id)
{
Stat st = stat_file(path, id);
patch_properties(path, instructions, result, id);
if (!st || (depth <= 0) || !st->isdir) return;
depth--;
foreach(find_dir(path, id), string filename) {
recurse_patch_properties(combine_path(path, filename), depth,
instructions, result, 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;
|
12e79e | 1999-12-07 | Martin Nilsson | | if(index[sizeof(index)-2..sizeof(index)-1]=="()") {
return compile_string((pre||"")+file->read())[index[..sizeof(index)-3]]();
}
return compile_string((pre||"")+file->read())[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,
void|array(string)|string defenition,
string|void comment,
int|void flag )
|
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 | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
a0487b | 2001-07-31 | Per Hedbor | |
|
1e9a1b | 2001-02-21 | Per Hedbor | |
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
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;
|
1e9a1b | 2001-02-21 | Per Hedbor | | if( !defenition )
{
defenition = 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;
}
|
1e9a1b | 2001-02-21 | Per Hedbor | | if( arrayp( defenition ) )
defenition *= ", ";
|
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
{
get_my_sql()->query( "CREATE TABLE "+res+" ("+defenition+")" );
|
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 | | }
|
2be198 | 2001-08-01 | Per Hedbor | |
|
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 | | }
|