plugin.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* vcc/include/vcc/plugin.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_PLUGIN_H
  19. #define __VCC_PLUGIN_H
  20. #include <sys/types.h>
  21. #include <vcc/vcc.h>
  22. #include <libintl.h>
  23. /* a plugin can define their own commands in cmd.c, and must check
  24. * it inserted, and abort command execution if it doesn't. */
  25. typedef char *(* hookfn_t) (char *);
  26. extern hookfn_t msg_hook, recv_hook;
  27. struct cmdtable {
  28. char *cmd;
  29. int (* do_cmd) (int argc, char **argv);
  30. char *help;
  31. };
  32. struct plugin {
  33. #define PLG_INSERTED 1
  34. int state;
  35. /* name of the plugin */
  36. char *name;
  37. /* short description */
  38. char *descr;
  39. int (* init) (void);
  40. int (* exit) (void);
  41. hookfn_t msg_hook,
  42. recv_hook;
  43. struct cmdtable *cmdtab;
  44. };
  45. /* plugin.c */
  46. extern struct plugin *plugins[];
  47. #define _(s) gettext(s)
  48. #define plg_check_enabled() ({ \
  49. if (this_plg->state != PLG_INSERTED) { \
  50. fprintf(stderr, _("*** this plugin didn't insert. " \
  51. "please insert it by -pins and try it again. \n")); \
  52. return 1; \
  53. } \
  54. })
  55. int plg_insert(struct plugin *);
  56. struct plugin *find_plg(char *name);
  57. int register_msghook(hookfn_t, struct plugin *);
  58. int unregister_msghook(hookfn_t, struct plugin *);
  59. int register_recvhook(hookfn_t, struct plugin *);
  60. int unregister_recvhook(hookfn_t, struct plugin *);
  61. #endif