mirror of
git://git.psyced.org/git/psyced
synced 2024-08-15 03:25:10 +00:00
fippo contributes support for bidirectional xmpp s2s.. try it out using #define XMPP_BIDI
This commit is contained in:
parent
eeeec5618b
commit
cfbd6c8827
4 changed files with 147 additions and 3 deletions
|
@ -233,6 +233,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXPERIMENTAL
|
#ifdef EXPERIMENTAL
|
||||||
|
# define XMPP_BIDI
|
||||||
# define USE_AUTOALIAS
|
# define USE_AUTOALIAS
|
||||||
// fippo's brilliant single-user channel emulation for jabber MUCs
|
// fippo's brilliant single-user channel emulation for jabber MUCs
|
||||||
// unfortunately it provides no advantages over the old method, yet.
|
// unfortunately it provides no advantages over the old method, yet.
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inherit NET_PATH "jabber/mixin_render";
|
inherit NET_PATH "jabber/mixin_render";
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
inherit NET_PATH "jabber/mixin_parse";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// a derivate of circuit which knows JABBER
|
// a derivate of circuit which knows JABBER
|
||||||
inherit NET_PATH "circuit";
|
inherit NET_PATH "circuit";
|
||||||
|
@ -157,6 +161,13 @@ handle_stream_features(XMLNode node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
if (node["/bidi"] && node["/bidi"]["@xmlns"] == "urn:xmpp:features:bidi") {
|
||||||
|
emitraw("<bidi xmlns='urn:xmpp:bidi'/>");
|
||||||
|
// we don't expect a reply
|
||||||
|
bidi = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef WANT_S2S_SASL
|
#ifdef WANT_S2S_SASL
|
||||||
// possibly authenticated via sasl?
|
// possibly authenticated via sasl?
|
||||||
if (authenticated && !node["/switch"]) {
|
if (authenticated && !node["/switch"]) {
|
||||||
|
@ -360,6 +371,9 @@ jabberMsg(XMLNode node) {
|
||||||
P2(("%O jabber/active got %O\n", ME, node[Tag]))
|
P2(("%O jabber/active got %O\n", ME, node[Tag]))
|
||||||
object o;
|
object o;
|
||||||
string t;
|
string t;
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
mixed su, tu;
|
||||||
|
#endif
|
||||||
switch (node[Tag]) {
|
switch (node[Tag]) {
|
||||||
case "db:result":
|
case "db:result":
|
||||||
/* 10: Receiving Server informs Originating Server of the result
|
/* 10: Receiving Server informs Originating Server of the result
|
||||||
|
@ -374,6 +388,9 @@ jabberMsg(XMLNode node) {
|
||||||
D0( log_file("XMPP_AUTH", "\n%O auth dialback", ME); )
|
D0( log_file("XMPP_AUTH", "\n%O auth dialback", ME); )
|
||||||
#endif
|
#endif
|
||||||
authenticated = 1;
|
authenticated = 1;
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
// sAuthenticated?
|
||||||
|
#endif
|
||||||
runQ();
|
runQ();
|
||||||
} else {
|
} else {
|
||||||
// else: queue failed
|
// else: queue failed
|
||||||
|
@ -475,9 +492,58 @@ jabberMsg(XMLNode node) {
|
||||||
o -> logon();
|
o -> logon();
|
||||||
destruct(ME);
|
destruct(ME);
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
case "message":
|
||||||
|
case "presence":
|
||||||
|
case "iq":
|
||||||
|
if (!authenticated) {
|
||||||
|
// we have not authenticated with either sasl or dialback
|
||||||
|
P2(("xmpp bidi: we have not authenticated with either sasl or dialback\n"))
|
||||||
|
STREAM_ERROR("invalid-from", "")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!bidi) {
|
||||||
|
P2(("xmpp bidi: we have not enabled bidi, so why...\n"))
|
||||||
|
STREAM_ERROR("invalid-from", "")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// check from and to!
|
||||||
|
// for from: == hostname
|
||||||
|
P2(("xmpp bidi from %O to %O\n", node["@from"], node["@to"]))
|
||||||
|
su = parse_uniform(XMPP + node["@from"]);
|
||||||
|
unless (su) {
|
||||||
|
// jid-malformed?
|
||||||
|
P2(("xmpp bidi: could not parse su for %O", node["@from"]))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// qAuthenticated(su[UHost]) ?
|
||||||
|
P2(("xmpp bidi: from host = %O, hostname = %O\n", su[UHost], hostname))
|
||||||
|
unless (su[UHost] == hostname) {
|
||||||
|
P2(("xmpp bidi: source host %O != hostname %O\n", su[UHost], hostname))
|
||||||
|
STREAM_ERROR("invalid-from", "")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for to: is_localhost
|
||||||
|
tu = parse_uniform(XMPP + node["@to"]);
|
||||||
|
unless (tu) {
|
||||||
|
// jid-malformed?
|
||||||
|
P2(("xmpp bidi: could not parse tu for %O", node["@to"]))
|
||||||
|
STREAM_ERROR("invalid-from", "")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
P2(("is_localhost(%O) = %O\n", tu[UHost], is_localhost(tu[UHost])))
|
||||||
|
if (!is_localhost(tu[UHost])) {
|
||||||
|
// ... ?
|
||||||
|
P2(("xmpp bidi: !is_localhost %O\n", node["@to"]))
|
||||||
|
STREAM_ERROR("invalid-from", "")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return ::jabberMsg(node);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
P0(("%O: unexpected %O:%O\n", ME, node["@tag"],
|
P0(("%O: unexpected %O:%O\n", ME, node[Tag],
|
||||||
node["@xmlns"]))
|
node["@xmlns"]))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
inherit NET_PATH "trust";
|
inherit NET_PATH "trust";
|
||||||
|
|
||||||
inherit NET_PATH "jabber/mixin_parse";
|
inherit NET_PATH "jabber/mixin_parse";
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
inherit NET_PATH "jabber/mixin_render";
|
||||||
|
#endif
|
||||||
|
|
||||||
//inherit NET_PATH "storage";
|
//inherit NET_PATH "storage";
|
||||||
volatile object active; // currently unused, but you could send w() to it
|
volatile object active; // currently unused, but you could send w() to it
|
||||||
|
@ -41,6 +44,7 @@ volatile string streamfrom;
|
||||||
volatile string resource;
|
volatile string resource;
|
||||||
volatile mapping certinfo;
|
volatile mapping certinfo;
|
||||||
|
|
||||||
|
|
||||||
v(a, b) {
|
v(a, b) {
|
||||||
PT(("%O v(%O, %O)\n", ME, a, b))
|
PT(("%O v(%O, %O)\n", ME, a, b))
|
||||||
return "";
|
return "";
|
||||||
|
@ -139,6 +143,12 @@ verify_connection(string to, string from, string type) {
|
||||||
D0( log_file("XMPP_AUTH", "\n%O has authenticated %O via dialback", ME, from); )
|
D0( log_file("XMPP_AUTH", "\n%O has authenticated %O via dialback", ME, from); )
|
||||||
#endif
|
#endif
|
||||||
sAuthenticated(from);
|
sAuthenticated(from);
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
if (bidi) {
|
||||||
|
P0(("doing register target for xmpp bidi!!!!\n"))
|
||||||
|
register_target(XMPP + from);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
while (remove_call_out(#'quit) != -1);
|
while (remove_call_out(#'quit) != -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,6 +212,9 @@ jabberMsg(XMLNode node) {
|
||||||
|| node[Tag] == "auth"
|
|| node[Tag] == "auth"
|
||||||
#ifdef SWITCH2PSYC
|
#ifdef SWITCH2PSYC
|
||||||
|| node[Tag] == "switching"
|
|| node[Tag] == "switching"
|
||||||
|
#endif
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
|| node[Tag] == "bidi"
|
||||||
#endif
|
#endif
|
||||||
|| node[Tag] == "starttls") ) {
|
|| node[Tag] == "starttls") ) {
|
||||||
// apparently we are the only jabber server to complain about it
|
// apparently we are the only jabber server to complain about it
|
||||||
|
@ -235,6 +248,14 @@ jabberMsg(XMLNode node) {
|
||||||
o -> sAuthHosts(authhosts);
|
o -> sAuthHosts(authhosts);
|
||||||
destruct(ME);
|
destruct(ME);
|
||||||
return;
|
return;
|
||||||
|
#endif
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
case "bidi":
|
||||||
|
if (node["@xmlns"] == "urn:xmpp:bidi") {
|
||||||
|
//emit("<success xmlns='urn:xmpp:bidi'/>");
|
||||||
|
bidi = 1;
|
||||||
|
}
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
case "db:result":
|
case "db:result":
|
||||||
target = NAMEPREP(target);
|
target = NAMEPREP(target);
|
||||||
|
@ -263,7 +284,7 @@ jabberMsg(XMLNode node) {
|
||||||
// protect against stolen certificates
|
// protect against stolen certificates
|
||||||
if (mappingp(certinfo) && certinfo[0] == 0
|
if (mappingp(certinfo) && certinfo[0] == 0
|
||||||
&& node["@from"] && certificate_check_jabbername(node["@from"], certinfo)) {
|
&& node["@from"] && certificate_check_jabbername(node["@from"], certinfo)) {
|
||||||
P2(("dialback without dialback %O\n", certinfo))
|
P0(("dialback without dialback %O\n", certinfo))
|
||||||
verify_connection(node["@to"], node["@from"], "valid");
|
verify_connection(node["@to"], node["@from"], "valid");
|
||||||
} else {
|
} else {
|
||||||
sendmsg(origin,
|
sendmsg(origin,
|
||||||
|
@ -382,6 +403,13 @@ jabberMsg(XMLNode node) {
|
||||||
P2(("successful sasl external authentication with "
|
P2(("successful sasl external authentication with "
|
||||||
"%O\n", t))
|
"%O\n", t))
|
||||||
sAuthenticated(t);
|
sAuthenticated(t);
|
||||||
|
while (remove_call_out(#'quit) != -1);
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
if (bidi) {
|
||||||
|
P0(("doing register target for xmpp bidi!!!!\n"))
|
||||||
|
register_target(XMPP + t);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
# ifdef LOG_XMPP_AUTH
|
# ifdef LOG_XMPP_AUTH
|
||||||
D0( log_file("XMPP_AUTH", "\n%O has authenticated %O via SASL external", ME, t); )
|
D0( log_file("XMPP_AUTH", "\n%O has authenticated %O via SASL external", ME, t); )
|
||||||
# endif
|
# endif
|
||||||
|
@ -491,7 +519,8 @@ open_stream(XMLNode node) {
|
||||||
// and we have verified it as X509_V_OK (0)
|
// and we have verified it as X509_V_OK (0)
|
||||||
// we offer SASL external (authentication via name
|
// we offer SASL external (authentication via name
|
||||||
// presented in x509 certificate
|
// presented in x509 certificate
|
||||||
P3(("gateway::certinfo %O\n", certinfo))
|
PT(("gateway::certinfo %O\n", certinfo))
|
||||||
|
P0(("gateway::certinfo valid %d\n", certinfo[0]))
|
||||||
# ifndef DIALBACK_WITHOUT_DIAL_BACK
|
# ifndef DIALBACK_WITHOUT_DIAL_BACK
|
||||||
if (mappingp(certinfo) && certinfo[0] == 0) {
|
if (mappingp(certinfo) && certinfo[0] == 0) {
|
||||||
// if from attribute is present we only offer
|
// if from attribute is present we only offer
|
||||||
|
@ -513,6 +542,9 @@ open_stream(XMLNode node) {
|
||||||
packet += "<switch xmlns='http://switch.psyced.org'>"
|
packet += "<switch xmlns='http://switch.psyced.org'>"
|
||||||
"<scheme>psyc</scheme>"
|
"<scheme>psyc</scheme>"
|
||||||
"</switch>";
|
"</switch>";
|
||||||
|
#endif
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
packet += "<bidi xmlns='urn:xmpp:features:bidi'/>";
|
||||||
#endif
|
#endif
|
||||||
packet += "</stream:features>";
|
packet += "</stream:features>";
|
||||||
} else {
|
} else {
|
||||||
|
@ -533,3 +565,44 @@ w(string mc, string data, mapping vars, mixed source) {
|
||||||
vars["_INTERNAL_source_jabber"] = objectp(source) ? mkjid(source) : _host_XMPP;
|
vars["_INTERNAL_source_jabber"] = objectp(source) ? mkjid(source) : _host_XMPP;
|
||||||
sendmsg(origin, mc, data, vars);
|
sendmsg(origin, mc, data, vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
int msg(string source, string mc, string data,
|
||||||
|
mapping vars, int showingLog, string target) {
|
||||||
|
// copy+paste stuff from active.c
|
||||||
|
vars = copy(vars);
|
||||||
|
#ifdef DEFLANG
|
||||||
|
unless(vars["_language"]) vars["_language"] = DEFLANG;
|
||||||
|
#else
|
||||||
|
unless(vars["_language"]) vars["_language"] = "en";
|
||||||
|
#endif
|
||||||
|
/* another note:
|
||||||
|
* instead of queuing the msg()-calls we could simply queue
|
||||||
|
* the output from emit (use the new net/outputb ?)
|
||||||
|
* this avoids bugs with destructed objects
|
||||||
|
*/
|
||||||
|
#if 0 // !EXPERIMENTAL
|
||||||
|
/* currently, we want _status_person_absent
|
||||||
|
* this may change...
|
||||||
|
*/
|
||||||
|
else if (abbrev("_status_person_absent", mc)) return 1;
|
||||||
|
#endif
|
||||||
|
switch (mc){
|
||||||
|
case "_message_echo_private":
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
// desperate hack
|
||||||
|
unless (vars["_INTERNAL_mood_jabber"])
|
||||||
|
vars["_INTERNAL_mood_jabber"] = "neutral";
|
||||||
|
if (abbrev("_dialback", mc)) {
|
||||||
|
P0(("gateway got dialback method %O, this should not happen...\n", mc))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
determine_sourcejid(source, vars);
|
||||||
|
determine_targetjid(target, vars);
|
||||||
|
if (vars["_place"]) vars["_place"] = mkjid(vars["_place"]);
|
||||||
|
// end of copy+paste from active
|
||||||
|
return ::msg(source, mc, data, vars, showingLog, target);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
|
|
||||||
volatile int flags = 0;
|
volatile int flags = 0;
|
||||||
|
|
||||||
|
#ifdef XMPP_BIDI
|
||||||
|
volatile int bidi; // is this stream bidirectional?
|
||||||
|
#endif
|
||||||
|
|
||||||
reboot(reason, restart, pass) {
|
reboot(reason, restart, pass) {
|
||||||
if (pass == 0) {
|
if (pass == 0) {
|
||||||
if (interactive(ME)) {
|
if (interactive(ME)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue