Exemplo n.º 1
0
 def placeOriginate(self, oroute):
     cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
     cld = oroute.cld
     self.huntstop_scodes = oroute.params.get('huntstop_scodes', ())
     if 'static_tr_out' in self.global_config:
         cld = re_replace(self.global_config['static_tr_out'], cld)
     if oroute.hostport == 'sip-ua':
         host = self.source[0]
         nh_address, same_af = self.source, True
     else:
         host = oroute.hostonly
         nh_address, same_af = oroute.getNHAddr(self.source)
     if not oroute.forward_on_fail and self.global_config['acct_enable']:
         self.acctO = RadiusAccounting(self.global_config, 'originate', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctO.ms_precision = self.global_config.getdefault(
             'precise_acct', False)
         self.acctO.setParams(oroute.params.get('bill-to', self.username), oroute.params.get('bill-cli', oroute.cli), \
           oroute.params.get('bill-cld', cld), self.cGUID, self.cId, host)
     else:
         self.acctO = None
     self.acctA.credit_time = oroute.credit_time
     conn_handlers = [self.oConn]
     disc_handlers = []
     if not oroute.forward_on_fail and self.global_config['acct_enable']:
         disc_handlers.append(self.acctO.disc)
     self.uaO = UA(self.global_config, self.recvEvent, oroute.user, oroute.passw, nh_address, oroute.credit_time, tuple(conn_handlers), \
       tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = oroute.expires, \
       no_progress_time = oroute.no_progress_expires, extra_headers = oroute.extra_headers)
     self.uaO.local_ua = self.global_config['_uaname']
     self.uaO.no_reply_time = oroute.no_reply_expires
     if self.source != oroute.params.get('outbound_proxy', None):
         self.uaO.outbound_proxy = oroute.params.get('outbound_proxy', None)
     if self.rtp_proxy_session != None and oroute.params.get('rtpp', True):
         self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         self.rtp_proxy_session.caller.raddress = nh_address
         if body != None:
             body = body.getCopy()
         self.proxied = True
     self.uaO.kaInterval = self.global_config['keepalive_orig']
     if 'group_timeout' in oroute.params:
         timeout, skipto = oroute.params['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     if self.global_config.getdefault('hide_call_id', False):
         cId = SipCallId(
             md5(str(cId).encode()).hexdigest() + ('-b2b_%d' % oroute.rnum))
     else:
         cId += '-b2b_%d' % oroute.rnum
     event = CCEventTry((cId, cGUID, oroute.cli, cld, body, auth, \
       oroute.params.get('caller_name', self.caller_name)))
     if self.eTry.max_forwards != None:
         event.max_forwards = self.eTry.max_forwards - 1
         if event.max_forwards <= 0:
             self.uaA.recvEvent(CCEventFail((483, 'Too Many Hops')))
             self.state = CCStateDead
             return
     event.reason = self.eTry.reason
     self.uaO.recvEvent(event)
Exemplo n.º 2
0
 def createUa0(self, param):
     self.global_config['_sip_logger'].write(
         'requestCallback %s==>' % (self.id), param)
     res = param.get('invite')
     if (res == None):
         return
     if res == "0":
         self._number = res
         self.uaA.recvEvent(
             CCEventFail((480, 'No Number'),
                         rtime=self._invite_event.rtime))
     else:
         self._number, _type, _gateway, _vos_ip = res.split("|")
         cId, cGUID, cli, cld, body, auth, caller_name = self._invite_event.getData(
         )
         oli = self.cli
         if _type == "3":
             oli = cli + cld[8:]
         event = self._invite_event
         event.data = (SipCallId(), cGUID, oli, self._number, body, auth,
                       caller_name)
         parts = _vos_ip.split(':')
         port = '5060'
         if len(parts) == 2:
             port = parts[1]
         self.uaO = UA(self.global_config,
                       event_cb=self.recvEvent,
                       nh_address=tuple([parts[0], int(port)]))
         self.uaO.recvEvent(event)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
 def __init__(self, tccfg):
     self.tccfg = tccfg
     if tccfg.cli != None:
         self.cli = tccfg.cli
     uaO = UA(tccfg.global_config, event_cb = self.recvEvent, nh_address = tccfg.nh_address, \
       conn_cbs = (self.connected,), disc_cbs = (self.disconnected,), fail_cbs = (self.disconnected,), \
       dead_cbs = (self.alldone,), ltag = gen_test_tag())
     uaO.godead_timeout = self.godead_timeout
     uaO.compact_sip = self.compact_sip
     self.call_id = SipCallId(body=gen_test_cid())
     event = CCEventTry((self.call_id, SipCiscoGUID(), self.cli, self.cld, tccfg.body, \
       None, 'Alice Smith'))
     self.run(uaO, event)
Exemplo n.º 5
0
def register_clients(ud):
    # For each record in UserData list create a registrar UA
    for (InternalUserId, ExtDisplayName, ExtName, ExtLogin, ExtPassword,
         ExtDomain, ExtPort) in ud.Data:
        Ua = UA(global_config,
                event_cb=recvEvent,
                username=ExtLogin,
                password=ExtPassword,
                conn_cbs=(recvConnect, ),
                disc_cbs=(recvDisconnect, ),
                fail_cbs=(recvDisconnect, ),
                dead_cbs=(recvDead, ),
                nh_address=(global_config['proxy_address'],
                            global_config['proxy_port']))

        if ExtPort == None:
            Ua.rTarget = SipURL(url="sip:" + ExtName + "@" + ExtDomain)
            Ua.rUri = SipTo(body="<sip:" + ExtName + "@" + ExtDomain + ">")
            Ua.lUri = SipFrom(body=ExtDisplayName + " <sip:" + ExtName + "@" +
                              ExtDomain + ">")
        else:
            Ua.rTarget = SipURL(url="sip:" + ExtName + "@" + ExtDomain + ":" +
                                ExtPort)
            Ua.rUri = SipTo(body="<sip:" + ExtName + "@" + ExtDomain + ":" +
                            ExtPort + ">")
            Ua.lUri = SipFrom(body=ExtDisplayName + " <sip:" + ExtName + "@" +
                              ExtDomain + ":" + ExtPort + ">")
        Ua.lUri.parse()
        Ua.lUri.genTag()
        Ua.lContact = SipContact(body="<sip:" + InternalUserId + "@" +
                                 global_config['proxy_address'] + ">")
        Ua.routes = ()
        Ua.lCSeq = 1
        Ua.rCSeq = 1
        Ua.cId = SipCallId()
        req = Ua.genRequest("REGISTER")
        Ua.changeState((UacStateTrying, ))
        global_config['_sip_tm'].regConsumer(Ua, str(Ua.cId))
        Ua.tr = global_config['_sip_tm'].newTransaction(req, Ua.recvResponse)
Exemplo n.º 6
0
 def placeOriginate(self, args):
     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:
         if host.startswith('['):
             # IPv6
             host = host.split(']', 1)
             port = host[1].split(':', 1)
             host = host[0] + ']'
             if len(port) > 1:
                 port = int(port[1])
             else:
                 port = SipConf.default_port
         else:
             # IPv4
             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.acctO = RadiusAccounting(self.global_config, 'originate', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctO.ms_precision = self.global_config.getdefault('precise_acct', False)
         self.acctO.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
           parameters.get('bill-cld', cld), self.cGUID, self.cId, host)
     else:
         self.acctO = None
     self.acctA.credit_time = credit_time
     conn_handlers = [self.oConn]
     disc_handlers = []
     if not forward_on_fail and self.global_config['acct_enable']:
         disc_handlers.append(self.acctO.disc)
     self.uaO = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, tuple(conn_handlers), \
       tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = expires, \
       no_progress_time = no_progress_expires, extra_headers = parameters.get('extra_headers', None))
     if self.source != parameters.get('outbound_proxy', None):
         self.uaO.outbound_proxy = parameters.get('outbound_proxy', None)
     if self.rtp_proxy_session != None and parameters.get('rtpp', True):
         self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         self.rtp_proxy_session.caller_raddress = (host, port)
         if body != None:
             body = body.getCopy()
             body.content += 'a=nortpproxy:yes\r\n'
         self.proxied = True
     self.uaO.kaInterval = self.global_config['keepalive_orig']
     if parameters.has_key('group_timeout'):
         timeout, skipto = parameters['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     if self.global_config.getdefault('hide_call_id', False):
         cId = SipCallId(md5(str(cId)).hexdigest() + ('-b2b_%d' % rnum))
     else:
         cId += '-b2b_%d' % rnum
     event = CCEventTry((cId, cGUID, cli, cld, body, auth, \
       parameters.get('caller_name', self.caller_name)))
     event.reason = self.eTry.reason
     self.uaO.recvEvent(event)
Exemplo n.º 7
0
 def recvEvent(self, event):
     if isinstance(event, CCEventTry):
         if self.ua.setup_ts == None:
             self.ua.setup_ts = event.rtime
         self.ua.origin = 'callee'
         cId, cGUID, callingID, calledID, body, auth, callingName = event.getData(
         )
         if body != None:
             if self.ua.on_local_sdp_change != None and body.needs_update:
                 self.ua.on_local_sdp_change(
                     body, lambda x: self.ua.recvEvent(event))
                 return None
         else:
             self.ua.late_media = True
         if cId == None:
             self.ua.cId = SipCallId()
         else:
             self.ua.cId = cId.getCopy()
         self.ua.global_config['_sip_tm'].regConsumer(
             self.ua, str(self.ua.cId), compact=self.ua.compact_sip)
         self.ua.rTarget = SipURL(username=calledID,
                                  host=self.ua.rAddr0[0],
                                  port=self.ua.rAddr0[1])
         self.ua.rUri = SipTo(address=SipAddress(
             url=self.ua.rTarget.getCopy(), hadbrace=True))
         self.ua.rUri.getUrl().port = None
         self.ua.lUri = SipFrom(address=SipAddress(url=SipURL(
             username=callingID),
                                                   hadbrace=True,
                                                   name=callingName))
         self.ua.lUri.getUrl().port = None
         self.ua.lUri.setTag(self.ua.lTag)
         self.ua.lCSeq = 200
         if self.ua.lContact == None:
             self.ua.lContact = SipContact()
         self.ua.lContact.getUrl().username = callingID
         self.ua.routes = []
         self.ua.cGUID = cGUID
         self.ua.lSDP = body
         event.onUacSetupComplete(self.ua)
         req = self.ua.genRequest('INVITE', body, reason = event.reason, \
           max_forwards = event.max_forwards)
         self.ua.lCSeq += 1
         self.ua.tr = self.ua.global_config['_sip_tm'].newTransaction(req, self.ua.recvResponse, \
           laddress = self.ua.source_address, cb_ifver = 2, compact = self.ua.compact_sip)
         self.ua.auth = None
         if self.ua.expire_time != None:
             self.ua.expire_time += event.rtime
         if self.ua.no_progress_time != None:
             self.ua.no_progress_time += event.rtime
             if self.ua.expire_time != None and self.ua.no_progress_time >= self.ua.expire_time:
                 self.ua.no_progress_time = None
         if self.ua.no_reply_time != None:
             if self.ua.no_reply_time < 32:
                 self.ua.no_reply_time += event.rtime
                 if self.ua.expire_time != None and self.ua.no_reply_time >= self.ua.expire_time:
                     self.ua.no_reply_time = None
                 elif self.ua.no_progress_time != None and self.ua.no_reply_time >= self.ua.no_progress_time:
                     self.ua.no_reply_time = None
             else:
                 self.ua.no_reply_time = None
         if self.ua.no_reply_time != None:
             self.ua.no_reply_timer = TimeoutAbsMono(
                 self.ua.no_reply_expires, self.ua.no_reply_time)
         elif self.ua.no_progress_time != None:
             self.ua.no_progress_timer = TimeoutAbsMono(
                 self.ua.no_progress_expires, self.ua.no_progress_time)
         elif self.ua.expire_time != None:
             self.ua.expire_timer = TimeoutAbsMono(self.ua.expires,
                                                   self.ua.expire_time)
         return (UacStateTrying, )
     if isinstance(event, CCEventFail) or isinstance(
             event, CCEventRedirect) or isinstance(event,
                                                   CCEventDisconnect):
         return (UaStateDead, self.ua.disc_cbs, event.rtime, event.origin)
     return None