当前位置: 首页>>代码示例>>Python>>正文


Python UA.recvEvent方法代码示例

本文整理汇总了Python中sippy.UA.UA.recvEvent方法的典型用法代码示例。如果您正苦于以下问题:Python UA.recvEvent方法的具体用法?Python UA.recvEvent怎么用?Python UA.recvEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sippy.UA.UA的用法示例。


在下文中一共展示了UA.recvEvent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
    def __init__(self, global_config, body, done_cb, portrange):
        uaO = UA(global_config, event_cb = self.recvEvent, nh_address = ('127.0.0.1', 5060), \
          conn_cbs = (self.connected,), disc_cbs = (self.disconnected,), fail_cbs = (self.disconnected,), \
          dead_cbs = (self.alldone,))
        uaO.godead_timeout = 10
        uaO.compact_sip = self.compact_sip

        event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, body, \
          None, 'Alice Smith'))
        uaO.recvEvent(event)
        self.done_cb = done_cb
        self.portrange = portrange
开发者ID:hongbinz,项目名称:voiptests,代码行数:14,代码来源:a_test1.py

示例2: placeOriginate

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
 def placeOriginate(self, args, conn_cbs):
     cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
     rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
       parameters = args
     self.huntstop_scodes = parameters.get('huntstop_scodes', ())
     if self.global_config.has_key('static_tr_out'):
         cld = re_replace(self.global_config['static_tr_out'], cld)
     if host == 'sip-ua':
         host = self.source[0]
         port = self.source[1]
     else:
         host = host.split(':', 1)
         if len(host) > 1:
             port = int(host[1])
         else:
             port = SipConf.default_port
         host = host[0]
     disc_cbs = []
     if not forward_on_fail and self.global_config['acct_enable']:
         self.acctO = RadiusAccounting(self.global_config, 'originate', send_start = self.global_config['start_acct_enable'])
         self.acctO.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
           parameters.get('bill-cld', cld), self.cGUID, self.cId, host, credit_time)
         print 'adding acct stop cb'
         disc_cbs.append(self.acctO.disc)
     else:
         self.acctO = None
     self.acctA.credit_time = credit_time
     ua = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, \
       (conn_cbs,), tuple(disc_cbs), tuple(disc_cbs), dead_cbs = (self.oDead,), \
       expire_time = expires, no_progress_time = no_progress_expires, \
       extra_headers = parameters.get('extra_headers', None))
     if self.rtp_proxy_session and parameters.get('rtpp', True):
         ua.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         ua.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         body = body.getCopy()
         body.content += 'a=nortpproxy:yes\r\n'
         self.proxied = True
     ua.kaInterval = self.global_config['ka_orig']
     if parameters.has_key('group_timeout'):
         timeout, skipto = parameters['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     ua.recvEvent(CCEventTry((cId + '-b2b_%d' % rnum, cGUID, cli, cld, body, auth, \
       parameters.get('caller_name', self.caller_name))))
     return ua
开发者ID:gtkiller,项目名称:b2bua,代码行数:46,代码来源:b2bua_radius.py

示例3: placeAnswer

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
 def placeAnswer(self, args):
     cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData() #TODO: move to a subroutine
     rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
       parameters = args
     self.huntstop_scodes = parameters.get('huntstop_scodes', ())
     if self.global_config.has_key('static_tr_out'):
         cld = re_replace(self.global_config['static_tr_out'], cld)
     if host == 'sip-ua':
         host = self.source[0]
         port = self.source[1]
     else:
         host = host.split(':', 1)
         if len(host) > 1:
             port = int(host[1])
         else:
             port = SipConf.default_port
         host = host[0]
     if not forward_on_fail and self.global_config['acct_enable']:
         self.acctA = RadiusAccounting(self.global_config, 'answer', send_start = self.global_config['start_acct_enable'])
         self.acctA.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
           parameters.get('bill-cld', cld), self.cGUID, self.cId, host, credit_time)
         print 'adding acct stop cb'
     else:
         self.acctA = FakeAccounting()
     ua = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, \
       (self.aConnA,), (self.aDisc,), (self.aDisc,), dead_cbs = (self.aDead,), \
       expire_time = expires, no_progress_time = no_progress_expires, \
       extra_headers = parameters.get('extra_headers', None))
     if self.rtp_proxy_session and parameters.get('rtpp', True):
         print 'placeAnswer() registering on sdp change callbacks'
         ua.on_local_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         ua.on_remote_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         body = body.getCopy()
         body.content += 'a=nortpproxy:yes\r\n'
         self.proxied = True
     ua.kaInterval = self.global_config['ka_ans'] #TODO: is this okay for uaA?
     if parameters.has_key('group_timeout'):
         timeout, skipto = parameters['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     ua.recvEvent(CCEventTry((cId + '-b2b_%d' % rnum, cGUID, cli, cld, body, auth, \
       parameters.get('caller_name', self.caller_name))))
     return ua
开发者ID:gtkiller,项目名称:b2bua,代码行数:44,代码来源:b2bua_radius.py

示例4: CallController

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
class CallController(object):
    global_config = None
    uaA = None
    uaO = None
    nh_addr = None

    def __init__(self, global_config):
        self.global_config = global_config
        self.uaA = UA(self.global_config, self.recvEvent)
        self.uaO = None

    def recvEvent(self, event, ua):
        if ua == self.uaA:
            if self.uaO == None:
                if not isinstance(event, CCEventTry):
                    # Some weird event received
                    self.uaA.recvEvent(CCEventDisconnect())
                    return
                self.uaO = UA(self.global_config, event_cb = self.recvEvent, nh_address = (self.global_config['nh_addr'], self.global_config['sip_port_default']))
            self.uaO.recvEvent(event)
        else:
            self.uaA.recvEvent(event)
开发者ID:gtkiller,项目名称:b2bua,代码行数:24,代码来源:b2bua_simple.py

示例5: CallController

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
class CallController(object):
    id = 1
    uaA = None
    uaO = None
    state = None
    cId = None
    cld = None
    eTry = None
    routes = None
    remote_ip = None
    source = None
    acctA = None
    acctO = None
    global_config = None
    rtp_proxy_session = None
    huntstop_scodes = None
    pass_headers = None
    auth_proc = None
    proxied = False
    challenge = None

    def __init__(self, remote_ip, source, global_config, pass_headers):
        self.id = CallController.id
        CallController.id += 1
        self.global_config = global_config
        self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
          fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
        self.uaA.kaInterval = self.global_config['keepalive_ans']
        self.state = CCStateIdle
        self.uaO = None
        self.routes = []
        self.remote_ip = remote_ip
        self.source = source
        self.pass_headers = pass_headers

    def recvEvent(self, event, ua):
        if ua == self.uaA:
            if self.state == CCStateIdle:
                if not isinstance(event, CCEventTry):
                    # Some weird event received
                    self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
                    return
                self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
                self.cGUID = cGUID.hexForm()
                if self.cld == None:
                    self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
                    self.state = CCStateDead
                    return
                if body == None:
                    self.uaA.recvEvent(CCEventFail((500, 'Body-less INVITE is not supported'), rtime = event.rtime))
                    self.state = CCStateDead
                    return
                if self.global_config.has_key('_allowed_pts'):
                    try:
                        body.parse()
                    except:
                        self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
                        self.state = CCStateDead
                        return
                    allowed_pts = self.global_config['_allowed_pts']
                    mbody = body.content.sections[0].m_header
                    if mbody.transport.lower() == 'rtp/avp':
                        mbody.formats = [x for x in mbody.formats if x in allowed_pts]
                        if len(mbody.formats) == 0:
                            self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
                            self.state = CCStateDead
                            return
                if self.cld.startswith('nat-'):
                    self.cld = self.cld[4:]
                    body.content += 'a=nated:yes\r\n'
                    event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
                if self.global_config.has_key('static_tr_in'):
                    self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
                    event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
                if self.global_config.has_key('_rtp_proxy_clients'):
                    self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
                      notify_socket = global_config['b2bua_socket'], \
                      notify_tag = quote('r %s' % str(self.id)))
                    self.rtp_proxy_session.callee_raddress = (self.remote_ip, 5060)
                self.eTry = event
                self.state = CCStateWaitRoute
                if not self.global_config['auth_enable']:
                    self.username = self.remote_ip
                    self.rDone(((), 0))
                elif auth == None or auth.username == None or len(auth.username) == 0:
                    self.username = self.remote_ip
                    self.auth_proc = self.global_config['_radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
                      self.cId, self.remote_ip, self.rDone)
                else:
                    self.username = auth.username
                    self.auth_proc = self.global_config['_radius_client'].do_auth(auth.username, self.cli, self.cld, self.cGUID, 
                      self.cId, self.remote_ip, self.rDone, auth.realm, auth.nonce, auth.uri, auth.response)
                return
            if self.state not in (CCStateARComplete, CCStateConnected, CCStateDisconnecting) or self.uaO == None:
                return
            self.uaO.recvEvent(event)
        else:
            if (isinstance(event, CCEventFail) or isinstance(event, CCEventDisconnect)) and self.state == CCStateARComplete and \
              (isinstance(self.uaA.state, UasStateTrying) or isinstance(self.uaA.state, UasStateRinging)) and len(self.routes) > 0:
                if isinstance(event, CCEventFail):
