/*_############################################################################
  _##
  _##  SNMP4J - TransportAuditListener.java
  _##
  _##  Copyright (C) 2003-2026  Frank Fock (SNMP4J.org)
  _##
  _##  Licensed under the Apache License, Version 2.0 (the "License");
  _##  you may not use this file except in compliance with the License.
  _##  You may obtain a copy of the License at
  _##
  _##      http://www.apache.org/licenses/LICENSE-2.0
  _##
  _##  Unless required by applicable law or agreed to in writing, software
  _##  distributed under the License is distributed on an "AS IS" BASIS,
  _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  _##  See the License for the specific language governing permissions and
  _##  limitations under the License.
  _##
  _##########################################################################*/


package org.snmp4j.transport;

import java.util.EventListener;

/**
 * The {@code TransportAuditListener} interface is implemented by objects that want to control and
 * audit the communication of a {@link org.snmp4j.TransportMapping}. Implementations are registered
 * with a transport mapping through {@link AbstractTransportMapping#addTransportAuditListener} and
 * are notified before a transport binds a listen address, before outgoing data is sent, when
 * incoming data is received, and when a listen address or connection is closed.
 * <p>
 * The single {@link #transportAudit(TransportAuditEvent)} method acts both as an authorization hook
 * and as an audit hook: returning {@code false} denies the corresponding communication (binding,
 * sending, or receiving), while returning {@code true} allows it. Implementations may additionally
 * write the audited {@link TransportAuditEvent} to a dedicated audit log. For
 * {@link TransportAuditEvent.TransportOperation#CLOSE} events the return value is ignored, because a
 * close cannot be denied.
 *
 * @author Frank Fock
 * @version 3.12.0
 * @since 3.12.0
 */
public interface TransportAuditListener extends EventListener {

    /**
     * Audits a transport operation described by the provided {@link TransportAuditEvent} and decides
     * whether the operation is permitted.
     *
     * @param event
     *    the {@link TransportAuditEvent} describing the transport operation to be audited.
     * @return
     *    {@code true} if the operation is permitted, {@code false} to deny (cancel) it. The return
     *    value is ignored for {@link TransportAuditEvent.TransportOperation#CLOSE} events.
     */
    boolean transportAudit(TransportAuditEvent event);
}
