hooks.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* vcc/include/vcc/hooks.h
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __VCC_HOOKS_H
  19. #define __VCC_HOOKS_H
  20. #include <sys/types.h>
  21. #include <vcc/vcc.h>
  22. #include <vcc/hooks.h>
  23. #include <klist.h>
  24. #include <libintl.h>
  25. #define HOOK_RECV 1
  26. #define HOOK_SEND 2
  27. struct hook_info {
  28. int type;
  29. char *msg;
  30. char *usr;
  31. int sid;
  32. };
  33. typedef char *(* hookfn_t) (struct hook_info *);
  34. struct hook {
  35. int type;
  36. hookfn_t hook;
  37. struct klist_node node;
  38. };
  39. #define hook_of(n) container_of(n, struct hook, node)
  40. /* failed, abore */
  41. #define HOOK_FAILED NULL
  42. /* ignored, continue */
  43. #define HOOK_IGNORE ((char *) 1)
  44. /* has handled, so break hook calling */
  45. #define HOOK_HANDLED ((char *) 2)
  46. struct hook *register_hook(int type, hookfn_t hook);
  47. int do_hook_recv(char *s, char *usrname, int sid);
  48. int do_hook_send(char *s);
  49. #endif