Esempio n. 1
0
class DNRelay(object):
    clim = None
    workers = None
    dest_sprefix = None
    in_address = None
    sip_logger = None

    def __init__(self, dnconfig, sip_logger):
        self.workers = {}
        self.clim = Cli_server_tcp(self.recv_dnotify, dnconfig.in_address)
        self.clim.accept_list = []
        self.dest_sprefix = dnconfig.dest_sprefix
        self.in_address = dnconfig.in_address
        self.sip_logger = sip_logger

    def recv_dnotify(self, clim, dnstring):
        #print 'DNRelay.recv_dnotify(%s)' % dnstring
        if clim.raddr != None:
            self.sip_logger.write('Disconnect notification from %s received on %s: "%s"' \
              % (str(clim.raddr), str(self.in_address), dnstring))
        else:
            self.sip_logger.write('Disconnect notification received on %s: "%s"' \
              % (str(self.in_address), dnstring))
        ssufx, dnstring = dnstring.split(None, 1)
        spath = self.dest_sprefix + ssufx
        dnw = self.workers.get(spath, None)
        if dnw == None:
            dnw = _DNRLWorker(spath, self.sip_logger)
            self.workers[spath] = dnw
        self.sip_logger.write(' forwarding notification to "%s": "%s"' % (spath, dnstring))
        dnw.send_dnotify(dnstring)

    def shutdown(self):
        for dnw in self.workers.itervalues():
            dnw.send_dnotify(None)
            dnw.join()
        self.clim.shutdown()
        self.sip_logger = None

    def cmpconfig(self, dnconfig):
        if dnconfig.dest_sprefix != self.dest_sprefix:
            return False
        if dnconfig.in_address != self.in_address:
            return False
        return True

    def allow_from(self, address):
        self.clim.accept_list.append(address[0])

    def disallow_from(self, address):
        self.clim.accept_list.remove(address[0])

    def get_allow_list(self):
        return tuple(self.clim.accept_list)

    def set_allow_list(self, accept_list):
        self.clim.accept_list = list(accept_list)
Esempio n. 2
0
 def __init__(self, dnconfig, sip_logger):
     self.workers = {}
     self.clim = Cli_server_tcp(self.recv_dnotify, dnconfig.in_address)
     self.clim.accept_list = []
     self.dest_sprefix = dnconfig.dest_sprefix
     self.in_address = dnconfig.in_address
     self.sip_logger = sip_logger
Esempio n. 3
0
class DNRelay(object):
    clim = None
    workers = None
    dest_sprefix = None
    in_address = None

    def __init__(self, dnconfig):
        self.workers = {}
        self.clim = Cli_server_tcp(self.recv_dnotify, dnconfig.in_address)
        self.clim.accept_list = []
        self.dest_sprefix = dnconfig.dest_sprefix
        self.in_address = dnconfig.in_address

    def recv_dnotify(self, clim, dnstring):
        #print 'DNRelay.recv_dnotify(%s)' % dnstring
        ssufx, dnstring = dnstring.split(None, 1)
        spath = self.dest_sprefix + ssufx
        dnw = self.workers.get(spath, None)
        if dnw == None:
            dnw = _DNRLWorker(spath)
            self.workers[spath] = dnw
        dnw.send_dnotify(dnstring)

    def shutdown(self):
        for dnw in self.workers.itervalues():
            dnw.send_dnotify(None)
            dnw.join()
        self.clim.shutdown()

    def cmpconfig(self, dnconfig):
        if dnconfig.dest_sprefix != self.dest_sprefix:
            return False
        if dnconfig.in_address != self.in_address:
            return False
        return True

    def allow_from(self, address):
        self.clim.accept_list.append(address[0])

    def disallow_from(self, address):
        self.clim.accept_list.remove(address[0])

    def get_allow_list(self):
        return tuple(self.clim.accept_list)

    def set_allow_list(self, accept_list):
        self.clim.accept_list = list(accept_list)
Esempio n. 4
0
class DNRelay(object):
    clim = None
    workers = None
    dest_sprefix = None
    in_address = None

    def __init__(self, dnconfig):
        self.workers = {}
        self.clim = Cli_server_tcp(self.recv_dnotify, dnconfig.in_address)
        self.clim.accept_list = []
        self.dest_sprefix = dnconfig.dest_sprefix
        self.in_address = dnconfig.in_address

    def recv_dnotify(self, clim, dnstring):
        #print 'DNRelay.recv_dnotify(%s)' % dnstring
        ssufx, dnstring = dnstring.split(None, 1)
        spath = self.dest_sprefix + ssufx
        dnw = self.workers.get(spath, None)
        if dnw == None:
            dnw = _DNRLWorker(spath)
            self.workers[spath] = dnw
        dnw.send_dnotify(dnstring)

    def shutdown(self):
        for dnw in self.workers.itervalues():
            dnw.send_dnotify(None)
            dnw.join()
        self.clim.shutdown()

    def cmpconfig(self, dnconfig):
        if dnconfig.dest_sprefix != self.dest_sprefix:
            return False
        if dnconfig.in_address != self.in_address:
            return False
        return True

    def allow_from(self, address):
        self.clim.accept_list.append(address[0])

    def disallow_from(self, address):
        self.clim.accept_list.remove(address[0])

    def get_allow_list(self):
        return tuple(self.clim.accept_list)

    def set_allow_list(self, accept_list):
        self.clim.accept_list = list(accept_list)
Esempio n. 5
0
 def __init__(self, dnconfig):
     self.workers = {}
     self.clim = Cli_server_tcp(self.recv_dnotify, dnconfig.in_address)
     self.clim.accept_list = []
     self.dest_sprefix = dnconfig.dest_sprefix
     self.in_address = dnconfig.in_address
Esempio n. 6
0
            continue
        if o == '-S':
            sippy_path = a.strip()
            continue
        if o == '-o':
            fname = a.strip()
            if fname == '-':
                file_out = sys.stdout
            else:
                file_out = file(fname, 'w')
        if o == '-t':
            timeout = float(a.strip())
            continue

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

    from sippy.Cli_server_local import Cli_server_local
    from sippy.Cli_server_tcp import Cli_server_tcp
    from sippy.Timeout import Timeout

    ch = cli_handler(file_out)
    if stype == 'unix':
        cs = Cli_server_local(ch.command_received, spath)
    else:
        cs = Cli_server_tcp(ch.command_received, spath)
    if timeout != None:
        Timeout(ch.done, timeout)
    reactor.run(installSignalHandlers=1)
    sys.exit(ch.rval)