forked from oceanbase/obconnector-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ma_plugin_info.c
211 lines (185 loc) · 4.68 KB
/
ma_plugin_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <my_global.h>
#include <my_sys.h>
#include <mysql.h>
#include <mysql/client_plugin.h>
#include <getopt.h>
#include <stdio.h>
#include <my_dir.h>
#include <ma_string.h>
#define CLIENT_PLUGIN_INFO_VERSION "1.0.0"
static struct option long_options[]=
{
{"all", no_argument, 0, 'a'},
{"builtin", no_argument, 0, 'b'},
{"dynamic", no_argument, 0, 'd'},
{"directory", 1, 0, 'p'},
{"plugin_name", 1, 0, 'n'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, '?'},
{NULL, 0, 0, 0}
};
static char *values[] =
{
"show information for all plugins",
"show information for builtin plugins",
"show information for dynamic plugins",
"show information for dynamic plugins in specified directory",
"show information for specified plugin",
"show version information",
"display this help and exit",
NULL
};
struct st_plugin_type
{
int type;
char *typename;
};
#ifndef _WIN32
int my_errno=0;
#endif
static struct st_plugin_type plugin_types[]=
{
{MYSQL_CLIENT_AUTHENTICATION_PLUGIN, "authentication"},
{MARIADB_CLIENT_PVIO_PLUGIN, "virtual IO"},
{MARIADB_CLIENT_TRACE_PLUGIN, "trace"},
{MARIADB_CLIENT_REMOTEIO_PLUGIN, "remote file access"},
{MARIADB_CLIENT_CONNECTION_PLUGIN, "connection handler"},
{0, "unknown"}
};
static void version()
{
printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION);
}
static void usage(void)
{
int i=0;
printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION);
puts("Copyright 2015 MariaDB Corporation AB");
puts("Show client plugin information for MariaDB Connector/C.");
printf("Usage: %s [OPTIONS] [plugin_name]\n", ma_progname);
while (long_options[i].name)
{
printf(" --%-12s -%s\n", long_options[i].name, values[i]);
i++;
}
}
static char *ma_get_type_name(int type)
{
int i=0;
while (plugin_types[i].type)
{
if (type== plugin_types[i].type)
return plugin_types[i].typename;
i++;
}
return plugin_types[i].typename;
}
static void show_plugin_info(struct st_mysql_client_plugin *plugin, my_bool builtin)
{
printf("Name: %s\n", plugin->name);
printf("Type: %s\n", ma_get_type_name(plugin->type));
printf("Desc: %s\n", plugin->desc);
printf("Author: %s\n", plugin->author);
printf("License: %s\n", plugin->license);
printf("Version: %d.%d.%d\n", plugin->version[0], plugin->version[1], plugin->version[2]);
printf("API Version: 0x%04X\n", plugin->interface_version);
printf("Build type: %s\n", builtin ? "builtin" : "dynamic");
printf("\n");
}
static void show_builtin()
{
struct st_mysql_client_plugin **builtin;
for (builtin= mysql_client_builtins; *builtin; builtin++)
show_plugin_info(*builtin, TRUE);
}
static void show_file(char *filename)
{
char dlpath[FN_REFLEN+1];
void *sym, *dlhandle;
struct st_mysql_client_plugin *plugin;
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");
char *has_so_ext= strstr(filename, SO_EXT);
if (!strchr(filename, FN_LIBCHAR))
snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s",
(env_plugin_dir) ? env_plugin_dir : PLUGINDIR,
filename,
has_so_ext ? "" : SO_EXT);
else
strcpy(dlpath, filename);
if ((dlhandle= dlopen((const char *)dlpath, RTLD_NOW)))
{
if (sym= dlsym(dlhandle, plugin_declarations_sym))
{
plugin= (struct st_mysql_client_plugin *)sym;
show_plugin_info(plugin, 0);
}
dlclose(dlhandle);
}
}
static void show_dynamic(const char *directory)
{
MY_DIR *dir= NULL;
unsigned int i;
char *plugin_dir= directory ? (char *)directory : getenv("MARIADB_PLUGIN_DIR");
if (!plugin_dir)
plugin_dir= PLUGINDIR;
printf("plugin_dir %s\n", plugin_dir);
dir= my_dir(plugin_dir, 0);
if (!dir || !dir->number_off_files)
{
printf("No plugins found in %s\n", plugin_dir);
goto end;
}
for (i=0; i < dir->number_off_files; i++)
{
char *p= strstr(dir->dir_entry[i].name, SO_EXT);
if (p)
show_file(dir->dir_entry[i].name);
}
end:
if (dir)
my_dirend(dir);
}
int main(int argc, char *argv[])
{
int option_index= 0;
int c;
ma_progname= argv[0];
mysql_server_init(0, NULL, NULL);
if (argc <= 1)
{
usage();
exit(1);
}
c= getopt_long(argc, argv, "bdapnvh?", long_options, &option_index);
switch(c) {
case 'a': /* all */
show_builtin();
show_dynamic(NULL);
break;
case 'b': /* builtin */
show_builtin();
break;
case 'd': /* dynamic */
show_dynamic(NULL);
break;
case 'v':
version();
break;
case 'n':
if (argc > 2)
show_file(argv[2]);
break;
case 'p':
if (argc > 2)
show_dynamic(argv[2]);
break;
case '?':
usage();
break;
default:
printf("unrecocognized option: %s", argv[1]);
exit(1);
}
exit(0);
}