#.........这里部分代码省略.........
开发者ID:DarthRa,项目名称:pulsar,代码行数:103,代码来源:b2bua_radius.py

示例6: CallController

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
class CallController(object):
    id = 1
    uaA = None
    uaO = None
    state = None
    cId = None
    cld = None
    eTry = None
    routes = None
    remote_ip = None
    source = None
    acctA = None
    acctO = None
    global_config = None
    rtp_proxy_session = None
    huntstop_scodes = None
    pass_headers = None
    auth_proc = None
    proxied = False
    challenge = None

    def __init__(self, remote_ip, source, global_config, pass_headers):
        self.id = CallController.id
        CallController.id += 1
        self.global_config = global_config
        self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
          fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
        self.uaA.kaInterval = self.global_config['keepalive_ans']
        self.uaA.local_ua = self.global_config['_uaname']
        self.state = CCStateIdle
        self.uaO = None
        self.routes = []
        self.remote_ip = remote_ip
        self.source = source
        self.pass_headers = pass_headers

    def recvEvent(self, event, ua):
        if ua == self.uaA:
            if self.state == CCStateIdle:
                if not isinstance(event, CCEventTry):
                    # Some weird event received
                    self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
                    return
                self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
                self.cGUID = cGUID.hexForm()
                if self.cld == None:
                    self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
                    self.state = CCStateDead
                    return
                if body != None and '_allowed_pts' in self.global_config:
                    try:
                        body.parse()
                    except:
                        self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
                        self.state = CCStateDead
                        return
                    allowed_pts = self.global_config['_allowed_pts']
                    mbody = body.content.sections[0].m_header
                    if mbody.transport.lower() == 'rtp/avp':
                        old_len = len(mbody.formats)
                        mbody.formats = [x for x in mbody.formats if x in allowed_pts]
                        if len(mbody.formats) == 0:
                            self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
                            self.state = CCStateDead
                            return
                        if old_len > len(mbody.formats):
                            body.content.sections[0].optimize_a()
                if self.cld.startswith('nat-'):
                    self.cld = self.cld[4:]
                    if body != None:
                        body.content += 'a=nated:yes\r\n'
                    event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
                if 'static_tr_in' in self.global_config:
                    self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
                    event.data = (self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name)
                if '_rtp_proxy_clients' in self.global_config:
                    self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
                      notify_socket = self.global_config['b2bua_socket'], \
                      notify_tag = quote('r %s' % str(self.id)))
                    self.rtp_proxy_session.callee.raddress = (self.remote_ip, 5060)
                    self.rtp_proxy_session.insert_nortpp = True
                self.eTry = event
                self.state = CCStateWaitRoute
                if not self.global_config['auth_enable']:
                    self.username = self.remote_ip
                    self.rDone(((), 0))
                elif auth == None or auth.username == None or len(auth.username) == 0:
                    self.username = self.remote_ip
                    self.auth_proc = self.global_config['_radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
                      self.cId, self.remote_ip, self.rDone)
                else:
                    self.username = auth.username
                    self.auth_proc = self.global_config['_radius_client'].do_auth(auth.username, self.cli, self.cld, self.cGUID, 
                      self.cId, self.remote_ip, self.rDone, auth.realm, auth.nonce, auth.uri, auth.response)
                return
            if self.state not in (CCStateARComplete, CCStateConnected, CCStateDisconnecting) or self.uaO == None:
                return
            self.uaO.recvEvent(event)
        else:
            if (isinstance(event, CCEventFail) or isinstance(event, CCEventDisconnect)) and self.state == CCStateARComplete and \
