Exemplo n.º 1
0
 def __init__(self, name, global_config, *args, **kwargs):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     self.global_config = global_config
     Rtp_proxy_client.__init__(self, global_config, *args, **kwargs)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Exemplo n.º 2
0
 def go_offline(self):
     #print 'go_offline', self
     if self.online:
         self.global_config['_sip_logger'].write('RTPproxy "%s" has changed ' \
           'status from online to offline' % self.name)
         if self.on_state_change != None:
             self.on_state_change(self, False)
     Rtp_proxy_client.go_offline(self)
Exemplo n.º 3
0
 def go_online(self):
     #print 'go_online', self
     if not self.online:
         self.global_config['_sip_logger'].write('RTPproxy "%s" has changed ' \
           'status from offline to online' % self.name)
         if self.on_state_change != None:
             self.on_state_change(self, True)
     Rtp_proxy_client.go_online(self)
Exemplo n.º 4
0
 def go_offline(self):
     #print 'go_offline', self
     if self.online:
         self.global_config['_sip_logger'].write('RTPproxy "%s" has changed ' \
           'status from online to offline' % self.name)
         self.stats_cache = {}
         if self.on_state_change != None:
             self.on_state_change(self, False)
     Rtp_proxy_client.go_offline(self)
Exemplo n.º 5
0
 def go_online(self):
     # print 'go_online', self
     if not self.online:
         self.global_config["_sip_logger"].write(
             'RTPproxy "%s" has changed ' "status from offline to online" % self.name
         )
         if self.on_state_change != None:
             self.on_state_change(self, True)
     Rtp_proxy_client.go_online(self)
Exemplo n.º 6
0
 def go_offline(self):
     # print 'go_offline', self
     if self.online:
         self.global_config["_sip_logger"].write(
             'RTPproxy "%s" has changed ' "status from online to offline" % self.name
         )
         self.stats_cache = {}
         if self.on_state_change != None:
             self.on_state_change(self, False)
     Rtp_proxy_client.go_offline(self)
Exemplo n.º 7
0
 def go_online(self):
     #print 'go_online', self
     online_pre = self.online
     # Rtp_proxy_client may or may not decide to change actual status
     Rtp_proxy_client.go_online(self)
     if online_pre or not self.online:
         return
     self.global_config['_sip_logger'].write('RTPproxy "%s" has changed ' \
       'state from offline to online' % self.name)
     if self.on_state_change != None:
         self.on_state_change(self, True)
Exemplo n.º 8
0
 def __init__(self, name, global_config, address, cmd_out_address):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     self.global_config = global_config
     self.asess_filtered = rc_filter(0.9)
     self.cmd_out_address = cmd_out_address
     if cmd_out_address != None:
         bind_address = (cmd_out_address, 0)
     else:
         bind_address = None
     Rtp_proxy_client.__init__(self, global_config, address, bind_address = bind_address)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Exemplo n.º 9
0
 def __init__(self, name, global_config, address, cmd_out_address,
              **kwargs):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     self.global_config = global_config
     self.asess_filtered = rc_filter(0.5)
     self.cmd_out_address = cmd_out_address
     self.stats_cache = {}
     if cmd_out_address != None:
         bind_address = (cmd_out_address, 0)
     else:
         bind_address = None
     Rtp_proxy_client.__init__(self,
                               global_config,
                               address,
                               bind_address=bind_address,
                               **kwargs)
     self.timer = TimeoutInact(self.call_id_map_aging, 600, -1)
     self.timer.spread_runs(0.1)
     self.timer.go()
Exemplo n.º 10
0
 def go_offline(self):
     # print 'go_offline', self
     if self.online and self.on_state_change != None:
         self.on_state_change(self, False)
     Rtp_proxy_client.go_offline(self)
Exemplo n.º 11
0
 def go_online(self):
     # print 'go_online', self
     if not self.online and self.on_state_change != None:
         self.on_state_change(self, True)
     Rtp_proxy_client.go_online(self)
Exemplo n.º 12
0
 def __init__(self, name, *args, **kwargs):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     Rtp_proxy_client.__init__(self, *args, **kwargs)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Exemplo n.º 13
