-# Copyright 2004-2005 James Bunton <james@delx.cjb.net>
+# Copyright 2004-2006 James Bunton <james@delx.cjb.net>
# Licensed for distribution under the GPL version 2, check COPYING for details
from debug import LogEvent, INFO, WARN, ERROR
from twisted.internet.defer import Deferred
from twisted.internet import reactor
-from tlib.xmlw import Element, jid
+from twisted.words.xish.domish import Element
+from twisted.words.protocols.jabber.jid import internJID
import sys
self.addFeature(DISCO, None, config.jid)
self.addFeature(DISCO, None, "USER")
+ self.addFeature(DISCO, None, "ROOM")
+
+ def _makeSearchJID(self, jid):
+ if jid.find('@') > 0:
+ if jid.find('%') > 0:
+ return "USER"
+ else:
+ return "ROOM"
+ elif config.compjid and to == config.compjid:
+ return config.jid
+ else:
+ return jid
def sendIq(self, el, timeout=15):
""" Used for sending IQ packets.
return d
def addIdentity(self, category, ctype, name, jid):
- """ Adds an identity to this JID's discovery profile. If jid == "USER" then MSN users will get this identity. """
+ """ Adds an identity to this JID's discovery profile. If jid == "USER" then MSN users will get this identity, jid == "ROOM" is for groupchat rooms. """
LogEvent(INFO)
if not self.identities.has_key(jid):
self.identities[jid] = []
self.identities[jid].append((category, ctype, name))
def addFeature(self, var, handler, jid):
- """ Adds a feature to this JID's discovery profile. If jid == "USER" then MSN users will get this feature. """
+ """ Adds a feature to this JID's discovery profile. If jid == "USER" then MSN users will get this feature, jid == "ROOM" is for groupchat rooms. """
LogEvent(INFO)
if not self.features.has_key(jid):
self.features[jid] = []
self.features[jid].append((var, handler))
def addNode(self, node, handler, name, jid, rootnode):
- """ Adds a node to this JID's discovery profile. If jid == "USER" then MSN users will get this node. """
+ """ Adds a node to this JID's discovery profile. If jid == "USER" then MSN users will get this node, jid == "ROOM" is for groupchat rooms. """
LogEvent(INFO)
if not self.nodes.has_key(jid):
self.nodes[jid] = {}
iqType = el.getAttribute("type")
ulang = utils.getLang(el)
try: # Stringprep
- froj = jid.intern(fro)
- to = jid.intern(to).full()
+ froj = internJID(fro)
+ to = internJID(to).full()
except Exception:
LogEvent(WARN, "", "Dropping IQ because of stringprep error")
self.sendDiscoItemsResponse(to=fro, ID=ID, ulang=ulang, jid=to)
return
- if to.find('@') > 0:
- searchjid = "USER"
- elif config.compjid and to == config.compjid:
- searchjid = config.jid
- else:
- searchjid = to
- for (feature, handler) in self.features.get(searchjid, []):
+ for (feature, handler) in self.features.get(self._makeSearchJID(to), []):
if feature == xmlns and handler:
LogEvent(INFO, "Handler found")
handler(el)
query = iq.addElement("query")
query.attributes["xmlns"] = DISCO_INFO
- searchjid = jid
- if jid.find('@') > 0: searchjid = "USER"
- if config.compjid and jid == config.compjid: searchjid = config.jid
+ searchjid = self._makeSearchJID(jid)
+
# Add any identities
for (category, ctype, name) in self.identities.get(searchjid, []):
identity = query.addElement("identity")
query = iq.addElement("query")
query.attributes["xmlns"] = DISCO_ITEMS
- searchjid = jid
- if jid.find('@') > 0: searchjid = "USER"
- if config.compjid and jid == config.compjid: searchjid = config.jid
+ searchjid = self._makeSearchJID(jid)
for node in self.nodes.get(searchjid, []):
handler, name, rootnode = self.nodes[jid][node]
if rootnode: