app_list = [item for item in os.listdir(toplevel) if os.path.isdir(os.path.join(toplevel, item)) and '__init__.py' in os.listdir(os.path.join(toplevel, item))]
for module in ['sylk.applications.%s' % item for item in set(app_list).difference(ServerConfig.disabled_applications)]:
app_list = [item for item in os.listdir(toplevel) if os.path.isdir(os.path.join(toplevel, item)) and '__init__.py' in os.listdir(os.path.join(toplevel, item))]
sys.path.append(toplevel)
for module in (item for item in set(app_list).difference(ServerConfig.disabled_applications)):
try:
__import__(module)
except ImportError, e:
log.warning('Error loading extra "%s" application: %s' % (module, e))
def load_applications():
load_builtin_applications()
load_extra_applications()
for app in ApplicationRegistry():
try:
app()
except Exception, e:
log.warning('Error loading application: %s' % e)
log.err()
class ApplicationNotLoadedError(Exception):
pass
class IncomingRequestHandler(object):
"""
Handle incoming requests and match them to applications.
"""
__metaclass__ = Singleton
implements(IObserver)
def __init__(self):
load_applications()
registry = ApplicationRegistry()
self.applications = dict((app.__appname__, app) for app in registry)
log.msg(u'Room %s - started by %s with %s' % (self.uri, format_identity(session.remote_identity), self.format_stream_types(session.streams)))
else:
log.msg(u'Room %s - %s joined with %s' % (self.uri, format_identity(session.remote_identity), self.format_stream_types(session.streams)))
if str(session.remote_identity.uri) not in set(str(s.remote_identity.uri) for s in self.sessions if s is not session):
self.dispatch_server_message('%s has joined the room %s' % (format_identity(session.remote_identity), self.format_stream_types(session.streams)), exclude=session)
user_count = len({str(s.remote_identity.uri) for s in self.room.sessions if any(stream for stream in s.streams if stream.type == 'audio')} - {str(self.session.remote_identity.uri)})
# Check if we have any already open chat session and dispatch it there
try:
handler = next(h for h in self.chat_sessions if h.xmpp_identity.uri.user == xmpp_leg_uri.user and h.xmpp_identity.uri.host == xmpp_leg_uri.host and h.sip_identity.uri.user == sip_leg_uri.user and h.sip_identity.uri.host == sip_leg_uri.host)
except StopIteration:
# Not found, need to create a new handler and a outgoing SIP session
# Try harder, maybe the XMPP client changed his from
try:
handler = next(h for h in self.chat_sessions if h.xmpp_identity.uri.user == xmpp_leg_uri.user and h.xmpp_identity.uri.host == xmpp_leg_uri.host and h.sip_identity.uri.user == sip_leg_uri.user and h.sip_identity.uri.host == sip_leg_uri.host)
except StopIteration:
# It's a new XMPP session to a full JID, disregard the full JID and start a new SIP session to the bare JID