>      elif (cbfnc is not None and self.__log_callback is not None):
>          # In this case, the program must first disable the
>          # current LogCallback() before setting a new one.
>          raise RuntimeError('LogCallback() is already enabled')
>
> This should enforce only one callback function being enabled this way,
> and if the callback need to be changed - it's enough to first do disable
> it (LogCallback(None)) before setting the new one.  And if more
> callbacks functions is wanted/needed, the additional ones can be called
> via the callback function registered with the LogCallback().  No need to
> make this code more complicated.

That makes sense! I *think* things get a little cleaner if we move this check
to the top of the relevant functions (StatusChangeCallback and LogCallback).
Basically, by first eliminating the possibility that we're changing an existing
registered dbus callback, then we don't actually need to be as careful later on.
For example, here's an updated version of LogCallback:

    def LogCallback(self, cbfnc):
        if cbfnc is not None and self.__log_callback is not None:
            # In this case, the program must first disable the
            # current LogCallback() before setting a new one.
            raise RuntimeError('LogCallback() is already enabled')

        if cbfnc is not None:
            self.__log_callback = cbfnc
            self.__dbuscon.add_signal_receiver(cbfnc,
                                               signal_name='Log',

dbus_interface='net.openvpn.v3.backends',
                                               bus_name='net.openvpn.v3.log',
                                               path=self.__session_path)
        else:
            # Only remove the callback if there actually *is* a callback
            # currently.
            if self.__log_callback is not None:

self.__dbuscon.remove_signal_receiver(self.__log_callback, 'Log')
                self.__log_callback = None

        self.__set_log_forward()

Does this seem safe?

I'm not familiar with path email etiquette/best practices. Let me know
if/when I should send a fully updated patch.


_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to