client_plugin.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
  2. /* Copyright (C) 2010 Sergei Golubchik and Monty Program Ab
  3. Copyright (c) 2010, 2011, Oracle and/or its affiliates.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  14. /**
  15. @file
  16. MySQL Client Plugin API
  17. This file defines the API for plugins that work on the client side
  18. */
  19. #define MYSQL_CLIENT_PLUGIN_INCLUDED
  20. /*
  21. On Windows, exports from DLL need to be declared
  22. Also, plugin needs to be declared as extern "C" because MSVC
  23. unlike other compilers, uses C++ mangling for variables not only
  24. for functions.
  25. */
  26. #undef MYSQL_PLUGIN_EXPORT
  27. #if defined(_MSC_VER)
  28. #ifdef __cplusplus
  29. #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport)
  30. #else
  31. #define MYSQL_PLUGIN_EXPORT __declspec(dllexport)
  32. #endif
  33. #else /*_MSC_VER */
  34. #ifdef __cplusplus
  35. #define MYSQL_PLUGIN_EXPORT extern "C"
  36. #else
  37. #define MYSQL_PLUGIN_EXPORT
  38. #endif
  39. #endif
  40. #ifndef MYSQL_ABI_CHECK
  41. #include <stdarg.h>
  42. #include <stdlib.h>
  43. #endif
  44. /* known plugin types */
  45. #define MYSQL_CLIENT_reserved1 0
  46. #define MYSQL_CLIENT_reserved2 1
  47. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2
  48. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
  49. #define MYSQL_CLIENT_MAX_PLUGINS 3
  50. #define mysql_declare_client_plugin(X) \
  51. MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \
  52. _mysql_client_plugin_declaration_ = { \
  53. MYSQL_CLIENT_ ## X ## _PLUGIN, \
  54. MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
  55. #define mysql_end_client_plugin }
  56. /* generic plugin header structure */
  57. #define MYSQL_CLIENT_PLUGIN_HEADER \
  58. int type; \
  59. unsigned int interface_version; \
  60. const char *name; \
  61. const char *author; \
  62. const char *desc; \
  63. unsigned int version[3]; \
  64. const char *license; \
  65. void *mysql_api; \
  66. int (*init)(char *, size_t, int, va_list); \
  67. int (*deinit)(); \
  68. int (*options)(const char *option, const void *);
  69. struct st_mysql_client_plugin
  70. {
  71. MYSQL_CLIENT_PLUGIN_HEADER
  72. };
  73. struct st_mysql;
  74. /******** authentication plugin specific declarations *********/
  75. #include <mysql/plugin_auth_common.h>
  76. struct st_mysql_client_plugin_AUTHENTICATION
  77. {
  78. MYSQL_CLIENT_PLUGIN_HEADER
  79. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
  80. };
  81. #include <mysql/auth_dialog_client.h>
  82. /******** using plugins ************/
  83. /**
  84. loads a plugin and initializes it
  85. @param mysql MYSQL structure.
  86. @param name a name of the plugin to load
  87. @param type type of plugin that should be loaded, -1 to disable type check
  88. @param argc number of arguments to pass to the plugin initialization
  89. function
  90. @param ... arguments for the plugin initialization function
  91. @retval
  92. a pointer to the loaded plugin, or NULL in case of a failure
  93. */
  94. struct st_mysql_client_plugin *
  95. mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
  96. int argc, ...);
  97. /**
  98. loads a plugin and initializes it, taking va_list as an argument
  99. This is the same as mysql_load_plugin, but take va_list instead of
  100. a list of arguments.
  101. @param mysql MYSQL structure.
  102. @param name a name of the plugin to load
  103. @param type type of plugin that should be loaded, -1 to disable type check
  104. @param argc number of arguments to pass to the plugin initialization
  105. function
  106. @param args arguments for the plugin initialization function
  107. @retval
  108. a pointer to the loaded plugin, or NULL in case of a failure
  109. */
  110. struct st_mysql_client_plugin *
  111. mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
  112. int argc, va_list args);
  113. /**
  114. finds an already loaded plugin by name, or loads it, if necessary
  115. @param mysql MYSQL structure.
  116. @param name a name of the plugin to load
  117. @param type type of plugin that should be loaded
  118. @retval
  119. a pointer to the plugin, or NULL in case of a failure
  120. */
  121. struct st_mysql_client_plugin *
  122. mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
  123. /**
  124. adds a plugin structure to the list of loaded plugins
  125. This is useful if an application has the necessary functionality
  126. (for example, a special load data handler) statically linked into
  127. the application binary. It can use this function to register the plugin
  128. directly, avoiding the need to factor it out into a shared object.
  129. @param mysql MYSQL structure. It is only used for error reporting
  130. @param plugin an st_mysql_client_plugin structure to register
  131. @retval
  132. a pointer to the plugin, or NULL in case of a failure
  133. */
  134. struct st_mysql_client_plugin *
  135. mysql_client_register_plugin(struct st_mysql *mysql,
  136. struct st_mysql_client_plugin *plugin);
  137. /**
  138. set plugin options
  139. Can be used to set extra options and affect behavior for a plugin.
  140. This function may be called multiple times to set several options
  141. @param plugin an st_mysql_client_plugin structure
  142. @param option a string which specifies the option to set
  143. @param value value for the option.
  144. @retval 0 on success, 1 in case of failure
  145. **/
  146. int mysql_plugin_options(struct st_mysql_client_plugin *plugin,
  147. const char *option, const void *value);
  148. #endif