e3bda3 | 2000-01-12 | Martin Nilsson | |
|
199d03 | 1999-09-05 | Francesco Chemolli | |
|
e3bda3 | 2000-01-12 | Martin Nilsson | |
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
f20692 | 2000-03-07 | Martin Stjernholm | | constant cvs_version = "$Id: http.pike,v 1.214 2000/03/07 21:36:49 mast Exp $";
|
2a2a5b | 1996-12-01 | Per Hedbor | |
|
86e77d | 1998-05-07 | Per Hedbor | | #define MAGIC_ERROR
#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>
|
fc2fcf | 1997-04-13 | Per Hedbor | | private inherit "roxenlib";
|
c5e096 | 1999-10-04 | 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 | |
|
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
|
6a409d | 1999-12-27 | Martin Nilsson | | #define MARK_FD(X) REQUEST_WERR(X)
|
323569 | 1998-03-26 | Per Hedbor | | #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;
constant _time = predef::time;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
7ee565 | 1996-12-10 | Per Hedbor | | private static array(string) cache;
private static int wanted_data, have_data;
|
b1fca0 | 1996-11-12 | Per Hedbor | | object conf;
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | object port_obj;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
#include <roxen.h>
#include <module.h>
|
470ed7 | 2000-01-03 | Martin Nilsson | | #include <variables.h>
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
9211b2 | 1998-04-24 | Per Hedbor | | int time;
|
b1fca0 | 1996-11-12 | Per Hedbor | | string raw_url;
|
d7b087 | 1997-08-31 | Per Hedbor | | int do_not_disconnect;
|
8200cd | 1998-07-14 | Henrik Grubbström (Grubba) | | mapping (string:string) variables = ([ ]);
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | mapping (string:mixed) misc =
([
#ifdef REQUEST_DEBUG
"trace_enter":lambda(mixed ...args) {
|
338ffa | 2000-02-15 | Martin Nilsson | | werror(sprintf("TRACE_ENTER(%{%O,%})\n", args));
|
59f65b | 2000-01-05 | Henrik Grubbström (Grubba) | | },
"trace_leave":lambda(mixed ...args) {
|
338ffa | 2000-02-15 | Martin Nilsson | | werror(sprintf("TRACE_LEAVE(%{%O,%})\n", 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 = (< >);
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;
|
b1fca0 | 1996-11-12 | Per Hedbor | | array (int|string) auth;
string rawauth, realauth;
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:
return _charset_decoder( Locale.Charset.encoder( (string)what ) )->decode;
}
}
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))
decoder = _charset_decoder( Locale.Charset.decoder(decoder) )->decode;
|
0b0d08 | 2000-02-14 | Per Hedbor | | if( misc->request_charset_decoded )
return;
|
653d7d | 2000-02-14 | Per Hedbor | |
|
ed1516 | 1999-11-19 | Per Hedbor | | if( !decoder )
return;
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | |
|
653d7d | 2000-02-14 | Per Hedbor | | misc->request_charset_decoded = 1;
|
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 );
|
ed1516 | 1999-11-19 | Per Hedbor | | if( auth )
{
auth = map( auth, lambda( mixed q ) {
if( stringp( q ) )
|
31c2ac | 2000-01-12 | Henrik Grubbström (Grubba) | | return safe_decoder( q );
|
ed1516 | 1999-11-19 | Per Hedbor | | return q;
} );
|
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 | |
decode_map( variables, decoder );
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 | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | void end(string|void a,int|void b);
|
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;
}
|
199d03 | 1999-09-05 | Francesco Chemolli | | if (!conf || !conf->query("req_throttle"))
|
ba88df | 1999-09-29 | Francesco Chemolli | | throttle->doit=0;
|
199d03 | 1999-09-05 | Francesco Chemolli | | if(!pipe) {
|
ba88df | 1999-09-29 | Francesco Chemolli | | if (throttle->doit || (conf && conf->throttler)) {
|
a57779 | 1999-11-24 | Per Hedbor | | pipe=roxen->slowpipe();
|
199d03 | 1999-09-05 | Francesco Chemolli | | } else {
|
a57779 | 1999-11-24 | Per Hedbor | | pipe=roxen->fastpipe();
|
199d03 | 1999-09-05 | Francesco Chemolli | | }
}
|
ba88df | 1999-09-29 | Francesco Chemolli | | if (throttle->doit) {
throttle->rate=max(throttle->rate,
conf->query("req_throttle_min"));
pipe->throttle(throttle->rate,
(int)(throttle->rate*conf->query("req_throttle_depth_mult")),
0);
|
199d03 | 1999-09-05 | Francesco Chemolli | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (conf && 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));
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!what) return;
|
e5bad2 | 1998-02-10 | Per Hedbor | | if(!pipe) setup_pipe();
if(!pipe) return;
|
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 | | }
|
199d03 | 1999-09-05 | Francesco Chemolli | | void start_sender (function callback, mixed ... args)
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | {
if (pipe) {
MARK_FD("HTTP really handled, piping "+not_query);
#ifdef FD_DEBUG
call_out(timer, 30, _time(1));
#endif
|
336ee4 | 1999-04-17 | Henrik Grubbström (Grubba) | |
pipe->set_done_callback( callback );
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | pipe->output(my_fd);
} else {
MARK_FD("HTTP really handled, pipe done");
|
336ee4 | 1999-04-17 | Henrik Grubbström (Grubba) | | callback(@args);
|
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, "+", " "));
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(variables[ a ])
variables[ a ] += "\0" + b;
else
variables[ a ] = b;
} 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;
}
private int really_set_config(array mod_config)
{
string url, m;
string base;
|
e3bda3 | 2000-01-12 | Martin Nilsson | | if (conf)
base = conf->query("MyWorldLocation");
else
base = "/";
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(supports->cookies)
{
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("Setting cookie..\n");
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(mod_config)
foreach(mod_config, m)
if(m[-1]=='-')
config[m[1..]]=0;
else
config[m]=1;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(sscanf(replace(raw_url,({"%3c","%3e","%3C","%3E" }),
({"<",">","<",">"})),"/<%*s>/%s",url)!=2)
url = "/";
|
537ec8 | 1997-11-12 | David Hedbor | | if ((base[-1] == '/') && (strlen(url) && url[0] == '/')) {
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | | url = base + url[1..];
} else {
url = base + url;
}
my_fd->write(prot + " 302 Config in cookie!\r\n"
|
b1fca0 | 1996-11-12 | Per Hedbor | | "Set-Cookie: "
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | | + http_roxen_config_cookie(indices(config) * ",") + "\r\n"
"Location: " + url + "\r\n"
|
b1fca0 | 1996-11-12 | Per Hedbor | | "Content-Type: text/html\r\n"
"Content-Length: 0\r\n\r\n");
} else {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("Setting {config} for user without Cookie support..\n");
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(mod_config)
foreach(mod_config, m)
if(m[-1]=='-')
prestate[m[1..]]=0;
else
prestate[m]=1;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
if (sscanf(replace(raw_url, ({ "%3c", "%3e", "%3C", "%3E" }),
|
0ddff6 | 1997-07-20 | Henrik Grubbström (Grubba) | | ({ "<", ">", "<", ">" })), "/<%*s>/%s", url) == 2) {
url = "/" + url;
}
if (sscanf(replace(url, ({ "%28", "%29" }), ({ "(", ")" })),
"/(%*s)/%s", url) == 2) {
url = "/" + url;
}
url = add_pre_state(url, prestate);
if (base[-1] == '/') {
url = base + url[1..];
} else {
url = base + url;
}
my_fd->write(prot + " 302 Config In Prestate!\r\n"
"\r\nLocation: " + url + "\r\n"
"Content-Type: text/html\r\n"
"Content-Length: 0\r\n\r\n");
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
41b77c | 1999-07-15 | David Hedbor | | return 2;
|
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;
}
}
|
c4ab8f | 1999-07-15 | David Hedbor | | private int parse_got()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
multiset (string) sup;
array mod_config;
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | | string a, b, s="", linename, contents;
|
b1fca0 | 1996-11-12 | Per Hedbor | | int config_in_url;
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("HTTP: parse_got(%O)", raw));
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (!method) {
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | |
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
b5218e | 1999-03-18 | Henrik Grubbström (Grubba) | |
|
41b77c | 1999-07-15 | David Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | | if (!sscanf(raw, "%s\r\n%s", line, s) &&
!sscanf(raw, "%s\n%s", line, s)) {
|
41b77c | 1999-07-15 | David Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("HTTP: parse_got(%O): Not enough data.", raw));
|
41b77c | 1999-07-15 | David Hedbor | | return 0;
|
b5218e | 1999-03-18 | Henrik Grubbström (Grubba) | | }
|
41b77c | 1999-07-15 | David Hedbor | | if(strlen(line) < 4)
{
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("HTTP: parse_got(%O): Malformed request.", raw));
|
41b77c | 1999-07-15 | David Hedbor | | return 1;
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | | }
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | string trailer, trailer_trailer;
switch(sscanf(line+" ", "%s %s %s %s %s",
method, f, clientprot, trailer, trailer_trailer))
|
41b77c | 1999-07-15 | David Hedbor | | {
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | case 5:
if (trailer_trailer != "") {
trailer += " " + trailer_trailer[..sizeof(trailer_trailer)-2];
}
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | | case 4:
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | |
|
0322b7 | 1999-08-06 | Per Hedbor | |
trailer = trailer[..sizeof(trailer) - 2];
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | f += " " + clientprot;
|
0322b7 | 1999-08-06 | Per Hedbor | |
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | |
|
0322b7 | 1999-08-06 | Per Hedbor | | int end;
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | if (!(end = (search(reverse(trailer), " ") + 1))) {
|
0322b7 | 1999-08-06 | Per Hedbor | |
clientprot = trailer;
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | } else {
|
0322b7 | 1999-08-06 | Per Hedbor | | f += " " + trailer[..sizeof(trailer) - (end + 1)];
clientprot = trailer[sizeof(trailer) - end ..];
|
1afe37 | 1997-06-12 | Henrik Grubbström (Grubba) | | }
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | |
case 3:
|
41b77c | 1999-07-15 | David Hedbor | |
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | |
prot = clientprot;
if(!(< "HTTP/1.0", "HTTP/1.1" >)[prot]) {
|
41b77c | 1999-07-15 | David Hedbor | | prot = "HTTP/1.1";
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | | }
|
7ae38b | 1999-08-04 | David Hedbor | | if (!sscanf(raw, "%s\r\n\r\n%s", s, data)) {
|
41b77c | 1999-07-15 | David Hedbor | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_got(): Request is not complete.");
|
41b77c | 1999-07-15 | David Hedbor | | return 0;
}
|
2bc908 | 1999-08-05 | Henrik Grubbström (Grubba) | |
if (!sscanf(s, "%*s\n%s", s)) {
s = "";
}
|
41b77c | 1999-07-15 | David Hedbor | | break;
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | |
case 2:
clientprot = prot = "HTTP/0.9";
if(method != "PING")
method = "GET";
s = data = "";
break;
case 1:
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(method == "PING")
|
9f85df | 1999-07-16 | Henrik Grubbström (Grubba) | | break;
return 1;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | | default:
|
41b77c | 1999-07-15 | David Hedbor | |
return 1;
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | | }
} else {
|
41b77c | 1999-07-15 | David Hedbor | | if (!sscanf(raw, "%s\r\n\r\n%s", s, data)) {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_got(): Request is still not complete.");
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | | return 0;
|
1afe37 | 1997-06-12 | Henrik Grubbström (Grubba) | | }
|
019b71 | 1999-01-13 | David Hedbor | | }
|
c4ab8f | 1999-07-15 | David Hedbor | | if(method == "PING") {
|
abdff2 | 1999-12-27 | Martin Nilsson | | my_fd->write("PONG\r\n");
|
c4ab8f | 1999-07-15 | David Hedbor | | return 2;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | raw_url = f;
time = _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.");
|
e5bad2 | 1998-02-10 | Per Hedbor | | end();
|
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 | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("After Remote Addr:%O", f));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | f = scan_for_query( f );
|
fe14f5 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("After query scan:%O", f));
|
fe14f5 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
fb5f68 | 1998-11-04 | Peter Bortas | | f = http_decode_string( f );
|
41b77c | 1999-07-15 | David Hedbor | | string prf = f[1..1];
if (prf == "<" && sscanf(f, "/<%s>/%s", a, f)==2)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
config_in_url = 1;
mod_config = (a/",");
|
e5bad2 | 1998-02-10 | Per Hedbor | | f = "/"+f;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
fe14f5 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("After cookie scan:%O", f));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | if (prf == "(" && (sscanf(f, "/(%s)/%s", a, f)==2) && strlen(a))
|
e5bad2 | 1998-02-10 | Per Hedbor | | {
|
b1fca0 | 1996-11-12 | Per Hedbor | | prestate = aggregate_multiset(@(a/","-({""})));
|
e5bad2 | 1998-02-10 | Per Hedbor | | f = "/"+f;
}
|
fe14f5 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("After prestate scan:%O", f));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
fb5f68 | 1998-11-04 | Peter Bortas | | not_query = simplify_path(f);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("After simplify_path == not_query:%O", not_query));
|
fe14f5 | 1998-08-26 | Henrik Grubbström (Grubba) | |
|
8200cd | 1998-07-14 | Henrik Grubbström (Grubba) | | request_headers = ([]);
|
21dda6 | 2000-02-10 | Martin Nilsson | | misc->pref_languages=PrefLanguages();
|
0a635b | 1998-03-08 | Henrik Grubbström (Grubba) | | if(sizeof(s)) {
|
41b77c | 1999-07-15 | David Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | |
foreach(s/"\r\n" - ({""}), line)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | if(sscanf(line, "%s:%*[ \t]%s", linename, contents) == 3)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("Header-sscanf :%s", linename));
|
41b77c | 1999-07-15 | David Hedbor | | linename=lower_case(linename);
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("lower-case :%s", linename));
|
797047 | 1999-07-15 | Henrik Grubbström (Grubba) | |
|
41b77c | 1999-07-15 | David Hedbor | | request_headers[linename] = contents;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(strlen(contents))
{
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | switch (linename) {
|
ebb1c5 | 1998-02-24 | Per Hedbor | | case "content-length":
|
41b77c | 1999-07-15 | David Hedbor | | misc->len = (int)contents;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(!misc->len) continue;
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(method == "POST")
{
|
dcc435 | 1997-05-20 | Per Hedbor | | if(!data) data="";
|
275fe2 | 1999-10-11 | Per Hedbor | | int l = misc->len;
|
7ee565 | 1996-12-10 | Per Hedbor | | wanted_data=l;
have_data=strlen(data);
|
ceb927 | 1997-05-15 | David Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(strlen(data) < l)
|
275fe2 | 1999-10-11 | Per Hedbor | | {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_request(): More data needed in POST.");
|
7ee565 | 1996-12-10 | Per Hedbor | | return 0;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | | }
|
275fe2 | 1999-10-11 | Per Hedbor | | leftovers = data[l+2..];
data = data[..l+1];
|
9211b2 | 1998-04-24 | Per Hedbor | |
|
fbfd72 | 1998-05-18 | Henrik Grubbström (Grubba) | | switch(lower_case((((misc["content-type"]||"")+";")/";")[0]-" "))
|
86c510 | 1997-10-05 | Henrik Grubbström (Grubba) | | {
default:
|
7ee565 | 1996-12-10 | Per Hedbor | | string v;
if(l < 200000)
{
|
7a0ee6 | 1998-06-27 | Henrik Grubbström (Grubba) | | foreach(replace(data,
({ "\n", "\r", "+" }),
({ "", "", " "}))/"&", v)
|
7ee565 | 1996-12-10 | Per Hedbor | | if(sscanf(v, "%s=%s", a, b) == 2)
{
a = http_decode_string( a );
b = http_decode_string( b );
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
7ee565 | 1996-12-10 | Per Hedbor | | if(variables[ a ])
variables[ a ] += "\0" + b;
else
variables[ a ] = b;
}
}
break;
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "multipart/form-data":
|
6a409d | 1999-12-27 | Martin Nilsson | |
|
57d41d | 1997-08-14 | Marcus Comstedt | | object messg = MIME.Message(data, misc);
foreach(messg->body_parts, object part) {
if(part->disp_params->filename) {
variables[part->disp_params->name]=part->getdata();
variables[part->disp_params->name+".filename"]=
part->disp_params->filename;
if(!misc->files)
misc->files = ({ part->disp_params->name });
else
misc->files += ({ part->disp_params->name });
} else {
|
05a7c8 | 1998-08-22 | Johan Schön | | if(variables[part->disp_params->name])
variables[part->disp_params->name] += "\0" + part->getdata();
else
variables[part->disp_params->name] = part->getdata();
|
7ee565 | 1996-12-10 | Per Hedbor | | }
}
break;
}
}
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "authorization":
|
b1fca0 | 1996-11-12 | Per Hedbor | | rawauth = contents;
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "proxy-authorization":
|
c5e096 | 1999-10-04 | Per Hedbor | | array y;
y = contents / " ";
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(sizeof(y) < 2)
break;
y[1] = decode(y[1]);
misc->proxyauth=y;
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "pragma":
|
5e8921 | 1997-02-13 | Per Hedbor | | pragma|=aggregate_multiset(@replace(contents, " ", "")/ ",");
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "user-agent":
|
404461 | 2000-01-20 | Martin Nilsson | | if(!client || !client_var->Fullname)
|
ebb1c5 | 1998-02-24 | Per Hedbor | | {
sscanf(contents, "%s via", contents);
|
f49bd3 | 2000-01-20 | Martin Nilsson | | client_var->Fullname=contents;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | client = contents/" " - ({ "" });
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "referer":
|
f6d62d | 1997-03-26 | Per Hedbor | | referer = contents/" ";
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | case "extension":
|
b1fca0 | 1996-11-12 | Per Hedbor | | #ifdef DEBUG
|
6a409d | 1999-12-27 | Martin Nilsson | | werror("Client extension: "+contents+"\n");
|
b1fca0 | 1996-11-12 | Per Hedbor | | #endif
|
84ae13 | 1999-07-28 | David Hedbor | | case "request-range":
|
d98628 | 1999-06-30 | David Hedbor | | contents = lower_case(contents-" ");
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(!search(contents, "bytes"))
|
d98628 | 1999-06-30 | David Hedbor | |
misc->range = contents[6..];
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
84ae13 | 1999-07-28 | David Hedbor | | case "range":
contents = lower_case(contents-" ");
if(!misc->range && !search(contents, "bytes"))
misc->range = contents[6..];
break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | case "connection":
case "content-type":
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | misc[linename] = lower_case(contents);
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "accept-encoding":
|
dd23d7 | 1998-03-31 | Henrik Grubbström (Grubba) | | foreach((contents-" ")/",", string e) {
if (lower_case(e) == "gzip") {
supports["autogunzip"] = 1;
}
}
case "accept":
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "accept-charset":
case "session-id":
case "message-id":
case "from":
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(misc[linename])
|
5e8921 | 1997-02-13 | Per Hedbor | | misc[linename] += (contents-" ") / ",";
|
b1fca0 | 1996-11-12 | Per Hedbor | | else
|
5e8921 | 1997-02-13 | Per Hedbor | | misc[linename] = (contents-" ") / ",";
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
06cc9a | 2000-01-23 | Martin Nilsson | | case "accept-language":
array alang=(contents-" ") / ",";
if(misc["accept-language"])
misc["accept-language"] += alang;
|
21dda6 | 2000-02-10 | Martin Nilsson | | else
|
06cc9a | 2000-01-23 | Martin Nilsson | | misc["accept-language"] = alang;
|
2aa88e | 2000-01-28 | Martin Nilsson | | misc->pref_languages->languages=misc["accept-language"];
|
06cc9a | 2000-01-23 | Martin Nilsson | | break;
|
b1fca0 | 1996-11-12 | Per Hedbor | | case "cookie":
string c;
misc->cookies = contents;
|
5e5d6a | 1998-04-30 | Henrik Grubbström (Grubba) | | if (!sizeof(contents)) {
break;
}
foreach(((contents/";") - ({""})), c)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
string name, value;
|
5e5d6a | 1998-04-30 | Henrik Grubbström (Grubba) | | while(sizeof(c) && c[0]==' ') c=c[1..];
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(sscanf(c, "%s=%s", name, value) == 2)
{
value=http_decode_string(value);
name=http_decode_string(name);
cookies[ name ]=value;
if(name == "RoxenConfig" && strlen(value))
{
array tmpconfig = value/"," + ({ });
string m;
if(mod_config && sizeof(mod_config))
foreach(mod_config, m)
if(!strlen(m))
{ continue; }
else if(m[0]=='-')
tmpconfig -= ({ m[1..] });
else
tmpconfig |= ({ m });
mod_config = 0;
config = aggregate_multiset(@tmpconfig);
}
}
}
break;
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "host":
case "proxy-connection":
case "security-scheme":
|
6e89ab | 1998-08-10 | Per Hedbor | | case "via":
case "cache-control":
case "negotiate":
case "forwarded":
|
9b10a4 | 1998-10-18 | Henrik Grubbström (Grubba) | | case "new-uri":
|
6e89ab | 1998-08-10 | Per Hedbor | | misc[linename]=contents;
|
a7ebda | 2000-01-30 | Per Hedbor | | break;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
48633b | 1997-08-04 | Henrik Grubbström (Grubba) | | case "proxy-by":
case "proxy-maintainer":
case "proxy-software":
case "mime-version":
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
4ee960 | 1999-07-02 | David Hedbor | | case "if-modified-since":
|
ebb1c5 | 1998-02-24 | Per Hedbor | | since=contents;
|
b1fca0 | 1996-11-12 | Per Hedbor | | break;
}
}
}
|
41b77c | 1999-07-15 | David Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
41b77c | 1999-07-15 | David Hedbor | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_got(): after header scan");
|
abdff2 | 1999-12-27 | Martin Nilsson | | #ifndef DISABLE_SUPPORTS
|
41b77c | 1999-07-15 | David Hedbor | | if(!client) {
client = ({ "unknown" });
|
338ffa | 2000-02-15 | Martin Nilsson | | array s_and_v = find_supports_and_vars("", supports);
supports = s_and_v[0];
client_var = s_and_v[1];
|
f49bd3 | 2000-01-20 | Martin Nilsson | | }
else {
client_var->fullname=lower_case(client_var->Fullname);
|
338ffa | 2000-02-15 | Martin Nilsson | | 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];
|
f49bd3 | 2000-01-20 | Martin Nilsson | | }
|
8d1602 | 1999-11-16 | Henrik Grubbström (Grubba) | |
|
653d7d | 2000-02-14 | Per Hedbor | | if ( client_var->charset && client_var->charset != "iso-8859-1" )
{
set_output_charset( client_var->charset );
input_charset = client_var->charset;
|
8d1602 | 1999-11-16 | Henrik Grubbström (Grubba) | | }
|
41b77c | 1999-07-15 | David Hedbor | | #else
supports = (< "images", "gifinline", "forms", "mailto">);
#endif
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_got(): supports");
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(!referer) referer = ({ });
|
dde965 | 1996-12-08 | David Hedbor | | if(misc->proxyauth) {
mixed tmp1,tmp2;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
dde965 | 1996-12-08 | David Hedbor | | foreach(tmp2 = (raw / "\n"), tmp1) {
if(!search(lower_case(tmp1), "proxy-authorization:"))
tmp2 -= ({tmp1});
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | raw = tmp2 * "\n";
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ceb927 | 1997-05-15 | David Hedbor | | if(config_in_url) {
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: parse_got(): config_in_url");
|
ceb927 | 1997-05-15 | David Hedbor | | return really_set_config( mod_config );
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!supports->cookies)
config = prestate;
else
if(conf
|
ab9b6d | 2000-02-11 | Per Hedbor | | && port_obj->query("set_cookie")
|
27b0e1 | 1996-11-26 | Per Hedbor | | && !cookies->RoxenUserID && strlen(not_query)
|
ebb1c5 | 1998-02-24 | Per Hedbor | | && not_query[0]=='/' && method!="PUT")
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
ab9b6d | 2000-02-11 | Per Hedbor | | if (!(port_obj->query("set_cookie_only_once") &&
|
a773c6 | 1997-07-06 | Henrik Grubbström (Grubba) | | cache_lookup("hosts_for_cookie",remoteaddr))) {
misc->moreheads = ([ "Set-Cookie":http_roxen_id_cookie(), ]);
}
|
ab9b6d | 2000-02-11 | Per Hedbor | | if (port_obj->query("set_cookie_only_once"))
|
a773c6 | 1997-07-06 | Henrik Grubbström (Grubba) | | cache_set("hosts_for_cookie",remoteaddr,1);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
41b77c | 1999-07-15 | David Hedbor | | return 3;
|
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
if (my_fd) MARK_FD("my_fd in HTTP disconnected?");
#endif
|
35ed00 | 1998-03-26 | Per Hedbor | | if(do_not_disconnect)return;
|
14179b | 1997-01-29 | Per Hedbor | | destruct();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ebb1c5 | 1998-02-24 | Per Hedbor | | void end(string|void s, int|void keepit)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
903e57 | 1998-03-25 | Per Hedbor | | pipe = 0;
|
8afc81 | 1998-02-04 | Per Hedbor | | #ifdef PROFILE
if(conf)
{
float elapsed = SECHR(HRTIME()-req_time);
|
311779 | 1998-08-20 | Per Hedbor | | string nid =
#ifdef FILE_PROFILE
not_query
#else
dirname(not_query)
#endif
;
|
8afc81 | 1998-02-04 | Per Hedbor | | array p;
|
311779 | 1998-08-20 | Per Hedbor | | if(!(p=conf->profile_map[nid]))
p = conf->profile_map[nid] = ({0,0.0,0.0});
|
10f797 | 1999-04-22 | Per Hedbor | | p[0]++;
|
8afc81 | 1998-02-04 | Per Hedbor | | p[1] += elapsed;
if(elapsed > p[2]) p[2]=elapsed;
}
|
ceb927 | 1997-05-15 | David Hedbor | | #endif
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
#ifdef KEEP_ALIVE
|
49c07e | 2000-01-17 | Henrik Grubbström (Grubba) | | if(keepit && !file->raw
|
41b77c | 1999-07-15 | David Hedbor | | && (misc->connection == "keep-alive" ||
(prot == "HTTP/1.1" && misc->connection != "close"))
|
ebb1c5 | 1998-02-24 | Per Hedbor | | && my_fd)
{
|
e554ae | 1999-12-26 | Johan Sundström | | object o = object_program(this_object())(my_fd, port_obj);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | o->remoteaddr = remoteaddr;
o->supports = supports;
o->host = host;
o->client = client;
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP kept alive");
|
ebb1c5 | 1998-02-24 | Per Hedbor | | object fd = my_fd;
my_fd=0;
|
903e57 | 1998-03-25 | Per Hedbor | | if(s) leftovers += s;
|
870a9e | 1999-10-04 | Per Hedbor | | o->chain(fd,port_obj,leftovers);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | disconnect();
return;
}
#endif
|
e8790b | 1998-02-19 | Per Hedbor | | if(objectp(my_fd))
{
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP closed");
|
ebb1c5 | 1998-02-24 | Per Hedbor | | catch {
my_fd->set_close_callback(0);
my_fd->set_read_callback(0);
|
323569 | 1998-03-26 | Per Hedbor | | my_fd->set_blocking();
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(s) my_fd->write(s);
|
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;
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | disconnect();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
9211b2 | 1998-04-24 | Per Hedbor | | static void do_timeout()
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
beb4b2 | 1998-06-02 | Per Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | int elapsed = _time()-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");
|
beb4b2 | 1998-06-02 | 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;
id = f->read(200);
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 "";
}
void add_id(array to)
{
|
0b651e | 1998-03-26 | Per Hedbor | | foreach(to[1], array q)
if(stringp(q[0]))
q[0]+=get_id(q[0]);
|
35ed00 | 1998-03-26 | Per Hedbor | | }
|
86e77d | 1998-05-07 | Per Hedbor | | string link_to(string what, int eid, int qq)
{
int line;
string file, fun;
sscanf(what, "%s(%*s in line %d in %s", fun, line, file);
if(file && fun && line)
{
sscanf(file, "%s (", file);
if(file[0]!='/') file = combine_path(getcwd(), file);
return ("<a href=\"/(old_error,find_file)/error?"+
"file="+http_encode_string(file)+"&"
"fun="+http_encode_string(fun)+"&"
"off="+qq+"&"
"error="+eid+"&"
"line="+line+"#here\">");
}
return "<a>";
}
string format_backtrace(array bt, int eid)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
2b9d4b | 1998-03-25 | Per Hedbor | |
|
0e5b1a | 1999-10-10 | Per Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | | bt = map( bt, lambda( string q ){
|
0e5b1a | 1999-10-10 | Per Hedbor | | return highlight_pike("foo", ([ "nopre":1 ]), q);
} );
|
35c263 | 1999-02-16 | Per Hedbor | | string reason = roxen.diagnose_error( bt );
|
bd2223 | 1998-03-27 | David Hedbor | | if(sizeof(bt) == 1)
bt += ({ "Unknown error, no backtrace."});
|
2b9d4b | 1998-03-25 | Per Hedbor | | string res = ("<title>Internal Server Error</title>"
"<body bgcolor=white text=black link=darkblue vlink=darkblue>"
"<table width=\"100%\" border=0 cellpadding=0 cellspacing=0>"
"<tr><td valign=bottom align=left><img border=0 "
|
86e77d | 1998-05-07 | Per Hedbor | | "src=\""+(conf?"/internal-roxen-":"/img/")+
"roxen-icon-gray.gif\" alt=\"\"></td>"
|
2b9d4b | 1998-03-25 | Per Hedbor | | "<td> </td><td width=100% height=39>"
"<table cellpadding=0 cellspacing=0 width=100% border=0>"
"<td width=\"100%\" align=right valigh=center height=28>"
"<b><font size=+1>Failed to complete your request</font>"
"</b></td></tr><tr width=\"100%\"><td bgcolor=\"#003366\" "
"align=right height=12 width=\"100%\"><font color=white "
"size=-2>Internal Server Error </font></td>"
|
86e77d | 1998-05-07 | Per Hedbor | | "</tr></table></td></tr></table>"
"<p>\n\n"
"<font size=+2 color=darkred>"
"<img alt=\"\" hspace=10 align=left src="+
(conf?"/internal-roxen-":"/img/") +"manual-warning.gif>"
+bt[0]+"</font><br>\n"
|
ac2e3f | 1999-10-08 | Per Hedbor | | "The error occured while calling <b>"+
bt[1]+"</b><p>\n"
|
86e77d | 1998-05-07 | Per Hedbor | | +(reason?reason+"<p>":"")
+"<br><h3><br>Complete Backtrace:</h3>\n\n<ol>");
|
2b9d4b | 1998-03-25 | Per Hedbor | | int q = sizeof(bt)-1;
foreach(bt[1..], string line)
{
|
35ed00 | 1998-03-26 | Per Hedbor | | string fun, args, where, fo;
|
0ce9d2 | 1998-05-12 | Henrik Grubbström (Grubba) | | if((sscanf(html_encode_string(line), "%s(%s) in %s",
fun, args, where) == 3) &&
|
721c05 | 1998-05-12 | Johan Schön | | (sscanf(where, "%*s in %s", fo) && fo)) {
|
86e77d | 1998-05-07 | Per Hedbor | | line += get_id( fo );
res += ("<li value="+(q--)+"> "+
|
0ce9d2 | 1998-05-12 | Henrik Grubbström (Grubba) | | (replace(line, fo, link_to(line,eid,sizeof(bt)-q-1)+fo+"</a>")
|
86e77d | 1998-05-07 | Per Hedbor | | -(getcwd()+"/"))+"<p>\n");
|
0ce9d2 | 1998-05-12 | Henrik Grubbström (Grubba) | | } else {
|
86e77d | 1998-05-07 | Per Hedbor | | res += "<li value="+(q--)+"> <b><font color=darkgreen>"+
line+"</font></b><p>\n";
|
0ce9d2 | 1998-05-12 | Henrik Grubbström (Grubba) | | }
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
86e77d | 1998-05-07 | Per Hedbor | | res += ("</ul><p><b><a href=\"/(old_error,plain)/error?error="+eid+"\">"
|
2b9d4b | 1998-03-25 | Per Hedbor | | "Generate text-only version of this error message, for bug reports"+
"</a></b>");
return res+"</body>";
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
f28818 | 1998-05-25 | Per Hedbor | | string generate_bugreport(array from, string u, string rd)
|
2b9d4b | 1998-03-25 | Per Hedbor | | {
|
35ed00 | 1998-03-26 | Per Hedbor | | add_id(from);
|
0b651e | 1998-03-26 | Per Hedbor | | return ("<pre>"+html_encode_string("Roxen version: "+version()+
|
35c263 | 1999-02-16 | Per Hedbor | | (roxen.real_version != version()?
" ("+roxen.real_version+")":"")+
|
f28818 | 1998-05-25 | Per Hedbor | | "\nRequested URL: "+u+"\n"
|
9a72d6 | 1998-03-25 | Per Hedbor | | "\nError: "+
|
35ed00 | 1998-03-26 | Per Hedbor | | describe_backtrace(from)-(getcwd()+"/")+
|
f28818 | 1998-05-25 | Per Hedbor | | "\n\nRequest data:\n"+rd));
}
string censor(string what)
{
string a, b, c;
|
0322b7 | 1999-08-06 | Per Hedbor | | if(!what)
return "No backtrace";
|
f28818 | 1998-05-25 | Per Hedbor | | if(sscanf(what, "%shorization:%s\n%s", a, b, c)==3)
return a+" ################ (censored)\n"+c;
return what;
|
2b9d4b | 1998-03-25 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
86e77d | 1998-05-07 | Per Hedbor | | int store_error(array err)
{
|
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;
|
f28818 | 1998-05-25 | Per Hedbor | | e[id] = ({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;
}
|
2b9d4b | 1998-03-25 | Per Hedbor | | void internal_error(array err)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
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 {
|
bd2223 | 1998-03-27 | David Hedbor | | array(string) bt = (describe_backtrace(err)/"\n") - ({""});
|
86e77d | 1998-05-07 | Per Hedbor | | file = http_low_answer(500, format_backtrace(bt, 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));
file = http_low_answer(500, "<h1>Error: The server failed to "
"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 {
|
b1fca0 | 1996-11-12 | Per Hedbor | | file = 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;
}
|
beaca0 | 1998-02-20 | Per Hedbor | | void do_log()
|
d7b087 | 1997-08-31 | Per Hedbor | | {
|
323569 | 1998-03-26 | Per Hedbor | | MARK_FD("HTTP logging");
|
d7b087 | 1997-08-31 | Per Hedbor | | if(conf)
{
int len;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(pipe) file->len = pipe->bytes_sent();
|
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 | | }
}
|
903e57 | 1998-03-25 | Per Hedbor | | end(0,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,
|
abdff2 | 1999-12-27 | Martin Nilsson | | _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 | |
string handle_error_file_request(array err, int eid)
{
string data = Stdio.read_bytes(variables->file);
array(string) bt = (describe_backtrace(err)/"\n") - ({""});
string down;
if((int)variables->off-1 >= 1)
down = link_to( bt[(int)variables->off-1],eid, (int)variables->off-1);
else
down = "<a>";
if(data)
{
int off = 49;
array (string) lines = data/"\n";
int start = (int)variables->line-50;
if(start < 0)
{
off += start;
start = 0;
}
int end = (int)variables->line+50;
lines=highlight_pike("foo", ([ "nopre":1 ]), lines[start..end]*"\n")/"\n";
if(sizeof(lines)>off)
lines[off]=("<font size=+2><b>"+down+lines[off]+"</a></b></font></a>");
lines[max(off-20,0)] = "<a name=here>"+lines[max(off-20,0)]+"</a>";
data = lines*"\n";
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
86e77d | 1998-05-07 | Per Hedbor | | return format_backtrace(bt,eid)+"<hr noshade><pre>"+data+"</pre>";
}
|
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];
}
}
}
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()
{
if (clientprot == "HTTP/1.1") {
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 | | {
|
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;
|
5bc199 | 1997-01-29 | Per Hedbor | | string head_string;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | if (result) {
file = result;
|
14179b | 1997-01-29 | Per Hedbor | | }
|
82f519 | 1997-03-02 | Per Hedbor | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("HTTP: send_result(%O)", file));
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!mappingp(file))
{
|
f6d62d | 1997-03-26 | Per Hedbor | | if(misc->error_code)
file = http_low_answer(misc->error_code, errors[misc->error]);
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | else if(err = catch {
file=http_low_answer(404,
|
f20692 | 2000-03-07 | Martin Stjernholm | | #ifdef OLD_RXML_COMPAT
replace(parse_rxml(conf->query("ZNoSuchFile"),
this_object()),
({"$File", "$Me"}),
({not_query,
conf->query("MyWorldLocation")})));
#else
|
a7e39f | 2000-02-04 | Per Hedbor | | parse_rxml(conf->query("ZNoSuchFile"),
this_object()));
|
f20692 | 2000-03-07 | Martin Stjernholm | | #endif
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }) {
|
2b40f4 | 1999-12-29 | Martin Stjernholm | | INTERNAL_ERROR(err);
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
|
14179b | 1997-01-29 | Per Hedbor | | } else {
|
abdff2 | 1999-12-27 | Martin Nilsson | | if((file->file == -1) || file->leave_me)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
903e57 | 1998-03-25 | Per Hedbor | | if(do_not_disconnect) {
file = 0;
pipe = 0;
return;
}
|
aa92c1 | 1998-08-20 | Henrik Grubbström (Grubba) | | my_fd = 0;
file = 0;
|
14179b | 1997-01-29 | Per Hedbor | | return;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(file->type == "raw") file->raw = 1;
else if(!file->type) file->type="text/plain";
|
14179b | 1997-01-29 | Per Hedbor | | }
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | if(!file->raw)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
41b77c | 1999-07-15 | David Hedbor | | heads = ([]);
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!file->len)
{
if(objectp(file->file))
|
14179b | 1997-01-29 | Per Hedbor | | if(!file->stat && !(file->stat=misc->stat))
|
7568ae | 2000-02-17 | Per Hedbor | | file->stat = (array(int))file->file->stat();
|
b1fca0 | 1996-11-12 | Per Hedbor | | array fstat;
if(arrayp(fstat = file->stat))
{
if(file->file && !file->len)
file->len = fstat[1];
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
6692f3 | 1999-12-06 | Henrik Grubbström (Grubba) | | if (fstat[3] > misc->last_modified) {
misc->last_modified = fstat[3];
|
fc5d57 | 1999-12-06 | Henrik Grubbström (Grubba) | | }
|
41b77c | 1999-07-15 | David Hedbor | | if(prot != "HTTP/0.9") {
|
6692f3 | 1999-12-06 | Henrik Grubbström (Grubba) | | heads["Last-Modified"] = http_date(misc->last_modified);
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | if(since)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
fc5d57 | 1999-12-06 | Henrik Grubbström (Grubba) | |
|
ba41f1 | 2000-01-03 | Martin Nilsson | | array(int) since_info = roxen->parse_since(since);
|
6692f3 | 1999-12-06 | Henrik Grubbström (Grubba) | | if ((since_info[0] >= misc->last_modified) &&
|
9e6274 | 1999-12-06 | Henrik Grubbström (Grubba) | | (since_info[0] + misc->cacheable >= predef::time(1)) &&
|
fc5d57 | 1999-12-06 | Henrik Grubbström (Grubba) | | ((since_info[1] == -1) || (since_info[1] == file->len)))
|
41b77c | 1999-07-15 | David Hedbor | | {
file->error = 304;
file->file = 0;
file->data="";
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
}
}
}
|
41b77c | 1999-07-15 | David Hedbor | | if(prot != "HTTP/0.9") {
|
1c8033 | 2000-02-17 | Per Hedbor | | string h, charset="";
|
0b0d08 | 2000-02-14 | Per Hedbor | |
if( stringp(file->data) )
{
|
65301c | 2000-03-06 | Jonas Wallden | | if (file["type"][0..4] == "text/") {
[charset,file->data] = output_encode( file->data );
if( charset )
charset = "; charset="+charset;
else
charset = "";
}
|
62caea | 2000-02-14 | Per Hedbor | | if(stringp(file->data))
|
d7978b | 2000-02-14 | Per Hedbor | | file->len = strlen(file->data);
|
0b0d08 | 2000-02-14 | Per Hedbor | | }
heads |= ([
|
41b77c | 1999-07-15 | David Hedbor | | "MIME-Version" : (file["mime-version"] || "1.0"),
|
0b0d08 | 2000-02-14 | Per Hedbor | | "Content-type" : file["type"]+charset,
|
41b77c | 1999-07-15 | David Hedbor | | "Accept-Ranges" : "bytes",
"Server" : replace(version(), " ", "·"),
#ifdef KEEP_ALIVE
"Connection": (misc->connection == "close" ? "close": "Keep-Alive"),
#else
"Connection" : "close",
#endif
"Date" : http_date(time)
]);
|
d98628 | 1999-06-30 | David Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | if(file->encoding)
heads["Content-Encoding"] = file->encoding;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
if(!file->error)
|
41b77c | 1999-07-15 | David Hedbor | | file->error=200;
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | if(file->expires)
heads->Expires = http_date(file->expires);
|
a7ebda | 2000-01-30 | Per Hedbor | | if(mappingp(file->extra_heads))
|
41b77c | 1999-07-15 | David Hedbor | | heads |= file->extra_heads;
|
a7ebda | 2000-01-30 | Per Hedbor | | if(mappingp(misc->moreheads))
|
41b77c | 1999-07-15 | David Hedbor | | heads |= misc->moreheads;
if(misc->range && file->len && objectp(file->file) && !file->data &&
file->error == 200 && (method == "GET" || method == "HEAD"))
{
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | array ranges = parse_range_header(file->len);
if(ranges)
|
abdff2 | 1999-12-27 | Martin Nilsson | | {
|
41b77c | 1999-07-15 | David Hedbor | | if(sizeof(ranges))
|
d98628 | 1999-06-30 | David Hedbor | | {
|
41b77c | 1999-07-15 | David Hedbor | | 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 {
|
84ae13 | 1999-07-28 | David Hedbor | | file->file = MultiRangeWrapper(file, heads, ranges, this_object());
|
41b77c | 1999-07-15 | David Hedbor | | }
|
d98628 | 1999-06-30 | David Hedbor | | } else {
|
41b77c | 1999-07-15 | David Hedbor | |
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;
}
|
d98628 | 1999-06-30 | David Hedbor | | }
}
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | head_string = prot+" "+(file->rettext||errors[file->error])+"\r\n";
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
41b77c | 1999-07-15 | David Hedbor | | foreach(indices(heads), h)
if(arrayp(heads[h]))
foreach(heads[h], tmp)
|
a7ebda | 2000-01-30 | Per Hedbor | | head_string += h+": "+tmp+"\r\n";
|
41b77c | 1999-07-15 | David Hedbor | | else
|
a7ebda | 2000-01-30 | Per Hedbor | | head_string += h+": "+heads[h]+"\r\n";
|
abdff2 | 1999-12-27 | Martin Nilsson | |
if(file->len > -1)
|
22dc8e | 1999-12-21 | Marcus Comstedt | | head_string += "Content-Length: "+ file->len +"\r\n";
|
49c07e | 2000-01-17 | Henrik Grubbström (Grubba) | | else
misc->connection = "close";
|
41b77c | 1999-07-15 | David Hedbor | | head_string += "\r\n";
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | | if(conf) conf->hsent += strlen(head_string);
}
|
14179b | 1997-01-29 | Per Hedbor | | }
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR(sprintf("Sending result for prot:%O, method:%O file:%O\n",
|
7a0ee6 | 1998-06-27 | Henrik Grubbström (Grubba) | | prot, method, file));
|
bd2223 | 1998-03-27 | David Hedbor | | MARK_FD("HTTP handled");
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
903e57 | 1998-03-25 | Per Hedbor | | #ifdef KEEP_ALIVE
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(!leftovers) leftovers = data||"";
|
903e57 | 1998-03-25 | Per Hedbor | | #endif
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
18b316 | 1998-03-25 | David Hedbor | | if(method != "HEAD" && file->error != 304)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
f71a6b | 2000-01-22 | Martin Stjernholm | | if(my_fd->query_fd && my_fd->query_fd() >= 0 &&
file->len > 0 && file->len < 2000)
{
|
0b0d08 | 2000-02-14 | Per Hedbor | | my_fd->write(head_string+
(file->file?file->file->read(file->len):
(file->data[..file->len-1])));
|
f71a6b | 2000-01-22 | Martin Stjernholm | | do_log();
return;
}
|
0b0d08 | 2000-02-14 | Per Hedbor | | if(head_string)
send(head_string);
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(file->data && strlen(file->data))
send(file->data, file->len);
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(file->file)
|
ebb1c5 | 1998-02-24 | Per Hedbor | | send(file->file, file->len);
|
18b316 | 1998-03-25 | David Hedbor | | } else
file->len = 1;
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
336ee4 | 1999-04-17 | Henrik Grubbström (Grubba) | | start_sender(do_log);
|
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()");
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
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 = ([
"type":"text/html",
|
f28818 | 1998-05-25 | Per Hedbor | | "data":generate_bugreport( @err ),
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | ]);
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | } else {
if(prestate->find_file)
{
if(!realauth)
file = http_auth_required("admin");
else
{
array auth = (realauth+":")/":";
|
35c263 | 1999-02-16 | Per Hedbor | | if((auth[0] != roxen.query("ConfigurationUser"))
|| !crypt(auth[1], roxen.query("ConfigurationPassword")))
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | file = http_auth_required("admin");
else
file = ([
"type":"text/html",
|
abdff2 | 1999-12-27 | Martin Nilsson | | "data":handle_error_file_request( err[0],
|
f28818 | 1998-05-25 | Per Hedbor | | (int)variables->error ),
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | ]);
}
|
8a80d4 | 1999-05-20 | Per Hedbor | | send_result();
return;
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
}
}
}
#endif /* MAGIC_ERROR */
remove_call_out(do_timeout);
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 );
|
338ffa | 2000-02-15 | Martin Nilsson | | if( !file || !file->pipe )
|
8139e8 | 2000-02-10 | Per Hedbor | | send_result();
|
d943c8 | 1998-05-18 | Henrik Grubbström (Grubba) | | }
|
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;
|
14179b | 1997-01-29 | Per Hedbor | | void got_data(mixed fooid, string s)
{
|
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");
|
ceb927 | 1997-05-15 | David Hedbor | | remove_call_out(do_timeout);
|
abdff2 | 1999-12-27 | Martin Nilsson | | call_out(do_timeout, 30);
|
ceb927 | 1997-05-15 | David Hedbor | |
|
3d5e91 | 1998-05-21 | David Hedbor | | time = _time(1);
|
c4ab8f | 1999-07-15 | David Hedbor | | if(!raw)
raw = s;
|
abdff2 | 1999-12-27 | Martin Nilsson | | else
|
c4ab8f | 1999-07-15 | David Hedbor | | raw += s;
|
14179b | 1997-01-29 | Per Hedbor | | if(wanted_data)
{
|
c4ab8f | 1999-07-15 | David Hedbor | | if(strlen(s) + have_data < wanted_data)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
c4ab8f | 1999-07-15 | David Hedbor | |
|
14179b | 1997-01-29 | Per Hedbor | | have_data += strlen(s);
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: We want more data.");
|
14179b | 1997-01-29 | Per Hedbor | | return;
}
}
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
41b77c | 1999-07-15 | David Hedbor | |
|
c4ab8f | 1999-07-15 | David Hedbor | | if(strlen(raw)) tmp = parse_got();
|
41b77c | 1999-07-15 | David Hedbor | | switch(tmp)
|
abdff2 | 1999-12-27 | Martin Nilsson | | {
|
fb5f68 | 1998-11-04 | Peter Bortas | | case 0:
|
abdff2 | 1999-12-27 | Martin Nilsson | |
|
c4ab8f | 1999-07-15 | David Hedbor | |
|
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");
|
41b77c | 1999-07-15 | David Hedbor | | end((prot||"HTTP/1.0")+" 500 Stupid Client Error\r\nContent-Length: 0\r\n\r\n");
|
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;
}
|
ebb1c5 | 1998-02-24 | Per Hedbor | |
|
ed1516 | 1999-11-19 | Per Hedbor | | mixed q;
if( q = variables->magic_roxen_automatic_charset_variable )
|
653d7d | 2000-02-14 | Per Hedbor | | decode_charset_encoding( get_client_charset_decoder( q,this_object() ) );
if( input_charset )
decode_charset_encoding( input_charset );
|
ed1516 | 1999-11-19 | Per Hedbor | |
|
653d7d | 2000-02-14 | Per Hedbor | | if (misc->host)
{
|
94a5b9 | 1999-10-25 | Henrik Grubbström (Grubba) | |
conf =
port_obj->find_configuration_for_url(port_obj->name + "://" +
misc->host +
(search(misc->host, ":")<0?
(":"+port_obj->default_port):"") +
not_query,
this_object());
|
653d7d | 2000-02-14 | Per Hedbor | | }
else
{
|
94a5b9 | 1999-10-25 | Henrik Grubbström (Grubba) | |
conf = port_obj->urls[port_obj->sorted_urls[0]]->conf;
}
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
abdff2 | 1999-12-27 | Martin Nilsson | | if (rawauth)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
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 (conf->auth_module)
|
c5e096 | 1999-10-04 | Per Hedbor | | y = conf->auth_module->auth(y, this_object());
auth = y;
}
}
|
abdff2 | 1999-12-27 | Martin Nilsson | | if( misc->proxyauth )
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
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++;
|
6a409d | 1999-12-27 | Martin Nilsson | | REQUEST_WERR("HTTP: Calling roxen.handle().");
|
9d8ea1 | 1999-04-16 | Henrik Grubbström (Grubba) | |
|
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;
|
35c263 | 1999-02-16 | Per Hedbor | | roxen.handle(this_object()->handle_request);
|
acd34a | 2000-01-22 | Martin Stjernholm | |
|
653d7d | 2000-02-14 | Per Hedbor | | })
{
|
acd34a | 2000-01-22 | Martin Stjernholm | | report_error("Internal server error: " + describe_backtrace(err));
my_fd->close();
destruct (my_fd);
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;
|
e554ae | 1999-12-26 | Johan Sundström | | c=object_program(t=this_object())(0, port_obj);
|
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;
c->variables = copy_value(variables);
|
48fa36 | 1997-04-05 | Per Hedbor | | c->misc = copy_value(misc);
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;
|
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();
|
abdff2 | 1999-12-27 | Martin Nilsson | | else if((_time(1) - time) > 4800)
|
323569 | 1998-03-26 | Per Hedbor | | end();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
14179b | 1997-01-29 | Per Hedbor | | void create(object f, object c)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
14179b | 1997-01-29 | Per Hedbor | | if(f)
{
|
41b77c | 1999-07-15 | David Hedbor | | MARK_FD("HTTP connection");
f->set_nonblocking(got_data, 0, end);
|
14179b | 1997-01-29 | Per Hedbor | | my_fd = f;
|
c5e096 | 1999-10-04 | Per Hedbor | | if( c )
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | port_obj = c;
|
3158d2 | 1997-12-10 | David Hedbor | | call_out(do_timeout, 30);
|
3d5e91 | 1998-05-21 | David Hedbor | | time = _time(1);
|
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;
|
870a9e | 1999-10-04 | Per Hedbor | | port_obj = c;
|
ebb1c5 | 1998-02-24 | Per Hedbor | | do_not_disconnect=-1;
|
a7ebda | 2000-01-30 | Per Hedbor | |
|
9211b2 | 1998-04-24 | Per Hedbor | | MARK_FD("Kept alive");
|
4949d7 | 1998-03-28 | David Hedbor | | if(strlen(le))
got_data(0,le);
|
a7ebda | 2000-01-30 | Per Hedbor | | else
{
|
18c62d | 1999-05-27 | Stephen R. van den Berg | |
call_out(do_timeout, 150);
time = _time(1);
}
|
4949d7 | 1998-03-28 | David Hedbor | |
|
ebb1c5 | 1998-02-24 | Per Hedbor | | if(!my_fd)
{
if(do_not_disconnect == -1)
{
do_not_disconnect=0;
disconnect();
}
|
a7ebda | 2000-01-30 | Per Hedbor | | }
else
{
|
abdff2 | 1999-12-27 | Martin Nilsson | | if(do_not_disconnect == -1)
|
903e57 | 1998-03-25 | Per Hedbor | | do_not_disconnect = 0;
|
a7ebda | 2000-01-30 | Per Hedbor | | if(!processed)
{
|
903e57 | 1998-03-25 | Per Hedbor | | f->set_close_callback(end);
f->set_read_callback(got_data);
}
|
ebb1c5 | 1998-02-24 | Per Hedbor | | }
}
|
08bd3c | 1999-11-02 | Per Hedbor | |
string _sprintf( )
{
return "RequestID()";
}
|
84fb68 | 2000-02-03 | Per Hedbor | |
Stdio.File connection( )
{
return my_fd;
}
Configuration configuration()
{
return conf;
}
|