client_plugin.h 7.0 KB

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