Blame src/gl/fd-hook.h

Packit aea12f
/* Hook for making file descriptor functions close(), ioctl() extensible.
Packit Service 991b93
   Copyright (C) 2009-2020 Free Software Foundation, Inc.
Packit aea12f
Packit aea12f
   This program is free software: you can redistribute it and/or modify it
Packit aea12f
   under the terms of the GNU General Public License as published
Packit aea12f
   by the Free Software Foundation; either version 3 of the License, or
Packit aea12f
   (at your option) any later version.
Packit aea12f
Packit aea12f
   This program is distributed in the hope that it will be useful,
Packit aea12f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
   General Public License for more details.
Packit aea12f
Packit aea12f
   You should have received a copy of the GNU General Public License
Packit aea12f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
Packit aea12f
Packit aea12f
Packit aea12f
#ifndef FD_HOOK_H
Packit aea12f
#define FD_HOOK_H
Packit aea12f
Packit aea12f
#ifdef __cplusplus
Packit aea12f
extern "C" {
Packit aea12f
#endif
Packit aea12f
Packit aea12f
Packit aea12f
/* Currently, this entire code is only needed for the handling of sockets
Packit aea12f
   on native Windows platforms.  */
Packit aea12f
#if WINDOWS_SOCKETS
Packit aea12f
Packit aea12f
Packit aea12f
/* Type of function that closes FD.  */
Packit aea12f
typedef int (*gl_close_fn) (int fd);
Packit aea12f
Packit aea12f
/* Type of function that applies a control request to FD.  */
Packit aea12f
typedef int (*gl_ioctl_fn) (int fd, int request, void *arg);
Packit aea12f
Packit aea12f
/* An element of the list of file descriptor hooks.
Packit aea12f
   In CLOS (Common Lisp Object System) speak, it consists of an "around"
Packit aea12f
   method for the close() function and an "around" method for the ioctl()
Packit aea12f
   function.
Packit aea12f
   The fields of this structure are considered private.  */
Packit aea12f
struct fd_hook
Packit aea12f
{
Packit aea12f
  /* Doubly linked list.  */
Packit aea12f
  struct fd_hook *private_next;
Packit aea12f
  struct fd_hook *private_prev;
Packit aea12f
  /* Function that treats the types of FD that it knows about and calls
Packit aea12f
     execute_close_hooks (REMAINING_LIST, PRIMARY, FD) as a fallback.  */
Packit aea12f
  int (*private_close_fn) (const struct fd_hook *remaining_list,
Packit aea12f
                           gl_close_fn primary,
Packit aea12f
                           int fd);
Packit aea12f
  /* Function that treats the types of FD that it knows about and calls
Packit aea12f
     execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG) as a
Packit aea12f
     fallback.  */
Packit aea12f
  int (*private_ioctl_fn) (const struct fd_hook *remaining_list,
Packit aea12f
                           gl_ioctl_fn primary,
Packit aea12f
                           int fd, int request, void *arg);
Packit aea12f
};
Packit aea12f
Packit aea12f
/* This type of function closes FD, applying special knowledge for the FD
Packit aea12f
   types it knows about, and calls
Packit aea12f
   execute_close_hooks (REMAINING_LIST, PRIMARY, FD)
Packit aea12f
   for the other FD types.
Packit aea12f
   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
Packit aea12f
   and PRIMARY is the "primary" method for close().  */
Packit aea12f
typedef int (*close_hook_fn) (const struct fd_hook *remaining_list,
Packit aea12f
                              gl_close_fn primary,
Packit aea12f
                              int fd);
Packit aea12f
Packit aea12f
/* Execute the close hooks in REMAINING_LIST, with PRIMARY as "primary" method.
Packit aea12f
   Return 0 or -1, like close() would do.  */
Packit aea12f
extern int execute_close_hooks (const struct fd_hook *remaining_list,
Packit aea12f
                                gl_close_fn primary,
Packit aea12f
                                int fd);
Packit aea12f
Packit aea12f
/* Execute all close hooks, with PRIMARY as "primary" method.
Packit aea12f
   Return 0 or -1, like close() would do.  */
Packit aea12f
extern int execute_all_close_hooks (gl_close_fn primary, int fd);
Packit aea12f
Packit aea12f
/* This type of function applies a control request to FD, applying special
Packit aea12f
   knowledge for the FD types it knows about, and calls
Packit aea12f
   execute_ioctl_hooks (REMAINING_LIST, PRIMARY, FD, REQUEST, ARG)
Packit aea12f
   for the other FD types.
Packit aea12f
   In CLOS speak, REMAINING_LIST is the remaining list of "around" methods,
Packit aea12f
   and PRIMARY is the "primary" method for ioctl().  */
Packit aea12f
typedef int (*ioctl_hook_fn) (const struct fd_hook *remaining_list,
Packit aea12f
                              gl_ioctl_fn primary,
Packit aea12f
                              int fd, int request, void *arg);
Packit aea12f
Packit aea12f
/* Execute the ioctl hooks in REMAINING_LIST, with PRIMARY as "primary" method.
Packit aea12f
   Return 0 or -1, like ioctl() would do.  */
Packit aea12f
extern int execute_ioctl_hooks (const struct fd_hook *remaining_list,
Packit aea12f
                                gl_ioctl_fn primary,
Packit aea12f
                                int fd, int request, void *arg);
Packit aea12f
Packit aea12f
/* Execute all ioctl hooks, with PRIMARY as "primary" method.
Packit aea12f
   Return 0 or -1, like ioctl() would do.  */
Packit aea12f
extern int execute_all_ioctl_hooks (gl_ioctl_fn primary,
Packit aea12f
                                    int fd, int request, void *arg);
Packit aea12f
Packit aea12f
/* Add a function pair to the list of file descriptor hooks.
Packit aea12f
   CLOSE_HOOK and IOCTL_HOOK may be NULL, indicating no change.
Packit aea12f
   The LINK variable points to a piece of memory which is guaranteed to be
Packit aea12f
   accessible until the corresponding call to unregister_fd_hook.  */
Packit aea12f
extern void register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook,
Packit aea12f
                              struct fd_hook *link);
Packit aea12f
Packit aea12f
/* Removes a hook from the list of file descriptor hooks.  */
Packit aea12f
extern void unregister_fd_hook (struct fd_hook *link);
Packit aea12f
Packit aea12f
Packit aea12f
#endif
Packit aea12f
Packit aea12f
Packit aea12f
#ifdef __cplusplus
Packit aea12f
}
Packit aea12f
#endif
Packit aea12f
Packit aea12f
#endif /* FD_HOOK_H */