0
            continue
        if o == '-i':
            fname = a.strip()
            if fname == '-':
                file_in = sys.stdin
            else:
                file_in = file(fname, 'r')
        if o == '-o':
           fname = a.strip()
           if fname == '-':
               file_out = sys.stdout
           else:
               file_out = file(fname, 'w')
        if o == '-b':
           no_rtpp_version_check = True

    if len(args) > 0:
        commands = args

    if sippy_path != None:
        sys.path.insert(0, sippy_path)

    from sippy.Rtp_proxy_client import Rtp_proxy_client

    rc = Rtp_proxy_client(global_config, spath = spath, no_version_check = no_rtpp_version_check)
    #commands = ('VF 123456', 'G nsess_created', 'G ncmds_rcvd')
    crun = command_runner(rc, commands, file_in, file_out)
    reactor.run(installSignalHandlers = 1)
    rc.shutdown()
    sys.exit(crun.rval)
Exemplo n.º 14
0
 def reconnect(self, address):
     if self.cmd_out_address != None:
         bind_address = (self.cmd_out_address, 0)
     else:
         bind_address = None
     Rtp_proxy_client.reconnect(self, address, bind_address=bind_address)
Exemplo n.º 15
0
 def update_active(self, active_sessions, *more_args):
     self.asess_filtered.apply(active_sessions)
     if self.active_sessions != active_sessions and self.on_active_update != None:
         self.on_active_update(self, active_sessions)
     Rtp_proxy_client.update_active(self, active_sessions, *more_args)
Exemplo n.º 16
0
 def go_online(self):
     #print 'go_online', self
     if not self.online and self.on_state_change != None:
         self.on_state_change(self, True)
     Rtp_proxy_client.go_online(self)
Exemplo n.º 17
0
 def go_offline(self):
     #print 'go_offline', self
     if self.online and self.on_state_change != None:
         self.on_state_change(self, False)
     Rtp_proxy_client.go_offline(self)
Exemplo n.º 18
0
        fd = os.open('/dev/null', os.O_RDONLY)
        os.dup2(fd, sys.__stdin__.fileno())
        os.close(fd)
        fd = os.open(global_config['logfile'],
                     os.O_WRONLY | os.O_CREAT | os.O_APPEND)
        os.dup2(fd, sys.__stdout__.fileno())
        os.dup2(fd, sys.__stderr__.fileno())
        os.close(fd)

    global_config['_sip_logger'] = SipLogger('b2bua')

    if len(rtp_proxy_clients) > 0:
        global_config['_rtp_proxy_clients'] = []
        for address in rtp_proxy_clients:
            global_config['_rtp_proxy_clients'].append(
                Rtp_proxy_client(global_config, address))

    if global_config['auth_enable'] or global_config['acct_enable']:
        global_config['_radius_client'] = RadiusAuthorisation(global_config)
    SipConf.my_uaname = 'Sippy B2BUA (RADIUS)'

    global_config['_cmap'] = CallMap(global_config)

    global_config['_sip_tm'] = SipTransactionManager(
        global_config, global_config['_cmap'].recvRequest)

    cmdfile = global_config['b2bua_socket']
    if cmdfile.startswith('unix:'):
        cmdfile = cmdfile[5:]
    cli_server = Cli_server_local(global_config['_cmap'].recvCommand, cmdfile)
Exemplo n.º 19
0
 def __init__(self, name, *args, **kwargs):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     Rtp_proxy_client.__init__(self, *args, **kwargs)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Exemplo n.º 20
