835c6c | 2001-06-17 | Martin Nilsson | |
|
b655bf | 2004-06-30 | Martin Stjernholm | |
|
835c6c | 2001-06-17 | Martin Nilsson | |
|
6b67fe | 2001-08-24 | Martin Nilsson | |
|
433771 | 2008-01-09 | Martin Stjernholm | | constant cvs_version = "$Id: configuration.pike,v 1.644 2008/01/09 16:40:43 mast Exp $";
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
|
a59d25 | 2000-07-04 | Per Hedbor | | #include <module_constants.h>
|
14179b | 1997-01-29 | Per Hedbor | | #include <roxen.h>
|
c5e096 | 1999-10-04 | Per Hedbor | | #include <request_trace.h>
|
9c1900 | 2001-02-27 | Per Hedbor | | #include <timers.h>
|
8afc81 | 1998-02-04 | Per Hedbor | |
|
c7a5f0 | 1999-02-16 | Per Hedbor | | #define CATCH(P,X) do{mixed e;if(e=catch{X;})report_error("While "+P+"\n"+describe_backtrace(e));}while(0)
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | |
|
23414a | 2000-07-21 | Andreas Lange | |
#define LOC_S(X,Y) _STR_LOCALE("roxen_start",X,Y)
#define LOC_C(X,Y) _STR_LOCALE("roxen_config",X,Y)
#define LOC_M(X,Y) _STR_LOCALE("roxen_message",X,Y)
#define DLOCALE(X,Y) _DEF_LOCALE("roxen_config",X,Y)
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | |
|
199d03 | 1999-09-05 | Francesco Chemolli | | #ifdef THROTTLING_DEBUG
#undef THROTTLING_DEBUG
|
91d3c3 | 2001-03-12 | Martin Nilsson | | #define THROTTLING_DEBUG(X) report_debug("Throttling: "+X+"\n")
|
199d03 | 1999-09-05 | Francesco Chemolli | | #else
#define THROTTLING_DEBUG(X)
#endif
|
10c7e1 | 1999-12-28 | Martin Nilsson | | #ifdef REQUEST_DEBUG
|
91d3c3 | 2001-03-12 | Martin Nilsson | | # define REQUEST_WERR(X) report_debug("CONFIG: "+X+"\n")
|
10c7e1 | 1999-12-28 | Martin Nilsson | | #else
# define REQUEST_WERR(X)
#endif
|
471705 | 2001-05-07 | Per Hedbor | |
#ifdef AVERAGE_PROFILING
|
7e1610 | 2001-11-01 | Henrik Grubbström (Grubba) | |
#if !constant(gethrvtime)
#define gethrvtime() gethrtime()
#endif /* !constant(gethrvtime) */
|
471705 | 2001-05-07 | Per Hedbor | | class ProfStack
{
array current_stack = ({});
void enter( string k, RequestID id )
{
current_stack += ({ ({ k, gethrtime(), gethrvtime() }) });
}
void leave( string k, RequestID id )
{
int t0 = gethrtime();
int t1 = gethrvtime();
if( !sizeof(current_stack ) )
{
|
7937df | 2001-05-16 | Per Hedbor | |
|
471705 | 2001-05-07 | Per Hedbor | | return;
}
int i = sizeof( current_stack )-1;
while( current_stack[ i ][0] != k && i >= 0 ) i--;
if(i < 0 )
{
return;
}
|
7937df | 2001-05-16 | Per Hedbor | | void low_leave( int i )
{
int tt = t0-current_stack[i][1];
int ttv = t1-current_stack[i][2];
if( i > 0 )
{
current_stack[i-1][1]+=tt+gethrtime()-t0;
current_stack[i-1][2]+=ttv+gethrvtime()-t1;
}
current_stack = current_stack[..i-1];
add_prof_entry( id, k, tt, ttv );
};
|
471705 | 2001-05-07 | Per Hedbor | |
|
7937df | 2001-05-16 | Per Hedbor | | if( i != sizeof( current_stack )-1 )
|
471705 | 2001-05-07 | Per Hedbor | | {
|
7937df | 2001-05-16 | Per Hedbor | | for( int j = sizeof( current_stack )-1; j>=i; j-- )
low_leave( j );
return;
|
471705 | 2001-05-07 | Per Hedbor | | }
|
7937df | 2001-05-16 | Per Hedbor | | low_leave( i );
|
471705 | 2001-05-07 | Per Hedbor | | }
}
class ProfInfo( string url )
{
mapping data = ([]);
void add( string k, int h, int hrv )
{
if( !data[k] )
data[k] = ({ h, hrv, 1 });
else
{
data[k][0]+=h;
data[k][1]+=hrv;
data[k][2]++;
}
}
array summarize_table( )
{
array table = ({});
int n, t, v;
foreach( indices( data ), string k )
table += ({ ({ k,
sprintf( "%d", (n=data[k][2]) ),
sprintf("%5.2f",(t=data[k][0])/1000000.0),
sprintf("%5.2f", (v=data[k][1])/1000000.0),
sprintf("%8.2f", t/n/1000.0),
sprintf("%8.2f",v/n/1000.0), }) });
sort( (array(float))column(table,2), table );
return reverse(table);
}
void dump( )
{
write( "\n"+url+": \n" );
|
ab1e02 | 2002-03-06 | Henrik Grubbström (Grubba) | | ADT.Table.table t = ADT.Table.table( summarize_table(),
({ "What", "Calls",
"Time", "CPU",
"t/call(ms)", "cpu/call(ms)" }));
|
471705 | 2001-05-07 | Per Hedbor | |
write( ADT.Table.ASCII.encode( t )+"\n" );
}
}
mapping profiling_info = ([]);
void debug_write_prof( )
{
foreach( sort( indices( profiling_info ) ), string p )
profiling_info[p]->dump();
}
void add_prof_entry( RequestID id, string k, int hr, int hrv )
{
|
e8dffa | 2001-05-14 | Per Hedbor | | string l = id->not_query;
|
7937df | 2001-05-16 | Per Hedbor | |
if( has_prefix( l, query_internal_location() ) )
l = dirname( l );
if( !profiling_info[l] )
profiling_info[l] = ProfInfo(l);
|
e8dffa | 2001-05-14 | Per Hedbor | | profiling_info[l]->add( k, hr, hrv );
|
471705 | 2001-05-07 | Per Hedbor | | }
void avg_prof_enter( string name, string type, RequestID id )
{
if( !id->misc->prof_stack )
id->misc->prof_stack = ProfStack();
id->misc->prof_stack->enter( name+":"+type,id );
}
void avg_prof_leave( string name, string type, RequestID id )
{
if( !id->misc->prof_stack ) id->misc->prof_stack = ProfStack();
id->misc->prof_stack->leave( name+":"+type,id );
}
#endif
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9a8a15 | 2000-09-25 | Per Hedbor | | inherit Configuration;
inherit "basic_defvar";
|
dfe036 | 2000-03-19 | Martin Nilsson | |
|
b9c387 | 2002-03-27 | Per Hedbor | | static mapping(RequestID:mapping) current_connections =
set_weak_flag( ([ ]), 1 );
void connection_add( RequestID id, mapping data )
{
current_connections[id] = data;
}
mapping connection_drop( RequestID id )
{
|
2d35f7 | 2007-02-01 | Arjan van Staalduijnen | | return m_delete( current_connections, id );
|
b9c387 | 2002-03-27 | Per Hedbor | | }
mapping(RequestID:mapping) connection_get( )
{
return current_connections;
}
|
3557f5 | 2001-06-30 | Martin Stjernholm | |
string name = roxen->bootstrap_info->get();
|
d09399 | 2000-09-25 | Per Hedbor | | class DataCache
{
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | static typedef array(string|mapping(string:mixed))|string|
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | function(string, RequestID:string|int) EntryType;
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | |
mapping(string:EntryType) cache = ([]);
|
d09399 | 2000-09-25 | Per Hedbor | |
int current_size;
int max_size;
int max_file_size;
int hits, misses;
void flush()
{
|
c3c8c0 | 2005-11-24 | Henrik Grubbström (Grubba) | | #ifndef RAM_CACHE_NO_RELOAD_FLUSH
|
d09399 | 2000-09-25 | Per Hedbor | | current_size = 0;
cache = ([]);
|
c3c8c0 | 2005-11-24 | Henrik Grubbström (Grubba) | | #endif
|
d09399 | 2000-09-25 | Per Hedbor | | }
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | |
static void really_low_expire_entry(string key)
{
EntryType e = m_delete(cache, key);
if (arrayp(e)) {
current_size -= sizeof(e[0]);
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | if (e[1]->co_handle) {
remove_call_out(e[1]->co_handle);
}
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | }
}
static int low_expire_entry(string key_prefix)
|
d09399 | 2000-09-25 | Per Hedbor | | {
|
764667 | 2006-11-14 | Henrik Grubbström (Grubba) | | if (!key_prefix) return 0;
|
4bd560 | 2006-11-14 | Henrik Grubbström (Grubba) | | if (arrayp(cache[key_prefix])) {
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | really_low_expire_entry(key_prefix);
|
4bd560 | 2006-11-14 | Henrik Grubbström (Grubba) | | return 1;
}
|
764667 | 2006-11-14 | Henrik Grubbström (Grubba) | | int res = 0;
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | foreach(indices(cache); int ind; string key) {
|
98cb8c | 2006-10-13 | Martin Stjernholm | | if (!key) continue;
if (has_prefix(key, key_prefix)) {
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | really_low_expire_entry(key);
|
764667 | 2006-11-14 | Henrik Grubbström (Grubba) | | res++;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
|
98cb8c | 2006-10-13 | Martin Stjernholm | | }
|
764667 | 2006-11-14 | Henrik Grubbström (Grubba) | | return res;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
void expire_entry(string key_prefix, RequestID|void id)
{
if (!id) {
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | low_expire_entry(key_prefix);
|
d09399 | 2000-09-25 | Per Hedbor | | return;
}
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | string url = key_prefix;
|
98cb8c | 2006-10-13 | Martin Stjernholm | | sscanf(url, "%[^\0]", url);
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | while(1) {
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | EntryType val;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (arrayp(val = cache[key_prefix])) {
current_size -= sizeof(val[0]);
m_delete(cache, key_prefix);
return;
}
if (!val) {
return;
}
|
88249d | 2006-06-30 | Arjan van Staalduijnen | | string|array(string) key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (stringp(val)) {
|
d7dbb2 | 2006-06-21 | Arjan van Staalduijnen | | key_frag = id->request_headers[val];
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | } else {
key_frag = val(url, id);
}
|
98cb8c | 2006-10-13 | Martin Stjernholm | | if (key_frag)
key_frag = replace (key_frag, "\0", "\0\1");
else key_frag = "";
key_prefix += "\0\0" + key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
|
d09399 | 2000-09-25 | Per Hedbor | | }
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | |
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | static void clear_some_cache()
|
d09399 | 2000-09-25 | Per Hedbor | | {
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | array(string) q = indices(cache);
if(!sizeof(q))
|
d09399 | 2000-09-25 | Per Hedbor | | {
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | current_size=0;
return;
|
d09399 | 2000-09-25 | Per Hedbor | | }
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | |
sort(q);
|
4bd560 | 2006-11-14 | Henrik Grubbström (Grubba) | | for(int i = 0; i < sizeof(q)/10; i++) {
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | int r = random(sizeof(q));
string key_prefix = q[r = random(sizeof(q))];
|
78fe04 | 2006-12-05 | Henrik Grubbström (Grubba) | | if (!key_prefix) continue;
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | for(;r < sizeof(q); r++,i++) {
|
78fe04 | 2006-12-05 | Henrik Grubbström (Grubba) | | if (!q[r]) continue;
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | if (!has_prefix(q[r], key_prefix)) break;
really_low_expire_entry(q[r]);
q[r] = 0;
}
|
4bd560 | 2006-11-14 | Henrik Grubbström (Grubba) | | }
|
d09399 | 2000-09-25 | Per Hedbor | | }
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | void set(string url, string data, mapping meta, int expire, RequestID id)
|
d09399 | 2000-09-25 | Per Hedbor | | {
|
433771 | 2008-01-09 | Martin Stjernholm | | if( strlen( data ) > max_file_size ) {
SIMPLE_TRACE_ENTER (this, "Result of size %d is too large "
"to store in the protocol cache (limit %d)",
sizeof (data), max_file_size);
SIMPLE_TRACE_LEAVE ("");
return;
}
|
7723f0 | 2005-11-28 | Henrik Grubbström (Grubba) | |
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Storing result of size %d in the protocol cache "
"using key %O (expire in %ds)",
sizeof (data), url, expire);
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | string key = url;
foreach(id->misc->vary_cb_order || ({}),
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | string|function(string, RequestID: string|int) vary_cb) {
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | array(string|mapping(string:mixed))|string|
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | function(string, RequestID:string|int) old = cache[key];
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (old && (old != vary_cb)) {
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Registering vary cb %O - conflicts with "
"existing entry %s, old entry expired",
vary_cb,
(arrayp (old) ? "of size " + sizeof (old[0]) :
sprintf ("%O", old)));
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | low_expire_entry(key);
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("");
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
cache[key] = vary_cb;
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Registering vary cb %O", vary_cb);
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | string key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (stringp(vary_cb)) {
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | string|array(string) header = id->request_headers[vary_cb];
if (arrayp(header)) key_frag = header * ",";
else key_frag = header;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | } else {
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | int|string frag = vary_cb(url, id);
if (intp(frag) && frag) {
key_frag = frag->digits(256);
} else {
key_frag = frag;
}
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
|
433771 | 2008-01-09 | Martin Stjernholm | |
SIMPLE_TRACE_LEAVE ("Vary cb resolved to key fragment %O",
key_frag || "");
|
98cb8c | 2006-10-13 | Martin Stjernholm | | if (key_frag)
key_frag = replace (key_frag, "\0", "\0\1");
else key_frag = "";
key += "\0\0" + key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
array(string|mapping(string:mixed))|string|
function(string, RequestID:string) old = cache[key];
if (old) {
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("Entry conflicts with existing entry %s, "
"old entry expired",
(arrayp (old) ? "of size " + sizeof (old[0]) :
sprintf ("%O", old)));
|
932f13 | 2006-12-05 | Henrik Grubbström (Grubba) | | low_expire_entry(key);
|
7723f0 | 2005-11-28 | Henrik Grubbström (Grubba) | | }
|
433771 | 2008-01-09 | Martin Stjernholm | | else
SIMPLE_TRACE_LEAVE ("");
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | |
|
d09399 | 2000-09-25 | Per Hedbor | | current_size += strlen( data );
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | cache[key] = ({ data, meta });
|
98cb8c | 2006-10-13 | Martin Stjernholm | |
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | meta->co_handle = call_out(really_low_expire_entry, expire, key);
|
d09399 | 2000-09-25 | Per Hedbor | | int n;
while( (current_size > max_size) && (n++<10))
clear_some_cache();
}
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | array(string|mapping(string:mixed)) get(string url, RequestID id)
|
d09399 | 2000-09-25 | Per Hedbor | | {
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Looking up entry for %O in the protocol cache",
url);
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | array(string|mapping(string:mixed))|string|
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | function(string, RequestID:string|int) res;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | string key = url;
while(1) {
|
4acd99 | 2006-04-20 | Henrik Grubbström (Grubba) | | id->misc->protcache_cost++;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (arrayp(res = cache[key])) {
hits++;
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("Found entry of size %d", sizeof (res[0]));
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | return [array(string|mapping(string:mixed))]res;
}
if (!res) {
misses++;
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE ("Found no entry");
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | return UNDEFINED;
}
|
433771 | 2008-01-09 | Martin Stjernholm | | SIMPLE_TRACE_ENTER (this, "Found vary cb %O", res);
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | string key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (stringp(res)) {
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | string|array(string) header = id->request_headers[res];
if (arrayp(header)) key_frag = header * ",";
else key_frag = header;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | } else {
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | int|string frag = res(url, id);
if (intp(frag) && frag) {
key_frag = frag->digits(256);
} else {
key_frag = frag;
}
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | }
|
433771 | 2008-01-09 | Martin Stjernholm | |
SIMPLE_TRACE_LEAVE ("Vary cb resolved to key fragment %O",
key_frag || "");
|
98cb8c | 2006-10-13 | Martin Stjernholm | | if (key_frag)
key_frag = replace (key_frag, "\0", "\0\1");
else key_frag = "";
key += "\0\0" + key_frag;
|
145592 | 2005-12-05 | Henrik Grubbström (Grubba) | | };
|
d09399 | 2000-09-25 | Per Hedbor | | }
void init_from_variables( )
{
max_size = query( "data_cache_size" ) * 1024;
max_file_size = query( "data_cache_file_max_size" ) * 1024;
if( max_size < max_file_size )
max_size += max_file_size;
int n;
while( (current_size > max_size) && (n++<10))
clear_some_cache();
}
static void create()
{
init_from_variables();
}
}
|
3b1783 | 1998-11-22 | Per Hedbor | | #include "rxml.pike";
|
9a8a15 | 2000-09-25 | Per Hedbor | | constant store = roxen.store;
constant retrieve = roxen.retrieve;
constant remove = roxen.remove;
|
14179b | 1997-01-29 | Per Hedbor | |
|
65c6d2 | 2000-03-10 | Martin Nilsson | | int config_id;
|
9a8a15 | 2000-09-25 | Per Hedbor | | int get_config_id()
{
|
65c6d2 | 2000-03-10 | Martin Nilsson | | if(config_id) return config_id;
for(int i=sizeof(roxen->configurations); i;)
if(roxen->configurations[--i]->name==name) return config_id=i;
}
|
c7a5f0 | 1999-02-16 | Per Hedbor | | string get_doc_for( string region, string variable )
{
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule module;
|
c7a5f0 | 1999-02-16 | Per Hedbor | | if(variable[0] == '_')
return 0;
if((int)reverse(region))
return 0;
if(module = find_module( region ))
{
if(module->variables[variable])
|
b2c49b | 2000-07-09 | Per Hedbor | | return module->variables[variable]->name()+
"\n"+module->variables[ variable ]->doc();
|
c7a5f0 | 1999-02-16 | Per Hedbor | | }
if(variables[ variable ])
|
b2c49b | 2000-07-09 | Per Hedbor | | return variables[variable]->name()+
"\n"+variables[ variable ]->doc();
|
c7a5f0 | 1999-02-16 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | |
|
e351dd | 1999-11-29 | Per Hedbor | | string query_internal_location(RoxenModule|void mod)
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
|
9ac033 | 2002-11-05 | Anders Johansson | | return internal_location+(mod?replace(otomod[mod]||"", "#", "!")+"/":"");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
string query_name()
{
|
8552d9 | 2001-01-13 | Martin Nilsson | | if(strlen(query("name")))
return query("name");
|
b1fca0 | 1996-11-12 | Per Hedbor | | return name;
}
string comment()
{
|
8552d9 | 2001-01-13 | Martin Nilsson | | return query("comment");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
b6675b | 2002-10-28 | Martin Stjernholm | | private float cached_compat_level;
float compat_level()
{
if (cached_compat_level == 0.0)
cached_compat_level = (float) query ("compat_level");
return cached_compat_level;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
e351dd | 1999-11-29 | Per Hedbor | | array (Priority) allocate_pris()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | return allocate(10, Priority)();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | array(int) query_oid()
{
|
7adb10 | 2007-11-05 | Henrik Grubbström (Grubba) | | return SNMP.RIS_OID_WEBSERVER + ({ 2 });
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | |
array(int) generate_module_oid_segment(RoxenModule me)
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | {
string s = otomod[me];
array(string) a = s/"#";
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | | return ({ sizeof(a[0]), @((array(int))a[0]), ((int)a[1]) + 1 });
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | }
ADT.Trie generate_module_mib(array(int) oid,
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | | array(int) oid_suffix,
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | RoxenModule me,
ModuleInfo moduleinfo,
ModuleCopies module)
{
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | | array(int) segment = generate_module_oid_segment(me);
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | return SNMP.SimpleMIB(oid,
|
747c74 | 2007-09-14 | Henrik Grubbström (Grubba) | | oid_suffix + segment,
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | ({
UNDEFINED,
|
7adb10 | 2007-11-05 | Henrik Grubbström (Grubba) | | SNMP.Integer(segment[-1], "moduleCopy"),
|
a6750f | 2007-09-12 | Henrik Grubbström (Grubba) | | SNMP.String(otomod[me],
"moduleIdentifier"),
SNMP.Integer(moduleinfo->type,
"moduleType"),
SNMP.String(me->cvs_version || "",
"moduleVersion"),
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | }));
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9ac033 | 2002-11-05 | Anders Johansson | |
private int sub_req_limit = 30;
private string internal_location = "/_internal/";
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
0ab494 | 2006-10-13 | Martin Stjernholm | | private mapping (int|string:string) log_format = ([]);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
053a55 | 2000-10-04 | Per Hedbor | | array (Priority) pri = allocate_pris();
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | mapping modules = ([]);
|
1dd64a | 2000-09-19 | Mattias Wingstedt | |
|
e75fd1 | 2000-07-26 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | mapping (RoxenModule:string) otomod = ([]);
|
e75fd1 | 2000-07-26 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
private array (function) url_module_cache, last_module_cache;
private array (function) logger_module_cache, first_module_cache;
private array (function) filter_module_cache;
private array (array (string|function)) location_module_cache;
private mapping (string:array (function)) file_extension_module_cache=([]);
|
e351dd | 1999-11-29 | Per Hedbor | | private mapping (string:array (RoxenModule)) provider_module_cache=([]);
|
3342dd | 2001-01-19 | Per Hedbor | | private array (RoxenModule) auth_module_cache, userdb_module_cache;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
38dca8 | 1996-12-10 | Per Hedbor | |
|
0e1557 | 2001-02-23 | Martin Stjernholm | | void unregister_urls()
|
38dca8 | 1996-12-10 | Per Hedbor | | {
|
9c3c6c | 2001-11-09 | Henrik Grubbström (Grubba) | | foreach( registered_urls + failed_urls, string url )
roxen.unregister_url(url, this_object());
|
dffa22 | 2000-12-10 | Per Hedbor | | registered_urls = ({});
|
38dca8 | 1996-12-10 | Per Hedbor | | }
|
0e1557 | 2001-02-23 | Martin Stjernholm | | private int num_modules = 0;
#ifdef THREADS
private Thread.Condition modules_stopped = Thread.Condition();
|
7660ad | 2002-10-23 | Martin Stjernholm | | private Thread.Mutex modules_stopped_mutex = Thread.Mutex();
|
0e1557 | 2001-02-23 | Martin Stjernholm | | #endif
private void safe_stop_module (RoxenModule mod, string desc)
{
if (mixed err = catch (mod && mod->stop && mod->stop()))
report_error ("While stopping " + desc + ": " + describe_backtrace (err));
|
a5249e | 2001-03-05 | Per Hedbor | | #ifdef THREADS
|
7660ad | 2002-10-23 | Martin Stjernholm | | Thread.MutexKey lock = modules_stopped_mutex->lock();
if (!--num_modules)
modules_stopped->signal();
lock = 0;
#else
--num_modules;
|
a5249e | 2001-03-05 | Per Hedbor | | #endif
|
0e1557 | 2001-02-23 | Martin Stjernholm | | }
void stop (void|int asynch)
{
|
79b7c3 | 2001-09-13 | Honza Petrous | |
#ifdef SNMP_AGENT
if(query("snmp_process") && objectp(roxen->snmpagent)) {
roxen->snmpagent->vs_stop_trap(get_config_id());
roxen->snmpagent->del_virtserv(get_config_id());
}
#endif
|
0e1557 | 2001-02-23 | Martin Stjernholm | | unregister_urls();
multiset allmods = mkmultiset (indices (otomod));
num_modules = 17;
if (types_module) {
num_modules++;
roxen.handle (safe_stop_module, types_module, "type module");
allmods[types_module] = 0;
}
if (dir_module) {
num_modules++;
roxen.handle (safe_stop_module, dir_module, "directory module");
allmods[dir_module] = 0;
}
for(int i=0; i<10; i++)
if (Priority p = pri[i]) {
#define STOP_MODULES(MODS, DESC) \
foreach(MODS, RoxenModule m) \
if (allmods[m]) { \
num_modules++; \
roxen.handle (safe_stop_module, m, DESC); \
allmods[m] = 0; \
}
STOP_MODULES (p->url_modules, "url module");
STOP_MODULES (p->logger_modules, "logging module");
STOP_MODULES (p->filter_modules, "filter module");
STOP_MODULES (p->location_modules, "location module");
STOP_MODULES (p->last_modules, "last module");
STOP_MODULES (p->first_modules, "first module");
STOP_MODULES (indices (p->provider_modules), "provider module");
}
if (mixed err = catch {
if (object m = log_function && function_object (log_function)) {
destruct (m);
allmods[m] = 0;
}
}) report_error ("While stopping the logger: " + describe_backtrace (err));
STOP_MODULES(indices (allmods), "unclassified module");
#undef STOP_MODULES
if (!asynch) {
#ifdef THREADS
|
7660ad | 2002-10-23 | Martin Stjernholm | | Thread.MutexKey lock = modules_stopped_mutex->lock();
num_modules -= 17;
if (num_modules) modules_stopped->wait (lock);
lock = 0;
|
0e1557 | 2001-02-23 | Martin Stjernholm | | #else
|
7660ad | 2002-10-23 | Martin Stjernholm | | if (num_modules != 17)
|
0e1557 | 2001-02-23 | Martin Stjernholm | | error ("num_modules shouldn't be nonzero here when running nonthreaded.\n");
#endif
}
}
|
d449d5 | 2003-06-02 | Henrik Grubbström (Grubba) | | string|array(string) type_from_filename( string file, int|void to,
string|void myext )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
f28c11 | 2000-03-06 | Martin Nilsson | | array(string)|string tmp;
|
14179b | 1997-01-29 | Per Hedbor | | if(!types_fun)
return to?({ "application/octet-stream", 0 }):"application/octet-stream";
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | string ext = lower_case(myext || Roxen.extension(file));
|
41b77c | 1999-07-15 | David Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | if(tmp = types_fun(ext))
{
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | |
if (tmp[0] == "strip")
|
14179b | 1997-01-29 | Per Hedbor | | {
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | array(string) tmp2 = file/".";
string nx;
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | if (sizeof(tmp2) > 2)
|
d64d90 | 2007-01-03 | Henrik Grubbström (Grubba) | | nx = lower_case(tmp2[-2]);
tmp[0] = (nx && types_fun(nx)) || types_fun("default") ||
"application/octet-stream";
|
14179b | 1997-01-29 | Per Hedbor | | }
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | } else if (!(tmp = types_fun("default"))) {
|
9be5aa | 1998-07-03 | Henrik Grubbström (Grubba) | | tmp = ({ "application/octet-stream", 0 });
|
14179b | 1997-01-29 | Per Hedbor | | }
|
9be5aa | 1998-07-03 | Henrik Grubbström (Grubba) | | return to?tmp:tmp[0];
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
e351dd | 1999-11-29 | Per Hedbor | | array (RoxenModule) get_providers(string provides)
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
ae32d0 | 1998-03-23 | David Hedbor | | {
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
ae32d0 | 1998-03-23 | David Hedbor | | if(!provider_module_cache[provides])
|
10c7e1 | 1999-12-28 | Martin Nilsson | | {
|
ae32d0 | 1998-03-23 | David Hedbor | | int i;
provider_module_cache[provides] = ({ });
for(i = 9; i >= 0; i--)
{
|
951e6f | 2007-08-06 | Fredrik Noring | | array(RoxenModule) modules = indices(pri[i]->provider_modules);
array(string) module_identifiers = modules->module_identifier();
sort(module_identifiers, modules);
foreach(modules, RoxenModule d)
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(pri[i]->provider_modules[ d ][ provides ])
|
ae32d0 | 1998-03-23 | David Hedbor | | provider_module_cache[provides] += ({ d });
}
}
return provider_module_cache[provides];
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule get_provider(string provides)
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
ae32d0 | 1998-03-23 | David Hedbor | | {
|
e351dd | 1999-11-29 | Per Hedbor | | array (RoxenModule) prov = get_providers(provides);
|
ae32d0 | 1998-03-23 | David Hedbor | | if(sizeof(prov))
return prov[0];
return 0;
}
|
bdb8da | 1998-09-02 | Johan Schön | | array(mixed) map_providers(string provides, string fun, mixed ... args)
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
ae32d0 | 1998-03-23 | David Hedbor | | {
|
e351dd | 1999-11-29 | Per Hedbor | | array (RoxenModule) prov = get_providers(provides);
|
0e1f26 | 2002-01-29 | Martin Stjernholm | | mixed error;
|
bdb8da | 1998-09-02 | Johan Schön | | array a=({ });
mixed m;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | foreach(prov, RoxenModule mod)
|
9bb813 | 1998-09-12 | Per Hedbor | | {
|
ae32d0 | 1998-03-23 | David Hedbor | | if(!objectp(mod))
continue;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(functionp(mod[fun]))
|
bdb8da | 1998-09-02 | Johan Schön | | error = catch(m=mod[fun](@args));
|
0e1f26 | 2002-01-29 | Martin Stjernholm | | if(error) {
report_debug("Error in map_providers(): " + describe_backtrace(error));
|
24fbd4 | 1999-04-21 | David Hedbor | | }
|
bdb8da | 1998-09-02 | Johan Schön | | else
|
9bb813 | 1998-09-12 | Per Hedbor | | a += ({ m });
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | | error = 0;
|
ae32d0 | 1998-03-23 | David Hedbor | | }
|
9bb813 | 1998-09-12 | Per Hedbor | | return a;
|
ae32d0 | 1998-03-23 | David Hedbor | | }
mixed call_provider(string provides, string fun, mixed ... args)
|
2f1e89 | 2000-08-15 | Martin Nilsson | |
|
ae32d0 | 1998-03-23 | David Hedbor | | {
|
10c7e1 | 1999-12-28 | Martin Nilsson | | foreach(get_providers(provides), RoxenModule mod)
|
e351dd | 1999-11-29 | Per Hedbor | | {
|
d8b772 | 1998-05-28 | Henrik Grubbström (Grubba) | | function f;
if(objectp(mod) && functionp(f = mod[fun])) {
|
a51a90 | 2001-11-12 | Martin Stjernholm | | mixed ret;
if (ret = f(@args)) {
return ret;
|
d8b772 | 1998-05-28 | Henrik Grubbström (Grubba) | | }
}
|
ae32d0 | 1998-03-23 | David Hedbor | | }
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
517c7e | 2000-09-30 | Per Hedbor | | array (function) file_extension_modules(string ext)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | if(!file_extension_module_cache[ext = lower_case(ext)])
|
10c7e1 | 1999-12-28 | Martin Nilsson | | {
|
b1fca0 | 1996-11-12 | Per Hedbor | | int i;
file_extension_module_cache[ext] = ({ });
for(i=9; i>=0; i--)
{
|
e351dd | 1999-11-29 | Per Hedbor | | array(RoxenModule) d;
RoxenModule p;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(d = pri[i]->file_extension_modules[ext])
foreach(d, p)
file_extension_module_cache[ext] += ({ p->handle_file_extension });
}
}
return file_extension_module_cache[ext];
}
|
517c7e | 2000-09-30 | Per Hedbor | | array (function) url_modules()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!url_module_cache)
{
int i;
url_module_cache=({ });
for(i=9; i>=0; i--)
{
|
e351dd | 1999-11-29 | Per Hedbor | | array(RoxenModule) d;
RoxenModule p;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(d=pri[i]->url_modules)
foreach(d, p)
url_module_cache += ({ p->remap_url });
}
}
return url_module_cache;
}
|
9a8a15 | 2000-09-25 | Per Hedbor | | static mapping api_module_cache = ([]);
|
e351dd | 1999-11-29 | Per Hedbor | | mapping api_functions(void|RequestID id)
|
4f4bc1 | 1998-02-04 | Per Hedbor | | {
|
fc9d8e | 2000-08-28 | Per Hedbor | | return api_module_cache+([]);
|
4f4bc1 | 1998-02-04 | Per Hedbor | | }
|
517c7e | 2000-09-30 | Per Hedbor | | array (function) logger_modules()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!logger_module_cache)
{
int i;
logger_module_cache=({ });
for(i=9; i>=0; i--)
{
|
e351dd | 1999-11-29 | Per Hedbor | | array(RoxenModule) d;
RoxenModule p;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(d=pri[i]->logger_modules)
foreach(d, p)
if(p->log)
logger_module_cache += ({ p->log });
}
}
return logger_module_cache;
}
|
517c7e | 2000-09-30 | Per Hedbor | | array (function) last_modules()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!last_module_cache)
{
int i;
last_module_cache=({ });
for(i=9; i>=0; i--)
{
|
e351dd | 1999-11-29 | Per Hedbor | | array(RoxenModule) d;
RoxenModule p;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(d=pri[i]->last_modules)
foreach(d, p)
if(p->last_resort)
last_module_cache += ({ p->last_resort });
}
}
return last_module_cache;
}
|
e351dd | 1999-11-29 | Per Hedbor | | static mixed strip_fork_information(RequestID id)
|
ca44e5 | 1998-07-02 | Henrik Grubbström (Grubba) | | {
|
bc37d3 | 2005-01-05 | Jonas Wallden | | if (uname()->sysname == "Darwin") {
if (has_value(id->not_query, "..namedfork/") ||
has_suffix(id->not_query, "/rsrc") ||
has_value(lower_case(id->not_query), ".ds_store"))
return error_file(id);
}
|
ca44e5 | 1998-07-02 | Henrik Grubbström (Grubba) | | array a = id->not_query/"::";
|
9934d6 | 2001-09-05 | Jonas Wallden | |
id->not_query = a[0];
|
ca44e5 | 1998-07-02 | Henrik Grubbström (Grubba) | | id->misc->fork_information = a[1..];
|
c5e096 | 1999-10-04 | Per Hedbor | | return 0;
|
ca44e5 | 1998-07-02 | Henrik Grubbström (Grubba) | | }
|
517c7e | 2000-09-30 | Per Hedbor | | array (function) first_modules()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!first_module_cache)
{
int i;
|
bc37d3 | 2005-01-05 | Jonas Wallden | | first_module_cache = ({ });
if (
|
ca44e5 | 1998-07-02 | Henrik Grubbström (Grubba) | | #ifdef __NT__
|
bc37d3 | 2005-01-05 | Jonas Wallden | | 1 ||
#endif
uname()->sysname == "Darwin") {
first_module_cache= ({
strip_fork_information,
});
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | for(i=9; i>=0; i--)
{
|
e351dd | 1999-11-29 | Per Hedbor | | array(RoxenModule) d; RoxenModule p;
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | if(d=pri[i]->first_modules) {
foreach(d, p) {
if(p->first_try) {
|
b1fca0 | 1996-11-12 | Per Hedbor | | first_module_cache += ({ p->first_try });
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | }
}
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
}
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | return first_module_cache;
}
|
4d1023 | 2001-06-26 | Per Hedbor | | void set_userdb_module_cache( array to )
{
userdb_module_cache = to;
}
|
3342dd | 2001-01-19 | Per Hedbor | | array(UserDB) user_databases()
{
if( userdb_module_cache )
return userdb_module_cache;
array tmp = ({});
foreach( values( modules ), mapping m )
foreach( values(m->copies), RoxenModule mo )
if( mo->module_type & MODULE_USERDB )
tmp += ({ ({ mo->query( "_priority" ), mo }) });
sort( tmp );
|
96d86e | 2001-01-29 | Per Hedbor | |
|
3342dd | 2001-01-19 | Per Hedbor | | return userdb_module_cache = reverse(column(tmp,1));
}
array(AuthModule) auth_modules()
{
if( auth_module_cache )
return auth_module_cache;
array tmp = ({});
foreach( values( modules ), mapping m )
foreach( values(m->copies), RoxenModule mo )
if( mo->module_type & MODULE_AUTH )
tmp += ({ ({ mo->query( "_priority" ), mo }) });
sort( tmp );
return auth_module_cache = reverse(column(tmp,1));
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
517c7e | 2000-09-30 | Per Hedbor | | array location_modules()
|
3342dd | 2001-01-19 | Per Hedbor | |
|
cd9287 | 2000-08-15 | Johan Sundström | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!location_module_cache)
{
int i;
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | array new_location_module_cache=({ });
|
b1fca0 | 1996-11-12 | Per Hedbor | | for(i=9; i>=0; i--)
{
|
10c7e1 | 1999-12-28 | Martin Nilsson | | array(RoxenModule) d;
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule p;
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | if(d=pri[i]->location_modules) {
array level_find_files = ({});
array level_locations = ({});
foreach(d, p) {
string location;
if(p->find_file && (location = p->query_location())) {
level_find_files += ({ p->find_file });
level_locations += ({ location });
}
}
|
dffddc | 2000-10-10 | Johan Sundström | | sort(map(level_locations, sizeof), level_locations, level_find_files);
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | int j;
for (j = sizeof(level_locations); j--;) {
new_location_module_cache += ({ ({ level_locations[j],
level_find_files[j] }) });
}
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | location_module_cache = new_location_module_cache;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
return location_module_cache;
}
|
517c7e | 2000-09-30 | Per Hedbor | | array(function) filter_modules()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
if(!filter_module_cache)
{
int i;
filter_module_cache=({ });
for(i=9; i>=0; i--)
{
|
10c7e1 | 1999-12-28 | Martin Nilsson | | array(RoxenModule) d;
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule p;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(d=pri[i]->filter_modules)
foreach(d, p)
if(p->filter)
filter_module_cache+=({ p->filter });
}
}
return filter_module_cache;
}
|
1c7823 | 2000-03-13 | Per Hedbor | | void init_log_file()
{
if(log_function)
{
destruct(function_object(log_function));
log_function = 0;
}
if(query("Log"))
{
string logfile = query("LogFile");
|
f7d981 | 1997-09-12 | Per Hedbor | | if(strlen(logfile))
|
8dc382 | 2006-09-08 | Fredrik Noring | | log_function = roxen.LogFile(logfile, query("LogFileCompressor"))->write;
|
1c7823 | 2000-03-13 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | private void parse_log_formats()
{
array foo=query("LogFormat")/"\n";
|
0ab494 | 2006-10-13 | Martin Stjernholm | | log_format = ([]);
foreach(foo; int i; string b)
if(strlen(b) && b[0] != '#') {
if (sscanf (b, "%d:%*[\t ]%s", int status, b))
log_format[status] = b;
else if (sscanf (b, "*:%*[\t ]%s", b))
log_format[0] = b;
else if (sscanf (b, "%[-_.#a-zA-Z0-9*]/%[-_.#a-zA-Z0-9*]:%*[\t ]%s",
string facility, string action, b) >= 2)
log_format[facility + "/" + action] = b;
else
report_warning ("Unrecognized format on line %d "
"in log format setting: %O\n", i + 1, b);
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | void log(mapping file, RequestID request_id)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
00d8f7 | 2006-05-22 | Henrik Grubbström (Grubba) | | array(function) log_funs = logger_module_cache||logger_modules();
if (sizeof(log_funs)) {
|
72ba2c | 2006-09-15 | Marcus Wellhardh | | request_id->init_cookies(1);
|
00d8f7 | 2006-05-22 | Henrik Grubbström (Grubba) | | foreach(log_funs, function f)
if( f( request_id, file ) )
return;
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
7a243b | 2000-08-19 | Per Hedbor | | if( !log_function )
|
6533f2 | 2001-08-23 | Martin Nilsson | | return;
|
14179b | 1997-01-29 | Per Hedbor | |
|
7a243b | 2000-08-19 | Per Hedbor | | if(do_not_log_patterns &&
Roxen._match(request_id->remoteaddr, do_not_log_patterns))
|
14179b | 1997-01-29 | Per Hedbor | | return;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
7a243b | 2000-08-19 | Per Hedbor | | string form;
|
0ab494 | 2006-10-13 | Martin Stjernholm | | if(!(form=log_format[(int) file->error]))
|
7a243b | 2000-08-19 | Per Hedbor | | form = log_format[0];
|
14179b | 1997-01-29 | Per Hedbor | | if(!form) return;
|
7a243b | 2000-08-19 | Per Hedbor | |
roxen.run_log_format( form, log_function, request_id, file );
|
14179b | 1997-01-29 | Per Hedbor | | }
|
0ab494 | 2006-10-13 | Martin Stjernholm | | void log_event (string facility, string action, string resource,
void|mapping(string:mixed) info)
{
if( !log_function )
return;
if(do_not_log_patterns &&
Roxen._match("0.0.0.0", do_not_log_patterns))
return;
sscanf (facility, "%[^#]", string modname);
if (string format =
log_format[facility + "/" + action] ||
log_format[facility + "/*"] ||
modname != "" && (log_format[modname + "/" + action] ||
log_format[modname + "/*"]) ||
log_format["*/*"])
roxen.run_log_event_format (format, log_function,
facility, action, resource, info);
}
|
9c1900 | 2001-02-27 | Per Hedbor | | array(string) userinfo(string u, RequestID|void id)
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
3342dd | 2001-01-19 | Per Hedbor | |
|
cd8192 | 2000-09-19 | Johan Sundström | |
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3342dd | 2001-01-19 | Per Hedbor | | User uid;
foreach( user_databases(), UserDB m )
if( uid = m->find_user( u ) )
|
ac7745 | 2001-06-13 | Per Hedbor | | return uid->compat_userinfo(id);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | array(string) userlist(RequestID|void id)
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
3342dd | 2001-01-19 | Per Hedbor | |
|
cd8192 | 2000-09-19 | Johan Sundström | |
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3342dd | 2001-01-19 | Per Hedbor | | array(string) list = ({});
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | list |= m->list_users(id);
|
3342dd | 2001-01-19 | Per Hedbor | | return list;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | array(string) user_from_uid(int u, RequestID|void id)
|
6533f2 | 2001-08-23 | Martin Nilsson | |
|
3342dd | 2001-01-19 | Per Hedbor | |
|
cd8192 | 2000-09-19 | Johan Sundström | |
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3342dd | 2001-01-19 | Per Hedbor | | User uid;
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | if( uid = m->find_user_from_uid( u,id ) )
|
3342dd | 2001-01-19 | Per Hedbor | | return uid->compat_userinfo();
|
14179b | 1997-01-29 | Per Hedbor | | }
|
e3f466 | 2001-01-19 | Per Hedbor | | UserDB find_user_database( string name )
|
96d86e | 2001-01-29 | Per Hedbor | |
|
e3f466 | 2001-01-19 | Per Hedbor | | {
foreach( user_databases(), UserDB m )
if( m->name == name )
return m;
}
AuthModule find_auth_module( string name )
|
96d86e | 2001-01-29 | Per Hedbor | |
|
e3f466 | 2001-01-19 | Per Hedbor | | {
foreach( auth_modules(), AuthModule m )
if( m->name == name )
return m;
}
|
3342dd | 2001-01-19 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | | User authenticate( RequestID id, UserDB|void database)
|
3342dd | 2001-01-19 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | |
|
3342dd | 2001-01-19 | Per Hedbor | |
|
0cde96 | 2001-01-21 | Per Hedbor | |
|
3342dd | 2001-01-19 | Per Hedbor | | {
User u;
|
61636c | 2004-04-29 | Martin Stjernholm | | if (!zero_type (u = id->misc->authenticated_user))
return u;
|
9a4c05 | 2001-01-28 | Per Hedbor | | foreach( auth_modules(), AuthModule method )
if( u = method->authenticate( id, database ) )
return id->misc->authenticated_user = u;
|
3342dd | 2001-01-19 | Per Hedbor | | }
|
96d86e | 2001-01-29 | Per Hedbor | | mapping authenticate_throw( RequestID id, string realm,
UserDB|void database)
|
3342dd | 2001-01-19 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | |
|
3342dd | 2001-01-19 | Per Hedbor | | {
mapping m;
|
9a4c05 | 2001-01-28 | Per Hedbor | | foreach( auth_modules(), AuthModule method )
if( m = method->authenticate_throw( id, realm, database ) )
return m;
|
96d86e | 2001-01-29 | Per Hedbor | | }
User find_user( string user, RequestID|void id )
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | | {
User uid;
|
d2fcaf | 2001-01-30 | Per Hedbor | | if( id && id->misc->authenticated_user
|
ac7745 | 2001-06-13 | Per Hedbor | | && ( uid = id->misc->authenticated_user->database->find_user(user,id)))
|
96d86e | 2001-01-29 | Per Hedbor | | return uid;
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | if( uid = m->find_user( user,id ) )
|
96d86e | 2001-01-29 | Per Hedbor | | return uid;
}
|
ac7745 | 2001-06-13 | Per Hedbor | | array(string) list_users(RequestID|void id)
|
d2fcaf | 2001-01-30 | Per Hedbor | |
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
d2fcaf | 2001-01-30 | Per Hedbor | | {
array(string) list = ({});
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | list |= m->list_users(id);
|
d2fcaf | 2001-01-30 | Per Hedbor | | return list;
}
|
ac7745 | 2001-06-13 | Per Hedbor | | array(string) list_groups(RequestID|void id)
|
d2fcaf | 2001-01-30 | Per Hedbor | |
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
d2fcaf | 2001-01-30 | Per Hedbor | | {
array(string) list = ({});
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | list |= m->list_groups(id);
|
d2fcaf | 2001-01-30 | Per Hedbor | | return list;
}
|
96d86e | 2001-01-29 | Per Hedbor | | Group find_group( string group, RequestID|void id )
|
ac7745 | 2001-06-13 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | | {
Group uid;
|
d2fcaf | 2001-01-30 | Per Hedbor | | if( id && id->misc->authenticated_user
|
96d86e | 2001-01-29 | Per Hedbor | | && ( uid = id->misc->authenticated_user->database->find_group( group ) ))
return uid;
foreach( user_databases(), UserDB m )
|
ac7745 | 2001-06-13 | Per Hedbor | | if( uid = m->find_group( group,id ) )
|
96d86e | 2001-01-29 | Per Hedbor | | return uid;
|
3342dd | 2001-01-19 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | string last_modified_by(Stdio.File file, RequestID id)
|
6103bc | 1999-10-09 | Henrik Grubbström (Grubba) | | {
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat s;
|
6103bc | 1999-10-09 | Henrik Grubbström (Grubba) | | int uid;
|
9f9fc3 | 2000-02-17 | Per Hedbor | | array u;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
6103bc | 1999-10-09 | Henrik Grubbström (Grubba) | | if(objectp(file)) s=file->stat();
if(!s || sizeof(s)<5) return "A. Nonymous";
uid=s[5];
u=user_from_uid(uid, id);
if(u) return u[0];
return "A. Nonymous";
}
|
14179b | 1997-01-29 | Per Hedbor | |
private mapping internal_gopher_image(string from)
{
sscanf(from, "%s.gif", from);
sscanf(from, "%s.jpg", from);
from -= ".";
|
1c7823 | 2000-03-13 | Per Hedbor | | Stdio.File f = lopen("roxen-images/dir/"+from+".gif","r");
if (f)
|
584884 | 2000-08-28 | Per Hedbor | | return (["file":f, "type":"image/gif", "stat":f->stat(),]);
else
|
06026c | 1999-10-19 | Henrik Grubbström (Grubba) | | return 0;
|
584884 | 2000-08-28 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | }
#ifdef MODULE_LEVEL_SECURITY
|
5910aa | 2004-02-17 | Martin Stjernholm | | private mapping(RoxenModule:array) security_level_cache = set_weak_flag (([]), 1);
|
14179b | 1997-01-29 | Per Hedbor | |
|
3e3bab | 2001-01-19 | Per Hedbor | | int|mapping check_security(function|RoxenModule a, RequestID id,
void|int slevel)
|
14179b | 1997-01-29 | Per Hedbor | | {
array seclevels;
|
12a9c5 | 1997-08-11 | Henrik Grubbström (Grubba) | |
|
193535 | 1997-04-28 | Henrik Grubbström (Grubba) | |
|
5910aa | 2004-02-17 | Martin Stjernholm | | if (RoxenModule mod = Roxen.get_owning_module (a)) {
if (!(seclevels = security_level_cache[mod])) {
if(mod->query_seclevels)
seclevels = ({
mod->query_seclevels(),
mod->query("_seclvl"),
});
else
seclevels = ({0,0});
security_level_cache[mod] = seclevels;
}
|
2b8642 | 2000-06-29 | Martin Stjernholm | | }
|
5910aa | 2004-02-17 | Martin Stjernholm | | else
seclevels = ({0,0});
|
14179b | 1997-01-29 | Per Hedbor | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | | if(slevel && (seclevels[1] > slevel))
|
5a4293 | 2001-08-30 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | return 1;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | | mixed err;
|
bc0fa0 | 2001-03-08 | Per Hedbor | | if( function(RequestID:int|mapping) f = seclevels[0] )
|
5a4293 | 2001-08-30 | Per Hedbor | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | | err=catch { return f( id ); };
else
return 0;
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | | report_error("check_security(): %s:\n%s\n",
LOC_M(39, "Error during module security check"),
describe_backtrace(err));
|
18be21 | 1998-05-07 | Henrik Grubbström (Grubba) | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | | return 1;
|
14179b | 1997-01-29 | Per Hedbor | | }
#endif
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | void invalidate_cache()
|
14179b | 1997-01-29 | Per Hedbor | | {
last_module_cache = 0;
filter_module_cache = 0;
|
3342dd | 2001-01-19 | Per Hedbor | | userdb_module_cache = 0;
auth_module_cache = 0;
|
14179b | 1997-01-29 | Per Hedbor | | first_module_cache = 0;
url_module_cache = 0;
location_module_cache = 0;
logger_module_cache = 0;
file_extension_module_cache = ([]);
|
ae32d0 | 1998-03-23 | David Hedbor | | provider_module_cache = ([]);
|
14179b | 1997-01-29 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
5910aa | 2004-02-17 | Martin Stjernholm | | security_level_cache = set_weak_flag (([ ]), 1);
|
14179b | 1997-01-29 | Per Hedbor | | #endif
}
|
ec058c | 1998-07-04 | Henrik Grubbström (Grubba) | |
void clear_memory_caches()
{
invalidate_cache();
|
10c7e1 | 1999-12-28 | Martin Nilsson | | foreach(indices(otomod), RoxenModule m)
if (m && m->clear_memory_caches)
if (mixed err = catch( m->clear_memory_caches() ))
|
434bac | 2000-07-14 | Andreas Lange | | report_error("clear_memory_caches() "+
|
49cd28 | 2000-08-11 | Andreas Lange | | LOC_M(40, "failed for module %O:\n%s\n"),
|
67f60e | 2000-07-09 | Martin Nilsson | | otomod[m], describe_backtrace(err));
|
ec058c | 1998-07-04 | Henrik Grubbström (Grubba) | | }
|
7de44b | 2000-09-13 | Jonas Wallden | |
|
1b664a | 2004-03-08 | Jonas Wallden | | static array(string) draw_saturation_bar(int hue,int brightness, int where,
int small_version)
|
fc9433 | 1997-10-25 | Per Hedbor | | {
|
1b664a | 2004-03-08 | Jonas Wallden | | Image.Image bar =
small_version ? Image.Image(16, 128) : Image.Image(30, 256);
|
fc9433 | 1997-10-25 | Per Hedbor | | for(int i=0;i<128;i++)
{
|
4205aa | 2004-03-06 | Jonas Wallden | | int j = i * 2;
array color = hsv_to_rgb(hue, 255 - j, brightness);
|
1b664a | 2004-03-08 | Jonas Wallden | | if (small_version) {
bar->line(0, i, 15, i, @color);
} else {
bar->line(0, j, 29, j, @color);
bar->line(0, j + 1,29, j + 1, @color);
}
|
fc9433 | 1997-10-25 | Per Hedbor | | }
|
e2d577 | 2004-03-13 | Jonas Wallden | |
if (where >= 0 && where <= 255) {
where = 255 - where;
int hilite = (brightness > 128) ? 0 : 255;
if (small_version)
bar->line(0, where / 2, 15, where / 2, hilite, hilite, hilite);
else
bar->line(0, where, 29, where, hilite, hilite, hilite);
}
|
1b664a | 2004-03-08 | Jonas Wallden | |
|
2a346d | 2000-09-19 | Per Hedbor | | #if constant(Image.JPEG) && constant(Image.JPEG.encode)
|
7de44b | 2000-09-13 | Jonas Wallden | | return ({ Image.JPEG.encode(bar), "image/jpeg" });
|
2a346d | 2000-09-19 | Per Hedbor | | #else
return ({ Image.PNG.encode(bar), "image/png" });
|
7de44b | 2000-09-13 | Jonas Wallden | | #endif
|
fc9433 | 1997-10-25 | Per Hedbor | | }
|
307201 | 2005-10-23 | Jonas Wallden | | #if constant(Image.GIF) && constant(Image.PNG)
array(mapping) spinner_data = 0;
static array(string) draw_spinner(string bgcolor)
{
array color = parse_color(bgcolor);
if (!spinner_data) {
|
fdac49 | 2006-02-23 | Jonas Wallden | | array(mapping) temp_spinner_data = ({ });
|
307201 | 2005-10-23 | Jonas Wallden | | for (int i = 0; i < 12; i++) {
string src = lopen("roxen-images/spinner" + i + ".png", "r")->read();
|
fdac49 | 2006-02-23 | Jonas Wallden | | temp_spinner_data += ({ Image.PNG._decode(src) });
|
307201 | 2005-10-23 | Jonas Wallden | | }
|
fdac49 | 2006-02-23 | Jonas Wallden | | spinner_data = temp_spinner_data;
|
307201 | 2005-10-23 | Jonas Wallden | | }
array(Image.Image) frames = ({ });
foreach(spinner_data, mapping data) {
Image.Image frame = Image.Image(17, 17, @color);
frame->paste_mask(data->image, data->alpha);
frames += ({ frame });
}
Image.Colortable colors = Image.Colortable(frames[0]);
string res = Image.GIF.header_block(17, 17, colors);
foreach(frames, Image.Image frame)
res += Image.GIF.render_block(frame, colors, 0, 0, 0, 1);
res +=
Image.GIF.netscape_loop_block(0) +
Image.GIF.end_block();
return ({ res, "image/gif" });
}
#endif
|
14179b | 1997-01-29 | Per Hedbor | |
|
a6ef1f | 2000-03-28 | Johan Sundström | |
|
2a346d | 2000-09-19 | Per Hedbor | | private mapping internal_roxen_image( string from, RequestID id )
|
14179b | 1997-01-29 | Per Hedbor | | {
sscanf(from, "%s.gif", from);
sscanf(from, "%s.jpg", from);
|
2b658c | 2000-02-07 | Per Hedbor | | sscanf(from, "%s.xcf", from);
sscanf(from, "%s.png", from);
|
fc9433 | 1997-10-25 | Per Hedbor | |
|
307201 | 2005-10-23 | Jonas Wallden | | #if constant(Image.GIF) && constant(Image.PNG)
if (has_prefix(from, "spinner-")) {
array(string) spinner = draw_spinner(from[8..]);
return ([ "data" : spinner[0],
"type" : spinner[1],
"stat" : ({ 0, 0, 0, 900000000, 0, 0, 0 }) ]);
}
#endif
|
1c7823 | 2000-03-13 | Per Hedbor | |
|
fc9433 | 1997-10-25 | Per Hedbor | | int hue,bright,w;
|
1b664a | 2004-03-08 | Jonas Wallden | | string colorbar;
if(sscanf(from, "%s:%d,%d,%d", colorbar, hue, bright,w)==4) {
array bar = draw_saturation_bar(hue, bright, w,
colorbar == "colorbar-small");
|
7de44b | 2000-09-13 | Jonas Wallden | | return Roxen.http_string_answer(bar[0], bar[1]);
}
|
fc9433 | 1997-10-25 | Per Hedbor | |
|
2b658c | 2000-02-07 | Per Hedbor | | Stdio.File f;
|
731076 | 2000-09-19 | Per Hedbor | | if( !id->misc->internal_get )
if(f = lopen("roxen-images/"+from+".gif", "r"))
return (["file":f, "type":"image/gif", "stat":f->stat()]);
|
1c7823 | 2000-03-13 | Per Hedbor | | if(f = lopen("roxen-images/"+from+".png", "r"))
|
584884 | 2000-08-28 | Per Hedbor | | return (["file":f, "type":"image/png", "stat":f->stat()]);
|
731076 | 2000-09-19 | Per Hedbor | |
if(f = lopen("roxen-images/"+from+".jpg", "r"))
return (["file":f, "type":"image/jpeg", "stat":f->stat()]);
|
1c7823 | 2000-03-13 | Per Hedbor | | if(f = lopen("roxen-images/"+from+".xcf", "r"))
|
584884 | 2000-08-28 | Per Hedbor | | return (["file":f, "type":"image/x-gimp-image", "stat":f->stat()]);
|
731076 | 2000-09-19 | Per Hedbor | |
if(f = lopen("roxen-images/"+from+".gif", "r"))
return (["file":f, "type":"image/gif", "stat":f->stat()]);
|
2b658c | 2000-02-07 | Per Hedbor | |
return 0;
|
14179b | 1997-01-29 | Per Hedbor | | }
mapping (mixed:function|int) locks = ([]);
#ifdef THREADS
|
e5bad2 | 1998-02-10 | Per Hedbor | |
|
e6aff0 | 1997-05-25 | Henrik Grubbström (Grubba) | |
|
55a89e | 1997-09-14 | Per Hedbor | | mapping locked = ([]), thread_safe = ([]);
|
e351dd | 1999-11-29 | Per Hedbor | | mixed _lock(object|function f)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3e3bab | 2001-01-19 | Per Hedbor | | Thread.MutexKey key;
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | function|int l;
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(module_lock);
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | if (functionp(f)) {
f = function_object(f);
}
|
55a89e | 1997-09-14 | Per Hedbor | | if (l = locks[f])
{
if (l != -1)
{
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | |
|
beb1f2 | 1998-05-23 | Mattias Wingstedt | | catch{
|
91d3c3 | 2001-03-12 | Martin Nilsson | |
|
55a89e | 1997-09-14 | Per Hedbor | | locked[f]++;
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | key = l();
|
beb1f2 | 1998-05-23 | Mattias Wingstedt | | };
|
55a89e | 1997-09-14 | Per Hedbor | | } else
thread_safe[f]++;
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | } else if (f->thread_safe) {
locks[f]=-1;
|
55a89e | 1997-09-14 | Per Hedbor | | thread_safe[f]++;
|
14179b | 1997-01-29 | Per Hedbor | | } else {
|
55a89e | 1997-09-14 | Per Hedbor | | if (!locks[f])
{
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | l = Thread.Mutex()->lock;
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | if (!locks[f]) {
locks[f]=l;
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
91d3c3 | 2001-03-12 | Martin Nilsson | |
|
55a89e | 1997-09-14 | Per Hedbor | | locked[f]++;
|
1fab6f | 1997-09-03 | Henrik Grubbström (Grubba) | | key = l();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(module_lock);
|
14179b | 1997-01-29 | Per Hedbor | | return key;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | #define LOCK(X) key=_lock(X)
|
d7b087 | 1997-08-31 | Per Hedbor | | #define UNLOCK() do{key=0;}while(0)
|
14179b | 1997-01-29 | Per Hedbor | | #else
#define LOCK(X)
|
c95bd5 | 1998-01-30 | Henrik Grubbström (Grubba) | | #define UNLOCK()
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | string examine_return_mapping(mapping m)
{
string res;
if (m->extra_heads)
m->extra_heads=mkmapping(Array.map(indices(m->extra_heads),
lower_case),
values(m->extra_heads));
else
m->extra_heads=([]);
switch (m->error||200)
{
case 302:
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if (m->extra_heads &&
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | (m->extra_heads->location))
|
dff832 | 2003-10-20 | Martin Stjernholm | | res = sprintf("Returned redirect to %O ", m->extra_heads->location);
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | else
|
1a89f4 | 2000-08-14 | Martin Stjernholm | | res = "Returned redirect, but no location header. ";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | break;
case 401:
if (m->extra_heads["www-authenticate"])
|
dff832 | 2003-10-20 | Martin Stjernholm | | res = sprintf("Returned authentication failed: %O ",
|
67f60e | 2000-07-09 | Martin Nilsson | | m->extra_heads["www-authenticate"]);
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | else
|
1a89f4 | 2000-08-14 | Martin Stjernholm | | res = "Returned authentication failed. ";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | break;
case 200:
|
1a89f4 | 2000-08-14 | Martin Stjernholm | | res = "Returned ok. ";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | break;
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | default:
|
dff832 | 2003-10-20 | Martin Stjernholm | | res = sprintf("Returned %O. ", m->error);
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | }
if (!zero_type(m->len))
if (m->len<0)
|
434bac | 2000-07-14 | Andreas Lange | | res += "No data ";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | else
|
dff832 | 2003-10-20 | Martin Stjernholm | | res += sprintf("%O bytes ", m->len);
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | else if (stringp(m->data))
|
434bac | 2000-07-14 | Andreas Lange | | res += sprintf("%d bytes ", strlen(m->data));
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | | else if (objectp(m->file))
if (catch {
|
1f4a6c | 2000-08-28 | Per Hedbor | | Stat a=m->file->stat();
|
dff832 | 2003-10-20 | Martin Stjernholm | | res += sprintf("%O bytes ", a[1]-m->file->tell());
|
b46164 | 1998-10-11 | Henrik Grubbström (Grubba) | | })
|
1a89f4 | 2000-08-14 | Martin Stjernholm | | res += "? bytes ";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | |
|
1a89f4 | 2000-08-14 | Martin Stjernholm | | if (m->data) res += "(static)";
|
434bac | 2000-07-14 | Andreas Lange | | else if (m->file) res += "(open file)";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | |
|
dffa22 | 2000-12-10 | Per Hedbor | | if (stringp(m->extra_heads["content-type"]) ||
|
b46164 | 1998-10-11 | Henrik Grubbström (Grubba) | | stringp(m->type)) {
|
dff832 | 2003-10-20 | Martin Stjernholm | | res += sprintf(" of %O", m->type||m->extra_heads["content-type"]);
|
b46164 | 1998-10-11 | Henrik Grubbström (Grubba) | | }
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | |
|
67f60e | 2000-07-09 | Martin Nilsson | | res+="<br />";
|
a1334f | 1998-02-20 | Mirar (Pontus Hagland) | |
return res;
}
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | |
multiset(DAVLock) find_locks(string path, int(0..1) recursive,
int(0..1) exclude_shared, RequestID id)
{
|
368141 | 2004-05-07 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_ENTER(0, "find_locks(%O, %O, %O, X)",
path, recursive, exclude_shared);
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | multiset(DAVLock) locks = (<>);
foreach(location_module_cache||location_modules(),
[string loc, function func])
{
|
368141 | 2004-05-07 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_ENTER(function_object(func),
"Finding locks in %O.", loc);
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | string subpath;
if (has_prefix(path, loc)) {
subpath = path[sizeof(loc)..];
} else if (recursive && has_prefix(loc, path)) {
subpath = "/";
} else {
|
e4acd9 | 2004-05-06 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("Skip this module.");
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | continue;
}
|
e4acd9 | 2004-05-06 | Henrik Grubbström (Grubba) | | TRACE_ENTER(sprintf("subpath: %O", subpath),
function_object(func)->find_locks);
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | multiset(DAVLock) sub_locks =
function_object(func)->find_locks(subpath, recursive,
exclude_shared, id);
|
e4acd9 | 2004-05-06 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
if (sub_locks) {
|
368141 | 2004-05-07 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_LEAVE("Got some locks: %O", sub_locks);
|
e4acd9 | 2004-05-06 | Henrik Grubbström (Grubba) | | locks |= sub_locks;
} else {
TRACE_LEAVE("Got no locks.");
}
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | }
|
368141 | 2004-05-07 | Henrik Grubbström (Grubba) | | SIMPLE_TRACE_LEAVE("Returning %O", locks);
|
3e0917 | 2004-05-03 | Henrik Grubbström (Grubba) | | return locks;
}
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
|
c85afa | 2004-05-07 | Martin Stjernholm | | DAVLock|LockFlag check_locks(string path, int(0..1) recursive, RequestID id)
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | {
|
c85afa | 2004-05-07 | Martin Stjernholm | | LockFlag state = 0;
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | foreach(location_module_cache||location_modules(),
[string loc, function func])
{
string subpath;
|
c85afa | 2004-05-07 | Martin Stjernholm | | int check_above;
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | if (has_prefix(path, loc)) {
subpath = path[sizeof(loc)..];
} else if (recursive && has_prefix(loc, path)) {
|
c85afa | 2004-05-07 | Martin Stjernholm | | subpath = "";
check_above = 1;
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | } else {
continue;
}
|
c85afa | 2004-05-07 | Martin Stjernholm | | int|DAVLock lock_info =
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | function_object(func)->check_locks(subpath, recursive, id);
|
9f8a91 | 2004-05-04 | Henrik Grubbström (Grubba) | | if (objectp(lock_info)) {
|
c85afa | 2004-05-07 | Martin Stjernholm | | if (!check_above) {
|
9f8a91 | 2004-05-04 | Henrik Grubbström (Grubba) | | return lock_info;
} else {
|
c85afa | 2004-05-07 | Martin Stjernholm | | lock_info = LOCK_OWN_BELOW;
|
9f8a91 | 2004-05-04 | Henrik Grubbström (Grubba) | | }
}
|
c85afa | 2004-05-07 | Martin Stjernholm | | else
if (check_above && (lock_info & 1))
lock_info &= ~1;
|
9f8a91 | 2004-05-04 | Henrik Grubbström (Grubba) | | if (lock_info > state) state = lock_info;
|
c85afa | 2004-05-07 | Martin Stjernholm | | if (state == LOCK_EXCL_AT) return LOCK_EXCL_AT;
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | }
|
9f8a91 | 2004-05-04 | Henrik Grubbström (Grubba) | | return state;
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | }
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | static multiset(DAVLock) active_locks = (<>);
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | |
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | | mapping(string:mixed) unlock_file(string path, DAVLock lock, RequestID id)
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | {
if (!has_suffix(path, "/")) path+="/";
foreach(location_module_cache||location_modules(),
[string loc, function func])
{
if (has_prefix(path, loc)) {
mapping(string:mixed) ret =
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | | function_object(func)->unlock_file(path[sizeof(loc)..], lock, id);
if (ret) return ret;
} else if (lock->recursive && has_prefix(loc, path)) {
mapping(string:mixed) ret =
function_object(func)->unlock_file("/", lock, id);
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
if (ret) return ret;
}
}
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | active_locks[lock] = 0;
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | |
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | return 0;
}
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | |
int expire_locks(RequestID id)
{
int t = time(1);
int min_time = 0x7fffffff;
foreach(active_locks; DAVLock lock;) {
if (lock->expiry_time) {
if (lock->expiry_time < t) {
unlock_file(lock->path, lock, id);
} else if (lock->expiry_time < min_time) {
min_time = lock->expiry_time;
}
}
}
return min_time - t;
}
static void expire_lock_loop()
{
int t = expire_locks(0);
if (sizeof(active_locks)) {
if (t < 3600) {
roxen.background_run(t, expire_lock_loop);
} else {
roxen.background_run(3600, expire_lock_loop);
}
}
}
void refresh_lock(DAVLock lock)
{
if (lock->expiry_delta) {
lock->expiry_time = lock->expiry_delta + time(1);
}
}
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
d1728c | 2004-05-14 | Henrik Grubbström (Grubba) | |
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
mapping(string:mixed)|DAVLock lock_file(string path,
int(0..1) recursive,
string lockscope,
string locktype,
|
fefe70 | 2004-05-14 | Henrik Grubbström (Grubba) | | int(0..) expiry_delta,
|
73f932 | 2004-05-06 | Martin Stjernholm | | array(Parser.XML.Tree.Node) owner,
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | RequestID id)
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | {
if (!has_suffix(path, "/")) path+="/";
|
c85afa | 2004-05-07 | Martin Stjernholm | | int|DAVLock lock_info = check_locks(path, recursive, id);
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
if (!intp(lock_info)) {
|
476e9c | 2004-05-10 | Henrik Grubbström (Grubba) | | if (id->request_headers->if) {
return Roxen.http_status(412, "Precondition Failed");
} else {
return Roxen.http_status(423, "Locked");
}
|
c85afa | 2004-05-07 | Martin Stjernholm | | } else if (lockscope == "DAV:exclusive" ?
lock_info >= LOCK_SHARED_BELOW :
lock_info >= LOCK_OWN_BELOW) {
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
return Roxen.http_status(423, "Locked");
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | |
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
803cdc | 2004-05-03 | Henrik Grubbström (Grubba) | | string locktoken = "opaquelocktoken:" + roxen->new_uuid_string();
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | DAVLock lock = DAVLock(locktoken, path, recursive, lockscope, locktype,
|
fefe70 | 2004-05-14 | Henrik Grubbström (Grubba) | | expiry_delta, owner);
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | foreach(location_module_cache||location_modules(),
[string loc, function func])
{
string subpath;
if (has_prefix(path, loc)) {
subpath = path[sizeof(loc)..];
} else if (recursive && has_prefix(loc, path)) {
subpath = "/";
} else {
continue;
}
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | mapping(string:mixed) lock_error =
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | function_object(func)->lock_file(subpath, lock, id);
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | if (lock_error) {
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | |
foreach(location_module_cache||location_modules(),
[string loc2, function func2])
{
if (has_prefix(path, loc2)) {
mapping(string:mixed) ret =
function_object(func2)->unlock_file(path[sizeof(loc2)..],
lock, id);
} else if (recursive && has_prefix(loc2, path)) {
mapping(string:mixed) ret =
function_object(func2)->unlock_file("/", lock, id);
}
if (func == func2) break;
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
987407 | 2004-05-04 | Henrik Grubbström (Grubba) | |
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | return lock_error;
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
}
|
4dfab2 | 2004-05-14 | Henrik Grubbström (Grubba) | | if (expiry_delta) {
if (!sizeof(active_locks)) {
active_locks[lock] = 1;
expire_lock_loop();
} else {
active_locks[lock] = 1;
}
}
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | |
|
38c76b | 2004-04-30 | Henrik Grubbström (Grubba) | | return lock;
|
29f229 | 2004-04-28 | Henrik Grubbström (Grubba) | | }
|
cd9287 | 2000-08-15 | Johan Sundström | | mapping|int(-1..0) low_get_file(RequestID id, int|void no_magic)
|
806204 | 2004-04-20 | Henrik Grubbström (Grubba) | |
|
cd9287 | 2000-08-15 | Johan Sundström | |
|
14179b | 1997-01-29 | Per Hedbor | | {
#ifdef MODULE_LEVEL_SECURITY
int slevel;
#endif
#ifdef THREADS
|
3e3bab | 2001-01-19 | Per Hedbor | | Thread.MutexKey key;
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
db5f6b | 2001-07-31 | Per Hedbor | |
id->not_query = VFS.normalize_path( id->not_query );
|
5655dc | 2001-06-06 | Per Hedbor | |
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Request for %s", id->not_query), 0);
|
14179b | 1997-01-29 | Per Hedbor | |
string file=id->not_query;
string loc;
function funp;
mixed tmp, tmp2;
|
cd9287 | 2000-08-15 | Johan Sundström | | mapping|object(Stdio.File)|int fid;
|
14179b | 1997-01-29 | Per Hedbor | |
if(!no_magic)
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(internal_magic);
|
41b77c | 1999-07-15 | David Hedbor | | #ifndef NO_INTERNAL_HACK
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | |
|
fd9302 | 2000-05-05 | Martin Nilsson | | string type;
|
67f60e | 2000-07-09 | Martin Nilsson | | if(sizeof(file) > 17 &&
|
51d4d2 | 2001-01-04 | Martin Nilsson | | #if ROXEN_COMPAT <= 2.1
|
67f60e | 2000-07-09 | Martin Nilsson | | (file[0] == '/') &&
|
cd9287 | 2000-08-15 | Johan Sundström | | sscanf(file, "%*s/internal-%s-%[^/]", type, loc) == 3
|
67f60e | 2000-07-09 | Martin Nilsson | | #else
|
cd9287 | 2000-08-15 | Johan Sundström | | sscanf(file, "/internal-%s-%[^/]", type, loc) == 2
|
67f60e | 2000-07-09 | Martin Nilsson | | #endif
|
cd9287 | 2000-08-15 | Johan Sundström | | ) {
|
41b77c | 1999-07-15 | David Hedbor | | switch(type) {
|
fd9302 | 2000-05-05 | Martin Nilsson | | case "roxen":
|
d738ba | 2002-04-10 | Jonas Wallden | |
|
f91060 | 2004-05-20 | Jonas Wallden | | RAISE_CACHE(60 * 60 * 24 * 365);
|
beddd1 | 2003-11-25 | Anders Johansson | | PROTO_CACHE();
|
d738ba | 2002-04-10 | Jonas Wallden | |
|
a7d034 | 2000-11-13 | Martin Nilsson | | TRACE_LEAVE("Magic internal roxen image");
|
5eb283 | 2001-01-03 | Martin Nilsson | | if(loc=="unit" || loc=="pixel-of-destiny")
|
9c1900 | 2001-02-27 | Per Hedbor | | {
TIMER_END(internal_magic);
return (["data":"GIF89a\1\0\1\0\200ÿ\0ÀÀÀ\0\0\0!ù\4\1\0\0\0\0,"
"\0\0\0\0\1\0\1\0\0\1\1""2\0;",
|
2f51ba | 2002-03-22 | Martin Stjernholm | | "type":"image/gif",
"stat": ({0, 0, 0, 900000000, 0, 0, 0})]);
|
9c1900 | 2001-02-27 | Per Hedbor | | }
|
5eb283 | 2001-01-03 | Martin Nilsson | | if(has_prefix(loc, "pixel-"))
|
9c1900 | 2001-02-27 | Per Hedbor | | {
TIMER_END(internal_magic);
return (["data":sprintf("GIF89a\1\0\1\0\200\0\0\0\0\0%c%c%c,\0\0\0"
"\0\1\0\1\0\0\2\2L\1\0;",
|
5eb283 | 2001-01-03 | Martin Nilsson | | @parse_color(loc[6..])),
|
2f51ba | 2002-03-22 | Martin Stjernholm | | "type":"image/gif",
"stat": ({0, 0, 0, 900000000, 0, 0, 0})]);
|
9c1900 | 2001-02-27 | Per Hedbor | | }
TIMER_END(internal_magic);
|
2a346d | 2000-09-19 | Per Hedbor | | return internal_roxen_image(loc, id);
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | case "gopher":
|
a7d034 | 2000-11-13 | Martin Nilsson | | TRACE_LEAVE("Magic internal gopher image");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(internal_magic);
|
14179b | 1997-01-29 | Per Hedbor | | return internal_gopher_image(loc);
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | }
#endif
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
9ac033 | 2002-11-05 | Anders Johansson | | if(has_prefix(file, internal_location))
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Magic internal module location", 0);
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule module;
|
5839c3 | 1999-01-22 | Marcus Comstedt | | string name, rest;
function find_internal;
|
9ac033 | 2002-11-05 | Anders Johansson | | if(2==sscanf(file[strlen(internal_location)..], "%s/%s", name, rest) &&
|
5839c3 | 1999-01-22 | Marcus Comstedt | | (module = find_module(replace(name, "!", "#"))) &&
(find_internal = module->find_internal))
{
#ifdef MODULE_LEVEL_SECURITY
if(tmp2 = check_security(find_internal, id, slevel))
if(intp(tmp2))
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission to access module denied.");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | find_internal = 0;
} else {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Request denied.");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(internal_magic);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return tmp2;
}
#endif
|
41b77c | 1999-07-15 | David Hedbor | | if(find_internal)
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Calling find_internal()...", find_internal);
|
471705 | 2001-05-07 | Per Hedbor | | PROF_ENTER("find_internal","location");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | LOCK(find_internal);
fid=find_internal( rest, id );
UNLOCK();
|
02c664 | 2001-08-22 | Martin Stjernholm | |
TRACE_LEAVE("");
|
471705 | 2001-05-07 | Per Hedbor | | PROF_LEAVE("find_internal","location");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(fid)
{
if(mappingp(fid))
{
TRACE_LEAVE("");
TRACE_LEAVE(examine_return_mapping(fid));
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(internal_magic);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return fid;
}
else
{
#ifdef MODULE_LEVEL_SECURITY
int oslevel = slevel;
|
e28079 | 2004-03-03 | Anders Johansson | | array slca;
if(slca = security_level_cache[ Roxen.get_owning_module (find_internal) ])
slevel = slca[1];
|
5910aa | 2004-02-17 | Martin Stjernholm | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | |
id->misc->seclevel = slevel;
#endif
if(objectp(fid))
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned open filedescriptor. "
|
5839c3 | 1999-01-22 | Marcus Comstedt | | #ifdef MODULE_LEVEL_SECURITY
+(slevel != oslevel?
|
434bac | 2000-07-14 | Andreas Lange | | sprintf(" The security level is now %d.", slevel):"")
|
5839c3 | 1999-01-22 | Marcus Comstedt | | #endif
|
67f60e | 2000-07-09 | Martin Nilsson | | );
|
5839c3 | 1999-01-22 | Marcus Comstedt | | else
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned directory indicator."
|
5839c3 | 1999-01-22 | Marcus Comstedt | | #ifdef MODULE_LEVEL_SECURITY
+(oslevel != slevel?
|
434bac | 2000-07-14 | Andreas Lange | | sprintf(" The security level is now %d.", slevel):"")
|
5839c3 | 1999-01-22 | Marcus Comstedt | | #endif
);
}
} else
TRACE_LEAVE("");
} else
TRACE_LEAVE("");
} else
TRACE_LEAVE("");
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(internal_magic);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(!fid)
{
|
14179b | 1997-01-29 | Per Hedbor | | #ifdef URL_MODULES
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(url_modules);
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(url_module_cache||url_modules(), funp)
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
471705 | 2001-05-07 | Per Hedbor | | PROF_ENTER(Roxen.get_owning_module(funp)->module_name,"url module");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | LOCK(funp);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("URL module", funp);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | tmp=funp( id, file );
UNLOCK();
|
471705 | 2001-05-07 | Per Hedbor | | PROF_LEAVE(Roxen.get_owning_module(funp)->module_name,"url module");
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
if(mappingp(tmp))
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(url_modules);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return tmp;
}
if(objectp( tmp ))
{
|
a51a90 | 2001-11-12 | Martin Stjernholm | | mixed err;
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->get_file_nest++;
|
5839c3 | 1999-01-22 | Marcus Comstedt | | err = catch {
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if( id->misc->get_file_nest < 20 )
|
5839c3 | 1999-01-22 | Marcus Comstedt | | tmp = (id->conf || this_object())->low_get_file( tmp, no_magic );
else
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Too deep recursion");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | error("Too deep recursion in roxen::get_file() while mapping "
+file+".\n");
}
};
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->get_file_nest = 0;
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(err) throw(err);
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(url_modules);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return tmp;
}
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(url_modules);
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(location_modules);
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(location_module_cache||location_modules(), tmp)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
5839c3 | 1999-01-22 | Marcus Comstedt | | loc = tmp[0];
|
73f932 | 2004-05-06 | Martin Stjernholm | | if(has_prefix(file, loc))
|
5839c3 | 1999-01-22 | Marcus Comstedt | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Location module [%s] ", loc), tmp[1]);
|
df8d71 | 1998-02-27 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(tmp2 = check_security(tmp[1], id, slevel))
if(intp(tmp2))
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission to access module denied.");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | continue;
} else {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Request denied.");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(location_modules);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return tmp2;
}
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
7937df | 2001-05-16 | Per Hedbor | | PROF_ENTER(Roxen.get_owning_module(tmp[1])->module_name,"location");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Calling find_file()...", 0);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | LOCK(tmp[1]);
fid=tmp[1]( file[ strlen(loc) .. ] + id->extra_extension, id);
UNLOCK();
|
b8b107 | 2000-03-24 | Per Hedbor | | TRACE_LEAVE("");
|
7937df | 2001-05-16 | Per Hedbor | | PROF_LEAVE(Roxen.get_owning_module(tmp[1])->module_name,"location");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(fid)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
5839c3 | 1999-01-22 | Marcus Comstedt | | id->virtfile = loc;
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(mappingp(fid))
{
|
fe616a | 2003-06-10 | Anders Johansson | | TRACE_LEAVE("");
|
5839c3 | 1999-01-22 | Marcus Comstedt | | TRACE_LEAVE(examine_return_mapping(fid));
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(location_modules);
|
5839c3 | 1999-01-22 | Marcus Comstedt | | return fid;
}
else
{
|
14179b | 1997-01-29 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
5839c3 | 1999-01-22 | Marcus Comstedt | | int oslevel = slevel;
|
e28079 | 2004-03-03 | Anders Johansson | | array slca;
if(slca = security_level_cache[ Roxen.get_owning_module (tmp[1]) ])
slevel = slca[1];
|
5910aa | 2004-02-17 | Martin Stjernholm | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | |
id->misc->seclevel = slevel;
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
5839c3 | 1999-01-22 | Marcus Comstedt | | if(objectp(fid))
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned open filedescriptor."
|
41d0f9 | 1998-02-20 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
5839c3 | 1999-01-22 | Marcus Comstedt | | +(slevel != oslevel?
|
434bac | 2000-07-14 | Andreas Lange | | sprintf(" The security level is now %d.", slevel):"")
|
41d0f9 | 1998-02-20 | Per Hedbor | | #endif
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
67f60e | 2000-07-09 | Martin Nilsson | | );
|
5839c3 | 1999-01-22 | Marcus Comstedt | | else
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned directory indicator."
|
41d0f9 | 1998-02-20 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
5839c3 | 1999-01-22 | Marcus Comstedt | | +(oslevel != slevel?
|
434bac | 2000-07-14 | Andreas Lange | | sprintf(" The security level is now %d.", slevel):"")
|
41d0f9 | 1998-02-20 | Per Hedbor | | #endif
|
5839c3 | 1999-01-22 | Marcus Comstedt | | );
break;
}
} else
TRACE_LEAVE("");
|
41b77c | 1999-07-15 | David Hedbor | | } else if(strlen(loc)-1==strlen(file) && file+"/" == loc) {
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
5839c3 | 1999-01-22 | Marcus Comstedt | |
|
67f60e | 2000-07-09 | Martin Nilsson | |
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Automatic redirect to location_module.", tmp[1]);
|
fe616a | 2003-06-10 | Anders Johansson | | TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | |
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
f49131 | 2004-10-11 | Martin Stjernholm | | string new_query = Roxen.http_encode_invalids(id->not_query) + "/" +
|
41b77c | 1999-07-15 | David Hedbor | | (id->query?("?"+id->query):"");
|
fd9302 | 2000-05-05 | Martin Nilsson | | new_query=Roxen.add_pre_state(new_query, id->prestate);
|
a8f1b3 | 2000-01-31 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(location_modules);
|
dfe036 | 2000-03-19 | Martin Nilsson | | return Roxen.http_redirect(new_query, id);
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(location_modules);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | if(fid == -1)
{
|
41d0f9 | 1998-02-20 | Per Hedbor | | if(no_magic)
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("No magic requested. Returning -1.");
|
41d0f9 | 1998-02-20 | Per Hedbor | | return -1;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(directory_module);
|
14179b | 1997-01-29 | Per Hedbor | | if(dir_module)
{
|
7937df | 2001-05-16 | Per Hedbor | | PROF_ENTER(dir_module->module_name,"directory");
|
14179b | 1997-01-29 | Per Hedbor | | LOCK(dir_module);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Directory module", dir_module);
|
14179b | 1997-01-29 | Per Hedbor | | fid = dir_module->parse_directory(id);
|
fe616a | 2003-06-10 | Anders Johansson | | TRACE_LEAVE("");
|
14179b | 1997-01-29 | Per Hedbor | | UNLOCK();
|
7937df | 2001-05-16 | Per Hedbor | | PROF_LEAVE(dir_module->module_name,"directory");
|
14179b | 1997-01-29 | Per Hedbor | | }
else
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("No directory module. Returning 'no such file'");
|
14179b | 1997-01-29 | Per Hedbor | | return 0;
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(directory_module);
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(mappingp(fid))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
41d0f9 | 1998-02-20 | Per Hedbor | | return (mapping)fid;
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(extension_module);
|
41b77c | 1999-07-15 | David Hedbor | | if(objectp(fid) &&
|
f511c5 | 2001-08-31 | Per Hedbor | | (tmp = file_extension_modules(loc =
lower_case(Roxen.extension(id->not_query,
id)))))
|
517c7e | 2000-09-30 | Per Hedbor | | {
|
14179b | 1997-01-29 | Per Hedbor | | foreach(tmp, funp)
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Extension module [%s] ", loc), funp);
|
14179b | 1997-01-29 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
if(tmp=check_security(funp, id, slevel))
if(intp(tmp))
{
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission to access module denied.");
|
14179b | 1997-01-29 | Per Hedbor | | continue;
}
else
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission denied");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(extension_module);
|
14179b | 1997-01-29 | Per Hedbor | | return tmp;
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
7937df | 2001-05-16 | Per Hedbor | | PROF_ENTER(Roxen.get_owning_module(funp)->module_name,"ext");
|
14179b | 1997-01-29 | Per Hedbor | | LOCK(funp);
tmp=funp(fid, loc, id);
UNLOCK();
|
7937df | 2001-05-16 | Per Hedbor | | PROF_LEAVE(Roxen.get_owning_module(funp)->module_name,"ext");
|
14179b | 1997-01-29 | Per Hedbor | | if(tmp)
{
if(!objectp(tmp))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(extension_module);
|
14179b | 1997-01-29 | Per Hedbor | | return tmp;
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
cd9287 | 2000-08-15 | Johan Sundström | | if(fid && tmp != fid)
|
41b77c | 1999-07-15 | David Hedbor | | destruct(fid);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned new open file");
|
14179b | 1997-01-29 | Per Hedbor | | fid = tmp;
break;
|
41d0f9 | 1998-02-20 | Per Hedbor | | } else
TRACE_LEAVE("");
|
14179b | 1997-01-29 | Per Hedbor | | }
|
41b77c | 1999-07-15 | David Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(extension_module);
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | if(objectp(fid))
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(content_type_module);
|
41b77c | 1999-07-15 | David Hedbor | | if(stringp(id->extension)) {
|
14179b | 1997-01-29 | Per Hedbor | | id->not_query += id->extension;
|
f511c5 | 2001-08-31 | Per Hedbor | | loc = lower_case(Roxen.extension(id->not_query, id));
|
41b77c | 1999-07-15 | David Hedbor | | }
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Content-type mapping module", types_module);
|
41b77c | 1999-07-15 | David Hedbor | | tmp=type_from_filename(id->not_query, 1, loc);
|
3d9458 | 2000-07-31 | Martin Nilsson | | TRACE_LEAVE(tmp?sprintf("Returned type %s %s.", tmp[0], tmp[1]||"")
|
434bac | 2000-07-14 | Andreas Lange | | : "Missing type.");
|
14179b | 1997-01-29 | Per Hedbor | | if(tmp)
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
TRACE_LEAVE("");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(content_type_module);
|
14179b | 1997-01-29 | Per Hedbor | | return ([ "file":fid, "type":tmp[0], "encoding":tmp[1] ]);
|
10c7e1 | 1999-12-28 | Martin Nilsson | | }
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(content_type_module);
|
14179b | 1997-01-29 | Per Hedbor | | return ([ "file":fid, ]);
}
|
9c1900 | 2001-02-27 | Per Hedbor | |
|
41d0f9 | 1998-02-20 | Per Hedbor | | if(!fid)
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned 'no such file'.");
|
41d0f9 | 1998-02-20 | Per Hedbor | | else
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning data");
|
14179b | 1997-01-29 | Per Hedbor | | return fid;
}
|
687762 | 2004-04-19 | Martin Stjernholm | | #define TRY_FIRST_MODULES(FILE, RECURSE_CALL) do { \
TIMER_START(first_modules); \
foreach(first_module_cache||first_modules(), function funp) \
{ \
TRACE_ENTER ("First try module", funp); \
if(FILE = funp( id )) { \
TRACE_LEAVE ("Got response"); \
break; \
} \
TRACE_LEAVE ("No response"); \
if(id->conf != this_object()) { \
TRACE_ENTER (sprintf ("Configuration changed to %O - " \
"redirecting", id->conf), 0); \
TRACE_LEAVE (""); \
TIMER_END (first_modules); \
TIMER_END (handle_request); \
return id->conf->RECURSE_CALL; \
} \
} \
TIMER_END(first_modules); \
} while (0)
#define TRY_LAST_MODULES(FILE, RECURSE_CALL) do { \
mixed ret; \
TIMER_START(last_modules); \
foreach(last_module_cache||last_modules(), function funp) { \
TRACE_ENTER ("Last try module", funp); \
if(ret = funp(id)) { \
if (ret == 1) { \
TRACE_LEAVE ("Request rewritten - try again"); \
TIMER_END(last_modules); \
TIMER_END(handle_request); \
return RECURSE_CALL; \
} \
TRACE_LEAVE ("Got response"); \
break; \
} \
TRACE_LEAVE ("No response"); \
} \
FILE = ret; \
TIMER_END(last_modules); \
} while (0)
mixed handle_request( RequestID id, void|int recurse_count)
|
c7a5f0 | 1999-02-16 | Per Hedbor | | {
mixed file;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | REQUEST_WERR("handle_request()");
|
687762 | 2004-04-19 | Martin Stjernholm | |
if (recurse_count > 50) {
TRACE_ENTER ("Looped " + recurse_count +
" times in internal redirects - giving up", 0);
TRACE_LEAVE ("");
return 0;
|
c7a5f0 | 1999-02-16 | Per Hedbor | | }
|
687762 | 2004-04-19 | Martin Stjernholm | |
TIMER_START(handle_request);
TRY_FIRST_MODULES (file, handle_request (id, recurse_count + 1));
|
fd8b15 | 1999-05-19 | David Hedbor | | if(!mappingp(file) && !mappingp(file = get_file(id)))
|
687762 | 2004-04-19 | Martin Stjernholm | | TRY_LAST_MODULES (file, handle_request(id, recurse_count + 1));
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
687762 | 2004-04-19 | Martin Stjernholm | |
|
10c7e1 | 1999-12-28 | Martin Nilsson | | REQUEST_WERR("handle_request(): Done");
|
9c1900 | 2001-02-27 | Per Hedbor | | MERGE_TIMERS(roxen);
|
c7a5f0 | 1999-02-16 | Per Hedbor | | return file;
}
|
9a0d4b | 2004-04-20 | Henrik Grubbström (Grubba) | | mapping|int get_file(RequestID id, int|void no_magic, int|void internal_get)
|
cd9287 | 2000-08-15 | Johan Sundström | |
|
09a068 | 2004-04-20 | Henrik Grubbström (Grubba) | |
|
14179b | 1997-01-29 | Per Hedbor | | {
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(get_file);
|
576c11 | 2000-03-07 | Martin Stjernholm | | int orig_internal_get = id->misc->internal_get;
id->misc->internal_get = internal_get;
|
483b06 | 2002-05-16 | Stefan Wallström | | RequestID root_id = id->root_id || id;
root_id->misc->_request_depth++;
if(sub_req_limit && root_id->misc->_request_depth > sub_req_limit)
|
9ac033 | 2002-11-05 | Anders Johansson | | error("Subrequest limit reached. (Possibly an insertion loop.)");
|
576c11 | 2000-03-07 | Martin Stjernholm | |
|
fd9302 | 2000-05-05 | Martin Nilsson | | mapping|int res;
mapping res2;
|
14179b | 1997-01-29 | Per Hedbor | | function tmp;
res = low_get_file(id, no_magic);
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(get_file);
|
fd9302 | 2000-05-05 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(filter_modules);
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(filter_module_cache||filter_modules(), tmp)
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("Filter module", tmp);
|
471705 | 2001-05-07 | Per Hedbor | | PROF_ENTER(Roxen.get_owning_module(tmp)->module_name,"filter");
|
14179b | 1997-01-29 | Per Hedbor | | if(res2=tmp(res,id))
{
|
8b815d | 2004-04-20 | Martin Stjernholm | | if(mappingp(res) && res->file && (res2->file != res->file))
|
14179b | 1997-01-29 | Per Hedbor | | destruct(res->file);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Rewrote result.");
|
14179b | 1997-01-29 | Per Hedbor | | res=res2;
|
41d0f9 | 1998-02-20 | Per Hedbor | | } else
TRACE_LEAVE("");
|
471705 | 2001-05-07 | Per Hedbor | | PROF_LEAVE(Roxen.get_owning_module(tmp)->module_name,"filter");
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(filter_modules);
|
576c11 | 2000-03-07 | Martin Stjernholm | |
|
483b06 | 2002-05-16 | Stefan Wallström | | root_id->misc->_request_depth--;
|
576c11 | 2000-03-07 | Martin Stjernholm | | id->misc->internal_get = orig_internal_get;
|
14179b | 1997-01-29 | Per Hedbor | | return res;
}
|
9a8a15 | 2000-09-25 | Per Hedbor | | array(string) find_dir(string file, RequestID id, void|int(0..1) verbose)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
fd9302 | 2000-05-05 | Martin Nilsson | | array dir;
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("List directory %O.", file), 0);
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
db43d1 | 2000-11-24 | Martin Stjernholm | | if(!sizeof (file) || file[0] != '/')
|
193535 | 1997-04-28 | Henrik Grubbström (Grubba) | | file = "/" + file;
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | #ifdef URL_MODULES
|
fc0e5d | 1997-08-26 | Henrik Grubbström (Grubba) | | #ifdef THREADS
|
3e3bab | 2001-01-19 | Per Hedbor | | Thread.MutexKey key;
|
fc0e5d | 1997-08-26 | Henrik Grubbström (Grubba) | | #endif
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | |
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(url_modules(), function funp)
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | {
string of = id->not_query;
id->not_query = file;
LOCK(funp);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("URL module", funp);
|
3e3bab | 2001-01-19 | Per Hedbor | | mixed remap=funp( id, file );
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | UNLOCK();
|
fd9302 | 2000-05-05 | Martin Nilsson | | if(mappingp( remap ))
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | {
id->not_query=of;
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned 'No thanks'.");
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | return 0;
}
|
fd9302 | 2000-05-05 | Martin Nilsson | | if(objectp( remap ))
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | {
|
a51a90 | 2001-11-12 | Martin Stjernholm | | mixed err;
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->find_dir_nest++;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Recursing");
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | file = id->not_query;
err = catch {
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if( id->misc->find_dir_nest < 20 )
|
fd9302 | 2000-05-05 | Martin Nilsson | | dir = (id->conf || this_object())->find_dir( file, id );
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | else
error("Too deep recursion in roxen::find_dir() while mapping "
+file+".\n");
};
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->find_dir_nest = 0;
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | if(err)
throw(err);
|
fd9302 | 2000-05-05 | Martin Nilsson | | return dir;
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | }
id->not_query=of;
}
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | #endif /* URL_MODULES */
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | |
|
3e3bab | 2001-01-19 | Per Hedbor | | array | mapping d;
|
e927de | 2000-05-06 | Martin Nilsson | | array(string) locks=({});
|
3e3bab | 2001-01-19 | Per Hedbor | | RoxenModule mod;
|
e927de | 2000-05-06 | Martin Nilsson | | string loc;
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(location_modules(), array tmp)
|
14179b | 1997-01-29 | Per Hedbor | | {
loc = tmp[0];
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | if(!search(file, loc)) {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Location module [%s] ", loc), tmp[1]);
|
a78a59 | 1997-04-28 | Henrik Grubbström (Grubba) | | #ifdef MODULE_LEVEL_SECURITY
|
41d0f9 | 1998-02-20 | Per Hedbor | | if(check_security(tmp[1], id)) {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission denied");
|
41d0f9 | 1998-02-20 | Per Hedbor | | continue;
}
|
a78a59 | 1997-04-28 | Henrik Grubbström (Grubba) | | #endif
|
e927de | 2000-05-06 | Martin Nilsson | | mod=function_object(tmp[1]);
if(d=mod->find_dir(file[strlen(loc)..], id))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
29a807 | 1998-08-21 | David Hedbor | | if(mappingp(d))
{
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(d->files) {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Got exclusive directory.");
TRACE_LEAVE(sprintf("Returning list of %d files.", sizeof(d->files)));
|
fd9302 | 2000-05-05 | Martin Nilsson | | return d->files;
|
29a807 | 1998-08-21 | David Hedbor | | } else
TRACE_LEAVE("");
} else {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Got files.");
|
e927de | 2000-05-06 | Martin Nilsson | | if(!dir) dir=({ });
|
29a807 | 1998-08-21 | David Hedbor | | dir |= d;
}
|
e927de | 2000-05-06 | Martin Nilsson | | }
else {
if(verbose && mod->list_lock_files)
locks |= mod->list_lock_files();
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
e927de | 2000-05-06 | Martin Nilsson | | }
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | } else if((search(loc, file)==0) && (loc[strlen(file)-1]=='/') &&
(loc[0]==loc[-1]) && (loc[-1]=='/') &&
|
6c67c8 | 1998-02-28 | Johan Schön | | (function_object(tmp[1])->stat_file(".", id))) {
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | |
24fa08 | 1998-02-28 | Henrik Grubbström (Grubba) | | * and stat_file(".") returns non-zero.
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | */
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Location module [%s] ", loc), tmp[1]);
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | loc=loc[strlen(file)..];
sscanf(loc, "%s/", loc);
|
df4045 | 2000-06-19 | Henrik Grubbström (Grubba) | | if (dir) {
dir |= ({ loc });
} else {
dir = ({ loc });
}
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Added module mountpoint.");
|
14179b | 1997-01-29 | Per Hedbor | | }
}
|
e927de | 2000-05-06 | Martin Nilsson | | if(!dir) return verbose ? ({0})+locks : ([])[0];
|
14179b | 1997-01-29 | Per Hedbor | | if(sizeof(dir))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE(sprintf("Returning list of %d files.", sizeof(dir)));
|
14179b | 1997-01-29 | Per Hedbor | | return dir;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | }
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returning 'No such directory'.");
|
fd9302 | 2000-05-05 | Martin Nilsson | | return 0;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
9a8a15 | 2000-09-25 | Per Hedbor | | array(int)|Stat stat_file(string file, RequestID id)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
1f4a6c | 2000-08-28 | Per Hedbor | | mixed s, tmp;
|
c5e096 | 1999-10-04 | Per Hedbor | | #ifdef THREADS
|
3e3bab | 2001-01-19 | Per Hedbor | | Thread.MutexKey key;
|
c5e096 | 1999-10-04 | Per Hedbor | | #endif
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Stat file %O.", file), 0);
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | file=replace(file, "//", "/");
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | |
#ifdef URL_MODULES
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | string of = id->not_query;
id->not_query = file;
foreach(url_module_cache||url_modules(), function funp)
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("URL module", funp);
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | LOCK(funp);
tmp=funp( id, file );
UNLOCK();
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if (tmp) {
if(mappingp( tmp )) {
id->not_query = of;
TRACE_LEAVE("");
TRACE_LEAVE("Returned 'No thanks'.");
return 0;
}
if(objectp( tmp ))
{
mixed err;
id->misc->stat_file_nest++;
TRACE_LEAVE("Recursing");
err = catch {
if( id->misc->stat_file_nest < 20 )
|
b2e9e1 | 2005-02-25 | Henrik Grubbström (Grubba) | | tmp = (id->conf || this_object())->stat_file(id->not_query, id );
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | else
error("Too deep recursion in roxen::stat_file() while mapping "
+file+".\n");
};
|
b2e9e1 | 2005-02-25 | Henrik Grubbström (Grubba) | | id->not_query = of;
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->stat_file_nest = 0;
if(err)
throw(err);
TRACE_LEAVE("");
TRACE_LEAVE("Returning data");
return tmp;
}
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | }
|
8fd51f | 1998-03-01 | Per Hedbor | | TRACE_LEAVE("");
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | }
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->not_query = of;
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | #endif
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | foreach(location_module_cache||location_modules(),
[string loc, function fun]) {
|
14179b | 1997-01-29 | Per Hedbor | | if((file == loc) || ((file+"/")==loc))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | TRACE_ENTER(sprintf("Location module [%s] ", loc), fun);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Exact match.");
|
41d0f9 | 1998-02-20 | Per Hedbor | | TRACE_LEAVE("");
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | return Stdio.Stat(({ 0775, -3, 0, 0, 0, 0, 0 }));
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if(has_prefix(file, loc))
|
14179b | 1997-01-29 | Per Hedbor | | {
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | TRACE_ENTER(sprintf("Location module [%s] ", loc), fun);
|
a78a59 | 1997-04-28 | Henrik Grubbström (Grubba) | | #ifdef MODULE_LEVEL_SECURITY
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if(check_security(fun, id)) {
|
8fd51f | 1998-03-01 | Per Hedbor | | TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Permission denied");
|
41d0f9 | 1998-02-20 | Per Hedbor | | continue;
}
|
a78a59 | 1997-04-28 | Henrik Grubbström (Grubba) | | #endif
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if(s=function_object(fun)->stat_file(file[strlen(loc)..], id))
|
41d0f9 | 1998-02-20 | Per Hedbor | | {
TRACE_LEAVE("");
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Stat ok.");
|
14179b | 1997-01-29 | Per Hedbor | | return s;
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
TRACE_LEAVE("");
|
14179b | 1997-01-29 | Per Hedbor | | }
}
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned 'no such file'.");
|
14179b | 1997-01-29 | Per Hedbor | | }
|
73ce3d | 2000-12-11 | Per Hedbor | | mapping error_file( RequestID id )
{
string data = query("ZNoSuchFile");
NOCACHE();
|
51d4d2 | 2001-01-04 | Martin Nilsson | | #if ROXEN_COMPAT <= 2.1
|
73ce3d | 2000-12-11 | Per Hedbor | | data = replace(data,({"$File", "$Me"}),
|
149344 | 2000-12-17 | Henrik Grubbström (Grubba) | | ({"&page.virtfile;", "&roxen.server;"}));
|
73ce3d | 2000-12-11 | Per Hedbor | | #endif
|
1371e0 | 2001-06-22 | Martin Nilsson | | mapping res = Roxen.http_rxml_answer( data, id, 0, "text/html" );
res->error = 404;
return res;
|
73ce3d | 2000-12-11 | Per Hedbor | | }
|
fafdea | 2005-12-13 | Anders Johansson | | mapping auth_failed_file( RequestID id, string message )
{
|
3e6144 | 2006-11-07 | Marcus Wellhardh | |
if(id->misc->generate_auth_failed)
return Roxen.http_low_answer(401, "<title>Access Denied</title>"
"<h2 align=center>Access Denied</h2>");
id->misc->generate_auth_failed = 1;
|
fafdea | 2005-12-13 | Anders Johansson | | string data = query("ZAuthFailed");
NOCACHE();
mapping res = Roxen.http_rxml_answer( data, id, 0, "text/html" );
res->error = 401;
return res;
}
|
e8790b | 1998-02-19 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | array open_file(string fname, string mode, RequestID id, void|int internal_get,
void|int recurse_count)
|
e8790b | 1998-02-19 | Per Hedbor | | {
|
687762 | 2004-04-19 | Martin Stjernholm | | mapping|int(0..1) file;
string oq = id->not_query;
|
517c7e | 2000-09-30 | Per Hedbor | | if( id->conf && (id->conf != this_object()) )
|
687762 | 2004-04-19 | Martin Stjernholm | | return id->conf->open_file( fname, mode, id, internal_get, recurse_count );
|
517c7e | 2000-09-30 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | if (recurse_count > 50) {
TRACE_ENTER ("Looped " + recurse_count +
" times in internal redirects - giving up", 0);
TRACE_LEAVE ("");
}
|
cd7ea4 | 1998-12-14 | Peter Bortas | |
|
687762 | 2004-04-19 | Martin Stjernholm | | else {
Configuration oc = id->conf;
id->not_query = fname;
TRY_FIRST_MODULES (file, open_file (fname, mode, id,
internal_get, recurse_count + 1));
fname = id->not_query;
|
c7a5f0 | 1999-02-16 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | if(search(mode, "R")!=-1)
|
e8790b | 1998-02-19 | Per Hedbor | | {
|
687762 | 2004-04-19 | Martin Stjernholm | | string f;
mode -= "R";
if(f = real_file(fname, id))
{
return ({ open(f, mode), ([]) });
}
|
e8790b | 1998-02-19 | Per Hedbor | | }
|
687762 | 2004-04-19 | Martin Stjernholm | | if(mode!="r") {
id->not_query = oq;
return ({ 0, (["error":501, "data":"Not implemented." ]) });
|
41d0f9 | 1998-02-20 | Per Hedbor | | }
|
e8790b | 1998-02-19 | Per Hedbor | |
if(!file)
{
|
517c7e | 2000-09-30 | Per Hedbor | | file = get_file( id, 0, internal_get );
|
687762 | 2004-04-19 | Martin Stjernholm | | if(!file)
TRY_LAST_MODULES (file, open_file (id->not_query, mode, id,
internal_get, recurse_count + 1));
|
e8790b | 1998-02-19 | Per Hedbor | | }
|
687762 | 2004-04-19 | Martin Stjernholm | | }
|
e8790b | 1998-02-19 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | if(!mappingp(file))
{
if(id->misc->error_code)
file = Roxen.http_low_answer(id->misc->error_code, "Failed" );
else if(id->method!="GET"&&id->method != "HEAD"&&id->method!="POST")
file = Roxen.http_low_answer(501, "Not implemented.");
else
file = error_file( id );
|
e8790b | 1998-02-19 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | id->not_query = oq;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
687762 | 2004-04-19 | Martin Stjernholm | | return ({ 0, file });
}
|
e8790b | 1998-02-19 | Per Hedbor | |
|
687762 | 2004-04-19 | Martin Stjernholm | | if( file->data )
{
file->file = StringFile(file->data);
m_delete(file, "data");
|
e8790b | 1998-02-19 | Per Hedbor | | }
id->not_query = oq;
|
7db929 | 2004-05-18 | Anders Johansson | | return ({ file->file || StringFile(""), file });
|
e8790b | 1998-02-19 | Per Hedbor | | }
|
9a8a15 | 2000-09-25 | Per Hedbor | | mapping(string:array(mixed)) find_dir_stat(string file, RequestID id)
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | {
string loc;
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | mapping(string:array(mixed)) dir = ([]);
mixed d, tmp;
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | |
|
c7a5f0 | 1999-02-16 | Per Hedbor | |
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | file=replace(file, "//", "/");
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
db43d1 | 2000-11-24 | Martin Stjernholm | | if(!sizeof (file) || file[0] != '/')
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | file = "/" + file;
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Request for directory and stat's \"%s\".", file), 0);
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | #ifdef URL_MODULES
#ifdef THREADS
|
3e3bab | 2001-01-19 | Per Hedbor | | Thread.MutexKey key;
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | #endif
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(url_modules(), function funp)
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | {
string of = id->not_query;
id->not_query = file;
LOCK(funp);
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER("URL module", funp);
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | tmp=funp( id, file );
UNLOCK();
if(mappingp( tmp ))
{
id->not_query=of;
|
3510fb | 1997-11-09 | Henrik Grubbström (Grubba) | | #ifdef MODULE_DEBUG
|
91d3c3 | 2001-03-12 | Martin Nilsson | | report_debug("conf->find_dir_stat(\"%s\"): url_module returned mapping:%O\n",
file, tmp);
|
3510fb | 1997-11-09 | Henrik Grubbström (Grubba) | | #endif /* MODULE_DEBUG */
|
64f3dc | 2004-08-18 | Martin Stjernholm | | TRACE_LEAVE("Returned mapping.");
|
07014c | 1999-05-24 | Per Hedbor | | TRACE_LEAVE("");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | return 0;
}
if(objectp( tmp ))
{
|
a51a90 | 2001-11-12 | Martin Stjernholm | | mixed err;
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->find_dir_stat_nest++;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | file = id->not_query;
err = catch {
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | if( id->misc->find_dir_stat_nest < 20 )
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | tmp = (id->conf || this_object())->find_dir_stat( file, id );
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | else {
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Too deep recursion");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | error("Too deep recursion in roxen::find_dir_stat() while mapping "
+file+".\n");
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | }
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | };
|
690694 | 2004-05-21 | Henrik Grubbström (Grubba) | | id->misc->find_dir_stat_nest = 0;
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | if(err)
throw(err);
|
3510fb | 1997-11-09 | Henrik Grubbström (Grubba) | | #ifdef MODULE_DEBUG
|
91d3c3 | 2001-03-12 | Martin Nilsson | | report_debug("conf->find_dir_stat(\"%s\"): url_module returned object:\n",
file);
|
3510fb | 1997-11-09 | Henrik Grubbström (Grubba) | | #endif /* MODULE_DEBUG */
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_LEAVE("Returned object.");
TRACE_LEAVE("Returning it.");
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | return tmp;
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
id->not_query=of;
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
#endif /* URL_MODULES */
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(location_modules(), tmp)
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | {
loc = tmp[0];
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | |
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("Location module [%s] ", loc), 0);
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | |
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | if(!search(file, loc))
{
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | |
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | #ifdef MODULE_LEVEL_SECURITY
|
8b44de | 2003-10-07 | Anders Johansson | | if(check_security(tmp[1], id)) {
TRACE_LEAVE("Security check failed.");
continue;
}
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | #endif
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule c = function_object(tmp[1]);
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | string f = file[strlen(loc)..];
if (c->find_dir_stat) {
|
64f3dc | 2004-08-18 | Martin Stjernholm | | SIMPLE_TRACE_ENTER(c, "Calling find_dir_stat().");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | if (d = c->find_dir_stat(f, id)) {
|
64f3dc | 2004-08-18 | Martin Stjernholm | | SIMPLE_TRACE_LEAVE("Returned mapping with %d entries.", sizeof (d));
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | dir = d | dir;
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
|
64f3dc | 2004-08-18 | Martin Stjernholm | | else
SIMPLE_TRACE_LEAVE("Returned zero.");
} else {
SIMPLE_TRACE_ENTER(c, "Calling find_dir().");
if(d = c->find_dir(f, id)) {
SIMPLE_TRACE_LEAVE("Returned array with %d entries.", sizeof (d));
dir = mkmapping(d, Array.map(d, lambda(string fn)
{
return c->stat_file(f + fn, id);
})) | dir;
}
else
SIMPLE_TRACE_LEAVE("Returned zero.");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | } else if(search(loc, file)==0 && loc[strlen(file)-1]=='/' &&
(loc[0]==loc[-1]) && loc[-1]=='/' &&
|
8935ad | 1998-03-30 | Johan Schön | | (function_object(tmp[1])->stat_file(".", id))) {
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | |
8935ad | 1998-03-30 | Johan Schön | | * and stat_file(".") returns non-zero.
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | */
|
434bac | 2000-07-14 | Andreas Lange | | TRACE_ENTER(sprintf("The file %O is on the path to the mountpoint %O.",
|
67f60e | 2000-07-09 | Martin Nilsson | | file, loc), 0);
|
a47671 | 1997-10-20 | Henrik Grubbström (Grubba) | | loc=loc[strlen(file)..];
sscanf(loc, "%s/", loc);
if (!dir[loc]) {
|
cd9287 | 2000-08-15 | Johan Sundström | | dir[loc] = ({ 0775, -3, 0, 0, 0, 0, 0 });
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
|
ae60b6 | 1998-05-23 | Henrik Grubbström (Grubba) | | TRACE_LEAVE("");
|
a86c6c | 1997-09-22 | Henrik Grubbström (Grubba) | | }
if(sizeof(dir))
return dir;
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
9a8a15 | 2000-09-25 | Per Hedbor | | array access(string file, RequestID id)
|
14179b | 1997-01-29 | Per Hedbor | | {
string loc;
array s, tmp;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | file=replace(file, "//", "/");
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(location_modules(), tmp)
|
14179b | 1997-01-29 | Per Hedbor | | {
loc = tmp[0];
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | if((file+"/")==loc) {
#ifdef MODULE_LEVEL_SECURITY
if(check_security(tmp[1], id)) continue;
#endif
if(s=function_object(tmp[1])->access("", id))
return s;
} else if(!search(file, loc)) {
|
14179b | 1997-01-29 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
if(check_security(tmp[1], id)) continue;
#endif
if(s=function_object(tmp[1])->access(file[strlen(loc)..], id))
return s;
}
}
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | return 0;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
9a8a15 | 2000-09-25 | Per Hedbor | | string real_file(string file, RequestID id)
|
9fd809 | 2000-08-08 | Johan Sundström | |
|
14179b | 1997-01-29 | Per Hedbor | | {
string loc;
string s;
array tmp;
file=replace(file, "//", "/");
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | if(!id) error("No id passed to real_file");
|
517c7e | 2000-09-30 | Per Hedbor | | foreach(location_modules(), tmp)
|
14179b | 1997-01-29 | Per Hedbor | | {
loc = tmp[0];
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(!search(file, loc))
|
14179b | 1997-01-29 | Per Hedbor | | {
#ifdef MODULE_LEVEL_SECURITY
if(check_security(tmp[1], id)) continue;
#endif
|
c5e096 | 1999-10-04 | Per Hedbor | | if(s=function_object(tmp[1])->real_file(file[strlen(loc)..], id))
|
14179b | 1997-01-29 | Per Hedbor | | return s;
}
}
}
|
742477 | 2002-11-05 | Anders Johansson | | array(int)|Stat try_stat_file(string s, RequestID id, int|void not_internal)
{
RequestID fake_id;
array(int)|Stat res;
if(!objectp(id))
error("No ID passed to 'try_stat_file'\n");
if ( !id->misc )
id->misc = ([]);
|
1156ad | 2005-10-21 | Henrik Grubbström (Grubba) | | fake_id = make_fake_id(s, id);
|
742477 | 2002-11-05 | Anders Johansson | |
fake_id->misc->internal_get = !not_internal;
fake_id->method = "GET";
res = stat_file(fake_id->not_query, fake_id);
destruct (fake_id);
return res;
}
|
829e8c | 2004-04-13 | Martin Stjernholm | | static RequestID make_fake_id (string s, RequestID id)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
e351dd | 1999-11-29 | Per Hedbor | | RequestID fake_id;
|
14179b | 1997-01-29 | Per Hedbor | |
|
964473 | 2001-11-27 | Martin Stjernholm | |
if ( !id->misc->common )
id->misc->common = ([]);
|
e351dd | 1999-11-29 | Per Hedbor | | fake_id = id->clone_me();
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
964473 | 2001-11-27 | Martin Stjernholm | | fake_id->misc->common = id->misc->common;
|
c8ff27 | 2002-09-20 | Anders Johansson | | fake_id->conf = this_object();
|
e351dd | 1999-11-29 | Per Hedbor | |
|
1ee907 | 2007-12-21 | Henrik Grubbström (Grubba) | | fake_id->raw_url=s;
|
4e0a53 | 2000-03-20 | Martin Stjernholm | | if (fake_id->scan_for_query)
|
c65dbe | 2001-05-03 | Per Hedbor | |
|
4e0a53 | 2000-03-20 | Martin Stjernholm | | s = fake_id->scan_for_query (s);
|
c65dbe | 2001-05-03 | Per Hedbor | |
|
1156ad | 2005-10-21 | Henrik Grubbström (Grubba) | | s = http_decode_string(s);
|
c65dbe | 2001-05-03 | Per Hedbor | | s = Roxen.fix_relative (s, id);
|
1156ad | 2005-10-21 | Henrik Grubbström (Grubba) | |
if (search(s, "\0") != -1)
sscanf(s, "%s\0", s);
|
14179b | 1997-01-29 | Per Hedbor | | fake_id->not_query=s;
|
829e8c | 2004-04-13 | Martin Stjernholm | |
return fake_id;
}
int|string try_get_file(string s, RequestID id,
int|void stat_only, int|void nocache,
int|void not_internal,
mapping|void result_mapping)
{
string res;
RequestID fake_id = make_fake_id (s, id);
mapping m;
fake_id->misc->internal_get = !not_internal;
|
7a4150 | 2001-08-30 | Henrik Grubbström (Grubba) | | fake_id->method = "GET";
|
14179b | 1997-01-29 | Per Hedbor | |
|
a878e2 | 2004-04-19 | Martin Stjernholm | | array a = open_file( fake_id->not_query, "r", fake_id, !not_internal );
|
7db929 | 2004-05-18 | Anders Johansson | |
m = a[1];
|
d60aa2 | 2005-04-12 | Anders Johansson | | if (result_mapping) {
|
7db929 | 2004-05-18 | Anders Johansson | | foreach(indices(m), string i)
result_mapping[i] = m[i];
|
d60aa2 | 2005-04-12 | Anders Johansson | | if (string|function(string:string) charset = fake_id->get_output_charset())
result_mapping->charset = charset;
|
f25972 | 2006-10-05 | Anders Johansson | | result_mapping->last_modified = fake_id->misc->last_modified;
|
d60aa2 | 2005-04-12 | Anders Johansson | | }
|
7db929 | 2004-05-18 | Anders Johansson | |
if(a[0]) {
|
829e8c | 2004-04-13 | Martin Stjernholm | | m->file = a[0];
}
else {
destruct (fake_id);
return 0;
|
c927a0 | 2000-03-18 | Martin Stjernholm | | }
|
a59fc9 | 2000-08-16 | Per Hedbor | | CACHE( fake_id->misc->cacheable );
|
c927a0 | 2000-03-18 | Martin Stjernholm | | destruct (fake_id);
|
889d03 | 1999-10-04 | Per Hedbor | |
|
96d86e | 2001-01-29 | Per Hedbor | |
if (!(< 0,2,3 >)[m->error/100]) return 0;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
829e8c | 2004-04-13 | Martin Stjernholm | | if(stat_only) return 1;
|
3510fb | 1997-11-09 | Henrik Grubbström (Grubba) | |
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(m->data)
|
a22f6f | 1999-05-12 | Per Hedbor | | res = m->data;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | else
|
a22f6f | 1999-05-12 | Per Hedbor | | res="";
|
14179b | 1997-01-29 | Per Hedbor | | m->data = 0;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
4cb221 | 2000-05-22 | Per Hedbor | | if( objectp(m->file) )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3a4d7e | 1997-09-03 | Per Hedbor | | res += m->file->read();
|
2c6659 | 2001-09-06 | Henrik Grubbström (Grubba) | | if (m->file) {
destruct(m->file);
}
|
14179b | 1997-01-29 | Per Hedbor | | m->file = 0;
}
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | if(m->raw)
{
res -= "\r";
if(!sscanf(res, "%*s\n\n%s", res))
sscanf(res, "%*s\n%s", res);
}
return res;
}
|
829e8c | 2004-04-13 | Martin Stjernholm | | mapping(string:string) try_get_headers(string s, RequestID id,
int|void not_internal)
{
RequestID fake_id = make_fake_id (s, id);
mapping m;
fake_id->misc->internal_get = !not_internal;
fake_id->method = "HEAD";
array a = open_file( s, "r", fake_id, !not_internal );
if(a && a[1]) {
if (a[0]) a[0]->close();
m = a[1];
}
else {
destruct (fake_id);
return 0;
}
CACHE( fake_id->misc->cacheable );
if (!m->raw)
m = fake_id->make_response_headers (m);
else {
Roxen.HeaderParser hp = Roxen.HeaderParser();
array res;
if(m->data)
res = hp->feed (m->data);
if (!res && objectp(m->file))
{
hp->feed (m->file->read());
if (m->file) {
destruct(m->file);
}
}
m = res && res[2];
}
destruct (fake_id);
return m;
}
|
f47b66 | 2004-03-16 | Henrik Grubbström (Grubba) | | mapping(string:mixed) try_put_file(string path, string data, RequestID id)
{
TIMER_START(try_put_file);
if ( !id->misc )
id->misc = ([]);
|
1156ad | 2005-10-21 | Henrik Grubbström (Grubba) | | RequestID fake_id = make_fake_id(path, id);
|
f47b66 | 2004-03-16 | Henrik Grubbström (Grubba) | |
fake_id->root_id->misc->_request_depth++;
if(sub_req_limit && fake_id->root_id->misc->_request_depth > sub_req_limit)
error("Subrequest limit reached. (Possibly an insertion loop.)");
fake_id->method = "PUT";
fake_id->data = data;
fake_id->misc->len = sizeof(data);
fake_id->misc->internal_get = 1;
mapping(string:mixed) res = low_get_file(fake_id, 1);
TIMER_END(try_put_file);
return res;
}
|
7345b0 | 2001-09-13 | Martin Nilsson | | int(0..1) is_file(string virt_path, RequestID id, int(0..1)|void internal)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
7345b0 | 2001-09-13 | Martin Nilsson | | if(internal) {
int(0..1) was_internal = id->misc->internal_get;
id->misc->internal_get = 1;
int(0..1) res = !!stat_file(virt_path, id);
if(!was_internal)
m_delete(id->misc, "internal_get");
return res;
}
if(stat_file(virt_path, id) ||
has_suffix(virt_path, "/internal-roxen-unit"))
return 1;
string f = (virt_path/"/")[-1];
if( sscanf(f, "internal-roxen-%s", f) ) {
if(internal_roxen_image(f, id) ||
has_prefix(f, "pixel-"))
return 1;
return 0;
}
if( sscanf(f, "internal-gopher-%s", f) &&
internal_gopher_image(f) )
return 1;
return 0;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
03aa49 | 2000-08-23 | Per Hedbor | | array registered_urls = ({}), failed_urls = ({ });
|
7a243b | 2000-08-19 | Per Hedbor | | array do_not_log_patterns = 0;
|
14179b | 1997-01-29 | Per Hedbor | | void start(int num)
{
|
c109fc | 2001-07-21 | Martin Stjernholm | | fix_my_url();
|
55c052 | 2001-11-07 | Henrik Grubbström (Grubba) | | #if 0
report_debug(sprintf("configuration:start():\n"
" registered_urls: ({ %{%O, %}})\n"
|
9c3c6c | 2001-11-09 | Henrik Grubbström (Grubba) | | " failed_urls: ({ %{%O, %}})\n"
|
55c052 | 2001-11-07 | Henrik Grubbström (Grubba) | | " URLs: ({ %{%O, %}})\n",
registered_urls,
failed_urls,
query("URLs")));
#endif /* 0 */
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
5d6c8d | 2000-09-01 | Per Hedbor | | foreach( (registered_urls-query("URLs"))+failed_urls, string url )
{
registered_urls -= ({ url });
|
9c3c6c | 2001-11-09 | Henrik Grubbström (Grubba) | | roxen.unregister_url(url, this_object());
|
5d6c8d | 2000-09-01 | Per Hedbor | | }
|
ecd9ab | 2000-08-23 | Per Hedbor | |
|
03aa49 | 2000-08-23 | Per Hedbor | | failed_urls = ({ });
|
ecd9ab | 2000-08-23 | Per Hedbor | |
|
5d6c8d | 2000-09-01 | Per Hedbor | | foreach( (query( "URLs" )-registered_urls), string url )
|
55c052 | 2001-11-07 | Henrik Grubbström (Grubba) | | {
|
ecd9ab | 2000-08-23 | Per Hedbor | | if( roxen.register_url( url, this_object() ) )
registered_urls += ({ url });
|
03aa49 | 2000-08-23 | Per Hedbor | | else
failed_urls += ({ url });
|
55c052 | 2001-11-07 | Henrik Grubbström (Grubba) | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | if( !datacache )
datacache = DataCache( );
else
datacache->init_from_variables();
|
7a243b | 2000-08-19 | Per Hedbor | |
parse_log_formats();
init_log_file();
do_not_log_patterns = query("NoLog");
if(!sizeof(do_not_log_patterns))
do_not_log_patterns = 0;
|
6f669a | 2001-08-14 | Honza Petrous | |
|
b9c387 | 2002-03-27 | Per Hedbor | | if( query("throttle") )
{
if( !throttler )
throttler=.throttler();
throttler->throttle(query("throttle_fill_rate"),
query("throttle_bucket_depth"),
query("throttle_min_grant"),
query("throttle_max_grant"));
}
else if( throttler )
{
throttler->throttle( 1000000000, 1000000000,
1024, 65536 );
throttler = 0;
}
|
6f669a | 2001-08-14 | Honza Petrous | | #ifdef SNMP_AGENT
if(query("snmp_process") && objectp(roxen->snmpagent))
roxen->snmpagent->add_virtserv(get_config_id());
#endif
|
7adb10 | 2007-11-05 | Henrik Grubbström (Grubba) | | foreach(registered_urls, string url) {
mapping(string:string|Configuration|Protocol) port_info = roxen.urls[url];
foreach((port_info && port_info->ports) || ({}), Protocol prot) {
if ((prot->prot_name != "snmp") || (!prot->mib)) {
continue;
}
string path = port_info->path || "";
if (has_prefix(path, "/")) {
path = path[1..];
}
if (has_suffix(path, "/")) {
path = path[..sizeof(path)-2];
}
array(int) oid_suffix = ({ sizeof(path), @((array(int))path) });
ADT.Trie mib =
SNMP.SimpleMIB(query_oid(), oid_suffix,
({
UNDEFINED,
UNDEFINED,
SNMP.String(query_name, "siteName"),
SNMP.String(comment, "siteComment"),
SNMP.Counter64(lambda() { return sent; },
"sent"),
SNMP.Counter64(lambda() { return received; },
"received"),
SNMP.Counter64(lambda() { return hsent; },
"sentHeaders"),
SNMP.Counter64(lambda() { return requests; },
"numRequests"),
UNDEFINED,
}));
SNMP.set_owner(mib, this_object());
prot->mib->merge(mib);
}
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
e7e603 | 1999-11-05 | Per Hedbor | | void save_me()
{
save_one( 0 );
}
|
14179b | 1997-01-29 | Per Hedbor | | void save(int|void all)
|
2688e2 | 2000-07-26 | Johan Sundström | |
|
14179b | 1997-01-29 | Per Hedbor | | {
if(all)
{
|
3f628a | 1999-12-09 | Martin Stjernholm | | store("spider#0", variables, 0, this_object());
|
14179b | 1997-01-29 | Per Hedbor | | start(2);
}
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
a2d079 | 2002-04-15 | Marcus Wellhardh | | store( "EnabledModules", enabled_modules, 1, this_object());
|
3f628a | 1999-12-09 | Martin Stjernholm | | foreach(indices(modules), string modname)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3f628a | 1999-12-09 | Martin Stjernholm | | foreach(indices(modules[modname]->copies), int i)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
3f628a | 1999-12-09 | Martin Stjernholm | | store(modname+"#"+i, modules[modname]->copies[i]->query(), 0, this_object());
|
49e3bc | 2001-03-12 | Anders Johansson | | if (mixed err = catch(modules[modname]->copies[i]->
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | start(2, this_object(), 0)))
|
49e3bc | 2001-03-12 | Anders Johansson | | report_error("Error calling start in module.\n%s",
describe_backtrace (err));
|
14179b | 1997-01-29 | Per Hedbor | | }
}
|
8cc31b | 1997-10-12 | Henrik Grubbström (Grubba) | | invalidate_cache();
|
14179b | 1997-01-29 | Per Hedbor | | }
|
e351dd | 1999-11-29 | Per Hedbor | | int save_one( RoxenModule o )
|
2688e2 | 2000-07-26 | Johan Sundström | |
|
14179b | 1997-01-29 | Per Hedbor | | {
mapping mod;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(!o)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | store("spider#0", variables, 0, this_object());
|
14179b | 1997-01-29 | Per Hedbor | | start(2);
return 1;
}
|
2c13a8 | 1999-11-10 | Per Hedbor | | string q = otomod[ o ];
if( !q )
error("Invalid module");
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
2c13a8 | 1999-11-10 | Per Hedbor | | store(q, o->query(), 0, this_object());
invalidate_cache();
|
0d1e43 | 2000-11-02 | Per Hedbor | | mixed error;
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | if( error = catch( o->start(2, this_object(), 0) ) )
|
0d1e43 | 2000-11-02 | Per Hedbor | | {
if( objectp(error ) )
error = (array)error;
if( sizeof(error)>1 && arrayp( error[1] ) )
{
int i;
for( i = 0; i<sizeof( error[1] ); i++ )
if( error[1][i][2] == save_one )
break;
error[1] = error[1][i+1..];
}
if( o->report_error )
o->report_error( "Call to start failed.\n"+describe_backtrace( error ) );
else
report_error( "Call to start failed.\n"+describe_backtrace( error ));
}
|
2c13a8 | 1999-11-10 | Per Hedbor | | invalidate_cache();
return 1;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
2f7920 | 2000-03-27 | Per Hedbor | | RoxenModule reload_module( string modname )
|
596425 | 1999-11-19 | Per Hedbor | | {
|
e351dd | 1999-11-29 | Per Hedbor | | RoxenModule old_module = find_module( modname );
|
9a8a15 | 2000-09-25 | Per Hedbor | | ModuleInfo mi = roxen.find_module( (modname/"#")[0] );
|
ffdab5 | 2001-08-24 | Per Hedbor | |
|
f7c574 | 2001-09-03 | Per Hedbor | | roxen->bootstrap_info->set (({this_object(), modname }));
|
2f7920 | 2000-03-27 | Per Hedbor | | if( !old_module ) return 0;
|
f56958 | 1999-11-23 | Per Hedbor | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | |
RXML.Context old_ctx = RXML.get_context();
RXML.set_context (0);
mixed err = catch {
|
1f5652 | 1999-11-23 | Per Hedbor | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | master()->clear_compilation_failures();
|
2f7920 | 2000-03-27 | Per Hedbor | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | if( !old_module->not_a_module )
{
save_one( old_module );
master()->refresh_inherit( object_program( old_module ) );
master()->refresh( object_program( old_module ), 1 );
}
|
2141a1 | 2001-07-12 | Martin Stjernholm | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | array old_error_log = (array) old_module->error_log;
|
2141a1 | 2001-07-12 | Martin Stjernholm | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | RoxenModule nm;
|
ffdab5 | 2001-08-24 | Per Hedbor | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | |
nm = mi->instance( this_object() );
if( nm->not_a_module )
{
old_module->report_error(LOC_C(385,"Reload failed")+"\n");
RXML.set_context (old_ctx);
return old_module;
}
|
ffdab5 | 2001-08-24 | Per Hedbor | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | disable_module( modname, 1 );
destruct( old_module );
|
2141a1 | 2001-07-12 | Martin Stjernholm | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | mixed err = catch {
mi->update_with( nm,0 );
};
if (err)
if (stringp (err)) {
report_error (err);
report_error(LOC_C(385,"Reload failed")+"\n");
RXML.set_context (old_ctx);
return 0;
}
else
throw (err);
enable_module( modname, nm, mi );
foreach (old_error_log, [string msg, array(int) times])
nm->error_log[msg] += times;
|
2141a1 | 2001-07-12 | Martin Stjernholm | |
|
b5e4a6 | 2007-05-31 | Martin Stjernholm | | nm->report_notice(LOC_C(11, "Reloaded %s.")+"\n", mi->get_name());
RXML.set_context (old_ctx);
return nm;
};
RXML.set_context (old_ctx);
|
1a517c | 2007-05-31 | Martin Stjernholm | | throw (err);
|
596425 | 1999-11-19 | Per Hedbor | | }
|
beba57 | 2000-03-20 | Martin Stjernholm | | #ifdef THREADS
Thread.Mutex enable_modules_mutex = Thread.Mutex();
|
c6bf40 | 2001-09-10 | Martin Stjernholm | | #define MODULE_LOCK(TYPE) \
Thread.MutexKey enable_modules_lock = enable_modules_mutex->lock (TYPE)
|
beba57 | 2000-03-20 | Martin Stjernholm | | #else
|
c6bf40 | 2001-09-10 | Martin Stjernholm | | #define MODULE_LOCK(TYPE)
|
beba57 | 2000-03-20 | Martin Stjernholm | | #endif
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | static int enable_module_batch_msgs;
|
2f7920 | 2000-03-27 | Per Hedbor | | RoxenModule enable_module( string modname, RoxenModule|void me,
|
bcf566 | 2000-04-05 | Per Hedbor | | ModuleInfo|void moduleinfo,
|
e6cd83 | 2002-04-09 | Marcus Wellhardh | | int|void nostart, int|void nosave )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c6bf40 | 2001-09-10 | Martin Stjernholm | | MODULE_LOCK (2);
|
c5e096 | 1999-10-04 | Per Hedbor | | int id;
|
e351dd | 1999-11-29 | Per Hedbor | | ModuleCopies module;
|
c5e096 | 1999-10-04 | Per Hedbor | | int pr;
mixed err;
int module_type;
|
acff93 | 2001-08-14 | Per Hedbor | | if( forcibly_added[modname] == 2 )
|
747a7c | 2001-08-13 | Per Hedbor | | return search(otomod, modname);
|
4867e9 | 2000-09-05 | Per Hedbor | | if( datacache ) datacache->flush();
|
8b16fe | 2000-09-05 | Per Hedbor | |
|
e7e603 | 1999-11-05 | Per Hedbor | | if( sscanf(modname, "%s#%d", modname, id ) != 2 )
|
2f7920 | 2000-03-27 | Per Hedbor | | while( modules[ modname ] && modules[ modname ][ id ] )
|
4f43eb | 1999-11-05 | Per Hedbor | | id++;
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
1e7925 | 2001-07-11 | Martin Stjernholm | | roxen->bootstrap_info->set (({this_object(), modname + "#" + id}));
|
a42fe4 | 2001-07-05 | Martin Nilsson | | #ifdef MODULE_DEBUG
|
7f0008 | 1998-03-20 | Per Hedbor | | int start_time = gethrtime();
|
a42fe4 | 2001-07-05 | Martin Nilsson | | #endif
|
25171c | 1999-11-06 | Per Hedbor | |
|
2f7920 | 2000-03-27 | Per Hedbor | | if( !moduleinfo )
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | {
|
2e8d0f | 2001-06-28 | Martin Stjernholm | | moduleinfo = roxen->find_module( modname );
|
2f7920 | 2000-03-27 | Per Hedbor | |
if (!moduleinfo)
{
report_warning("Failed to load %s. The module probably "
"doesn't exist in the module path.\n", modname);
|
8b700e | 2000-09-19 | Martin Stjernholm | | got_no_delayed_load = -1;
|
3557f5 | 2001-06-30 | Martin Stjernholm | | roxen->bootstrap_info->set (0);
|
2f7920 | 2000-03-27 | Per Hedbor | | return 0;
}
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | string descr = moduleinfo->get_name() + (id ? " copy " + (id + 1) : "");
|
835c6c | 2001-06-17 | Martin Nilsson | |
|
9a1d47 | 2000-01-12 | Martin Stjernholm | |
|
3bbda8 | 1997-06-11 | Henrik Grubbström (Grubba) | | #ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs)
report_debug(" %-43s... \b", descr );
|
c5e096 | 1999-10-04 | Per Hedbor | | else
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | report_debug("Enabling " + descr + "\n");
|
3bbda8 | 1997-06-11 | Henrik Grubbström (Grubba) | | #endif
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
0b7d2b | 1999-12-22 | Per Hedbor | | module = modules[ modname ];
|
c5e096 | 1999-10-04 | Per Hedbor | |
if(!module)
|
7e446c | 1999-11-24 | Per Hedbor | | modules[ modname ] = module = ModuleCopies();
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
f56958 | 1999-11-23 | Per Hedbor | | if( !me )
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
f56958 | 1999-11-23 | Per Hedbor | | if(err = catch(me = moduleinfo->instance(this_object())))
{
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs) report_debug("\bERROR\n");
|
67f60e | 2000-07-09 | Martin Nilsson | | if (err != "") {
#endif
string bt=describe_backtrace(err);
|
434bac | 2000-07-14 | Andreas Lange | | report_error("enable_module(): " +
|
49cd28 | 2000-08-11 | Andreas Lange | | LOC_M(41, "Error while initiating module copy of %s%s"),
|
434bac | 2000-07-14 | Andreas Lange | | moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));
|
67f60e | 2000-07-09 | Martin Nilsson | | #ifdef MODULE_DEBUG
}
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #endif
|
f63aca | 2000-09-08 | Martin Stjernholm | | got_no_delayed_load = -1;
|
3557f5 | 2001-06-30 | Martin Stjernholm | | roxen->bootstrap_info->set (0);
|
0b7d2b | 1999-12-22 | Per Hedbor | | return module[id];
|
f56958 | 1999-11-23 | Per Hedbor | | }
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
0b7d2b | 1999-12-22 | Per Hedbor | | if(module[id] && module[id] != me)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
0e1f26 | 2002-01-29 | Martin Stjernholm | | if( module[id]->stop ) {
if (err = catch( module[id]->stop() )) {
string bt=describe_backtrace(err);
report_error("disable_module(): " +
LOC_M(44, "Error while disabling module %s%s"),
descr, (bt ? ":\n"+bt : "\n"));
}
}
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | }
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | me->set_configuration( this_object() );
module_type = moduleinfo->type;
if (module_type & (MODULE_LOCATION|MODULE_EXTENSION|
MODULE_CONFIG|MODULE_FILE_EXTENSION|MODULE_LOGGER|
MODULE_URL|MODULE_LAST|MODULE_PROVIDER|
|
b7b653 | 2002-06-06 | Anders Johansson | | MODULE_FILTER|MODULE_TAG|MODULE_FIRST|
MODULE_USERDB))
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type != MODULE_CONFIG)
|
3b1783 | 1998-11-22 | Per Hedbor | | {
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | if (err = catch {
|
23414a | 2000-07-21 | Andreas Lange | | me->defvar("_priority", 5, DLOCALE(12, "Priority"), TYPE_INT_LIST,
DLOCALE(13, "The priority of the module. 9 is highest and 0 is lowest."
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | " Modules with the same priority can be assumed to be "
|
ae57c1 | 2005-01-12 | Martin Stjernholm | | "called in random order."),
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | ({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
}) {
|
3557f5 | 2001-06-30 | Martin Stjernholm | | roxen->bootstrap_info->set (0);
|
477042 | 1999-11-22 | Henrik Grubbström (Grubba) | | throw(err);
}
|
3b1783 | 1998-11-22 | Per Hedbor | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
21306c | 2000-11-02 | Per Hedbor | | #ifdef MODULE_LEVEL_SECURITY
|
b7b653 | 2002-06-06 | Anders Johansson | | if( (module_type & ~(MODULE_LOGGER|MODULE_PROVIDER|MODULE_USERDB)) != 0 )
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | {
|
bc0fa0 | 2001-03-08 | Per Hedbor | |
|
23414a | 2000-07-21 | Andreas Lange | |
me->defvar("_seclevels", "", DLOCALE(16, "Security: Patterns"),
TYPE_TEXT_FIELD,
|
89d1d8 | 2001-05-16 | Martin Nilsson | | DLOCALE(245,
|
62e2cb | 2001-03-08 | Per Hedbor | | "The syntax is:\n"
" \n<dl>"
" <dt><b>userdb</b> <i>userdatabase module</i></dt>\n"
" <dd> Select a non-default userdatabase module. The default is to "
" search all modules. The userdatabase module config_userdb is always "
" present, and contains the configuration users</dd>\n"
"<dt><b>authmethod</b> <i>authentication module</i></dt>\n"
"<dd>Select a non-default authentication method.</dd>"
"<dt><b>realm</b> <i>realm name</i></dt>\n"
"<dd>The realm is used when user authentication info is requested</dd>"
"</dl>\n"
" Below, CMD is one of 'allow' and 'deny'\n"
" <dl>\n"
" <dt>CMD <b>ip</b>=<i>ip/bits</i> [return]<br />\n"
" CMD <b>ip</b>=<i>ip:mask</i> [return] <br />\n"
" CMD <b>ip</b>=<i>pattern[,pattern,...]</i> [return] <br /></dt>\n"
" <dd>Match the remote IP-address.</dd>\n"
" \n"
" <dt>CMD <b>user</b>=<i>name[,name,...]</i> [return]</dt>\n"
" <dd>Requires a authenticated user. If the user name 'any' is used, any "
"valid user will be OK. Otherwise, one of the listed users are required.</dd>"
" <dt>CMD <b>group</b>=<i>name[,name,...]</i> [return]</dt>\n"
"<dd>Requires a authenticated user with a group. If the group name "
" 'any' is used, any valid group will be OK. Otherwise, one of the "
"listed groups are required.</dd>\n"
" \n"
"<dt>CMD <b>dns</b>=<i>pattern[,pattern,...]</i> [return]</dt>\n"
"<dd>Require one of the specified DNS domain-names</dd>"
" \n"
"<dt>CMD <b>time</b>=<i>HH:mm-HH:mm</i> [return]</dt>\n"
"<dd>Only allow access to the module from the first time to the "
" second each day. Both times should be specified in 24-hour "
" HH:mm format.</dd>\n"
"<dt>CMD <b>day</b>=<i>day[,day,...]</i> [return]</dt>\n"
"<dd>Only allow access during certain days. Day is either a numerical "
|
d5a37b | 2004-02-20 | Martin Stjernholm | | " value (Monday=1, Sunday=7) or a string (monday, tuesday etc)</dd>"
|
62e2cb | 2001-03-08 | Per Hedbor | | "</dl><p>\n"
" pattern is always a glob pattern (* = any characters, ? = any character).\n"
"</p><p>\n"
" return means that reaching this command results in immediate\n"
" return, only useful for 'allow'.</p>\n"
" \n"
" <p>'deny' always implies a return, no futher testing is done if a\n"
" 'deny' match.</p>\n"));
|
23414a | 2000-07-21 | Andreas Lange | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(!(module_type & MODULE_PROXY))
|
14179b | 1997-01-29 | Per Hedbor | | {
|
23414a | 2000-07-21 | Andreas Lange | | me->defvar("_seclvl", 0, DLOCALE(18, "Security: Security level"),
TYPE_INT,
|
55a866 | 2000-11-20 | Per Hedbor | | DLOCALE(305, "The modules security level is used to determine if a "
|
3bf345 | 1998-10-01 | Peter Bortas | | " request should be handled by the module."
"\n<p><h2>Security level vs Trust level</h2>"
" Each module has a configurable <i>security level</i>."
" Each request has an assigned trust level. Higher"
" <i>trust levels</i> grants access to modules with higher"
" <i>security levels</i>."
"\n<p><h2>Definitions</h2><ul>"
|
f498ed | 2000-07-11 | Martin Nilsson | | " <li>A requests initial Trust level is infinitely high.</li>"
|
3bf345 | 1998-10-01 | Peter Bortas | | " <li> A request will only be handled by a module if its"
" <i>trust level</i> is higher or equal to the"
|
f498ed | 2000-07-11 | Martin Nilsson | | " <i>security level</i> of the module.</li>"
|
3bf345 | 1998-10-01 | Peter Bortas | | " <li> Each time the request is handled by a module the"
" <i>trust level</i> of the module will be set to the"
" lower of its <i>trust level</i> and the modules"
|
90ecbb | 2000-11-15 | Per Hedbor | | " <i>security level</i>, <i>unless</i> the security "
" level of the module is 0, which is a special "
" case and means that no change should be made.</li>"
|
f498ed | 2000-07-11 | Martin Nilsson | | " </ul></p>"
|
3bf345 | 1998-10-01 | Peter Bortas | | "\n<p><h2>Example</h2>"
" Modules:<ul>"
|
f498ed | 2000-07-11 | Martin Nilsson | | " <li> User filesystem, <i>security level</i> 1</li>"
" <li> Filesystem module, <i>security level</i> 3</li>"
" <li> CGI module, <i>security level</i> 2</li>"
" </ul></p>"
|
3bf345 | 1998-10-01 | Peter Bortas | | "\n<p>A request handled by \"User filesystem\" is assigned"
" a <i>trust level</i> of one after the <i>security"
" level</i> of that module. That request can then not be"
" handled by the \"CGI module\" since that module has a"
" higher <i>security level</i> than the requests trust"
|
f498ed | 2000-07-11 | Martin Nilsson | | " level.</p>"
|
3bf345 | 1998-10-01 | Peter Bortas | | "\n<p>On the other hand, a request handled by the the"
" \"Filsystem module\" could later be handled by the"
|
f498ed | 2000-07-11 | Martin Nilsson | | " \"CGI module\".</p>"));
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | } else {
me->definvisvar("_seclvl", -10, TYPE_INT);
|
14179b | 1997-01-29 | Per Hedbor | | }
|
3bbda8 | 1997-06-11 | Henrik Grubbström (Grubba) | | }
|
21306c | 2000-11-02 | Per Hedbor | | #endif
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | } else {
me->defvar("_priority", 0, "", TYPE_INT, "", 0, 1);
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
a0fbcc | 2000-04-05 | Martin Stjernholm | | mapping(string:mixed) stored_vars = retrieve(modname + "#" + id, this_object());
int has_stored_vars = sizeof (stored_vars);
me->setvars(stored_vars);
|
33e635 | 1998-02-28 | Martin Stjernholm | |
|
0b7d2b | 1999-12-22 | Per Hedbor | | module[ id ] = me;
|
37c1b3 | 1999-10-12 | Per Hedbor | | otomod[ me ] = modname+"#"+id;
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
bcf566 | 2000-04-05 | Per Hedbor | | if(!nostart) call_start_callbacks( me, moduleinfo, module );
#ifdef MODULE_DEBUG
|
be87a7 | 2002-04-17 | Marcus Wellhardh | | if (enable_module_batch_msgs) {
if(moduleinfo->config_locked[this_object()])
report_debug("\bLocked %6.1fms\n", (gethrtime()-start_time)/1000.0);
else
report_debug("\bOK %6.1fms\n", (gethrtime()-start_time)/1000.0);
}
#else
if(moduleinfo->config_locked[this_object()])
report_error(" Error: \"%s\" not loaded (license restriction).\n",
moduleinfo->get_name());
|
bcf566 | 2000-04-05 | Per Hedbor | | #endif
|
fd24e2 | 2000-08-28 | Per Hedbor | | if( !enabled_modules[modname+"#"+id] )
{
enabled_modules[modname+"#"+id] = 1;
|
e6cd83 | 2002-04-09 | Marcus Wellhardh | | if(!nosave)
store( "EnabledModules", enabled_modules, 1, this_object());
|
fd24e2 | 2000-08-28 | Per Hedbor | | }
|
6f595f | 2000-08-20 | Per Hedbor | |
|
e6cd83 | 2002-04-09 | Marcus Wellhardh | | if (!has_stored_vars && !nosave)
|
bcf566 | 2000-04-05 | Per Hedbor | | store (modname + "#" + id, me->query(), 0, this_object());
|
f63aca | 2000-09-08 | Martin Stjernholm | | if( me->no_delayed_load && got_no_delayed_load >= 0 )
got_no_delayed_load = 1;
|
a8ba69 | 2000-08-29 | Marcus Wellhardh | |
|
3557f5 | 2001-06-30 | Martin Stjernholm | | roxen->bootstrap_info->set (0);
|
bcf566 | 2000-04-05 | Per Hedbor | | return me;
}
void call_start_callbacks( RoxenModule me,
ModuleInfo moduleinfo,
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | ModuleCopies module,
void|int newly_added)
|
bcf566 | 2000-04-05 | Per Hedbor | | {
|
a8ba69 | 2000-08-29 | Marcus Wellhardh | | call_low_start_callbacks( me, moduleinfo, module );
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | call_high_start_callbacks (me, moduleinfo, newly_added);
|
a8ba69 | 2000-08-29 | Marcus Wellhardh | | }
void call_low_start_callbacks( RoxenModule me,
ModuleInfo moduleinfo,
ModuleCopies module )
{
|
40f064 | 2000-09-13 | Per Hedbor | | if(!me) return;
if(!moduleinfo) return;
if(!module) return;
|
a8ba69 | 2000-08-29 | Marcus Wellhardh | | int module_type = moduleinfo->type, pr;
mixed err;
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if (err = catch(pr = me->query("_priority")))
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs) report_debug("\bERROR\n");
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #endif
|
67f60e | 2000-07-09 | Martin Nilsson | | string bt=describe_backtrace(err);
|
49cd28 | 2000-08-11 | Andreas Lange | | report_error(LOC_M(41, "Error while initiating module copy of %s%s"),
|
67f60e | 2000-07-09 | Martin Nilsson | | moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pr = 3;
}
api_module_cache |= me->api_functions();
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(module_type & MODULE_EXTENSION)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
434bac | 2000-07-14 | Andreas Lange | | report_error("%s is an MODULE_EXTENSION, that type is no "
"longer available.\nPlease notify the modules writer.\n"
"Suitable replacement types include MODULE_FIRST and "
" MODULE_LAST.\n", moduleinfo->get_name());
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_FILE_EXTENSION)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | if (err = catch {
array arr = me->query_file_extensions();
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if (arrayp(arr))
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | string foo;
foreach( me->query_file_extensions(), foo )
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | if(pri[pr]->file_extension_modules[foo = lower_case(foo)] )
pri[pr]->file_extension_modules[foo] += ({me});
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | else
|
0ba038 | 2001-08-28 | Henrik Grubbström (Grubba) | | pri[pr]->file_extension_modules[foo] = ({me});
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | }
|
c45b2a | 1999-12-09 | Martin Stjernholm | | }) {
#ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs) report_debug("\bERROR\n");
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #endif
|
f63aca | 2000-09-08 | Martin Stjernholm | | string bt=describe_backtrace(err);
report_error(LOC_M(41, "Error while initiating module copy of %s%s"),
moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));
got_no_delayed_load = -1;
|
c45b2a | 1999-12-09 | Martin Stjernholm | | }
|
14179b | 1997-01-29 | Per Hedbor | |
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(module_type & MODULE_PROVIDER)
if (err = catch
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
747a7c | 2001-08-13 | Per Hedbor | | mixed provs = me->query_provides ? me->query_provides() : ({});
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | if(stringp(provs))
provs = (< provs >);
if(arrayp(provs))
provs = mkmultiset(provs);
if (multisetp(provs)) {
pri[pr]->provider_modules [ me ] = provs;
|
3bbda8 | 1997-06-11 | Henrik Grubbström (Grubba) | | }
|
c45b2a | 1999-12-09 | Martin Stjernholm | | }) {
#ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs) report_debug("\bERROR\n");
|
c45b2a | 1999-12-09 | Martin Stjernholm | | #endif
|
f63aca | 2000-09-08 | Martin Stjernholm | | string bt=describe_backtrace(err);
report_error(LOC_M(41, "Error while initiating module copy of %s%s"),
moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));
got_no_delayed_load = -1;
|
c45b2a | 1999-12-09 | Martin Stjernholm | | }
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_TYPES)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | {
types_module = me;
types_fun = me->type_from_extension;
}
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
f59076 | 2000-09-10 | Martin Nilsson | | if(module_type & MODULE_TAG)
|
c5e096 | 1999-10-04 | Per Hedbor | | add_parse_module( me );
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_DIRECTORIES)
|
aaf391 | 2000-09-19 | Jonas Wallden | | if (me->parse_directory)
dir_module = me;
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_LOCATION)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->location_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_LOGGER)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->logger_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_URL)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->url_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_LAST)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->last_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(module_type & MODULE_FILTER)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->filter_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if(module_type & MODULE_FIRST)
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | pri[pr]->first_modules += ({ me });
|
14179b | 1997-01-29 | Per Hedbor | |
|
7adb10 | 2007-11-05 | Henrik Grubbström (Grubba) | | foreach(registered_urls, string url) {
mapping(string:string|Configuration|Protocol) port_info = roxen.urls[url];
foreach((port_info && port_info->ports) || ({}), Protocol prot) {
if ((prot->prot_name != "snmp") || (!prot->mib)) {
continue;
}
string path = port_info->path || "";
if (has_prefix(path, "/")) {
path = path[1..];
}
if (has_suffix(path, "/")) {
path = path[..sizeof(path)-2];
}
array(int) oid_suffix = ({ sizeof(path), @((array(int))path) });
ADT.Trie sub_mib = generate_module_mib(query_oid() + ({ 8, 1 }),
oid_suffix, me, moduleinfo, module);
SNMP.set_owner(sub_mib, this_object(), me);
prot->mib->merge(sub_mib);
if (me->query_snmp_mib) {
array(int) segment = generate_module_oid_segment(me);
sub_mib = me->query_snmp_mib(query_oid() + ({ 8, 2 }) +
segment[..sizeof(segment)-2],
oid_suffix + ({ segment[-1] }));
SNMP.set_owner(sub_mib, this_object(), me);
prot->mib->merge(sub_mib);
}
}
|
a5c23c | 2007-09-10 | Henrik Grubbström (Grubba) | | }
|
ad683e | 1998-05-09 | Henrik Grubbström (Grubba) | | invalidate_cache();
|
14179b | 1997-01-29 | Per Hedbor | | }
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | void call_high_start_callbacks (RoxenModule me, ModuleInfo moduleinfo,
void|int newly_added)
|
79538a | 2002-12-10 | Martin Stjernholm | | {
if(!me) return;
if(!moduleinfo) return;
mixed err;
|
0a1a76 | 2006-05-31 | Martin Stjernholm | | if((me->start) &&
(err = catch( me->start(0, this_object(), newly_added) ) ) )
|
79538a | 2002-12-10 | Martin Stjernholm | | {
#ifdef MODULE_DEBUG
if (enable_module_batch_msgs)
report_debug("\bERROR\n");
#endif
string bt=describe_backtrace(err);
report_error(LOC_M(41, "Error while initiating module copy of %s%s"),
moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));
got_no_delayed_load = -1;
}
if( inited && me->ready_to_receive_requests )
if( mixed q = catch( me->ready_to_receive_requests( this_object() ) ) )
{
#ifdef MODULE_DEBUG
if (enable_module_batch_msgs) report_debug("\bERROR\n");
#endif
report_error( "While calling ready_to_receive_requests:\n"+
describe_backtrace( q ) );
got_no_delayed_load = -1;
}
}
|
a6ef1f | 2000-03-28 | Johan Sundström | |
|
199d03 | 1999-09-05 | Francesco Chemolli | | string check_variable(string name, mixed value)
|
14179b | 1997-01-29 | Per Hedbor | | {
switch(name)
{
|
cffbaa | 2000-04-11 | Per Hedbor | |
|
c109fc | 2001-07-21 | Martin Stjernholm | | case "MyWorldLocation":
case "URLs":
fix_my_url();
return 0;
|
b9c387 | 2002-03-27 | Per Hedbor | |
|
e42791 | 2001-06-30 | Honza Petrous | | #ifdef SNMP_AGENT
case "snmp_process":
if (objectp(roxen->snmpagent)) {
int cid = get_config_id();
value ? roxen->snmpagent->add_virtserv(cid) : roxen->snmpagent->del_virtserv(cid);
}
return 0;
#endif
|
14179b | 1997-01-29 | Per Hedbor | | }
}
|
2f4ac1 | 2000-11-02 | Per Hedbor | | void module_changed( ModuleInfo moduleinfo,
RoxenModule me )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
2f4ac1 | 2000-11-02 | Per Hedbor | | clean_up_for_module( moduleinfo, me );
call_low_start_callbacks( me,
moduleinfo,
modules[ moduleinfo->sname ] );
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
2f4ac1 | 2000-11-02 | Per Hedbor | | void clean_up_for_module( ModuleInfo moduleinfo,
RoxenModule me )
{
int pr;
|
c5e096 | 1999-10-04 | Per Hedbor | | if(moduleinfo->type & MODULE_FILE_EXTENSION)
|
14179b | 1997-01-29 | Per Hedbor | | {
string foo;
|
d54d06 | 1999-06-10 | Martin Stjernholm | | for(pr=0; pr<10; pr++)
foreach( indices (pri[pr]->file_extension_modules), foo )
pri[pr]->file_extension_modules[foo]-=({me});
|
14179b | 1997-01-29 | Per Hedbor | | }
|
c5e096 | 1999-10-04 | Per Hedbor | | if(moduleinfo->type & MODULE_PROVIDER) {
|
ae32d0 | 1998-03-23 | David Hedbor | | for(pr=0; pr<10; pr++)
m_delete(pri[pr]->provider_modules, me);
}
|
10c7e1 | 1999-12-28 | Martin Nilsson | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(moduleinfo->type & MODULE_TYPES)
|
14179b | 1997-01-29 | Per Hedbor | | {
types_module = 0;
types_fun = 0;
}
|
f59076 | 2000-09-10 | Martin Nilsson | | if(moduleinfo->type & MODULE_TAG)
|
b796b5 | 1998-11-18 | Per Hedbor | | remove_parse_module( me );
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_DIRECTORIES )
|
14179b | 1997-01-29 | Per Hedbor | | dir_module = 0;
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_LOCATION )
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->location_modules -= ({ me });
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_URL )
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->url_modules -= ({ me });
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_LAST )
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->last_modules -= ({ me });
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_FILTER )
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->filter_modules -= ({ me });
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_FIRST ) {
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->first_modules -= ({ me });
|
f12890 | 1997-08-15 | Henrik Grubbström (Grubba) | | }
|
14179b | 1997-01-29 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if( moduleinfo->type & MODULE_LOGGER )
|
14179b | 1997-01-29 | Per Hedbor | | for(pr=0; pr<10; pr++)
pri[pr]->logger_modules -= ({ me });
|
7adb10 | 2007-11-05 | Henrik Grubbström (Grubba) | |
foreach(registered_urls, string url) {
mapping(string:string|Configuration|Protocol) port_info = roxen.urls[url];
foreach((port_info && port_info->ports) || ({}), Protocol prot) {
if ((prot->prot_name != "snmp") || (!prot->mib)) {
continue;
}
SNMP.remove_owned(prot->mib, this_object(), me);
}
}
|
2f4ac1 | 2000-11-02 | Per Hedbor | | }
int disable_module( string modname, int|void nodest )
{
|
c6bf40 | 2001-09-10 | Martin Stjernholm | | MODULE_LOCK (2);
|
2f4ac1 | 2000-11-02 | Per Hedbor | | RoxenModule me;
int id, pr;
sscanf(modname, "%s#%d", modname, id );
if( datacache ) datacache->flush();
ModuleInfo moduleinfo = roxen.find_module( modname );
mapping module = modules[ modname ];
string descr = moduleinfo->get_name() + (id ? " copy " + (id + 1) : "");
if(!module)
{
report_error("disable_module(): " +
LOC_M(42, "Failed to disable module:\n"
"No module by that name: \"%s\".\n"), modname);
return 0;
}
me = module[id];
m_delete(module->copies, id);
if(!sizeof(module->copies))
m_delete( modules, modname );
invalidate_cache();
if(!me)
{
report_error("disable_module(): " +
LOC_M(43, "Failed to disable module \"%s\".\n"),
descr);
return 0;
}
if(me->stop)
if (mixed err = catch (me->stop())) {
string bt=describe_backtrace(err);
report_error("disable_module(): " +
LOC_M(44, "Error while disabling module %s%s"),
descr, (bt ? ":\n"+bt : "\n"));
}
#ifdef MODULE_DEBUG
report_debug("Disabling "+descr+"\n");
#endif
|
14179b | 1997-01-29 | Per Hedbor | |
|
2f4ac1 | 2000-11-02 | Per Hedbor | | clean_up_for_module( moduleinfo, me );
|
14179b | 1997-01-29 | Per Hedbor | |
|
5fbaec | 2001-04-11 | Per Hedbor | | if( !nodest )
{
|
a42fe4 | 2001-07-05 | Martin Nilsson | | m_delete( enabled_modules, modname + "#" + id );
|
acff93 | 2001-08-14 | Per Hedbor | | m_delete( forcibly_added, modname + "#" + id );
|
5fbaec | 2001-04-11 | Per Hedbor | | store( "EnabledModules",enabled_modules, 1, this_object());
|
2f7920 | 2000-03-27 | Per Hedbor | | destruct(me);
|
5fbaec | 2001-04-11 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | return 1;
}
|
9a8a15 | 2000-09-25 | Per Hedbor | | RoxenModule find_module(string name)
|
9fd809 | 2000-08-08 | Johan Sundström | |
|
d5c864 | 2001-08-23 | Martin Stjernholm | |
|
14179b | 1997-01-29 | Per Hedbor | | {
int id;
sscanf(name, "%s#%d", name, id);
if(modules[name])
|
c5e096 | 1999-10-04 | Per Hedbor | | return modules[name]->copies[id];
|
14179b | 1997-01-29 | Per Hedbor | | return 0;
}
|
acff93 | 2001-08-14 | Per Hedbor | | mapping forcibly_added = ([]);
|
f5a274 | 1999-10-18 | Per Hedbor | | int add_modules( array(string) mods, int|void now )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
ba18d7 | 1999-11-27 | Per Hedbor | | #ifdef MODULE_DEBUG
|
c5e096 | 1999-10-04 | Per Hedbor | | int wr;
|
ba18d7 | 1999-11-27 | Per Hedbor | | #endif
|
c5e096 | 1999-10-04 | Per Hedbor | | foreach (mods, string mod)
|
8f061b | 1999-11-19 | Per Hedbor | | {
sscanf( mod, "%s#", mod );
|
10c7e1 | 1999-12-28 | Martin Nilsson | | if( ((now && !modules[ mod ]) ||
|
0ce25d | 1999-11-15 | Per Hedbor | | !enabled_modules[ mod+"#0" ] )
&& !forcibly_added[ mod+"#0" ])
|
14179b | 1997-01-29 | Per Hedbor | | {
|
ba18d7 | 1999-11-27 | Per Hedbor | | #ifdef MODULE_DEBUG
|
c5e096 | 1999-10-04 | Per Hedbor | | if( !wr++ )
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if (enable_module_batch_msgs)
report_debug("\b[ adding req module" + (sizeof (mods) > 1 ? "s" : "") + "\n");
else
report_debug("Adding required module" + (sizeof (mods) > 1 ? "s" : "") + "\n");
|
14179b | 1997-01-29 | Per Hedbor | | #endif
|
747a7c | 2001-08-13 | Per Hedbor | | forcibly_added[ mod+"#0" ] = 1;
|
acff93 | 2001-08-14 | Per Hedbor | | enable_module( mod+"#0" );
forcibly_added[ mod+"#0" ] = 2;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
8f061b | 1999-11-19 | Per Hedbor | | }
|
ba18d7 | 1999-11-27 | Per Hedbor | | #ifdef MODULE_DEBUG
|
9a1d47 | 2000-01-12 | Martin Stjernholm | | if( wr && enable_module_batch_msgs )
|
ed8d26 | 1999-12-30 | Martin Stjernholm | | report_debug("] \b");
|
c79b26 | 1998-02-05 | Johan Schön | | #endif
|
14179b | 1997-01-29 | Per Hedbor | | }
|
850c28 | 2001-01-10 | Per Hedbor | | #if ROXEN_COMPAT < 2.2
|
279a0c | 1997-11-26 | Henrik Grubbström (Grubba) | |
|
14179b | 1997-01-29 | Per Hedbor | |
|
279a0c | 1997-11-26 | Henrik Grubbström (Grubba) | | mapping(string:string) sql_urls = ([]);
|
3f059e | 2001-06-24 | Per Hedbor | | constant sql_cache_get = DBManager.sql_cache_get;
|
ed9313 | 1998-07-09 | Johan Schön | |
|
a31e39 | 2006-09-18 | Martin Stjernholm | | Sql.Sql sql_connect(string db, void|string charset)
|
279a0c | 1997-11-26 | Henrik Grubbström (Grubba) | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | if (sql_urls[db])
|
a31e39 | 2006-09-18 | Martin Stjernholm | | return sql_cache_get(sql_urls[db], 0, charset);
|
c5e096 | 1999-10-04 | Per Hedbor | | else
|
a31e39 | 2006-09-18 | Martin Stjernholm | | return sql_cache_get(db, 0, charset);
|
279a0c | 1997-11-26 | Henrik Grubbström (Grubba) | | }
|
850c28 | 2001-01-10 | Per Hedbor | | #endif
|
14179b | 1997-01-29 | Per Hedbor | |
|
c109fc | 2001-07-21 | Martin Stjernholm | | static string my_url;
void fix_my_url()
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c109fc | 2001-07-21 | Martin Stjernholm | | my_url = query ("MyWorldLocation");
|
f41857 | 2001-07-21 | Martin Stjernholm | | if (!sizeof (my_url) &&
!(my_url = Roxen.get_world (query ("URLs"))))
|
3ec7cf | 2001-07-21 | Martin Stjernholm | |
my_url = "";
else
if (!has_suffix (my_url, "/")) my_url += "/";
|
14179b | 1997-01-29 | Per Hedbor | | }
|
6b67fe | 2001-08-24 | Martin Nilsson | |
|
c109fc | 2001-07-21 | Martin Stjernholm | | strin |