Beispiel #1
0
 def new_from_sip_session(cls, session):
     proposed_stream_types = set(
         [stream.type for stream in session.proposed_streams])
     streams = []
     for stream_type in proposed_stream_types:
         try:
             klass = JingleMediaStreamRegistry.get(stream_type)
         except Exception:
             continue
         streams.append(klass())
     if not streams:
         session.reject(488)
         return None
     session.send_ring_indication()
     instance = cls()
     NotificationCenter().add_observer(instance, sender=session)
     # Get URI representing the SIP side
     contact_uri = session._invitation.remote_contact_header.uri
     if contact_uri.parameters.get('gr') is not None:
         sip_leg_uri = FrozenURI(contact_uri.user, contact_uri.host,
                                 contact_uri.parameters.get('gr'))
     else:
         tmp = session.remote_identity.uri
         sip_leg_uri = FrozenURI(tmp.user, tmp.host,
                                 generate_sylk_resource())
     instance._sip_identity = Identity(sip_leg_uri)
     # Get URI representing the XMPP side
     request_uri = session.request_uri
     remote_resource = request_uri.parameters.get('gr', None)
     if remote_resource is not None:
         try:
             remote_resource = decode_resource(remote_resource)
         except (TypeError, UnicodeError):
             remote_resource = None
     xmpp_leg_uri = FrozenURI(request_uri.user, request_uri.host,
                              remote_resource)
     instance._xmpp_identity = Identity(xmpp_leg_uri)
     instance.sip_session = session
     instance._start_outgoing_jingle_session(streams)
     return instance
Beispiel #2
0
 def new_from_sip_session(cls, session):
     proposed_stream_types = set([stream.type for stream in session.proposed_streams])
     streams = []
     for stream_type in proposed_stream_types:
         try:
             klass = JingleMediaStreamRegistry.get(stream_type)
         except Exception:
             continue
         streams.append(klass())
     if not streams:
         session.reject(488)
         return None
     session.send_ring_indication()
     instance = cls()
     NotificationCenter().add_observer(instance, sender=session)
     # Get URI representing the SIP side
     contact_uri = session._invitation.remote_contact_header.uri
     if contact_uri.parameters.get('gr') is not None:
         sip_leg_uri = FrozenURI(contact_uri.user, contact_uri.host, contact_uri.parameters.get('gr'))
     else:
         tmp = session.remote_identity.uri
         sip_leg_uri = FrozenURI(tmp.user, tmp.host, generate_sylk_resource())
     instance._sip_identity = Identity(sip_leg_uri)
     # Get URI representing the XMPP side
     request_uri = session.request_uri
     remote_resource = request_uri.parameters.get('gr', None)
     if remote_resource is not None:
         try:
             remote_resource = decode_resource(remote_resource)
         except (TypeError, UnicodeError):
             remote_resource = None
     xmpp_leg_uri = FrozenURI(request_uri.user, request_uri.host, remote_resource)
     instance._xmpp_identity = Identity(xmpp_leg_uri)
     instance.sip_session = session
     instance._start_outgoing_jingle_session(streams)
     return instance
Beispiel #3
0
    def incoming_chat_session(self, session):
        # Check if this session is really an invitation to add a participant to a conference room / muc
        if session.remote_identity.uri.host in self.xmpp_manager.muc_domains and 'isfocus' in session._invitation.remote_contact_header.parameters:
            try:
                referred_by_uri = SIPURI.parse(
                    session.transfer_info.referred_by)
            except SIPCoreError:
                log.info(
                    "SIP multiparty session invitation %s failed: invalid Referred-By header"
                    % session.call_id)
                session.reject(488)
                return
            muc_uri = FrozenURI(session.remote_identity.uri.user,
                                session.remote_identity.uri.host)
            inviter_uri = FrozenURI(referred_by_uri.user, referred_by_uri.host)
            recipient_uri = FrozenURI(session.local_identity.uri.user,
                                      session.local_identity.uri.host)
            sender = Identity(muc_uri)
            recipient = Identity(recipient_uri)
            inviter = Identity(inviter_uri)
            try:
                handler = self.s2x_muc_add_participant_handlers[(
                    muc_uri, recipient_uri)]
            except KeyError:
                handler = S2XMucInvitationHandler(session, sender, recipient,
                                                  inviter)
                self.s2x_muc_add_participant_handlers[(
                    muc_uri, recipient_uri)] = handler
                NotificationCenter().add_observer(self, sender=handler)
                handler.start()
            else:
                log.info(
                    "SIP multiparty session invitation %s failed: there is another invitation in progress from %s to %s"
                    % (session.call_id, format_uri(inviter_uri, 'sip'),
                       format_uri(recipient_uri, 'xmpp')))
                session.reject(480)
            return

        # Check domain
        if session.remote_identity.uri.host not in XMPPGatewayConfig.domains:
            log.info(
                'Session rejected: From domain is not a local XMPP domain')
            session.reject(606, 'Not Acceptable')
            return

        # Get URI representing the SIP side
        contact_uri = session._invitation.remote_contact_header.uri
        if contact_uri.parameters.get('gr') is not None:
            sip_leg_uri = FrozenURI(contact_uri.user, contact_uri.host,
                                    contact_uri.parameters.get('gr'))
        else:
            tmp = session.remote_identity.uri
            sip_leg_uri = FrozenURI(tmp.user, tmp.host,
                                    generate_sylk_resource())

        # Get URI representing the XMPP side
        request_uri = session.request_uri
        remote_resource = request_uri.parameters.get('gr', None)
        if remote_resource is not None:
            try:
                remote_resource = decode_resource(remote_resource)
            except (TypeError, UnicodeError):
                remote_resource = None
        xmpp_leg_uri = FrozenURI(request_uri.user, request_uri.host,
                                 remote_resource)

        try:
            handler = self.pending_sessions[(sip_leg_uri, xmpp_leg_uri)]
        except KeyError:
            pass
        else:
            # There is another pending session with same identifiers, can't accept this one
            log.info(
                'Session rejected: other session with same identifiers in progress'
            )
            session.reject(488)
            return

        sip_identity = Identity(sip_leg_uri,
                                session.remote_identity.display_name)
        handler = ChatSessionHandler.new_from_sip_session(
            sip_identity, session)
        NotificationCenter().add_observer(self, sender=handler)
        key = (sip_leg_uri, xmpp_leg_uri)
        self.pending_sessions[key] = handler

        if xmpp_leg_uri.resource is not None:
            # Incoming session target contained GRUU, so create XMPPChatSession immediately
            xmpp_session = XMPPChatSession(
                local_identity=handler.sip_identity,
                remote_identity=Identity(xmpp_leg_uri))
            handler.xmpp_identity = xmpp_session.remote_identity
            handler.xmpp_session = xmpp_session