0
           if fname == '-':
               file_out = sys.stdout
           else:
               file_out = open(fname, 'w')
        elif o == '-b':
           no_rtpp_version_check = True
        elif o == '-n':
           nwrks = int(a)
        elif o == '-t':
           timeout = float(a.strip())

    if len(args) > 0:
        commands = args

    if sippy_path != None:
        sys.path.insert(0, sippy_path)

    from sippy.Rtp_proxy_client import Rtp_proxy_client
    from sippy.Time.Timeout import Timeout
    from sippy.Core.EventDispatcher import ED2

    rc = Rtp_proxy_client(global_config, spath = spath, nworkers = nwrks, \
      no_version_check = no_rtpp_version_check)
    #commands = ('VF 123456', 'G nsess_created', 'G ncmds_rcvd')
    crun = command_runner(rc, commands, file_in, file_out)
    if timeout != None:
        Timeout(crun.timeout, timeout)
    ED2.loop(freq = 100.0)
    rc.shutdown()
    sys.exit(crun.rval)
Exemplo n.º 21
0
 def update_active(self, active_sessions):
     if self.active_sessions != active_sessions and self.on_active_update != None:
         self.on_active_update(self, active_sessions)
     Rtp_proxy_client.update_active(self, active_sessions)
Exemplo n.º 22
0
 def update_active(self, active_sessions, *more_args):
     self.asess_filtered.apply(active_sessions)
     if self.active_sessions != active_sessions and self.on_active_update != None:
         self.on_active_update(self, active_sessions)
     Rtp_proxy_client.update_active(self, active_sessions, *more_args)
Exemplo n.º 23
0
 def update_active(self, active_sessions):
     if self.active_sessions != active_sessions and self.on_active_update != None:
         self.on_active_update(self, active_sessions)
     Rtp_proxy_client.update_active(self, active_sessions)
Exemplo n.º 24
0
            #print 'Rtp_proxy_session.__del__() from wrong thread, re-routing'
            ED2.callFromThread(self.delete)
        else:
            self.delete()

if __name__ == '__main__':
    from sippy.Time.Timeout import Timeout
    from sippy.Rtp_proxy_client import Rtp_proxy_client
    def display(*args):
        print('got:', args)
        ED2.breakLoop()
    def waitonline(rpc):
        if rpc.online:
            ED2.breakLoop()
    gc = {'_sip_address':'1.2.3.4'}
    r = Rtp_proxy_client(gc)
    t = Timeout(waitonline, 0.1, 10, r)
    ED2.loop(2.0)
    assert(r.online)
    t.cancel()

    gc['rtp_proxy_client'] = r
    rs = Rtp_proxy_session(gc, 'call_id1', 'from_tag1', 'to_tag1')
    rs.version(display)
    ED2.loop()

    rs.start_recording('bogus', result_callback = display)
    print(1)
    ED2.loop()
    print(2)
    rs.play_callee('bogus', result_callback = display)
