e3bda3 | 2000-01-12 | Martin Nilsson | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
b64328 | 2000-03-16 | Martin Nilsson | |
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
900d71 | 2001-05-09 | Jonas Wallden | | constant cvs_version = "$Id: http.pike,v 1.313 2001/05/09 11:54:32 jonasw Exp $";
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
86e77d | 1998-05-07 | Per Hedbor | | #define MAGIC_ERROR
|
19ebcb | 2000-09-01 | Per Hedbor | | #ifndef INITIAL_CACHEABLE
# define INITIAL_CACHEABLE 300
#endif
|
86e77d | 1998-05-07 | Per Hedbor | | #ifdef MAGIC_ERROR
inherit "highlight_pike";
#endif
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
2a2a5b | 1996-12-01 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <config.h>
|
9c1900 | 2001-02-27 | Per Hedbor | | #define TIMER_PREFIX "http:"
#include <timers.h>
|
26f44e | 2000-08-13 | Per Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | #ifdef PROFILE
|
c5e096 | 1999-10-04 | Per Hedbor | | #define HRTIME() gethrtime()
#define HRSEC(X) ((int)((X)*1000000))
#define SECHR(X) ((X)/(float)1000000)
|
8afc81 | 1998-02-04 | Per Hedbor | | int req_time = HRTIME();
|
ebb1c5 | 1998-02-24 | Per Hedbor | | #endif
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
cbe6c6 | 2000-03-18 | Martin Stjernholm | | #ifdef ID_OBJ_DEBUG
Debug.ObjectMarker __marker = Debug.ObjectMarker (this_object());
#endif
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #ifdef REQUEST_DEBUG
|
41b77c | 1999-07-15 | David Hedbor | | int footime, bartime;
|
338ffa | 2000-02-15 | Martin Nilsson | | #define REQUEST_WERR(X) bartime = gethrtime()-footime; werror("%s (%d)\n", (X), bartime);footime=gethrtime()
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #else
|
6a409d | 1999-12-27 | Martin Nilsson | | #define REQUEST_WERR(X)
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | #endif
|
323569 | 1998-03-26 | Per Hedbor | | #ifdef FD_DEBUG
|
6a409d | 1999-12-27 | Martin Nilsson | | #define MARK_FD(X) catch{REQUEST_WERR(X); mark_fd(my_fd->query_fd(), (X)+" "+remoteaddr);}
|
323569 | 1998-03-26 | Per Hedbor | | #else
|
bc0fa0 | 2001-03-08 | Per Hedbor | | #define MARK_FD(X)
|
323569 | 1998-03-26 | Per Hedbor | | #endif
|
bdd308 | 2000-05-14 | Francesco Chemolli | | #ifdef THROTTLING_DEBUG
#undef THROTTLING_DEBUG
#define THROTTLING_DEBUG(X) werror("Throttling: "+X+"\n")
#else
#define THROTTLING_DEBUG(X)
#endif
|
f49bd3 | 2000-01-20 | Martin Nilsson | | constant decode = MIME.decode_base64;
|
338ffa | 2000-02-15 | Martin Nilsson | | constant find_supports_and_vars = roxen.find_supports_and_vars;
|
f49bd3 | 2000-01-20 | Martin Nilsson | | constant version = roxen.version;
constant _query = roxen.query;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
7ee565 | 1996-12-10 | Per Hedbor | | private static array(string) cache;
private static int wanted_data, have_data;
|
cf4a90 | 2001-01-19 | Per Hedbor | | Configuration conf;
Protocol port_obj;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
#include <roxen.h>
#include <module.h>
|
470ed7 | 2000-01-03 | Martin Nilsson | | #include <variables.h>
|
773ac6 | 2001-03-20 | Martin Stjernholm | | #include <request_trace.h>
#define MY_TRACE_ENTER(A, B) \
do {RequestID id = this_object(); TRACE_ENTER (A, B);} while (0)
#define MY_TRACE_LEAVE(A) \
do {RequestID id = this_object(); TRACE_LEAVE (A);} while (0)
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9211b2 | 1998-04-24 | Per Hedbor | | int time;
|
a86c3b | 2000-08-28 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | string raw_url;
|
d7b087 | 1997-08-31 | Per Hedbor | | int do_not_disconnect;
|
2fdf09 | 2000-12-02 | Per Hedbor | |
mapping(string:mixed) real_variables = ([]);
|
99cb5e | 2001-02-05 | Per Hedbor | | FakedVariables variables = FakedVariables( real_variables );
|
2fdf09 | 2000-12-02 | Per Hedbor | |
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | mapping (string:mixed) misc =
([
#ifdef REQUEST_DEBUG
"trace_enter":lambda(mixed ...args) {
|
52e082 | 2000-03-07 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("TRACE_ENTER(%{%O,%})", args));
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | },
"trace_leave":lambda(mixed ...args) {
|
52e082 | 2000-03-07 | Henrik Grubbström (Grubba) | | REQUEST_WERR(sprintf("TRACE_LEAVE(%{%O,%})", args));
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | }
|
338ffa | 2000-02-15 | Martin Nilsson | | #endif // REQUEST_DEBUG
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | ]);
|
8200cd | 1998-07-14 | Henrik Grubbström (Grubba) | | mapping (string:string) cookies = ([ ]);
mapping (string:string) request_headers = ([ ]);
|
f49bd3 | 2000-01-20 | Martin Nilsson | | mapping (string:string) client_var = ([ ]);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
06d533 | 1998-04-03 | Per Hedbor | | multiset (string) prestate = (< >);
multiset (string) config = (< >);
|
f16377 | 2000-08-28 | Per Hedbor | | multiset (string) supports;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | multiset (string) pragma = (< >);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
string remoteaddr, host;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | array (string) client;
array (string) referer;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
beaca0 | 1998-02-20 | Per Hedbor | | mapping file;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
object my_fd;
string prot;
|
1afe37 | 1997-06-12 | Henrik Grubbström (Grubba) | | string clientprot;
|
b1fca0 | 1996-11-12 | Per Hedbor | | string method;
string realfile, virtfile;
string rest_query="";
string raw;
string query;
string not_query;
|
60a1a1 | 1998-08-03 | Henrik Grubbström (Grubba) | | string extra_extension = "";
|
ebb1c5 | 1998-02-24 | Per Hedbor | | string data, leftovers;
|
cf4a90 | 2001-01-19 | Per Hedbor | |
class AuthEmulator
{
mixed `[]( int i )
{
User u;
switch( i )
{
case 0:
return conf->authenticate( this_object() );
case 1:
if( u = conf->authenticate( this_object() ) )
return u->name();
if( realauth )
return (realauth/":")[0];
case 2:
if( u = conf->authenticate( this_object() ) )
return 0;
if( realauth )
return ((realauth/":")[1..])*":";
}
}
int `!( )
{
return !realauth;
}
}
AuthEmulator auth;
string rawauth, realauth;
|
b1fca0 | 1996-11-12 | Per Hedbor | | string since;
|
0b0d08 | 2000-02-14 | Per Hedbor | | array(string) output_charset = ({});
|
653d7d | 2000-02-14 | Per Hedbor | | string input_charset;
|
0b0d08 | 2000-02-14 | Per Hedbor | |
|
cf68f1 | 2000-02-16 | Per Hedbor | | void set_output_charset( string|function to, int|void mode )
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
|
cf68f1 | 2000-02-16 | Per Hedbor | | if( search( output_charset, to ) != -1 )
|
653d7d | 2000-02-14 | Per Hedbor | | return;
|
cf68f1 | 2000-02-16 | Per Hedbor | |
switch( mode )
{
case 0:
output_charset = ({ to });
break;
case 1:
if( !sizeof( output_charset ) )
output_charset = ({ to });
break;
case 2:
output_charset |= ({ to });
break;
}
|
0b0d08 | 2000-02-14 | Per Hedbor | | }
|
cf68f1 | 2000-02-16 | Per Hedbor | | string charset_name( function|string what )
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
|
cf68f1 | 2000-02-16 | Per Hedbor | | switch( f )
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
|
cf68f1 | 2000-02-16 | Per Hedbor | | case string_to_unicode: return "ISO10646-1";
case string_to_utf8: return "UTF-8";
default: return upper_case((string)what);
|
0b0d08 | 2000-02-14 | Per Hedbor | | }
|
cf68f1 | 2000-02-16 | Per Hedbor | | }
function charset_function( function|string what )
{
switch( f )
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
|
cf68f1 | 2000-02-16 | Per Hedbor | | case "ISO-10646-1":
case "ISO10646-1":
case string_to_unicode:
return string_to_unicode;
case "UTF-8":
case string_to_utf8:
return string_to_utf8;
default:
|
c8f39d | 2000-09-16 | Per Hedbor | | catch {
return Roxen._charset_decoder( Locale.Charset.encoder( (string)what,"" ) )->decode;
};
|
cf68f1 | 2000-02-16 | Per Hedbor | | }
|
c8f39d | 2000-09-16 | Per Hedbor | | return lambda(string what){return what;};
|
cf68f1 | 2000-02-16 | Per Hedbor | | }
static array(string) join_charset( string old,
function|string add,
function|void oldcodec)
{
switch( old&&upper_case(old) )
{
case 0:
return ({ charset_name( add ), charset_function( add ) });
case "ISO10646-1":
case "UTF-8":
return ({ old, oldcodec });
case "ISO-2022":
return ({ old, oldcodec });
default:
return ({ charset_name( add ), charset_function( add ) });
}
}
static array(string) output_encode( string what )
{
string charset;
function encoder;
foreach( output_charset, string|function f )
[charset,encoder] = join_charset( charset, f, encoder );
if( !encoder )
|
62caea | 2000-02-14 | Per Hedbor | | if( String.width( what ) > 8 )
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
charset = "UTF-8";
|
cf68f1 | 2000-02-16 | Per Hedbor | | encoder = string_to_utf8;
|
0b0d08 | 2000-02-14 | Per Hedbor | | }
|
cf68f1 | 2000-02-16 | Per Hedbor | | if( encoder )
what = encoder( what );
|
0b0d08 | 2000-02-14 | Per Hedbor | | return ({ charset, what });
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ed1516 | 1999-11-19 | Per Hedbor | | void decode_map( mapping what, function decoder )
{
foreach( indices( what ), mixed q )
{
string ni;
mixed val;
if( stringp( q ) )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | catch { ni = decoder( q ); };
|
ed1516 | 1999-11-19 | Per Hedbor | | val = what[q];
if( stringp( val ) )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | catch { val = decoder( val ); };
|
ed1516 | 1999-11-19 | Per Hedbor | | else if( arrayp( val ) )
val = map( val, lambda( mixed q ) {
if( stringp( q ) )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | catch { return decoder( q ); };
|
ed1516 | 1999-11-19 | Per Hedbor | | return q;
} );
else if( mappingp( val ) )
decode_map( val, decoder );
else if( multisetp( val ) )
val = mkmultiset( map( indices(val), lambda( mixed q ) {
if( stringp( q ) )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | catch { return decoder( q ); };
|
ed1516 | 1999-11-19 | Per Hedbor | | return q;
} ));
what[ni] = val;
if( q != ni )
m_delete( what, q );
}
}
|
653d7d | 2000-02-14 | Per Hedbor | | void decode_charset_encoding( string|function(string:string) decoder )
|
ed1516 | 1999-11-19 | Per Hedbor | | {
|
653d7d | 2000-02-14 | Per Hedbor | | if(stringp(decoder))
|
a3ebea | 2000-08-12 | Per Hedbor | | decoder = Roxen._charset_decoder(Locale.Charset.decoder(decoder))->decode;
|
653d7d | 2000-02-14 | Per Hedbor | |
|
0b0d08 | 2000-02-14 | Per Hedbor | | if( misc->request_charset_decoded )
return;
|
653d7d | 2000-02-14 | Per Hedbor | |
|
99cb5e | 2001-02-05 | Per Hedbor | | misc->request_charset_decoded = 1;
|
ed1516 | 1999-11-19 | Per Hedbor | | if( !decoder )
return;
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | |
string safe_decoder(string s) {
catch { return decoder(s); };
return s;
};
if( prot ) prot = safe_decoder( prot );
if( clientprot ) clientprot = safe_decoder( clientprot );
if( method ) method = safe_decoder( method );
if( rest_query ) rest_query = safe_decoder( rest_query );
if( query ) query = safe_decoder( query );
if( not_query ) not_query = safe_decoder( not_query );
|
cf4a90 | 2001-01-19 | Per Hedbor | | if( realauth )
|
ed1516 | 1999-11-19 | Per Hedbor | | {
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | rawauth = safe_decoder( rawauth );
realauth = safe_decoder( realauth );
|
ed1516 | 1999-11-19 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | | if( since )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | since = safe_decoder( since );
|
ed1516 | 1999-11-19 | Per Hedbor | |
|
2fdf09 | 2000-12-02 | Per Hedbor | | decode_map( real_variables, decoder );
|
ed1516 | 1999-11-19 | Per Hedbor | | decode_map( misc, decoder );
decode_map( cookies, decoder );
decode_map( request_headers, decoder );
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | |
|
ed1516 | 1999-11-19 | Per Hedbor | | if( client )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | client = map( client, safe_decoder );
|
ed1516 | 1999-11-19 | Per Hedbor | | if( referer )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | referer = map( referer, safe_decoder );
prestate = mkmultiset( map( (array(string))indices( prestate ),
safe_decoder ) );
config = mkmultiset( map( (array(string))indices( config ),
safe_decoder ) );
pragma = mkmultiset( map( (array(string))indices( pragma ),
safe_decoder ) );
|
ed1516 | 1999-11-19 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
199d03 | 1999-09-05 | Francesco Chemolli | | object pipe;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
ba88df | 1999-09-29 | Francesco Chemolli | |
mapping throttle=([]);
|
199d03 | 1999-09-05 | Francesco Chemolli | | object throttler;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
e5bad2 | 1998-02-10 | Per Hedbor | | private void setup_pipe()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
199d03 | 1999-09-05 | Francesco Chemolli | | if(!my_fd) {
|
184261 | 1997-05-30 | Henrik Grubbström (Grubba) | | end();
return;
}
|
5f6dae | 2000-08-13 | Per Hedbor | | if ( throttle->doit && conf->query("req_throttle") )
throttle->doit = 0;
if( throttle->doit || conf->throttler )
pipe=roxen.slowpipe();
else
pipe=roxen.fastpipe();
if (throttle->doit)
{
throttle->rate=max(throttle->rate, conf->query("req_throttle_min"));
|
ba88df | 1999-09-29 | Francesco Chemolli | | pipe->throttle(throttle->rate,
(int)(throttle->rate*conf->query("req_throttle_depth_mult")),
0);
|
bdd308 | 2000-05-14 | Francesco Chemolli | | THROTTLING_DEBUG("throtting request at "+throttle->rate);
|
199d03 | 1999-09-05 | Francesco Chemolli | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | if ( conf->throttler )
|
199d03 | 1999-09-05 | Francesco Chemolli | | pipe->assign_throttler(conf->throttler);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
199d03 | 1999-09-05 | Francesco Chemolli | |
void send (string|object what, int|void len)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("send(%O, %O)\n", what, len));
|
9c1900 | 2001-02-27 | Per Hedbor | | if( len && port_obj->minimum_bitrate )
call_out( end, len / port_obj->minimum_bitrate );
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!what) return;
|
e5bad2 | 1998-02-10 | Per Hedbor | | if(!pipe) setup_pipe();
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(stringp(what)) pipe->write(what);
|
e5bad2 | 1998-02-10 | Per Hedbor | | else pipe->input(what,len);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | void start_sender( )
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | if (pipe)
{
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | MARK_FD("HTTP really handled, piping "+not_query);
#ifdef FD_DEBUG
|
e2df6a | 2001-01-03 | Per Hedbor | | call_out(timer, 30, predef::time(1));
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | #endif
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe->set_done_callback( do_log );
pipe->output( my_fd );
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | } else {
MARK_FD("HTTP really handled, pipe done");
|
5f6dae | 2000-08-13 | Per Hedbor | | do_log();
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | }
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | string scan_for_query( string f )
{
if(sscanf(f,"%s?%s", f, query) == 2)
{
string v, a, b;
foreach(query / "&", v)
if(sscanf(v, "%s=%s", a, b) == 2)
{
a = http_decode_string(replace(a, "+", " "));
b = http_decode_string(replace(b, "+", " "));
|
2fdf09 | 2000-12-02 | Per Hedbor | | real_variables[ a ] += ({ b });
|
b1fca0 | 1996-11-12 | Per Hedbor | | } else
if(strlen( rest_query ))
rest_query += "&" + http_decode_string( v );
else
rest_query = http_decode_string( v );
|
ebb1c5 | 1998-02-24 | Per Hedbor | | rest_query=replace(rest_query, "+", "\000");
|
9211b2 | 1998-04-24 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | return f;
}
|
3e2c34 | 2001-01-11 | Per Hedbor | | #define OLD_RXML_CONFIG
#ifdef OLD_RXML_CONFIG
private void really_set_config(array mod_config)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
3e2c34 | 2001-01-11 | Per Hedbor | | string url;
if(sscanf(replace(raw_url,({"%3c","%3e","%3C","%3E" }),
({"<",">","<",">"})),"/<%*s>/%s",url)!=2)
url = "/";
|
e3bda3 | 2000-01-12 | Martin Nilsson | | else
|
3e2c34 | 2001-01-11 | Per Hedbor | | url = "/"+url;
|
e3bda3 | 2000-01-12 | Martin Nilsson | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | multiset do_mod_config( multiset config )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
3e2c34 | 2001-01-11 | Per Hedbor | | if(!mod_config) return config;
foreach(mod_config, string m)
if(m[0]=='-')
config[m[1..]]=0;
else
config[m]=1;
return config;
};
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | void do_send_reply( string what, string url ) {
if( misc->host )
url= port_obj->name+"://"+misc->host + url;
else if (conf)
url = conf->query("MyWorldLocation") + url[1..];
my_fd->write( prot + " 302 Roxen config coming up\r\n"+
(what?what+"\r\n":"")+"Location: "+url+
"Connection: close\r\nDate: "+
Roxen.http_date(predef::time(1))+
"\r\nContent-Type: text/html\r\n"
"Content-Length: 0\r\n\r\n" );
my_fd->close();
my_fd = 0;
end();
};
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | |
|
3e2c34 | 2001-01-11 | Per Hedbor | | if(supports->cookies)
{
do_send_reply("Set-Cookie: "+
Roxen.http_roxen_config_cookie(indices(do_mod_config(config))*","),
url );
return;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
3e2c34 | 2001-01-11 | Per Hedbor | | if (sscanf(replace(url, ({ "%28", "%29" }), ({ "(", ")" })),
"/(%*s)/%s", url) == 2)
url = "/" + url;
do_send_reply(0,Roxen.add_pre_state( url, do_mod_config( prestate ) ));
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
a3ebea | 2000-08-12 | Per Hedbor | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | | private static mixed f, line;
|
b5218e | 1999-03-18 | Henrik Grubbström (Grubba) | | private static int hstart;
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | |
|
2aa88e | 2000-01-28 | Martin Nilsson | | class PrefLanguages {
int decoded=0;
int sorted=0;
array(string) subtags=({});
array(string) languages=({});
array(float) qualities=({});
array(string) get_languages() {
sort_lang();
return languages;
}
string get_language() {
|
c250bf | 2000-02-23 | Martin Nilsson | | if(!languages || !sizeof(languages)) return 0;
|
2aa88e | 2000-01-28 | Martin Nilsson | | sort_lang();
return languages[0];
}
array(float) get_qualities() {
sort_lang();
return qualities;
}
float get_quality() {
|
c250bf | 2000-02-23 | Martin Nilsson | | if(!qualities || !sizeof(qualities)) return 0.0;
|
2aa88e | 2000-01-28 | Martin Nilsson | | sort_lang();
return qualities[0];
}
void set_sorted(array(string) lang, void|array(float) q) {
languages=lang;
if(q && sizeof(q)==sizeof(lang))
qualities=q;
else
qualities=({1.0})*sizeof(lang);
sorted=1;
}
void sort_lang() {
if(sorted && decoded) return;
array(float) q;
|
a4ce0c | 2000-03-06 | Martin Nilsson | | array(string) s=reverse(languages)-({""}), u=({});
|
2aa88e | 2000-01-28 | Martin Nilsson | |
if(!decoded) {
q=({});
s=Array.map(s, lambda(string x) {
float n=1.0;
string sub="";
sscanf(lower_case(x), "%s;q=%f", x, n);
if(n==0.0) return "";
sscanf(x, "%s-%s", x, sub);
q+=({n});
u+=({sub});
return x;
});
s-=({""});
decoded=1;
}
else
q=reverse(qualities);
sort(q,s,u);
languages=reverse(s);
qualities=reverse(q);
subtags=reverse(u);
sorted=1;
}
}
|
a86c3b | 2000-08-28 | Per Hedbor | |
|
a2a5aa | 2000-08-31 | Per Hedbor | | class CacheKey {}
|
a86c3b | 2000-08-28 | Per Hedbor | | void things_to_do_when_not_sending_from_cache( )
{
#ifdef OLD_RXML_CONFIG
array mod_config;
int config_in_url;
#endif
|
bf2543 | 2001-02-24 | Per Hedbor | | array|string contents;
|
a86c3b | 2000-08-28 | Per Hedbor | | misc->pref_languages=PrefLanguages();
|
a2a5aa | 2000-08-31 | Per Hedbor | | misc->cachekey = CacheKey();
misc->_cachecallbacks = ({});
|
bf2543 | 2001-02-24 | Per Hedbor | | if( contents = request_headers[ "accept-language" ] )
|
a86c3b | 2000-08-28 | Per Hedbor | | {
|
bf2543 | 2001-02-24 | Per Hedbor | | if( !arrayp( contents ) )
contents = (contents-" ")/",";
|
a86c3b | 2000-08-28 | Per Hedbor | | else
|
bf2543 | 2001-02-24 | Per Hedbor | | contents =
Array.flatten( map( map( contents, `-, " " ), `/, "," ))-({""});
misc->pref_languages->languages=contents;
misc["accept-language"] = contents;
|
a86c3b | 2000-08-28 | Per Hedbor | | }
|
bf2543 | 2001-02-24 | Per Hedbor | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if( contents = request_headers[ "cookie" ] )
{
|
bf2543 | 2001-02-24 | Per Hedbor | | misc->cookies = ({});
foreach( arrayp( contents )? contents : ({ contents }), contents )
|
a86c3b | 2000-08-28 | Per Hedbor | | {
string c;
|
bf2543 | 2001-02-24 | Per Hedbor | |
|
a86c3b | 2000-08-28 | Per Hedbor | | foreach(((contents/";") - ({""})), c)
{
string name, value;
while(sizeof(c) && c[0]==' ') c=c[1..];
if(sscanf(c, "%s=%s", name, value) == 2)
{
value=http_decode_string(value);
name=http_decode_string(name);
cookies[ name ]=value;
#ifdef OLD_RXML_CONFIG
|
3e2c34 | 2001-01-11 | Per Hedbor | | if( (name == "RoxenConfig") && strlen(value) )
config = mkmultiset( value/"," );
|
a86c3b | 2000-08-28 | Per Hedbor | | #endif
}
}
}
}
string f = raw_url;
f = scan_for_query( f );
f = http_decode_string( f );
|
4a9aaa | 2001-02-06 | Johan Schön | |
if(search(f, "\0") != -1)
sscanf(f, "%s\0", f);
|
a86c3b | 2000-08-28 | Per Hedbor | | if( strlen( f ) > 5 )
{
string a;
switch( f[1] )
{
#ifdef OLD_RXML_CONFIG
case '<':
if (sscanf(f, "/<%s>/%s", a, f)==2)
{
config_in_url = 1;
mod_config = (a/",");
f = "/"+f;
}
#endif
case '(':
|
273ac2 | 2000-08-28 | Per Hedbor | | if(strlen(f) && sscanf(f, "/(%s)/%s", a, f)==2)
|
a86c3b | 2000-08-28 | Per Hedbor | | {
prestate = (multiset)( a/","-({""}) );
f = "/"+f;
}
}
}
not_query = Roxen.simplify_path(f);
#ifndef DISABLE_SUPPORTS
|
f16377 | 2000-08-28 | Per Hedbor | | if( !supports )
|
a86c3b | 2000-08-28 | Per Hedbor | | {
if( !client )
{
client = ({ "unknown" });
array s_and_v = find_supports_and_vars("", supports);
supports = s_and_v[0];
client_var = s_and_v[1];
}
else
{
if( !client_var->Fullname )
client_var->Fullname = "unknown";
client_var->fullname=lower_case(client_var->Fullname);
array s_and_v=find_supports_and_vars(client_var->fullname,supports,client_var);
supports = s_and_v[0];
client_var = s_and_v[1];
}
}
if ( client_var->charset && client_var->charset != "iso-8859-1" )
{
misc->cacheable = 0;
set_output_charset( client_var->charset );
input_charset = client_var->charset;
decode_charset_encoding( client_var->charset );
}
#else
supports = (< "images", "gifinline", "forms", "mailto">);
#endif
REQUEST_WERR("HTTP: parse_got(): supports");
if(!referer) referer = ({ });
if(misc->proxyauth)
{
mixed tmp1,tmp2;
foreach(tmp2 = (raw / "\n"), tmp1) {
if(!search(lower_case(tmp1), "proxy-authorization:"))
tmp2 -= ({tmp1});
}
raw = tmp2 * "\n";
}
#ifdef OLD_RXML_CONFIG
if(config_in_url) {
REQUEST_WERR("HTTP: parse_got(): config_in_url");
|
e056e9 | 2000-10-19 | Per Hedbor | | really_set_config( mod_config );
return;
|
a86c3b | 2000-08-28 | Per Hedbor | | }
#endif
if(!supports->cookies)
config = prestate;
else
|
bc0fa0 | 2001-03-08 | Per Hedbor | | if( port_obj->set_cookie
|
a86c3b | 2000-08-28 | Per Hedbor | | && !cookies->RoxenUserID && strlen(not_query)
&& not_query[0]=='/' && method!="PUT")
{
if (!(port_obj->set_cookie_only_once &&
cache_lookup("hosts_for_cookie",remoteaddr)))
misc->moreheads = ([ "Set-Cookie":Roxen.http_roxen_id_cookie(), ]);
if (port_obj->set_cookie_only_once)
cache_set("hosts_for_cookie",remoteaddr,1);
}
|
2fdf09 | 2000-12-02 | Per Hedbor | | if( mixed q = real_variables->magic_roxen_automatic_charset_variable )
decode_charset_encoding(Roxen.get_client_charset_decoder(q[0],this_object()));
}
|
d25fde | 2000-10-17 | Per Hedbor | |
|
a3ebea | 2000-08-12 | Per Hedbor | | static Roxen.HeaderParser hp = Roxen.HeaderParser();
|
d25fde | 2000-10-17 | Per Hedbor | | static function(string:array(string|mapping)) hpf = hp->feed;
|
8fb48a | 2000-06-26 | David Hedbor | | int last;
|
d25fde | 2000-10-17 | Per Hedbor | |
|
a3ebea | 2000-08-12 | Per Hedbor | | private int parse_got( string new_data )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(parse_got);
|
b1fca0 | 1996-11-12 | Per Hedbor | | multiset (string) sup;
|
a3ebea | 2000-08-12 | Per Hedbor | | string a, b, s="", linename, contents;
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
a3ebea | 2000-08-12 | Per Hedbor | | if( !method )
{
array res;
|
d25fde | 2000-10-17 | Per Hedbor | | while( strlen( new_data ) )
{
string q;
if( strlen( new_data ) > 4192 )
q = new_data[..4191];
else
{
q = new_data;
new_data = "";
}
if( catch { res = hpf( q ); } ) return 1;
if( res && strlen( new_data = new_data[4192..] ) )
{
res[0] += new_data;
break;
}
}
|
a3ebea | 2000-08-12 | Per Hedbor | | if( !res )
|
9c1900 | 2001-02-27 | Per Hedbor | | {
TIMER_END(parse_got);
|
a3ebea | 2000-08-12 | Per Hedbor | | return 0;
|
9c1900 | 2001-02-27 | Per Hedbor | | }
|
d25fde | 2000-10-17 | Per Hedbor | | |
a3ebea | 2000-08-12 | Per Hedbor | | */
data = res[0];
line = res[1];
|
d25fde | 2000-10-17 | Per Hedbor | | request_headers = res[2];
|
a3ebea | 2000-08-12 | Per Hedbor | | }
|
d25fde | 2000-10-17 | Per Hedbor | | string trailer, trailer_trailer;
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
94add0 | 2001-02-01 | Henrik Grubbström (Grubba) | | array(string) sl = line / " ";
|
c0202a | 2001-02-01 | Per Hedbor | | switch( sizeof( sl ) )
|
a3ebea | 2000-08-12 | Per Hedbor | | {
|
c0202a | 2001-02-01 | Per Hedbor | | default:
|
94add0 | 2001-02-01 | Henrik Grubbström (Grubba) | | sl = ({ sl[0], sl[1..sizeof(sl)-2]*" ", sl[-1] });
|
c0202a | 2001-02-01 | Per Hedbor | |
case 3:
method = sl[0];
f = sl[1];
clientprot = sl[2];
prot = clientprot;
if(!(< "HTTP/1.0", "HTTP/1.1" >)[prot])
{
prot = "HTTP/1.1";
}
break;
case 2:
case 1:
method = sl[0];
f = sl[-1];
if( sizeof( sl ) == 1 )
sscanf( method, "%s%*[\r\n]", method );
clientprot = prot = "HTTP/0.9";
if(method != "PING")
method = "GET";
else
{
my_fd->write("PONG\r\n");
return 2;
}
s = data = "";
sscanf( f, "%s%*[\r\n]", f );
misc->cacheable = 0;
break;
|
94add0 | 2001-02-01 | Henrik Grubbström (Grubba) | |
case 0:
break;
|
c4ab8f | 1999-07-15 | David Hedbor | | }
|
93db64 | 2000-06-29 | David Hedbor | | REQUEST_WERR(sprintf("***** req line: %O", line));
|
d25fde | 2000-10-17 | Per Hedbor | | REQUEST_WERR(sprintf("***** headers: %O", request_headers));
REQUEST_WERR(sprintf("***** data (%d):%O", strlen(data),data));
|
b1fca0 | 1996-11-12 | Per Hedbor | | raw_url = f;
|
e2df6a | 2001-01-03 | Per Hedbor | | time = predef::time(1);
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("RAW_URL:%O", raw_url));
|
7ec660 | 1997-01-29 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!remoteaddr)
{
|
41b77c | 1999-07-15 | David Hedbor | | if(my_fd) {
remoteaddr = my_fd->query_address();
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(remoteaddr)
|
41b77c | 1999-07-15 | David Hedbor | | sscanf(remoteaddr, "%s %*s", remoteaddr);
}
|
e5bad2 | 1998-02-10 | Per Hedbor | | if(!remoteaddr) {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_request(): No remote address.");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(parse_got);
|
41b77c | 1999-07-15 | David Hedbor | | return 2;
|
e5bad2 | 1998-02-10 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
7ec660 | 1997-01-29 | Per Hedbor | |
|
d25fde | 2000-10-17 | Per Hedbor | | foreach( (array)request_headers, [string linename, array|string contents] )
|
e8b214 | 2001-05-08 | Per Hedbor | | {
if( arrayp(contents) ) contents = contents[0];
|
d25fde | 2000-10-17 | Per Hedbor | | switch (linename)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
d25fde | 2000-10-17 | Per Hedbor | | case "pragma": pragma|=(multiset)((contents-" ")/","); break;
case "content-length": misc->len = (int)contents; break;
case "authorization": rawauth = contents; break;
|
e8b214 | 2001-05-08 | Per Hedbor | | case "referer": referer = ({contents}); break;
|
d25fde | 2000-10-17 | Per Hedbor | | case "if-modified-since": since=contents; break;
case "proxy-authorization":
array y;
y = contents / " ";
if(sizeof(y) < 2)
|
a86c3b | 2000-08-28 | Per Hedbor | | break;
|
d25fde | 2000-10-17 | Per Hedbor | | y[1] = decode(y[1]);
misc->proxyauth=y;
break;
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
d25fde | 2000-10-17 | Per Hedbor | | case "user-agent":
if( !client )
{
sscanf(contents, "%s via", contents);
client_var->Fullname=contents;
client = contents/" " - ({ "" });
}
break;
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
d25fde | 2000-10-17 | Per Hedbor | | case "request-range":
contents = lower_case(contents-" ");
if(!search(contents, "bytes"))
misc->range = contents[6..];
break;
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
d25fde | 2000-10-17 | Per Hedbor | | case "range":
contents = lower_case(contents-" ");
if(!misc->range && !search(contents, "bytes"))
misc->range = contents[6..];
break;
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
d25fde | 2000-10-17 | Per Hedbor | | case "host":
case "connection":
case "content-type":
misc[linename] = lower_case(contents);
break;
|
41b77c | 1999-07-15 | David Hedbor | | }
|
51dd02 | 2001-05-08 | Anders Johansson | | }
|
a86c3b | 2000-08-28 | Per Hedbor | | if(misc->len && method == "POST")
{
if(!data) data="";
int l = misc->len;
wanted_data=l;
have_data=strlen(data);
|
fdd26d | 2000-07-23 | Stefan Wallström | |
|
a86c3b | 2000-08-28 | Per Hedbor | | if(strlen(data) < l)
{
REQUEST_WERR("HTTP: parse_request(): More data needed in POST.");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(parse_got);
|
a86c3b | 2000-08-28 | Per Hedbor | | return 0;
}
leftovers = data[l+2..];
data = data[..l+1];
|
fdd26d | 2000-07-23 | Stefan Wallström | |
|
a86c3b | 2000-08-28 | Per Hedbor | | switch(lower_case((((misc["content-type"]||"")+";")/";")[0]-" "))
{
|
1d3134 | 2000-09-03 | Per Hedbor | | default:
|
a86c3b | 2000-08-28 | Per Hedbor | | string v;
|
1d3134 | 2000-09-03 | Per Hedbor | |
data = String.trim_all_whites( data );
l = misc->len = strlen(data);
|
a86c3b | 2000-08-28 | Per Hedbor | | if(l < 200000)
|
1d3134 | 2000-09-03 | Per Hedbor | | foreach(replace(data,"+"," ")/"&", v)
|
a86c3b | 2000-08-28 | Per Hedbor | | if(sscanf(v, "%s=%s", a, b) == 2)
{
a = http_decode_string( a );
b = http_decode_string( b );
|
2fdf09 | 2000-12-02 | Per Hedbor | | real_variables[ a ] += ({ b });
|
a3ebea | 2000-08-12 | Per Hedbor | | }
|
a86c3b | 2000-08-28 | Per Hedbor | | break;
case "multipart/form-data":
object messg = MIME.Message(data, misc);
|
2fdf09 | 2000-12-02 | Per Hedbor | | foreach(messg->body_parts, object part)
{
if(part->disp_params->filename)
{
real_variables[part->disp_params->name] += ({part->getdata()});
real_variables[part->disp_params->name+".filename"] +=
({part->disp_params->filename});
misc->files += ({ part->disp_params->name });
} else
real_variables[part->disp_params->name] += ({part->getdata()});
|
a86c3b | 2000-08-28 | Per Hedbor | | }
break;
|
dde965 | 1996-12-08 | David Hedbor | | }
|
ceb927 | 1997-05-15 | David Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(parse_got);
|
41b77c | 1999-07-15 | David Hedbor | | return 3;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
2fdf09 | 2000-12-02 | Per Hedbor | | int get_max_cache()
{
return misc->cacheable;
}
int set_max_cache( int t )
{
int ot = misc->cacheable;
misc->cacheable = t;
return ot;
}
|
a86c3b | 2000-08-28 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | void disconnect()
{
|
ebb1c5 | 1998-02-24 | Per Hedbor | | file = 0;
|
943da9 | 1999-09-26 | Martin Stjernholm | | #ifdef REQUEST_DEBUG
|
c60a40 | 2000-08-22 | Per Hedbor | | if (my_fd)
MARK_FD("my_fd in HTTP disconnected?");
|
943da9 | 1999-09-26 | Martin Stjernholm | | #endif
|
9c1900 | 2001-02-27 | Per Hedbor | | MERGE_TIMERS(conf);
if(do_not_disconnect) return;
|
14179b | 1997-01-29 | Per Hedbor | | destruct();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
c60a40 | 2000-08-22 | Per Hedbor | | void end(int|void keepit)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
0aee22 | 2000-08-15 | Martin Stjernholm | | if(keepit
|
c60a40 | 2000-08-22 | Per Hedbor | | && !file->raw
|
41b77c | 1999-07-15 | David Hedbor | | && (misc->connection == "keep-alive" ||
|
5f6dae | 2000-08-13 | Per Hedbor | | (prot == "HTTP/1.1" && misc->connection != "close"))
|
ebb1c5 | 1998-02-24 | Per Hedbor | | && my_fd)
{
|
26f44e | 2000-08-13 | Per Hedbor | | object o = object_program(this_object())(0, 0, 0);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->remoteaddr = remoteaddr;
|
be1610 | 2000-08-16 | Per Hedbor | | o->client = client;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->supports = supports;
|
5f6dae | 2000-08-13 | Per Hedbor | | o->client_var = client_var;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->host = host;
|
26f44e | 2000-08-13 | Per Hedbor | | o->conf = conf;
|
5f6dae | 2000-08-13 | Per Hedbor | | o->pipe = pipe;
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP kept alive");
|
0aee22 | 2000-08-15 | Martin Stjernholm | | object fd = my_fd;
my_fd=0;
o->chain(fd,port_obj,leftovers);
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe = 0;
|
0aee22 | 2000-08-15 | Martin Stjernholm | | disconnect();
|
ebb1c5 | 1998-02-24 | Per Hedbor | | return;
}
|
5f6dae | 2000-08-13 | Per Hedbor | | pipe = 0;
|
e8790b | 1998-02-19 | Per Hedbor | | if(objectp(my_fd))
{
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP closed");
|
5f6dae | 2000-08-13 | Per Hedbor | | catch
{
|
bc0fa0 | 2001-03-08 | Per Hedbor | | my_fd->set_blocking();
|
e8790b | 1998-02-19 | Per Hedbor | | my_fd->close();
destruct(my_fd);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | };
|
e8790b | 1998-02-19 | Per Hedbor | | my_fd = 0;
}
|
0aee22 | 2000-08-15 | Martin Stjernholm | | disconnect();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
9211b2 | 1998-04-24 | Per Hedbor | | static void do_timeout()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
e2df6a | 2001-01-03 | Per Hedbor | | int elapsed = predef::time(1)-time;
|
9211b2 | 1998-04-24 | Per Hedbor | | if(time && elapsed >= 30)
|
8afc81 | 1998-02-04 | Per Hedbor | | {
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP timeout");
|
5f6dae | 2000-08-13 | Per Hedbor | | end();
|
8afc81 | 1998-02-04 | Per Hedbor | | } else {
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
8afc81 | 1998-02-04 | Per Hedbor | | call_out(do_timeout, 10);
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP premature timeout");
|
8afc81 | 1998-02-04 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
35ed00 | 1998-03-26 | Per Hedbor | | static string last_id, last_from;
string get_id(string from)
{
if(last_from == from) return last_id;
last_from=from;
catch {
object f = open(from,"r");
string id;
|
282739 | 2000-03-26 | Martin Stjernholm | | id = f->read(1024);
|
35ed00 | 1998-03-26 | Per Hedbor | | if(sscanf(id, "%*s$"+"Id: %*s,v %s ", id) == 3)
|
0b651e | 1998-03-26 | Per Hedbor | | return last_id=" (version "+id+")";
|
35ed00 | 1998-03-26 | Per Hedbor | | };
last_id = "";
return "";
}
|
8641d4 | 2000-03-24 | Martin Stjernholm | | void add_id(mixed to)
|
35ed00 | 1998-03-26 | Per Hedbor | | {
|
282739 | 2000-03-26 | Martin Stjernholm | | if (arrayp (to) && sizeof (to) >= 2 && arrayp (to[1]) ||
objectp (to) && to->is_generic_error)
|
8641d4 | 2000-03-24 | Martin Stjernholm | | foreach(to[1], array q)
|
282739 | 2000-03-26 | Martin Stjernholm | | if(sizeof(q) && stringp(q[0])) {
string id = get_id(q[0]);
catch (q[0] += id);
}
|
35ed00 | 1998-03-26 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string link_to(string file, int line, string fun, int eid, int qq)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!file || !line) return "<a>";
if(file[0]!='/') file = combine_path(getcwd(), file);
|
4f6d92 | 2000-03-27 | Johan Sundström | | return ("<a href=\"/(old_error,find_file)/error/?"+
|
3befe1 | 2000-08-22 | Martin Stjernholm | | "file="+Roxen.http_encode_url(file)+
(fun ? "&fun="+Roxen.http_encode_url(fun) : "") +
|
8641d4 | 2000-03-24 | Martin Stjernholm | | "&off="+qq+
"&error="+eid+
(line ? "&line="+line+"#here" : "") +
"\">");
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | | static string error_page_header (string title)
{
|
7dba2f | 2000-05-08 | Martin Nilsson | | title = Roxen.html_encode_string (title);
|
8641d4 | 2000-03-24 | Martin Stjernholm | | return #"<html><head><title>" + title + #"</title></head>
<body bgcolor='white' text='black' link='#ce5c00' vlink='#ce5c00'>
<table width='100%'><tr>
<td><a href='http://www.roxen.com/'><img border='0' src='/internal-roxen-roxen-small'></a></td>
<td><b><font size='+1'>" + title + #"</font></b></td>
|
7dba2f | 2000-05-08 | Martin Nilsson | | <td align='right'><font size='+1'>Roxen WebServer " + Roxen.html_encode_string (roxen_version()) + #"</font></td>
|
8641d4 | 2000-03-24 | Martin Stjernholm | | </tr></table>
";
}
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string format_backtrace(int eid)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | [string msg, array(string) rxml_bt, array(array) bt,
|
282739 | 2000-03-26 | Martin Stjernholm | | string raw_bt_descr, string raw_url, string raw] =
|
8641d4 | 2000-03-24 | Martin Stjernholm | | roxen.query_var ("errors")[eid];
string res = error_page_header ("Internal Server Error") +
|
7dba2f | 2000-05-08 | Martin Nilsson | | "<h1>" + replace (Roxen.html_encode_string (msg), "\n", "<br />\n") + "</h1>\n";
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
if (rxml_bt && sizeof (rxml_bt)) {
res += "<h3>RXML frame backtrace</h3>\n<ul>\n";
foreach (rxml_bt, string line)
|
7dba2f | 2000-05-08 | Martin Nilsson | | res += "<li>" + Roxen.html_encode_string (line) + "</li>\n";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | res += "</ul>\n\n";
}
|
c658b9 | 2000-03-24 | Martin Stjernholm | | if (bt && sizeof (bt)) {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | res += "<h3>Pike backtrace</h3>\n<ul>\n";
int q = sizeof (bt);
foreach(reverse (bt), [string file, int line, string func, string descr])
res += "<li value="+(q--)+">" +
link_to (file, line, func, eid, q) +
|
7dba2f | 2000-05-08 | Martin Nilsson | | (file ? Roxen.html_encode_string (file) : "<i>Unknown program</i>") +
|
8641d4 | 2000-03-24 | Martin Stjernholm | | (line ? ":" + line : "") +
|
7dba2f | 2000-05-08 | Martin Nilsson | | "</a>" + (file ? Roxen.html_encode_string (get_id (file)) : "") + ":<br />\n" +
replace (Roxen.html_encode_string (descr),
|
3befe1 | 2000-08-22 | Martin Stjernholm | | ({"(", ")", " "}), ({"<b>(</b>", "<b>)</b>", " "})) +
|
8641d4 | 2000-03-24 | Martin Stjernholm | | "</li>\n";
res += "</ul>\n\n";
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
|
4f6d92 | 2000-03-27 | Johan Sundström | | res += ("<p><b><a href=\"/(old_error,plain)/error/?error="+eid+"\">"
|
8641d4 | 2000-03-24 | Martin Stjernholm | | "Generate text only version of this error message, for bug reports"+
"</a></b></p>\n\n");
|
258bb1 | 2000-03-15 | Martin Nilsson | | return res+"</body></html>";
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string generate_bugreport(string msg, array(string) rxml_bt, array(string) bt,
|
282739 | 2000-03-26 | Martin Stjernholm | | string raw_bt_descr, string raw_url, string raw)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
282739 | 2000-03-26 | Martin Stjernholm | | return ("Roxen version: "+version()+
(roxen.real_version != version()?
" ("+roxen.real_version+")":"")+
"\nPike version: " + predef::version() +
"\nRequested URL: "+raw_url+"\n"
"\nError: " + raw_bt_descr +
"\nRequest data:\n"+raw);
|
f28818 | 1998-05-25 | Per Hedbor | | }
string censor(string what)
{
string a, b, c;
|
0322b7 | 1999-08-06 | Per Hedbor | | if(!what)
return "No backtrace";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if(sscanf(what, "%suthorization:%s\n%s", a, b, c)==3)
return a+"uthorization: ################ (censored)\n"+c;
|
f28818 | 1998-05-25 | Per Hedbor | | return what;
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
1d3134 | 2000-09-03 | Per Hedbor | | int store_error(mixed _err)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
1d3134 | 2000-09-03 | Per Hedbor | | mixed err = _err;
_err = 0;
|
35c263 | 1999-02-16 | Per Hedbor | | mapping e = roxen.query_var("errors");
if(!e) roxen.set_var("errors", ([]));
e = roxen.query_var("errors");
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
86e77d | 1998-05-07 | Per Hedbor | | int id = ++e[0];
if(id>1024) id = 1;
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
string msg;
array(string) rxml_bt;
if (!err) msg = "Unknown error";
else {
msg = describe_error (err);
int i = search (msg, "\nRXML frame backtrace:\n");
if (i >= 0) {
rxml_bt = (msg[i + sizeof ("\nRXML frame backtrace:")..] / "\n | ")[1..];
if (sizeof (rxml_bt)) rxml_bt[-1] = rxml_bt[-1][..sizeof (rxml_bt[-1]) - 2];
msg = msg[..i - 1];
}
}
|
1d3134 | 2000-09-03 | Per Hedbor | | function dp = master()->describe_program;
|
008c69 | 2001-03-16 | Martin Nilsson | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string cwd = getcwd() + "/";
array bt;
|
c658b9 | 2000-03-24 | Martin Stjernholm | | if (arrayp (err) && sizeof (err) >= 2 && arrayp (err[1]) ||
objectp (err) && err->is_generic_error) {
|
008c69 | 2001-03-16 | Martin Nilsson | |
object d = master()->Describer();
d->identify_parts(err);
function dcl = d->describe_comma_list;
|
8641d4 | 2000-03-24 | Martin Stjernholm | | bt = ({});
|
008c69 | 2001-03-16 | Martin Nilsson | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | foreach (err[1], mixed ent) {
string file, func, descr;
int line;
if (arrayp (ent)) {
if (sizeof (ent) && stringp (ent[0]))
if (ent[0][..sizeof (cwd) - 1] == cwd)
file = ent[0] = ent[0][sizeof (cwd)..];
else
file = ent[0];
if (sizeof (ent) >= 2) line = ent[1];
if (sizeof (ent) >= 3)
if(functionp(ent[2])) {
|
3befe1 | 2000-08-22 | Martin Stjernholm | | func = "";
if (object o = function_object (ent[2])) {
string s;
if (!catch (s = sprintf ("%O",o)) && s != "object")
func = s + "->";
}
func += function_name(ent[2]);
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!file)
catch {
|
1d3134 | 2000-09-03 | Per Hedbor | | file = dp(object_program( function_object( ent[2] ) ) );
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (file[..sizeof (cwd) - 1] == cwd) file = file[sizeof (cwd)..];
};
}
else if (stringp(ent[2])) func = ent[2];
|
2c639f | 2000-09-02 | Per Hedbor | | else func ="<unknown function>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (sizeof (ent) >= 4)
|
1d3134 | 2000-09-03 | Per Hedbor | | descr = func + "(" +dcl(ent[3..],999999)+")";
|
8641d4 | 2000-03-24 | Martin Stjernholm | | else
descr = func + "()";
}
else if (stringp (ent)) descr = ent;
else if (catch (descr = sprintf ("%O", ent)))
descr = "???";
bt += ({({file, line, func, descr})});
}
}
|
282739 | 2000-03-26 | Martin Stjernholm | | add_id (err);
e[id] = ({msg,rxml_bt,bt,describe_backtrace (err),raw_url,censor(raw)});
|
86e77d | 1998-05-07 | Per Hedbor | | return id;
}
array get_error(string eid)
{
|
35c263 | 1999-02-16 | Per Hedbor | | mapping e = roxen.query_var("errors");
|
86e77d | 1998-05-07 | Per Hedbor | | if(e) return e[(int)eid];
return 0;
}
|
1d3134 | 2000-09-03 | Per Hedbor | | void internal_error(array _err)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
f904d6 | 2000-09-10 | Per Hedbor | | misc->cacheable = 0;
|
1d3134 | 2000-09-03 | Per Hedbor | | mixed err = _err;
_err = 0;
|
bd2223 | 1998-03-27 | David Hedbor | | array err2;
|
ab9b6d | 2000-02-11 | Per Hedbor | | if(port_obj->query("show_internals"))
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
abdff2 | 1999-12-27 | Martin Nilsson | | err2 = catch {
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_low_answer(500, format_backtrace(store_error(err)));
|
a7ebda | 2000-01-30 | Per Hedbor | | };
|
bd2223 | 1998-03-27 | David Hedbor | | if(err2) {
werror("Internal server error in internal_error():\n" +
|
86e77d | 1998-05-07 | Per Hedbor | | describe_backtrace(err2)+"\n while processing \n"+
|
bd2223 | 1998-03-27 | David Hedbor | | describe_backtrace(err));
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_low_answer(500, "<h1>Error: The server failed to "
|
bd2223 | 1998-03-27 | David Hedbor | | "fulfill your query, due to an "
|
86e77d | 1998-05-07 | Per Hedbor | | "internal error in the internal error routine.</h1>");
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
f78848 | 1998-03-18 | Henrik Grubbström (Grubba) | | } else {
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_low_answer(500, "<h1>Error: The server failed to "
|
2b9d4b | 1998-03-25 | Per Hedbor | | "fulfill your query, due to an internal error.</h1>");
|
f78848 | 1998-03-18 | Henrik Grubbström (Grubba) | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | report_error("Internal server error: " +
describe_backtrace(err) + "\n");
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | #ifdef INTERNAL_ERROR_DEBUG
report_error(sprintf("Raw backtrace:%O\n", err));
#endif /* INTERNAL_ERROR_DEBUG */
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
2b40f4 | 1999-12-29 | Martin Stjernholm | |
#define INTERNAL_ERROR(err) \
if (mixed __eRr = catch (internal_error (err))) \
report_error("Internal server error: " + describe_backtrace(err) + \
"internal_error() also failed: " + describe_backtrace(__eRr))
|
23a789 | 1996-12-15 | Per Hedbor | | int wants_more()
{
return !!cache;
}
|
888665 | 2000-09-19 | Per Hedbor | | void do_log( int|void fsent )
|
d7b087 | 1997-08-31 | Per Hedbor | | {
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP logging");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(do_log);
|
d7b087 | 1997-08-31 | Per Hedbor | | if(conf)
{
int len;
|
888665 | 2000-09-19 | Per Hedbor | | if(!fsent && pipe)
|
5f6dae | 2000-08-13 | Per Hedbor | | file->len = pipe->bytes_sent();
|
888665 | 2000-09-19 | Per Hedbor | | else
file->len = fsent;
|
d7b087 | 1997-08-31 | Per Hedbor | | if(conf)
{
if(file->len > 0) conf->sent+=file->len;
|
d98628 | 1999-06-30 | David Hedbor | | file->len += misc->_log_cheat_addition;
|
f7d981 | 1997-09-12 | Per Hedbor | | conf->log(file, this_object());
|
d7b087 | 1997-08-31 | Per Hedbor | | }
}
|
35233d | 2000-09-01 | Per Hedbor | | if( !port_obj )
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(do_log);
MERGE_TIMERS(conf);
|
35233d | 2000-09-01 | Per Hedbor | | catch
{
my_fd->close();
destruct( my_fd );
destruct( );
};
return;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(do_log);
|
c60a40 | 2000-08-22 | Per Hedbor | | end(1);
|
e5bad2 | 1998-02-10 | Per Hedbor | | return;
|
d7b087 | 1997-08-31 | Per Hedbor | | }
|
fa44bd | 1998-03-28 | David Hedbor | | #ifdef FD_DEBUG
|
4949d7 | 1998-03-28 | David Hedbor | | void timer(int start)
{
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | if(pipe) {
|
42ba93 | 1998-03-28 | David Hedbor | | MARK_FD(sprintf("HTTP_piping_%d_%d_%d_%d_(%s)",
|
2c499e | 1998-03-28 | David Hedbor | | pipe->sent,
stringp(pipe->current_input) ?
|
b52900 | 1998-03-28 | David Hedbor | | strlen(pipe->current_input) : -1,
|
9feab4 | 1998-03-28 | David Hedbor | | pipe->last_called,
|
e2df6a | 2001-01-03 | Per Hedbor | | predef::time(1) - start,
|
42ba93 | 1998-03-28 | David Hedbor | | not_query));
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | } else {
|
42ba93 | 1998-03-28 | David Hedbor | | MARK_FD("HTTP piping, but no pipe for "+not_query);
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | }
|
4949d7 | 1998-03-28 | David Hedbor | | call_out(timer, 30, start);
}
|
fa44bd | 1998-03-28 | David Hedbor | | #endif
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | string handle_error_file_request (string msg, array(string) rxml_bt, array(array) bt,
|
282739 | 2000-03-26 | Martin Stjernholm | | string raw_bt_descr, string raw_url, string raw)
|
86e77d | 1998-05-07 | Per Hedbor | | {
string data = Stdio.read_bytes(variables->file);
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
if(!data)
return error_page_header (variables->file) +
"<h3><i>Source file could not be read</i></h3>\n"
"</body></html>";
|
86e77d | 1998-05-07 | Per Hedbor | | string down;
|
8641d4 | 2000-03-24 | Martin Stjernholm | | int next = (int) variables->off + 1;
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if(next < sizeof (bt)) {
[string file, int line, string func, string descr] = bt[next];
down = link_to (file, line, func, (int) variables->error, next);
}
|
86e77d | 1998-05-07 | Per Hedbor | | else
down = "<a>";
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
int off = 49;
array (string) lines = data/"\n";
int start = (int)variables->line-50;
if(start < 0)
|
86e77d | 1998-05-07 | Per Hedbor | | {
|
8641d4 | 2000-03-24 | Martin Stjernholm | | off += start;
start = 0;
}
int end = (int)variables->line+50;
|
86e77d | 1998-05-07 | Per Hedbor | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
|
7dba2f | 2000-05-08 | Martin Nilsson | | lines = map (lines[start..end], Roxen.html_encode_string);
|
8641d4 | 2000-03-24 | Martin Stjernholm | |
if(sizeof(lines)>off) {
sscanf (lines[off], "%[ \t]%s", string indent, string code);
if (!sizeof (code)) code = " ";
lines[off] = indent + "<font size='+1'><b>"+down+code+"</a></b></font></a>";
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
8641d4 | 2000-03-24 | Martin Stjernholm | | lines[max(off-20,0)] = "<a name=here>"+lines[max(off-20,0)]+"</a>";
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
8641d4 | 2000-03-24 | Martin Stjernholm | | return error_page_header (variables->file) +
"<font size='-1'><pre>" + lines*"\n" + "</pre></font>\n"
"</body></html>";
|
86e77d | 1998-05-07 | Per Hedbor | | }
|
d98628 | 1999-06-30 | David Hedbor | |
#define BOUND "Byte_Me_Now_Roxen"
class MultiRangeWrapper
{
object file;
function rcb;
int current_pos, len, separator;
array ranges;
array range_info = ({});
string type;
string stored_data = "";
|
84ae13 | 1999-07-28 | David Hedbor | | void create(mapping _file, mapping heads, array _ranges, object id)
|
d98628 | 1999-06-30 | David Hedbor | | {
file = _file->file;
len = _file->len;
foreach(indices(heads), string h)
{
if(lower_case(h) == "content-type") {
type = heads[h];
m_delete(heads, h);
}
}
|
84ae13 | 1999-07-28 | David Hedbor | | if(id->request_headers["request-range"])
heads["Content-Type"] = "multipart/x-byteranges; boundary=" BOUND;
else
heads["Content-Type"] = "multipart/byteranges; boundary=" BOUND;
|
d98628 | 1999-06-30 | David Hedbor | | ranges = _ranges;
int clen;
foreach(ranges, array range)
{
int rlen = 1+ range[1] - range[0];
|
84ae13 | 1999-07-28 | David Hedbor | | string sep = sprintf("\r\n--" BOUND "\r\nContent-Type: %s\r\n"
|
d98628 | 1999-06-30 | David Hedbor | | "Content-Range: bytes %d-%d/%d\r\n\r\n",
|
84ae13 | 1999-07-28 | David Hedbor | | type||"application/octet-stream",
@range, len);
|
d98628 | 1999-06-30 | David Hedbor | | clen += rlen + strlen(sep);
range_info += ({ ({ rlen, sep }) });
}
clen += strlen(BOUND) + 8;
_file->len = clen;
}
string read(int num_bytes)
{
string out = stored_data;
int rlen, total = num_bytes;
num_bytes -= strlen(out);
|
037f4b | 1999-07-04 | David Hedbor | | stored_data = "";
|
d98628 | 1999-06-30 | David Hedbor | | foreach(ranges, array range)
{
rlen = range_info[0][0] - current_pos;
if(separator != 1) {
|
4ee960 | 1999-07-02 | David Hedbor | |
|
d98628 | 1999-06-30 | David Hedbor | | out += range_info[0][1];
num_bytes -= strlen(range_info[0][1]);
file->seek(range[0]);
separator = 1;
}
if(num_bytes > 0) {
if(rlen <= num_bytes)
{
out += file->read(rlen);
num_bytes -= rlen;
current_pos = separator = 0;
ranges = ranges[1..];
range_info = range_info[1..];
} else {
out += file->read(num_bytes);
current_pos += num_bytes;
num_bytes = 0;
}
}
|
30f032 | 1999-07-04 | David Hedbor | | if(num_bytes <= 0)
break;
|
d98628 | 1999-06-30 | David Hedbor | | }
|
037f4b | 1999-07-04 | David Hedbor | | if(!sizeof(ranges) && separator != 2) {
|
d98628 | 1999-06-30 | David Hedbor | | separator = 2;
out += "\r\n--" BOUND "--\r\n";
|
abdff2 | 1999-12-27 | Martin Nilsson | | }
|
d98628 | 1999-06-30 | David Hedbor | | if(strlen(out) > total)
{
stored_data = out[total..];
return out[..total-1];
}
return out ;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
bceeba | 1999-07-05 | Henrik Grubbström (Grubba) | | mixed `->(string what)
{
|
d98628 | 1999-06-30 | David Hedbor | | switch(what) {
case "read":
return read;
case "set_nonblocking":
return 0;
|
30f032 | 1999-07-04 | David Hedbor | | case "query_fd":
|
bceeba | 1999-07-05 | Henrik Grubbström (Grubba) | | return lambda() { return -1; };
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
d98628 | 1999-06-30 | David Hedbor | | default:
return file[what];
}
}
}
|
9c1900 | 2001-02-27 | Per Hedbor | |
|
d98628 | 1999-06-30 | David Hedbor | | array parse_range_header(int len)
{
array ranges = ({});
foreach(misc->range / ",", string range)
{
int r1, r2;
if(range[0] == '-' ) {
r1 = (len - (int)range[1..]);
if(r1 < 0) {
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
d98628 | 1999-06-30 | David Hedbor | | r1 = 0;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | ranges += ({ ({ len - (int)range[1..], len-1 }) });
|
d98628 | 1999-06-30 | David Hedbor | | } else if(range[-1] == '-') {
r1 = (int)range;
if(r1 >= len)
|
abdff2 | 1999-12-27 | Martin Nilsson | | continue;
|
d98628 | 1999-06-30 | David Hedbor | | ranges += ({ ({ r1, len-1 }) });
} else if(sscanf(range, "%d-%d", r1, r2)==2) {
if(r1 <= r2) {
if(r1 >= len)
continue;
ranges += ({ ({ r1, r2 < len ? r2 : len -1 }) });
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | else
|
d98628 | 1999-06-30 | David Hedbor | |
return 0;
} else
|
abdff2 | 1999-12-27 | Martin Nilsson | | return 0;
|
d98628 | 1999-06-30 | David Hedbor | | }
return ranges;
}
|
45b22b | 1998-10-26 | Henrik Grubbström (Grubba) | |
void ready_to_receive()
{
|
657de7 | 2001-05-04 | Per Hedbor | | if (clientprot == "HTTP/1.1" && request_headers->Expect &&
(request_headers->Expect == "100-continue" ||
has_value(request_headers->Expect, "100-continue" )))
|
45b22b | 1998-10-26 | Henrik Grubbström (Grubba) | | my_fd->write("HTTP/1.1 100 Continue\r\n");
}
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | |
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | |
void send_result(mapping|void result)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(send_result);
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | array err;
|
5bc199 | 1997-01-29 | Per Hedbor | | int tmp;
|
b1fca0 | 1996-11-12 | Per Hedbor | | mapping heads;
|
5f6dae | 2000-08-13 | Per Hedbor | | string head_string="";
|
26f44e | 2000-08-13 | Per Hedbor | | if (result)
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | file = result;
|
0d0e95 | 2000-11-13 | Per Hedbor | | #ifdef PROFILE
float elapsed = SECHR(HRTIME()-req_time);
string nid =
#ifdef FILE_PROFILE
(raw_url/"?")[0]
#else
dirname((raw_url/"?")[0])
#endif
;
array p;
if(!(p=conf->profile_map[nid]))
p = conf->profile_map[nid] = ({0,0.0,0.0});
p[0]++;
p[1] += elapsed;
if(elapsed > p[2]) p[2]=elapsed;
#endif
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("HTTP: send_result(%O)", file));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
c0202a | 2001-02-01 | Per Hedbor | | if( prot == "HTTP/0.9" ) misc->cacheable = 0;
|
5f6dae | 2000-08-13 | Per Hedbor | |
if(!leftovers)
leftovers = data||"";
|
99b98b | 2000-08-14 | Per Hedbor | | if(!mappingp(file))
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
99b98b | 2000-08-14 | Per Hedbor | | misc->cacheable = 0;
if(misc->error_code)
file = Roxen.http_low_answer(misc->error_code, errors[misc->error]);
else if(err = catch {
|
73ce3d | 2000-12-11 | Per Hedbor | | file = conf->error_file( this_object() );
|
99b98b | 2000-08-14 | Per Hedbor | | })
|
2b40f4 | 1999-12-29 | Martin Stjernholm | | INTERNAL_ERROR(err);
|
99b98b | 2000-08-14 | Per Hedbor | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | else
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | if((file->file == -1) || file->leave_me)
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(send_result);
file = 0;
pipe = 0;
if(do_not_disconnect)
|
5f6dae | 2000-08-13 | Per Hedbor | | return;
my_fd = 0;
return;
|
903e57 | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(file->type == "raw") file->raw = 1;
else if(!file->type) file->type="text/plain";
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(!file->raw)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | heads = ([]);
|
edaa6f | 2001-02-01 | Per Hedbor | | if(objectp(file->file))
if(!file->stat && !(file->stat=misc->stat))
file->stat = file->file->stat();
if( Stat fstat = file->stat )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
edaa6f | 2001-02-01 | Per Hedbor | | if( !file->len )
file->len = fstat[1];
if ( fstat[ST_MTIME] > misc->last_modified )
misc->last_modified = fstat[ST_MTIME];
if(prot != "HTTP/0.9" && (misc->cacheable >= INITIAL_CACHEABLE) )
{
heads["Last-Modified"] = Roxen.http_date(misc->last_modified);
if(since)
{
array(int) since_info = Roxen.parse_since( since );
if ( ((since_info[0] >= misc->last_modified) &&
((since_info[1] == -1) || (since_info[1] == file->len)))
|| ((misc->cacheable>0)
&& (since_info[0] + misc->cacheable<= predef::time(1)))
)
{
file->error = 304;
file->file = 0;
file->data="";
}
}
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
edaa6f | 2001-02-01 | Per Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(prot != "HTTP/0.9")
|
0b0d08 | 2000-02-14 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | string h, charset="";
if( stringp(file->data) )
|
358288 | 2000-03-24 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | if (file["type"][0..4] == "text/")
{
[charset,file->data] = output_encode( file->data );
|
900d71 | 2001-05-09 | Jonas Wallden | | if( charset && (search(file["type"], "; charset=") == -1))
charset = "; charset="+charset;
|
5f6dae | 2000-08-13 | Per Hedbor | | else
charset = "";
}
|
d7978b | 2000-02-14 | Per Hedbor | | file->len = strlen(file->data);
|
5f6dae | 2000-08-13 | Per Hedbor | | }
heads["Content-Type"] = file["type"]+charset;
heads["Accept-Ranges"] = "bytes";
heads["Server"] = replace(version(), " ", "·");
|
73ce3d | 2000-12-11 | Per Hedbor | | if( misc->connection )
heads["Connection"] = misc->connection;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(file->encoding) heads["Content-Encoding"] = file->encoding;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(!file->error)
file->error=200;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
e2df6a | 2001-01-03 | Per Hedbor | | heads->Date = Roxen.http_date(predef::time(1));
|
5f6dae | 2000-08-13 | Per Hedbor | | if(file->expires)
heads->Expires = Roxen.http_date(file->expires);
|
41b77c | 1999-07-15 | David Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(mappingp(file->extra_heads))
heads |= file->extra_heads;
|
41b77c | 1999-07-15 | David Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(mappingp(misc->moreheads))
heads |= misc->moreheads;
|
41b77c | 1999-07-15 | David Hedbor | |
|
5f6dae | 2000-08-13 | Per Hedbor | | if(misc->range && file->len && objectp(file->file) && !file->data &&
file->error == 200 && (method == "GET" || method == "HEAD"))
{
array ranges = parse_range_header(file->len);
if(ranges)
{
misc->cacheable = 0;
if(sizeof(ranges))
{
file->error = 206;
if(sizeof(ranges) == 1)
{
heads["Content-Range"] = sprintf("bytes %d-%d/%d",
@ranges[0], file->len);
file->file->seek(ranges[0][0]);
if(ranges[0][1] == (file->len - 1) &&
GLOBVAR(RestoreConnLogFull))
misc->_log_cheat_addition = ranges[0][0];
file->len = ranges[0][1] - ranges[0][0]+1;
} else {
file->file = MultiRangeWrapper(file, heads, ranges, this_object());
}
} else {
file->error = 416;
heads["Content-Range"] = "*/"+file->len;
if(method == "GET") {
file->data = "The requested byte range is out-of-bounds. Sorry.";
file->len = strlen(file->data);
file->file = 0;
}
}
}
}
|
648612 | 2000-12-10 | Per Hedbor | | head_string = sprintf("%s %d %s\r\n",
prot, file->error,
file->rettext ||errors[file->error]||"");
|
62376c | 2000-11-22 | Per Hedbor | | if( file->len > 0 || (file->error != 200) )
|
e7bf33 | 2000-09-05 | Johan Sundström | | heads["Content-Length"] = (string)file->len;
|
6f32e3 | 2000-08-17 | Per Hedbor | |
if( file->error/100 == 2
&& file->len <= 0 )
{
heads->Connection = "close";
misc->connection = "close";
}
|
5f6dae | 2000-08-13 | Per Hedbor | | head_string += Roxen.make_http_headers( heads );
|
d25fde | 2000-10-17 | Per Hedbor | |
|
e8493d | 2000-08-20 | Per Hedbor | | if( strlen( charset ) )
head_string = output_encode( head_string )[1];
|
5f6dae | 2000-08-13 | Per Hedbor | | conf->hsent += strlen(head_string);
}
|
41b77c | 1999-07-15 | David Hedbor | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | REQUEST_WERR(sprintf("Sending result for prot:%O, method:%O file:%O\n",
prot, method, file));
MARK_FD("HTTP handled");
if( (method!="HEAD") && (file->error!=304) )
|
f71a6b | 2000-01-22 | Martin Stjernholm | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | #ifdef RAM_CACHE
|
c0202a | 2001-02-01 | Per Hedbor | | if( (misc->cacheable > 0) && (file->data || file->file) &&
prot != "HTTP/0.9" )
|
5f6dae | 2000-08-13 | Per Hedbor | | {
|
a32a61 | 2000-11-02 | Per Hedbor | | if( file->len>0 &&
((file->len + strlen( head_string )) <
|
a2a5aa | 2000-08-31 | Per Hedbor | | conf->datacache->max_file_size)
&& misc->cachekey )
|
5f6dae | 2000-08-13 | Per Hedbor | | {
|
e2df6a | 2001-01-03 | Per Hedbor | | string data = "";
|
93f799 | 2000-08-14 | Per Hedbor | | if( file->file ) data += file->file->read();
if( file->data ) data += file->data;
|
773ac6 | 2001-03-20 | Martin Stjernholm | | MY_TRACE_ENTER (sprintf ("Storing in ram cache, entry: %O", raw_url), 0);
MY_TRACE_LEAVE ("");
conf->datacache->set( raw_url, data,
|
99b98b | 2000-08-14 | Per Hedbor | | ([
|
e2df6a | 2001-01-03 | Per Hedbor | |
"hs":head_string,
|
a2a5aa | 2000-08-31 | Per Hedbor | | "key":misc->cachekey,
"callbacks":misc->_cachecallbacks,
|
99b98b | 2000-08-14 | Per Hedbor | | "len":file->len,
|
876567 | 2000-08-28 | Per Hedbor | |
"raw":(file->raw||misc->connection=="close"),
|
99b98b | 2000-08-14 | Per Hedbor | | "error":file->error,
|
0a900b | 2000-08-17 | Per Hedbor | | "mtime":(file->stat && file->stat[ST_MTIME]),
"rf":realfile,
|
99b98b | 2000-08-14 | Per Hedbor | | ]),
|
5f6dae | 2000-08-13 | Per Hedbor | | misc->cacheable );
|
9c1900 | 2001-02-27 | Per Hedbor | | file = ([ "data":data, "raw":file->raw, "len":strlen(data) ]);
|
5f6dae | 2000-08-13 | Per Hedbor | | }
}
#endif
if( file->len > 0 && file->len < 4000 )
{
|
888665 | 2000-09-19 | Per Hedbor | | int s;
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(send_result);
TIMER_START(blocking_write);
|
888665 | 2000-09-19 | Per Hedbor | | s = my_fd->write(head_string +
(file->file?file->file->read(file->len):
(file->data[..file->len-1])));
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(blocking_write);
|
888665 | 2000-09-19 | Per Hedbor | | do_log( s );
|
5f6dae | 2000-08-13 | Per Hedbor | | return;
}
if(strlen(head_string)) send(head_string);
if(file->data && strlen(file->data)) send(file->data, file->len);
if(file->file) send(file->file, file->len);
|
f71a6b | 2000-01-22 | Martin Stjernholm | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | else
|
358288 | 2000-03-24 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | | if( strlen( head_string ) < 4000)
|
358288 | 2000-03-24 | Per Hedbor | | {
|
888665 | 2000-09-19 | Per Hedbor | | do_log( my_fd->write( head_string ) );
|
358288 | 2000-03-24 | Per Hedbor | | return;
}
send(head_string);
|
5f6dae | 2000-08-13 | Per Hedbor | | file->len = 1;
}
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(send_result);
|
5f6dae | 2000-08-13 | Per Hedbor | | start_sender();
|
14179b | 1997-01-29 | Per Hedbor | | }
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | |
void handle_request( )
{
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: handle_request()");
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(handle_request);
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | #ifdef MAGIC_ERROR
if(prestate->old_error)
{
array err = get_error(variables->error);
if(err)
{
if(prestate->plain)
{
file = ([
|
282739 | 2000-03-26 | Martin Stjernholm | | "type":"text/plain",
|
f28818 | 1998-05-25 | Per Hedbor | | "data":generate_bugreport( @err ),
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | ]);
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | } else {
if(prestate->find_file)
{
|
8641d4 | 2000-03-24 | Martin Stjernholm | | if (!roxen.configuration_authenticate (this_object(), "View Settings"))
|
7dba2f | 2000-05-08 | Martin Nilsson | | file = Roxen.http_auth_required("admin");
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | else
|
8641d4 | 2000-03-24 | Martin Stjernholm | | file = ([
"type":"text/html",
"data":handle_error_file_request( @err ),
]);
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
}
}
}
#endif /* MAGIC_ERROR */
MARK_FD("HTTP handling request");
|
35c263 | 1999-02-16 | Per Hedbor | | array e;
|
c5e096 | 1999-10-04 | Per Hedbor | | if(e= catch(file = conf->handle_request( this_object() )))
|
2b40f4 | 1999-12-29 | Martin Stjernholm | | INTERNAL_ERROR( e );
|
a3ebea | 2000-08-12 | Per Hedbor | |
|
41b64e | 2001-01-28 | Per Hedbor | | if( file )
if( file->try_again_later )
{
if( objectp( file->try_again_later ) )
;
else
call_out( roxen.handle, file->try_again_later, handle_request );
return;
}
else if( file->pipe )
return;
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(handle_request);
|
26f44e | 2000-08-13 | Per Hedbor | | send_result();
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
|
347c72 | 2000-08-31 | Per Hedbor | | void adjust_for_config_path( string p )
{
if( not_query ) not_query = not_query[ strlen(p).. ];
raw_url = raw_url[ strlen(p).. ];
|
332d79 | 2000-12-04 | Martin Nilsson | | misc->site_prefix_path = p;
|
347c72 | 2000-08-31 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | |
abdff2 | 1999-12-27 | Martin Nilsson | | * =================================================
|
14179b | 1997-01-29 | Per Hedbor | | */
|
ebb1c5 | 1998-02-24 | Per Hedbor | | int processed;
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | void got_data(mixed fooid, string s)
{
|
0d0e95 | 2000-11-13 | Per Hedbor | | if(wanted_data)
|
d042a8 | 2000-08-31 | Per Hedbor | | {
|
0d0e95 | 2000-11-13 | Per Hedbor | | data += s;
if(strlen(s) + have_data < wanted_data)
|
d042a8 | 2000-08-31 | Per Hedbor | | {
|
0d0e95 | 2000-11-13 | Per Hedbor | |
have_data += strlen(s);
REQUEST_WERR("HTTP: We want more data.");
return;
}
|
d042a8 | 2000-08-31 | Per Hedbor | | }
|
acd34a | 2000-01-22 | Martin Stjernholm | | if (mixed err = catch {
|
14179b | 1997-01-29 | Per Hedbor | | int tmp;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP got data");
|
a86c3b | 2000-08-28 | Per Hedbor | | if(!raw) raw = s; else raw += s;
|
0d0e95 | 2000-11-13 | Per Hedbor | |
|
bc0fa0 | 2001-03-08 | Per Hedbor | |
|
0d0e95 | 2000-11-13 | Per Hedbor | |
if( !port_obj )
|
14179b | 1997-01-29 | Per Hedbor | | {
|
0d0e95 | 2000-11-13 | Per Hedbor | | catch
|
14179b | 1997-01-29 | Per Hedbor | | {
|
bc0fa0 | 2001-03-08 | Per Hedbor | | my_fd->set_blocking();
|
0d0e95 | 2000-11-13 | Per Hedbor | | my_fd->close();
destruct( my_fd );
destruct( );
};
return;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
26f44e | 2000-08-13 | Per Hedbor | | if(strlen(raw))
tmp = parse_got( s );
|
41b77c | 1999-07-15 | David Hedbor | | switch(tmp)
|
abdff2 | 1999-12-27 | Martin Nilsson | | {
|
fb5f68 | 1998-11-04 | Peter Bortas | | case 0:
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: Request needs more data.");
|
14179b | 1997-01-29 | Per Hedbor | | return;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | case 1:
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: Stupid Client Error");
|
c60a40 | 2000-08-22 | Per Hedbor | | my_fd->write((prot||"HTTP/1.0")+" 500 Stupid Client Error\r\n"
"Content-Length: 0\r\n\r\n");
end();
|
14179b | 1997-01-29 | Per Hedbor | | return;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
14179b | 1997-01-29 | Per Hedbor | | case 2:
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: Done");
|
14179b | 1997-01-29 | Per Hedbor | | end();
return;
}
|
c0202a | 2001-02-01 | Per Hedbor | | if( method == "GET" )
|
19ebcb | 2000-09-01 | Per Hedbor | | misc->cacheable = INITIAL_CACHEABLE;
|
ed1516 | 1999-11-19 | Per Hedbor | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(find_conf);
|
be1610 | 2000-08-16 | Per Hedbor | | string path;
|
347c72 | 2000-08-31 | Per Hedbor | | if( !conf || !(path = port_obj->path )
|| (sizeof( path )
|
f73026 | 2000-11-05 | Martin Nilsson | | && raw_url[..sizeof(path) - 1] != path) )
|
a2a5aa | 2000-08-31 | Per Hedbor | |
|
653d7d | 2000-02-14 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | |
conf =
port_obj->find_configuration_for_url(port_obj->name + "://" +
|
c68e29 | 2000-09-04 | Per Hedbor | | (misc->host||"*") +
(search(misc->host||"", ":")<0?
|
a86c3b | 2000-08-28 | Per Hedbor | | (":"+port_obj->default_port):"") +
|
b8d2ef | 2000-08-28 | Per Hedbor | | raw_url,
|
5f6dae | 2000-08-13 | Per Hedbor | | this_object());
|
94a5b9 | 1999-10-25 | Henrik Grubbström (Grubba) | | }
|
a86c3b | 2000-08-28 | Per Hedbor | | else if( strlen(path) )
|
347c72 | 2000-08-31 | Per Hedbor | | adjust_for_config_path( path );
|
0aee22 | 2000-08-15 | Martin Stjernholm | |
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(find_conf);
|
26f44e | 2000-08-13 | Per Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (rawauth)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
a86c3b | 2000-08-28 | Per Hedbor | | misc->cacheable = 0;
|
c5e096 | 1999-10-04 | Per Hedbor | | array(string) y = rawauth / " ";
realauth = 0;
auth = 0;
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (sizeof(y) >= 2)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
y[1] = MIME.decode_base64(y[1]);
realauth = y[1];
}
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | if( misc->proxyauth )
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
a86c3b | 2000-08-28 | Per Hedbor | | misc->cacheable = 0;
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (sizeof(misc->proxyauth) >= 2)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
703bf9 | 1999-10-04 | Marcus Comstedt | |
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (conf->auth_module)
|
703bf9 | 1999-10-04 | Marcus Comstedt | | misc->proxyauth
|
c5e096 | 1999-10-04 | Per Hedbor | | = conf->auth_module->auth(misc->proxyauth,this_object() );
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
2154ca | 1997-08-31 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | conf->received += strlen(s);
conf->requests++;
|
abdff2 | 1999-12-27 | Martin Nilsson | | my_fd->set_close_callback(0);
my_fd->set_read_callback(0);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | processed=1;
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
1a3593 | 2000-09-12 | Per Hedbor | | remove_call_out(do_timeout);
|
5f6dae | 2000-08-13 | Per Hedbor | | #ifdef RAM_CACHE
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(cache_lookup);
|
5f6dae | 2000-08-13 | Per Hedbor | | array cv;
|
c0202a | 2001-02-01 | Per Hedbor | | if( prot != "HTTP/0.9" &&
misc->cacheable &&
(cv = conf->datacache->get( raw_url )) )
|
5f6dae | 2000-08-13 | Per Hedbor | | {
|
773ac6 | 2001-03-20 | Martin Stjernholm | | MY_TRACE_ENTER (sprintf ("Found %O in ram cache - checking entry", raw_url), 0);
if( !cv[1]->key ) {
MY_TRACE_LEAVE ("Entry invalid due to zero key");
|
a2a5aa | 2000-08-31 | Per Hedbor | | conf->datacache->expire_entry( raw_url );
|
773ac6 | 2001-03-20 | Martin Stjernholm | | }
|
a2a5aa | 2000-08-31 | Per Hedbor | | else
|
99b98b | 2000-08-14 | Per Hedbor | | {
|
a2a5aa | 2000-08-31 | Per Hedbor | | int can_cache = 1;
if(!leftovers)
leftovers = data||"";
string d = cv[ 0 ];
file = cv[1];
if( sizeof(file->callbacks) )
|
0a900b | 2000-08-17 | Per Hedbor | | {
|
a2a5aa | 2000-08-31 | Per Hedbor | | if( mixed e = catch
{
|
773ac6 | 2001-03-20 | Martin Stjernholm | | foreach( file->callbacks, function f ) {
MY_TRACE_ENTER (sprintf ("Checking with %s",
master()->describe_function (f)), 0);
|
c3c632 | 2000-09-20 | Per Hedbor | | if( !f(this_object(), cv[1]->key ) )
|
a2a5aa | 2000-08-31 | Per Hedbor | | {
|
773ac6 | 2001-03-20 | Martin Stjernholm | | MY_TRACE_LEAVE ("Entry invalid according to callback");
MY_TRACE_LEAVE ("");
|
a2a5aa | 2000-08-31 | Per Hedbor | | can_cache = 0;
break;
}
|
773ac6 | 2001-03-20 | Martin Stjernholm | | MY_TRACE_LEAVE ("");
}
|
a2a5aa | 2000-08-31 | Per Hedbor | | } )
{
INTERNAL_ERROR( e );
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(cache_lookup);
|
a2a5aa | 2000-08-31 | Per Hedbor | | send_result();
return;
}
}
|
c3c632 | 2000-09-20 | Per Hedbor | | if( !cv[1]->key )
{
|
773ac6 | 2001-03-20 | Martin Stjernholm | | MY_TRACE_LEAVE ("Entry invalid due to zero key");
|
c3c632 | 2000-09-20 | Per Hedbor | | conf->datacache->expire_entry( raw_url );
can_cache = 0;
}
|
a2a5aa | 2000-08-31 | Per Hedbor | | if( can_cache )
|
0a900b | 2000-08-17 | Per Hedbor | | {
|
a2a5aa | 2000-08-31 | Per Hedbor | | #ifndef RAM_CACHE_ASUME_STATIC_CONTENT
Stat st;
if( !file->rf || !file->mtime ||
|
e2df6a | 2001-01-03 | Per Hedbor | | ((st = file_stat( file->rf )) && st->mtime == file->mtime ))
|
a2a5aa | 2000-08-31 | Per Hedbor | | #endif
{
|
e2df6a | 2001-01-03 | Per Hedbor | | string fix_date( string headers )
{
string a, b;
if( sscanf( headers, "%sDate: %*s\n%s", a, b ) == 3 )
return a+"Date: "+Roxen.http_date( predef::time(1) ) +"\n"+b;
return headers;
};
|
773ac6 | 2001-03-20 | Martin Stjernholm | |
MY_TRACE_LEAVE ("Using entry from ram cache");
|
e2df6a | 2001-01-03 | Per Hedbor | | conf->hsent += strlen(file->hs);
|
a2a5aa | 2000-08-31 | Per Hedbor | | if( strlen( d ) < 4000 )
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(cache_lookup);
do_log( my_fd->write( fix_date(file->hs)+d ) );
|
a2a5aa | 2000-08-31 | Per Hedbor | | }
else
{
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(cache_lookup);
|
e2df6a | 2001-01-03 | Per Hedbor | | send( fix_date(file->hs)+d );
|
a2a5aa | 2000-08-31 | Per Hedbor | | start_sender( );
}
return;
}
|
773ac6 | 2001-03-20 | Martin Stjernholm | | #ifndef RAM_CACHE_ASUME_STATIC_CONTENT
else
MY_TRACE_LEAVE (
sprintf ("Entry out of date (disk: %s, cache: mtime %d)",
st ? "mtime " + st->mtime : "gone", file->mtime));
#endif
} else
|
fdfc59 | 2000-09-20 | Per Hedbor | | misc->cacheable = 0;
|
a2a5aa | 2000-08-31 | Per Hedbor | | file = 0;
|
99b98b | 2000-08-14 | Per Hedbor | | }
|
5f6dae | 2000-08-13 | Per Hedbor | | }
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(cache_lookup);
|
5f6dae | 2000-08-13 | Per Hedbor | | #endif
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_START(parse_request);
|
a86c3b | 2000-08-28 | Per Hedbor | | things_to_do_when_not_sending_from_cache( );
|
9c1900 | 2001-02-27 | Per Hedbor | | TIMER_END(parse_request);
|
a86c3b | 2000-08-28 | Per Hedbor | | REQUEST_WERR("HTTP: Calling roxen.handle().");
|
5f6dae | 2000-08-13 | Per Hedbor | | #ifdef THREADS
|
a3ebea | 2000-08-12 | Per Hedbor | | roxen.handle(handle_request);
|
5f6dae | 2000-08-13 | Per Hedbor | | #else
handle_request();
#endif
|
653d7d | 2000-02-14 | Per Hedbor | | })
{
|
acd34a | 2000-01-22 | Martin Stjernholm | | report_error("Internal server error: " + describe_backtrace(err));
|
bc0fa0 | 2001-03-08 | Per Hedbor | | my_fd->set_blocking();
|
acd34a | 2000-01-22 | Martin Stjernholm | | my_fd->close();
|
5f6dae | 2000-08-13 | Per Hedbor | | destruct( my_fd );
|
acd34a | 2000-01-22 | Martin Stjernholm | | disconnect();
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | | |
b1fca0 | 1996-11-12 | Per Hedbor | | * 'simulated' requests. */
object clone_me()
{
|
14179b | 1997-01-29 | Per Hedbor | | object c,t;
|
a3ebea | 2000-08-12 | Per Hedbor | | c=object_program(t=this_object())(0, port_obj, conf);
|
cbe6c6 | 2000-03-18 | Martin Stjernholm | | #ifdef ID_OBJ_DEBUG
|
8bf31a | 2000-03-20 | Martin Stjernholm | | werror ("clone %O -> %O\n", t, c);
|
cbe6c6 | 2000-03-18 | Martin Stjernholm | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
0e5b1a | 1999-10-10 | Per Hedbor | | c->port_obj = port_obj;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->conf = conf;
c->time = time;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->raw_url = raw_url;
|
99cb5e | 2001-02-05 | Per Hedbor | |
c->real_variables = copy_value( real_variables );
c->variables = FakedVariables( c->real_variables );
|
a2a5aa | 2000-08-31 | Per Hedbor | | c->misc = copy_value( misc );
|
48fa36 | 1997-04-05 | Per Hedbor | | c->misc->orig = t;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->prestate = prestate;
c->supports = supports;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->config = config;
|
dc5f17 | 2000-04-28 | Martin Nilsson | | c->client_var = client_var;
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->remoteaddr = remoteaddr;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->host = host;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->client = client;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->referer = referer;
c->pragma = pragma;
c->cookies = cookies;
c->my_fd = 0;
c->prot = prot;
|
1afe37 | 1997-06-12 | Henrik Grubbström (Grubba) | | c->clientprot = clientprot;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->method = method;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
f6d62d | 1997-03-26 | Per Hedbor | | c->rest_query = rest_query;
c->raw = raw;
c->query = query;
c->not_query = not_query;
c->data = data;
|
746c3b | 1998-09-16 | Peter J. Holzer | | c->extra_extension = extra_extension;
|
b1fca0 | 1996-11-12 | Per Hedbor | | c->auth = auth;
c->realauth = realauth;
|
f6d62d | 1997-03-26 | Per Hedbor | | c->rawauth = rawauth;
c->since = since;
|
b1fca0 | 1996-11-12 | Per Hedbor | | return c;
}
void clean()
{
|
4b71f5 | 1998-03-25 | David Hedbor | | if(!(my_fd && objectp(my_fd)))
end();
|
e2df6a | 2001-01-03 | Per Hedbor | | else if((predef::time(1) - time) > 4800)
|
323569 | 1998-03-26 | Per Hedbor | | end();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
a3ebea | 2000-08-12 | Per Hedbor | | static void create(object f, object c, object cc)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | if(f)
{
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | MARK_FD("HTTP connection");
|
26f44e | 2000-08-13 | Per Hedbor | | f->set_read_callback(got_data);
f->set_close_callback(end);
|
14179b | 1997-01-29 | Per Hedbor | | my_fd = f;
|
a3ebea | 2000-08-12 | Per Hedbor | | if( c ) port_obj = c;
if( cc ) conf = cc;
|
e2df6a | 2001-01-03 | Per Hedbor | | time = predef::time(1);
|
491abc | 2000-08-17 | Per Hedbor | | call_out(do_timeout, 90);
|
26e767 | 2000-08-14 | Per Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ceb927 | 1997-05-15 | David Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | void chain(object f, object c, string le)
{
my_fd = f;
|
bc0fa0 | 2001-03-08 | Per Hedbor | | f->set_read_callback(0);
f->set_close_callback(end);
|
870a9e | 1999-10-04 | Per Hedbor | | port_obj = c;
|
5f6dae | 2000-08-13 | Per Hedbor | | processed = 0;
|
0aee22 | 2000-08-15 | Martin Stjernholm | | do_not_disconnect=-1;
|
9211b2 | 1998-04-24 | Per Hedbor | | MARK_FD("Kept alive");
|
e2df6a | 2001-01-03 | Per Hedbor | | time = predef::time(1);
|
5f6dae | 2000-08-13 | Per Hedbor | |
|
0aee22 | 2000-08-15 | Martin Stjernholm | | if ( strlen( le ) )
|
5f6dae | 2000-08-13 | Per Hedbor | | got_data( 0,le );
|
a7ebda | 2000-01-30 | Per Hedbor | | else
{
|
18c62d | 1999-05-27 | Stephen R. van den Berg | |
|
d39142 | 2000-03-25 | Martin Stjernholm | | remove_call_out(do_timeout);
|
491abc | 2000-08-17 | Per Hedbor | | call_out(do_timeout, 90);
|
18c62d | 1999-05-27 | Stephen R. van den Berg | | }
|
4949d7 | 1998-03-28 | David Hedbor | |
|
0aee22 | 2000-08-15 | Martin Stjernholm | | if(!my_fd)
{
if(do_not_disconnect == -1)
{
do_not_disconnect=0;
disconnect();
}
}
else
|
ebb1c5 | 1998-02-24 | Per Hedbor | | {
|
0aee22 | 2000-08-15 | Martin Stjernholm | | if(do_not_disconnect == -1)
do_not_disconnect = 0;
if(!processed)
{
|
bc0fa0 | 2001-03-08 | Per Hedbor | | f->set_read_callback(got_data);
f->set_close_callback(end);
|
0aee22 | 2000-08-15 | Martin Stjernholm | | }
|
ebb1c5 | 1998-02-24 | Per Hedbor | | }
}
|
08bd3c | 1999-11-02 | Per Hedbor | |
string _sprintf( )
{
|
8bf31a | 2000-03-20 | Martin Stjernholm | | #ifdef ID_OBJ_DEBUG
return "RequestID()" + (__marker ? "[" + __marker->count + "]" : "");
#else
|
08bd3c | 1999-11-02 | Per Hedbor | | return "RequestID()";
|
8bf31a | 2000-03-20 | Martin Stjernholm | | #endif
|
08bd3c | 1999-11-02 | Per Hedbor | | }
|
84fb68 | 2000-02-03 | Per Hedbor | |
Stdio.File connection( )
{
return my_fd;
}
Configuration configuration()
{
return conf;
}
|