#.........这里部分代码省略.........
开发者ID:sippy,项目名称:b2bua,代码行数:103,代码来源:b2bua_radius.py

示例7: IoTUAC

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
class IoTUAC(object):
    global_config = None
    ua = None
    cli = 'pel150_uac'
    cld = 'pel150_uas'
    authname = None
    authpass = None
    body = None
    rgen = None
    rserv = None

    def __init__(self, global_config):
        self.global_config = global_config
        SipTransactionManager.nworkers_udp = 1
        global_config['_sip_tm'] = SipTransactionManager(global_config)
        self.body = MsgBody(body_txt)
        self.body.parse()

    def sess_started(self):
        print('started')
        self.ua = UA(self.global_config, event_cb = self.recvEvent, \
          nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
        self.ua.username = self.authname
        self.ua.password = self.authpass
        rtp_laddr = local4remote(self.global_config['nh_addr'][0])
        rserv_opts = Udp_server_opts((rtp_laddr, 0), self.rtp_received)
        rserv_opts.nworkers = 1
        self.rserv = Udp_server({}, rserv_opts)
        sect = self.body.content.sections[0]
        sect.c_header.addr = self.rserv.uopts.laddress[0]
        sect.m_header.port = self.rserv.uopts.laddress[1]
        self.body.content.o_header = SdpOrigin()
        event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
          None, 'PEL 150-2'))
        self.rgen = RTPGen()
        self.ua.recvEvent(event)
        return (self.rgen.enqueue)

    def sess_term(self, ua, rtime, origin, result = 0):
        print('disconnected', origin)
        if origin == 'IoTUAC':
            return
        self.rgen.suspend()
        self.ua = UA(self.global_config, event_cb = self.recvEvent, \
          nh_address = tuple(self.global_config['nh_addr']), disc_cbs = (self.sess_term,))
        self.ua.username = self.authname
        self.ua.password = self.authpass
        self.body.content.o_header = SdpOrigin()
        event = CCEventTry((SipCallId(), SipCiscoGUID(), self.cli, self.cld, self.body, \
          None, 'PEL 150-2'))
        self.ua.recvEvent(event)

    def sess_ended(self):
        print('ended')
        event = CCEventDisconnect(origin = 'IoTUAC')
        self.ua.recvEvent(event)
        self.rgen.stop()
        self.rserv.shutdown()
        self.rgen = None

    def rtp_received(self, data, address, udp_server, rtime):
        pass

    def recvEvent(self, event, ua):
        print('recvEvent', event, ua)
        if isinstance(event, CCEventRing) or isinstance(event, CCEventConnect) or \
          isinstance(event, CCEventPreConnect):
            code, reason, sdp_body = event.getData()
            if sdp_body == None:
                return
            sdp_body.parse()
            sect = sdp_body.content.sections[0]
            rtp_target = (sect.c_header.addr, sect.m_header.port)
            self.rgen.start(self.rserv, rtp_target)
