/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2009-04-16 22:51:36 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090416225136-wz8p0nsuteiasxn2
Code cleanup.

* mandos (ForkingMixInWithPipe.process_request): Call "self.add_pipe".
  (ForkingMixInWithPipe.handle_ipc): Removed.
  (ForkingMixInWithPipe.add_pipe): New.
  (MandosServer.add_pipe): New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
893
893
 
894
894
 
895
895
class ForkingMixInWithPipe(socketserver.ForkingMixIn, object):
896
 
    """Like socketserver.ForkingMixIn, but also pass a pipe.
897
 
    
898
 
    Assumes a gobject.MainLoop event loop.
899
 
    """
 
896
    """Like socketserver.ForkingMixIn, but also pass a pipe."""
900
897
    def process_request(self, request, client_address):
901
898
        """Overrides and wraps the original process_request().
902
899
        
906
903
        super(ForkingMixInWithPipe,
907
904
              self).process_request(request, client_address)
908
905
        os.close(self.pipe[1])  # close write end
909
 
        # Call "handle_ipc" for both data and EOF events
910
 
        gobject.io_add_watch(self.pipe[0],
911
 
                             gobject.IO_IN | gobject.IO_HUP,
912
 
                             self.handle_ipc)
913
 
    def handle_ipc(self, source, condition):
 
906
        self.add_pipe(self.pipe[0])
 
907
    def add_pipe(self, pipe):
914
908
        """Dummy function; override as necessary"""
915
 
        os.close(source)
916
 
        return False
 
909
        os.close(pipe)
917
910
 
918
911
 
919
912
class IPv6_TCPServer(ForkingMixInWithPipe,
924
917
        enabled:        Boolean; whether this server is activated yet
925
918
        interface:      None or a network interface name (string)
926
919
        use_ipv6:       Boolean; to use IPv6 or not
927
 
        ----
928
 
        clients:        set of Client objects
929
 
        gnutls_priority GnuTLS priority string
930
 
        use_dbus:       Boolean; to emit D-Bus signals or not
931
920
    """
932
921
    def __init__(self, server_address, RequestHandlerClass,
933
922
                 interface=None, use_ipv6=True):
990
979
        clients:        set of Client objects
991
980
        gnutls_priority GnuTLS priority string
992
981
        use_dbus:       Boolean; to emit D-Bus signals or not
 
982
        clients:        set of Client objects
 
983
        gnutls_priority GnuTLS priority string
 
984
        use_dbus:       Boolean; to emit D-Bus signals or not
 
985
    
 
986
    Assumes a gobject.MainLoop event loop.
993
987
    """
994
988
    def __init__(self, server_address, RequestHandlerClass,
995
989
                 interface=None, use_ipv6=True, clients=None,
1007
1001
            return socketserver.TCPServer.server_activate(self)
1008
1002
    def enable(self):
1009
1003
        self.enabled = True
 
1004
    def add_pipe(self, pipe):
 
1005
        # Call "handle_ipc" for both data and EOF events
 
1006
        gobject.io_add_watch(pipe, gobject.IO_IN | gobject.IO_HUP,
 
1007
                             self.handle_ipc)
1010
1008
    def handle_ipc(self, source, condition, file_objects={}):
1011
1009
        condition_names = {
1012
1010
            gobject.IO_IN: u"IN",   # There is data to read.