1 #ifndef MYSQL_CLIENT_PLUGIN_INCLUDED 2 /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. 3 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 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 17 /** 18 @file 19 20 MySQL Client Plugin API 21 22 This file defines the API for plugins that work on the client side 23 */ 24 #define MYSQL_CLIENT_PLUGIN_INCLUDED 25 26 #ifndef MYSQL_ABI_CHECK 27 #include <stdarg.h> 28 #include <stdlib.h> 29 #endif 30 31 /* known plugin types */ 32 #define MYSQL_CLIENT_reserved1 0 33 #define MYSQL_CLIENT_reserved2 1 34 #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN 2 35 36 #define MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION 0x0100 37 38 #define MYSQL_CLIENT_MAX_PLUGINS 3 39 40 #define mysql_declare_client_plugin(X) \ 41 MYSQL_PLUGIN_EXPORT struct st_mysql_client_plugin_ ## X \ 42 _mysql_client_plugin_declaration_ = { \ 43 MYSQL_CLIENT_ ## X ## _PLUGIN, \ 44 MYSQL_CLIENT_ ## X ## _PLUGIN_INTERFACE_VERSION, 45 #define mysql_end_client_plugin } 46 47 /* generic plugin header structure */ 48 #define MYSQL_CLIENT_PLUGIN_HEADER \ 49 int type; \ 50 unsigned int interface_version; \ 51 const char *name; \ 52 const char *author; \ 53 const char *desc; \ 54 unsigned int version[3]; \ 55 const char *license; \ 56 void *mysql_api; \ 57 int (*init)(char *, size_t, int, va_list); \ 58 int (*deinit)(); \ 59 int (*options)(const char *option, const void *); 60 61 struct st_mysql_client_plugin 62 { 63 MYSQL_CLIENT_PLUGIN_HEADER 64 }; 65 66 struct st_mysql; 67 68 /******** authentication plugin specific declarations *********/ 69 #include <mysql/plugin_auth_common.h> 70 71 struct st_mysql_client_plugin_AUTHENTICATION 72 { 73 MYSQL_CLIENT_PLUGIN_HEADER 74 int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql); 75 }; 76 77 /******** using plugins ************/ 78 79 /** 80 loads a plugin and initializes it 81 82 @param mysql MYSQL structure. 83 @param name a name of the plugin to load 84 @param type type of plugin that should be loaded, -1 to disable type check 85 @param argc number of arguments to pass to the plugin initialization 86 function 87 @param ... arguments for the plugin initialization function 88 89 @retval 90 a pointer to the loaded plugin, or NULL in case of a failure 91 */ 92 struct st_mysql_client_plugin * 93 mysql_load_plugin(struct st_mysql *mysql, const char *name, int type, 94 int argc, ...); 95 96 /** 97 loads a plugin and initializes it, taking va_list as an argument 98 99 This is the same as mysql_load_plugin, but take va_list instead of 100 a list of arguments. 101 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 args arguments for the plugin initialization function 108 109 @retval 110 a pointer to the loaded plugin, or NULL in case of a failure 111 */ 112 struct st_mysql_client_plugin * 113 mysql_load_plugin_v(struct st_mysql *mysql, const char *name, int type, 114 int argc, va_list args); 115 116 /** 117 finds an already loaded plugin by name, or loads it, if necessary 118 119 @param mysql MYSQL structure. 120 @param name a name of the plugin to load 121 @param type type of plugin that should be loaded 122 123 @retval 124 a pointer to the plugin, or NULL in case of a failure 125 */ 126 struct st_mysql_client_plugin * 127 mysql_client_find_plugin(struct st_mysql *mysql, const char *name, int type); 128 129 /** 130 adds a plugin structure to the list of loaded plugins 131 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 137 @param mysql MYSQL structure. It is only used for error reporting 138 @param plugin an st_mysql_client_plugin structure to register 139 140 @retval 141 a pointer to the plugin, or NULL in case of a failure 142 */ 143 struct st_mysql_client_plugin * 144 mysql_client_register_plugin(struct st_mysql *mysql, 145 struct st_mysql_client_plugin *plugin); 146 147 /** 148 set plugin options 149 150 Can be used to set extra options and affect behavior for a plugin. 151 This function may be called multiple times to set several options 152 153 @param plugin an st_mysql_client_plugin structure 154 @param option a string which specifies the option to set 155 @param value value for the option. 156 157 @retval 0 on success, 1 in case of failure 158 **/ 159 int mysql_plugin_options(struct st_mysql_client_plugin *plugin, 160 const char *option, const void *value); 161 #endif 162 163