Esempio n. 1
0
 def run(self):
     local_host = '127.0.0.1'
     local_host6 = '[::1]'
     remote_host = local_host
     remote_host6 = local_host6
     self.ping_laddr = (local_host, 12345)
     self.pong_laddr = (local_host, 54321)
     self.ping_laddr6 = (local_host6, 12345)
     self.pong_laddr6 = (local_host6, 54321)
     self.ping_raddr = (remote_host, 12345)
     self.pong_raddr = (remote_host, 54321)
     self.ping_raddr6 = (remote_host6, 12345)
     self.pong_raddr6 = (remote_host6, 54321)
     uopts_ping = Udp_server_opts(self.ping_laddr, self.ping_received)
     uopts_ping6 = Udp_server_opts(self.ping_laddr6, self.ping_received)
     uopts_pong = Udp_server_opts(self.pong_laddr, self.pong_received)
     uopts_pong6 = Udp_server_opts(self.pong_laddr6, self.pong_received)
     udp_server_ping = Udp_server({}, uopts_ping)
     udp_server_pong = Udp_server({}, uopts_pong)
     udp_server_pong.send_to(self.ping_data, self.ping_laddr)
     udp_server_ping6 = Udp_server({}, uopts_ping6)
     udp_server_pong6 = Udp_server({}, uopts_pong6)
     udp_server_pong6.send_to(self.ping_data6, self.ping_laddr6)
     ED2.loop()
     udp_server_ping.shutdown()
     udp_server_pong.shutdown()
     udp_server_ping6.shutdown()
     udp_server_pong6.shutdown()
Esempio n. 2
0
def testTimeoutAbsMono():
    def test1(arguments, testnum, mtm):
        arguments['delay'] = mtm.offsetFromNow()
        print(testnum, arguments['delay'])
        arguments['test'] = True
        ED2.breakLoop()

    def test2(arguments, testnum, mtm):
        arguments['delay'] = mtm.offsetFromNow()
        print(testnum, arguments['delay'])
        arguments['test'] = 'bar'
        ED2.breakLoop()

    mt = MonoTime()
    arguments = {'test': False, 'delay': None}
    timeout_1 = TimeoutAbsMono(test1, mt, arguments, 'test1', mt)
    ED2.loop()
    assert (arguments['test'])
    assert (arguments['delay'] < 0.1)
    mt1 = mt.getOffsetCopy(0.1)
    mt2 = mt.getOffsetCopy(0.2)
    arguments = {'test': False, 'delay': None}
    timeout_1 = TimeoutAbsMono(test1, mt1, arguments, 'test2', mt1)
    timeout_2 = TimeoutAbsMono(test2, mt2, arguments, 'test3', mt2)
    timeout_1.cancel()
    ED2.loop()
    assert (arguments['test'] == 'bar')
    assert (arguments['delay'] < 0.1)
Esempio n. 3
0
def testTimeoutAbsMono():
    def test1(arguments, testnum, mtm):
        arguments['delay'] = mtm.offsetFromNow()
        print(testnum, arguments['delay'])
        arguments['test'] = True
        ED2.breakLoop()

    def test2(arguments, testnum, mtm):
        arguments['delay'] = mtm.offsetFromNow()
        print(testnum, arguments['delay'])
        arguments['test'] = 'bar'
        ED2.breakLoop()

    mt = MonoTime()
    arguments = {'test':False, 'delay':None}
    timeout_1 = TimeoutAbsMono(test1, mt, arguments, 'test1', mt)
    ED2.loop()
    assert(arguments['test'])
    assert(arguments['delay'] < 0.1)
    mt1 = mt.getOffsetCopy(0.1)
    mt2 = mt.getOffsetCopy(0.2)
    arguments = {'test':False, 'delay':None}
    timeout_1 = TimeoutAbsMono(test1, mt1, arguments, 'test2', mt1)
    timeout_2 = TimeoutAbsMono(test2, mt2, arguments, 'test3', mt2)
    timeout_1.cancel()
    ED2.loop()
    assert(arguments['test'] == 'bar')
    assert(arguments['delay'] < 0.1)
Esempio n. 4
0
 def run(self):
     local_host = '127.0.0.1'
     local_host6 = '[::1]'
     remote_host = local_host
     remote_host6 = local_host6
     self.ping_laddr = (local_host, 12345)
     self.pong_laddr = (local_host, 54321)
     self.ping_laddr6 = (local_host6, 12345)
     self.pong_laddr6 = (local_host6, 54321)
     self.ping_raddr = (remote_host, 12345)
     self.pong_raddr = (remote_host, 54321)
     self.ping_raddr6 = (remote_host6, 12345)
     self.pong_raddr6 = (remote_host6, 54321)
     uopts_ping = Udp_server_opts(self.ping_laddr, self.ping_received)
     uopts_ping6 = Udp_server_opts(self.ping_laddr6, self.ping_received)
     uopts_pong = Udp_server_opts(self.pong_laddr, self.pong_received)
     uopts_pong6 = Udp_server_opts(self.pong_laddr6, self.pong_received)
     udp_server_ping = Udp_server({}, uopts_ping)
     udp_server_pong = Udp_server({}, uopts_pong)
     udp_server_pong.send_to(self.ping_data, self.ping_laddr)
     udp_server_ping6 = Udp_server({}, uopts_ping6)
     udp_server_pong6 = Udp_server({}, uopts_pong6)
     udp_server_pong6.send_to(self.ping_data6, self.ping_laddr6)
     ED2.loop()
     udp_server_ping.shutdown()
     udp_server_pong.shutdown()
     udp_server_ping6.shutdown()
     udp_server_pong6.shutdown()