Exemplo n.º 25
0
def main_func():
    global_config = MyConfigParser()
    global_config['digest_auth'] = True
    global_config['start_acct_enable'] = False
    global_config['keepalive_ans'] = 0
    global_config['keepalive_orig'] = 0
    global_config['auth_enable'] = True
    global_config['acct_enable'] = True
    global_config['_pass_headers'] = []
    global_config['_orig_argv'] = sys.argv[:]
    global_config['_orig_cwd'] = os.getcwd()
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], 'fDl:p:d:P:L:s:a:t:T:k:m:A:ur:F:R:h:c:M:HC:W:',
            global_config.get_longopts())
    except getopt.GetoptError:
        usage(global_config)
    global_config['foreground'] = False
    global_config['pidfile'] = '/var/run/b2bua.pid'
    global_config['logfile'] = '/var/log/b2bua.log'
    global_config['b2bua_socket'] = '/var/run/b2bua.sock'
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    global_config['_my_pid'] = os.getpid()
    rtp_proxy_clients = []
    writeconf = None
    for o, a in opts:
        if o == '-f':
            global_config['foreground'] = True
            continue
        if o == '-l':
            global_config.check_and_set('sip_address', a)
            continue
        if o == '-p':
            global_config.check_and_set('sip_port', a)
            continue
        if o == '-P':
            global_config.check_and_set('pidfile', a)
            continue
        if o == '-L':
            global_config.check_and_set('logfile', a)
            continue
        if o == '-s':
            global_config.check_and_set('static_route', a)
            continue
        if o == '-a':
            global_config.check_and_set('accept_ips', a)
            continue
        if o == '-D':
            global_config['digest_auth'] = False
            continue
        if o == '-A':
            acct_level = int(a.strip())
            if acct_level == 0:
                global_config['acct_enable'] = False
                global_config['start_acct_enable'] = False
            elif acct_level == 1:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = False
            elif acct_level == 2:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = True
            else:
                sys.__stderr__.write(
                    'ERROR: -A argument not in the range 0-2\n')
                usage(global_config, True)
            continue
        if o == '-t':
            global_config.check_and_set('static_tr_in', a)
            continue
        if o == '-T':
            global_config.check_and_set('static_tr_out', a)
            continue
        if o == '-k':
            ka_level = int(a.strip())
            if ka_level == 0:
                pass
            elif ka_level == 1:
                global_config['keepalive_ans'] = 32
            elif ka_level == 2:
                global_config['keepalive_orig'] = 32
            elif ka_level == 3:
                global_config['keepalive_ans'] = 32
                global_config['keepalive_orig'] = 32
            else:
                sys.__stderr__.write(
                    'ERROR: -k argument not in the range 0-3\n')
                usage(global_config, True)
        if o == '-m':
            global_config.check_and_set('max_credit_time', a)
            continue
        if o == '-u':
            global_config['auth_enable'] = False
            continue
        if o == '-r':
            global_config.check_and_set('rtp_proxy_client', a)
            continue
        if o == '-F':
            global_config.check_and_set('allowed_pts', a)
            continue
        if o == '-R':
            global_config.check_and_set('radiusclient.conf', a)
            continue
        if o == '-h':
            for a in a.split(','):
                global_config.check_and_set('pass_header', a)
            continue
        if o == '-c':
            global_config.check_and_set('b2bua_socket', a)
            continue
        if o == '-M':
            global_config.check_and_set('max_radiusclients', a)
            continue
        if o == '-H':
            global_config['hide_call_id'] = True
            continue
        if o in ('-C', '--config'):
            global_config.read(a.strip())
            continue
        if o.startswith('--'):
            global_config.check_and_set(o[2:], a)
            continue
        if o == '-W':
            writeconf = a.strip()
            continue

    if '_rtp_proxy_clients' in global_config:
        for a in global_config['_rtp_proxy_clients']:
            rtp_proxy_clients.append(a)

    if 'static_route' in global_config:
        global_config['_static_route'] = B2BRoute(
            global_config['static_route'])
    elif not global_config['auth_enable']:
        sys.__stderr__.write(
            'ERROR: static route should be specified when Radius auth is disabled\n'
        )
        usage(global_config, True)

    if writeconf != None:
        global_config.write(open(writeconf, 'w'))

    if not global_config['foreground']:
        daemonize(logfile=global_config['logfile'])

    global_config['_sip_logger'] = SipLogger('b2bua')

    if len(rtp_proxy_clients) > 0:
        global_config['_rtp_proxy_clients'] = []
        for address in rtp_proxy_clients:
            global_config['_rtp_proxy_clients'].append(
                Rtp_proxy_client(global_config, spath=address))

    if global_config['auth_enable'] or global_config['acct_enable']:
        global_config['_radius_client'] = RadiusAuthorisation(global_config)
    global_config['_uaname'] = 'Sippy B2BUA (RADIUS)'

    global_config['_cmap'] = CallMap(global_config)
    if 'sip_proxy' in global_config:
        host_port = global_config['sip_proxy'].split(':', 1)
        if len(host_port) == 1:
            global_config['_sip_proxy'] = (host_port[0], 5060)
        else:
            global_config['_sip_proxy'] = (host_port[0], int(host_port[1]))
        global_config['_cmap'].proxy = StatefulProxy(
            global_config, global_config['_sip_proxy'])

    if global_config.getdefault('xmpp_b2bua_id', None) != None:
        global_config['_xmpp_mode'] = True
    global_config['_sip_tm'] = SipTransactionManager(
        global_config, global_config['_cmap'].recvRequest)
    global_config['_sip_tm'].nat_traversal = global_config.getdefault(
        'nat_traversal', False)

    cmdfile = global_config['b2bua_socket']
    if cmdfile.startswith('unix:'):
        cmdfile = cmdfile[5:]
    cli_server = CLIConnectionManager(global_config['_cmap'].recvCommand,
                                      cmdfile)

    if not global_config['foreground']:
        open(global_config['pidfile'], 'w').write(str(os.getpid()) + '\n')
        Signal(SIGUSR1, reopen, SIGUSR1, global_config['logfile'])

    ED2.loop()
