client_plugin.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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)(); \
  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, const char *user, const char *passwd,
  78. const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag);
  79. void (*close)(MYSQL *mysql);
  80. int (*set_options)(MYSQL *mysql, enum mysql_option, void *arg);
  81. int (*set_connection)(MYSQL *mysql,enum enum_server_command command, const char *arg,
  82. size_t length, my_bool skipp_check, void *opt_arg);
  83. my_bool (*reconnect)(MYSQL *mysql);
  84. int (*reset)(MYSQL *mysql);
  85. } MARIADB_CONNECTION_PLUGIN;
  86. #define MARIADB_DB_DRIVER(a) ((a)->ext_db)
  87. /******************* Communication IO plugin *****************/
  88. #include <ma_pvio.h>
  89. typedef struct st_mariadb_client_plugin_PVIO
  90. {
  91. MYSQL_CLIENT_PLUGIN_HEADER
  92. struct st_ma_pvio_methods *methods;
  93. } MARIADB_PVIO_PLUGIN;
  94. /******** authentication plugin specific declarations *********/
  95. #include <mysql/plugin_auth_common.h>
  96. struct st_mysql_client_plugin_AUTHENTICATION
  97. {
  98. MYSQL_CLIENT_PLUGIN_HEADER
  99. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql);
  100. };
  101. /******** trace plugin *******/
  102. struct st_mysql_client_plugin_TRACE
  103. {
  104. MYSQL_CLIENT_PLUGIN_HEADER
  105. };
  106. /**
  107. type of the mysql_authentication_dialog_ask function
  108. @param mysql mysql
  109. @param type type of the input
  110. 1 - ordinary string input
  111. 2 - password string
  112. @param prompt prompt
  113. @param buf a buffer to store the use input
  114. @param buf_len the length of the buffer
  115. @retval a pointer to the user input string.
  116. It may be equal to 'buf' or to 'mysql->password'.
  117. In all other cases it is assumed to be an allocated
  118. string, and the "dialog" plugin will free() it.
  119. */
  120. typedef char *(*mysql_authentication_dialog_ask_t)(struct st_mysql *mysql,
  121. int type, const char *prompt, char *buf, int buf_len);
  122. /********************** remote IO plugin **********************/
  123. #ifdef HAVE_REMOTEIO
  124. #include <mariadb/ma_io.h>
  125. /* Remote IO plugin */
  126. typedef struct st_mysql_client_plugin_REMOTEIO
  127. {
  128. MYSQL_CLIENT_PLUGIN_HEADER
  129. struct st_rio_methods *methods;
  130. } MARIADB_REMOTEIO_PLUGIN;
  131. #endif
  132. /******** using plugins ************/
  133. /**
  134. loads a plugin and initializes it
  135. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  136. and last_errno/last_error, for error reporting
  137. @param name a name of the plugin to load
  138. @param type type of plugin that should be loaded, -1 to disable type check
  139. @param argc number of arguments to pass to the plugin initialization
  140. function
  141. @param ... arguments for the plugin initialization function
  142. @retval
  143. a pointer to the loaded plugin, or NULL in case of a failure
  144. */
  145. struct st_mysql_client_plugin * STDCALL
  146. mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
  147. int argc, ...);
  148. /**
  149. loads a plugin and initializes it, taking va_list as an argument
  150. This is the same as mysql_load_plugin, but take va_list instead of
  151. a list of arguments.
  152. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  153. and last_errno/last_error, for error reporting
  154. @param name a name of the plugin to load
  155. @param type type of plugin that should be loaded, -1 to disable type check
  156. @param argc number of arguments to pass to the plugin initialization
  157. function
  158. @param args arguments for the plugin initialization function
  159. @retval
  160. a pointer to the loaded plugin, or NULL in case of a failure
  161. */
  162. struct st_mysql_client_plugin * STDCALL
  163. mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type,
  164. int argc, va_list args);
  165. /**
  166. finds an already loaded plugin by name, or loads it, if necessary
  167. @param mysql MYSQL structure. only MYSQL_PLUGIN_DIR option value is used,
  168. and last_errno/last_error, for error reporting
  169. @param name a name of the plugin to load
  170. @param type type of plugin that should be loaded
  171. @retval
  172. a pointer to the plugin, or NULL in case of a failure
  173. */
  174. struct st_mysql_client_plugin * STDCALL
  175. mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type);
  176. /**
  177. adds a plugin structure to the list of loaded plugins
  178. This is useful if an application has the necessary functionality
  179. (for example, a special load data handler) statically linked into
  180. the application binary. It can use this function to register the plugin
  181. directly, avoiding the need to factor it out into a shared object.
  182. @param mysql MYSQL structure. It is only used for error reporting
  183. @param plugin an st_mysql_client_plugin structure to register
  184. @retval
  185. a pointer to the plugin, or NULL in case of a failure
  186. */
  187. struct st_mysql_client_plugin * STDCALL
  188. mysql_client_register_plugin(struct st_mysql *mysql,
  189. struct st_mysql_client_plugin *plugin);
  190. extern struct st_mysql_client_plugin *mysql_client_builtins[];
  191. #endif