Esempio n. 5
0
def main_func():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'fl:p:n:L:')
    except getopt.GetoptError:
        print(
            'usage: b2bua.py [-l addr] [-p port] [-n addr] [-f] [-L logfile]')
        sys.exit(1)
    laddr = None
    lport = None
    logfile = '/var/log/sippy.log'
    global_config = {'nh_addr': ['192.168.0.102', 5060]}
    foreground = False
    for o, a in opts:
        if o == '-f':
            foreground = True
            continue
        if o == '-l':
            laddr = a
            continue
        if o == '-p':
            lport = int(a)
            continue
        if o == '-L':
            logfile = a
        if o == '-n':
            if a.startswith('['):
                parts = a.split(']', 1)
                global_config['nh_addr'] = [parts[0] + ']', 5060]
                parts = parts[1].split(':', 1)
            else:
                parts = a.split(':', 1)
                global_config['nh_addr'] = [parts[0], 5060]
            if len(parts) == 2:
                global_config['nh_addr'][1] = int(parts[1])
            continue
    global_config['nh_addr'] = tuple(global_config['nh_addr'])

    if not foreground:
        daemonize(logfile)

    SipConf.my_uaname = 'Sippy B2BUA (Simple)'
    SipConf.allow_formats = (0, 8, 18, 100, 101)
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    if laddr != None:
        global_config['_sip_address'] = laddr
    if lport != None:
        global_config['_sip_port'] = lport
    global_config['_sip_logger'] = SipLogger('b2bua')

    cmap = CallMap(global_config)

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

    ED2.loop()
Esempio n. 6
0
def testTimeout():
    def test1(arguments, testnum):
        print(testnum)
        arguments['test'] = True
        ED2.breakLoop()

    def test2(arguments, testnum):
        print(testnum)
        arguments['test'] = 'bar'
        ED2.breakLoop()

    arguments = {'test': False}
    timeout_1 = Timeout(test1, 0, 1, arguments, 'test1')
    ED2.loop()
    assert (arguments['test'])
    timeout_1 = Timeout(test1, 0.1, 1, arguments, 'test2')
    timeout_2 = Timeout(test2, 0.2, 1, arguments, 'test3')
    timeout_1.cancel()
    ED2.loop()
    assert (arguments['test'] == 'bar')

    arguments = {'test': False}
    timeout_1 = TimeoutAbsMono(test1, MonoTime(), arguments, 'test4')
    ED2.loop()
    assert (arguments['test'])

    timeout_1 = TimeoutAbsMono(test1,
                               MonoTime().getOffsetCopy(0.1), arguments,
                               'test5')
    timeout_2 = TimeoutAbsMono(test2,
                               MonoTime().getOffsetCopy(0.2), arguments,
                               'test6')
    timeout_1.cancel()
    ED2.loop()
    assert (arguments['test'] == 'bar')
Esempio n. 7
0
def testTimeout():
    def test1(arguments, testnum):
        print(testnum)
        arguments['test'] = True
        ED2.breakLoop()

    def test2(arguments, testnum):
        print(testnum)
        arguments['test'] = 'bar'
        ED2.breakLoop()

    arguments = {'test':False}
    timeout_1 = Timeout(test1, 0, 1, arguments, 'test1')
    ED2.loop()
    assert(arguments['test'])
    timeout_1 = Timeout(test1, 0.1, 1, arguments, 'test2')
    timeout_2 = Timeout(test2, 0.2, 1, arguments, 'test3')
    timeout_1.cancel()
    ED2.loop()
    assert(arguments['test'] == 'bar')

    arguments = {'test':False}
    timeout_1 = TimeoutAbsMono(test1, MonoTime(), arguments, 'test4')
    ED2.loop()
    assert(arguments['test'])

    timeout_1 = TimeoutAbsMono(test1, MonoTime().getOffsetCopy(0.1), arguments, 'test5')
    timeout_2 = TimeoutAbsMono(test2, MonoTime().getOffsetCopy(0.2), arguments, 'test6')
    timeout_1.cancel()
    ED2.loop()
    assert(arguments['test'] == 'bar')
