172054 | 1998-10-04 | Henrik Grubbström (Grubba) | | |
725645 | 1999-12-08 | Per Hedbor | | * $Id: roxen.pike,v 1.367 1999/12/08 12:24:08 per Exp $
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | | *
* The Roxen Challenger main program.
*
* Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.
*/
|
edc9af | 1998-07-11 | David Hedbor | |
|
725645 | 1999-12-08 | Per Hedbor | | constant cvs_version="$Id: roxen.pike,v 1.367 1999/12/08 12:24:08 per Exp $";
|
34d3fa | 1999-04-22 | Per Hedbor | |
object backend_thread;
|
855c39 | 1999-11-29 | Per Hedbor | | ArgCache argcache;
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
4dd97c | 1996-12-04 | Per Hedbor | | #define IN_ROXEN
|
8540e1 | 1997-06-14 | Francesco Chemolli | | #include <roxen.h>
#include <config.h>
|
b1fca0 | 1996-11-12 | Per Hedbor | | #include <module.h>
#include <variables.h>
|
753a83 | 1999-08-30 | Per Hedbor | | #include <stat.h>
|
14179b | 1997-01-29 | Per Hedbor | |
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
753a83 | 1999-08-30 | Per Hedbor | | inherit "global_variables";
|
b1fca0 | 1996-11-12 | Per Hedbor | | inherit "hosts";
inherit "disk_cache";
inherit "language";
|
2ff846 | 1999-09-02 | Per Hedbor | | inherit "supports";
|
7c92b9 | 1998-11-19 | Per Hedbor | |
|
992083 | 1999-12-07 | Martin Stjernholm | |
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | |
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
constant __roxen_version__ = "1.4";
|
c5e096 | 1999-10-04 | Per Hedbor | | constant __roxen_build__ = "0";
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
#ifdef __NT__
|
753a83 | 1999-08-30 | Per Hedbor | | string real_version= "Roxen Challenger/"+__roxen_version__+"."+__roxen_build__+" NT";
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #else
|
753a83 | 1999-08-30 | Per Hedbor | | string real_version= "Roxen Challenger/"+__roxen_version__+"."+__roxen_build__;
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #endif
|
855c39 | 1999-11-29 | Per Hedbor | |
|
7c92b9 | 1998-11-19 | Per Hedbor | |
|
855c39 | 1999-11-29 | Per Hedbor | |
class RoxenModule
{
constant is_module=1;
constant module_type = 0;
constant module_unique = 1;
string|mapping(string:string) module_name;
string|mapping(string:string) module_doc;
array(int|string|mapping) register_module();
string file_name_and_stuff();
void start(void|int num, void|object conf);
void defvar(string var, mixed value, string name,
int type, string|void doc_str, mixed|void misc,
int|function|void not_in_config);
void definvisvar(string name, int value, int type, array|void misc);
void deflocaledoc( string locale, string variable,
string name, string doc,
mapping|void translate );
int killvar(string var);
string check_variable( string s, mixed value );
mixed query(string|void var, int|void ok);
void set(string var, mixed value);
int setvars( mapping (string:mixed) vars );
string query_internal_location();
string query_location();
string query_provides();
array query_seclevels();
array(int) stat_file(string f, RequestID id);
array(String) find_dir(string f, RequestID id);
mapping(string:array(mixed)) find_dir_stat(string f, RequestID id);
string real_file(string f, RequestID id);
void save();
mapping api_functions();
mapping query_tag_callers();
mapping query_container_callers();
mapping query_if_callers();
string info(object conf);
string comment();
}
|
7c92b9 | 1998-11-19 | Per Hedbor | | class RequestID
{
object conf;
int time;
string raw_url;
int do_not_disconnect;
mapping (string:string) variables;
mapping (string:mixed) misc;
mapping (string:string) cookies;
mapping (string:string) request_headers;
|
df4fbf | 1999-10-10 | Francesco Chemolli | | mapping (string:mixed) throttle;
|
7c92b9 | 1998-11-19 | Per Hedbor | | multiset(string) prestate;
multiset(string) config;
multiset(string) supports;
multiset(string) pragma;
array(string) client;
array(string) referer;
Stdio.File my_fd;
string prot;
string clientprot;
string method;
string realfile;
string virtfile;
string rest_query;
string raw;
string query;
string not_query;
string extra_extension;
string data;
string leftovers;
array (int|string) auth;
string rawauth;
string realauth;
string since;
|
e682c1 | 1998-11-22 | Per Hedbor | | string remoteaddr;
string host;
void create(object|void master_request_id);
|
7c92b9 | 1998-11-19 | Per Hedbor | | void send(string|object what, int|void len);
string scan_for_query( string in );
void end(string|void s, int|void keepit);
void ready_to_receive();
void send_result(mapping|void result);
RequestID clone_me();
};
|
596425 | 1999-11-19 | Per Hedbor | | mapping old_programs = set_weak_flag( ([]),1 );
|
7c92b9 | 1998-11-19 | Per Hedbor | |
|
596425 | 1999-11-19 | Per Hedbor | | string filename( program|object o )
|
95b69e | 1999-09-05 | Per Hedbor | | {
|
596425 | 1999-11-19 | Per Hedbor | | if( objectp( o ) )
o = object_program( o );
string fname = search( master()->programs, o );
if( !fname )
if( old_programs[ o ] )
|
b42206 | 1999-11-19 | Per Hedbor | | fname = old_programs[ o ];
|
596425 | 1999-11-19 | Per Hedbor | | if( !fname )
fname = "Unknown Program";
return fname-(getcwd()+"/");
|
95b69e | 1999-09-05 | Per Hedbor | | }
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #ifdef THREADS
|
855c39 | 1999-11-29 | Per Hedbor | | Thread.Mutex euid_egid_lock = Thread.Mutex();
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #endif /* THREADS */
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | int privs_level;
|
c5e096 | 1999-10-04 | Per Hedbor | | static class Privs
{
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #if efun(seteuid)
int saved_uid;
int saved_gid;
int new_uid;
int new_gid;
#define LOGP (variables && variables->audit && GLOBVAR(audit))
#if constant(geteuid) && constant(getegid) && constant(seteuid) && constant(setegid)
#define HAVE_EFFECTIVE_USER
#endif
static private string _getcwd()
{
if (catch{return(getcwd());}) {
return("Unknown directory (no x-bit on current directory?)");
}
}
static private string dbt(array t)
{
if(!arrayp(t) || (sizeof(t)<2)) return "";
return (((t[0]||"Unknown program")-(_getcwd()+"/"))-"base_server/")+":"+t[1]+"\n";
}
#ifdef THREADS
|
b84a16 | 1999-06-07 | Martin Stjernholm | | static mixed mutex_key;
|
d3a71c | 1999-04-20 | Martin Stjernholm | | static object threads_disabled;
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #endif /* THREADS */
int p_level;
void create(string reason, int|string|void uid, int|string|void gid)
{
#ifdef PRIVS_DEBUG
werror(sprintf("Privs(%O, %O, %O)\n"
"privs_level: %O\n",
reason, uid, gid, privs_level));
#endif /* PRIVS_DEBUG */
#ifdef HAVE_EFFECTIVE_USER
array u;
#ifdef THREADS
if (euid_egid_lock) {
catch { mutex_key = euid_egid_lock->lock(); };
}
|
d3a71c | 1999-04-20 | Martin Stjernholm | | threads_disabled = _disable_threads();
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | #endif /* THREADS */
p_level = privs_level++;
if(getuid()) return;
saved_uid = geteuid();
saved_gid = getegid();
seteuid(0);
|
c5e096 | 1999-10-04 | Per Hedbor | | if(stringp(uid) && (replace(uid,"0123456789"/"",({""})*10)==""))
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | uid = (int)uid;
|
c5e096 | 1999-10-04 | Per Hedbor | |
if(stringp(gid) && (replace(gid, "0123456789"/"", ({"" })*10 == "")))
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | gid = (int)gid;
|
c5e096 | 1999-10-04 | Per Hedbor | | if(!stringp(uid))
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | u = getpwuid(uid);
|
c5e096 | 1999-10-04 | Per Hedbor | | else
{
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | u = getpwnam(uid);
if(u)
uid = u[2];
}
|
c5e096 | 1999-10-04 | Per Hedbor | | if(u && !gid)
gid = u[3];
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
|
c5e096 | 1999-10-04 | Per Hedbor | | if(!u)
{
if (uid && (uid != "root"))
{
if (intp(uid) && (uid >= 60000))
{
|
b84a16 | 1999-06-07 | Martin Stjernholm | | report_warning(sprintf("Privs: User %d is not in the password database.\n"
"Assuming nobody.\n", uid));
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
gid = gid || uid;
u = ({ "fake-nobody", "x", uid, gid, "A real nobody", "/", "/sbin/sh" });
} else {
error("Unknown user: "+uid+"\n");
}
} else {
u = ({ "root", "x", 0, gid, "The super-user", "/", "/sbin/sh" });
}
}
if(LOGP)
report_notice(sprintf("Change to %s(%d):%d privs wanted (%s), from %s",
(string)u[0], (int)uid, (int)gid,
(string)reason,
(string)dbt(backtrace()[-2])));
#if efun(cleargroups)
catch { cleargroups(); };
#endif /* cleargroups */
#if efun(initgroups)
catch { initgroups(u[0], u[3]); };
#endif
gid = gid || getgid();
int err = (int)setegid(new_gid = gid);
if (err < 0) {
|
07c992 | 1999-11-23 | Per Hedbor | | report_warning(sprintf("Privs: WARNING: Failed to set the effective group id to %d!\n"
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | "Check that your password database is correct for user %s(%d),\n"
"and that your group database is correct.\n",
gid, (string)u[0], (int)uid));
int gid2 = gid;
#ifdef HPUX_KLUDGE
if (gid >= 60000) {
perror("Privs: WARNING: Assuming nobody-group.\n"
"Trying some alternatives...\n");
foreach(({ 60001, 65534, -2 }), gid2) {
perror("%d... ", gid2);
if (initgroups(u[0], gid2) >= 0) {
if ((err = setegid(new_gid = gid2)) >= 0) {
perror("Success!\n");
break;
}
}
}
}
#endif /* HPUX_KLUDGE */
if (err < 0) {
perror("Privs: Failed\n");
throw(({ sprintf("Failed to set EGID to %d\n", gid), backtrace() }));
}
perror("Privs: WARNING: Set egid to %d instead of %d.\n",
gid2, gid);
gid = gid2;
}
if(getgid()!=gid) setgid(gid||getgid());
seteuid(new_uid = uid);
#endif /* HAVE_EFFECTIVE_USER */
}
void destroy()
{
#ifdef PRIVS_DEBUG
werror(sprintf("Privs->destroy()\n"
"privs_level: %O\n",
privs_level));
#endif /* PRIVS_DEBUG */
#ifdef HAVE_EFFECTIVE_USER
if (p_level >= privs_level) {
report_error(sprintf("Change back to uid#%d gid#%d from uid#%d gid#%d\n"
"in wrong order! Saved level:%d Current level:%d\n"
"Occurs in:\n%s\n",
saved_uid, saved_gid, new_uid, new_gid,
p_level, privs_level,
describe_backtrace(backtrace())));
return(0);
}
if (p_level != privs_level-1) {
report_error(sprintf("Change back to uid#%d gid#%d from uid#%d gid#%d\n"
"Skips privs level. Saved level:%d Current level:%d\n"
"Occurs in:\n%s\n",
saved_uid, saved_gid, new_uid, new_gid,
p_level, privs_level,
describe_backtrace(backtrace())));
}
privs_level = p_level;
if(LOGP) {
catch {
array bt = backtrace();
if (sizeof(bt) >= 2) {
|
d3a71c | 1999-04-20 | Martin Stjernholm | | report_notice(sprintf("Change back to uid#%d gid#%d, from %s\n",
saved_uid, saved_gid, dbt(bt[-2])));
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | } else {
|
d3a71c | 1999-04-20 | Martin Stjernholm | | report_notice(sprintf("Change back to uid#%d gid#%d, from backend\n",
saved_uid, saved_gid));
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | | }
};
}
if(getuid()) return;
#ifdef DEBUG
int uid = geteuid();
if (uid != new_uid) {
report_warning(sprintf("Privs: UID #%d differs from expected #%d\n"
"%s\n",
uid, new_uid, describe_backtrace(backtrace())));
}
int gid = getegid();
if (gid != new_gid) {
report_warning(sprintf("Privs: GID #%d differs from expected #%d\n"
"%s\n",
gid, new_gid, describe_backtrace(backtrace())));
}
#endif /* DEBUG */
seteuid(0);
array u = getpwuid(saved_uid);
#if efun(cleargroups)
catch { cleargroups(); };
#endif /* cleargroups */
if(u && (sizeof(u) > 3)) {
catch { initgroups(u[0], u[3]); };
}
setegid(saved_gid);
seteuid(saved_uid);
#endif /* HAVE_EFFECTIVE_USER */
}
#endif /* efun(seteuid) */
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
static object PRIVS(string r, int|string|void u, int|string|void g)
{
return Privs(r, u, g);
}
|
0f8c87 | 1997-06-01 | Henrik Grubbström (Grubba) | | #ifdef MODULE_DEBUG
|
95b69e | 1999-09-05 | Per Hedbor | | #define MD_PERROR(X) roxen_perror X;
|
0f8c87 | 1997-06-01 | Henrik Grubbström (Grubba) | | #else
#define MD_PERROR(X)
#endif /* MODULE_DEBUG */
|
2ff846 | 1999-09-02 | Per Hedbor | | #ifndef THREADS
|
b796b5 | 1998-11-18 | Per Hedbor | | class container
{
mixed value;
mixed set(mixed to)
{
return value=to;
}
mixed get()
{
return value;
}
}
|
2ff846 | 1999-09-02 | Per Hedbor | | #endif
|
b796b5 | 1998-11-18 | Per Hedbor | |
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | |
|
d00fcc | 1999-09-05 | Per Hedbor | | Locale.Roxen.standard default_locale=Locale.Roxen.standard;
|
fb7ef9 | 1998-11-02 | Per Hedbor | | object fonts;
|
c5e096 | 1999-10-04 | Per Hedbor | | #if constant( thread_local )
|
59912f | 1998-10-15 | Henrik Grubbström (Grubba) | | object locale = thread_local();
#else
|
df022f | 1998-11-22 | Per Hedbor | | object locale = container();
|
59912f | 1998-10-15 | Henrik Grubbström (Grubba) | | #endif /* THREADS */
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
59912f | 1998-10-15 | Henrik Grubbström (Grubba) | | #define LOCALE LOW_LOCALE->base_server
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | |
|
dca5dc | 1998-09-12 | Per Hedbor | | program Configuration;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
48fa36 | 1997-04-05 | Per Hedbor | | array configurations = ({});
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
4f4bc1 | 1998-02-04 | Per Hedbor | | int die_die_die;
|
506ede | 1997-11-11 | Henrik Grubbström (Grubba) | |
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
a9d811 | 1998-09-01 | Henrik Grubbström (Grubba) | | private static void really_low_shutdown(int exit_code)
{
|
310710 | 1998-09-01 | Marcus Comstedt | | #ifdef THREADS
|
c974c9 | 1999-06-27 | Per Hedbor | | catch( stop_handler_threads() );
|
310710 | 1998-09-01 | Marcus Comstedt | | #endif /* THREADS */
|
a9d811 | 1998-09-01 | Henrik Grubbström (Grubba) | | exit(exit_code);
}
private static void low_shutdown(int exit_code)
{
|
c5e096 | 1999-10-04 | Per Hedbor | | catch
{
configurations->stop();
int pid;
if (exit_code) {
roxen_perror("Restarting Roxen.\n");
} else {
roxen_perror("Shutting down Roxen.\n");
}
};
call_out(really_low_shutdown, 0.01, exit_code);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
a9d811 | 1998-09-01 | Henrik Grubbström (Grubba) | |
|
c974c9 | 1999-06-27 | Per Hedbor | |
|
f4e1b7 | 1999-10-08 | Per Hedbor | | void restart(float|void i)
{
call_out(low_shutdown, i, -1);
}
void shutdown(float|void i)
{
call_out(low_shutdown, i, 0);
}
|
14179b | 1997-01-29 | Per Hedbor | |
|
4820e0 | 1999-07-27 | Henrik Grubbström (Grubba) | |
|
2ff846 | 1999-09-02 | Per Hedbor | | #ifndef THREADS
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
3aaaa7 | 1997-06-12 | Wilhelm Köhler | | void unthreaded_handle(function f, mixed ... args)
{
f(@args);
}
|
34fbbc | 1998-02-05 | Henrik Grubbström (Grubba) | | function handle = unthreaded_handle;
|
2ff846 | 1999-09-02 | Per Hedbor | | #else
|
7277a1 | 1999-09-02 | Per Hedbor | | function handle = threaded_handle;
|
2ff846 | 1999-09-02 | Per Hedbor | | #endif
|
34fbbc | 1998-02-05 | Henrik Grubbström (Grubba) | |
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
34fbbc | 1998-02-05 | Henrik Grubbström (Grubba) | | #ifdef THREADS
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | |
|
34fbbc | 1998-02-05 | Henrik Grubbström (Grubba) | |
|
4f4bc1 | 1998-02-04 | Per Hedbor | | object do_thread_create(string id, function f, mixed ... args)
{
object t = thread_create(f, @args);
catch(t->set_name( id ));
|
c5e096 | 1999-10-04 | Per Hedbor | | #ifdef THREAD_DEBUG
|
dca5dc | 1998-09-12 | Per Hedbor | | roxen_perror(id+" started\n");
|
c5e096 | 1999-10-04 | Per Hedbor | | #endif
|
4f4bc1 | 1998-02-04 | Per Hedbor | | return t;
}
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
310710 | 1998-09-01 | Marcus Comstedt | | static object (Thread.Queue) handle_queue = Thread.Queue();
|
172054 | 1998-10-04 | Henrik Grubbström (Grubba) | |
|
310710 | 1998-09-01 | Marcus Comstedt | | static int thread_reap_cnt;
|
14179b | 1997-01-29 | Per Hedbor | |
void handler_thread(int id)
{
|
4f4bc1 | 1998-02-04 | Per Hedbor | | array (mixed) h, q;
|
34d3fa | 1999-04-22 | Per Hedbor | | while(!die_die_die)
|
4f4bc1 | 1998-02-04 | Per Hedbor | | {
if(q=catch {
|
45cae3 | 1998-03-06 | Henrik Grubbström (Grubba) | | do {
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | | #ifdef THREAD_DEBUG
|
75cdcb | 1999-03-29 | Henrik Grubbström (Grubba) | | werror("Handle thread ["+id+"] waiting for next event\n");
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | | #endif /* THREAD_DEBUG */
|
310710 | 1998-09-01 | Marcus Comstedt | | if((h=handle_queue->read()) && h[0]) {
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | | #ifdef THREAD_DEBUG
|
75cdcb | 1999-03-29 | Henrik Grubbström (Grubba) | | werror(sprintf("Handle thread [%O] calling %O(@%O)...\n",
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | | id, h[0], h[1..]));
#endif /* THREAD_DEBUG */
|
b796b5 | 1998-11-18 | Per Hedbor | | SET_LOCALE(default_locale);
|
45cae3 | 1998-03-06 | Henrik Grubbström (Grubba) | | h[0](@h[1]);
h=0;
|
310710 | 1998-09-01 | Marcus Comstedt | | } else if(!h) {
werror("Handle thread ["+id+"] stopped\n");
thread_reap_cnt--;
return;
|
45cae3 | 1998-03-06 | Henrik Grubbström (Grubba) | | }
} while(1);
}) {
|
600096 | 1999-04-24 | Henrik Grubbström (Grubba) | | report_error(describe_backtrace(q));
|
45cae3 | 1998-03-06 | Henrik Grubbström (Grubba) | | if (q = catch {h = 0;}) {
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | report_error(LOCALE->
uncaught_error(describe_backtrace(q)));
|
45cae3 | 1998-03-06 | Henrik Grubbström (Grubba) | | }
}
|
4f4bc1 | 1998-02-04 | Per Hedbor | | }
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
3aaaa7 | 1997-06-12 | Wilhelm Köhler | | void threaded_handle(function f, mixed ... args)
{
handle_queue->write(({f, args }));
}
|
14179b | 1997-01-29 | Per Hedbor | | int number_of_threads;
void start_handler_threads()
{
|
a60c4c | 1997-07-03 | Henrik Grubbström (Grubba) | | if (QUERY(numthreads) <= 1) {
QUERY(numthreads) = 1;
|
07c992 | 1999-11-23 | Per Hedbor | | report_notice("Starting one thread to handle requests.\n");
|
a60c4c | 1997-07-03 | Henrik Grubbström (Grubba) | | } else {
|
07c992 | 1999-11-23 | Per Hedbor | | report_notice("Starting "+
|
c5e096 | 1999-10-04 | Per Hedbor | | languages["en"]->number( QUERY(numthreads) )
|
2ff846 | 1999-09-02 | Per Hedbor | | +" threads to handle requests.\n");
|
a60c4c | 1997-07-03 | Henrik Grubbström (Grubba) | | }
|
14179b | 1997-01-29 | Per Hedbor | | for(; number_of_threads < QUERY(numthreads); number_of_threads++)
|
4f4bc1 | 1998-02-04 | Per Hedbor | | do_thread_create( "Handle thread ["+number_of_threads+"]",
handler_thread, number_of_threads );
|
14179b | 1997-01-29 | Per Hedbor | | }
|
06583f | 1997-09-03 | Per Hedbor | |
|
310710 | 1998-09-01 | Marcus Comstedt | | void stop_handler_threads()
{
|
95b69e | 1999-09-05 | Per Hedbor | | int timeout=10;
|
2ff846 | 1999-09-02 | Per Hedbor | | roxen_perror("Stopping all request handler threads.\n");
|
310710 | 1998-09-01 | Marcus Comstedt | | while(number_of_threads>0) {
number_of_threads--;
handle_queue->write(0);
thread_reap_cnt++;
}
while(thread_reap_cnt) {
if(--timeout<=0) {
|
2ff846 | 1999-09-02 | Per Hedbor | | roxen_perror("Giving up waiting on threads!\n");
|
310710 | 1998-09-01 | Marcus Comstedt | | return;
}
|
34d3fa | 1999-04-22 | Per Hedbor | | sleep(0.1);
|
310710 | 1998-09-01 | Marcus Comstedt | | }
}
|
95e2b4 | 1997-05-25 | Wilhelm Köhler | | #endif /* THREADS */
|
14179b | 1997-01-29 | Per Hedbor | |
|
15635b | 1999-10-10 | Per Hedbor | | class fallback_redirect_request
|
4820e0 | 1999-07-27 | Henrik Grubbström (Grubba) | | {
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | string in = "";
string out;
string default_prefix;
int port;
object f;
void die()
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:fallback_redirect_request::die()\n"));
#endif /* SSL3_DEBUG */
#if 0
object dummy = Stdio.File();
if (dummy->open("/dev/null", "rw"))
dummy->dup2(f);
#endif
f->close();
destruct(f);
destruct(this_object());
}
void write_callback(object id)
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:fallback_redirect_request::write_callback()\n"));
#endif /* SSL3_DEBUG */
int written = id->write(out);
if (written <= 0)
die();
out = out[written..];
if (!strlen(out))
die();
}
void read_callback(object id, string s)
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:fallback_redirect_request::read_callback(X, \"%s\")\n", s));
#endif /* SSL3_DEBUG */
in += s;
string name;
string prefix;
if (search(in, "\r\n\r\n") >= 0)
{
array(string) lines = in / "\r\n";
array(string) req = replace(lines[0], "\t", " ") / " ";
if (sizeof(req) < 2)
{
out = "HTTP/1.0 400 Bad Request\r\n\r\n";
}
else
{
if (sizeof(req) == 2)
{
name = req[1];
}
else
{
name = req[1..sizeof(req)-2] * " ";
foreach(Array.map(lines[1..], `/, ":"), array header)
{
if ( (sizeof(header) >= 2) &&
(lower_case(header[0]) == "host") )
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | prefix = "https://" + header[1] - " ";
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | }
}
if (prefix) {
if (prefix[-1] == '/')
prefix = prefix[..strlen(prefix)-2];
prefix = prefix + ":" + port;
} else {
if (!(prefix = default_prefix)) {
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | string ip = (f->query_address(1)/" ")[0];
prefix = "https://" + ip + ":" + port;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | } else if (prefix[..4] == "http:") {
prefix = "https:" + prefix[5..];
}
}
out = sprintf("HTTP/1.0 301 Redirect to secure server\r\n"
"Location: %s%s\r\n\r\n", prefix, name);
}
f->set_read_callback(0);
f->set_write_callback(write_callback);
}
}
void create(object socket, string s, string l, int p)
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:fallback_redirect_request(X, \"%s\", \"%s\", %d)\n", s, l||"CONFIG PORT", p));
#endif /* SSL3_DEBUG */
f = socket;
default_prefix = l;
port = p;
f->set_nonblocking(read_callback, 0, die);
f->set_id(f);
read_callback(f, s);
}
}
|
c5e096 | 1999-10-04 | Per Hedbor | | class Protocol
{
|
761baa | 1999-12-08 | Per Hedbor | | inherit Stdio.Port: port;
|
c5e096 | 1999-10-04 | Per Hedbor | |
constant name = "unknown";
constant supports_ipless = 0;
constant requesthandlerfile = "";
constant default_port = 4711;
int port;
int refs;
string ip;
program requesthandler;
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | array(string) sorted_urls = ({});
mapping(string:mapping) urls = ([]);
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | void ref(string name, mapping data)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | if(urls[name])
return;
|
c5e096 | 1999-10-04 | Per Hedbor | | refs++;
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | urls[name] = data;
sorted_urls = Array.sort_array(indices(urls), lambda(string a, string b) {
return sizeof(a)<sizeof(b);
});
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | void unref(string name)
|
c5e096 | 1999-10-04 | Per Hedbor | | {
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | if(!urls[name])
return;
m_delete(urls, name);
sorted_urls -= ({name});
|
c5e096 | 1999-10-04 | Per Hedbor | | if( !--refs )
destruct( );
}
void got_connection()
{
object q = accept( );
if( !q )
;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | else {
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | requesthandler( q, this_object() );
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | }
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | }
object find_configuration_for_url( string url, RequestID id )
{
|
37c1b3 | 1999-10-12 | Per Hedbor | |
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | foreach( sorted_urls, string in )
{
if( glob( in+"*", url ) )
{
if( urls[in]->path )
|
9699bf | 1999-10-11 | Per Hedbor | | {
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | id->not_query = id->not_query[strlen(urls[in]->path)..];
|
9699bf | 1999-10-11 | Per Hedbor | | id->misc->site_prefix_path = urls[in]->path;
}
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | return urls[ in ]->conf;
}
}
return values( urls )[0]->conf;
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
10bdc5 | 1999-10-08 | Henrik Grubbström (Grubba) | | void set_option_default(string option, mixed value)
{
mapping all_options = QUERY(port_options);
all_options[""][option] = value;
}
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | mixed query_option(string option)
{
mapping(string:mapping(string:mixed)) all_options = QUERY(port_options);
mixed res;
mapping val;
if (val = all_options[name]) {
mapping val2;
if (val2 = val[ip]) {
mapping val3;
if (val3 = val2[port]) {
if (!zero_type(res = val3[option])) {
return res;
}
}
if (!zero_type(res = val2[""][option])) {
return res;
}
}
if (!zero_type(res = val[""][option])) {
return res;
}
}
|
15635b | 1999-10-10 | Per Hedbor | | if( all_options[""] )
return all_options[""][option];
return 0;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | }
|
c5e096 | 1999-10-04 | Per Hedbor | | void create( int pn, string i )
{
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | if (query_option("do_not_bind")) {
report_warning(sprintf("Binding to %s://%s:%d/ disabled\n",
name, ip, port));
destruct();
}
|
c5e096 | 1999-10-04 | Per Hedbor | | if( !requesthandler )
requesthandler = (program)requesthandlerfile;
port = pn;
ip = i;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
|
c5e096 | 1999-10-04 | Per Hedbor | | ::create();
|
b6fb05 | 1999-11-02 | Per Hedbor | | if(!bind( port, got_connection, ip ))
{
report_error("Failed to bind %s://%s:%d/ (%s)\n", (string)name,
(ip||"*"), (int)port, strerror( errno() ));
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
}
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
b6fb05 | 1999-11-02 | Per Hedbor | |
string _sprintf( )
{
return "Protocol("+name+"://"+ip+":"+port+")";
}
|
c5e096 | 1999-10-04 | Per Hedbor | | }
|
4820e0 | 1999-07-27 | Henrik Grubbström (Grubba) | |
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | class SSLProtocol
{
inherit Protocol;
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | | #if constant(Standards) && constant(Standards.PKCS.RSA) && constant(SSL.sslfile)
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | |
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
object ctx;
class destruct_protected_sslfile
{
object sslfile;
mixed `[](string s)
{
return sslfile[s];
}
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | mixed `[]=(string s, mixed val)
{
return sslfile[s] = val;
}
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | mixed `->(string s)
{
return sslfile[s];
}
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | mixed `->=(string s, mixed val)
{
return sslfile[s] = val;
}
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | void destroy()
{
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | if (sslfile) {
sslfile->close();
}
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | }
void create(object q, object ctx)
{
sslfile = SSL.sslfile(q, ctx);
}
}
object accept()
{
object q = ::accept();
if (q) {
return destruct_protected_sslfile(q, ctx);
}
return 0;
}
void create(int pn, string i)
{
ctx = SSL.context();
object privs = Privs("Reading cert file");
string f = Stdio.read_file(query_option("ssl_cert_file") ||
"demo_certificate.pem");
string f2 = query_option("ssl_key_file") &&
Stdio.read_file(query_option("ssl_key_file"));
if (privs)
destruct(privs);
if (!f) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Reading cert-file failed!\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
object msg = Tools.PEM.pem_msg()->init(f);
object part = msg->parts["CERTIFICATE"]
||msg->parts["X509 CERTIFICATE"];
string cert;
if (!part || !(cert = part->decoded_body())) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: No certificate found.\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
if (query_option("ssl_key_file"))
{
if (!f2) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Reading key-file failed!\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
msg = Tools.PEM.pem_msg()->init(f2);
}
function r = Crypto.randomness.reasonably_random()->read;
#ifdef SSL3_DEBUG
werror(sprintf("ssl3: key file contains: %O\n", indices(msg->parts)));
#endif
if (part = msg->parts["RSA PRIVATE KEY"])
{
string key;
if (!(key = part->decoded_body())) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Private rsa key not valid (PEM).\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
object rsa = Standards.PKCS.RSA.parse_private_key(key);
if (!rsa) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Private rsa key not valid (DER).\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
ctx->rsa = rsa;
#ifdef SSL3_DEBUG
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_debug(sprintf("ssl3: RSA key size: %d bits\n", rsa->rsa_size()));
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | #endif
if (rsa->rsa_size() > 512)
{
ctx->short_rsa = Crypto.rsa()->generate_key(512, r);
}
ctx->rsa_mode();
object tbs = Tools.X509.decode_certificate (cert);
if (!tbs) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Certificate not valid (DER).\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
if (!tbs->public_key->rsa->public_key_equal (rsa)) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Certificate and private key do not match.\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
}
else if (part = msg->parts["DSA PRIVATE KEY"])
{
string key;
if (!(key = part->decoded_body())) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Private dsa key not valid (PEM).\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
object dsa = Standards.PKCS.DSA.parse_private_key(key);
if (!dsa) {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: Private dsa key not valid (DER).\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
#ifdef SSL3_DEBUG
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_debug(sprintf("ssl3: Using DSA key.\n"));
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | #endif
dsa->use_random(r);
ctx->dsa = dsa;
ctx->dh_params = SSL.cipher.dh_parameters();
ctx->dhe_dss_mode();
}
else {
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | report_error("ssl3: No private key found.\n");
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | destruct();
return;
}
ctx->certificates = ({ cert });
ctx->random = r;
#if EXPORT
ctx->export_mode();
#endif
::create(pn, i);
}
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | #else /* !constant(SSL.sslfile) */
void create(int pn, string i) {
report_error("No SSL support\n");
destruct();
}
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | #endif /* constant(SSL.sslfile) */
|
b6fb05 | 1999-11-02 | Per Hedbor | |
string _sprintf( )
{
return "SSLProtocol("+name+"://"+ip+":"+port+")";
}
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | }
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
|
761baa | 1999-12-08 | Per Hedbor | | #if constant(HTTPLoop.prog)
class FHTTP
{
inherit Protocol;
constant supports_ipless=1;
constant name = "fhttp";
constant default_port = 80;
int dolog;
int requests, received, sent;
HTTPLoop.Loop l;
Stdio.Port portobj;
mapping flatten_headers( mapping from )
{
mapping res = ([]);
foreach(indices(from), string f)
res[f] = from[f]*", ";
return res;
}
void setup_fake(object o)
{
mapping vars = ([]);
o->extra_extension = "";
o->misc = flatten_headers(o->headers);
o->cmf = 100*1024;
o->cmp = 100*1024;
if(o->method == "POST" && strlen(o->data))
{
mapping variabels = ([]);
switch((o->misc["content-type"]/";")[0])
{
default:
break;
case "multipart/form-data":
object messg = MIME.Message(o->data, o->misc);
mapping misc = o->misc;
foreach(messg->body_parts, object part)
{
if(part->disp_params->filename)
{
vars[part->disp_params->name]=part->getdata();
vars[part->disp_params->name+".filename"]=
part->disp_params->filename;
if(!misc->files)
misc->files = ({ part->disp_params->name });
else
misc->files += ({ part->disp_params->name });
} else {
vars[part->disp_params->name]=part->getdata();
}
}
break;
}
o->variables = vars|o->variables;
}
string contents;
if(contents = o->misc["cookie"])
{
string c;
mapping cookies = ([]);
multiset config = (<>);
o->misc->cookies = contents;
foreach(((contents/";") - ({""})), c)
{
string name, value;
while(sizeof(c) && c[0]==' ') c=c[1..];
if(sscanf(c, "%s=%s", name, value) == 2)
{
value=http_decode_string(value);
name=http_decode_string(name);
cookies[ name ]=value;
if(name == "RoxenConfig" && strlen(value))
config = aggregate_multiset(@(value/"," + ({ })));
}
}
o->cookies = cookies;
o->config = config;
} else {
o->cookies = ([]);
o->config = (<>);
}
if(contents = o->misc->accept)
o->misc->accept = contents/",";
if(contents = o->misc["accept-charset"])
o->misc["accept-charset"] = ({ contents/"," });
if(contents = o->misc["accept-language"])
o->misc["accept-language"] = ({ contents/"," });
if(contents = o->misc["session-id"])
o->misc["session-id"] = ({ contents/"," });
}
void handle_request(object o)
{
setup_fake( o );
handle( o->handle_request, this_object() );
}
int cdel=10;
void do_log()
{
if(l->logp())
{
switch(query("log"))
{
case "None":
l->log_as_array();
break;
case "Commonlog":
object f = Stdio.File( query("log_file"), "wca" );
l->log_as_commonlog_to_file( f );
destruct(f);
break;
}
cdel--;
if(cdel < 1) cdel=1;
} else {
cdel++;
}
call_out(do_log, cdel);
}
void low_adjust_stats(mapping m)
{
|
725645 | 1999-12-08 | Per Hedbor | |
#define PCT(X) ((int)(((X)/(float)(m->total+0.1))*100))
werror("\nCache statistics\n");
m->total = m->hits + m->misses + m->stale;
werror(" %d elements in cache, size is %1.1fKb max is %1.1fMb\n"
" %d cache lookups, %d%% hits, %d%% misses and %d%% stale.\n",
m->entries, m->size/1024.0, m->max_size/(1024*1024.0),
m->total, PCT(m->hits), PCT(m->misses), PCT(m->stale));
|
761baa | 1999-12-08 | Per Hedbor | | array q = values( urls )->conf;
if( sizeof( q ) )
{
q[0]->requests += m->num_request;
q[0]->received += m->received_bytes;
q[0]->sent += m->sent_bytes;
}
requests += m->num_requests;
received += m->received_bytes;
sent += m->sent_bytes;
}
void adjust_stats()
{
call_out(adjust_stats, 2);
low_adjust_stats( l->cache_status() );
}
void create( int pn, string i )
{
requesthandler = (program)"protocols/fhttp.pike";
if (query_option("do_not_bind"))
{
report_warning(sprintf("Binding to %s://%s:%d/ disabled\n",
name, ip, port));
destruct();
return;
}
port = pn;
ip = i;
dolog = (query_option( "log" ) && (query_option( "log" )!="none"));
portobj = Stdio.Port();
if( !portobj->bind( port, 0, ip ) )
{
report_error("Failed to bind %s://%s:%d/ (%s)\n",
name,ip||"*",(int)port, strerror(errno()));
destruct(portobj);
destruct();
return;
}
l = HTTPLoop.Loop( portobj, requesthandler,
handle_request, 0,
(query_option("ram_cache")||20)*1024*1024,
dolog, (query_option("read_timeout")||120) );
call_out(adjust_stats, 10);
if(dolog)
call_out(do_log, 5);
}
}
#endif
|
c5e096 | 1999-10-04 | Per Hedbor | | class HTTP
{
inherit Protocol;
constant supports_ipless = 1;
constant name = "http";
constant requesthandlerfile = "protocols/http.pike";
constant default_port = 80;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | class HTTPS
{
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | inherit SSLProtocol;
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | constant supports_ipless = 0;
constant name = "https";
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | constant requesthandlerfile = "protocols/http.pike";
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | constant default_port = 443;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | #if constant(SSL.sslfile)
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | class http_fallback {
object my_fd;
void ssl_alert_callback(object alert, object|int n, string data)
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:http_fallback(X, %O, \"%s\")\n", n, data));
#endif /* SSL3_DEBUG */
#if 0
werror(sprintf("ssl3->http_fallback: alert(%d, %d)\n"
"seq_num = %s\n"
"data = '%s'", alert->level, alert->description,
(string) n, data));
#endif
if ( (my_fd->current_write_state->seq_num == 0)
&& search(lower_case(data), "http"))
{
object raw_fd = my_fd->socket;
|
60a912 | 1999-10-10 | Henrik Grubbström (Grubba) | | my_fd->socket = 0;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
fallback_redirect_request(raw_fd, data,
my_fd->config &&
my_fd->config->query("MyWorldLocation"),
port);
destruct(my_fd);
destruct(this_object());
}
}
void ssl_accept_callback(object id)
{
#ifdef SSL3_DEBUG
roxen_perror(sprintf("SSL3:ssl_accept_callback(X)\n"));
#endif /* SSL3_DEBUG */
id->set_alert_callback(0);
my_fd = 0;
}
void create(object fd)
{
my_fd = fd;
fd->set_alert_callback(ssl_alert_callback);
fd->set_accept_callback(ssl_accept_callback);
}
}
object accept()
{
object q = ::accept();
if (q) {
http_fallback(q);
}
return q;
}
#endif /* constant(SSL.sslfile) */
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | }
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | class FTP
{
inherit Protocol;
constant supports_ipless = 0;
constant name = "ftp";
constant requesthandlerfile = "protocols/ftp.pike";
constant default_port = 21;
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
int sessions;
int ftp_users;
int ftp_users_now;
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | }
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | | class FTPS
{
inherit SSLProtocol;
constant supports_ipless = 0;
constant name = "ftps";
constant requesthandlerfile = "protocols/ftp.pike";
constant default_port = 21;
int sessions;
int ftp_users;
int ftp_users_now;
}
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | class GOPHER
{
inherit Protocol;
constant supports_ipless = 0;
constant name = "gopher";
constant requesthandlerfile = "protocols/gopher.pike";
constant default_port = 70;
}
class TETRIS
{
inherit Protocol;
constant supports_ipless = 0;
constant name = "tetris";
constant requesthandlerfile = "protocols/tetris.pike";
constant default_port = 2050;
}
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | | class SMTP
{
inherit Protocol;
constant supports_ipless = 1;
constant name = "smtp";
constant requesthandlerfile = "protocols/smtp.pike";
constant default_port = Protocols.Ports.tcp.smtp;
}
class POP3
{
inherit Protocol;
constant supports_ipless = 0;
constant name = "pop3";
constant requesthandlerfile = "protocols/pop3.pike";
constant default_port = Protocols.Ports.tcp.pop3;
}
class IMAP
{
inherit Protocol;
constant supports_ipless = 0;
constant name = "imap";
constant requesthandlerfile = "protocols/imap.pike";
constant default_port = Protocols.Ports.tcp.imap2;
}
|
c5e096 | 1999-10-04 | Per Hedbor | | mapping protocols = ([
|
761baa | 1999-12-08 | Per Hedbor | | #if constant(HTTPLoop.prog)
"fhttp":FHTTP,
#else
"fhttp":HTTP,
#endif
|
c5e096 | 1999-10-04 | Per Hedbor | | "http":HTTP,
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | "ftp":FTP,
|
df36c6 | 1999-10-08 | Henrik Grubbström (Grubba) | |
"https":HTTPS,
"ftps":FTPS,
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | "gopher":GOPHER,
"tetris":TETRIS,
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | |
"smtp":SMTP,
"pop3":POP3,
"imap":IMAP,
|
c5e096 | 1999-10-04 | Per Hedbor | | ]);
mapping(string:mapping) open_ports = ([ ]);
mapping(string:object) urls = ([]);
array sorted_urls = ({});
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | array(string) find_ips_for( string what )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | if( what == "*" || lower_case(what) == "any" )
|
b1fca0 | 1996-11-12 | Per Hedbor | | return 0;
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
15635b | 1999-10-10 | Per Hedbor | | if( is_ip( what ) )
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | return ({ what });
|
c5e096 | 1999-10-04 | Per Hedbor | |
array res = gethostbyname( what );
if( !res || !sizeof( res[1] ) )
report_error( "I cannot possibly bind to "+what+
", that host is unknown. "
"Substituting with ANY\n");
else
|
92898c | 1999-10-10 | Marcus Comstedt | | return Array.uniq(res[1]);
|
c5e096 | 1999-10-04 | Per Hedbor | | }
void unregister_url( string url )
{
|
e7e603 | 1999-11-05 | Per Hedbor | | report_debug("Unregister "+url+"\n");
|
c5e096 | 1999-10-04 | Per Hedbor | | if( urls[ url ] && urls[ url ]->port )
{
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | urls[ url ]->port->unref(url);
|
c5e096 | 1999-10-04 | Per Hedbor | | m_delete( urls, url );
sort_urls();
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
}
|
c5e096 | 1999-10-04 | Per Hedbor | | void sort_urls()
|
1668b2 | 1998-04-23 | Henrik Grubbström (Grubba) | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | sorted_urls = indices( urls );
sort( map( map( sorted_urls, strlen ), `-), sorted_urls );
|
1668b2 | 1998-04-23 | Henrik Grubbström (Grubba) | | }
|
c5e096 | 1999-10-04 | Per Hedbor | | int register_url( string url, object conf )
{
|
07c992 | 1999-11-23 | Per Hedbor | | report_notice("Register "+url+" for "+conf->query_name()+"\n");
|
c5e096 | 1999-10-04 | Per Hedbor | | string protocol;
string host;
int port;
string path;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
ac76fc | 1999-10-07 | Henrik Grubbström (Grubba) | | url = replace( url, "/ANY", "/*" );
url = replace( url, "/any", "/*" );
|
c5e096 | 1999-10-04 | Per Hedbor | |
sscanf( url, "%[^:]://%[^/]%s", protocol, host, path );
sscanf( host, "%[^:]:%d", host, port );
if( strlen( path ) && ( path[-1] == '/' ) )
path = path[..strlen(path)-2];
if( !strlen( path ) )
path = 0;
if( urls[ url ] )
{
if( urls[ url ]->conf != conf )
{
report_error( "Cannot register URL "+url+
", already registerd by " +
urls[ url ]->conf->name + "!\n" );
return 0;
}
|
ddefa6 | 1999-10-04 | Marcus Comstedt | | urls[ url ]->port->ref(url, urls[url]);
|
c5e096 | 1999-10-04 | Per Hedbor | | return 1;
}
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | Protocol prot;
|
c5e096 | 1999-10-04 | Per Hedbor | | if( !( prot = protocols[ protocol ] ) )
{
report_error( "Cannot register URL "+url+
", cannot find the protocol " +
protocol + "!\n" );
return 0;
}
if( !port )
port = prot->default_port;
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | array(string) required_hosts;
|
b6fb05 | 1999-11-02 | Per Hedbor | |
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | required_hosts = find_ips_for( host );
|
b6fb05 | 1999-11-02 | Per Hedbor | | if (!required_hosts)
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | required_hosts = ({ 0 });
|
b6fb05 | 1999-11-02 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | |
mapping m;
if( !( m = open_ports[ protocol ] ) )
m = open_ports[ protocol ] = ([]);
urls[ url ] = ([ "conf":conf, "path":path ]);
sorted_urls += ({ url });
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | int failures;
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | foreach(required_hosts, string required_host) {
if( m[ required_host ] && m[ required_host ][ port ] )
{
m[ required_host ][ port ]->ref(url, urls[url]);
urls[ url ]->port = prot;
continue;
}
if( !m[ required_host ] )
m[ required_host ] = ([ ]);
m[ required_host ][ port ] = prot( port, required_host );
if( !( m[ required_host ][ port ] ) )
{
m_delete( m[ required_host ], port );
failures++;
if (required_host) {
report_warning("Binding the port on IP " + required_host +
|
b6fb05 | 1999-11-02 | Per Hedbor | | " failed\n for URL " + url + "!\n");
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | }
continue;
}
urls[ url ]->port = m[ required_host ][ port ];
m[ required_host ][ port ]->ref(url, urls[url]);
}
if (failures == sizeof(required_hosts)) {
|
c5e096 | 1999-10-04 | Per Hedbor | | m_delete( urls, url );
|
b6fb05 | 1999-11-02 | Per Hedbor | | report_error( "Cannot register URL "+url+"!\n" );
|
dd7e66 | 1999-10-09 | Henrik Grubbström (Grubba) | | sort_urls();
|
c5e096 | 1999-10-04 | Per Hedbor | | return 0;
}
sort_urls();
return 1;
}
object find_configuration( string name )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
9699bf | 1999-10-11 | Per Hedbor | | name = replace( lower_case( replace(name,"-"," ") )-" ", "/", "-" );
|
c5e096 | 1999-10-04 | Per Hedbor | | foreach( configurations, object o )
|
9699bf | 1999-10-11 | Per Hedbor | | {
|
066674 | 1999-12-07 | Henrik Grubbström (Grubba) | | if( (lower_case( replace( replace(o->name, "-"," ") - " " ,
"/", "-" ) ) == name) ||
(lower_case( replace( replace(o->query_name(), "-", " ") - " " ,
"/", "-" ) ) == name) )
|
c5e096 | 1999-10-04 | Per Hedbor | | return o;
|
2856a4 | 1999-11-15 | Per Hedbor | |
|
9699bf | 1999-10-11 | Per Hedbor | | }
|
066674 | 1999-12-07 | Henrik Grubbström (Grubba) | | return 0;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
c5e096 | 1999-10-04 | Per Hedbor | |
int add_new_configuration(string name, string type)
{
}
|
025d22 | 1997-06-01 | Henrik Grubbström (Grubba) | |
|
c5e096 | 1999-10-04 | Per Hedbor | | mapping(string:array(int)) error_log=([]);
|
ec2fe1 | 1997-06-09 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
e99fd4 | 1999-11-17 | Per Hedbor | | void nwrite(string s, int|void perr, int|void type,
int|void mod, int|void conf)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
c5e096 | 1999-10-04 | Per Hedbor | | if (!error_log[type+","+s])
|
9b9f70 | 1997-08-12 | Per Hedbor | | error_log[type+","+s] = ({ time() });
|
c5e096 | 1999-10-04 | Per Hedbor | | else
|
9b9f70 | 1997-08-12 | Per Hedbor | | error_log[type+","+s] += ({ time() });
|
e99fd4 | 1999-11-17 | Per Hedbor | |
if( mod )
{
if( !mod->error_log )
mod->error_log = ([]);
mod->error_log[type+","+s] += ({time()});
}
if( conf )
{
if( !conf->error_log )
conf->error_log = ([]);
conf->error_log[type+","+s] += ({time()});
}
|
c5e096 | 1999-10-04 | Per Hedbor | | if(type >= 1)
|
af4c80 | 1999-11-19 | Per Hedbor | | werror( s );
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | int boot_time =time();
int start_time =time();
|
b1fca0 | 1996-11-12 | Per Hedbor | |
string version()
{
|
71a11e | 1997-08-13 | Henrik Grubbström (Grubba) | | return QUERY(default_ident)?real_version:QUERY(ident);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
public void log(mapping file, object request_id)
{
|
14179b | 1997-01-29 | Per Hedbor | | if(!request_id->conf) return;
request_id->conf->log(file, request_id);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
private object current_user_id_file;
private int current_user_id_number, current_user_id_file_last_mod;
private void restore_current_user_id_number()
{
if(!current_user_id_file)
current_user_id_file = open(configuration_dir + "LASTUSER~", "rwc");
if(!current_user_id_file)
{
call_out(restore_current_user_id_number, 2);
return;
}
current_user_id_number = (int)current_user_id_file->read(100);
current_user_id_file_last_mod = current_user_id_file->stat()[2];
perror("Restoring unique user ID information. (" + current_user_id_number
+ ")\n");
|
323569 | 1998-03-26 | Per Hedbor | | #ifdef FD_DEBUG
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | mark_fd(current_user_id_file->query_fd(), LOCALE->unique_uid_logfile());
|
323569 | 1998-03-26 | Per Hedbor | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
f6d62d | 1997-03-26 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | int increase_id()
{
if(!current_user_id_file)
{
restore_current_user_id_number();
return current_user_id_number+time();
}
if(current_user_id_file->stat()[2] != current_user_id_file_last_mod)
restore_current_user_id_number();
current_user_id_number++;
current_user_id_file->seek(0);
current_user_id_file->write((string)current_user_id_number);
current_user_id_file_last_mod = current_user_id_file->stat()[2];
return current_user_id_number;
}
public string full_status()
{
int tmp;
string res="";
array foo = ({0.0, 0.0, 0.0, 0.0, 0});
if(!sizeof(configurations))
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | return LOCALE->no_servers_enabled();
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
528175 | 1997-11-26 | Henrik Grubbström (Grubba) | | foreach(configurations, object conf)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
88e1cb | 1996-12-07 | David Hedbor | | if(!conf->sent
||!conf->received
||!conf->hsent)
continue;
|
48315a | 1999-11-23 | Per Hedbor | | foo[0] += conf->sent/(1024.0*1024.0)/(float)(time(1)-start_time+1);
foo[1] += conf->sent/(1024.0*1024.0);
foo[2] += conf->hsent/(1024.0*1024.0);
foo[3] += conf->received/(1024.0*1024.0);
|
528175 | 1997-11-26 | Henrik Grubbström (Grubba) | | foo[4] += conf->requests;
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
528175 | 1997-11-26 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | for(tmp = 1; tmp < 4; tmp ++)
{
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(foo[tmp] < 1024.0)
|
27b0e1 | 1996-11-26 | Per Hedbor | | foo[tmp] = sprintf("%.2f MB", foo[tmp]);
|
b1fca0 | 1996-11-12 | Per Hedbor | | else
|
27b0e1 | 1996-11-26 | Per Hedbor | | foo[tmp] = sprintf("%.2f GB", foo[tmp]/1024.0);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
60ecef | 1998-06-13 | Henrik Grubbström (Grubba) | | int uptime = time()-start_time;
int days = uptime/(24*60*60);
int hrs = uptime/(60*60);
int min = uptime/60 - hrs*60;
hrs -= days*24;
|
053e9a | 1998-08-20 | Per Hedbor | | tmp=(int)((foo[4]*600.0)/(uptime+1));
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | return(LOCALE->full_status(real_version, boot_time, start_time-boot_time,
days, hrs, min, uptime%60,
foo[1], foo[0] * 8192.0, foo[2],
foo[4], (float)tmp/(float)10, foo[3]));
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
ee8b20 | 1998-07-13 | David Hedbor | | static int abs_started;
|
6ca8f6 | 1998-10-13 | Per Hedbor | |
void restart_if_stuck (int force)
{
|
ee8b20 | 1998-07-13 | David Hedbor | | remove_call_out(restart_if_stuck);
if (!(QUERY(abs_engage) || force))
|
edc9af | 1998-07-11 | David Hedbor | | return;
|
6ca8f6 | 1998-10-13 | Per Hedbor | | if(!abs_started)
{
|
ee8b20 | 1998-07-13 | David Hedbor | | abs_started = 1;
|
dca5dc | 1998-09-12 | Per Hedbor | | roxen_perror("Anti-Block System Enabled.\n");
|
ee8b20 | 1998-07-13 | David Hedbor | | }
call_out (restart_if_stuck,10);
|
6ca8f6 | 1998-10-13 | Per Hedbor | | signal(signum("SIGALRM"),
lambda( int n ) {
|
b0659e | 1999-07-20 | Henrik Grubbström (Grubba) | | werror(sprintf("**** %s: ABS engaged!\n"
"Trying to dump backlog: \n",
ctime(time()) - "\n"));
catch {
describe_all_threads();
};
werror(sprintf("**** %s: ABS exiting roxen!\n\n",
ctime(time())));
|
6ca8f6 | 1998-10-13 | Per Hedbor | | _exit(1);
});
|
ee8b20 | 1998-07-13 | David Hedbor | | alarm (60*QUERY(abs_timeout)+10);
|
edc9af | 1998-07-11 | David Hedbor | | }
|
6ca8f6 | 1998-10-13 | Per Hedbor | | void post_create ()
{
|
ee8b20 | 1998-07-13 | David Hedbor | | if (QUERY(abs_engage))
call_out (restart_if_stuck,10);
|
edc9af | 1998-07-11 | David Hedbor | | if (QUERY(suicide_engage))
|
ee8b20 | 1998-07-13 | David Hedbor | | call_out (restart,60*60*24*QUERY(suicide_timeout));
|
edc9af | 1998-07-11 | David Hedbor | | }
|
59912f | 1998-10-15 | Henrik Grubbström (Grubba) | |
|
c5e096 | 1999-10-04 | Per Hedbor | |
class ConfigIFCache
{
string dir;
void create( string name )
{
dir = "config_caches/"+replace(configuration_dir-".", "/", "-") + "/" + name + "/";
mkdirhier( dir+"/foo" );
}
mixed set( string name, mixed to )
{
Stdio.File f = Stdio.File();
if(!f->open( dir + replace( name, "/", "-" ), "wct" ))
{
mkdirhier( dir+"/foo" );
if(!f->open( dir + replace( name, "/", "-" ), "wct" ))
{
report_error("Failed to create configuration interface cache file ("+
dir + replace( name, "/", "-" )+") "+
strerror( errno() )+"\n");
return to;
}
}
f->write( encode_value( to ) );
return to;
}
mixed get( string name )
{
Stdio.File f = Stdio.File();
if(!f->open( dir + replace( name, "/", "-" ), "r" ))
return 0;
return decode_value( f->read() );
}
|
6b3486 | 1999-11-15 | Per Hedbor | | array list()
{
return get_dir( dir );
}
|
c5e096 | 1999-10-04 | Per Hedbor | | void delete( string name )
{
rm( dir + replace( name, "/", "-" ) );
}
}
|
753a83 | 1999-08-30 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | class ImageCache
{
string name;
string dir;
function draw_function;
mapping data_cache = ([]);
mapping meta_cache = ([]);
|
0f8b2f | 1999-03-27 | Henrik Grubbström (Grubba) | |
|
34d3fa | 1999-04-22 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | static mapping meta_cache_insert( string i, mapping what )
{
return meta_cache[i] = what;
}
static string data_cache_insert( string i, string what )
{
return data_cache[i] = what;
}
|
753a83 | 1999-08-30 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | static mixed frommapp( mapping what )
|
753a83 | 1999-08-30 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | if( what[""] ) return what[""];
return what;
|
753a83 | 1999-08-30 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | static void draw( string name, RequestID id )
{
mixed args = Array.map( Array.map( name/"$", argcache->lookup, id->client ), frommapp);
mapping meta;
string data;
mixed reply = draw_function( @copy_value(args), id );
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if( arrayp( args ) )
args = args[0];
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if( objectp( reply ) || (mappingp(reply) && reply->img) )
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | int quant = (int)args->quant;
string format = lower_case(args->format || "gif");
string dither = args->dither;
Image.Colortable ct;
|
e9d7c5 | 1999-11-02 | Per Hedbor | | Image.Color.Color bgcolor;
|
2ff846 | 1999-09-02 | Per Hedbor | | object alpha;
int true_alpha;
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if( args->fs || dither == "fs" )
dither = "floyd_steinberg";
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if( dither == "random" )
dither = "random_dither";
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if( format == "jpg" )
format = "jpeg";
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | if(mappingp(reply))
{
alpha = reply->alpha;
reply = reply->img;
|
93ebdd | 1999-03-11 | Martin Stjernholm | | }
|
2ff846 | 1999-09-02 | Per Hedbor | |
if( args->gamma )
reply = reply->gamma( (float)args->gamma );
|
b79be2 | 1999-06-11 | Per Hedbor | |
|
c3a53d | 1999-06-25 | Per Hedbor | | if( args["true-alpha"] )
true_alpha = 1;
|
e7e603 | 1999-11-05 | Per Hedbor | | if( args["background"] || args["background-color"])
bgcolor = Image.Color( (args["background"]||args["background-color"]) );
|
e9d7c5 | 1999-11-02 | Per Hedbor | |
|
b79be2 | 1999-06-11 | Per Hedbor | | if( args["opaque-value"] )
{
|
c3a53d | 1999-06-25 | Per Hedbor | | true_alpha = 1;
|
b79be2 | 1999-06-11 | Per Hedbor | | int ov = (int)(((float)args["opaque-value"])*2.55);
if( ov < 0 )
ov = 0;
else if( ov > 255 )
ov = 255;
if( alpha )
{
object i = Image.image( reply->xsize(), reply->ysize(), ov,ov,ov );
|
e9d7c5 | 1999-11-02 | Per Hedbor | | i = i->paste_alpha( alpha, ov );
|
b79be2 | 1999-06-11 | Per Hedbor | | alpha = i;
}
else
{
alpha = Image.image( reply->xsize(), reply->ysize(), ov,ov,ov );
}
}
|
c52692 | 1999-05-18 | Per Hedbor | |
if( args->scale )
{
int x, y;
if( sscanf( args->scale, "%d,%d", x, y ) == 2)
{
reply = reply->scale( x, y );
if( alpha )
alpha = alpha->scale( x, y );
}
|
3255b1 | 1999-05-19 | Per Hedbor | | else if( (float)args->scale < 3.0)
|
c52692 | 1999-05-18 | Per Hedbor | | {
|
3255b1 | 1999-05-19 | Per Hedbor | | reply = reply->scale( ((float)args->scale) );
|
c52692 | 1999-05-18 | Per Hedbor | | if( alpha )
|
3255b1 | 1999-05-19 | Per Hedbor | | alpha = alpha->scale( ((float)args->scale) );
|
c52692 | 1999-05-18 | Per Hedbor | | }
}
|
e7e603 | 1999-11-05 | Per Hedbor | | if( args->maxwidth || args->maxheight ||
args["max-width"] || args["max-height"])
|
c52692 | 1999-05-18 | Per Hedbor | | {
|
e7e603 | 1999-11-05 | Per Hedbor | | int x = (int)args->maxwidth||(int)args["max-width"];
int y = (int)args->maxheight||(int)args["max-height"];
|
c52692 | 1999-05-18 | Per Hedbor | | if( x && reply->xsize() > x )
{
reply = reply->scale( x, 0 );
if( alpha )
alpha = alpha->scale( x, 0 );
}
if( y && reply->ysize() > y )
{
reply = reply->scale( 0, y );
if( alpha )
alpha = alpha->scale( 0, y );
}
}
|
e7e603 | 1999-11-05 | Per Hedbor | | if( bgcolor && alpha )
{
reply = Image.Image( reply->xsize(),
reply->ysize(), bgcolor )
->paste_mask( reply, alpha );
}
|
69a869 | 1999-05-18 | Per Hedbor | | if( quant || (format=="gif") )
{
|
e9d7c5 | 1999-11-02 | Per Hedbor | | int ncols = quant||id->misc->defquant||32;
|
7ed2ef | 1999-05-25 | Peter Bortas | | if( ncols > 250 )
|
000c78 | 1999-05-25 | Per Hedbor | | ncols = 250;
ct = Image.Colortable( reply, ncols );
|
69a869 | 1999-05-18 | Per Hedbor | | if( dither )
|
000c78 | 1999-05-25 | Per Hedbor | | if( ct[ dither ] )
ct[ dither ]();
|
69a869 | 1999-05-18 | Per Hedbor | | else
ct->ordered();
}
|
376017 | 1999-06-27 | Per Hedbor | | if(!Image[upper_case( format )]
|| !Image[upper_case( format )]->encode )
|
69a869 | 1999-05-18 | Per Hedbor | | error("Image format "+format+" unknown\n");
mapping enc_args = ([]);
if( ct )
enc_args->colortable = ct;
if( alpha )
enc_args->alpha = alpha;
|
c52692 | 1999-05-18 | Per Hedbor | | foreach( glob( "*-*", indices(args)), string n )
if(sscanf(n, "%*[^-]-%s", string opt ) == 2)
enc_args[opt] = (int)args[n];
|
69a869 | 1999-05-18 | Per Hedbor | | switch(format)
{
case "gif":
|
c3a53d | 1999-06-25 | Per Hedbor | | if( alpha && true_alpha )
|
b79be2 | 1999-06-11 | Per Hedbor | | {
|
e9d7c5 | 1999-11-02 | Per Hedbor | | object bw=Image.Colortable( ({ ({ 0,0,0 }), ({ 255,255,255 }) }) );
bw->floyd_steinberg();
alpha = bw->map( alpha );
|
b79be2 | 1999-06-11 | Per Hedbor | | }
|
000c78 | 1999-05-25 | Per Hedbor | | if( catch {
if( alpha )
data = Image.GIF.encode_trans( reply, ct, alpha );
else
data = Image.GIF.encode( reply, ct );
})
data = Image.GIF.encode( reply );
break;
|
e9d7c5 | 1999-11-02 | Per Hedbor | |
|
69a869 | 1999-05-18 | Per Hedbor | | case "png":
|
e9d7c5 | 1999-11-02 | Per Hedbor | | if( ct ) enc_args->palette = ct;
|
69a869 | 1999-05-18 | Per Hedbor | | m_delete( enc_args, "colortable" );
|
e9d7c5 | 1999-11-02 | Per Hedbor | | if( !enc_args->alpha ) m_delete( enc_args, "alpha" );
|
69a869 | 1999-05-18 | Per Hedbor | | default:
data = Image[upper_case( format )]->encode( reply, enc_args );
}
|
e9d7c5 | 1999-11-02 | Per Hedbor | | meta =
([
|
69a869 | 1999-05-18 | Per Hedbor | | "xsize":reply->xsize(),
"ysize":reply->ysize(),
"type":"image/"+format,
]);
|
c52692 | 1999-05-18 | Per Hedbor | | }
|
69a869 | 1999-05-18 | Per Hedbor | | else if( mappingp(reply) )
{
meta = reply->meta;
data = reply->data;
if( !meta || !data )
error("Invalid reply mapping.\n"
"Should be ([ \"meta\": ([metadata]), \"data\":\"data\" ])\n");
}
store_meta( name, meta );
store_data( name, data );
}
static void store_meta( string id, mapping meta )
{
meta_cache_insert( id, meta );
string data = encode_value( meta );
|
b50362 | 1999-07-27 | Per Hedbor | | Stdio.File f = Stdio.File( );
if(!f->open(dir+id+".i", "wct" ))
|
69a869 | 1999-05-18 | Per Hedbor | | {
report_error( "Failed to open image cache persistant cache file "+
dir+id+".i: "+strerror( errno() )+ "\n" );
return;
}
f->write( data );
}
static void store_data( string id, string data )
{
|
b50362 | 1999-07-27 | Per Hedbor | | Stdio.File f = Stdio.File( );
if(!f->open(dir+id+".d", "wct" ))
|
69a869 | 1999-05-18 | Per Hedbor | | {
data_cache_insert( id, data );
report_error( "Failed to open image cache persistant cache file "+
|
376017 | 1999-06-27 | Per Hedbor | | dir+id+".d: "+strerror( errno() )+ "\n" );
|
69a869 | 1999-05-18 | Per Hedbor | | return;
}
f->write( data );
}
static mapping restore_meta( string id )
{
Stdio.File f;
if( meta_cache[ id ] )
return meta_cache[ id ];
f = Stdio.File( );
if( !f->open(dir+id+".i", "r" ) )
return 0;
return meta_cache_insert( id, decode_value( f->read() ) );
}
static mapping restore( string id )
{
string|object(Stdio.File) f;
mapping m;
if( data_cache[ id ] )
f = data_cache[ id ];
else
f = Stdio.File( );
|
376017 | 1999-06-27 | Per Hedbor | | if(!f->open(dir+id+".d", "r" ))
|
69a869 | 1999-05-18 | Per Hedbor | | return 0;
m = restore_meta( id );
if(!m)
return 0;
if( stringp( f ) )
|
2ff846 | 1999-09-02 | Per Hedbor | | return roxenp()->http_string_answer( f, m->type||("image/gif") );
|
69a869 | 1999-05-18 | Per Hedbor | | return roxenp()->http_file_answer( f, m->type||("image/gif") );
}
string data( string|mapping args, RequestID id, int|void nodraw )
{
string na = store( args, id );
mixed res;
if(!( res = restore( na )) )
{
if(nodraw)
return 0;
draw( na, id );
res = restore( na );
}
if( res->file )
return res->file->read();
return res->data;
}
|
c3a53d | 1999-06-25 | Per Hedbor | | mapping http_file_answer( string|mapping data,
RequestID id,
int|void nodraw )
|
69a869 | 1999-05-18 | Per Hedbor | | {
string na = store( data,id );
mixed res;
if(!( res = restore( na )) )
{
if(nodraw)
return 0;
draw( na, id );
res = restore( na );
}
return res;
}
|
2ff846 | 1999-09-02 | Per Hedbor | | mapping metadata( string|mapping data, RequestID id, int|void nodraw )
{
string na = store( data,id );
if(!restore_meta( na ))
{
if(nodraw)
return 0;
draw( na, id );
return restore_meta( na );
}
return restore_meta( na );
}
mapping tomapp( mixed what )
{
if( mappingp( what ))
return what;
return ([ "":what ]);
}
string store( array|string|mapping data, RequestID id )
{
string ci;
if( mappingp( data ) )
ci = argcache->store( data );
else if( arrayp( data ) )
ci = Array.map( Array.map( data, tomapp ), argcache->store )*"$";
else
ci = data;
return ci;
}
void set_draw_function( function to )
{
draw_function = to;
}
void create( string id, function draw_func, string|void d )
{
if(!d) d = roxenp()->QUERY(argument_cache_dir);
if( d[-1] != '/' )
d+="/";
d += id+"/";
mkdirhier( d+"foo");
dir = d;
name = id;
draw_function = draw_func;
}
}
class ArgCache
{
static string name;
static string path;
static int is_db;
static object db;
#define CACHE_VALUE 0
#define CACHE_SKEY 1
#define CACHE_SIZE 600
#define CLEAN_SIZE 100
#ifdef THREADS
static Thread.Mutex mutex = Thread.Mutex();
# define LOCK() object __key = mutex->lock()
#else
# define LOCK()
#endif
static mapping (string:mixed) cache = ([ ]);
|
b870ac | 1999-09-03 | Henrik Grubbström (Grubba) | | static void setup_table()
|
2ff846 | 1999-09-02 | Per Hedbor | | {
if(catch(db->query("select id from "+name+" where id=-1")))
if(catch(db->query("create table "+name+" ("
"id int auto_increment primary key, "
"lkey varchar(80) not null default '', "
"contents blob not null default '', "
"atime bigint not null default 0)")))
throw("Failed to create table in database\n");
}
void create( string _name,
string _path,
int _is_db )
{
name = _name;
path = _path;
is_db = _is_db;
if(is_db)
{
db = Sql.sql( path );
if(!db)
error("Failed to connect to database for argument cache\n");
setup_table( );
} else {
if(path[-1] != '/' && path[-1] != '\\')
path += "/";
path += replace(name, "/", "_")+"/";
mkdirhier( path + "/tmp" );
object test = Stdio.File();
if (!test->open (path + "/.testfile", "wc"))
error ("Can't create files in the argument cache directory " + path + "\n");
else {
test->close();
rm (path + "/.testfile");
}
}
}
static string read_args( string id )
{
if( is_db )
{
mapping res = db->query("select contents from "+name+" where id='"+id+"'");
if( sizeof(res) )
{
db->query("update "+name+" set atime='"+
time()+"' where id='"+id+"'");
return res[0]->contents;
}
return 0;
} else {
if( file_stat( path+id ) )
return Stdio.read_bytes(path+"/"+id);
}
return 0;
}
static string create_key( string long_key )
{
if( is_db )
{
mapping data = db->query(sprintf("select id,contents from %s where lkey='%s'",
name,long_key[..79]));
foreach( data, mapping m )
if( m->contents == long_key )
return m->id;
db->query( sprintf("insert into %s (contents,lkey,atime) values "
"('%s','%s','%d')",
name, long_key, long_key[..79], time() ));
return create_key( long_key );
} else {
string _key=MIME.encode_base64(Crypto.md5()->update(long_key)->digest(),1);
_key = replace(_key-"=","/","=");
string short_key = _key[0..1];
while( file_stat( path+short_key ) )
{
if( Stdio.read_bytes( path+short_key ) == long_key )
return short_key;
short_key = _key[..strlen(short_key)];
if( strlen(short_key) >= strlen(_key) )
short_key += ".";
}
object f = Stdio.File( path + short_key, "wct" );
f->write( long_key );
return short_key;
}
}
int key_exists( string key )
{
LOCK();
if( !is_db )
return !!file_stat( path+key );
return !!read_args( key );
}
string store( mapping args )
|
69a869 | 1999-05-18 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | LOCK();
array b = values(args), a = sort(indices(args),b);
string data = MIME.encode_base64(encode_value(({a,b})),1);
if( cache[ data ] )
return cache[ data ][ CACHE_SKEY ];
string id = create_key( data );
cache[ data ] = ({ 0, 0 });
cache[ data ][ CACHE_VALUE ] = copy_value( args );
cache[ data ][ CACHE_SKEY ] = id;
cache[ id ] = data;
if( sizeof( cache ) > CACHE_SIZE )
|
69a869 | 1999-05-18 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | array i = indices(cache);
while( sizeof(cache) > CACHE_SIZE-CLEAN_SIZE )
m_delete( cache, i[random(sizeof(i))] );
|
69a869 | 1999-05-18 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | return id;
|
69a869 | 1999-05-18 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | mapping lookup( string id, string|void client )
|
c3a53d | 1999-06-25 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | LOCK();
|
c5e096 | 1999-10-04 | Per Hedbor | | if(cache[id] && cache[ cache[id] ] )
|
2ff846 | 1999-09-02 | Per Hedbor | | return cache[cache[id]][CACHE_VALUE];
string q = read_args( id );
if(!q) error("Key does not exist! (Thinks "+ client +")\n");
mixed data = decode_value(MIME.decode_base64( q ));
data = mkmapping( data[0],data[1] );
cache[ q ] = ({0,0});
cache[ q ][ CACHE_VALUE ] = data;
cache[ q ][ CACHE_SKEY ] = id;
cache[ id ] = q;
return data;
|
c3a53d | 1999-06-25 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | void delete( string id )
|
69a869 | 1999-05-18 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | LOCK();
if(cache[id])
{
m_delete( cache, cache[id] );
m_delete( cache, id );
}
if( is_db )
db->query( "delete from "+name+" where id='"+id+"'" );
|
69a869 | 1999-05-18 | Per Hedbor | | else
|
2ff846 | 1999-09-02 | Per Hedbor | | rm( path+id );
|
69a869 | 1999-05-18 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | }
|
69a869 | 1999-05-18 | Per Hedbor | |
|
95b69e | 1999-09-05 | Per Hedbor | | mapping cached_decoders = ([]);
string decode_charset( string charset, string data )
{
|
808e17 | 1999-09-05 | Henrik Grubbström (Grubba) | |
|
95b69e | 1999-09-05 | Per Hedbor | | if( charset == "iso-8859-1" ) return data;
if( !cached_decoders[ charset ] )
cached_decoders[ charset ] = Locale.Charset.decoder( charset );
data = cached_decoders[ charset ]->feed( data )->drain();
cached_decoders[ charset ]->flush();
return data;
}
|
2ff846 | 1999-09-02 | Per Hedbor | | void create()
{
SET_LOCALE(default_locale);
dump( "base_server/newdecode.pike" );
dump( "base_server/read_config.pike" );
dump( "base_server/global_variables.pike" );
dump( "base_server/module_support.pike" );
dump( "base_server/http.pike" );
dump( "base_server/socket.pike" );
dump( "base_server/cache.pike" );
dump( "base_server/supports.pike" );
dump( "base_server/fonts.pike");
dump( "base_server/hosts.pike");
dump( "base_server/language.pike");
|
69a869 | 1999-05-18 | Per Hedbor | |
|
95b69e | 1999-09-05 | Per Hedbor | | #ifndef __NT__
|
640cc4 | 1999-11-29 | Per Hedbor | | if(!getuid())
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant("Privs", Privs);
|
640cc4 | 1999-11-29 | Per Hedbor | | else
|
95b69e | 1999-09-05 | Per Hedbor | | #endif /* !__NT__ */
|
640cc4 | 1999-11-29 | Per Hedbor | | add_constant("Privs",class{});
|
69a869 | 1999-05-18 | Per Hedbor | |
|
855c39 | 1999-11-29 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | |
|
d3b98e | 1999-11-28 | Per Hedbor | |
add_constant( "MIME.encode_base64", MIME.encode_base64 );
add_constant( "MIME.decode_base64", MIME.decode_base64 );
|
95b69e | 1999-09-05 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | add_constant( "Image", Image );
add_constant( "Image.Image", Image.Image );
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "Image.Font", Image.Font );
|
2ff846 | 1999-09-02 | Per Hedbor | | add_constant( "Image.Colortable", Image.Colortable );
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "Image.Color", Image.Color );
add_constant( "Image.GIF.encode", Image.GIF.encode );
add_constant( "Image.Color.Color", Image.Color.Color );
add_constant( "roxen.argcache", argcache );
add_constant( "ArgCache", ArgCache );
add_constant( "Regexp", Regexp );
add_constant( "Stdio.File", Stdio.File );
add_constant( "Stdio.stdout", Stdio.stdout );
add_constant( "Stdio.stderr", Stdio.stderr );
add_constant( "Stdio.stdin", Stdio.stdin );
add_constant( "Stdio.read_bytes", Stdio.read_bytes );
add_constant( "Stdio.write_file", Stdio.write_file );
add_constant( "Stdio.sendfile", Stdio.sendfile );
add_constant( "Process.create_process", Process.create_process );
add_constant( "roxen.load_image", load_image );
|
2ff846 | 1999-09-02 | Per Hedbor | | #if constant(Thread.Mutex)
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "Thread.Mutex", Thread.Mutex );
add_constant( "Thread.Queue", Thread.Queue );
|
2ff846 | 1999-09-02 | Per Hedbor | | #endif
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "roxen", this_object());
add_constant( "roxen.decode_charset", decode_charset);
|
855c39 | 1999-11-29 | Per Hedbor | |
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "RequestID", RequestID);
|
855c39 | 1999-11-29 | Per Hedbor | | add_constant( "RoxenModule", RoxenModule);
add_constant( "ModuleInfo", Module );
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "load", load);
add_constant( "Roxen.set_locale", set_locale );
add_constant( "Roxen.locale", locale );
add_constant( "Locale.Roxen", Locale.Roxen );
|
d00fcc | 1999-09-05 | Per Hedbor | | add_constant( "Locale.Roxen.standard", Locale.Roxen.standard );
add_constant( "Locale.Roxen.standard.register_module_doc",
Locale.Roxen.standard.register_module_doc );
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "roxen.ImageCache", ImageCache );
|
2ff846 | 1999-09-02 | Per Hedbor | |
|
95b69e | 1999-09-05 | Per Hedbor | | add_constant( "hsv_to_rgb", Colors.hsv_to_rgb );
add_constant( "rgb_to_hsv", Colors.rgb_to_hsv );
add_constant( "parse_color", Colors.parse_color );
add_constant( "color_name", Colors.color_name );
add_constant( "colors", Colors );
add_constant( "roxen.fonts", (fonts = (object)"fonts.pike") );
|
c82127 | 1999-11-11 | Martin Stjernholm | | if ((file_stat("base_server/configuration.pike.o")||(<>))[ST_MTIME] <
file_stat("base_server/configuration.pike")[ST_MTIME] ||
(file_stat("base_server/configuration.pike.o")||(<>))[ST_MTIME] <
file_stat("base_server/rxml.pike")[ST_MTIME])
rm ("base_server/configuration.pike.o");
|
855c39 | 1999-11-29 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | Configuration = (program)"configuration";
|
2bb924 | 1999-11-24 | Per Hedbor | | dump( "base_server/configuration.pike" );
|
855c39 | 1999-11-29 | Per Hedbor | | add_constant( "Configuration", Configuration );
|
2ff846 | 1999-09-02 | Per Hedbor | |
call_out(post_create,1);
|
69a869 | 1999-05-18 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | |
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | int set_u_and_gid()
{
#ifndef __NT__
string u, g;
int uid, gid;
array pw;
u=QUERY(User);
sscanf(u, "%s:%s", u, g);
if(strlen(u))
{
if(getuid())
{
report_error ("It is only possible to change uid and gid if the server "
"is running as root.\n");
} else {
if (g) {
#if constant(getgrnam)
pw = getgrnam (g);
if (!pw)
if (sscanf (g, "%d", gid)) pw = getgrgid (gid), g = (string) gid;
else report_error ("Couldn't resolve group " + g + ".\n"), g = 0;
if (pw) g = pw[0], gid = pw[2];
|
a22f6f | 1999-05-12 | Per Hedbor | | #else
|
2ff846 | 1999-09-02 | Per Hedbor | | if (!sscanf (g, "%d", gid))
report_warning ("Can't resolve " + g + " to gid on this system; "
"numeric gid required.\n");
|
a22f6f | 1999-05-12 | Per Hedbor | | #endif
|
2ff846 | 1999-09-02 | Per Hedbor | | }
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | pw = getpwnam (u);
if (!pw)
if (sscanf (u, "%d", uid)) pw = getpwuid (uid), u = (string) uid;
else {
report_error ("Couldn't resolve user " + u + ".\n");
return 0;
}
if (pw) {
u = pw[0], uid = pw[2];
if (!g) gid = pw[3];
}
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | #ifdef THREADS
object mutex_key;
catch { mutex_key = euid_egid_lock->lock(); };
object threads_disabled = _disable_threads();
#endif
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | #if constant(seteuid)
if (geteuid() != getuid()) seteuid (getuid());
#endif
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | #if constant(initgroups)
catch {
initgroups(pw[0], gid);
};
#endif
if (QUERY(permanent_uid)) {
#if constant(setuid)
if (g) {
# if constant(setgid)
setgid(gid);
if (getgid() != gid) report_error ("Failed to set gid.\n"), g = 0;
# else
report_warning ("Setting gid not supported on this system.\n");
g = 0;
# endif
}
setuid(uid);
if (getuid() != uid) report_error ("Failed to set uid.\n"), u = 0;
if (u) report_notice(LOCALE->setting_uid_gid_permanently (uid, gid, u, g));
#else
report_warning ("Setting uid not supported on this system.\n");
u = g = 0;
#endif
}
|
b84a16 | 1999-06-07 | Martin Stjernholm | | else {
|
2ff846 | 1999-09-02 | Per Hedbor | | #if constant(seteuid)
if (g) {
# if constant(setegid)
setegid(gid);
if (getegid() != gid) report_error ("Failed to set effective gid.\n"), g = 0;
# else
report_warning ("Setting effective gid not supported on this system.\n");
g = 0;
# endif
}
seteuid(uid);
if (geteuid() != uid) report_error ("Failed to set effective uid.\n"), u = 0;
if (u) report_notice(LOCALE->setting_uid_gid (uid, gid, u, g));
#else
report_warning ("Setting effective uid not supported on this system.\n");
u = g = 0;
#endif
|
b84a16 | 1999-06-07 | Martin Stjernholm | | }
|
2ff846 | 1999-09-02 | Per Hedbor | |
return !!u;
|
a22f6f | 1999-05-12 | Per Hedbor | | }
}
|
2ff846 | 1999-09-02 | Per Hedbor | | #endif
return 0;
}
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | void reload_all_configurations()
{
object conf;
array (object) new_confs = ({});
mapping config_cache = ([]);
int modified;
report_notice(LOCALE->reloading_config_interface());
configs = ([]);
setvars(retrieve("Variables", 0));
foreach(list_all_configurations(), string config)
|
a22f6f | 1999-05-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | array err, st;
foreach(configurations, conf)
|
a22f6f | 1999-05-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | if(lower_case(conf->name) == lower_case(config))
|
a22f6f | 1999-05-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | break;
} else
conf = 0;
}
if(!(st = config_is_modified(config))) {
if(conf) {
config_cache[config] = config_stat_cache[config];
new_confs += ({ conf });
|
a22f6f | 1999-05-12 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | continue;
|
a22f6f | 1999-05-12 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | modified = 1;
config_cache[config] = st;
if(conf) {
if (conf->server_ports) {
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | | Array.map(values(conf->server_ports),
lambda(object o) { destruct(o); });
|
2ff846 | 1999-09-02 | Per Hedbor | | } else {
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | | Array.map(indices(conf->open_ports),
lambda(object o) { destruct(o); });
|
2ff846 | 1999-09-02 | Per Hedbor | | }
conf->stop();
conf->invalidate_cache();
conf->modules = ([]);
conf->create(conf->name);
|
a22f6f | 1999-05-12 | Per Hedbor | | } else {
|
2ff846 | 1999-09-02 | Per Hedbor | | if(err = catch
|
a22f6f | 1999-05-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | conf = enable_configuration(config);
}) {
report_error(LOCALE->
error_enabling_configuration(config,
describe_backtrace(err)));
continue;
|
a22f6f | 1999-05-12 | Per Hedbor | | }
}
|
2ff846 | 1999-09-02 | Per Hedbor | | if(err = catch
{
conf->start();
conf->enable_all_modules();
}) {
report_error(LOCALE->
error_enabling_configuration(config,
describe_backtrace(err)));
continue;
}
new_confs += ({ conf });
|
a22f6f | 1999-05-12 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | |
foreach(configurations - new_confs, conf)
|
a22f6f | 1999-05-12 | Per Hedbor | | {
|
2ff846 | 1999-09-02 | Per Hedbor | | modified = 1;
report_notice(LOCALE->disabling_configuration(conf->name));
|
479d8a | 1999-11-25 | Henrik Grubbström (Grubba) | | Array.map(values(conf->server_ports), lambda(object o) { destruct(o); });
|
2ff846 | 1999-09-02 | Per Hedbor | | conf->stop();
destruct(conf);
}
if(modified) {
configurations = new_confs;
config_stat_cache = config_cache;
|
a22f6f | 1999-05-12 | Per Hedbor | | }
|
2ff846 | 1999-09-02 | Per Hedbor | | }
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | object enable_configuration(string name)
{
|
15635b | 1999-10-10 | Per Hedbor | | object cf = Configuration( name );
|
2ff846 | 1999-09-02 | Per Hedbor | | configurations += ({ cf });
|
15635b | 1999-10-10 | Per Hedbor | | report_notice( LOCALE->enabled_server(name) );
|
2ff846 | 1999-09-02 | Per Hedbor | | return cf;
}
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | |
void enable_configurations()
{
array err;
configurations = ({});
|
15635b | 1999-10-10 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | foreach(list_all_configurations(), string config)
|
15635b | 1999-10-10 | Per Hedbor | | if(err=catch( enable_configuration(config)->start() ))
report_error("Error while loading configuration "+config+":\n"+
describe_backtrace(err)+"\n");
|
2ff846 | 1999-09-02 | Per Hedbor | | }
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
2ff846 | 1999-09-02 | Per Hedbor | | void enable_configurations_modules()
{
|
15635b | 1999-10-10 | Per Hedbor | | mixed err;
|
2ff846 | 1999-09-02 | Per Hedbor | | foreach(configurations, object config)
|
15635b | 1999-10-10 | Per Hedbor | | if(err=catch( config->enable_all_modules() ))
report_error("Error while loading modules in configuration "+
config->name+":\n"+describe_backtrace(err)+"\n");
|
a22f6f | 1999-05-12 | Per Hedbor | | }
array(int) invert_color(array color )
{
return ({ 255-color[0], 255-color[1], 255-color[2] });
}
mapping low_decode_image(string data, void|array tocolor)
{
Image.image i, a;
string format;
if(!data)
return 0;
#if constant(Image.GIF._decode)
catch
{
array chunks = Image.GIF._decode( data );
foreach(chunks, mixed chunk)
if(arrayp(chunk) && chunk[0] == Image.GIF.RENDER )
[i,a] = chunk[3..4];
format = "GIF";
};
if(!i) catch
{
i = Image.GIF.decode( data );
format = "GIF";
};
#endif
#if constant(Image.JPEG) && constant(Image.JPEG.decode)
if(!i) catch
{
i = Image.JPEG.decode( data );
format = "JPEG";
};
#endif
#if constant(Image.XCF) && constant(Image.XCF._decode)
if(!i) catch
{
|
c3a53d | 1999-06-25 | Per Hedbor | | mixed q = Image.XCF._decode( data,(["background":tocolor,]) );
|
a22f6f | 1999-05-12 | Per Hedbor | | tocolor=0;
format = "XCF Gimp file";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.PSD) && constant(Image.PSD._decode)
if(!i) catch
{
mixed q = Image.PSD._decode( data, ([
"background":tocolor,
]));
tocolor=0;
format = "PSD Photoshop file";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.PNG) && constant(Image.PNG._decode)
if(!i) catch
{
mixed q = Image.PNG._decode( data );
format = "PNG";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.BMP) && constant(Image.BMP._decode)
if(!i) catch
{
mixed q = Image.BMP._decode( data );
format = "Windows bitmap file";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.TGA) && constant(Image.TGA._decode)
if(!i) catch
{
mixed q = Image.TGA._decode( data );
format = "Targa";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.PCX) && constant(Image.PCX._decode)
if(!i) catch
{
mixed q = Image.PCX._decode( data );
format = "PCX";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.XBM) && constant(Image.XBM._decode)
if(!i) catch
{
mixed q = Image.XBM._decode( data, (["bg":tocolor||({255,255,255}),
"fg":invert_color(tocolor||({255,255,255})) ]));
format = "XBM";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.XPM) && constant(Image.XPM._decode)
if(!i) catch
{
mixed q = Image.XPM._decode( data );
format = "XPM";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.TIFF) && constant(Image.TIFF._decode)
if(!i) catch
{
mixed q = Image.TIFF._decode( data );
format = "TIFF";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.ILBM) && constant(Image.ILBM._decode)
if(!i) catch
{
mixed q = Image.ILBM._decode( data );
format = "ILBM";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.PS) && constant(Image.PS._decode)
if(!i) catch
{
mixed q = Image.PS._decode( data );
format = "Postscript";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.XWD) && constant(Image.XWD.decode)
if(!i) catch
{
i = Image.XWD.decode( data );
format = "XWD";
};
#endif
#if constant(Image.HRZ) && constant(Image.HRZ._decode)
if(!i) catch
{
mixed q = Image.HRZ._decode( data );
format = "HRZ";
i = q->image;
a = q->alpha;
};
#endif
#if constant(Image.AVS) && constant(Image.AVS._decode)
if(!i) catch
{
mixed q = Image.AVS._decode( data );
format = "AVS X";
i = q->image;
a = q->alpha;
};
#endif
|
c5e096 | 1999-10-04 | Per Hedbor | | #if constant(Image.PNM)
|
a22f6f | 1999-05-12 | Per Hedbor | | if(!i)
catch{
i = Image.PNM.decode( data );
format = "PNM";
};
|
c5e096 | 1999-10-04 | Per Hedbor | | #endif
|
a22f6f | 1999-05-12 | Per Hedbor | |
if(!i)
return 0;
if( tocolor && i && a )
{
object o = Image.image( i->xsize(), i->ysize(), @tocolor );
o->paste_mask( i,a );
i = o;
}
return ([
"format":format,
"alpha":a,
"img":i,
]);
}
mapping low_load_image(string f,object id)
{
string data;
object file, img;
|
69a869 | 1999-05-18 | Per Hedbor | | if(id->misc->_load_image_called < 5)
{
|
3ffe06 | 1999-05-16 | David Hedbor | |
id->misc->_load_image_called++;
|
c52692 | 1999-05-18 | Per Hedbor | | if(!(data=id->conf->try_get_file(f, id)))
{
|
3ffe06 | 1999-05-16 | David Hedbor | | file=Stdio.File();
|
c52692 | 1999-05-18 | Per Hedbor | | if(!file->open(f,"r") || !(data=file->read()))
|
3ffe06 | 1999-05-16 | David Hedbor | | return 0;
}
}
id->misc->_load_image_called = 0;
if(!data) return 0;
|
a22f6f | 1999-05-12 | Per Hedbor | | return low_decode_image( data );
}
object load_image(string f,object id)
{
mapping q = low_load_image( f, id );
if( q ) return q->img;
return 0;
}
|
b1fca0 | 1996-11-12 | Per Hedbor | |
private void fix_root(string to)
{
|
c79b26 | 1998-02-05 | Johan Schön | | #ifndef __NT__
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(getuid())
{
perror("It is impossible to chroot() if the server is not run as root.\n");
return;
}
if(!chroot(to))
{
perror("Roxen: Cannot chroot to "+to+": ");
#if efun(real_perror)
real_perror();
#endif
return;
}
perror("Root is now "+to+".\n");
|
c79b26 | 1998-02-05 | Johan Schön | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
void create_pid_file(string where)
{
|
c79b26 | 1998-02-05 | Johan Schön | | #ifndef __NT__
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(!where) return;
where = replace(where, ({ "$pid", "$uid" }),
({ (string)getpid(), (string)getuid() }));
rm(where);
|
5e8921 | 1997-02-13 | Per Hedbor | | if(catch(Stdio.write_file(where, sprintf("%d\n%d", getpid(), getppid()))))
|
b1fca0 | 1996-11-12 | Per Hedbor | | perror("I cannot create the pid file ("+where+").\n");
|
c79b26 | 1998-02-05 | Johan Schön | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
95b69e | 1999-09-05 | Per Hedbor | | program pipe;
|
ccffe7 | 1999-03-05 | Wilhelm Köhler | | object shuffle(object from, object to,
object|void to2, function(:void)|void callback)
|
14179b | 1997-01-29 | Per Hedbor | | {
|
beaca0 | 1998-02-20 | Per Hedbor | | #if efun(spider.shuffle)
if(!to2)
|
5bc199 | 1997-01-29 | Per Hedbor | | {
|
95b69e | 1999-09-05 | Per Hedbor | | if(!pipe)
pipe = ((program)"smartpipe");
object p = pipe( );
|
beaca0 | 1998-02-20 | Per Hedbor | | p->input(from);
|
95e2b4 | 1997-05-25 | Wilhelm Köhler | | p->set_done_callback(callback);
|
beaca0 | 1998-02-20 | Per Hedbor | | p->output(to);
|
ccffe7 | 1999-03-05 | Wilhelm Köhler | | return p;
|
a60c4c | 1997-07-03 | Henrik Grubbström (Grubba) | | } else {
|
beaca0 | 1998-02-20 | Per Hedbor | | #endif
object p = Pipe.pipe();
if (callback) p->set_done_callback(callback);
p->output(to);
|
33b770 | 1998-03-20 | Johan Schön | | if(to2) p->output(to2);
|
beaca0 | 1998-02-20 | Per Hedbor | | p->input(from);
|
ccffe7 | 1999-03-05 | Wilhelm Köhler | | return p;
|
beaca0 | 1998-02-20 | Per Hedbor | | #if efun(spider.shuffle)
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
beaca0 | 1998-02-20 | Per Hedbor | | #endif
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
3aaaa7 | 1997-06-12 | Wilhelm Köhler | |
|
4f4bc1 | 1998-02-04 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | static private int _recurse;
|
a9d811 | 1998-09-01 | Henrik Grubbström (Grubba) | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | void exit_when_done()
{
object o;
int i;
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | roxen_perror("Interrupt request received. Exiting,\n");
|
4f4bc1 | 1998-02-04 | Per Hedbor | | die_die_die=1;
|
c5e096 | 1999-10-04 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | if(++_recurse > 4)
|
38dca8 | 1996-12-10 | Per Hedbor | | {
|
dca5dc | 1998-09-12 | Per Hedbor | | roxen_perror("Exiting roxen (spurious signals received).\n");
|
c5e096 | 1999-10-04 | Per Hedbor | | configurations->stop();
|
1f79ba | 1998-09-01 | Marcus Comstedt | | #ifdef THREADS
stop_handler_threads();
#endif /* THREADS */
|
3835ca | 1998-01-16 | Henrik Grubbström (Grubba) | | exit(-1);
|
38dca8 | 1996-12-10 | Per Hedbor | | }
|
4f4bc1 | 1998-02-04 | Per Hedbor | |
|
c5e096 | 1999-10-04 | Per Hedbor | | roxen_perror("Exiting roxen.\n");
configurations->stop();
|
1f79ba | 1998-09-01 | Marcus Comstedt | | #ifdef THREADS
|
c5e096 | 1999-10-04 | Per Hedbor | | stop_handler_threads();
|
1f79ba | 1998-09-01 | Marcus Comstedt | | #endif /* THREADS */
|
c5e096 | 1999-10-04 | Per Hedbor | | exit(-1);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
void exit_it()
{
perror("Recursive signals.\n");
|
3835ca | 1998-01-16 | Henrik Grubbström (Grubba) | | exit(-1);
|
b1fca0 | 1996-11-12 | Per Hedbor | | }
|
7c92b9 | 1998-11-19 | Per Hedbor | | void set_locale( string to )
{
if( to == "standard" )
SET_LOCALE( default_locale );
SET_LOCALE( Locale.Roxen[ to ] || default_locale );
}
|
a22f6f | 1999-05-12 | Per Hedbor | |
|
1c9d08 | 1999-07-19 | Henrik Grubbström (Grubba) | |
void describe_all_threads()
{
array(mixed) all_backtraces;
#if constant(all_threads)
all_backtraces = all_threads()->backtrace();
#else /* !constant(all_threads) */
all_backtraces = ({ backtrace() });
#endif /* constant(all_threads) */
werror("Describing all threads:\n");
int i;
for(i=0; i < sizeof(all_backtraces); i++) {
werror(sprintf("Thread %d:\n"
"%s\n",
i+1,
describe_backtrace(all_backtraces[i])));
}
}
|
753a83 | 1999-08-30 | Per Hedbor | |
void dump( string file )
{
|
dde833 | 1999-11-15 | Per Hedbor | | if( file[0] != '/' )
file = getcwd() +"/"+ file;
program p = master()->programs[ replace(file, "//", "/" ) ];
|
753a83 | 1999-08-30 | Per Hedbor | | array q;
|
2bb924 | 1999-11-24 | Per Hedbor | |
|
753a83 | 1999-08-30 | Per Hedbor | | if(!p)
|
2ff846 | 1999-09-02 | Per Hedbor | | {
#ifdef DUMP_DEBUG
report_debug(file+" not loaded, and thus cannot be dumped.\n");
#endif
|
753a83 | 1999-08-30 | Per Hedbor | | return;
|
2ff846 | 1999-09-02 | Per Hedbor | | }
|
753a83 | 1999-08-30 | Per Hedbor | |
|
2bb924 | 1999-11-24 | Per Hedbor | | string ofile = master()->make_ofilename( replace(file, "//", "/") );
if(!file_stat( ofile ) ||
(file_stat( ofile )[ ST_MTIME ] < file_stat(file)[ ST_MTIME ]))
|
2ff846 | 1999-09-02 | Per Hedbor | | {
|
2bb924 | 1999-11-24 | Per Hedbor | | if(q=catch( master()->dump_program( replace(file, "//", "/"), p ) ) )
report_debug("** Cannot encode "+file+": "+describe_backtrace(q)+"\n");
|
2ff846 | 1999-09-02 | Per Hedbor | | #ifdef DUMP_DEBUG
|
2bb924 | 1999-11-24 | Per Hedbor | | else
|
95b69e | 1999-09-05 | Per Hedbor | | report_debug( file+" dumped successfully to "+file+".o\n" );
|
2ff846 | 1999-09-02 | Per Hedbor | | #endif
}
#ifdef DUMP_DEBUG
else
report_debug(file+" already dumped (and up to date)\n");
#endif
|
753a83 | 1999-08-30 | Per Hedbor | | }
|
a57779 | 1999-11-24 | Per Hedbor | | program slowpipe, fastpipe;
|
95b69e | 1999-09-05 | Per Hedbor | | int main(int argc, array argv)
|
b1fca0 | 1996-11-12 | Per Hedbor | | {
|
2bb924 | 1999-11-24 | Per Hedbor | | mkdir( "precompiled" );
|
a57779 | 1999-11-24 | Per Hedbor | | slowpipe = ((program)"slowpipe");
fastpipe = ((program)"fastpipe");
|
2bb924 | 1999-11-24 | Per Hedbor | |
|
753a83 | 1999-08-30 | Per Hedbor | | call_out( lambda() {
|
95b69e | 1999-09-05 | Per Hedbor | | dump( "protocols/http.pike");
dump( "protocols/ftp.pike");
dump( "protocols/https.pike");
|
753a83 | 1999-08-30 | Per Hedbor | | dump( "base_server/state.pike" );
|
95b69e | 1999-09-05 | Per Hedbor | | dump( "base_server/struct/node.pike" );
|
2ff846 | 1999-09-02 | Per Hedbor | | dump( "base_server/highlight_pike.pike");
|
753a83 | 1999-08-30 | Per Hedbor | | dump( "base_server/wizard.pike" );
dump( "base_server/proxyauth.pike" );
dump( "base_server/html.pike" );
dump( "base_server/module.pike" );
|
95b69e | 1999-09-05 | Per Hedbor | | dump( "base_server/throttler.pike" );
dump( "base_server/smartpipe.pike" );
dump( "base_server/slowpipe.pike" );
dump( "base_server/fastpipe.pike" );
|
753a83 | 1999-08-30 | Per Hedbor | | }, 9);
switch(getenv("LANG"))
{
case "sv":
default_locale = Locale.Roxen["svenska"];
break;
case "jp":
default_locale = Locale.Roxen["nihongo"];
break;
}
|
59912f | 1998-10-15 | Henrik Grubbström (Grubba) | | SET_LOCALE(default_locale);
|
c24569 | 1997-10-25 | Per Hedbor | | initiate_languages();
|
b1fca0 | 1996-11-12 | Per Hedbor | | mixed tmp;
|
2ff846 | 1999-09-02 | Per Hedbor | |
|
b1fca0 | 1996-11-12 | Per Hedbor | | mark_fd(0, "Stdin");
mark_fd(1, "Stdout");
mark_fd(2, "Stderr");
|
51643e | 1997-08-21 | Per Hedbor | | configuration_dir =
|
6ca8f6 | 1998-10-13 | Per Hedbor | | Getopt.find_option(argv, "d",({"config-dir","configuration-directory" }),
|
51643e | 1997-08-21 | Per Hedbor | | ({ "ROXEN_CONFIGDIR", "CONFIGURATIONS" }), "../configurations");
|
b1fca0 | 1996-11-12 | Per Hedbor | |
|
a92b95 | 1997-08-05 | Martin Stjernholm | | if(configuration_dir[-1] != '/')
|
b1fca0 | 1996-11-12 | Per Hedbor | | configuration_dir += "/";
|
14179b | 1997-01-29 | Per Hedbor | |
|
6ca8f6 | 1998-10-13 | Per Hedbor | | if(tmp = Getopt.find_option(argv, "r", "root")) fix_root(tmp);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
argv -= ({ 0 });
|
51643e | 1997-08-21 | Per Hedbor | | argc = sizeof(argv);
|
b1fca0 | 1996-11-12 | Per Hedbor | |
define_global_variables(argc, argv);
|
95b69e | 1999-09-05 | Per Hedbor | |
|
b796b5 | 1998-11-18 | Per Hedbor | | object o;
if(QUERY(locale) != "standard" && (o = Locale.Roxen[QUERY(locale)]))
{
default_locale = o;
SET_LOCALE(default_locale);
}
|
b1fca0 | 1996-11-12 | Per Hedbor | | #if efun(syslog)
init_logger();
#endif
init_garber();
initiate_supports();
|
b84a16 | 1999-06-07 | Martin Stjernholm | | enable_configurations();
|
95b69e | 1999-09-05 | Per Hedbor | | set_u_and_gid();
|
b84a16 | 1999-06-07 | Martin Stjernholm | |
create_pid_file(Getopt.find_option(argv, "p", "pid-file", "ROXEN_PID_FILE")
|| QUERY(pidfile));
|
a22f6f | 1999-05-12 | Per Hedbor | | roxen_perror("Initiating argument cache ... ");
int id;
string cp = QUERY(argument_cache_dir), na = "args";
if( QUERY(argument_cache_in_db) )
{
id = 1;
cp = QUERY(argument_cache_db_path);
na = "argumentcache";
}
mixed e;
e = catch( argcache = ArgCache(na,cp,id) );
if( e )
{
report_error( "Failed to initialize the global argument cache:\n"
+ (describe_backtrace( e )/"\n")[0]+"\n");
werror( describe_backtrace( e ) );
}
roxen_perror( "\n" );
|
acd9e7 | 1999-05-12 | Per Hedbor | |
enable_configurations_modules();
|
b1fca0 | 1996-11-12 | Per Hedbor | |
call_out(update_supports_from_roxen_com,
QUERY(next_supports_update)-time());
|
48fa36 | 1997-04-05 | Per Hedbor | | #ifdef THREADS
start_handler_threads();
|
4f4bc1 | 1998-02-04 | Per Hedbor | | catch( this_thread()->set_name("Backend") );
|
34d3fa | 1999-04-22 | Per Hedbor | | backend_thread = this_thread();
|
34fbbc | 1998-02-05 | Henrik Grubbström (Grubba) | | #endif /* THREADS */
|
990cbb | 1997-08-12 | David Hedbor | |
|
3835ca | 1998-01-16 | Henrik Grubbström (Grubba) | |
|
15635b | 1999-10-10 | Per Hedbor | | foreach( ({ "SIGINT", "SIGTERM" }), string sig)
catch( signal(signum(sig), exit_when_done) );
catch( signal(signum("SIGHUP"), reload_all_configurations) );
|
1c9d08 | 1999-07-19 | Henrik Grubbström (Grubba) | |
|
15635b | 1999-10-10 | Per Hedbor | | foreach( ({ "SIGUSR1", "SIGUSR2", "SIGTRAP" }), string sig)
catch( signal(signum(sig), describe_all_threads) );
|
0f28da | 1997-08-13 | Per Hedbor | |
|
4f4bc1 | 1998-02-04 | Per Hedbor | | #ifdef __RUN_TRACE
trace(1);
#endif
|
08152b | 1998-04-24 | Per Hedbor | | start_time=time();
|
b1fca0 | 1996-11-12 | Per Hedbor | | return -1;
}
|
7a61de | 1998-03-26 | Per Hedbor | |
string diagnose_error(array from)
{
}
|
edc9af | 1998-07-11 | David Hedbor | |
|
ee8b20 | 1998-07-13 | David Hedbor | | string check_variable(string name, mixed value)
|
edc9af | 1998-07-11 | David Hedbor | | {
switch(name)
{
case "ConfigurationURL":
case "MyWorldLocation":
if(strlen(value)<7 || value[-1] != '/' ||
!(sscanf(value,"%*s://%*s/")==2))
|
c31f7b | 1998-10-10 | Henrik Grubbström (Grubba) | | return(LOCALE->url_format());
|
ee8b20 | 1998-07-13 | David Hedbor | | break;
case "abs_engage":
if (value)
restart_if_stuck(1);
else
remove_call_out(restart_if_stuck);
break;
case "suicide_engage":
if (value)
call_out(restart,60*60*24*QUERY(suicide_timeout));
else
remove_call_out(restart);
break;
|
b796b5 | 1998-11-18 | Per Hedbor | | case "locale":
object o;
if(value != "standard" && (o = Locale.Roxen[value]))
{
default_locale = o;
SET_LOCALE(default_locale);
}
break;
|
edc9af | 1998-07-11 | David Hedbor | | }
}
|
9fd61c | 1999-02-16 | Per Hedbor | |
mapping config_cache = ([ ]);
mapping host_accuracy_cache = ([]);
int is_ip(string s)
{
|
753a83 | 1999-08-30 | Per Hedbor | | return (replace(s,"0123456789."/"",({""})*11) == "");
|
9fd61c | 1999-02-16 | Per Hedbor | | }
|