Exemplo n.º 26
0
 def reconnect(self, address):
     if self.cmd_out_address != None:
         bind_address = (self.cmd_out_address, 0)
     else:
         bind_address = None
     Rtp_proxy_client.reconnect(self, address, bind_address = bind_address)
Exemplo n.º 27
0

if __name__ == '__main__':
    from sippy.Time.Timeout import Timeout
    from sippy.Rtp_proxy_client import Rtp_proxy_client

    def display(*args):
        print('got:', args)
        ED2.breakLoop()

    def waitonline(rpc):
        if rpc.online:
            ED2.breakLoop()

    gc = {'_sip_address': '1.2.3.4'}
    r = Rtp_proxy_client(gc)
    t = Timeout(waitonline, 0.1, 10, r)
    ED2.loop(2.0)
    assert (r.online)
    t.cancel()

    gc['rtp_proxy_client'] = r
    rs = Rtp_proxy_session(gc, 'call_id1', 'from_tag1', 'to_tag1')
    rs.version(display)
    ED2.loop()

    rs.start_recording('bogus', result_callback=display)
    print(1)
    ED2.loop()
    print(2)
    rs.play_callee('bogus', result_callback=display)
Exemplo n.º 28
0
def main_func():
    global_config = MyConfigParser()
    global_config['digest_auth'] = True
    global_config['start_acct_enable'] = False
    global_config['keepalive_ans'] = 0
    global_config['keepalive_orig'] = 0
    global_config['auth_enable'] = True
    global_config['acct_enable'] = True
    global_config['_pass_headers'] = []
    global_config['_orig_argv'] = sys.argv[:]
    global_config['_orig_cwd'] = os.getcwd()
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'fDl:p:d:P:L:s:a:t:T:k:m:A:ur:F:R:h:c:M:HC:W:',
          global_config.get_longopts())
    except getopt.GetoptError:
        usage(global_config)
    global_config['foreground'] = False
    global_config['pidfile'] = '/var/run/b2bua.pid'
    global_config['logfile'] = '/var/log/b2bua.log'
    global_config['b2bua_socket'] = '/var/run/b2bua.sock'
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    rtp_proxy_clients = []
    writeconf = None
    for o, a in opts:
        if o == '-f':
            global_config['foreground'] = True
            continue
        if o == '-l':
            global_config.check_and_set('sip_address', a)
            continue
        if o == '-p':
            global_config.check_and_set('sip_port', a)
            continue
        if o == '-P':
            global_config.check_and_set('pidfile', a)
            continue
        if o == '-L':
            global_config.check_and_set('logfile', a)
            continue
        if o == '-s':
            global_config.check_and_set('static_route', a)
            continue
        if o == '-a':
            global_config.check_and_set('accept_ips', a)
            continue
        if o == '-D':
            global_config['digest_auth'] = False
            continue
        if o == '-A':
            acct_level = int(a.strip())
            if acct_level == 0:
                global_config['acct_enable'] = False
                global_config['start_acct_enable'] = False
            elif acct_level == 1:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = False
            elif acct_level == 2:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = True
            else:
                sys.__stderr__.write('ERROR: -A argument not in the range 0-2\n')
                usage(global_config, True)
            continue
        if o == '-t':
            global_config.check_and_set('static_tr_in', a)
            continue
        if o == '-T':
            global_config.check_and_set('static_tr_out', a)
            continue
        if o == '-k':
            ka_level = int(a.strip())
            if ka_level == 0:
                pass
            elif ka_level == 1:
                global_config['keepalive_ans'] = 32
            elif ka_level == 2:
                global_config['keepalive_orig'] = 32
            elif ka_level == 3:
                global_config['keepalive_ans'] = 32
                global_config['keepalive_orig'] = 32
            else:
                sys.__stderr__.write('ERROR: -k argument not in the range 0-3\n')
                usage(global_config, True)
        if o == '-m':
            global_config.check_and_set('max_credit_time', a)
            continue
        if o == '-u':
            global_config['auth_enable'] = False
            continue
        if o == '-r':
            global_config.check_and_set('rtp_proxy_client', a)
            continue
        if o == '-F':
            global_config.check_and_set('allowed_pts', a)
            continue
        if o == '-R':
            global_config.check_and_set('radiusclient.conf', a)
            continue
        if o == '-h':
            for a in a.split(','):
                global_config.check_and_set('pass_header', a)
            continue
        if o == '-c':
            global_config.check_and_set('b2bua_socket', a)
            continue
        if o == '-M':
            global_config.check_and_set('max_radiusclients', a)
            continue
        if o == '-H':
            global_config['hide_call_id'] = True
            continue
        if o in ('-C', '--config'):
            global_config.read(a.strip())
            continue
        if o.startswith('--'):
            global_config.check_and_set(o[2:], a)
            continue
        if o == '-W':
            writeconf = a.strip()
            continue

    if global_config.has_key('_rtp_proxy_clients'):
        for a in global_config['_rtp_proxy_clients']:
            rtp_proxy_clients.append(a)

    if global_config.has_key('static_route'):
        global_config['_static_route'] = B2BRoute(global_config['static_route'])
    elif not global_config['auth_enable']:
        sys.__stderr__.write('ERROR: static route should be specified when Radius auth is disabled\n')
        usage(global_config, True)

    if writeconf != None:
        global_config.write(open(writeconf, 'w'))

    if not global_config['foreground']:
        try:
            daemonize(logfile = global_config['logfile'])
        except IOError as e:
            print("IOError: {}".format(e))
            sys.exit(e.errno)

    global_config['_sip_logger'] = SipLogger('b2bua')

    if len(rtp_proxy_clients) > 0:
        global_config['_rtp_proxy_clients'] = []
        for address in rtp_proxy_clients:
            client = Rtp_proxy_client(global_config, spath = address)

            if 'hrtb_ival' in global_config:
                client.hrtb_ival = global_config['hrtb_ival']

            if 'hrtb_retr_ival' in global_config:
                client.hrtb_retr_ival = global_config['hrtb_retr_ival']

            global_config['_rtp_proxy_clients'].append(client)

    if global_config['auth_enable'] or global_config['acct_enable']:
        global_config['_radius_client'] = RadiusAuthorisation(global_config)
    global_config['_uaname'] = 'Sippy B2BUA (RADIUS)'

    global_config['_cmap'] = CallMap(global_config)
    if global_config.has_key('sip_proxy'):
        host_port = global_config['sip_proxy'].split(':', 1)
        if len(host_port) == 1:
            global_config['_sip_proxy'] = (host_port[0], 5060)
        else:
            global_config['_sip_proxy'] = (host_port[0], int(host_port[1]))
        global_config['_cmap'].proxy = StatefulProxy(global_config, global_config['_sip_proxy'])

    if global_config.getdefault('xmpp_b2bua_id', None) != None:
        global_config['_xmpp_mode'] = True
    global_config['_sip_tm'] = SipTransactionManager(global_config, global_config['_cmap'].recvRequest)
    global_config['_sip_tm'].nat_traversal = global_config.getdefault('nat_traversal', False)

    cmdfile = global_config['b2bua_socket']
    if cmdfile.startswith('unix:'):
        cmdfile = cmdfile[5:]
    cli_server = Cli_server_local(global_config['_cmap'].recvCommand, cmdfile)

    if not global_config['foreground']:
        file(global_config['pidfile'], 'w').write(str(os.getpid()) + '\n')
        Signal(SIGUSR1, reopen, SIGUSR1, global_config['logfile'])

    reactor.suggestThreadPoolSize(50)
    reactor.run(installSignalHandlers = True)