Blame lib/fd-hook.h

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