2009-01-26 19:21:29 +00:00
|
|
|
// vim:foldmethod=marker:syntax=lpc:noexpandtab
|
2009-01-26 20:12:53 +00:00
|
|
|
// $Id: active.c,v 1.41 2008/06/17 09:35:45 lynx Exp $
|
2009-01-26 19:21:29 +00:00
|
|
|
//
|
2009-01-26 20:12:53 +00:00
|
|
|
#include "common.h"
|
2009-01-26 19:21:29 +00:00
|
|
|
#include <net.h>
|
|
|
|
#include <services.h>
|
|
|
|
|
2009-03-03 15:28:17 +00:00
|
|
|
#ifdef SPYC
|
|
|
|
inherit SPYC_PATH "circuit";
|
|
|
|
#else
|
2009-01-26 19:21:29 +00:00
|
|
|
inherit PSYC_PATH "circuit";
|
2009-03-03 15:28:17 +00:00
|
|
|
#endif
|
|
|
|
|
2009-01-26 19:21:29 +00:00
|
|
|
inherit NET_PATH "circuit";
|
|
|
|
|
|
|
|
volatile object super;
|
|
|
|
|
|
|
|
void takeover() {
|
|
|
|
super = previous_object();
|
|
|
|
if (super == ME) /* TODO: prevent elsewhere */ {
|
|
|
|
super = 0;
|
|
|
|
}
|
|
|
|
unless (interactive(ME)) runQ();
|
|
|
|
}
|
|
|
|
|
|
|
|
// we love multiple inheritance.. rock'n'roll!
|
|
|
|
int logon(int failure) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
P2(("%O logon kriegt %O, prev: %O\n", ME, failure, previous_object()))
|
|
|
|
ret = NET_PATH "circuit"::logon(failure);
|
|
|
|
if (failure >= 0 && ret > 0) {
|
|
|
|
#if 0 // apparently wrong
|
|
|
|
emit(".\n"); // should we do the greeting?
|
|
|
|
PSYC_PATH "circuit"::logon(failure);
|
|
|
|
|
|
|
|
peeraddr = peerhost = host;
|
|
|
|
if (port && port != PSYC_SERVICE) peeraddr += ":"+port;
|
|
|
|
#else // probably better
|
|
|
|
peeraddr = peerhost = host;
|
|
|
|
peerport = port;
|
|
|
|
if (port && port != PSYC_SERVICE) peeraddr += ":"+port;
|
|
|
|
// circuit::logon now also implies a full greeting
|
|
|
|
// therefore it needs peeraddr, and the emit is redundant
|
2009-03-03 15:28:17 +00:00
|
|
|
# ifdef SPYC
|
|
|
|
SPYC_PATH "circuit"::logon(failure);
|
|
|
|
# else
|
2009-01-26 19:21:29 +00:00
|
|
|
PSYC_PATH "circuit"::logon(failure);
|
2009-03-03 15:28:17 +00:00
|
|
|
# endif
|
2009-01-26 19:21:29 +00:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int msg(string source, string method, string data,
|
|
|
|
mapping vars, int showingLog, string target) {
|
|
|
|
P3(("active.c:msg(%O, %O, %O) in %O%s\n", source, method, data, ME,
|
|
|
|
(interactive()) ? "(connected)" : "(not connected)"))
|
|
|
|
|
|
|
|
unless (interactive())
|
|
|
|
#ifdef FORK // {{{
|
|
|
|
{
|
|
|
|
if (!member(vars, "_source"))
|
|
|
|
vars["_source"] = UNIFORM(source);
|
|
|
|
unless (super)
|
|
|
|
return enqueue(source, method, data, vars, showingLog, target);
|
|
|
|
return super->msg(source, method, data, vars, showingLog, target);
|
|
|
|
}
|
|
|
|
return ::msg(source, method, data, vars, showingLog, target);
|
|
|
|
#else // }}}
|
|
|
|
{
|
|
|
|
P2(("%O ist nicht interactive\n", ME))
|
|
|
|
if (!member(vars, "_source"))
|
|
|
|
vars["_source"] = UNIFORM(source);
|
|
|
|
// this stuff is causing loops and i don't know how to fix it right now
|
|
|
|
// unless (super)
|
|
|
|
# ifdef SPYC
|
|
|
|
// NOTE: SPYC uses a per-host verification and therefore
|
|
|
|
// may not send certain packets before verification
|
|
|
|
// is done (those packets usually have source and target)
|
|
|
|
// for now, this check works most of the time
|
|
|
|
# endif
|
|
|
|
return enqueue(source, method, data, vars, showingLog, target);
|
|
|
|
// return super->msg(source, method, data, vars, showingLog, target);
|
|
|
|
}
|
|
|
|
return ::msg(source, method, data, vars, showingLog, target);
|
|
|
|
#endif // !FORK
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
connect(host, port) {
|
|
|
|
if (host) {
|
|
|
|
// funky but who needs this?
|
|
|
|
if (interactive()) {
|
|
|
|
if (ahost == host && aport == port) return -8;
|
|
|
|
else remove_interactive(ME);
|
|
|
|
}
|
|
|
|
...
|
|
|
|
|
|
|
|
P1(("PSYC/TCP %O * net_connect(%O, %O) = %O\n",
|
|
|
|
ME, host, port, rc))
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|