Beispiel #4
0
    def incoming_chat_session(self, session):
        # Check if this session is really an invitation to add a participant to a conference room / muc
        if (
            session.remote_identity.uri.host in self.xmpp_manager.muc_domains
            and "isfocus" in session._invitation.remote_contact_header.parameters
        ):
            try:
                referred_by_uri = SIPURI.parse(session.transfer_info.referred_by)
            except SIPCoreError:
                log.msg("SIP multiparty session invitation %s failed: invalid Referred-By header" % session.call_id)
                session.reject(488)
                return
            muc_uri = FrozenURI(session.remote_identity.uri.user, session.remote_identity.uri.host)
            inviter_uri = FrozenURI(referred_by_uri.user, referred_by_uri.host)
            recipient_uri = FrozenURI(session.local_identity.uri.user, session.local_identity.uri.host)
            sender = Identity(muc_uri)
            recipient = Identity(recipient_uri)
            inviter = Identity(inviter_uri)
            try:
                handler = self.s2x_muc_add_participant_handlers[(muc_uri, recipient_uri)]
            except KeyError:
                handler = S2XMucInvitationHandler(session, sender, recipient, inviter)
                self.s2x_muc_add_participant_handlers[(muc_uri, recipient_uri)] = handler
                NotificationCenter().add_observer(self, sender=handler)
                handler.start()
            else:
                log.msg(
                    "SIP multiparty session invitation %s failed: there is another invitation in progress from %s to %s"
                    % (session.call_id, format_uri(inviter_uri, "sip"), format_uri(recipient_uri, "xmpp"))
                )
                session.reject(480)
            return

        # Check domain
        if session.remote_identity.uri.host not in XMPPGatewayConfig.domains:
            log.msg("Session rejected: From domain is not a local XMPP domain")
            session.reject(606, "Not Acceptable")
            return

        # Get URI representing the SIP side
        contact_uri = session._invitation.remote_contact_header.uri
        if contact_uri.parameters.get("gr") is not None:
            sip_leg_uri = FrozenURI(contact_uri.user, contact_uri.host, contact_uri.parameters.get("gr"))
        else:
            tmp = session.remote_identity.uri
            sip_leg_uri = FrozenURI(tmp.user, tmp.host, generate_sylk_resource())

        # Get URI representing the XMPP side
        request_uri = session.request_uri
        remote_resource = request_uri.parameters.get("gr", None)
        if remote_resource is not None:
            try:
                remote_resource = decode_resource(remote_resource)
            except (TypeError, UnicodeError):
                remote_resource = None
        xmpp_leg_uri = FrozenURI(request_uri.user, request_uri.host, remote_resource)

        try:
            handler = self.pending_sessions[(sip_leg_uri, xmpp_leg_uri)]
        except KeyError:
            pass
        else:
            # There is another pending session with same identifiers, can't accept this one
            log.msg("Session rejected: other session with same identifiers in progress")
            session.reject(488)
            return

        sip_identity = Identity(sip_leg_uri, session.remote_identity.display_name)
        handler = ChatSessionHandler.new_from_sip_session(sip_identity, session)
        NotificationCenter().add_observer(self, sender=handler)
        key = (sip_leg_uri, xmpp_leg_uri)
        self.pending_sessions[key] = handler

        if xmpp_leg_uri.resource is not None:
            # Incoming session target contained GRUU, so create XMPPChatSession immediately
            xmpp_session = XMPPChatSession(local_identity=handler.sip_identity, remote_identity=Identity(xmpp_leg_uri))
            handler.xmpp_identity = xmpp_session.remote_identity
            handler.xmpp_session = xmpp_session