1
0

plugin.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * plugin.h
  3. */
  4. #ifndef _clish_plugin_h
  5. #define _clish_plugin_h
  6. #ifdef HAVE_CONFIG_H
  7. #include "config.h"
  8. #endif /* HAVE_CONFIG_H */
  9. #include "lub/types.h"
  10. /* Symbol */
  11. /* Symbol types. Functions with different purposes. */
  12. typedef enum {
  13. CLISH_SYM_TYPE_NONE = 0, /* None */
  14. CLISH_SYM_TYPE_ACTION, /* Common builtin symbol for ACTION tag */
  15. CLISH_SYM_TYPE_ACCESS, /* Callback for "access" field */
  16. CLISH_SYM_TYPE_CONFIG, /* Callback for CONFIG tag */
  17. CLISH_SYM_TYPE_LOG, /* Callback for logging */
  18. CLISH_SYM_TYPE_MAX /* Number of elements */
  19. } clish_sym_type_e;
  20. /* External functions APIs. */
  21. typedef enum {
  22. CLISH_SYM_API_SIMPLE = 0, /* Simple (may be single) API */
  23. CLISH_SYM_API_STDOUT /* Symbol for ACTION tag without "out" argument */
  24. } clish_sym_api_e;
  25. typedef struct clish_sym_s clish_sym_t;
  26. typedef struct clish_plugin_s clish_plugin_t;
  27. /* Plugin types */
  28. /* Name of init function within plugin */
  29. #define CLISH_PLUGIN_INIT_FNAME(name) clish_plugin_##name##_init
  30. #define CLISH_PLUGIN_INIT_NAME_PREFIX "clish_plugin_"
  31. #define CLISH_PLUGIN_INIT_NAME_SUFFIX "_init"
  32. #define CLISH_PLUGIN_INIT_FUNC(name) int name(void *clish_shell, clish_plugin_t *plugin)
  33. #define CLISH_PLUGIN_INIT(name) CLISH_PLUGIN_INIT_FUNC(CLISH_PLUGIN_INIT_FNAME(name))
  34. #define CLISH_PLUGIN_FINI(name) int name(void *clish_shell, clish_plugin_t *plugin)
  35. #define CLISH_PLUGIN_SYM(name) int name(void *clish_context, const char *script, char **out)
  36. #define CLISH_PLUGIN_OSYM(name) int name(void *clish_context, const char *script)
  37. #define CLISH_HOOK_ACCESS(name) int name(void *clish_shell, const char *access)
  38. #define CLISH_HOOK_CONFIG(name) int name(void *clish_context)
  39. #define CLISH_HOOK_LOG(name) int name(void *clish_context, const char *line, int retcode)
  40. typedef CLISH_PLUGIN_INIT_FUNC(clish_plugin_init_t);
  41. typedef CLISH_PLUGIN_FINI(clish_plugin_fini_t);
  42. typedef CLISH_PLUGIN_SYM(clish_hook_action_fn_t);
  43. typedef CLISH_PLUGIN_OSYM(clish_hook_oaction_fn_t);
  44. typedef CLISH_HOOK_ACCESS(clish_hook_access_fn_t);
  45. typedef CLISH_HOOK_CONFIG(clish_hook_config_fn_t);
  46. typedef CLISH_HOOK_LOG(clish_hook_log_fn_t);
  47. /* Helpers */
  48. #define SYM_FN(TYPE,SYM) (*((clish_hook_##TYPE##_fn_t *)(clish_sym__get_func(SYM))))
  49. /* Create an array of builtin plugin's init functions */
  50. struct clish_plugin_builtin_list_s {
  51. const char *name; /* Plugin name */
  52. clish_plugin_init_t *init; /* Plugin init function */
  53. };
  54. typedef struct clish_plugin_builtin_list_s clish_plugin_builtin_list_t;
  55. extern clish_plugin_builtin_list_t clish_plugin_builtin_list[];
  56. /* Symbol */
  57. int clish_sym_compare(const void *first, const void *second);
  58. clish_sym_t *clish_sym_new(const char *name, void *func, int type);
  59. void clish_sym_free(clish_sym_t *instance);
  60. void clish_sym__set_func(clish_sym_t *instance, void *func);
  61. void *clish_sym__get_func(clish_sym_t *instance);
  62. void clish_sym__set_name(clish_sym_t *instance, const char *name);
  63. char *clish_sym__get_name(clish_sym_t *instance);
  64. void clish_sym__set_permanent(clish_sym_t *instance, bool_t permanent);
  65. bool_t clish_sym__get_permanent(clish_sym_t *instance);
  66. void clish_sym__set_plugin(clish_sym_t *instance, clish_plugin_t *plugin);
  67. clish_plugin_t *clish_sym__get_plugin(clish_sym_t *instance);
  68. void clish_sym__set_type(clish_sym_t *instance, int type);
  69. int clish_sym__get_type(const clish_sym_t *instance);
  70. void clish_sym__set_api(clish_sym_t *instance, clish_sym_api_e api);
  71. clish_sym_api_e clish_sym__get_api(const clish_sym_t *instance);
  72. int clish_sym_clone(clish_sym_t *dst, clish_sym_t *src);
  73. /* Plugin */
  74. clish_plugin_t *clish_plugin_new(const char *name);
  75. void clish_plugin_free(clish_plugin_t *instance, void *userdata);
  76. int clish_plugin_load(clish_plugin_t *instance, void *userdata);
  77. clish_sym_t *clish_plugin_get_sym(clish_plugin_t *instance,
  78. const char *name, int type);
  79. clish_sym_t *clish_plugin_add_generic(clish_plugin_t *instance,
  80. void *func, const char *name, int type, bool_t permanent);
  81. clish_sym_t *clish_plugin_add_sym(clish_plugin_t *instance,
  82. clish_hook_action_fn_t *func, const char *name);
  83. clish_sym_t *clish_plugin_add_psym(clish_plugin_t *instance,
  84. clish_hook_action_fn_t *func, const char *name);
  85. clish_sym_t *clish_plugin_add_osym(clish_plugin_t *instance,
  86. clish_hook_oaction_fn_t *func, const char *name);
  87. clish_sym_t *clish_plugin_add_posym(clish_plugin_t *instance,
  88. clish_hook_oaction_fn_t *func, const char *name);
  89. clish_sym_t *clish_plugin_add_hook(clish_plugin_t *instance,
  90. void *func, const char *name, int type);
  91. clish_sym_t *clish_plugin_add_phook(clish_plugin_t *instance,
  92. void *func, const char *name, int type);
  93. void clish_plugin_add_fini(clish_plugin_t *instance,
  94. clish_plugin_fini_t *fini);
  95. clish_plugin_fini_t * clish_plugin_get_fini(clish_plugin_t *instance);
  96. void clish_plugin_add_init(clish_plugin_t *instance,
  97. clish_plugin_init_t *init);
  98. clish_plugin_init_t * clish_plugin_get_init(clish_plugin_t *instance);
  99. void clish_plugin_dump(const clish_plugin_t *instance);
  100. char *clish_plugin__get_name(const clish_plugin_t *instance);
  101. void clish_plugin__set_alias(clish_plugin_t *instance, const char *alias);
  102. char *clish_plugin__get_alias(const clish_plugin_t *instance);
  103. char *clish_plugin__get_pubname(const clish_plugin_t *instance);
  104. void clish_plugin__set_file(clish_plugin_t *instance, const char *file);
  105. char *clish_plugin__get_file(const clish_plugin_t *instance);
  106. void clish_plugin__set_builtin_flag(clish_plugin_t *instance, bool_t builtin_flag);
  107. bool_t clish_plugin__get_builtin_flag(const clish_plugin_t *instance);
  108. void clish_plugin__set_conf(clish_plugin_t *instance, const char *conf);
  109. char *clish_plugin__get_conf(const clish_plugin_t *instance);
  110. #endif /* _clish_plugin_h */
  111. /** @} clish_plugin */