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