client_plugin.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
  2. /* Copyright (c) 2010, 2016, 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. @file
  15. MySQL Client Plugin API
  16. This file defines the API for plugins that work on the client side
  17. */
  18. #define MYSQL_CLIENT_PLUGIN_INCLUDED
  19. #ifndef MYSQL_ABI_CHECK
  20. #include <stdarg.h>
  21. #include <stdlib.h>
  22. #endif
  23. /*
  24. On Windows, exports from DLL need to be declared.
  25. Also, plugin needs to be declared as extern "C" because MSVC
  26. unlike other compilers, uses C++ mangling for variables not only
  27. for functions.
  28. */
  29. #undef MYSQL_PLUGIN_EXPORT
  30. #if defined(_MSC_VER)
  31. #if defined(MYSQL_DYNAMIC_PLUGIN)
  32. #ifdef __cplusplus
  33. #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
  34. #else
  35. #define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
  36. #endif
  37. #else /* MYSQL_DYNAMIC_PLUGIN */
  38. #ifdef __cplusplus
  39. #define MYSQL_PLUGIN_EXPORT extern "C"
  40. #else
  41. #define MYSQL_PLUGIN_EXPORT
  42. #endif
  43. #endif /*MYSQL_DYNAMIC_PLUGIN */
  44. #else /*_MSC_VER */
  45. #define MYSQL_PLUGIN_EXPORT
  46. #endif
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /* known plugin types */
  51. #define MYSQL_CLIENT_reserved1 0
  52. #define MYSQL_CLIENT_reserved2 1
  53. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
  54. #define MYSQL_CLIENT_TRACE_PLUGIN 3
  55. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
  56. #define MYSQL_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0100
  57. #define MYSQL_CLIENT_MAX_PLUGINS 4
  58. #define mysql_declare_client_plugin(X) \
  59. MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \
  60. _mysql_client_plugin_declaration_ = { \
  61. MYSQL_CLIENT_ ## X ## _PLUGIN, \
  62. MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
  63. #define mysql_end_client_plugin }
  64. /* generic plugin header structure */
  65. #define MYSQL_CLIENT_PLUGIN_HEADER \
  66. int type; \
  67. unsigned int interface_version; \
  68. const char *name; \
  69. const char *author; \
  70. const char *desc; \
  71. unsigned int version[3]; \
  72. const char *license; \
  73. void *mysql_api; \
  74. int (*init)(char *, size_t, int, va_list); \
  75. int (*deinit)(void); \
  76. int (*options)(const char *option, const void *);
  77. struct st_mysql_client_plugin
  78. {
  79. MYSQL_CLIENT_PLUGIN_HEADER
  80. };
  81. struct st_mysql;
  82. /******** authentication plugin specific declarations *********/
  83. #include "plugin_auth_common.h"
  84. struct st_mysql_client_plugin_AUTHENTICATION
  85. {
  86. MYSQL_CLIENT_PLUGIN_HEADER
  87. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
  88. };
  89. /******** using plugins ************/
  90. /**
  91. loads a plugin and initializes it
  92. @param mysql MYSQL structure.
  93. @param name a name of the plugin to load
  94. @param type type of plugin that should be loaded, -1 to disable type check
  95. @param argc number of arguments to pass to the plugin initialization
  96. function
  97. @param ... arguments for the plugin initialization function
  98. @retval
  99. a pointer to the loaded plugin, or NULL in case of a failure
  100. */
  101. struct st_mysql_client_plugin *
  102. mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
  103. int argc, ...);
  104. /**
  105. loads a plugin and initializes it, taking va_list as an argument
  106. This is the same as mysql_load_plugin, but take va_list instead of
  107. a list of arguments.
  108. @param mysql MYSQL structure.
  109. @param name a name of the plugin to load
  110. @param type type of plugin that should be loaded, -1 to disable type check
  111. @param argc number of arguments to pass to the plugin initialization
  112. function
  113. @param args arguments for the plugin initialization function
  114. @retval
  115. a pointer to the loaded plugin, or NULL in case of a failure
  116. */
  117. struct st_mysql_client_plugin *
  118. mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
  119. int argc, va_list args);
  120. /**
  121. finds an already loaded plugin by name, or loads it, if necessary
  122. @param mysql MYSQL structure.
  123. @param name a name of the plugin to load
  124. @param type type of plugin that should be loaded
  125. @retval
  126. a pointer to the plugin, or NULL in case of a failure
  127. */
  128. struct st_mysql_client_plugin *
  129. mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
  130. /**
  131. adds a plugin structure to the list of loaded plugins
  132. This is useful if an application has the necessary functionality
  133. (for example, a special load data handler) statically linked into
  134. the application binary. It can use this function to register the plugin
  135. directly, avoiding the need to factor it out into a shared object.
  136. @param mysql MYSQL structure. It is only used for error reporting
  137. @param plugin an st_mysql_client_plugin structure to register
  138. @retval
  139. a pointer to the plugin, or NULL in case of a failure
  140. */
  141. struct st_mysql_client_plugin *
  142. mysql_client_register_plugin(struct st_mysql *mysql,
  143. struct st_mysql_client_plugin *plugin);
  144. /**
  145. set plugin options
  146. Can be used to set extra options and affect behavior for a plugin.
  147. This function may be called multiple times to set several options
  148. @param plugin an st_mysql_client_plugin structure
  149. @param option a string which specifies the option to set
  150. @param value value for the option.
  151. @retval 0 on success, 1 in case of failure
  152. **/
  153. int mysql_plugin_options(struct st_mysql_client_plugin *plugin,
  154. const char *option, const void *value);
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif