2
0

client_plugin.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab
  2. 2014 MariaDB Corporation AB
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library 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 GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not see <http://www.gnu.org/licenses>
  13. or write to the Free Software Foundation, Inc.,
  14. 51 Franklin St., Fifth Floor, Boston, MA 02110, USA */
  15. /**
  16. @file
  17. MySQL Client Plugin API
  18. This file defines the API for plugins that work on the client side
  19. */
  20. #ifndef MYSQL_CLIENT_PLUGIN_INCLUDED
  21. #define MYSQL_CLIENT_PLUGIN_INCLUDED
  22. #ifndef MYSQL_ABI_CHECK
  23. #include <stdarg.h>
  24. #include <stdlib.h>
  25. #endif
  26. #ifndef PLUGINDIR
  27. #define PLUGINDIR "lib/plugin"
  28. #endif
  29. #define plugin_declarations_sym "_mysql_client_plugin_declaration_"
  30. /* known plugin types */
  31. #define MYSQL_CLIENT_PLUGIN_RESERVED 0
  32. #define MYSQL_CLIENT_PLUGIN_RESERVED2 1
  33. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 /* authentication */
  34. #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100
  35. #define MYSQL_CLIENT_MAX_PLUGINS 3
  36. /* Connector/C specific plugin types */
  37. #define MARIADB_CLIENT_REMOTEIO_PLUGIN 100 /* communication IO */
  38. #define MARIADB_CLIENT_PVIO_PLUGIN 101
  39. #define MARIADB_CLIENT_TRACE_PLUGIN 102
  40. #define MARIADB_CLIENT_CONNECTION_PLUGIN 103
  41. #define MARIADB_CLIENT_REMOTEIO_PLUGIN_INTERFACE_VERSION 0x0100
  42. #define MARIADB_CLIENT_PVIO_PLUGIN_INTERFACE_VERSION 0x0100
  43. #define MARIADB_CLIENT_TRACE_PLUGIN_INTERFACE_VERSION 0x0100
  44. #define MARIADB_CLIENT_CONNECTION_PLUGIN_INTERFACE_VERSION 0x0100
  45. #define MARIADB_CLIENT_MAX_PLUGINS 4
  46. #define mysql_declare_client_plugin(X) \
  47. struct st_mysql_client_plugin_ ## X \
  48. _mysql_client_plugin_declaration_ = { \
  49. MYSQL_CLIENT_ ## X ## _PLUGIN, \
  50. MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION,
  51. #define mysql_end_client_plugin }
  52. /* generic plugin header structure */
  53. #ifndef MYSQL_CLIENT_PLUGIN_HEADER
  54. #define MYSQL_CLIENT_PLUGIN_HEADER \
  55. int type; \
  56. unsigned int interface_version; \
  57. const char *name; \
  58. const char *author; \
  59. const char *desc; \
  60. unsigned int version[3]; \
  61. const char *license; \
  62. void *mysql_api; \
  63. int (*init)(char *, size_t, int, va_list); \
  64. int (*deinit)(void); \
  65. int (*options)(const char *option, const void *);
  66. struct st_mysql_client_plugin
  67. {
  68. MYSQL_CLIENT_PLUGIN_HEADER
  69. };
  70. #endif
  71. struct st_mysql;
  72. /********* connection handler plugin specific declarations **********/
  73. typedef struct st_ma_connection_plugin
  74. {
  75. MYSQL_CLIENT_PLUGIN_HEADER
  76. /* functions */
  77. MYSQL *(*connect)(MYSQL *mysql, const char *host,
  78. const char *user, const char *passwd,
  79. const char *db, unsigned int port,
  80. const char *unix_socket, unsigned long clientflag);
  81. void (*close)(MYSQL *mysql);
  82. int (*set_optionsv)(MYSQL *mysql, unsigned int option, ...);
  83. int (*set_connection)(MYSQL *mysql,enum enum_server_command command,
  84. const char *arg,
  85. size_t length, my_bool skipp_check, void *opt_arg);
  86. my_bool (*reconnect)(MYSQL *mysql);
  87. int (*reset)(MYSQL *mysql);
  88. } MARIADB_CONNECTION_PLUGIN;
  89. #define MARIADB_DB_DRIVER(a) ((a)->ext_db)
  90. /******************* Communication IO plugin *****************/
  91. #include <ma_pvio.h>
  92. typedef struct st_mariadb_client_plugin_PVIO
  93. {
  94. MYSQL_CLIENT_PLUGIN_HEADER
  95. struct st_ma_pvio_methods *methods;
  96. } MARIADB_PVIO_PLUGIN;
  97. /******** authentication plugin specific declarations *********/
  98. #include <mysql/plugin_auth_common.h>
  99. struct st_mysql_client_plugin_AUTHENTICATION
  100. {
  101. MYSQL_CLIENT_PLUGIN_HEADER
  102. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
  103. };
  104. /******** trace plugin *******/
  105. struct st_mysql_client_plugin_TRACE
  106. {
  107. MYSQL_CLIENT_PLUGIN_HEADER
  108. };
  109. /**
  110. type of the mysql_authentication_dialog_ask function
  111. @param mysql mysql
  112. @param type type of the input
  113. 1 - ordinary string input
  114. 2 - password string
  115. @param prompt prompt
  116. @param buf a buffer to store the use input
  117. @param buf_len the length of the buffer
  118. @retval a pointer to the user input string.
  119. It may be equal to 'buf' or to 'mysql->password'.
  120. In all other cases it is assumed to be an allocated
  121. string, and the "dialog" plugin will free() it.
  122. */
  123. typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
  124. int type, const char *prompt, char *buf, int buf_len);
  125. /********************** remote IO plugin **********************/
  126. #ifdef HAVE_REMOTEIO
  127. #include <mariadb/ma_io.h>
  128. /* Remote IO plugin */
  129. typedef struct st_mysql_client_plugin_REMOTEIO
  130. {
  131. MYSQL_CLIENT_PLUGIN_HEADER
  132. struct st_rio_methods *methods;
  133. } MARIADB_REMOTEIO_PLUGIN;
  134. #endif
  135. /******** using plugins ************/
  136. /**
  137. loads a plugin and initializes it
  138. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  139. and last_errno/last_error, for error reporting
  140. @param name a name of the plugin to load
  141. @param type type of plugin that should be loaded, -1 to disable type check
  142. @param argc number of arguments to pass to the plugin initialization
  143. function
  144. @param ... arguments for the plugin initialization function
  145. @retval
  146. a pointer to the loaded plugin, or NULL in case of a failure
  147. */
  148. struct st_mysql_client_plugin *
  149. mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
  150. int argc, ...);
  151. /**
  152. loads a plugin and initializes it, taking va_list as an argument
  153. This is the same as mysql_load_plugin, but take va_list instead of
  154. a list of arguments.
  155. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  156. and last_errno/last_error, for error reporting
  157. @param name a name of the plugin to load
  158. @param type type of plugin that should be loaded, -1 to disable type check
  159. @param argc number of arguments to pass to the plugin initialization
  160. function
  161. @param args arguments for the plugin initialization function
  162. @retval
  163. a pointer to the loaded plugin, or NULL in case of a failure
  164. */
  165. struct st_mysql_client_plugin * STDCALL
  166. mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
  167. int argc, va_list args);
  168. /**
  169. finds an already loaded plugin by name, or loads it, if necessary
  170. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  171. and last_errno/last_error, for error reporting
  172. @param name a name of the plugin to load
  173. @param type type of plugin that should be loaded
  174. @retval
  175. a pointer to the plugin, or NULL in case of a failure
  176. */
  177. struct st_mysql_client_plugin * STDCALL
  178. mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
  179. /**
  180. adds a plugin structure to the list of loaded plugins
  181. This is useful if an application has the necessary functionality
  182. (for example, a special load data handler) statically linked into
  183. the application binary. It can use this function to register the plugin
  184. directly, avoiding the need to factor it out into a shared object.
  185. @param mysql MYSQL structure. It is only used for error reporting
  186. @param plugin an st_mysql_client_plugin structure to register
  187. @retval
  188. a pointer to the plugin, or NULL in case of a failure
  189. */
  190. struct st_mysql_client_plugin * STDCALL
  191. mysql_client_register_plugin(struct st_mysql *mysql,
  192. struct st_mysql_client_plugin *plugin);
  193. extern struct st_mysql_client_plugin *mysql_client_builtins[];
  194. #endif