You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
5.4 KiB

  1. /*
  2. Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  13. */
  14. #ifndef _sql_plugin_h
  15. #define _sql_plugin_h
  16. class sys_var;
  17. /*
  18. the following flags are valid for plugin_init()
  19. */
  20. #define PLUGIN_INIT_SKIP_DYNAMIC_LOADING 1
  21. #define PLUGIN_INIT_SKIP_PLUGIN_TABLE 2
  22. #define PLUGIN_INIT_SKIP_INITIALIZATION 4
  23. #define INITIAL_LEX_PLUGIN_LIST_SIZE 16
  24. /*
  25. the following #define adds server-only members to enum_mysql_show_type,
  26. that is defined in plugin.h
  27. */
  28. #define SHOW_FUNC SHOW_FUNC, SHOW_KEY_CACHE_LONG, SHOW_KEY_CACHE_LONGLONG, \
  29. SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_HAVE, \
  30. SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, SHOW_LONG_NOFLUSH, \
  31. SHOW_LONGLONG_STATUS
  32. #include <mysql/plugin.h>
  33. #undef SHOW_FUNC
  34. typedef enum enum_mysql_show_type SHOW_TYPE;
  35. typedef struct st_mysql_show_var SHOW_VAR;
  36. #define MYSQL_ANY_PLUGIN -1
  37. /*
  38. different values of st_plugin_int::state
  39. though they look like a bitmap, plugin may only
  40. be in one of those eigenstates, not in a superposition of them :)
  41. It's a bitmap, because it makes it easier to test
  42. "whether the state is one of those..."
  43. */
  44. #define PLUGIN_IS_FREED 1
  45. #define PLUGIN_IS_DELETED 2
  46. #define PLUGIN_IS_UNINITIALIZED 4
  47. #define PLUGIN_IS_READY 8
  48. #define PLUGIN_IS_DYING 16
  49. #define PLUGIN_IS_DISABLED 32
  50. /* A handle for the dynamic library containing a plugin or plugins. */
  51. struct st_plugin_dl
  52. {
  53. LEX_STRING dl;
  54. void *handle;
  55. struct st_mysql_plugin *plugins;
  56. int version;
  57. uint ref_count; /* number of plugins loaded from the library */
  58. };
  59. /* A handle of a plugin */
  60. struct st_plugin_int
  61. {
  62. LEX_STRING name;
  63. struct st_mysql_plugin *plugin;
  64. struct st_plugin_dl *plugin_dl;
  65. uint state;
  66. uint ref_count; /* number of threads using the plugin */
  67. void *data; /* plugin type specific, e.g. handlerton */
  68. MEM_ROOT mem_root; /* memory for dynamic plugin structures */
  69. sys_var *system_vars; /* server variables for this plugin */
  70. bool is_mandatory; /* If true then plugin must not fail to load */
  71. };
  72. /*
  73. See intern_plugin_lock() for the explanation for the
  74. conditionally defined plugin_ref type
  75. */
  76. #ifdef DBUG_OFF
  77. typedef struct st_plugin_int *plugin_ref;
  78. #define plugin_decl(pi) ((pi)->plugin)
  79. #define plugin_dlib(pi) ((pi)->plugin_dl)
  80. #define plugin_data(pi,cast) ((cast)((pi)->data))
  81. #define plugin_name(pi) (&((pi)->name))
  82. #define plugin_state(pi) ((pi)->state)
  83. #define plugin_equals(p1,p2) ((p1) == (p2))
  84. #else
  85. typedef struct st_plugin_int **plugin_ref;
  86. #define plugin_decl(pi) ((pi)[0]->plugin)
  87. #define plugin_dlib(pi) ((pi)[0]->plugin_dl)
  88. #define plugin_data(pi,cast) ((cast)((pi)[0]->data))
  89. #define plugin_name(pi) (&((pi)[0]->name))
  90. #define plugin_state(pi) ((pi)[0]->state)
  91. #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0])
  92. #endif
  93. typedef int (*plugin_type_init)(struct st_plugin_int *);
  94. extern char *opt_plugin_load;
  95. extern char *opt_plugin_dir_ptr;
  96. extern char opt_plugin_dir[FN_REFLEN];
  97. extern const LEX_STRING plugin_type_names[];
  98. extern int plugin_init(int *argc, char **argv, int init_flags);
  99. extern void plugin_shutdown(void);
  100. extern void my_print_help_inc_plugins(struct my_option *options, uint size);
  101. extern bool plugin_is_ready(const LEX_STRING *name, int type);
  102. #define my_plugin_lock_by_name(A,B,C) plugin_lock_by_name(A,B,C CALLER_INFO)
  103. #define my_plugin_lock_by_name_ci(A,B,C) plugin_lock_by_name(A,B,C ORIG_CALLER_INFO)
  104. #define my_plugin_lock(A,B) plugin_lock(A,B CALLER_INFO)
  105. #define my_plugin_lock_ci(A,B) plugin_lock(A,B ORIG_CALLER_INFO)
  106. extern plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO);
  107. extern plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name,
  108. int type CALLER_INFO_PROTO);
  109. extern void plugin_unlock(THD *thd, plugin_ref plugin);
  110. extern void plugin_unlock_list(THD *thd, plugin_ref *list, uint count);
  111. extern bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
  112. const LEX_STRING *dl);
  113. extern bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name);
  114. extern bool plugin_register_builtin(struct st_mysql_plugin *plugin);
  115. extern void plugin_thdvar_init(THD *thd);
  116. extern void plugin_thdvar_cleanup(THD *thd);
  117. extern bool check_valid_path(const char *path, size_t length);
  118. typedef my_bool (plugin_foreach_func)(THD *thd,
  119. plugin_ref plugin,
  120. void *arg);
  121. #define plugin_foreach(A,B,C,D) plugin_foreach_with_mask(A,B,C,PLUGIN_IS_READY,D)
  122. extern bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
  123. int type, uint state_mask, void *arg);
  124. #endif