开发者ID:sippy,项目名称:b2bua,代码行数:76,代码来源:IoTUAC.py

示例8: CallController

# 需要导入模块: from sippy.UA import UA [as 别名]
# 或者: from sippy.UA.UA import recvEvent [as 别名]
class CallController(object):
    id = 1
    uaA = None
    uaO = None
    state = None
    cId = None
    cld = None
    eTry = None
    routes = None
    remote_ip = None
    source = None
    acctA = None
    acctO = None
    global_config = None
    rtp_proxy_session = None
    huntstop_scodes = None
    pass_headers = None
    auth_proc = None
    proxied = False
    challenge = None

    def __init__(self, remote_ip, source, global_config, pass_headers, username = None):
        self.id = CallController.id
        CallController.id += 1
        self.global_config = global_config
        if remote_ip:
            self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
              fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
            self.uaA.kaInterval = self.global_config['ka_ans']
        self.state = CCStateIdle
        self.uaO = None
        self.routes = []
        self.remote_ip = remote_ip
        self.source = source
        self.pass_headers = pass_headers
        self.username = username

    def recvEvent(self, event, ua):
        who = 'uaA' if ua == self.uaA else 'uaO'
        print who, 'received event', event, 'in state', self.state.sname
        if self.uaA:
            print 'self.uaA.state:', self.uaA.state
        if self.uaO:
            print 'self.uaO.state:', self.uaO.state
        if ua == self.uaA:
            if self.state == CCStateIdle:
                if not isinstance(event, CCEventTry):
                    # Some weird event received
                    self.uaA.recvEvent(CCEventDisconnect(rtime = event.rtime))
                    return
                self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name = event.getData()
                print 'auth:', auth
                self.cGUID = cGUID.hexForm()
                if not self.cld:
                    self.uaA.recvEvent(CCEventFail((500, 'Internal Server Error (1)'), rtime = event.rtime))
                    self.state = CCStateDead
                    return
                if not body:
                    self.uaA.recvEvent(CCEventFail((500, 'Body-less INVITE is not supported'), rtime = event.rtime))
                    self.state = CCStateDead
                    return
                if self.global_config.has_key('allowed_pts'):
                    try:
                        body.parse()
                    except:
                        self.uaA.recvEvent(CCEventFail((400, 'Malformed SDP Body'), rtime = event.rtime))
                        self.state = CCStateDead
                        return
                    allowed_pts = self.global_config['allowed_pts']
                    mbody = body.content.sections[0].m_header
                    if mbody.transport.lower() == 'rtp/avp':
                        mbody.formats = [x for x in mbody.formats if x in allowed_pts]
                        if not mbody.formats:
                            self.uaA.recvEvent(CCEventFail((488, 'Not Acceptable Here')))
                            self.state = CCStateDead
                            return
                if self.cld.startswith('nat-'):
                    self.cld = self.cld[4:]
                    body.content += 'a=nated:yes\r\n'
                    event = CCEventTry((self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name), \
                      rtime = event.rtime, origin = event.origin)
                if self.global_config.has_key('static_tr_in'):
                    self.cld = re_replace(self.global_config['static_tr_in'], self.cld)
                    event = CCEventTry((self.cId, cGUID, self.cli, self.cld, body, auth, self.caller_name), \
                      rtime = event.rtime, origin = event.origin)
                if self.global_config.has_key('rtp_proxy_clients'):
                    self.rtp_proxy_session = Rtp_proxy_session(self.global_config, call_id = self.cId, \
                      notify_socket = global_config['b2bua_socket'], \
                      notify_tag = quote('r %s' % str(self.id)))
                self.eTry = event
                self.state = CCStateWaitRoute
                if not self.global_config['auth_enable']:
                    self.username = self.remote_ip
                    self.rDone(((), 0))
                elif not auth or not auth.username:
                    print 'setting username to remote ip ', self.remote_ip
                    self.username = self.remote_ip
                    self.auth_proc = self.global_config['radius_client'].do_auth(self.remote_ip, self.cli, self.cld, self.cGUID, \
                      self.cId, self.remote_ip, self.rDone)
                else:
#.........这里部分代码省略.........
开发者ID:gtkiller,项目名称:b2bua,代码行数:103,代码来源:b2bua_radius.py


注:本文中的sippy.UA.UA.recvEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。