Esempio n. 8
0
 def run(self):
     import os
     global_config = {}
     global_config['my_pid'] = os.getpid()
     rtpc = Rtp_proxy_client_udp(global_config, ('127.0.0.1', 22226), None)
     rtpc.rtpp_class = Rtp_proxy_client_udp
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('Ib', self.gotreply)
     ED2.loop()
     rtpc.reconnect(('localhost', 22226), ('0.0.0.0', 34222))
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('V', self.gotreply)
     ED2.loop()
     rtpc.reconnect(('localhost', 22226), ('127.0.0.1', 57535))
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('V', self.gotreply)
     ED2.loop()
     rtpc.shutdown()
Esempio n. 9
0
 def run(self):
     import os
     global_config = {}
     global_config['my_pid'] = os.getpid()
     rtpc = Rtp_proxy_client_udp(global_config, ('127.0.0.1', 22226), None)
     rtpc.rtpp_class = Rtp_proxy_client_udp
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('Ib', self.gotreply)
     ED2.loop()
     rtpc.reconnect(('localhost', 22226), ('0.0.0.0', 34222))
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('V', self.gotreply)
     ED2.loop()
     rtpc.reconnect(('localhost', 22226), ('127.0.0.1', 57535))
     os.system('sockstat | grep -w %d' % global_config['my_pid'])
     rtpc.send_command('V', self.gotreply)
     ED2.loop()
     rtpc.shutdown()
Esempio n. 10
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)
    ED2.loop()
    print(3)
Esempio n. 11
0

class Rtp_proxy_client_local(Rtp_proxy_client_stream):
    is_local = True

    def __init__(self, global_config, address = '/var/run/rtpproxy.sock', \
      bind_address = None, nworkers = 1):
        Rtp_proxy_client_stream.__init__(self, global_config = global_config, \
          address = address, bind_address = bind_address, nworkers = nworkers, \
          family = socket.AF_UNIX)


if __name__ == '__main__':
    from sippy.Core.EventDispatcher import ED2

    class robj(object):
        rval = None

    r = robj()

    def display(res, ro, arg):
        print(res, arg)
        ro.rval = (res, arg)
        ED2.breakLoop()

    rc = Rtp_proxy_client_local({'_sip_address': '1.2.3.4'})
    rc.send_command('VF 123456', display, r, 'abcd')
    ED2.loop()
    rc.shutdown()
    assert (r.rval == ('0', 'abcd'))
Esempio n. 12
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)
Esempio n. 13
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()
Esempio n. 14
0
        self.work_available.notify()
        self.work_available.release()

    def process_result(self, result_callback, result, *callback_parameters):
        try:
            result_callback(result, *callback_parameters)
        except Exception as ex:
            if isinstance(ex, SystemExit):
                raise
            dump_exception('External_command: unhandled exception in external command results callback')

if __name__ == '__main__':
    from sys import exit
    from time import sleep

    test_data = (b'foo', b'bar')

    def results_received(results):
        global external_command
        external_command.shutdown()
        # Give threads time to finish
        sleep(0.05)
        if not results == test_data:
            print(test_data, results)
            exit(1)
        ED2.breakLoop()

    external_command = External_command('/bin/cat')
    external_command.process_command(test_data, results_received)
    ED2.loop()
Esempio n. 15
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()
Esempio n. 16
0
            continue
        if o == '-o':
            fname = a.strip()
            if fname == '-':
                file_out = sys.stdout
            else:
                file_out = open(fname, 'w')
        if o == '-t':
            timeout = float(a.strip())
            continue

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

    from sippy.CLIManager import CLIConnectionManager
    from sippy.Time.Timeout import Timeout
    from sippy.Core.EventDispatcher import ED2

    ch = cli_handler(file_out)
    if stype == 'unix':
        rep = lambda x, y: ch.command_received(spath, x, y)
        cs = CLIConnectionManager(rep, spath, tcp=False)
    else:
        rep = lambda x, y: ch.command_received(spath[0], x, y)
        cs = CLIConnectionManager(rep, tuple(spath), tcp=True)
    if timeout != None:
        Timeout(ch.done, timeout)
    ED2.regSignal(SIGTERM, ch.sigin)
    ED2.loop(freq=1000.0)
    sys.exit(ch.rval)
Esempio n. 17
0
        self.ptransmitted = ptransmitted

    def shutdown(self):
        if self.shut_down: # do not crash when shutdown() called twice
            return
        self.shut_down = True
        self.rtpp_class.shutdown(self)
        self.rtpp_class = None

    def get_rtpc_delay(self):
        return self.rtpp_class.get_rtpc_delay(self)

if __name__ == '__main__':
    from sippy.Core.EventDispatcher import ED2
    from sippy.Time.Timeout import Timeout
    def display(*args):
        print(args)
        ED2.breakLoop()
    def waitonline(rpc):
        if rpc.online:
            ED2.breakLoop()
    r = Rtp_proxy_client({'_sip_address':'1.2.3.4'})
    t = Timeout(waitonline, 0.1, 10, r)
    ED2.loop(2.0)
    assert(r.online)
    t.cancel()
    r.send_command('VF 123456', display, 'abcd')
    ED2.loop()
    r.shutdown()
    print('passed')