f41b98 | 2009-05-07 | Martin Stjernholm | |
|
ecafe8 | 2000-12-18 | Martin Nilsson | |
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | |
|
ecafe8 | 2000-12-18 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | #include <roxen.h>
|
69e4cd | 2000-03-09 | Martin Stjernholm | | #include <config.h>
|
88bff1 | 2000-09-12 | Per Hedbor | | #include <version.h>
|
3c4c6e | 2000-11-02 | Per Hedbor | | #include <module.h>
|
a97287 | 2000-12-11 | Per Hedbor | | #include <stat.h>
|
e079b2 | 2000-12-11 | Per Hedbor | | #define roxen roxenp()
|
a97287 | 2000-12-11 | Per Hedbor | |
#ifdef HTTP_DEBUG
|
072082 | 2001-03-13 | Martin Nilsson | | # define HTTP_WERR(X) report_debug("HTTP: "+X+"\n");
|
a97287 | 2000-12-11 | Per Hedbor | | #else
# define HTTP_WERR(X)
#endif
|
32cd1c | 2008-10-13 | Martin Stjernholm | |
constant pike_cycle_depth = 0;
|
12082b | 2011-02-15 | Henrik Grubbström (Grubba) | |
enum OnError {
THROW_INTERNAL = 0,
THROW_RXML,
LOG_ERROR,
RETURN_ZERO,
};
int(0..0) raise_err (OnError on_error, sprintf_format msg,
sprintf_args... args)
{
switch(on_error) {
case LOG_ERROR: report_error(msg, @args); break;
case RETURN_ZERO: break;
case THROW_RXML: RXML.run_error(msg, @args);
default: error(msg, @args);
}
return 0;
}
|
c7182e | 2010-10-29 | Martin Stjernholm | |
function cache_lookup =
lambda (mixed... args) {
return (cache_lookup = all_constants()["cache_lookup"]) (@args);
};
function cache_set =
lambda (mixed... args) {
return (cache_set = all_constants()["cache_set"]) (@args);
};
function cache_remove =
lambda (mixed... args) {
return (cache_remove = all_constants()["cache_remove"]) (@args);
};
|
7ab12f | 2001-08-16 | Per Hedbor | | object|array(object) parse_xml_tmpl( string ttag, string itag,
string xml_file,
string|void ident )
{
string tmpl;
array(mapping) data = ({});
Parser.HTML p = Parser.HTML();
object apply_template( mapping data )
{
Parser.HTML p = Parser.HTML();
p->ignore_tags( 1 );
p->_set_entity_callback( lambda( Parser.HTML p, string ent )
{
string enc = "none";
sscanf( ent, "&%s;", ent );
sscanf( ent, "%s:%s", ent, enc );
sscanf( ent, "_.%s", ent );
switch( enc )
{
case "none":
return data[ ent ];
case "int":
return (string)(int)data[ ent ];
case "float":
return (string)(float)data[ ent ];
case "string":
default:
return sprintf("%O", data[ent] );
}
} );
string code = p->feed( tmpl )->finish()->read();
|
950a8c | 2009-11-20 | Martin Stjernholm | | p = 0;
|
7ab12f | 2001-08-16 | Per Hedbor | | return compile_string( code, xml_file )();
};
p->xml_tag_syntax( 2 );
p->add_quote_tag ("!--", "", "--");
p->add_container( ttag,
lambda( Parser.HTML p, mapping m, string c )
{
tmpl = c;
} );
p->add_container( itag,
lambda( Parser.HTML p, mapping m, string c )
{
string current_tag;
mapping row = m;
void got_tag( Parser.HTML p, string c )
{
sscanf( c, "<%s>", c );
if( c[0] == '/' )
current_tag = 0;
else
current_tag = c;
};
void got_data( Parser.HTML p, string c )
{
if( current_tag )
if( row[current_tag] )
row[current_tag] += html_decode_string(c);
else
row[current_tag] = html_decode_string(c);
};
p = Parser.HTML( );
p->xml_tag_syntax( 2 );
p->add_quote_tag ("!--", "", "--")
->_set_tag_callback( got_tag )
->_set_data_callback( got_data )
->feed( c )
->finish();
data += ({ row });
|
950a8c | 2009-11-20 | Martin Stjernholm | | p = 0;
|
7ab12f | 2001-08-16 | Per Hedbor | | } )
->feed( Stdio.read_file( xml_file ) )
->finish();
|
950a8c | 2009-11-20 | Martin Stjernholm | | p = 0;
|
7ab12f | 2001-08-16 | Per Hedbor | | if( ident )
{
foreach( data, mapping m )
if( m->ident == ident )
return apply_template( m );
return 0;
}
return map( data, apply_template );
}
object|array(object) parse_box_xml( string xml_file, string|void ident )
{
return parse_xml_tmpl( "template", "box", xml_file, ident );
}
|
bc0fa0 | 2001-03-08 | Per Hedbor | | int ip_to_int(string ip)
{
int res;
foreach(((ip/".") + ({ "0", "0", "0" }))[..3], string num)
res = (res<<8) | (int)num;
return res;
}
|
a97287 | 2000-12-11 | Per Hedbor | |
|
e079b2 | 2000-12-11 | Per Hedbor | | string http_roxen_config_cookie(string from)
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
e079b2 | 2000-12-11 | Per Hedbor | | return "RoxenConfig="+http_encode_cookie(from)
+"; expires=" + http_date (3600*24*365*2 + time (1)) + "; path=/";
}
|
a97287 | 2000-12-11 | Per Hedbor | |
|
43c2ce | 2012-04-17 | Erik Dahl | | string http_roxen_id_cookie(void|string unique_id)
|
e079b2 | 2000-12-11 | Per Hedbor | | {
|
43c2ce | 2012-04-17 | Erik Dahl | | return "RoxenUserID=" + (unique_id || roxen->create_unique_id()) + "; expires=" +
|
d4f21c | 2001-01-06 | Martin Nilsson | | http_date (3600*24*365*2 + time (1)) + "; path=/";
|
e079b2 | 2000-12-11 | Per Hedbor | | }
|
a97287 | 2000-12-11 | Per Hedbor | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mapping(string:function(string, RequestID:string)) cookie_callbacks =
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | ([]);
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected class CookieChecker(string cookie)
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | {
string `()(string path, RequestID id)
{
|
dca270 | 2006-08-16 | Henrik Grubbström (Grubba) | | if (!id->real_cookies) {
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | id->init_cookies();
}
|
dca270 | 2006-08-16 | Henrik Grubbström (Grubba) | |
return id->real_cookies[cookie];
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | }
string _sprintf(int c)
{
|
7e4e99 | 2006-12-11 | Martin Stjernholm | | return c == 'O' && sprintf("CookieChecker(%O)", cookie);
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | }
}
|
4b8bb2 | 2005-12-05 | Henrik Grubbström (Grubba) | | function(string, RequestID:string) get_cookie_callback(string cookie)
|
25c6d0 | 2005-12-05 | Henrik Grubbström (Grubba) | | {
|
4b8bb2 | 2005-12-05 | Henrik Grubbström (Grubba) | | function(string, RequestID:string) cb = cookie_callbacks[cookie];
|
25c6d0 | 2005-12-05 | Henrik Grubbström (Grubba) | | if (cb) return cb;
|
fb6e79 | 2006-08-15 | Henrik Grubbström (Grubba) | | cb = CookieChecker(cookie);
|
25c6d0 | 2005-12-05 | Henrik Grubbström (Grubba) | | return cookie_callbacks[cookie] = cb;
}
|
a97287 | 2000-12-11 | Per Hedbor | |
|
14ca44 | 2009-02-19 | Jonas Wallden | | protected mapping(string:function(string, RequestID:string)) lang_callbacks = ([ ]);
protected class LangChecker(multiset(string) known_langs, string header,
string extra)
{
string `()(string path, RequestID id)
{
string proto_key = "";
switch (header) {
case "accept-language":
PrefLanguages pl = id->misc->pref_languages;
if (!pl) {
id->init_pref_languages();
pl = id->misc->pref_languages;
}
proto_key = filter(pl->get_languages(), known_langs) * ",";
break;
|
e7a518 | 2009-04-17 | Jonas Wallden | | case "cookie":
|
a689af | 2009-02-19 | Jonas Wallden | | if (!id->real_cookies)
id->init_cookies();
|
14ca44 | 2009-02-19 | Jonas Wallden | |
if (string cookie_val = id->real_cookies[extra]) {
if (known_langs[cookie_val])
proto_key = cookie_val;
}
break;
}
return proto_key;
}
string _sprintf(int c)
{
return (c == 'O') && sprintf("LangChecker(%O,%O,%O)",
indices(known_langs) * "+", header, extra);
}
}
function(string, RequestID:string) get_lang_vary_cb(multiset(string) known_langs,
string header, string extra)
{
string key = sort(indices(known_langs)) * "+" + "|" + header + "|" + extra;
return
lang_callbacks[key] ||
(lang_callbacks[key] = LangChecker(known_langs, header, extra));
}
|
3916ae | 2006-04-18 | Henrik Grubbström (Grubba) | |
string get_remoteaddr(string ignored, RequestID id)
{
return id->remoteaddr;
}
|
766443 | 2000-12-11 | Per Hedbor | |
string msectos(int t)
{
|
ecafe8 | 2000-12-18 | Martin Nilsson | | if(t<1000)
|
766443 | 2000-12-11 | Per Hedbor | | {
return sprintf("0.%02d sec", t/10);
|
ecafe8 | 2000-12-18 | Martin Nilsson | | } else if(t<6000) {
|
766443 | 2000-12-11 | Per Hedbor | | return sprintf("%d.%02d sec", t/1000, (t%1000 + 5) / 10);
|
ecafe8 | 2000-12-18 | Martin Nilsson | | } else if(t<3600000) {
|
766443 | 2000-12-11 | Per Hedbor | | return sprintf("%d:%02d m:s", t/60000, (t%60000)/1000);
}
return sprintf("%d:%02d h:m", t/3600000, (t%3600000)/60000);
}
string decode_mode(int m)
{
string s;
s="";
if(S_ISLNK(m)) s += "Symbolic link";
else if(S_ISREG(m)) s += "File";
else if(S_ISDIR(m)) s += "Dir";
else if(S_ISSOCK(m)) s += "Socket";
|
528349 | 2001-08-24 | Henrik Grubbström (Grubba) | | else if(S_ISFIFO(m)) s += "FIFO";
|
766443 | 2000-12-11 | Per Hedbor | | else if((m&0xf000)==0xd000) s+="Door";
|
528349 | 2001-08-24 | Henrik Grubbström (Grubba) | | else if(S_ISBLK(m)) s += "Device";
else if(S_ISCHR(m)) s += "Special";
|
766443 | 2000-12-11 | Per Hedbor | | else s+= "Unknown";
s+=", ";
if(S_ISREG(m) || S_ISDIR(m))
{
s+="<tt>";
if(m&S_IRUSR) s+="r"; else s+="-";
if(m&S_IWUSR) s+="w"; else s+="-";
if(m&S_IXUSR) s+="x"; else s+="-";
if(m&S_IRGRP) s+="r"; else s+="-";
if(m&S_IWGRP) s+="w"; else s+="-";
if(m&S_IXGRP) s+="x"; else s+="-";
if(m&S_IROTH) s+="r"; else s+="-";
if(m&S_IWOTH) s+="w"; else s+="-";
if(m&S_IXOTH) s+="x"; else s+="-";
s+="</tt>";
} else {
s+="--";
}
return s;
}
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | mapping(string:mixed) add_http_header(mapping(string:mixed) to,
string name, string value)
|
c9d28f | 2002-01-29 | Martin Stjernholm | |
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | |
|
c9d28f | 2002-01-29 | Martin Stjernholm | |
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | |
|
c9d28f | 2002-01-29 | Martin Stjernholm | |
|
766443 | 2000-12-11 | Per Hedbor | | {
if(to[name]) {
|
225442 | 2001-11-05 | Henrik Grubbström (Grubba) | | if(arrayp(to[name])) {
if (search(to[name], value) == -1)
to[name] += ({ value });
} else {
if (to[name] != value)
to[name] = ({ to[name], value });
}
|
766443 | 2000-12-11 | Per Hedbor | | }
else
to[name] = value;
return to;
}
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | mapping(string:mixed) merge_http_headers (mapping(string:mixed) a,
mapping(string:mixed) b)
{
mapping(string:mixed) res = a ^ b;
foreach (a & b; string name;) {
string|array(string) a_val = a[name], b_val = b[name];
if (a_val == b_val)
res[name] = a_val;
else {
if (!arrayp (a_val)) a_val = ({a_val});
if (!arrayp (b_val)) b_val = ({b_val});
res[name] = a_val | b_val;
}
}
return res;
}
|
477250 | 2001-08-17 | Per Hedbor | | int is_mysql_keyword( string name )
|
e079b2 | 2000-12-11 | Per Hedbor | | {
|
477250 | 2001-08-17 | Per Hedbor | | return (<
"action", "add", "aggregate", "all", "alter", "after", "and", "as",
"asc", "avg", "avg_row_length", "auto_increment", "between", "bigint",
"bit", "binary", "blob", "bool", "both", "by", "cascade", "case",
"char", "character", "change", "check", "checksum", "column",
"columns", "comment", "constraint", "create", "cross", "current_date",
"current_time", "current_timestamp", "data", "database", "databases",
"date", "datetime", "day", "day_hour", "day_minute", "day_second",
"dayofmonth", "dayofweek", "dayofyear", "dec", "decimal", "default",
"delayed", "delay_key_write", "delete", "desc", "describe", "distinct",
"distinctrow", "double", "drop", "end", "else", "escape", "escaped",
"enclosed", "enum", "explain", "exists", "fields", "file", "first",
"float", "float4", "float8", "flush", "foreign", "from", "for", "full",
"function", "global", "grant", "grants", "group", "having", "heap",
"high_priority", "hour", "hour_minute", "hour_second", "hosts",
"identified", "ignore", "in", "index", "infile", "inner", "insert",
"insert_id", "int", "integer", "interval", "int1", "int2", "int3",
"int4", "int8", "into", "if", "is", "isam", "join", "key", "keys",
"kill", "last_insert_id", "leading", "left", "length", "like",
"lines", "limit", "load", "local", "lock", "logs", "long", "longblob",
"longtext", "low_priority", "max", "max_rows", "match", "mediumblob",
"mediumtext", "mediumint", "middleint", "min_rows", "minute",
"minute_second", "modify", "month", "monthname", "myisam", "natural",
"numeric", "no", "not", "null", "on", "optimize", "option",
"optionally", "or", "order", "outer", "outfile", "pack_keys",
"partial", "password", "precision", "primary", "procedure", "process",
"processlist", "privileges", "read", "real", "references", "reload",
"regexp", "rename", "replace", "restrict", "returns", "revoke",
"rlike", "row", "rows", "second", "select", "set", "show", "shutdown",
"smallint", "soname", "sql_big_tables", "sql_big_selects",
"sql_low_priority_updates", "sql_log_off", "sql_log_update",
"sql_select_limit", "sql_small_result", "sql_big_result",
"sql_warnings", "straight_join", "starting", "status", "string",
"table", "tables", "temporary", "terminated", "text", "then", "time",
"timestamp", "tinyblob", "tinytext", "tinyint", "trailing", "to",
"type", "use", "using", "unique", "unlock", "unsigned", "update",
"usage", "values", "varchar", "variables", "varying", "varbinary",
"with", "write", "when", "where", "year", "year_month", "zerofill",
>)[ name ];
}
string short_name(string|Configuration long_name)
{
string id;
if( objectp( long_name ) )
{
if( !long_name->name )
error("Illegal first argument to short_name.\n"
"Expected Configuration object or string\n");
|
bc6f06 | 2001-08-23 | Jonas Wallden | | long_name = long_name->name;
|
477250 | 2001-08-17 | Per Hedbor | | }
id = Unicode.split_words_and_normalize( lower_case(long_name) )*"_";
if( strlen( id ) > 20 )
id = (id[..16]+"_"+hash(id)->digits(36))[..19];
if( !strlen( id ) )
id = hash(long_name)->digits(36);
if( is_mysql_keyword( id ) )
return "x"+id[..19];
while( strlen(string_to_utf8( id )) > 20 )
|
2f0d96 | 2005-02-08 | Martin Stjernholm | | id = id[..strlen(id)-2];
|
477250 | 2001-08-17 | Per Hedbor | |
return string_to_utf8( id );
|
e079b2 | 2000-12-11 | Per Hedbor | | }
|
a97287 | 2000-12-11 | Per Hedbor | |
|
e079b2 | 2000-12-11 | Per Hedbor | | int _match(string w, array (string) a)
{
if(!stringp(w))
return -1;
foreach(a, string q)
if(stringp(q) && strlen(q) && glob(q, w))
return 1;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
317147 | 2009-04-03 | Martin Stjernholm | | string canonicalize_http_header (string header)
{
return ([
"cache-control": "Cache-Control",
"connection": "Connection",
"date": "Date",
"pragma": "Pragma",
"trailer": "Trailer",
"transfer-encoding": "Transfer-Encoding",
"upgrade": "Upgrade",
"via": "Via",
"warning": "Warning",
"accept": "Accept",
"accept-charset": "Accept-Charset",
"accept-encoding": "Accept-Encoding",
"accept-language": "Accept-Language",
"authorization": "Authorization",
"expect": "Expect",
"from": "From",
"host": "Host",
"if-match": "If-Match",
"if-modified-since": "If-Modified-Since",
"if-none-match": "If-None-Match",
"if-range": "If-Range",
"if-unmodified-since": "If-Unmodified-Since",
"max-forwards": "Max-Forwards",
"proxy-authorization": "Proxy-Authorization",
"range": "Range",
"referer": "Referer",
"te": "TE",
"user-agent": "User-Agent",
"accept-ranges": "Accept-Ranges",
"age": "Age",
"etag": "ETag",
"location": "Location",
"proxy-authenticate": "Proxy-Authenticate",
"retry-after": "Retry-After",
"server": "Server",
"vary": "Vary",
"www-authenticate": "WWW-Authenticate",
"allow": "Allow",
"content-encoding": "Content-Encoding",
"content-language": "Content-Language",
"content-length": "Content-Length",
"content-location": "Content-Location",
"content-md5": "Content-MD5",
"content-range": "Content-Range",
"content-type": "Content-Type",
"expires": "Expires",
"last-modified": "Last-Modified",
|
80f42f | 2010-07-12 | Martin Stjernholm | |
"keep-alive": "Keep-Alive",
"cookie": "Cookie",
"cookie2": "Cookie2",
"set-cookie2": "Set-Cookie2",
|
317147 | 2009-04-03 | Martin Stjernholm | | ])[lower_case (header)];
}
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_low_answer( int status_code, string data )
|
a97287 | 2000-12-11 | Per Hedbor | | {
if(!data) data="";
|
16b6ec | 2004-03-03 | Martin Stjernholm | | HTTP_WERR("Return code "+status_code+" ("+data+")");
|
a97287 | 2000-12-11 | Per Hedbor | | return
([
|
16b6ec | 2004-03-03 | Martin Stjernholm | | "error" : status_code,
|
a97287 | 2000-12-11 | Per Hedbor | | "data" : data,
"len" : strlen( data ),
"type" : "text/html",
]);
}
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_status (int status_code,
void|string message, mixed... args)
|
e826c4 | 2004-05-05 | Martin Stjernholm | |
|
16b6ec | 2004-03-03 | Martin Stjernholm | |
{
if (message) {
if (sizeof (args)) message = sprintf (message, @args);
HTTP_WERR ("Return status " + status_code + " " + message);
return (["error": status_code, "rettext": message]);
}
else {
HTTP_WERR ("Return status " + status_code);
return (["error": status_code]);
}
}
mapping(string:mixed) http_method_not_allowed (
string allowed_methods, void|string message, mixed... args)
|
dd03b2 | 2006-04-20 | Henrik Grubbström (Grubba) | |
|
16b6ec | 2004-03-03 | Martin Stjernholm | | {
mapping(string:mixed) response =
http_status (Protocols.HTTP.HTTP_METHOD_INVALID, message, @args);
|
6092ad | 2009-05-29 | Martin Stjernholm | | response->extra_heads = (["Allow": allowed_methods]);
|
16b6ec | 2004-03-03 | Martin Stjernholm | | return response;
}
|
4d5c3c | 2001-03-12 | Johan Sundström | |
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_pipe_in_progress()
|
a97287 | 2000-12-11 | Per Hedbor | | {
HTTP_WERR("Pipe in progress");
return ([ "file":-1, "pipe":1, ]);
}
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_rxml_answer( string rxml, RequestID id,
void|Stdio.File file,
void|string type )
|
a97287 | 2000-12-11 | Per Hedbor | |
{
rxml =
([function(string,RequestID,Stdio.File:string)]id->conf->parse_rxml)
(rxml, id, file);
HTTP_WERR("RXML answer ("+(type||"text/html")+")");
return (["data":rxml,
"type":(type||"text/html"),
"stat":id->misc->defines[" _stat"],
"error":id->misc->defines[" _error"],
"rettext":id->misc->defines[" _rettext"],
"extra_heads":id->misc->defines[" _extra_heads"],
]);
}
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_try_again( float delay )
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
return ([ "try_again_later":delay ]);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected class Delayer
|
a97287 | 2000-12-11 | Per Hedbor | | {
RequestID id;
int resumed;
void resume( )
{
if( resumed )
return;
remove_call_out( resume );
resumed = 1;
if( !id )
error("Cannot resume request -- connection close\n");
roxenp()->handle( id->handle_request );
id = 0;
}
void create( RequestID _id, float max_delay )
{
id = _id;
if( max_delay && max_delay > 0.0 )
call_out( resume, max_delay );
}
}
array(object|mapping) http_try_resume( RequestID id, float|void max_delay )
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | |
{
Delayer delay = Delayer( id, max_delay );
|
96a8b6 | 2006-10-30 | Arjan van Staalduijnen | | return ({delay, ([ "try_again_later":delay ]) });
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_string_answer(string text, string|void type)
|
a97287 | 2000-12-11 | Per Hedbor | |
{
HTTP_WERR("String answer ("+(type||"text/html")+")");
return ([ "data":text, "type":(type||"text/html") ]);
}
|
16b6ec | 2004-03-03 | Martin Stjernholm | | mapping(string:mixed) http_file_answer(Stdio.File text,
string|void type, void|int len)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
HTTP_WERR("file answer ("+(type||"text/html")+")");
return ([ "file":text, "type":(type||"text/html"), "len":len ]);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected constant months = ({ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" });
protected constant days = ({ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" });
|
a97287 | 2000-12-11 | Per Hedbor | |
|
6fcfeb | 2006-09-05 | Stefan Wallström | | string log_date(int t) {
mapping(string:int) lt = localtime(t);
return(sprintf("%04d-%02d-%02d",
1900+lt->year,lt->mon+1, lt->mday));
}
string log_time(int t) {
mapping(string:int) lt = localtime(t);
return(sprintf("%02d:%02d:%02d",
lt->hour, lt->min, lt->sec));
}
|
f55ffd | 2006-10-13 | Martin Stjernholm | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int chd_lt;
protected string chd_lf;
|
f55ffd | 2006-10-13 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | string cern_http_date(int t)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
f55ffd | 2006-10-13 | Martin Stjernholm | | if( t == chd_lt )
return chd_lf;
|
a97287 | 2000-12-11 | Per Hedbor | |
string c;
mapping(string:int) lt = localtime(t);
|
35fcb7 | 2004-04-02 | Henrik Grubbström (Grubba) | | int tzh = lt->timezone/3600;
|
a97287 | 2000-12-11 | Per Hedbor | | if(tzh > 0)
c="-";
else {
tzh = -tzh;
c="+";
}
|
f55ffd | 2006-10-13 | Martin Stjernholm | |
c = sprintf("%02d/%s/%04d:%02d:%02d:%02d %s%02d00",
lt->mday, months[lt->mon], 1900+lt->year,
lt->hour, lt->min, lt->sec, c, tzh);
|
a97287 | 2000-12-11 | Per Hedbor | | chd_lt = t;
|
f55ffd | 2006-10-13 | Martin Stjernholm | |
chd_lf = c;
return c;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
1f5732 | 2008-05-07 | Martin Stjernholm | | constant http_status_messages = ([
100:"Continue",
101:"Switching Protocols",
102:"Processing",
200:"OK",
201:"Created",
202:"Accepted",
203:"Non-Authoritative Information",
204:"No Content",
205:"Reset Content",
206:"Partial Content",
207:"Multi-Status",
226:"IM Used",
300:"Multiple Choices",
301:"Moved Permanently",
302:"Found",
303:"See Other",
304:"Not Modified",
305:"Use Proxy",
307:"Temporary Redirect",
400:"Bad Request",
401:"Unauthorized",
402:"Payment Required",
403:"Forbidden",
404:"Not Found",
405:"Method Not Allowed",
406:"Not Acceptable",
407:"Proxy Authentication Required",
408:"Request Timeout",
409:"Conflict",
410:"Gone",
411:"Length Required",
412:"Precondition Failed",
413:"Request Entity Too Large",
414:"Request-URI Too Long",
415:"Unsupported Media Type",
416:"Requested Range Not Satisfiable",
417:"Expectation Failed",
418:"I'm a teapot",
420:"Server temporarily unavailable",
421:"Server shutting down at operator request",
422:"Unprocessable Entity",
423:"Locked",
424:"Failed Dependency",
500:"Internal Server Error.",
501:"Not Implemented",
502:"Bad Gateway",
503:"Service Unavailable",
504:"Gateway Timeout",
505:"HTTP Version Not Supported",
506:"Variant Also Negotiates",
507:"Insufficient Storage",
]);
|
e9811d | 2004-06-29 | Martin Stjernholm | | string http_status_message (int status_code)
{
|
1f5732 | 2008-05-07 | Martin Stjernholm | | return http_status_messages[status_code];
|
e9811d | 2004-06-29 | Martin Stjernholm | | }
|
a57bd9 | 2002-03-27 | Per Hedbor | | string http_date( mixed t )
|
a97287 | 2000-12-11 | Per Hedbor | |
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
a57bd9 | 2002-03-27 | Per Hedbor | | mapping(string:int) l = gmtime( (int)t );
|
a97287 | 2000-12-11 | Per Hedbor | | return(sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT",
days[l->wday], l->mday, months[l->mon], 1900+l->year,
l->hour, l->min, l->sec));
}
|
b14c2c | 2010-12-01 | Martin Stjernholm | | string parse_http_response (string response,
void|mapping(string:mixed) response_map,
void|mapping(string:string) headers,
void|int|string on_error)
{
array parsed = Roxen.HeaderParser()->feed (response);
if (!parsed) {
string err_msg = "Could not find http headers.\n";
if (stringp (on_error))
werror ("Error parsing http response%s: %s",
on_error != "" ? " " + on_error : "", err_msg);
else if (on_error == 0)
error (err_msg);
else if (on_error == 1)
RXML.run_error (err_msg);
return response;
}
mapping(string:string) hdr = parsed[2];
if (headers)
foreach (hdr; string name; string val)
headers[name] = val;
return low_parse_http_response (hdr, parsed[0], response_map, on_error);
}
string low_parse_http_response (mapping(string:string) headers,
string body,
void|mapping(string:mixed) response_map,
|
1a7867 | 2011-08-19 | Martin Jonsson | | void|int|string on_error,
void|int(0..1) ignore_unknown_ce)
|
b14c2c | 2010-12-01 | Martin Stjernholm | |
|
1a7867 | 2011-08-19 | Martin Jonsson | |
|
b14c2c | 2010-12-01 | Martin Stjernholm | | {
string err_msg;
proc: {
if (response_map) {
if (string lm = headers["last-modified"])
response_map->last_modified = parse_since (lm)[0];
}
string type, subtype, charset;
if (string ct = headers["content-type"]) {
MIME.Message m = MIME.Message ("", (["content-type": ct]), 0, 1);
type = m->type;
subtype = m->subtype;
charset = m->charset;
if (charset == "us-ascii" && !has_value (lower_case (ct), "us-ascii"))
charset = 0;
if (response_map)
response_map->type = type + "/" + subtype;
}
if (string ce = headers["content-encoding"]) {
|
8b41a0 | 2011-08-16 | Henrik Grubbström (Grubba) | | switch(lower_case(ce)) {
case "gzip":
{
Stdio.FakeFile f = Stdio.FakeFile(body, "rb");
Gz.File gz = Gz.File(f, "rb");
body = gz->read();
}
break;
case "deflate":
body = Gz.inflate(-15)->inflate(body);
break;
default:
|
1a7867 | 2011-08-19 | Martin Jonsson | | if (!ignore_unknown_ce) {
err_msg = sprintf("Content-Encoding %O not supported.\n", ce);
break proc;
}
|
8b41a0 | 2011-08-16 | Henrik Grubbström (Grubba) | | }
|
b14c2c | 2010-12-01 | Martin Stjernholm | | }
if (!charset) {
if (type == "text" ||
(type == "application" &&
(subtype == "xml" || has_prefix (subtype || "", "xml-")))) {
if (subtype == "html") {
Parser.HTML parser = Parser.HTML();
parser->case_insensitive_tag(1);
parser->lazy_entity_end(1);
parser->ignore_unknown(1);
parser->match_tag(0);
parser->add_quote_tag ("!--", "", "--");
parser->add_tag (
"meta",
lambda (Parser.HTML p, mapping m)
{
string val = m->content;
if(val && m["http-equiv"] &&
lower_case(m["http-equiv"]) == "content-type") {
MIME.Message m =
MIME.Message ("", (["content-type": val]), 0, 1);
charset = m->charset;
if (charset == "us-ascii" &&
!has_value (lower_case (val), "us-ascii"))
charset = 0;
throw (0);
}
});
if (mixed err = catch (parser->finish (body))) {
err_msg = describe_error (err);
break proc;
}
}
else if (subtype == "xml" || has_prefix (subtype || "", "xml-")) {
if (sscanf (body, "\xef\xbb\xbf%s", body))
charset = "utf-8";
else if (sscanf (body, "\xfe\xff%s", body))
charset = "utf-16";
|
749d9b | 2010-12-02 | Martin Stjernholm | | else if (sscanf (body, "\xff\xfe\x00\x00%s", body))
charset = "utf-32le";
|
b14c2c | 2010-12-01 | Martin Stjernholm | | else if (sscanf (body, "\xff\xfe%s", body))
charset = "utf-16le";
else if (sscanf (body, "\x00\x00\xfe\xff%s", body))
charset = "utf-32";
else if (sizeof(body) > 6 &&
has_prefix(body, "<?xml") &&
Parser.XML.isspace(body[5]) &&
sscanf(body, "<?%s?>", string hdr)) {
hdr += "?";
if (sscanf(lower_case(hdr), "%*sencoding=%s%*[\n\r\t ?]",
string xml_enc) == 3)
charset = xml_enc - "'" - "\"";
}
}
}
}
|
e925a4 | 2012-06-10 | Martin Stjernholm | |
|
b14c2c | 2010-12-01 | Martin Stjernholm | | if (charset) {
|
50aa16 | 2015-04-28 | Jonas Walldén | | Charset.Decoder decoder;
if (mixed err = catch (decoder = Charset.decoder (charset))) {
|
b14c2c | 2010-12-01 | Martin Stjernholm | | err_msg = sprintf ("Unrecognized charset %q.\n", charset);
break proc;
}
if (mixed err = catch (body = decoder->feed (body)->drain())) {
if (objectp (err) && err->is_charset_decode_error) {
err_msg = describe_error (err);
break proc;
}
throw (err);
}
}
if (response_map)
response_map->data = body;
return body;
}
if (stringp (on_error))
werror ("Error parsing http response%s: %s",
on_error != "" ? " " + on_error : "", err_msg);
else if (on_error == 0)
error (err_msg);
else if (on_error == 1)
RXML.run_error ("Error parsing http response: " + err_msg);
return body;
}
|
bd6c45 | 2003-07-07 | Martin Stjernholm | |
|
c6a8a5 | 2003-10-06 | Henrik Grubbström (Grubba) | | string iso8601_date_time(int ts, int|void ns)
|
bd6c45 | 2003-07-07 | Martin Stjernholm | | {
mapping(string:int) gmt = gmtime(ts);
|
c6a8a5 | 2003-10-06 | Henrik Grubbström (Grubba) | | if (zero_type(ns)) {
return sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
1900 + gmt->year, gmt->mon+1, gmt->mday,
gmt->hour, gmt->min, gmt->sec);
}
return sprintf("%04d-%02d-%02dT%02d:%02d:%02d.%09dZ",
1900 + gmt->year, gmt->mon+1, gmt->mday,
|
9db2ff | 2003-10-06 | Henrik Grubbström (Grubba) | | gmt->hour, gmt->min, gmt->sec, ns);
|
bd6c45 | 2003-07-07 | Martin Stjernholm | | }
|
b8fd89 | 2010-03-15 | Martin Stjernholm | | #if !defined (MODULE_DEBUG) || \
defined (ENABLE_INHERENTLY_BROKEN_HTTP_ENCODE_STRING_FUNCTION)
|
a97287 | 2000-12-11 | Per Hedbor | | string http_encode_string(string f)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
018af2 | 2004-10-11 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
return replace(f, ({ "\000", " ", "\t", "\n", "\r", "%", "'", "\"" }),
|
6ac223 | 2008-02-20 | Martin Stjernholm | | ({"%00", "%20", "%09", "%0A", "%0D", "%25", "%27", "%22"}));
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
b8fd89 | 2010-03-15 | Martin Stjernholm | | #endif
|
a97287 | 2000-12-11 | Per Hedbor | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | string http_encode_invalids (string f)
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
628a53 | 2008-03-14 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
a225df | 2007-02-07 | Martin Stjernholm | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | {
return replace (
|
6d6204 | 2005-08-16 | Martin Stjernholm | | string_to_utf8 (f), ({
|
628a53 | 2008-03-14 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",
|
c238bb | 2004-10-11 | Martin Stjernholm | | "\177",
|
628a53 | 2008-03-14 | Martin Stjernholm | |
" ", "\"",
"'",
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
"\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207",
"\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",
"\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
"\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237",
"\240", "\241", "\242", "\243", "\244", "\245", "\246", "\247",
"\250", "\251", "\252", "\253", "\254", "\255", "\256", "\257",
"\260", "\261", "\262", "\263", "\264", "\265", "\266", "\267",
"\270", "\271", "\272", "\273", "\274", "\275", "\276", "\277",
"\300", "\301", "\302", "\303", "\304", "\305", "\306", "\307",
"\310", "\311", "\312", "\313", "\314", "\315", "\316", "\317",
"\320", "\321", "\322", "\323", "\324", "\325", "\326", "\327",
"\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337",
"\340", "\341", "\342", "\343", "\344", "\345", "\346", "\347",
"\350", "\351", "\352", "\353", "\354", "\355", "\356", "\357",
"\360", "\361", "\362", "\363", "\364", "\365", "\366", "\367",
"\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }),
({
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",
|
018af2 | 2004-10-11 | Martin Stjernholm | | "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",
"%7F",
|
628a53 | 2008-03-14 | Martin Stjernholm | | "%20", "%22",
"%27",
|
6d6204 | 2005-08-16 | Martin Stjernholm | | "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",
|
6d6204 | 2005-08-16 | Martin Stjernholm | | "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",
"%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",
"%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",
"%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",
"%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",
"%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",
"%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",
"%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",
"%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",
"%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",
"%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",
"%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",
"%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }));
}
|
a97287 | 2000-12-11 | Per Hedbor | | string http_encode_cookie(string f)
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | return replace(
f, ({
"\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",
|
c238bb | 2004-10-11 | Martin Stjernholm | | "\177",
|
604092 | 2004-10-11 | Martin Stjernholm | | "=", ",", ";", "%",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }), ({
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",
|
018af2 | 2004-10-11 | Martin Stjernholm | | "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",
"%7F",
"%3D", "%2C", "%3B", "%25",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }));
|
a97287 | 2000-12-11 | Per Hedbor | | }
string http_encode_url (string f)
|
018af2 | 2004-10-11 | Martin Stjernholm | |
|
628a53 | 2008-03-14 | Martin Stjernholm | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
628a53 | 2008-03-14 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
c238bb | 2004-10-11 | Martin Stjernholm | |
|
a225df | 2007-02-07 | Martin Stjernholm | |
|
6d6204 | 2005-08-16 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
018af2 | 2004-10-11 | Martin Stjernholm | | return replace (
|
c238bb | 2004-10-11 | Martin Stjernholm | | string_to_utf8 (f), ({
|
628a53 | 2008-03-14 | Martin Stjernholm | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027",
"\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037",
|
c238bb | 2004-10-11 | Martin Stjernholm | | "\177",
|
628a53 | 2008-03-14 | Martin Stjernholm | |
":", "/", "?", "#", "[", "]", "@",
"!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "=",
" ", "\"", "%", "<", ">", "\\", "^", "`", "{", "|", "}",
|
c238bb | 2004-10-11 | Martin Stjernholm | |
"\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207",
"\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217",
"\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227",
"\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237",
"\240", "\241", "\242", "\243", "\244", "\245", "\246", "\247",
"\250", "\251", "\252", "\253", "\254", "\255", "\256", "\257",
"\260", "\261", "\262", "\263", "\264", "\265", "\266", "\267",
"\270", "\271", "\272", "\273", "\274", "\275", "\276", "\277",
"\300", "\301", "\302", "\303", "\304", "\305", "\306", "\307",
"\310", "\311", "\312", "\313", "\314", "\315", "\316", "\317",
"\320", "\321", "\322", "\323", "\324", "\325", "\326", "\327",
"\330", "\331", "\332", "\333", "\334", "\335", "\336", "\337",
"\340", "\341", "\342", "\343", "\344", "\345", "\346", "\347",
"\350", "\351", "\352", "\353", "\354", "\355", "\356", "\357",
"\360", "\361", "\362", "\363", "\364", "\365", "\366", "\367",
"\370", "\371", "\372", "\373", "\374", "\375", "\376", "\377",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }),
({
"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",
|
018af2 | 2004-10-11 | Martin Stjernholm | | "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",
"%7F",
|
628a53 | 2008-03-14 | Martin Stjernholm | | "%3A", "%2F", "%3F", "%23", "%5B", "%5D", "%40",
"%21","%24","%26","%27","%28","%29","%2A","%2B","%2C","%3B","%3D",
"%20","%22","%25","%3C","%3E","%5C","%5E","%60","%7B","%7C","%7D",
|
c238bb | 2004-10-11 | Martin Stjernholm | | "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",
|
c238bb | 2004-10-11 | Martin Stjernholm | | "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",
|
6ac223 | 2008-02-20 | Martin Stjernholm | | "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",
"%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",
"%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",
"%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",
"%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",
"%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",
"%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",
"%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",
"%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",
"%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",
"%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",
"%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",
"%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF",
|
018af2 | 2004-10-11 | Martin Stjernholm | | }));
}
|
c238bb | 2004-10-11 | Martin Stjernholm | |
|
0ac928 | 2001-09-13 | Martin Nilsson | | string correctly_http_encode_url(string f) {
|
c238bb | 2004-10-11 | Martin Stjernholm | | return http_encode_url (f);
|
a97287 | 2000-12-11 | Per Hedbor | | }
string add_pre_state( string url, multiset state )
|
5d225e | 2000-12-11 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
4f4938 | 2008-05-09 | Martin Stjernholm | | #ifdef MODULE_DEBUG
|
a97287 | 2000-12-11 | Per Hedbor | | if(!url)
error("URL needed for add_pre_state()\n");
|
4f4938 | 2008-05-09 | Martin Stjernholm | | #endif
|
a97287 | 2000-12-11 | Per Hedbor | | if(!state || !sizeof(state))
return url;
|
f7bc8a | 2001-07-21 | Martin Stjernholm | | string base;
if (sscanf (url, "%s://%[^/]%s", base, string host, url) == 3)
base += "://" + host;
else
base = "";
|
a97287 | 2000-12-11 | Per Hedbor | | if(strlen(url)>5 && (url[1] == '(' || url[1] == '<'))
|
f7bc8a | 2001-07-21 | Martin Stjernholm | | return base + url;
return base + "/(" + sort(indices(state)) * "," + ")" + url ;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
4f4938 | 2008-05-09 | Martin Stjernholm | | string make_absolute_url (string url, RequestID|void id,
multiset|void prestates, mapping|void variables)
|
563520 | 2002-09-10 | Martin Stjernholm | |
|
4f4938 | 2008-05-09 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
edcdb7 | 2001-05-21 | Martin Nilsson | |
|
4f4938 | 2008-05-09 | Martin Stjernholm | | url = fix_relative(url, id);
|
c1f6f1 | 2001-09-06 | Per Hedbor | |
|
f7bc8a | 2001-07-21 | Martin Stjernholm | |
|
4f4938 | 2008-05-09 | Martin Stjernholm | | if (has_prefix (url, "/")) {
|
edcdb7 | 2001-05-21 | Martin Nilsson | | if(id) {
|
216ebf | 2016-05-25 | Henrik Grubbström (Grubba) | | url = (string)Standards.URI(url, id->url_base());
|
f7bc8a | 2001-07-21 | Martin Stjernholm | | if (!prestates) prestates = id->prestate;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
edcdb7 | 2001-05-21 | Martin Nilsson | | else {
}
}
|
f7bc8a | 2001-07-21 | Martin Stjernholm | |
if(prestates && sizeof(prestates))
url = add_pre_state (url, prestates);
|
edcdb7 | 2001-05-21 | Martin Nilsson | |
|
a66902 | 2001-10-08 | Per Hedbor | | if( String.width( url )>8 && !has_value( url, "?" ) )
|
dc3798 | 2003-04-09 | Anders Johansson | | url += "?magic_roxen_automatic_charset_variable="+
|
a2cd48 | 2003-04-09 | Anders Johansson | | magic_charset_variable_value;
|
a66902 | 2001-10-08 | Per Hedbor | |
|
018af2 | 2004-10-11 | Martin Stjernholm | | url = http_encode_invalids (url);
|
563520 | 2002-09-10 | Martin Stjernholm | | if (variables) {
string concat_char = has_value (url, "?") ? "&" : "?";
foreach (indices (variables), string var) {
var = http_encode_url (var);
mixed val = variables[var];
if (stringp (val)) {
url += concat_char + var + "=" + http_encode_url (val);
concat_char = "&";
}
else if (arrayp (val))
foreach (val, mixed part)
if (stringp (part)) {
url += concat_char + var + "=" + http_encode_url (part);
concat_char = "&";
}
}
}
|
4f4938 | 2008-05-09 | Martin Stjernholm | | return url;
}
mapping http_redirect( string url, RequestID|void id, multiset|void prestates,
|
f407fe | 2009-02-10 | Martin Stjernholm | | mapping|void variables, void|int http_code)
|
4f4938 | 2008-05-09 | Martin Stjernholm | |
|
f407fe | 2009-02-10 | Martin Stjernholm | |
|
4f4938 | 2008-05-09 | Martin Stjernholm | | {
if(!url)
url = "";
url = make_absolute_url (url, id, prestates, variables);
|
470351 | 2016-06-29 | Henrik Grubbström (Grubba) | | url = http_encode_invalids(url);
|
2409bb | 2002-09-24 | Martin Stjernholm | | HTTP_WERR("Redirect -> "+url);
|
563520 | 2002-09-10 | Martin Stjernholm | |
|
f407fe | 2009-02-10 | Martin Stjernholm | | return http_status( http_code || Protocols.HTTP.HTTP_FOUND,
|
be1835 | 2002-11-19 | Stephen R. van den Berg | | "Redirect to " + html_encode_string(url))
|
2409bb | 2002-09-24 | Martin Stjernholm | | + ([ "extra_heads":([ "Location":url ]) ]);
|
a97287 | 2000-12-11 | Per Hedbor | | }
mapping http_stream(Stdio.File from)
{
return ([ "raw":1, "file":from, "len":-1, ]);
}
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | mapping(string:mixed) http_digest_required(mapping(string:string) challenge,
string|void message)
|
e9bb26 | 2005-02-25 | Henrik Grubbström (Grubba) | |
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | |
|
e9bb26 | 2005-02-25 | Henrik Grubbström (Grubba) | | {
if(!message)
message = "<h1>Authentication failed.\n</h1>";
HTTP_WERR(sprintf("Auth required (%O)", challenge));
string digest_challenge = "";
foreach(challenge; string key; string val) {
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | |
|
e9bb26 | 2005-02-25 | Henrik Grubbström (Grubba) | | digest_challenge += sprintf(" %s=%O", key, val);
}
return http_low_answer(401, message)
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | + ([ "extra_heads":([ "WWW-Authenticate":"Digest"+digest_challenge,]),]);
|
e9bb26 | 2005-02-25 | Henrik Grubbström (Grubba) | | }
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | mapping(string:mixed) http_auth_required(string realm, string|void message,
void|RequestID id)
|
a97287 | 2000-12-11 | Per Hedbor | |
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
fafdea | 2005-12-13 | Anders Johansson | | HTTP_WERR("Auth required ("+realm+")");
if (id) {
return id->conf->auth_failed_file( id, message )
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | + ([ "extra_heads":([ "WWW-Authenticate":
sprintf ("Basic realm=%O", realm)])]);
|
fafdea | 2005-12-13 | Anders Johansson | | }
|
a97287 | 2000-12-11 | Per Hedbor | | if(!message)
|
89c71f | 2004-05-12 | Martin Stjernholm | | message = "<h1>Authentication failed.</h1>";
return http_low_answer(401, message)
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | + ([ "extra_heads":([ "WWW-Authenticate":
sprintf ("Basic realm=%O", realm)])]);
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | mapping(string:mixed) http_proxy_auth_required(string realm,
void|string message)
|
a97287 | 2000-12-11 | Per Hedbor | | {
if(!message)
|
89c71f | 2004-05-12 | Martin Stjernholm | | message = "<h1>Proxy authentication failed.</h1>";
return http_low_answer(407, message)
|
8ee5a2 | 2008-06-18 | Martin Stjernholm | | + ([ "extra_heads":([ "Proxy-Authenticate":
sprintf ("Basic realm=%O", realm)])]);
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
685ff7 | 2000-12-11 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | string extract_query(string from)
{
if(!from) return "";
if(sscanf(from, "%*s?%s%*[ \t\n]", from))
return (from/"\r")[0];
return "";
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string mk_env_var_name(string name)
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | {
name = replace(name, " ", "_");
string res = "";
do {
string ok_part="";
sscanf(name, "%[A-Za-z0-9_]%s", ok_part, name);
res += ok_part;
if (sizeof(name)) {
res += "_";
name = name[1..];
}
} while (sizeof(name));
return res;
}
|
a97287 | 2000-12-11 | Per Hedbor | | mapping build_env_vars(string f, RequestID id, string path_info)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | |
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
string addr=id->remoteaddr || "Internal";
mapping(string:string) new = ([]);
if(id->query && strlen(id->query))
new->INDEX=id->query;
if(path_info && strlen(path_info))
{
if(path_info[0] != '/')
path_info = "/" + path_info;
if ( ([mapping(string:mixed)]id->misc)->path_info == path_info ) {
new["SCRIPT_NAME"]=id->not_query;
} else {
new["SCRIPT_NAME"]=
id->not_query[0..strlen([string]id->not_query)-strlen(path_info)-1];
}
new["PATH_INFO"]=path_info;
|
7897ae | 2006-08-04 | Eiichiro ITANI | |
string trailer = "";
|
a97287 | 2000-12-11 | Per Hedbor | | while(1)
{
|
7897ae | 2006-08-04 | Eiichiro ITANI | | string translated_base = id->conf->real_file(path_info, id);
if (translated_base)
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
7897ae | 2006-08-04 | Eiichiro ITANI | | new["PATH_TRANSLATED"] = combine_path_unix(translated_base, trailer);
|
a97287 | 2000-12-11 | Per Hedbor | | break;
}
array(string) tmp = path_info/"/" - ({""});
if(!sizeof(tmp))
break;
|
7897ae | 2006-08-04 | Eiichiro ITANI | | path_info = "/" + (tmp[..sizeof(tmp)-2]) * "/";
trailer = tmp[-1] + "/" + trailer;
|
a97287 | 2000-12-11 | Per Hedbor | | }
} else
new["SCRIPT_NAME"]=id->not_query;
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | |
RequestID tmpid = id;
RequestID previd;
while(tmpid->misc->orig) {
|
a97287 | 2000-12-11 | Per Hedbor | |
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | | tmpid = (previd = tmpid)->misc->orig;
}
|
57262b | 2006-11-13 | Jonas Wallden | | new["REQUEST_URI"] =
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | | tmpid->misc->redirected_raw_url || tmpid->raw_url;
if(tmpid->misc->is_redirected || previd) {
if (tmpid->misc->redirected_to) {
|
57262b | 2006-11-13 | Jonas Wallden | | new["REDIRECT_URL"] =
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | | Roxen.http_encode_invalids(tmpid->misc->redirected_to);
} else if (previd) {
|
57262b | 2006-11-13 | Jonas Wallden | | new["REDIRECT_URL"] = previd->raw_url;
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | | }
|
57262b | 2006-11-13 | Jonas Wallden | | new["REDIRECT_STATUS"] = "200";
|
91cf5b | 2006-11-08 | Henrik Grubbström (Grubba) | | }
|
a97287 | 2000-12-11 | Per Hedbor | |
array(string) tmps;
if(sizeof(tmps = tmpid->not_query/"/" - ({""})))
new["DOCUMENT_NAME"]=tmps[-1];
new["DOCUMENT_URI"]= tmpid->not_query;
Stat tmpi;
string real_file=tmpid->conf->real_file(tmpid->not_query||"", tmpid);
if (real_file) {
if(stringp(real_file)) {
if ((tmpi = file_stat(real_file)) &&
sizeof(tmpi)) {
new["LAST_MODIFIED"]=http_date(tmpi[3]);
}
} else {
report_error(sprintf("real_file(%O, %O) returned %O\n",
tmpid->not_query||"", tmpid, real_file));
}
}
if(string tmp = id->conf->real_file(new["SCRIPT_NAME"], id))
new["SCRIPT_FILENAME"] = tmp;
if(string tmp = id->conf->real_file("/", id))
new["DOCUMENT_ROOT"] = tmp;
if(!new["PATH_TRANSLATED"])
m_delete(new, "PATH_TRANSLATED");
else if(new["PATH_INFO"][-1] != '/' && new["PATH_TRANSLATED"][-1] == '/')
new["PATH_TRANSLATED"] =
new["PATH_TRANSLATED"][0..strlen(new["PATH_TRANSLATED"])-2];
mapping hdrs;
if ((hdrs = id->request_headers)) {
foreach(indices(hdrs) - ({ "authorization", "proxy-authorization",
"security-scheme", }), string h) {
string hh = "HTTP_" + replace(upper_case(h),
({ " ", "-", "\0", "=" }),
({ "_", "_", "", "_" }));
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new[mk_env_var_name(hh)] = replace(hdrs[h], ({ "\0" }), ({ "" }));
|
a97287 | 2000-12-11 | Per Hedbor | | }
if (!new["HTTP_HOST"]) {
if(objectp(id->my_fd) && id->my_fd->query_address(1))
new["HTTP_HOST"] = replace(id->my_fd->query_address(1)," ",":");
}
} else {
if(id->misc->host)
new["HTTP_HOST"]=id->misc->host;
else if(objectp(id->my_fd) && id->my_fd->query_address(1))
new["HTTP_HOST"]=replace(id->my_fd->query_address(1)," ",":");
if(id->misc["proxy-connection"])
new["HTTP_PROXY_CONNECTION"]=id->misc["proxy-connection"];
if(id->misc->accept) {
if (arrayp(id->misc->accept)) {
new["HTTP_ACCEPT"]=id->misc->accept*", ";
} else {
new["HTTP_ACCEPT"]=(string)id->misc->accept;
}
}
if(id->misc->cookies)
new["HTTP_COOKIE"] = id->misc->cookies;
if(sizeof(id->pragma))
new["HTTP_PRAGMA"]=indices(id->pragma)*", ";
if(stringp(id->misc->connection))
new["HTTP_CONNECTION"]=id->misc->connection;
new["HTTP_USER_AGENT"] = id->client*" ";
if(id->referer && sizeof(id->referer))
new["HTTP_REFERER"] = id->referer*"";
}
new["REMOTE_ADDR"]=addr;
if(roxen->quick_ip_to_host(addr) != addr)
new["REMOTE_HOST"]=roxen->quick_ip_to_host(addr);
catch {
if(id->my_fd)
new["REMOTE_PORT"] = (id->my_fd->query_address()/" ")[1];
};
if (id->query && sizeof(id->query)) {
new["QUERY_STRING"] = id->query;
}
if(id->realauth)
new["REMOTE_USER"] = (id->realauth / ":")[0];
|
076486 | 2001-03-16 | Per Hedbor | | if( User u = id->conf->authenticate( id ) )
new["ROXEN_AUTHENTICATED"] = u->name();
|
a97287 | 2000-12-11 | Per Hedbor | | if(id->data && strlen(id->data))
{
if(id->misc["content-type"])
new["CONTENT_TYPE"]=id->misc["content-type"];
else
new["CONTENT_TYPE"]="application/x-www-form-urlencoded";
new["CONTENT_LENGTH"]=(string)strlen(id->data);
}
if(id->query && strlen(id->query))
new["INDEX"]=id->query;
new["REQUEST_METHOD"]=id->method||"GET";
new["SERVER_PORT"] = id->my_fd?
((id->my_fd->query_address(1)||"foo unknown")/" ")[1]: "Internal";
|
9e38c7 | 2014-09-25 | Henrik Grubbström (Grubba) | |
foreach(new; string e; string v) {
if (has_prefix(v, "() {")) {
report_warning("ENV: Function definition in environment variable:\n"
"ENV: %O=%O\n",
e, v);
new[e] = " " + v;
}
}
|
a97287 | 2000-12-11 | Per Hedbor | | return new;
}
mapping build_roxen_env_vars(RequestID id)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
5d225e | 2000-12-11 | Martin Nilsson | |
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
mapping(string:string) new = ([]);
string tmp;
if(id->cookies->RoxenUserID)
new["ROXEN_USER_ID"]=id->cookies->RoxenUserID;
new["COOKIES"] = "";
foreach(indices(id->cookies), tmp)
{
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["COOKIE_"+mk_env_var_name(tmp)] = id->cookies[tmp];
new["COOKIES"]+= mk_env_var_name(tmp)+" ";
|
a97287 | 2000-12-11 | Per Hedbor | | }
foreach(indices(id->config), tmp)
{
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | tmp = mk_env_var_name(tmp);
new["CONFIG_"+tmp]="true";
|
a97287 | 2000-12-11 | Per Hedbor | | if(new["CONFIGS"])
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["CONFIGS"] += " " + tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | else
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["CONFIGS"] = tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | }
foreach(indices(id->variables), tmp)
{
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | string name = mk_env_var_name(tmp);
|
2e0591 | 2001-02-16 | Martin Stjernholm | | if (mixed value = id->variables[tmp])
if (!catch (value = (string) value) && (sizeof(value) < 8192)) {
new["QUERY_"+name] = replace(value,"\000"," ");
new["VAR_"+name] = replace(value,"\000","#");
}
|
a97287 | 2000-12-11 | Per Hedbor | | if(new["VARIABLES"])
new["VARIABLES"]+= " " + name;
else
new["VARIABLES"]= name;
}
foreach(indices(id->prestate), tmp)
{
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | tmp = mk_env_var_name(tmp);
new["PRESTATE_"+tmp]="true";
|
a97287 | 2000-12-11 | Per Hedbor | | if(new["PRESTATES"])
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["PRESTATES"] += " " + tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | else
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["PRESTATES"] = tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | }
foreach(indices(id->supports), tmp)
{
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | tmp = mk_env_var_name(tmp-",");
new["SUPPORTS_"+tmp]="true";
|
a97287 | 2000-12-11 | Per Hedbor | | if (new["SUPPORTS"])
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["SUPPORTS"] += " " + tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | else
|
47364d | 2003-02-10 | Henrik Grubbström (Grubba) | | new["SUPPORTS"] = tmp;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
9e38c7 | 2014-09-25 | Henrik Grubbström (Grubba) | |
foreach(new; string e; string v) {
if (has_prefix(v, "() {")) {
report_warning("ENV: Function definition in environment variable:\n"
"ENV: %O=%O\n",
e, v);
new[e] = " " + v;
}
}
|
a97287 | 2000-12-11 | Per Hedbor | | return new;
}
string strip_config(string from)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
sscanf(from, "/<%*s>%s", from);
return from;
}
string strip_prestate(string from)
|
e079b2 | 2000-12-11 | Per Hedbor | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
sscanf(from, "/(%*s)%s", from);
return from;
}
|
5d225e | 2000-12-11 | Martin Nilsson | | string parse_rxml(string what, RequestID id )
|
8c6e81 | 2001-06-18 | Martin Stjernholm | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
if(!objectp(id)) error("No id passed to parse_rxml\n");
|
5d225e | 2000-12-11 | Martin Nilsson | | return id->conf->parse_rxml( what, id );
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
37389a | 2001-06-21 | Martin Stjernholm | | array(string|RXML.PCode) compile_rxml (string what, RequestID id)
{
RXML.Parser parser = get_rxml_parser (id, 0, 1);
parser->write_end (what);
array(string|RXML.PCode) res = ({parser->eval(), parser->p_code});
|
e64fae | 2002-04-03 | Martin Stjernholm | | res[1]->finish();
|
187817 | 2001-07-09 | Martin Stjernholm | |
|
37389a | 2001-06-21 | Martin Stjernholm | | return res;
}
mixed eval_p_code (RXML.PCode p_code, RequestID id)
|
c5f5f0 | 2001-07-12 | Martin Stjernholm | |
|
f179cf | 2001-07-21 | Martin Stjernholm | |
|
37389a | 2001-06-21 | Martin Stjernholm | | {
return p_code->eval (p_code->new_context (id));
}
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | RXML.Parser get_rxml_parser (RequestID id, void|RXML.Type type, void|int make_p_code)
|
e64fae | 2002-04-03 | Martin Stjernholm | |
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | {
|
405064 | 2001-06-19 | Martin Stjernholm | | RXML.Parser parser = id->conf->rxml_tag_set->get_parser (
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | type || id->conf->default_content_type, id, make_p_code);
|
405064 | 2001-06-19 | Martin Stjernholm | | parser->recover_errors = 1;
|
735cfa | 2001-06-19 | Martin Stjernholm | | if (make_p_code) parser->p_code->recover_errors = 1;
|
405064 | 2001-06-19 | Martin Stjernholm | | return parser;
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int(0..0) return_zero() {return 0;}
|
8c6e81 | 2001-06-18 | Martin Stjernholm | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Parser.HTML xml_parser =
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | lambda() {
Parser.HTML p = Parser.HTML();
p->lazy_entity_end (1);
p->match_tag (0);
p->xml_tag_syntax (3);
p->add_quote_tag ("!--", return_zero, "--");
p->add_quote_tag ("![CDATA[", return_zero, "]]");
p->add_quote_tag ("?", return_zero, "?");
return p;
}();
Parser.HTML get_xml_parser()
{
return xml_parser->clone();
}
|
a97287 | 2000-12-11 | Per Hedbor | | constant iso88591
=([ " ": " ",
"¡": "¡",
"¢": "¢",
"£": "£",
"¤": "¤",
"¥": "¥",
"¦": "¦",
"§": "§",
"¨": "¨",
"©": "©",
"ª": "ª",
"«": "«",
"¬": "¬",
"­": "",
"®": "®",
"¯": "¯",
"°": "°",
"±": "±",
"²": "²",
"³": "³",
"´": "´",
"µ": "µ",
"¶": "¶",
"·": "·",
"¸": "¸",
"¹": "¹",
"º": "º",
"»": "»",
"¼": "¼",
"½": "½",
"¾": "¾",
"¿": "¿",
"À": "À",
"Á": "Á",
"Â": "Â",
"Ã": "Ã",
"Ä": "Ä",
"Å": "Å",
"Æ": "Æ",
"Ç": "Ç",
"È": "È",
"É": "É",
"Ê": "Ê",
"Ë": "Ë",
"Ì": "Ì",
"Í": "Í",
"Î": "Î",
"Ï": "Ï",
"Ð": "Ð",
"Ñ": "Ñ",
"Ò": "Ò",
"Ó": "Ó",
"Ô": "Ô",
"Õ": "Õ",
"Ö": "Ö",
"×": "×",
"Ø": "Ø",
"Ù": "Ù",
"Ú": "Ú",
"Û": "Û",
"Ü": "Ü",
"Ý": "Ý",
"Þ": "Þ",
"ß": "ß",
"à": "à",
"á": "á",
"â": "â",
"ã": "ã",
"ä": "ä",
"å": "å",
"æ": "æ",
"ç": "ç",
"è": "è",
"é": "é",
"ê": "ê",
"ë": "ë",
"ì": "ì",
"í": "í",
"î": "î",
"ï": "ï",
"ð": "ð",
"ñ": "ñ",
"ò": "ò",
"ó": "ó",
"ô": "ô",
"õ": "õ",
"ö": "ö",
"÷": "÷",
"ø": "ø",
"ù": "ù",
"ú": "ú",
"û": "û",
"ü": "ü",
"ý": "ý",
"þ": "þ",
"ÿ": "ÿ",
]);
constant international
=([ "Œ": "\x0152",
"œ": "\x0153",
"Š": "\x0160",
"š": "\x0161",
"Ÿ": "\x0178",
"ˆ": "\x02C6",
"˜": "\x02DC",
" ": "\x2002",
" ": "\x2003",
" ": "\x2009",
"‌": "\x200C",
"‍": "\x200D",
"‎": "\x200E",
"‏": "\x200F",
"–": "\x2013",
"—": "\x2014",
"‘": "\x2018",
"’": "\x2019",
"‚": "\x201A",
"“": "\x201C",
"”": "\x201D",
"„": "\x201E",
"†": "\x2020",
"‡": "\x2021",
"‰": "\x2030",
"‹": "\x2039",
"›": "\x203A",
"€": "\x20AC",
]);
constant symbols
=([ "ƒ": "\x0192",
"ϑ": "\x03D1",
"ϒ": "\x03D2",
"ϖ": "\x03D6",
"•": "\x2022",
"…": "\x2026",
"′": "\x2032",
"″": "\x2033",
"‾": "\x203E",
"⁄": "\x2044",
"℘": "\x2118",
"ℑ": "\x2111",
"ℜ": "\x211C",
"™": "\x2122",
"ℵ": "\x2135",
"←": "\x2190",
"↑": "\x2191",
"→": "\x2192",
"↓": "\x2193",
"↔": "\x2194",
"↵": "\x21B5",
"⇐": "\x21D0",
"⇑": "\x21D1",
"⇒": "\x21D2",
"⇓": "\x21D3",
"⇔": "\x21D4",
"∀": "\x2200",
"∂": "\x2202",
"∃": "\x2203",
"∅": "\x2205",
"∇": "\x2207",
"∈": "\x2208",
"∉": "\x2209",
"∋": "\x220B",
"∏": "\x220F",
"∑": "\x2211",
"−": "\x2212",
"∗": "\x2217",
"√": "\x221A",
"∝": "\x221D",
"∞": "\x221E",
"∠": "\x2220",
"∧": "\x2227",
"∨": "\x2228",
"∩": "\x2229",
"∪": "\x222A",
"∫": "\x222B",
"∴": "\x2234",
"∼": "\x223C",
"≅": "\x2245",
"≈": "\x2248",
"≠": "\x2260",
"≡": "\x2261",
"≤": "\x2264",
"≥": "\x2265",
"⊂": "\x2282",
"⊃": "\x2283",
"⊄": "\x2284",
"⊆": "\x2286",
"⊇": "\x2287",
"⊕": "\x2295",
"⊗": "\x2297",
"⊥": "\x22A5",
"⋅": "\x22C5",
"⌈": "\x2308",
"⌉": "\x2309",
"⌊": "\x230A",
"⌋": "\x230B",
"⟨": "\x2329",
"⟩": "\x232A",
"◊": "\x25CA",
"♠": "\x2660",
"♣": "\x2663",
"♥": "\x2665",
"♦": "\x2666",
]);
constant greek
= ([ "Α": "\x391",
"Β": "\x392",
"Γ": "\x393",
"Δ": "\x394",
"Ε": "\x395",
"Ζ": "\x396",
"Η": "\x397",
"Θ": "\x398",
"Ι": "\x399",
"Κ": "\x39A",
"Λ": "\x39B",
"Μ": "\x39C",
"Ν": "\x39D",
"Ξ": "\x39E",
"Ο": "\x39F",
"Π": "\x3A0",
"Ρ": "\x3A1",
"Σ": "\x3A3",
"Τ": "\x3A4",
"Υ": "\x3A5",
"Φ": "\x3A6",
"Χ": "\x3A7",
"Ψ": "\x3A8",
"Ω": "\x3A9",
"α": "\x3B1",
"β": "\x3B2",
"γ": "\x3B3",
"δ": "\x3B4",
"ε": "\x3B5",
"ζ": "\x3B6",
"η": "\x3B7",
"θ": "\x3B8",
"ι": "\x3B9",
"κ": "\x3BA",
"λ": "\x3BB",
"μ": "\x3BC",
"ν": "\x3BD",
"ξ": "\x3BE",
"ο": "\x3BF",
"π": "\x3C0",
"ρ": "\x3C1",
"ς": "\x3C2",
"σ": "\x3C3",
"τ": "\x3C4",
"υ": "\x3C5",
"φ": "\x3C6",
"χ": "\x3C7",
"ψ": "\x3C8",
"ω": "\x3C9",
]);
|
685ff7 | 2000-12-11 | Martin Nilsson | | constant replace_entities = indices( iso88591 ) +
indices( international ) +
indices( symbols ) +
indices( greek ) +
({"<",">","&",""","'",""",""","'","�"});
constant replace_values = values( iso88591 ) +
values( international ) +
values( symbols ) +
values( greek ) +
({"<",">","&","\"","\'","\"","\"","\'","\000"});
|
a97287 | 2000-12-11 | Per Hedbor | |
constant safe_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"/"";
constant empty_strings = ({""})*sizeof(safe_characters);
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
int(0..1) is_safe_string(string in)
|
a97287 | 2000-12-11 | Per Hedbor | | {
return strlen(in) && !strlen(replace(in, safe_characters, empty_strings));
}
string make_entity( string q )
{
return "&"+q+";";
}
|
8d3152 | 2002-10-16 | Jonas Wallden | | string make_tag_attributes(mapping(string:string) in,
void|int preserve_roxen_entities)
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
8d3152 | 2002-10-16 | Jonas Wallden | | if (!in || !sizeof(in))
return "";
string quote_fn(string text)
{
string out = "";
int pos = 0;
while ((pos = search(text, "&")) >= 0) {
if ((sscanf(text[pos..], "&%[^ <>;&];", string entity) == 1) &&
search(entity, ".") >= 0) {
out += html_encode_string(text[..pos - 1]) + "&" + entity + ";";
text = text[pos + strlen(entity) + 2..];
} else {
out += html_encode_string(text[..pos]);
text = text[pos + 1..];
}
}
return out + html_encode_string(text);
};
string res = "";
|
5ab06c | 2010-11-02 | Jonas Wallden | | array(string) sorted_attrs = sort(indices(in));
|
8d3152 | 2002-10-16 | Jonas Wallden | | if (preserve_roxen_entities) {
|
5ab06c | 2010-11-02 | Jonas Wallden | | foreach(sorted_attrs, string a)
|
8d3152 | 2002-10-16 | Jonas Wallden | | res += " " + a + "=\"" + quote_fn((string) in[a]) + "\"";
} else {
|
5ab06c | 2010-11-02 | Jonas Wallden | | foreach(sorted_attrs, string a)
|
8d3152 | 2002-10-16 | Jonas Wallden | | res += " " + a + "=\"" + html_encode_string((string) in[a]) + "\"";
}
|
a97287 | 2000-12-11 | Per Hedbor | | return res;
}
|
8d3152 | 2002-10-16 | Jonas Wallden | | string make_tag(string name, mapping(string:string) args, void|int xml,
void|int preserve_roxen_entities)
|
d8816e | 2002-10-22 | Jonas Wallden | |
|
8d3152 | 2002-10-16 | Jonas Wallden | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
8d3152 | 2002-10-16 | Jonas Wallden | | string attrs = make_tag_attributes(args, preserve_roxen_entities);
return "<" + name + attrs + (xml ? " /" : "" ) + ">";
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
8d3152 | 2002-10-16 | Jonas Wallden | | string make_container(string name, mapping(string:string) args, string content,
void|int preserve_roxen_entities)
|
d8816e | 2002-10-22 | Jonas Wallden | |
|
a97287 | 2000-12-11 | Per Hedbor | |
{
if(args["/"]=="/") m_delete(args, "/");
|
8d3152 | 2002-10-16 | Jonas Wallden | | return make_tag(name, args, 0,
preserve_roxen_entities) + content + "</" + name + ">";
|
a97287 | 2000-12-11 | Per Hedbor | | }
string add_config( string url, array config, multiset prestate )
{
if(!sizeof(config))
return url;
if(strlen(url)>5 && (url[1] == '(' || url[1] == '<'))
return url;
return "/<" + config * "," + ">" + add_pre_state(url, prestate);
}
string extension( string f, RequestID|void id)
{
string ext, key;
if(!f || !strlen(f)) return "";
if(!id || !(ext = [string]id->misc[key="_ext_"+f])) {
sscanf(reverse(f), "%s.%*s", ext);
if(!ext) ext = "";
else {
ext = lower_case(reverse(ext));
if(sizeof (ext) && (ext[-1] == '~' || ext[-1] == '#'))
ext = ext[..strlen(ext)-2];
}
if(id) id->misc[key]=ext;
}
return ext;
}
int(0..1) backup_extension( string f )
{
if(!strlen(f))
return 1;
return (f[-1] == '#' || f[-1] == '~' || f[0..1]==".#"
|| (f[-1] == 'd' && sscanf(f, "%*s.old"))
|| (f[-1] == 'k' && sscanf(f, "%*s.bak")));
}
array(string) win_drive_prefix(string path)
{
#ifdef __NT__
string prefix;
if (sscanf(path, "\\\\%s%*[\\/]%s", prefix, string path_end) == 3) {
return ({ "\\\\" + prefix, "/" + path_end });
} else if (sscanf(path, "%1s:%s", prefix, path) == 2) {
return ({ prefix + ":", path });
}
#endif
return ({ "", path });
}
string simplify_path(string file)
{
if(!strlen(file) || (!has_value(file, "./") && (file[-1] != '.') &&
!has_value (file, "//")))
return file;
|
4f4938 | 2008-05-09 | Martin Stjernholm | | int relative, got_slashdot_suffix;
|
a97287 | 2000-12-11 | Per Hedbor | |
[string prefix, file] = win_drive_prefix(file);
|
4f4938 | 2008-05-09 | Martin Stjernholm | | if (!has_prefix (file, "/"))
relative = 1;
|
a97287 | 2000-12-11 | Per Hedbor | |
|
4f4938 | 2008-05-09 | Martin Stjernholm | |
if (has_suffix (file, "/."))
got_slashdot_suffix = 1;
|
a97287 | 2000-12-11 | Per Hedbor | |
file=combine_path("/", file);
|
4f4938 | 2008-05-09 | Martin Stjernholm | | if(got_slashdot_suffix) file += "/.";
if(relative) return prefix + file[1..];
|
a97287 | 2000-12-11 | Per Hedbor | |
return prefix + file;
}
string short_date(int timestamp)
{
int date = time(1);
if(ctime(date)[20..23] != ctime(timestamp)[20..23])
return ctime(timestamp)[4..9] +" "+ ctime(timestamp)[20..23];
return ctime(timestamp)[4..9] +" "+ ctime(timestamp)[11..15];
}
string int2roman(int m)
{
string res="";
if (m>10000000||m<0) return "que";
while (m>999) { res+="M"; m-=1000; }
if (m>899) { res+="CM"; m-=900; }
else if (m>499) { res+="D"; m-=500; }
else if (m>399) { res+="CD"; m-=400; }
while (m>99) { res+="C"; m-=100; }
if (m>89) { res+="XC"; m-=90; }
else if (m>49) { res+="L"; m-=50; }
else if (m>39) { res+="XL"; m-=40; }
while (m>9) { res+="X"; m-=10; }
if (m>8) return res+"IX";
else if (m>4) { res+="V"; m-=5; }
else if (m>3) return res+"IV";
while (m) { res+="I"; m--; }
return res;
}
string number2string(int n, mapping m, array|function names)
{
string s;
switch (m->type)
{
case "string":
if (functionp(names)) {
s=([function(int:string)]names)(n);
break;
}
if (n<0 || n>=sizeof(names))
s="";
else
s=([array(string)]names)[n];
break;
case "roman":
s=int2roman(n);
break;
default:
return (string)n;
}
switch(m["case"]) {
case "lower": return lower_case(s);
case "upper": return upper_case(s);
case "capitalize": return capitalize(s);
}
#ifdef old_rxml_compat
if (m->lower) return lower_case(s);
if (m->upper) return upper_case(s);
if (m->cap||m->capitalize) return capitalize(s);
#endif
return s;
}
string image_from_type( string t )
{
if(t)
{
sscanf(t, "%s/", t);
switch(t)
{
case "audio":
case "sound":
return "internal-gopher-sound";
case "image":
return "internal-gopher-image";
case "application":
return "internal-gopher-binary";
case "text":
return "internal-gopher-text";
}
}
return "internal-gopher-unknown";
}
|
8d32cd | 2009-12-02 | Martin Stjernholm | | protected constant size_suffix =
({ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" });
|
2778c3 | 2009-12-04 | Martin Stjernholm | | string sizetostring( int|float size )
|
a97287 | 2000-12-11 | Per Hedbor | |
|
8d32cd | 2009-12-02 | Martin Stjernholm | |
|
8ff672 | 2001-08-29 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
|
8d32cd | 2009-12-02 | Martin Stjernholm | | int neg = size < 0;
|
2778c3 | 2009-12-04 | Martin Stjernholm | | int|float abs_size = abs (size);
if (abs_size < 1024) {
if (intp (size))
return size + " " + size_suffix[0];
return size < 10.0 ?
sprintf ("%.2f %s", size, size_suffix[0]) :
sprintf ("%.0f %s", size, size_suffix[0]);
}
|
8d32cd | 2009-12-02 | Martin Stjernholm | |
|
2778c3 | 2009-12-04 | Martin Stjernholm | | float s = (float) abs_size;
|
8d32cd | 2009-12-02 | Martin Stjernholm | | size=0;
|
2778c3 | 2009-12-04 | Martin Stjernholm | | while( s >= 1024.0 )
|
a97287 | 2000-12-11 | Per Hedbor | | {
s /= 1024.0;
|
2778c3 | 2009-12-04 | Martin Stjernholm | | if (++size == sizeof (size_suffix) - 1) break;
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
8d32cd | 2009-12-02 | Martin Stjernholm | | if (neg) s = -s;
return sprintf("%.1f %s", s, size_suffix[ size ]);
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
5877e5 | 2008-11-06 | Martin Stjernholm | | string format_hrtime (int hrtime, void|int pad)
{
if (hrtime < 1000000)
return sprintf (pad ? "%7.3f ms" : "%.3f ms", hrtime / 1e3);
else if (hrtime < 60 * 1000000)
return sprintf (pad ? "%8.3f s" : "%.3f s", hrtime / 1e6);
else if (hrtime < 60 * 60 * 1000000)
return sprintf (pad ? "%3d:%02d min" : "%d:%02d min",
hrtime / (60 * 1000000), (hrtime / 1000000) % 60);
else
return sprintf (pad ? "%4d:%02d:%02d" : "%d:%02d:%02d",
hrtime / (60 * 60 * 1000000),
(hrtime / (60 * 1000000)) % 60,
(hrtime / 1000000) % 60);
}
|
a97287 | 2000-12-11 | Per Hedbor | | string html_decode_string(LocaleString str)
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | {
return replace((string)str, replace_entities, replace_values);
}
string html_encode_tag_value(LocaleString str)
{
return "\"" + replace((string)str, ({"&", "\"", "<"}), ({"&", """, "<"})) + "\"";
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string my_sprintf(int prefix, string f, int arg)
|
dd03b2 | 2006-04-20 | Henrik Grubbström (Grubba) | |
{
if(!prefix && sscanf(f, "%%%*d%s", string format) == 2)
f = "%" + format;
return sprintf(f, arg);
}
|
8ae599 | 2003-07-11 | Anders Johansson | | string strftime(string fmt, int t,
void|string lang, void|function language, void|RequestID id)
|
a97287 | 2000-12-11 | Per Hedbor | |
{
if(!sizeof(fmt)) return "";
mapping lt = localtime(t);
fmt=replace(fmt, "%%", "\0");
array(string) a = fmt/"%";
string res = a[0];
|
8ae599 | 2003-07-11 | Anders Johansson | | mapping(string:string) m = (["type":"string"]);
|
eedca7 | 2004-07-02 | Marcus Wellhardh | |
|
a97287 | 2000-12-11 | Per Hedbor | | foreach(a[1..], string key) {
|
c4f986 | 2015-05-04 | Martin Karlgren | | m_delete (m, "case");
|
eedca7 | 2004-07-02 | Marcus Wellhardh | | int(0..1) prefix = 1;
|
13573e | 2013-03-22 | Henrik Grubbström (Grubba) | | int(0..1) alternative_numbers = 0;
int(0..1) alternative_form = 0;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | while (sizeof(key)) {
switch(key[0]) {
|
6659d8 | 2015-04-22 | Martin Karlgren | | case '!':
case '-':
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | prefix = 0;
key = key[1..];
continue;
|
6659d8 | 2015-04-22 | Martin Karlgren | | case '^':
m->case = "upper";
key = key[1..];
continue;
case '~':
m->case = "capitalize";
key = key[1..];
continue;
|
13573e | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'E':
alternative_form = 1;
key = key[1..];
continue;
case 'O':
alternative_numbers = 1;
key = key[1..];
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | continue;
case 'a':
if (language)
res += number2string(lt->wday+1,m,language(lang,"short_day",id));
else
res += ({ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" })[lt->wday];
break;
case 'A':
if (language)
res += number2string(lt->wday+1,m,language(lang,"day",id));
else
res += ({ "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" })[lt->wday];
break;
case 'b':
case 'h':
if (language)
res += number2string(lt->mon+1,m,language(lang,"short_month",id));
else
res += ({ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })[lt->mon];
break;
case 'B':
|
70c91e | 2013-03-22 | Henrik Grubbström (Grubba) | | if (language) {
if (alternative_form) {
res += number2string(lt->mon+1,m,language(lang,"numbered_month",id));
} else {
res += number2string(lt->mon+1,m,language(lang,"month",id));
}
} else
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | res += ({ "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" })[lt->mon];
break;
case 'c':
|
cdfb94 | 2013-03-22 | Henrik Grubbström (Grubba) | |
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | res += strftime(sprintf("%%a %%b %02d %02d:%02d:%02d %04d",
lt->mday, lt->hour, lt->min, lt->sec, 1900 + lt->year), t);
break;
case 'C':
res += my_sprintf(prefix, "%02d", 19 + lt->year/100);
break;
case 'd':
res += my_sprintf(prefix, "%02d", lt->mday);
break;
case 'D':
res += strftime("%m/%d/%y", t);
break;
case 'e':
res += my_sprintf(prefix, "%2d", lt->mday);
break;
|
5e7726 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'F':
res += sprintf("%04d-%02d-%02d",
1900 + lt->year, lt->mon + 1, lt->mday);
break;
case 'G':
{
int wday = (lt->wday + 1)%7;
if ((wday - lt->yday) >= 4) {
res += my_sprintf(prefix, "%04d", 1899 + lt->year);
} else if ((lt->mon == 11) && ((lt->mday - wday) >= 29)) {
res += my_sprintf(prefix, "%04d", 1901 + lt->year);
} else {
res += my_sprintf(prefix, "%04d", 1900 + lt->year);
}
}
break;
case 'g':
{
int wday = (lt->wday + 1)%7;
if ((wday - lt->yday) >= 4) {
res += my_sprintf(prefix, "%02d", (99 + lt->year) % 100);
} else if ((lt->mon == 11) && ((lt->mday - wday) >= 29)) {
res += my_sprintf(prefix, "%02d", (1 + lt->year) % 100);
} else {
res += my_sprintf(prefix, "%02d", (lt->year) % 100);
}
}
break;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'H':
res += my_sprintf(prefix, "%02d", lt->hour);
break;
case 'I':
res += my_sprintf(prefix, "%02d", 1 + (lt->hour + 11)%12);
break;
case 'j':
res += my_sprintf(prefix, "%03d", lt->yday);
break;
case 'k':
res += my_sprintf(prefix, "%2d", lt->hour);
break;
case 'l':
res += my_sprintf(prefix, "%2d", 1 + (lt->hour + 11)%12);
break;
case 'm':
res += my_sprintf(prefix, "%02d", lt->mon + 1);
break;
case 'M':
res += my_sprintf(prefix, "%02d", lt->min);
break;
case 'n':
res += "\n";
break;
case 'p':
res += lt->hour<12 ? "a.m." : "p.m.";
break;
case 'P':
res += lt->hour<12 ? "am" : "pm";
break;
case 'r':
|
7032b3 | 2013-03-22 | Henrik Grubbström (Grubba) | | res += strftime("%I:%M:%S %p", t);
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | break;
case 'R':
res += sprintf("%02d:%02d", lt->hour, lt->min);
break;
|
5e7726 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 's':
res += my_sprintf(prefix, "%d", t);
break;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'S':
res += my_sprintf(prefix, "%02d", lt->sec);
break;
case 't':
res += "\t";
break;
case 'T':
|
cdfb94 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'X':
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | res += sprintf("%02d:%02d:%02d", lt->hour, lt->min, lt->sec);
break;
|
739b1d | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'u':
res += my_sprintf(prefix, "%d", 1 + ((lt->wday + 6) % 7));
break;
case 'U':
res += my_sprintf(prefix, "%02d", 1 + (lt->yday - lt->wday)/ 7);
break;
case 'V':
res += my_sprintf(prefix, "%02d", Calendar.ISO.Second(t)->week_no());
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | break;
case 'w':
res += my_sprintf(prefix, "%d", lt->wday);
break;
|
739b1d | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'W':
res += my_sprintf(prefix, "%02d", ((lt->yday+(5+lt->wday)%7)/7));
break;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'x':
|
cdfb94 | 2013-03-22 | Henrik Grubbström (Grubba) | |
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | res += strftime("%a %b %d %Y", t);
break;
case 'y':
res += my_sprintf(prefix, "%02d", lt->year % 100);
break;
case 'Y':
res += my_sprintf(prefix, "%04d", 1900 + lt->year);
break;
|
5e7726 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'z':
{
int minutes = lt->timezone/60;
int hours = minutes/60;
minutes -= hours * 60;
res += my_sprintf(prefix, "%+05d%", hours*100 + minutes);
}
break;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | case 'Z':
|
ecafe8 | 2000-12-18 | Martin Nilsson | |
|
cdfb94 | 2013-03-22 | Henrik Grubbström (Grubba) | | break;
|
0ada17 | 2013-03-22 | Henrik Grubbström (Grubba) | | }
res+=key[1..];
break;
|
a97287 | 2000-12-11 | Per Hedbor | | }
}
return replace(res, "\0", "%");
}
RoxenModule get_module (string modname)
{
string cname, mname;
int mid = 0;
if (sscanf (modname, "%s/%s", cname, mname) != 2 ||
!sizeof (cname) || !sizeof(mname)) return 0;
sscanf (mname, "%s#%d", mname, mid);
if (Configuration conf = roxen->get_configuration (cname))
if (mapping moddata = conf->modules[mname])
return moddata->copies[mid];
return 0;
}
string get_modname (RoxenModule module)
{
|
4246ca | 2001-06-28 | Martin Stjernholm | | return module && module->module_identifier();
|
a97287 | 2000-12-11 | Per Hedbor | | }
string get_modfullname (RoxenModule module)
{
if (module) {
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | string|mapping(string:string)|Locale.DeferredLocale name = 0;
|
a97287 | 2000-12-11 | Per Hedbor | | if (module->query)
catch {
mixed res = module->query ("_name");
if (res) name = (string) res;
};
if (!(name && sizeof (name)) && module->query_name)
name = module->query_name();
|
61c757 | 2010-03-22 | Martin Stjernholm | | if (!(name && sizeof (name))) {
|
a97287 | 2000-12-11 | Per Hedbor | | name = [string]module->register_module()[1];
|
61c757 | 2010-03-22 | Martin Stjernholm | | sscanf (module->module_local_id(), "%*s#%d", int mod_copy);
if (mod_copy) name += " # " + mod_copy;
}
|
a97287 | 2000-12-11 | Per Hedbor | | if (mappingp (name))
name = name->standard;
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | return (string) name;
|
a97287 | 2000-12-11 | Per Hedbor | | }
else return 0;
}
|
a2e9b1 | 2014-08-15 | Henrik Grubbström (Grubba) | | protected constant xml_invalid_mappings = ([
|
7f1231 | 2010-06-22 | Marcus Agehall | | "\0":"\22000", "\1":"\22001",
"\2":"\22002", "\3":"\22003",
"\4":"\22004", "\5":"\22005",
"\6":"\22006", "\7":"\22007",
"\b":"\22010", "\13":"\22013",
"\14":"\22014", "\16":"\22016",
"\17":"\22017", "\20":"\22020",
"\21":"\22021", "\22":"\22022",
"\23":"\22023", "\24":"\22024",
"\25":"\22025", "\26":"\22026",
"\27":"\22027", "\30":"\22030",
"\31":"\22031", "\32":"\22032",
"\33":"\22033", "\34":"\22034",
"\35":"\22035", "\36":"\22036",
"\37":"\22037", "\177":"\22041",
"\xFFFE":"", "\xFFFF":""
]);
|
266e2b | 2007-10-17 | Henrik Grubbström (Grubba) | |
string encode_xml_invalids(string s)
{
|
7f1231 | 2010-06-22 | Marcus Agehall | | return replace(s, xml_invalid_mappings);
|
266e2b | 2007-10-17 | Henrik Grubbström (Grubba) | | }
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected string low_roxen_encode(string val, string encoding)
|
a97287 | 2000-12-11 | Per Hedbor | | {
switch (encoding) {
case "":
case "none":
return val;
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | | case "utf8":
case "utf-8":
return string_to_utf8(val);
|
15f386 | 2012-11-14 | Stefan Wallström | | case "-utf8":
case "-utf-8":
if( catch {
return utf8_to_string(val);
})
RXML.run_error("Cannot decode utf-8 string. Bad data.\n");
|
40faf0 | 2008-11-05 | Stefan Wallström | | case "utf16":
case "utf16be":
|
50aa16 | 2015-04-28 | Jonas Walldén | | return Charset.encoder("utf16be")->feed(val)->drain();
|
40faf0 | 2008-11-05 | Stefan Wallström | |
case "utf16le":
|
50aa16 | 2015-04-28 | Jonas Walldén | | return Charset.encoder("utf16le")->feed(val)->drain();
|
40faf0 | 2008-11-05 | Stefan Wallström | |
case "hex":
if(String.width(val) > 8)
RXML.run_error( "Cannot hex encode wide characters.\n" );
|
d3764f | 2008-11-05 | Martin Stjernholm | | return String.string2hex(val);
|
40faf0 | 2008-11-05 | Stefan Wallström | |
|
15f386 | 2012-11-14 | Stefan Wallström | | case "-hex":
if( catch {
return String.hex2string(val);
})
RXML.run_error("Cannot decode hex string. Bad data.\n");
|
1c1f73 | 2016-03-11 | Martin Karlgren | | case "base64":
case "base-64":
case "b64":
return MIME.encode_base64(val);
case "-base64":
case "-base-64":
case "-b64":
if( catch {
return MIME.decode_base64(val);
})
RXML.run_error("Cannot decode base64 string. Bad data.\n");
case "base64url":
case "base-64-url":
case "b64url":
#if constant (MIME.encode_base64url)
return MIME.encode_base64url(val);
#else
return replace (MIME.encode_base64 (val, 1),
([ "=": "",
"+": "-",
"/": "_" ]));
#endif
case "-base64url":
case "-base-64-url":
case "-b64url":
if( catch {
#if constant (MIME.decode_base64url)
return MIME.decode_base64url(val);
#else
string data = replace (val, ([ "-": "+",
"_": "/",
"=": "" ]));
data = (data + ("=" * (4-sizeof (data) % 4)));
return MIME.decode_base64 (data);
#endif
})
RXML.run_error("Cannot decode base64 string. Bad data.\n");
|
e04ef0 | 2011-07-06 | Jonas Wallden | | case "md5":
case "sha1":
case "sha256":
if (String.width(val) > 8)
|
a1d2e5 | 2011-07-06 | Jonas Wallden | | RXML.run_error("Cannot hash wide characters.\n");
|
e04ef0 | 2011-07-06 | Jonas Wallden | | return Crypto[upper_case(encoding)]->hash(val);
|
37edee | 2005-12-09 | Henrik Grubbström (Grubba) | | case "quotedprintable":
case "quoted-printable":
case "qp":
return MIME.encode_qp(val);
|
a97287 | 2000-12-11 | Per Hedbor | | case "http":
|
f49131 | 2004-10-11 | Martin Stjernholm | | return http_encode_invalids (val);
|
a97287 | 2000-12-11 | Per Hedbor | |
case "cookie":
return http_encode_cookie (val);
case "url":
return http_encode_url (val);
|
258aed | 2016-03-18 | Anders Johansson | | case "-url":
return http_decode_string (val);
|
0ac928 | 2001-09-13 | Martin Nilsson | | case "wml-url":
|
b86553 | 2006-01-11 | Martin Stjernholm | |
|
08f314 | 2008-11-05 | Martin Stjernholm | | return http_encode_url(val);
|
0ac928 | 2001-09-13 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | case "html":
return html_encode_string (val);
|
fbcff6 | 2012-11-16 | Jonas Wallden | | case "-html":
return RXML.TXml()->decode_charrefs(val);
|
a97287 | 2000-12-11 | Per Hedbor | |
|
266e2b | 2007-10-17 | Henrik Grubbström (Grubba) | | case "invalids":
case "xmlinvalids":
case "xml-invalids":
return encode_xml_invalids(val);
|
0ac928 | 2001-09-13 | Martin Nilsson | | case "wml":
return replace(html_encode_string(val), "$", "$$");
|
a97287 | 2000-12-11 | Per Hedbor | | case "dtag":
return replace (val, "\"", "\"'\"'\"");
case "stag":
return replace(val, "'", "'\"'\"'");
case "pike":
return replace (val,
({ "\"", "\\", "\n" }),
({ "\\\"", "\\\\", "\\n" }));
|
51ed75 | 2011-09-13 | Henrik Grubbström (Grubba) | | case "json":
|
75967e | 2011-09-21 | Martin Stjernholm | | #if constant (Standards.JSON.escape_string)
return Standards.JSON.escape_string (val);
#else
|
51ed75 | 2011-09-13 | Henrik Grubbström (Grubba) | | return replace(val,
({ "\"", "\\", "/", "\b",
|
21bb53 | 2011-09-13 | Henrik Grubbström (Grubba) | | "\f", "\n", "\r", "\t",
"\u2028", "\u2029", }),
|
51ed75 | 2011-09-13 | Henrik Grubbström (Grubba) | | ({ "\\\"", "\\\\", "\\/", "\\b",
|
21bb53 | 2011-09-13 | Henrik Grubbström (Grubba) | | "\\f", "\\n", "\\r", "\\t",
"\\u2028", "\\u2029", }));
|
75967e | 2011-09-21 | Martin Stjernholm | | #endif
|
51ed75 | 2011-09-13 | Henrik Grubbström (Grubba) | |
|
a97287 | 2000-12-11 | Per Hedbor | | case "js":
case "javascript":
return replace (val,
|
0dc2ae | 2011-07-05 | Martin Stjernholm | | ({ "\b", "\014", "\n", "\r", "\t", "\\",
"'", "\"",
|
239de0 | 2011-09-21 | Martin Stjernholm | | "\u2028", "\u2029",
|
0dc2ae | 2011-07-05 | Martin Stjernholm | | "</", "<!--"}),
|
a97287 | 2000-12-11 | Per Hedbor | | ({ "\\b", "\\f", "\\n", "\\r", "\\t", "\\\\",
|
0dc2ae | 2011-07-05 | Martin Stjernholm | | "\\'", "\\\"",
|
239de0 | 2011-09-21 | Martin Stjernholm | | "\\u2028", "\\u2029",
|
0dc2ae | 2011-07-05 | Martin Stjernholm | | "<\\/", "<\\!--" }));
|
a97287 | 2000-12-11 | Per Hedbor | |
case "mysql":
|
668b36 | 2010-05-17 | Henrik Grubbström (Grubba) | |
|
a97287 | 2000-12-11 | Per Hedbor | | return replace (val,
({ "\"", "'", "\\" }),
|
668b36 | 2010-05-17 | Henrik Grubbström (Grubba) | | ({ "\\\"" , "''", "\\\\" }) );
|
a97287 | 2000-12-11 | Per Hedbor | |
case "sql":
case "oracle":
return replace (val, "'", "''");
|
c5bd64 | 2011-02-02 | Stephen R. van den Berg | | case "bytea":
return replace (val,
({ "'", "\\", "\0", "&" }),
|
bd5a3a | 2011-02-11 | Martin Jonsson | | ({ "\\'", "\\\\\\\\", "\\\\000", "\\\\046" }) );
|
c5bd64 | 2011-02-02 | Stephen R. van den Berg | |
|
51d34a | 2010-03-30 | Stephen R. van den Berg | | case "csv":
if (sizeof(val) &&
((<' ', '\t'>)[val[0]] || (<' ', '\t'>)[val[-1]] ||
has_value(val, ",") || has_value(val, ";") ||
has_value(val, "\"") || has_value(val, "\n"))) {
return "\"" + replace(val, "\"", "\"\"") + "\"";
}
return val;
|
a97287 | 2000-12-11 | Per Hedbor | | case "mysql-dtag":
return replace (val,
({ "\"", "'", "\\" }),
({ "\\\"'\"'\"", "\\'", "\\\\" }));
case "mysql-pike":
return replace (val,
({ "\"", "'", "\\", "\n" }),
({ "\\\\\\\"", "\\\\'",
"\\\\\\\\", "\\n" }) );
case "sql-dtag":
case "oracle-dtag":
return replace (val,
({ "'", "\"" }),
({ "''", "\"'\"'\"" }) );
default:
|
7263fd | 2001-08-09 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | | return 0;
}
}
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
187ab8 | 2009-04-24 | Jonas Wallden | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
15f386 | 2012-11-14 | Stefan Wallström | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
50aa16 | 2015-04-28 | Jonas Walldén | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
50aa16 | 2015-04-28 | Jonas Walldén | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
15f386 | 2012-11-14 | Stefan Wallström | |
|
37edee | 2005-12-09 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
37edee | 2005-12-09 | Henrik Grubbström (Grubba) | |
|
15f386 | 2012-11-14 | Stefan Wallström | |
|
e04ef0 | 2011-07-06 | Jonas Wallden | |
|
37edee | 2005-12-09 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
f412f3 | 2008-11-05 | Martin Stjernholm | |
|
37edee | 2005-12-09 | Henrik Grubbström (Grubba) | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
258aed | 2016-03-18 | Anders Johansson | |
|
199497 | 2016-03-22 | Anders Johansson | |
|
258aed | 2016-03-18 | Anders Johansson | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
317147 | 2009-04-03 | Martin Stjernholm | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
b1f105 | 2012-11-17 | Jonas Wallden | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
51d34a | 2010-03-30 | Stephen R. van den Berg | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
317147 | 2009-04-03 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
0a7b70 | 2011-09-13 | Henrik Grubbström (Grubba) | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
0dc2ae | 2011-07-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
80f42f | 2010-07-12 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
80f42f | 2010-07-12 | Martin Stjernholm | |
|
39bd1d | 2010-04-22 | Henrik Grubbström (Grubba) | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
c5bd64 | 2011-02-02 | Stephen R. van den Berg | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
08f314 | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
|
d3764f | 2008-11-05 | Martin Stjernholm | |
|
1fc295 | 2005-11-29 | Henrik Grubbström (Grubba) | |
string roxen_encode(string val, string encoding)
{
foreach(encoding/".", string enc) {
if (!(val = low_roxen_encode(val, enc)))
return 0;
}
return val;
}
|
cb3e2b | 2010-12-02 | Henrik Grubbström (Grubba) | | string fix_relative( string file, RequestID|void id )
|
4f4938 | 2008-05-09 | Martin Stjernholm | |
{
|
1e20d5 | 2015-05-06 | Henrik Grubbström (Grubba) | | Standards.URI uri = Standards.URI(":///");
|
cb3e2b | 2010-12-02 | Henrik Grubbström (Grubba) | | if (id) {
uri = Standards.URI(id->not_query, uri);
}
uri = Standards.URI(file, uri);
|
98f135 | 2015-09-28 | Henrik Grubbström (Grubba) | | if (uri->path != "") {
uri->path = (uri->combine_uri_path("", uri->path)/"/" - ({ ".." })) * "/";
}
|
939343 | 2010-12-02 | Henrik Grubbström (Grubba) | | string res = sprintf("%s", uri);
|
a97287 | 2000-12-11 | Per Hedbor | |
|
939343 | 2010-12-02 | Henrik Grubbström (Grubba) | | if (has_prefix(res, "://") && !has_prefix(file, "://") &&
|
cb3e2b | 2010-12-02 | Henrik Grubbström (Grubba) | | (!id || !has_prefix(id->not_query, "://"))) {
|
939343 | 2010-12-02 | Henrik Grubbström (Grubba) | |
|
cb3e2b | 2010-12-02 | Henrik Grubbström (Grubba) | | if (!has_prefix(file, "//") &&
(!id || !has_prefix(id->not_query, "//"))) {
|
939343 | 2010-12-02 | Henrik Grubbström (Grubba) | |
return res[sizeof("://")..];
}
return res[1..];
}
return res;
|
a97287 | 2000-12-11 | Per Hedbor | | }
Stdio.File open_log_file( string logfile )
{
mapping m = localtime(time(1));
m->year += 1900;
m->mon++;
if(m->mon < 10) m->mon = "0"+m->mon;
if(m->mday < 10) m->mday = "0"+m->mday;
if(m->hour < 10) m->hour = "0"+m->hour;
logfile = replace(logfile,({"%d","%m","%y","%h" }),
({ (string)m->mday, (string)(m->mon),
(string)(m->year),(string)m->hour,}));
if(strlen(logfile))
{
Stdio.File lf=Stdio.File( logfile, "wac");
if(!lf)
{
mkdirhier(logfile);
if(!(lf=Stdio.File( logfile, "wac")))
{
report_error("Failed to open logfile. ("+logfile+"): "
+ strerror( errno() )+"\n");
return 0;
}
}
return lf;
}
return Stdio.stderr;
}
string tagtime(int t, mapping(string:string) m, RequestID id,
function(string, string,
object:function(int, mapping(string:string):string)) language)
{
string res;
if (m->adjust) t+=(int)m->adjust;
string lang;
|
63f82b | 2006-06-30 | Anders Johansson | | if(id && id->misc->defines && id->misc->defines->theme_language)
lang=id->misc->defines->theme_language;
|
a97287 | 2000-12-11 | Per Hedbor | | if(m->lang) lang=m->lang;
if(m->strftime)
|
8ae599 | 2003-07-11 | Anders Johansson | | return strftime(m->strftime, t, lang, language, id);
|
a97287 | 2000-12-11 | Per Hedbor | |
if (m->part)
{
string sp;
if(m->type == "ordered")
{
m->type="string";
sp = "ordered";
}
switch (m->part)
{
case "year":
return number2string(localtime(t)->year+1900,m,
language(lang, sp||"number",id));
case "month":
return number2string(localtime(t)->mon+1,m,
language(lang, sp||"month",id));
case "week":
return number2string(Calendar.ISO.Second(t)->week_no(),
m, language(lang, sp||"number",id));
case "beat":
mapping lt=gmtime(t);
int secs=3600;
secs+=lt->hour*3600;
secs+=lt->min*60;
secs+=lt->sec;
secs%=24*3600;
float beats=secs/86.4;
if(!sp) return sprintf("@%03d",(int)beats);
return number2string((int)beats,m,
language(lang, sp||"number",id));
case "day":
case "wday":
return number2string(localtime(t)->wday+1,m,
language(lang, sp||"day",id));
case "date":
case "mday":
return number2string(localtime(t)->mday,m,
language(lang, sp||"number",id));
case "hour":
return number2string(localtime(t)->hour,m,
language(lang, sp||"number",id));
case "min":
case "minute":
return number2string(localtime(t)->min,m,
language(lang, sp||"number",id));
case "sec":
case "second":
return number2string(localtime(t)->sec,m,
language(lang, sp||"number",id));
case "seconds":
return number2string(t,m,
language(lang, sp||"number",id));
case "yday":
return number2string(localtime(t)->yday,m,
language(lang, sp||"number",id));
default: return "";
}
}
else if(m->type) {
switch(m->type)
{
|
00c804 | 2001-03-29 | Martin Nilsson | | case "unix":
return (string)t;
|
a97287 | 2000-12-11 | Per Hedbor | | case "iso":
mapping eris=localtime(t);
if(m->date)
return sprintf("%d-%02d-%02d",
(eris->year+1900), eris->mon+1, eris->mday);
if(m->time)
return sprintf("%02d:%02d:%02d", eris->hour, eris->min, eris->sec);
return sprintf("%d-%02d-%02dT%02d:%02d:%02d",
(eris->year+1900), eris->mon+1, eris->mday,
eris->hour, eris->min, eris->sec);
|
66af91 | 2004-04-14 | Martin Stjernholm | | case "http":
return http_date (t);
|
aa430d | 2015-03-13 | Henrik Grubbström (Grubba) | | #pragma no_deprecation_warnings
|
a97287 | 2000-12-11 | Per Hedbor | | case "discordian":
|
538975 | 2009-01-09 | Martin Stjernholm | | #if constant (spider.discdate)
|
aa430d | 2015-03-13 | Henrik Grubbström (Grubba) | | array(string) not=spider.discdate(t);
|
a97287 | 2000-12-11 | Per Hedbor | | res=not[0];
if(m->year)
res += " in the YOLD of "+not[1];
if(m->holiday && not[2])
res += ". Celebrate "+not[2];
return res;
#else
return "Discordian date support disabled";
#endif
case "stardate":
|
538975 | 2009-01-09 | Martin Stjernholm | | #if constant (spider.stardate)
return (string)spider.stardate(t, (int)m->prec||1);
|
a97287 | 2000-12-11 | Per Hedbor | | #else
return "Stardate support disabled";
#endif
}
}
res=language(lang, "date", id)(t,m);
if(m["case"])
switch(lower_case(m["case"]))
{
case "upper": return upper_case(res);
case "lower": return lower_case(res);
case "capitalize": return capitalize(res);
}
#ifdef old_rxml_compat
if (m->upper) {
res=upper_case(res);
report_warning("Old RXML in "+(id->query||id->not_query)+
", contains upper attribute in a tag. Use case=\"upper\" instead.");
}
if (m->lower) {
res=lower_case(res);
report_warning("Old RXML in "+(id->query||id->not_query)+
", contains lower attribute in a tag. Use case=\"lower\" instead.");
}
if (m->cap||m->capitalize) {
res=capitalize(res);
report_warning("Old RXML in "+(id->query||id->not_query)+
", contains capitalize or cap attribute in a tag. Use case=\"capitalize\" instead.");
}
#endif
return res;
}
|
aa430d | 2015-03-13 | Henrik Grubbström (Grubba) | | #pragma deprecation_warnings
|
a97287 | 2000-12-11 | Per Hedbor | |
|
bbfe25 | 2001-09-10 | Martin Nilsson | | int time_dequantifier(mapping m, void|int t )
|
a97287 | 2000-12-11 | Per Hedbor | |
|
bbfe25 | 2001-09-10 | Martin Nilsson | |
|
a97287 | 2000-12-11 | Per Hedbor | |
{
|
bbfe25 | 2001-09-10 | Martin Nilsson | | int initial = t;
if (m->seconds) t+=(int)(m->seconds);
if (m->minutes) t+=(int)(m->minutes)*60;
if (m->beats) t+=(int)((float)(m->beats)*86.4);
if (m->hours) t+=(int)(m->hours)*3600;
|
a1a992 | 2004-01-28 | Anders Johansson | | if (m->days) {
int days = (int)m->days;
if(initial) {
if(days<0)
t = (Calendar.ISO.Second("unix", t) -
Calendar.ISO.Day()*abs(days))->unix_time();
else
t = (Calendar.ISO.Second("unix", t) +
Calendar.ISO.Day()*days)->unix_time();
}
else
t+=days*24*3600;
}
if (m->weeks) {
int weeks = (int)m->weeks;
if(initial) {
if(weeks<0)
t = (Calendar.ISO.Second("unix", t) -
Calendar.ISO.Week()*abs(weeks))->unix_time();
else
t = (Calendar.ISO.Second("unix", t) +
Calendar.ISO.Week()*weeks)->unix_time();
}
else
t+=weeks*604800;
}
|
bbfe25 | 2001-09-10 | Martin Nilsson | | if (m->months) {
|
2086ad | 2001-09-13 | Martin Nilsson | | int mon = (int)m->months;
if(initial) {
if(mon<0)
t = (Calendar.ISO.Second("unix", t) -
Calendar.ISO.Month()*abs(mon))->unix_time();
else
t = (Calendar.ISO.Second("unix", t) +
Calendar.ISO.Month()*mon)->unix_time();
}
|
bbfe25 | 2001-09-10 | Martin Nilsson | | else
|
2086ad | 2001-09-13 | Martin Nilsson | | t+=(int)(mon*24*3600*30.436849);
|
bbfe25 | 2001-09-10 | Martin Nilsson | | }
if (m->years) {
|
2086ad | 2001-09-13 | Martin Nilsson | | int year = (int)m->years;
if(initial) {
if(year<0)
t = (Calendar.ISO.Second("unix", t) -
Calendar.ISO.Year()*abs(year))->unix_time();
else
t = (Calendar.ISO.Second("unix", t) +
Calendar.ISO.Year()*(int)m->years)->unix_time();
}
|
bbfe25 | 2001-09-10 | Martin Nilsson | | else
t+=(int)((float)(m->years)*3600*24*365.242190);
}
|
a97287 | 2000-12-11 | Per Hedbor | | return (int)t;
}
|
cc2ec9 | 2009-11-26 | Henrik Grubbström (Grubba) | |
int timeout_dequantifier(mapping args)
{
int res = UNDEFINED;
if (args["unix-time"]) {
res = (int)args["unix-time"] - time(1);
}
res = time_dequantifier(args, res);
if (!zero_type(res)) {
foreach(({ "unix-time", "seconds", "minutes", "beats", "hours",
"days", "weeks", "months", "years" }), string arg) {
m_delete(args, arg);
}
}
return res;
}
|
a97287 | 2000-12-11 | Per Hedbor | | class _charset_decoder(object cs)
{
string decode(string what)
{
return cs->clear()->feed(what)->drain();
}
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected class CharsetDecoderWrapper
|
79c89a | 2008-02-16 | Martin Stjernholm | | {
|
50aa16 | 2015-04-28 | Jonas Walldén | | protected Charset.Decoder decoder;
|
79c89a | 2008-02-16 | Martin Stjernholm | | string charset;
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void create (string cs)
|
79c89a | 2008-02-16 | Martin Stjernholm | | {
|
50aa16 | 2015-04-28 | Jonas Walldén | |
decoder = Charset.decoder (charset = cs);
|
79c89a | 2008-02-16 | Martin Stjernholm | | }
string decode (string what)
{
|
50aa16 | 2015-04-28 | Jonas Walldén | | Charset.Decoder d = decoder;
|
79c89a | 2008-02-16 | Martin Stjernholm | |
decoder = 0;
if (d) d->clear();
|
50aa16 | 2015-04-28 | Jonas Walldén | | else d = Charset.decoder (charset);
|
79c89a | 2008-02-16 | Martin Stjernholm | | string res = d->feed (what)->drain();
decoder = d;
return res;
}
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected multiset(string) charset_warned_for = (<>);
|
668948 | 2002-03-01 | Henrik Grubbström (Grubba) | |
|
360c1b | 2004-06-30 | Stefan Wallström | | constant magic_charset_variable_placeholder = "UTF-8";
constant magic_charset_variable_value = "åäö芟@" + magic_charset_variable_placeholder;
|
dc3798 | 2003-04-09 | Anders Johansson | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mapping(string:function(string:string)) client_charset_decoders = ([
|
79c89a | 2008-02-16 | Martin Stjernholm | | "http": http_decode_string,
"html": Parser.parse_html_entities,
"utf-8": utf8_to_string,
"utf-16": unicode_to_string,
]);
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected function(string:string) make_composite_decoder (
|
79c89a | 2008-02-16 | Martin Stjernholm | | function(string:string) outer, function(string:string) inner)
{
return lambda (string what) {
return outer (inner (what));
};
}
function(string:string) get_decoder_for_client_charset (string charset)
{
if (function(string:string) dec = client_charset_decoders[charset])
return dec;
if (sscanf (charset, "%s|%s", string outer_cs, string inner_cs)) {
function(string:string) outer = client_charset_decoders[outer_cs];
if (!outer)
outer = client_charset_decoders[outer_cs] =
CharsetDecoderWrapper (outer_cs)->decode;
return client_charset_decoders[charset] =
make_composite_decoder (outer, get_decoder_for_client_charset (inner_cs));
}
return client_charset_decoders[charset] =
CharsetDecoderWrapper (charset)->decode;
}
string get_client_charset (string åäö)
|
c86cc2 | 2002-02-04 | Stefan Wallström | | {
|
b7280b | 2004-01-27 | Jonas Wallden | |
if (has_prefix(åäö, "%") && !has_prefix(åäö, "%%")) {
report_notice("Warning: Double HTTP encoding detected: %s\n", åäö);
|
79c89a | 2008-02-16 | Martin Stjernholm | | string cs = get_client_charset (http_decode_string(åäö));
if (cs) {
return cs + "|http";
|
b7280b | 2004-01-27 | Jonas Wallden | | } else {
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "http";
|
b7280b | 2004-01-27 | Jonas Wallden | | }
}
|
360c1b | 2004-06-30 | Stefan Wallström | |
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | |
|
79c89a | 2008-02-16 | Martin Stjernholm | | string test = åäö;
sscanf (test, "%s\0", test);
string test2 = test;
sscanf (test2, "%s@%s", test2, string charset);
test2 = replace(test2, ({ "\201", "?x829f;", }), ({ "?", "?", }));
|
360c1b | 2004-06-30 | Stefan Wallström | |
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | test = replace(test2,
|
360c1b | 2004-06-30 | Stefan Wallström | | ({ "å", "å", "å",
"ä", "ä", "ä",
"ö", "ö", "ö",
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | "芟","芟", }),
|
360c1b | 2004-06-30 | Stefan Wallström | | ({ "?", "?", "?",
"?", "?", "?",
"?", "?", "?",
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | "?", "?", }));
|
360c1b | 2004-06-30 | Stefan Wallström | |
|
c86cc2 | 2002-02-04 | Stefan Wallström | | switch( test ) {
case "edv":
case "edv?":
|
c854b6 | 2008-02-16 | Martin Stjernholm | | report_notice( "Warning: Non 8-bit safe client detected.\n");
|
c86cc2 | 2002-02-04 | Stefan Wallström | | return 0;
|
a97287 | 2000-12-11 | Per Hedbor | |
|
c86cc2 | 2002-02-04 | Stefan Wallström | | case "åäö?":
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | if (test2 != test)
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "html";
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | |
case "åäö":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "iso-8859-1";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
case "\33-Aåäö":
case "\33-A\345\344\366\33$Bgl":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "iso-2022-jp";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
case "+AOUA5AD2-":
case "+AOUA5AD2gp8-":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "utf-7";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
|
668948 | 2002-03-01 | Henrik Grubbström (Grubba) | | case "åäö?":
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | if (test != test2) {
|
b180ff | 2008-03-11 | Martin Stjernholm | | return "html|utf-8";
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | }
case "åäö":
|
c86cc2 | 2002-02-04 | Stefan Wallström | | case "åä":
case "åäö\350\212\237":
|
11579f | 2004-08-06 | Fredrik Noring | | case "\357\277\275\357\277\275\357\277\275\350\212\237":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "utf-8";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
case "\214\212\232?":
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | if (test != test2) {
|
b180ff | 2008-03-11 | Martin Stjernholm | | return "html|mac";
|
aaa910 | 2004-09-06 | Henrik Grubbström (Grubba) | | }
case "\214\212\232":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "mac";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
case "\0å\0ä\0ö":
case "\0å\0ä\0ö\202\237":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "utf-16";
|
c86cc2 | 2002-02-04 | Stefan Wallström | |
case "\344\214":
case "???\344\214":
case "\217\206H\217\206B\217\206r\344\214":
|
79c89a | 2008-02-16 | Martin Stjernholm | | return "shift_jis";
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
360c1b | 2004-06-30 | Stefan Wallström | |
|
79c89a | 2008-02-16 | Martin Stjernholm | | if (charset)
catch {
get_decoder_for_client_charset (charset);
return charset;
};
|
360c1b | 2004-06-30 | Stefan Wallström | |
|
668948 | 2002-03-01 | Henrik Grubbström (Grubba) | | if (!charset_warned_for[test] && (sizeof(charset_warned_for) < 256)) {
charset_warned_for[test] = 1;
|
79c89a | 2008-02-16 | Martin Stjernholm | | report_warning( "Unable to find charset decoder for %O "
"(vector %O, charset %O).\n",
åäö, test, charset);
|
668948 | 2002-03-01 | Henrik Grubbström (Grubba) | | }
|
a97287 | 2000-12-11 | Per Hedbor | | }
|
79c89a | 2008-02-16 | Martin Stjernholm | |
function(string:string) get_client_charset_decoder( string åäö,
RequestID|void id )
{
string charset = get_client_charset (åäö);
|
c854b6 | 2008-02-16 | Martin Stjernholm | | if (function(string|function:void) f = id && id->set_output_charset)
|
79c89a | 2008-02-16 | Martin Stjernholm | | switch (charset) {
case "iso-2022-jp": f ("iso-2022"); break;
case "utf-7": f ("utf-7"); break;
|
b180ff | 2008-03-11 | Martin Stjernholm | | case "html|utf-8": case "utf-8": f ("utf-8"); break;
case "html|mac": case "mac": f ("mac"); break;
|
79c89a | 2008-02-16 | Martin Stjernholm | | case "utf-16": f (string_to_unicode); break;
case "shift_jis": f ("shift_jis"); break;
}
return get_decoder_for_client_charset (charset);
}
|
a97287 | 2000-12-11 | Per Hedbor | |
|
796fb6 | 2000-08-12 | Per Hedbor | |
inherit _Roxen;
|
7962a0 | 2005-10-28 | Henrik Grubbström (Grubba) | |
#if constant(HAVE_OLD__Roxen_make_http_headers)
string make_http_headers(mapping(string:string|array(string)) heads,
int(0..1)|void no_terminator)
{
|
d5c852 | 2016-06-29 | Henrik Grubbström (Grubba) | | foreach(heads; string key; string|array(string) val) {
if (has_value(key, "\n") || has_value(key, "\r") ||
has_value(key, ":") || has_value(key, " ") || has_value(key, "\t")) {
error("Invalid headername: %O (value: %O)\n", key, val);
}
if (stringp(val) && (has_value(val, "\n") || has_value(val, "\r"))) {
error("Invalid value for header %O: %O\n", key, val);
}
if (arrayp(val)) {
foreach(val, string v) {
if (has_value(v, "\n") || has_value(v, "\r")) {
error("Invalid value for header %O: %O\n", key, val);
}
}
}
|
7962a0 | 2005-10-28 | Henrik Grubbström (Grubba) | | }
|
d5c852 | 2016-06-29 | Henrik Grubbström (Grubba) | | return ::make_http_headers(heads, no_terminator);
|
7962a0 | 2005-10-28 | Henrik Grubbström (Grubba) | | }
#endif /* constant(HAVE_OLD__Roxen_make_http_headers) */
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
#ifdef QUOTA_DEBUG
|
072082 | 2001-03-13 | Martin Nilsson | | #define QD_WRITE(X) report_debug(X)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | #else /* !QUOTA_DEBUG */
#define QD_WRITE(X)
#endif /* QUOTA_DEBUG */
|
7e9a0b | 2000-09-16 | Per Hedbor | |
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | class QuotaDB
{
object(Thread.Mutex) lock = Thread.Mutex();
|
2543b7 | 2000-07-02 | Henrik Grubbström (Grubba) | | #define LOCK() mixed key__; catch { key__ = lock->lock(); }
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | #define UNLOCK() do { if (key__) destruct(key__); } while(0)
constant READ_BUF_SIZE = 256;
constant CACHE_SIZE_LIMIT = 512;
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | string base;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | object catalog_file;
object data_file;
mapping(string:int) new_entries_cache = ([]);
mapping(string:object) active_objects = ([]);
array(int) index;
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | array(string) index_acc;
int acc_scale;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
int next_offset;
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected class QuotaEntry
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
string name;
int data_offset;
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int usage;
protected int quota;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void store()
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
LOCK();
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaEntry::store(): Usage for %O is now %O(%O)\n",
name, usage, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
data_file->seek(data_offset);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | data_file->write(sprintf("%4c", usage));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
UNLOCK();
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void read()
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
LOCK();
data_file->seek(data_offset);
string s = data_file->read(4);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | usage = 0;
sscanf(s, "%4c", usage);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
01f680 | 1999-06-20 | Henrik Grubbström (Grubba) | | if (usage < 0) {
usage = 0;
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaEntry::read(): Usage for %O is %O(%O)\n",
name, usage, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
UNLOCK();
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | void create(string n, int d_o, int q)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaEntry(%O, %O, %O)\n", n, d_o, q));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
name = n;
data_offset = d_o;
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | quota = q;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
read();
}
int check_quota(string uri, int amount)
{
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaEntry::check_quota(%O, %O): usage:%d(%d)\n",
uri, amount, usage, quota));
if (!quota) {
return 0;
}
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
if (amount == 0x7fffffff) {
return 1;
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return(usage + amount <= quota);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
int allocate(string uri, int amount)
{
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaEntry::allocate(%O, %O): usage:%d => %d(%d)\n",
uri, amount, usage, usage + amount, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | usage += amount;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
01f680 | 1999-06-20 | Henrik Grubbström (Grubba) | | if (usage < 0) {
usage = 0;
}
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | store();
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return(usage <= quota);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
int deallocate(string uri, int amount)
{
return(allocate(uri, -amount));
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | int get_usage(string uri)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return usage;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | void set_usage(string uri, int amount)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | usage = amount;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
store();
}
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected object read_entry(int offset, int|void quota)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::read_entry(%O, %O)\n", offset, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
catalog_file->seek(offset);
string data = catalog_file->read(READ_BUF_SIZE);
if (data == "") {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::read_entry(%O, %O): At EOF\n",
offset, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
return 0;
}
int len;
int data_offset;
string key;
sscanf(data[..7], "%4c%4c", len, data_offset);
if (len > sizeof(data)) {
key = data[8..] + catalog_file->read(len - sizeof(data));
len -= 8;
if (sizeof(key) != len) {
error(sprintf("Failed to read catalog entry at offset %d.\n"
"len: %d, sizeof(key):%d\n",
offset, len, sizeof(key)));
}
} else {
key = data[8..len-1];
|
6fa7e8 | 1999-05-14 | Henrik Grubbström (Grubba) | | catalog_file->seek(offset + 8 + sizeof(key));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return QuotaEntry(key, data_offset, quota);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected Stdio.File open(string fname, int|void create_new)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
3e3bab | 2001-01-19 | Per Hedbor | | Stdio.File f = Stdio.File();
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | string mode = create_new?"rwc":"rw";
if (!f->open(fname, mode)) {
error(sprintf("Failed to open quota file %O.\n", fname));
}
if (f->try_lock && !f->try_lock()) {
error(sprintf("Failed to lock quota file %O.\n", fname));
}
return(f);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected void init_index_acc()
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | {
acc_scale = 1;
if (sizeof(index)) {
int i = sizeof(index)/2;
while (i) {
i /= 4;
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | acc_scale *= 2;
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | }
}
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | index_acc = allocate((sizeof(index) + acc_scale -1)/acc_scale);
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | |
QD_WRITE(sprintf("QuotaDB()::init_index_acc(): "
"sizeof(index):%d, sizeof(index_acc):%d acc_scale:%d\n",
sizeof(index), sizeof(index_acc), acc_scale));
}
|
1a7b00 | 1999-05-14 | Henrik Grubbström (Grubba) | | void rebuild_index()
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | array(string) new_keys = sort(indices(new_entries_cache));
int prev;
array(int) new_index = ({});
foreach(new_keys, string key) {
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::rebuild_index(): key:%O lo:0 hi:%d\n",
key, sizeof(index_acc)));
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | int lo;
int hi = sizeof(index_acc);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (hi) {
do {
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | |
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | int probe = (lo + hi)/2;
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::rebuild_index(): acc: "
"key:%O lo:%d probe:%d hi:%d\n",
key, lo, probe, hi));
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (!index_acc[probe]) {
object e = read_entry(index[probe * acc_scale]);
index_acc[probe] = e->name;
}
if (index_acc[probe] < key) {
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | lo = probe + 1;
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | } else if (index_acc[probe] > key) {
hi = probe;
} else {
break;
}
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | } while(lo < hi);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | |
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | if (lo < hi) {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | |
continue;
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | }
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | if (hi) {
hi *= acc_scale;
lo = hi - acc_scale;
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | |
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | if (hi > sizeof(index)) {
hi = sizeof(index);
}
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | |
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | | do {
int probe = (lo + hi)/2;
QD_WRITE(sprintf("QuotaDB::rebuild_index(): "
"key:%O lo:%d probe:%d hi:%d\n",
key, lo, probe, hi));
object e = read_entry(index[probe]);
if (e->name < key) {
lo = probe + 1;
} else if (e->name > key) {
hi = probe;
} else {
break;
}
} while (lo < hi);
if (lo < hi) {
continue;
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | }
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | }
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | new_index += index[prev..hi-1] + ({ new_entries_cache[key] });
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | prev = hi;
} else {
new_index += ({ new_entries_cache[key] });
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | }
}
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | |
new_index += index[prev..];
QD_WRITE("Index rebuilt.\n");
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | LOCK();
object index_file = open(base + ".index.new", 1);
string to_write = sprintf("%@4c", new_index);
if (index_file->write(to_write) != sizeof(to_write)) {
index_file->close();
rm(base + ".index.new");
} else {
mv(base + ".index.new", base + ".index");
}
index = new_index;
init_index_acc();
UNLOCK();
foreach(new_keys, string key) {
m_delete(new_entries_cache, key);
}
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected object low_lookup(string key, int quota)
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::low_lookup(%O, %O)\n", key, quota));
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | int cat_offset;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | if (!zero_type(cat_offset = new_entries_cache[key])) {
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB::low_lookup(%O, %O): "
"Found in new entries cache.\n", key, quota));
return read_entry(cat_offset, quota);
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | }
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | |
int lo;
int hi = sizeof(index_acc);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (hi) {
do {
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | |
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | int probe = (lo + hi)/2;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB:low_lookup(%O): "
"In acc: lo:%d, probe:%d, hi:%d\n",
key, lo, probe, hi));
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (!index_acc[probe]) {
object e = read_entry(index[probe * acc_scale], quota);
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | |
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | index_acc[probe] = e->name;
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | |
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (key == e->name) {
QD_WRITE(sprintf("QuotaDB:low_lookup(%O): In acc: Found at %d\n",
key, probe * acc_scale));
return e;
}
}
if (index_acc[probe] < key) {
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | lo = probe + 1;
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | } else if (index_acc[probe] > key) {
hi = probe;
} else {
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | QD_WRITE(sprintf("QuotaDB:low_lookup(%O): In acc: Found at %d\n",
key, probe * acc_scale));
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return read_entry(index[probe * acc_scale], quota);
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | }
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | } while(lo < hi);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | if (hi) {
hi *= acc_scale;
lo = hi - acc_scale;
|
8b5f0c | 1999-05-16 | Henrik Grubbström (Grubba) | |
if (hi > sizeof(index)) {
hi = sizeof(index);
}
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | do {
int probe = (lo + hi)/2;
QD_WRITE(sprintf("QuotaDB:low_lookup(%O): lo:%d, probe:%d, hi:%d\n",
key, lo, probe, hi));
object e = read_entry(index[probe], quota);
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | |
|
366b79 | 1999-05-16 | Henrik Grubbström (Grubba) | | if (e->name < key) {
lo = probe + 1;
} else if (e->name > key) {
hi = probe;
} else {
QD_WRITE(sprintf("QuotaDB:low_lookup(%O): Found at %d\n",
key, probe));
return e;
}
} while (lo < hi);
}
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | }
QD_WRITE(sprintf("QuotaDB::low_lookup(%O): Not found\n", key));
return 0;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
object lookup(string key, int quota)
{
QD_WRITE(sprintf("QuotaDB::lookup(%O, %O)\n", key, quota));
LOCK();
object res;
if (res = active_objects[key]) {
QD_WRITE(sprintf("QuotaDB::lookup(%O, %O): User in active objects.\n",
key, quota));
return res;
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (res = low_lookup(key, quota)) {
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | active_objects[key] = res;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | return res;
}
QD_WRITE(sprintf("QuotaDB::lookup(%O, %O): New user.\n", key, quota));
data_file->seek(-1);
data_file->read(1);
catalog_file->seek(next_offset);
int data_offset = data_file->tell();
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | if (data_file->write(sprintf("%4c", 0)) != 4) {
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | error(sprintf("write() failed for quota data file!\n"));
}
string entry = sprintf("%4c%4c%s", sizeof(key)+8, data_offset, key);
if (catalog_file->write(entry) != sizeof(entry)) {
error(sprintf("write() failed for quota catalog file!\n"));
}
new_entries_cache[key] = next_offset;
next_offset = catalog_file->tell();
if (sizeof(new_entries_cache) > CACHE_SIZE_LIMIT) {
rebuild_index();
}
|
eed714 | 1999-05-12 | Henrik Grubbström (Grubba) | | return low_lookup(key, quota);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | }
void create(string base_name, int|void create_new)
{
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | base = base_name;
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | catalog_file = open(base_name + ".cat", create_new);
data_file = open(base_name + ".data", create_new);
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | object index_file = open(base_name + ".index", 1);
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | |
set_weak_flag(active_objects, 1);
array index_st = index_file->stat();
if (!index_st || !sizeof(index_st)) {
error(sprintf("stat() failed for quota index file!\n"));
}
array data_st = data_file->stat();
if (!data_st || !sizeof(data_st)) {
error(sprintf("stat() failed for quota data file!\n"));
}
if (index_st[1] < 0) {
error("quota index file isn't a regular file!\n");
}
if (data_st[1] < 0) {
error("quota data file isn't a regular file!\n");
}
if (data_st[1] < index_st[1]) {
error("quota data file is shorter than the index file!\n");
}
if (index_st[1] & 3) {
error("quota index file has odd length!\n");
}
if (data_st[1] & 3) {
error("quota data file has odd length!\n");
}
int i;
array(string) index_str = index_file->read()/4;
index = allocate(sizeof(index_str));
|
a3e427 | 1999-05-11 | Henrik Grubbström (Grubba) | | if (sizeof(index_str) && (sizeof(index_str[-1]) != 4)) {
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | error("Truncated read of the index file!\n");
}
foreach(index_str, string offset_str) {
int offset;
sscanf(offset_str, "%4c", offset);
index[i++] = offset;
if (offset > next_offset) {
next_offset = offset;
}
}
|
e9857a | 1999-05-08 | Henrik Grubbström (Grubba) | | init_index_acc();
|
ebc988 | 1999-05-06 | Henrik Grubbström (Grubba) | | if (sizeof(index)) {
mixed entry = read_entry(next_offset);
next_offset = catalog_file->tell();
}
if (index_st[1] < data_st[1]) {
while (mixed entry = read_entry(next_offset)) {
new_entries_cache[entry->name] = next_offset;
next_offset = catalog_file->tell();
}
rebuild_index();
}
}
}
|
69e4cd | 2000-03-09 | Martin Stjernholm | |
|
df6c03 | 2000-08-09 | Per Hedbor | | #define CTX()
|
f35256 | 2000-09-24 | Henrik Grubbström (Grubba) | | class EScope(string scope)
|
df6c03 | 2000-08-09 | Per Hedbor | | {
void delete( string var )
{
RXML.Context ctx = RXML.get_context( );
ctx->delete_var( var, scope );
}
string name()
{
RXML.Context ctx = RXML.get_context( );
return scope == "_" ? ctx->current_scope() : scope;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mixed `[]( string what )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
|
0eebca | 2012-08-15 | Henrik Grubbström (Grubba) | |
|
66e543 | 2012-08-15 | Henrik Grubbström (Grubba) | | RXML.Context ctx = RXML.get_context( );
|
0eebca | 2012-08-15 | Henrik Grubbström (Grubba) | | return ctx->scopes[scope || "_"] && ctx->get_var( what, scope );
|
df6c03 | 2000-08-09 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mixed `->( string what )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
|
0eebca | 2012-08-15 | Henrik Grubbström (Grubba) | | return `[]( what );
|
df6c03 | 2000-08-09 | Per Hedbor | | }
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mixed `[]=( string what, mixed nval )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
RXML.Context ctx = RXML.get_context( );
ctx->set_var( what, nval, scope );
return nval;
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mixed `->=( string what, mixed nval )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
return `[]=( what, nval );
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected array(string) _indices( )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
RXML.Context ctx = RXML.get_context( );
return ctx->list_var( scope );
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected array(string) _values( )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
RXML.Context ctx = RXML.get_context( );
return map( ctx->list_var( scope ), `[] );
}
}
class SRestore
{
mapping osc = ([]);
void destroy()
{
foreach( indices( osc ), string o )
add_constant( o, osc[o] );
add_constant( "roxen", roxenp() );
}
}
|
24de1e | 2001-08-28 | Per Hedbor | | SRestore add_scope_constants( string|void name, function|void add_constant )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
SRestore res = SRestore();
mapping ac = all_constants();
|
24de1e | 2001-08-28 | Per Hedbor | | if(!add_constant)
add_constant = predef::add_constant;
|
df6c03 | 2000-08-09 | Per Hedbor | | if(!name) name = "";
|
85a1bb | 2000-08-10 | Per Hedbor | | if( RXML.get_context() )
|
df6c03 | 2000-08-09 | Per Hedbor | | {
|
85a1bb | 2000-08-10 | Per Hedbor | | foreach( RXML.get_context()->list_scopes()|({"_"}), string scope )
{
|
24de1e | 2001-08-28 | Per Hedbor | | if( add_constant == predef::add_constant )
res->osc[ name+scope ] = ac[ name+scope ];
|
85a1bb | 2000-08-10 | Per Hedbor | | add_constant( name+scope, EScope( scope ) );
}
|
df6c03 | 2000-08-09 | Per Hedbor | | }
return res;
}
|
703503 | 2000-08-23 | Martin Nilsson | |
mapping(string:string) parser_charref_table =
lambda () {
mapping(string:string) table = ([]);
for (int i = 0; i < sizeof (replace_entities); i++) {
string chref = replace_entities[i];
table[chref[1..sizeof (chref) - 2]] = replace_values[i];
}
return table;
}();
|
f4c4d5 | 2000-08-27 | Martin Stjernholm | |
mapping(string:string) inverse_charref_table =
lambda () {
mapping(string:string) table = ([]);
for (int i = 0; i < sizeof (replace_entities); i++) {
string chref = replace_entities[i];
table[replace_values[i]] = chref[1..sizeof (chref) - 2];
}
return table;
}();
string decode_charref (string chref)
{
if (sizeof (chref) <= 2 || chref[0] != '&' || chref[-1] != ';') return 0;
if (chref[1] != '#') return parser_charref_table[chref[1..sizeof (chref) - 2]];
|
216531 | 2001-03-01 | Martin Stjernholm | | if (sscanf (chref,
(<'x', 'X'>)[chref[2]] ? "&%*2s%x;%*c" : "&%*c%d;%*c",
int c) == 2)
catch {return (string) ({c});};
|
f4c4d5 | 2000-08-27 | Martin Stjernholm | | return 0;
}
|
425fc6 | 2000-09-21 | Per Hedbor | | string|program safe_compile( string code )
{
program ret;
|
6465b9 | 2000-09-27 | Per Hedbor | | roxenloader.LowErrorContainer ec = roxenloader.LowErrorContainer();
|
425fc6 | 2000-09-21 | Per Hedbor | | roxenloader.push_compile_error_handler( ec );
|
d7c13e | 2004-06-25 | Anders Johansson | | catch(ret = compile_string( code ));
|
6465b9 | 2000-09-27 | Per Hedbor | | roxenloader.pop_compile_error_handler( );
|
425fc6 | 2000-09-21 | Per Hedbor | | if( !ret ) return ec->get();
return ret;
}
|
f4c4d5 | 2000-08-27 | Martin Stjernholm | | string encode_charref (string char)
|
d3beb0 | 2000-08-27 | Martin Stjernholm | |
|
f4c4d5 | 2000-08-27 | Martin Stjernholm | | {
if (string chref = inverse_charref_table[char]) return "&" + chref + ";";
|
d3beb0 | 2000-08-27 | Martin Stjernholm | | return sprintf ("&#%d;", char[0]);
|
f4c4d5 | 2000-08-27 | Martin Stjernholm | | }
|
703503 | 2000-08-23 | Martin Nilsson | |
|
df6c03 | 2000-08-09 | Per Hedbor | |
|
69e4cd | 2000-03-09 | Martin Stjernholm | |
|
6ad1bb | 2004-06-08 | Fredrik Noring | | class ScopeRequestHeader {
inherit RXML.Scope;
mixed `[] (string var, void|RXML.Context c, void|string scope, void|RXML.Type type) {
string|array(string) val = (c || RXML_CONTEXT)->id->request_headers[var];
if(!val)
return RXML.nil;
if(type)
{
if(arrayp(val) && type->subtype_of (RXML.t_any_text))
val *= "\0";
return type->encode(val);
}
return val;
}
array(string) _indices(void|RXML.Context c) {
return indices((c || RXML_CONTEXT)->id->request_headers);
}
array(string) _values(void|RXML.Context c) {
return values((c || RXML_CONTEXT)->id->request_headers);
}
|
7e4e99 | 2006-12-11 | Martin Stjernholm | | string _sprintf (int flag)
{
return flag == 'O' && "RXML.Scope(request-header)";
}
|
6ad1bb | 2004-06-08 | Fredrik Noring | | }
|
69e4cd | 2000-03-09 | Martin Stjernholm | | class ScopeRoxen {
inherit RXML.Scope;
string pike_version=predef::version();
int ssl_strength=0;
#if constant(SSL)
void create() {
ssl_strength=40;
|
c4ee17 | 2000-04-06 | Henrik Grubbström (Grubba) | | #if constant(SSL.constants.CIPHER_des)
|
69e4cd | 2000-03-09 | Martin Stjernholm | | if(SSL.constants.CIPHER_algorithms[SSL.constants.CIPHER_des])
ssl_strength=128;
if(SSL.constants.CIPHER_algorithms[SSL.constants.CIPHER_3des])
ssl_strength=168;
|
c4ee17 | 2000-04-06 | Henrik Grubbström (Grubba) | | #endif /* !constant(SSL.constants.CIPHER_des) */
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
#endif
|
216531 | 2001-03-01 | Martin Stjernholm | | mixed `[] (string var, void|RXML.Context c, void|string scope, void|RXML.Type type) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
08f44d | 2003-12-08 | Fredrik Noring | |
mixed val = c->misc->scope_roxen[var];
if(!zero_type(val))
{
if (objectp(val) && val->rxml_var_eval) return val;
return ENCODE_RXML_TEXT(val, type);
}
|
69e4cd | 2000-03-09 | Martin Stjernholm | | switch(var)
{
|
242bdc | 2006-01-13 | Henrik Grubbström (Grubba) | | case "nodename":
return uname()->nodename;
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "uptime":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (1);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(time(1)-roxenp()->start_time, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "uptime-days":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (3600 * 2);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT((time(1)-roxenp()->start_time)/3600/24, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "uptime-hours":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (1800);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT((time(1)-roxenp()->start_time)/3600, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "uptime-minutes":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (60);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT((time(1)-roxenp()->start_time)/60, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "hits-per-minute":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (2);
|
216531 | 2001-03-01 | Martin Stjernholm | |
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(c->id->conf->requests / ((time(1)-roxenp()->start_time)/60 + 1),
type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "hits":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->set_max_cache (0);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(c->id->conf->requests, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "sent-mb":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (10);
|
216531 | 2001-03-01 | Martin Stjernholm | |
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(sprintf("%1.2f",c->id->conf->sent / (1024.0*1024.0)), type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "sent":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->set_max_cache (0);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(c->id->conf->sent, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "sent-per-minute":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (2);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(c->id->conf->sent / ((time(1)-roxenp()->start_time)/60 || 1),
type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "sent-kbit-per-second":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (2);
|
216531 | 2001-03-01 | Martin Stjernholm | |
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(sprintf("%1.2f",((c->id->conf->sent*8)/1024.0/
(time(1)-roxenp()->start_time || 1))),
type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "ssl-strength":
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_INT(ssl_strength, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "pike-version":
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(pike_version, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "version":
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(roxenp()->version(), type);
|
88bff1 | 2000-09-12 | Per Hedbor | | case "base-version":
|
bb1fc4 | 2008-06-24 | Martin Stjernholm | | return ENCODE_RXML_TEXT(roxen_ver, type);
|
88bff1 | 2000-09-12 | Per Hedbor | | case "build":
|
bb1fc4 | 2008-06-24 | Martin Stjernholm | | return ENCODE_RXML_TEXT(roxen_build, type);
|
5a272a | 2002-05-07 | Jonas Wallden | | case "dist-version":
return ENCODE_RXML_TEXT(roxen_dist_version, type);
|
88edde | 2009-04-20 | Jonas Wallden | | case "dist-os":
return ENCODE_RXML_TEXT(roxen_dist_os, type);
|
cdddcb | 2002-04-08 | Johan Schön | | case "product-name":
return ENCODE_RXML_TEXT(roxen_product_name, type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "time":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->lower_max_cache (1);
|
8ff672 | 2001-08-29 | Martin Nilsson | | return ENCODE_RXML_INT(time(), type);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | case "server":
|
f7bc8a | 2001-07-21 | Martin Stjernholm | | return ENCODE_RXML_TEXT (c->id->url_base(), type);
|
dc8928 | 2008-12-11 | Jonas Wallden | | case "domain": {
Standards.URI u = Standards.URI(c->id->url_base());
string tmp = u && u->host;
if (tmp && has_value(tmp, ":"))
tmp = "[" + tmp + "]";
return ENCODE_RXML_TEXT(tmp || "", type);
}
|
703503 | 2000-08-23 | Martin Nilsson | | case "locale":
|
b1dc3a | 2009-04-21 | Martin Stjernholm | | c->id->set_max_cache (0);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(roxenp()->locale->get(), type);
|
b44ce5 | 2000-12-04 | Martin Nilsson | | case "path":
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(c->id->misc->site_prefix_path, type);
|
af7eeb | 2001-04-21 | Martin Nilsson | | case "unique-id":
return ENCODE_RXML_TEXT(roxenp()->create_unique_id(), type);
|
c2bd8c | 2002-04-09 | Marcus Wellhardh | |
|
17e952 | 2002-04-15 | Marcus Wellhardh | | case "license-type": {
|
c2bd8c | 2002-04-09 | Marcus Wellhardh | | object key = c->id->conf->getvar("license")->get_key();
return ENCODE_RXML_TEXT(key?key->type():"none", type);
|
17e952 | 2002-04-15 | Marcus Wellhardh | | }
case "license-warnings": {
|
461881 | 2002-04-15 | Marcus Wellhardh | | object key = c->id->conf->getvar("license")->get_key();
return ENCODE_RXML_TEXT(key?sizeof(key->get_warnings()):0, type);
|
17e952 | 2002-04-15 | Marcus Wellhardh | | }
|
4f84e2 | 2007-11-08 | Jonas Wallden | |
case "auto-charset-variable":
return ENCODE_RXML_TEXT("magic_roxen_automatic_charset_variable", type);
case "auto-charset-value":
return ENCODE_RXML_TEXT(magic_charset_variable_value, type);
|
9f6f80 | 2011-11-14 | Martin Stjernholm | |
case "null":
|
e925a4 | 2012-06-10 | Martin Stjernholm | |
|
9f6f80 | 2011-11-14 | Martin Stjernholm | | return Val->null;
case "true":
return Val->true;
case "false":
return Val->false;
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
08f44d | 2003-12-08 | Fredrik Noring | |
return RXML.nil;
|
8b43d5 | 2002-02-13 | Marcus Wellhardh | | }
mixed `[]= (string var, mixed val, void|RXML.Context c,
void|string scope_name) {
if (!c) c = RXML_CONTEXT;
return c->misc->scope_roxen[var]=val;
}
array(string) _indices(void|RXML.Context c) {
if (!c) c = RXML_CONTEXT;
|
1a4071 | 2006-02-27 | Jonas Wallden | | return
Array.uniq(indices(c->misc->scope_roxen) +
({ "uptime", "uptime-days", "uptime-hours", "uptime-minutes",
"hits-per-minute", "hits", "sent-mb", "sent", "unique-id",
"sent-per-minute", "sent-kbit-per-second", "ssl-strength",
"pike-version", "version", "time", "server", "domain",
|
4f84e2 | 2007-11-08 | Jonas Wallden | | "locale", "path", "auto-charset-variable",
"auto-charset-value" }) );
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
8b43d5 | 2002-02-13 | Marcus Wellhardh | | void _m_delete (string var, void|RXML.Context c, void|string scope_name) {
if (!c) c = RXML_CONTEXT;
predef::m_delete(c->misc->scope_roxen, var);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
7e4e99 | 2006-12-11 | Martin Stjernholm | | string _sprintf (int flag) { return flag == 'O' && "RXML.Scope(roxen)"; }
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
362428 | 2007-01-03 | Henrik Grubbström (Grubba) | | int get_ssl_strength(string ignored, RequestID id)
{
|
280400 | 2009-06-10 | Marcus Wellhardh | | if (!id->my_fd || !id->my_fd->get_peer_certificate_info ||
|
362428 | 2007-01-03 | Henrik Grubbström (Grubba) | | !id->my_fd->query_connection())
return 0;
return id->my_fd->query_connection()->session->cipher_spec->key_bits;
}
|
91950b | 2016-05-20 | Henrik Grubbström (Grubba) | | string hash_query_data(string ignored, RequestID id)
{
if (!id->data) return 0;
|
28b88a | 2016-06-16 | Henrik Grubbström (Grubba) | | if (zero_type(id->misc->len)) return 0;
|
91950b | 2016-05-20 | Henrik Grubbström (Grubba) | | if (id->data == "") return "";
return Crypto.SHA1.hash(id->data);
}
|
69e4cd | 2000-03-09 | Martin Stjernholm | | class ScopePage {
inherit RXML.Scope;
constant converter=(["fgcolor":"fgcolor", "bgcolor":"bgcolor",
"theme-bgcolor":"theme_bgcolor", "theme-fgcolor":"theme_fgcolor",
"theme-language":"theme_language"]);
|
216531 | 2001-03-01 | Martin Stjernholm | | mixed `[] (string var, void|RXML.Context c, void|string scope, void|RXML.Type type) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
08f44d | 2003-12-08 | Fredrik Noring | |
mixed val;
if(converter[var])
val = c->misc[converter[var]];
else
val = c->misc->scope_page[var];
if(!zero_type(val))
{
if (objectp (val) && val->rxml_var_eval)
return val;
return ENCODE_RXML_TEXT(val, type);
}
|
971ed3 | 2000-03-20 | Martin Stjernholm | | switch (var) {
|
a527c3 | 2001-03-24 | Martin Nilsson | | case "pathinfo": return ENCODE_RXML_TEXT(c->id->misc->path_info, type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "realfile": return ENCODE_RXML_TEXT(c->id->realfile, type);
case "virtroot": return ENCODE_RXML_TEXT(c->id->virtfile, type);
|
4c3c5d | 2002-10-15 | Marcus Wellhardh | | case "mountpoint":
string s = c->id->virtfile || "";
return ENCODE_RXML_TEXT(s[sizeof(s)-1..sizeof(s)-1] == "/"? s[..sizeof(s)-2]: s, type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "virtfile":
|
7661f6 | 2003-12-08 | Fredrik Noring | | case "path": return ENCODE_RXML_TEXT(c->id->not_query, type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "query": return ENCODE_RXML_TEXT(c->id->query, type);
case "url": return ENCODE_RXML_TEXT(c->id->raw_url, type);
|
91950b | 2016-05-20 | Henrik Grubbström (Grubba) | | case "post-data":
c->id->register_vary_callback(0, hash_query_data);
|
28b88a | 2016-06-16 | Henrik Grubbström (Grubba) | | if (!c->id->data || zero_type(c->id->misc->len)) return RXML.nil;
return ENCODE_RXML_TEXT(c->id->data, type);
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | case "last-true": return ENCODE_RXML_INT(c->misc[" _ok"], type);
case "language": return ENCODE_RXML_TEXT(c->misc->language, type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "scope": return ENCODE_RXML_TEXT(c->current_scope(), type);
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | case "filesize": return ENCODE_RXML_INT(c->misc[" _stat"]?
c->misc[" _stat"][1]:-4, type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "self": return ENCODE_RXML_TEXT( (c->id->not_query/"/")[-1], type);
case "ssl-strength":
|
e3589d | 2008-01-10 | Martin Stjernholm | | c->id->register_vary_callback("host", get_ssl_strength);
|
362428 | 2007-01-03 | Henrik Grubbström (Grubba) | | return ENCODE_RXML_INT(get_ssl_strength("", c->id), type);
|
c47909 | 2001-04-21 | Martin Nilsson | | case "dir":
|
7661f6 | 2003-12-08 | Fredrik Noring | | array parts = c->id->not_query/"/";
|
c47909 | 2001-04-21 | Martin Nilsson | | return ENCODE_RXML_TEXT( parts[..sizeof(parts)-2]*"/"+"/", type);
|
fbd2c1 | 2001-05-30 | Martin Nilsson | | case "counter":
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | return ENCODE_RXML_INT(++c->misc->internal_counter, type);
|
971ed3 | 2000-03-20 | Martin Stjernholm | | }
|
08f44d | 2003-12-08 | Fredrik Noring | |
return RXML.nil;
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
mixed `[]= (string var, mixed val, void|RXML.Context c, void|string scope_name) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
971ed3 | 2000-03-20 | Martin Stjernholm | | switch (var) {
case "pathinfo": return c->id->misc->path_info = val;
}
|
072082 | 2001-03-13 | Martin Nilsson | | if(converter[var])
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | return c->misc[converter[var]]=val;
return c->misc->scope_page[var]=val;
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
array(string) _indices(void|RXML.Context c) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
bf2403 | 2001-06-29 | Martin Nilsson | | array ind=indices(c->misc->scope_page) +
|
4c3c5d | 2002-10-15 | Marcus Wellhardh | | ({ "pathinfo", "realfile", "virtroot", "mountpoint", "virtfile", "path", "query",
|
91950b | 2016-05-20 | Henrik Grubbström (Grubba) | | "url", "post-data", "last-true", "language", "scope", "filesize", "self",
|
bf2403 | 2001-06-29 | Martin Nilsson | | "ssl-strength", "dir", "counter" });
|
072082 | 2001-03-13 | Martin Nilsson | | foreach(indices(converter), string def)
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | if(c->misc[converter[def]]) ind+=({def});
|
1a4071 | 2006-02-27 | Jonas Wallden | | return Array.uniq(ind);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
216531 | 2001-03-01 | Martin Stjernholm | | void _m_delete (string var, void|RXML.Context c, void|string scope_name) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
971ed3 | 2000-03-20 | Martin Stjernholm | | switch (var) {
case "pathinfo":
predef::m_delete (c->id->misc, "pathinfo");
return;
}
|
072082 | 2001-03-13 | Martin Nilsson | | if(converter[var]) {
|
69e4cd | 2000-03-09 | Martin Stjernholm | | if(var[0..4]=="theme")
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | predef::m_delete(c->misc, converter[var]);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | else
|
216531 | 2001-03-01 | Martin Stjernholm | | ::_m_delete(var, c, scope_name);
|
971ed3 | 2000-03-20 | Martin Stjernholm | | return;
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | predef::m_delete(c->misc->scope_page, var);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
7e4e99 | 2006-12-11 | Martin Stjernholm | | string _sprintf (int flag) { return flag == 'O' && "RXML.Scope(page)"; }
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
703503 | 2000-08-23 | Martin Nilsson | | class ScopeCookie {
inherit RXML.Scope;
|
69e4cd | 2000-03-09 | Martin Stjernholm | |
|
216531 | 2001-03-01 | Martin Stjernholm | | mixed `[] (string var, void|RXML.Context c, void|string scope, void|RXML.Type type) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
1aa164 | 2009-04-21 | Martin Stjernholm | | if (c->id->conf->compat_level() < 5.0)
c->id->set_max_cache (0);
|
a527c3 | 2001-03-24 | Martin Nilsson | | return ENCODE_RXML_TEXT(c->id->cookies[var], type);
|
703503 | 2000-08-23 | Martin Nilsson | | }
mixed `[]= (string var, mixed val, void|RXML.Context c, void|string scope_name) {
|
216531 | 2001-03-01 | Martin Stjernholm | | if (mixed err = catch (val = (string) val || ""))
RXML.parse_error ("Cannot set cookies of type %t.\n", val);
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
if(c->id->cookies[var]!=val) {
|
778369 | 2002-06-24 | Martin Stjernholm | |
|
703503 | 2000-08-23 | Martin Nilsson | | c->id->cookies[var]=val;
|
778369 | 2002-06-24 | Martin Stjernholm | | add_http_header(c->misc[" _extra_heads"], "Set-Cookie", http_encode_cookie(var)+
"="+http_encode_cookie( val )+
"; expires="+http_date(time(1)+(3600*24*365*2))+"; path=/");
|
9bf118 | 2000-08-12 | Martin Stjernholm | | }
|
216531 | 2001-03-01 | Martin Stjernholm | | return val;
|
703503 | 2000-08-23 | Martin Nilsson | | }
array(string) _indices(void|RXML.Context c) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
|
1aa164 | 2009-04-21 | Martin Stjernholm | | if (c->id->conf->compat_level() < 5.0)
c->id->set_max_cache (0);
|
703503 | 2000-08-23 | Martin Nilsson | | return indices(c->id->cookies);
}
|
216531 | 2001-03-01 | Martin Stjernholm | | void _m_delete (string var, void|RXML.Context c, void|string scope_name) {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!c) c = RXML_CONTEXT;
if(!c->id->cookies[var]) return;
|
778369 | 2002-06-24 | Martin Stjernholm | |
|
703503 | 2000-08-23 | Martin Nilsson | | predef::m_delete(c->id->cookies, var);
|
778369 | 2002-06-24 | Martin Stjernholm | | add_http_header(c->misc[" _extra_heads"], "Set-Cookie",
http_encode_cookie(var)+"=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/");
|
703503 | 2000-08-23 | Martin Nilsson | | }
|
7e4e99 | 2006-12-11 | Martin Stjernholm | | string _sprintf (int flag) { return flag == 'O' && "RXML.Scope(Cookie)"; }
|
703503 | 2000-08-23 | Martin Nilsson | | }
|
6ad1bb | 2004-06-08 | Fredrik Noring | | RXML.Scope scope_request_header=ScopeRequestHeader();
|
703503 | 2000-08-23 | Martin Nilsson | | RXML.Scope scope_roxen=ScopeRoxen();
RXML.Scope scope_page=ScopePage();
RXML.Scope scope_cookie=ScopeCookie();
|
9bf118 | 2000-08-12 | Martin Stjernholm | |
|
3c4c6e | 2000-11-02 | Per Hedbor | | class ScopeModVar
{
class Modules( mapping module, string sname )
{
class ModVars( RoxenModule mod )
{
class Var(object var )
{
inherit RXML.Value;
mixed cast( string type )
{
switch( type )
{
case "string": return (string)var->query();
case "int": return (int)var->query();
case "float": return (float)var->query();
case "array": return (array)var->query();
}
}
mixed rxml_var_eval( RXML.Context ctx, string vn, string scp,
void|RXML.Type type )
{
mixed res = var->query();
if( type )
res = type->encode( res );
return res;
}
}
mixed cast( string type )
{
switch( type )
{
case "string":
return roxenp()->find_module( sname ) ?
roxenp()->find_module( sname )->get_name() : sname;
}
}
array _indices()
{
mapping m = mod->getvars();
return sort( filter( indices(m),
lambda(string n) {
return m[n]->get_flags()&VAR_PUBLIC;
} ) );
}
mixed `[]( string what )
{
object var;
if( (var = mod->getvar( what )) )
{
if( (var->get_flags() & VAR_PUBLIC) )
return Var( var );
else
RXML.parse_error("The variable "+what+" is not public\n");
} else
RXML.parse_error("The variable "+what+" does not exist\n");
}
}
mixed cast( string type )
{
switch( type )
{
case "string":
return roxenp()->find_module( sname ) ?
roxenp()->find_module( sname )->get_name() : sname;
}
}
array _indices()
{
return sort(indices( module ));
}
mixed `[]( string what )
{
mixed mod;
if( (mod = (int)what) )
if( (mod = module[ mod-1 ]) )
return ModVars( module[mod-1] );
|
343ee6 | 2000-11-06 | Per Hedbor | |
|
3c4c6e | 2000-11-02 | Per Hedbor | | return ModVars( values( module )[0] )[ what ];
}
}
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | mixed `[]( string what, void|RXML.Context ctx )
|
3c4c6e | 2000-11-02 | Per Hedbor | | {
if( what == "global" )
return Modules( ([ 0:roxenp() ]), "roxen" );
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!ctx) ctx = RXML_CONTEXT;
if( what == "site" )
return Modules( ([ 0: ctx->id->conf ]), "site" );
if( !ctx->id->conf->modules[ what ] )
|
3c4c6e | 2000-11-02 | Per Hedbor | | RXML.parse_error("The module "+what+" does not exist\n");
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | return Modules( ctx->id->conf->modules[ what ], what );
|
3c4c6e | 2000-11-02 | Per Hedbor | | }
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | array _indices (void|RXML.Context ctx)
|
3c4c6e | 2000-11-02 | Per Hedbor | | {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | return ({ "global", "site" }) +
sort(indices((ctx || RXML_CONTEXT)->id->conf->modules));
|
3c4c6e | 2000-11-02 | Per Hedbor | | }
}
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | ScopeModVar scope_modvar = ScopeModVar();
class FormScope
|
3c4c6e | 2000-11-02 | Per Hedbor | | {
inherit RXML.Scope;
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | mixed `[]=( string index, mixed newval, void|RXML.Context ctx )
|
8c6fbe | 2000-11-02 | Per Hedbor | | {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if(!ctx) ctx = RXML_CONTEXT;
|
9d262a | 2001-04-18 | Per Hedbor | | if( arrayp( newval ) )
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | ctx->id->real_variables[ index ] = newval;
|
9d262a | 2001-04-18 | Per Hedbor | | else
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | ctx->id->real_variables[ index ] = ({ newval });
|
9d262a | 2001-04-18 | Per Hedbor | | return newval;
|
8c6fbe | 2000-11-02 | Per Hedbor | | }
|
216531 | 2001-03-01 | Martin Stjernholm | | mixed `[] (string what, void|RXML.Context ctx,
void|string scope_name, void|RXML.Type type)
|
3c4c6e | 2000-11-02 | Per Hedbor | | {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if (!ctx) ctx = RXML_CONTEXT;
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | mapping variables = ctx->id->real_variables;
|
a527c3 | 2001-03-24 | Martin Nilsson | | if( zero_type(variables[what]) ) return RXML.nil;
|
3c4c6e | 2000-11-02 | Per Hedbor | | mixed q = variables[ what ];
|
216531 | 2001-03-01 | Martin Stjernholm | | if( arrayp(q) && sizeof( q ) == 1 )
q = q[0];
|
3cd919 | 2001-03-12 | Martin Stjernholm | | if (type && !(objectp (q) && q->rxml_var_eval)) {
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | if (arrayp(q) && type->subtype_of (RXML.t_any_text))
|
216531 | 2001-03-01 | Martin Stjernholm | | q *= "\0";
return type->encode (q);
}
else return q;
|
3c4c6e | 2000-11-02 | Per Hedbor | | }
|
f2fbdd | 2001-09-18 | Martin Stjernholm | | void _m_delete (string var, void|RXML.Context ctx, void|string scope_name)
{
if (!ctx) ctx = RXML_CONTEXT;
predef::m_delete (ctx->id->real_variables, var);
}
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | array _indices( void|RXML.Context ctx )
|
3c4c6e | 2000-11-02 | Per Hedbor | | {
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | | if(!ctx) ctx = RXML_CONTEXT;
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | return indices( ctx->id->real_variables );
|
3c4c6e | 2000-11-02 | Per Hedbor | | }
}
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | FormScope scope_form = FormScope();
|
3c4c6e | 2000-11-02 | Per Hedbor | |
|
69e4cd | 2000-03-09 | Martin Stjernholm | | RXML.TagSet entities_tag_set = class
{
inherit RXML.TagSet;
|
f1fae2 | 2003-06-24 | Henrik Grubbström (Grubba) | | void entities_prepare_context (RXML.Context c) {
|
6ad1bb | 2004-06-08 | Fredrik Noring | | c->add_scope("request-header", scope_request_header);
|
8b43d5 | 2002-02-13 | Marcus Wellhardh | | c->misc->scope_roxen=([]);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | c->add_scope("roxen",scope_roxen);
|
8c6e81 | 2001-06-18 | Martin Stjernholm | | c->misc->scope_page=([]);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | c->add_scope("page",scope_page);
|
703503 | 2000-08-23 | Martin Nilsson | | c->add_scope("cookie", scope_cookie);
|
3c4c6e | 2000-11-02 | Per Hedbor | | c->add_scope("modvar", scope_modvar);
|
3e8ae9 | 2001-04-21 | Martin Nilsson | | c->add_scope("form", scope_form );
|
703503 | 2000-08-23 | Martin Nilsson | | c->add_scope("client", c->id->client_var);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | c->add_scope("var", ([]) );
}
|
3fe8a1 | 2001-06-28 | Martin Stjernholm | | void create()
|
69e4cd | 2000-03-09 | Martin Stjernholm | | {
|
dd9a41 | 2001-08-24 | Martin Stjernholm | | ::create (0, "entities_tag_set");
|
f1fae2 | 2003-06-24 | Henrik Grubbström (Grubba) | | prepare_context = entities_prepare_context;
|
7eeec7 | 2000-07-06 | Martin Stjernholm | |
|
9bf118 | 2000-08-12 | Martin Stjernholm | | add_string_entities (parser_charref_table);
|
69e4cd | 2000-03-09 | Martin Stjernholm | | }
|
3fe8a1 | 2001-06-28 | Martin Stjernholm | | }();
|
dbf991 | 2000-03-19 | Martin Nilsson | |
|
b92a1c | 2000-08-14 | Martin Stjernholm | |
|
dbf991 | 2000-03-19 | Martin Nilsson | | constant monthnum=(["Jan":0, "Feb":1, "Mar":2, "Apr":3, "May":4, "Jun":5,
"Jul":6, "Aug":7, "Sep":8, "Oct":9, "Nov":10, "Dec":11,
"jan":0, "feb":1, "mar":2, "apr":3, "may":4, "jun":5,
"jul":6, "aug":7, "sep":8, "oct":9, "nov":10, "dec":11,]);
#define MAX_SINCE_CACHE 16384
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected mapping(string:int) since_cache=([ ]);
|
dbf991 | 2000-03-19 | Martin Nilsson | | array(int) parse_since(string date)
{
if(!date || sizeof(date)<14) return({0,-1});
int t=0, length = -1;
#if constant(mktime)
|
f6deda | 2000-07-11 | Martin Nilsson | | string dat=lower_case(date);
sscanf(dat+"; length=", "%*s, %s; length=%d", dat, length);
|
dbf991 | 2000-03-19 | Martin Nilsson | |
if(!(t=since_cache[dat])) {
int day, year = -1, month, hour, minute, second;
string m;
|
e4b275 | 2009-11-12 | Henrik Grubbström (Grubba) | | if((sscanf(dat, "%d-%d-%d %d:%d:%d", year, month, day, hour, minute, second)>2) ||
(sscanf(dat, "%d-%d-%dT%d:%d:%d", year, month, day, hour, minute, second)>2))
{
} else if(sscanf(dat, "%d-%s-%d %d:%d:%d", day, m, year, hour, minute, second)>2)
|
dbf991 | 2000-03-19 | Martin Nilsson | | {
month=monthnum[m];
} else if(!(int)dat) {
sscanf(dat, "%*[^ ] %s %d %d:%d:%d %d", m, day, hour, minute, second, year);
month=monthnum[m];
} else {
sscanf(dat, "%d %s %d %d:%d:%d", day, m, year, hour, minute, second);
month=monthnum[m];
}
if(year >= 0) {
if (year < 60) {
year += 100;
} else if (year >= 1900) {
year -= 1900;
}
catch {
|
df6c03 | 2000-08-09 | Per Hedbor | | t = mktime(second, minute, hour, day, month, year, 0, 0);
|
dbf991 | 2000-03-19 | Martin Nilsson | | };
} else {
report_debug("Could not parse \""+date+"\" to a time int.");
}
if (sizeof(since_cache) > MAX_SINCE_CACHE)
since_cache = ([]);
since_cache[dat]=t;
}
#endif /* constant(mktime) */
return ({ t, length });
}
int is_modified(string a, int t, void|int len)
{
array vals=parse_since(a);
if(len && len!=vals[1]) return 0;
if(vals[0]<t) return 0;
return 1;
}
|
f9eeaf | 2001-08-20 | Martin Nilsson | |
|
dbf991 | 2000-03-19 | Martin Nilsson | | int httpdate_to_time(string date)
{
return parse_since(date)[0]||-1;
}
|
31d164 | 2000-03-26 | Martin Nilsson | |
|
3580f5 | 2000-09-03 | Per Hedbor | | void set_cookie( RequestID id,
string name,
string value,
int|void expire_time_delta,
string|void domain,
|
4e27e7 | 2016-04-29 | Henrik Grubbström (Grubba) | | int(0..1)|string|void path,
int(0..1)|string|void secure,
int(0..1)|string|void httponly)
|
c9d28f | 2002-01-29 | Martin Stjernholm | |
|
3580f5 | 2000-09-03 | Per Hedbor | |
|
cf1319 | 2001-09-25 | Martin Nilsson | |
|
3580f5 | 2000-09-03 | Per Hedbor | |
|
cf1319 | 2001-09-25 | Martin Nilsson | |
|
3580f5 | 2000-09-03 | Per Hedbor | | {
|
52049e | 2000-12-04 | Stefan Wallström | | if( expire_time_delta == -1 )
|
3580f5 | 2000-09-03 | Per Hedbor | | expire_time_delta = (3600*(24*365*5));
string cookie = (http_encode_cookie( name )+"="+
http_encode_cookie( value ));
|
cf1319 | 2001-09-25 | Martin Nilsson | |
if( expire_time_delta == -2 )
cookie += "; expires="+http_date(1)+"; Max-Age=0";
|
a73c07 | 2003-03-20 | Anders Johansson | | else if( expire_time_delta )
|
3580f5 | 2000-09-03 | Per Hedbor | | cookie += "; expires="+http_date( expire_time_delta+time(1) );
|
cf1319 | 2001-09-25 | Martin Nilsson | |
|
3580f5 | 2000-09-03 | Per Hedbor | | if( domain ) cookie += "; domain="+http_encode_cookie( domain );
|
cf1319 | 2001-09-25 | Martin Nilsson | | if( path!=1 ) cookie += "; path="+http_encode_cookie( path||"" );
|
072e5b | 2012-03-12 | Rineke Bos | | if( secure ) cookie += "; secure";
if( httponly ) cookie += "; HttpOnly";
|
c9d28f | 2002-01-29 | Martin Stjernholm | | id->add_response_header ("Set-Cookie", cookie);
|
3580f5 | 2000-09-03 | Per Hedbor | | }
void remove_cookie( RequestID id,
string name,
string value,
string|void domain,
string|void path )
{
|
cf1319 | 2001-09-25 | Martin Nilsson | | set_cookie( id, name, value, -2, domain, path );
|
3580f5 | 2000-09-03 | Per Hedbor | | }
|
c9dd7f | 2000-11-21 | Per Hedbor | | void add_cache_stat_callback( RequestID id, string file, int mtime )
{
while( id->misc->orig )
id = id->misc->orig;
if( !id->misc->_cachecallbacks ) return;
id->misc->_cachecallbacks += ({ lambda( RequestID id, object key ) {
Stat st = file_stat( file );
if( !st || (st[ST_MTIME] != mtime) )
{
destruct( key );
return 0;
}
return 1;
} });
}
|
c3c632 | 2000-09-20 | Per Hedbor | | void add_cache_callback( RequestID id,function(RequestID,object:int) callback )
|
a45647 | 2000-08-31 | Per Hedbor | |
|
c3c632 | 2000-09-20 | Per Hedbor | |
|
a45647 | 2000-08-31 | Per Hedbor | | {
while( id->misc->orig )
id = id->misc->orig;
|
129ed7 | 2000-09-25 | Per Hedbor | | if( !id->misc->_cachecallbacks ) return;
|
a45647 | 2000-08-31 | Per Hedbor | | id->misc->_cachecallbacks |= ({ callback });
}
|
f7bc8a | 2001-07-21 | Martin Stjernholm | | string get_server_url(Configuration c)
|
fbe1f0 | 2001-07-25 | Martin Stjernholm | |
|
f7bc8a | 2001-07-21 | Martin Stjernholm | |
|
129ed7 | 2000-09-25 | Per Hedbor | | {
|
b40bd5 | 2001-07-21 | Martin Stjernholm | | return c->get_url();
|
31d164 | 2000-03-26 | Martin Nilsson | | }
|
99f37d | 2013-04-25 | Jonas Walldén | | #ifndef NO_DNS
|
a2e9b1 | 2014-08-15 | Henrik Grubbström (Grubba) | | private array(string) local_addrs;
|
99f37d | 2013-04-25 | Jonas Walldén | | #endif
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | |
|
31d164 | 2000-03-26 | Martin Nilsson | | string get_world(array(string) urls) {
if(!sizeof(urls)) return 0;
|
dc8928 | 2008-12-11 | Jonas Wallden | | string url = urls[0];
mapping(string:Standards.URI) uris = ([ ]);
foreach (urls, string u)
uris[u] = Standards.URI(u);
|
bc0dec | 2001-08-05 | Martin Nilsson | | foreach( ({"http:","https:","ftp:"}), string p)
|
31d164 | 2000-03-26 | Martin Nilsson | | foreach(urls, string u)
|
dc8928 | 2008-12-11 | Jonas Wallden | | if (has_prefix(u, p)) {
uris[u]->fragment = 0;
url = (string) uris[u];
uris[url] = uris[u];
|
31d164 | 2000-03-26 | Martin Nilsson | | break;
}
|
dc8928 | 2008-12-11 | Jonas Wallden | |
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | Standards.URI uri = uris[url];
string server = uri->host;
if (server == "::")
server = "*";
if (!has_value(server, "*")) return (string)uri;
|
5d6323 | 2011-09-21 | Martin Stjernholm | | array hosts=({ gethostname() });
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | |
|
804c05 | 2002-03-14 | Henrik Grubbström (Grubba) | | #ifndef NO_DNS
|
5d6323 | 2011-09-21 | Martin Stjernholm | | array dns;
|
1f6b0c | 2008-12-23 | Martin Stjernholm | | catch(dns=roxen->gethostbyname(hosts[0]));
|
31d164 | 2000-03-26 | Martin Nilsson | | if(dns && sizeof(dns))
hosts+=dns[2]+dns[1];
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | if (!local_addrs) {
string ifconfig =
Process.locate_binary(({ "/sbin", "/usr/sbin", "/bin", "/usr/bin",
"/etc" }), "ifconfig");
local_addrs = dns[1];
if (ifconfig) {
|
814194 | 2011-02-28 | Henrik Grubbström (Grubba) | | foreach(Process.run(({ ifconfig, "-a" }),
([ "env":getenv() +
([
"LC_ALL":"C",
"LANG":"C",
])]))->stdout/"\n", string line) {
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | int i;
while ((i = search(line, "inet")) >= 0) {
line = line[i..];
string addr;
if (has_prefix(line, "inet ")) {
line = line[5..];
} else if (has_prefix(line, "inet6 ")) {
line = line[6..];
}
if (has_prefix(line, "addr: ")) {
line = line[6..];
} else if (has_prefix(line, "addr:")) {
line = line[5..];
}
sscanf(line, "%[^ ]%s", addr, line);
if (addr && sizeof(addr)) {
addr = (addr/"/")[0];
addr = (addr/"%")[0];
local_addrs += ({ addr });
}
}
}
local_addrs = Array.uniq(local_addrs);
}
foreach(local_addrs, string addr) {
|
3e51d3 | 2014-01-14 | Jonas Walldén | |
if (addr == "127.0.0.1" || addr == "::1" || addr == "fe80::1") {
if (addr != "fe80::1")
hosts += ({ "localhost" });
break;
}
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | if ((dns = Protocols.DNS.gethostbyaddr(addr)) && sizeof(dns)) {
if (dns[0]) {
hosts += ({ dns[0] });
}
hosts += dns[1] + ({ addr });
if ((sizeof(dns[2]) != 1) || (dns[2][0] != addr)) {
hosts += dns[2];
}
}
}
hosts = Array.uniq(hosts);
}
|
804c05 | 2002-03-14 | Henrik Grubbström (Grubba) | | #endif /* !NO_DNS */
|
31d164 | 2000-03-26 | Martin Nilsson | |
foreach(hosts, string host)
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | if (glob(server, host)) {
|
dc8928 | 2008-12-11 | Jonas Wallden | | uri->host = host;
|
3af5fe | 2010-03-04 | Henrik Grubbström (Grubba) | | break;
}
|
dc8928 | 2008-12-11 | Jonas Wallden | | return (string) uri;
|
31d164 | 2000-03-26 | Martin Nilsson | | }
|
c16622 | 2000-08-09 | Per Hedbor | |
|
b92a1c | 2000-08-14 | Martin Stjernholm | | RoxenModule get_owning_module (object|function thing)
{
|
566c07 | 2000-11-02 | Per Hedbor | | if (functionp (thing))
thing = function_object (thing);
if (objectp (thing))
{
if (thing->is_module)
return thing;
object o = [object]thing;
while (object parent =
functionp (object_program (o)) &&
function_object (object_program (o)))
{
|
b92a1c | 2000-08-14 | Martin Stjernholm | |
|
566c07 | 2000-11-02 | Per Hedbor | | if (parent->is_module)
return parent;
o = parent;
|
b92a1c | 2000-08-14 | Martin Stjernholm | | }
|
566c07 | 2000-11-02 | Per Hedbor | |
if( thing->_do_return )
return get_owning_module( thing->_do_return );
|
b92a1c | 2000-08-14 | Martin Stjernholm | | }
return 0;
}
Configuration get_owning_config (object|function thing)
{
if (RoxenModule mod = get_owning_module (thing))
return mod->my_configuration();
if (functionp (thing)) thing = function_object (thing);
if (objectp (thing)) {
if (thing->is_configuration) return thing;
if (object parent =
functionp (object_program (thing)) &&
function_object (object_program (thing))) {
if (parent->is_configuration) return parent;
}
}
return 0;
}
|
21e014 | 2008-08-06 | Martin Stjernholm | |
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int dwim_compare(string a0,string b0)
|
21e014 | 2008-08-06 | Martin Stjernholm | | {
string a2="",b2="";
int a1,b1;
sscanf(a0,"%[^0-9]%d%s",a0,a1,a2);
sscanf(b0,"%[^0-9]%d%s",b0,b1,b2);
if (a0>b0) return 1;
if (a0<b0) return -1;
if (a1>b1) return 1;
if (a1<b1) return -1;
if (a2==b2) return 0;
return dwim_compare(a2,b2);
}
|
fc4039 | 2008-08-15 | Martin Stjernholm | | protected int strict_compare (mixed a, mixed b)
|
21e014 | 2008-08-06 | Martin Stjernholm | |
{
if (stringp (a)) {
if (sscanf (a, "%d%*[ \t]%*c", int i) == 2) a = i;
else if (sscanf (a, "%f%*[ \t]%*c", float f) == 2) a = f;
}
if (stringp (b)) {
if (sscanf (b, "%d%*[ \t]%*c", int i) == 2) b = i;
else if (sscanf (b, "%f%*[ \t]%*c", float f) == 2) b = f;
}
int res;
if (mixed err = catch (res = b < a)) {
a = sprintf ("%t", a);
b = sprintf ("%t", b);
res = b < a;
}
if (res)
return 1;
else if (a < b)
return -1;
else
return 0;
}
array(mapping(string:mixed)|object) rxml_emit_sort (
array(mapping(string:mixed)|object) dataset, string sort_spec,
void|float compat_level)
{
array(string) raw_fields = (sort_spec - " ")/"," - ({ "" });
class FieldData {
string name;
int order, string_cast, lcase;
function(mixed,mixed:int) compare;
mapping value_cache = ([]);
};
array(FieldData) fields = allocate (sizeof (raw_fields));
for (int idx = 0; idx < sizeof (raw_fields); idx++) {
string raw_field = raw_fields[idx];
FieldData field = fields[idx] = FieldData |