Author: paul
Date: 2010-11-04 20:54:58 +0100 (Thu, 04 Nov 2010)
New Revision: 23576
Log:
r65157@frost: paul | 2010-11-04 14:30:36 -0500
Add sample program to demonstrate client plugin functions
Added:
trunk/sample-programs/client_plugin.c
Modified:
trunk/sample-programs/Makefile
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 07c7e7b4-24e3-4b51-89d0-6dc09fec6bec:/mysqldoc-local/mysqldoc/trunk:35498
07c7e7b4-24e3-4b51-89d0-6dc09fec6bec:/mysqldoc-local/trunk:43912
4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:43968
4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/trunk:44480
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:65152
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:39036
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/trunk:39546
+ 07c7e7b4-24e3-4b51-89d0-6dc09fec6bec:/mysqldoc-local/mysqldoc/trunk:35498
07c7e7b4-24e3-4b51-89d0-6dc09fec6bec:/mysqldoc-local/trunk:43912
4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:43968
4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/trunk:44480
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:65157
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:39036
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/trunk:39546
Modified: trunk/sample-programs/Makefile
===================================================================
--- trunk/sample-programs/Makefile 2010-11-04 19:54:40 UTC (rev 23575)
+++ trunk/sample-programs/Makefile 2010-11-04 19:54:58 UTC (rev 23576)
Changed blocks: 2, Lines Added: 5, Lines Deleted: 1; 694 bytes
@@ -7,7 +7,7 @@
LIBS = ${shell $(MYSQL_CONFIG) --libs}
EMBLIBS = ${shell $(MYSQL_CONFIG) --libmysqld-libs}
-ALL_PROGRAMS = ps_call
+ALL_PROGRAMS = ps_call client_plugin
default::
@echo "You must say what you want to build. For example:"
@@ -25,5 +25,9 @@
ps_call:: ps_call.o
$(CXX) -o $@ ps_call.o $(LIBS)
+client_plugin.o: client_plugin.c
+client_plugin:: client_plugin.o
+ $(CXX) -o $@ client_plugin.o $(LIBS)
+
clean::
rm -f $(ALL_PROGRAMS) *.o
Added: trunk/sample-programs/client_plugin.c
===================================================================
--- trunk/sample-programs/client_plugin.c (rev 0)
+++ trunk/sample-programs/client_plugin.c 2010-11-04 19:54:58 UTC (rev 23576)
Changed blocks: 1, Lines Added: 82, Lines Deleted: 0; 2236 bytes
@@ -0,0 +1,82 @@
+/*
+ * client_plugin.c - demonstrate the C API client plugin calls
+ *
+ * This demonstrates the low level calls, not the MYSQL_DEFAULT_AUTH
+ * and MYSQL_PLUGIN_DIR options for mysql_options() for plugin loading.
+ *
+ * The test plugin is included in MySQL distributions as of MySQL 5.5.7.
+ */
+
+#include <my_global.h>
+#include <mysql.h>
+#include <mysql/plugin_auth.h>
+#include <mysql/client_plugin.h>
+
+static MYSQL *mysql; /* pointer to connection handler */
+
+static void
+print_error (MYSQL *mysql, char *message)
+{
+ fprintf (stderr, "%s\n", message);
+ if (mysql != NULL)
+ {
+ fprintf (stderr, "Error %u (%s): %s\n",
+ mysql_errno (mysql), mysql_sqlstate (mysql), mysql_error (mysql));
+ }
+}
+
+static void test_error(MYSQL *mysql, int status)
+{
+ if (status)
+ {
+ printf("Error: %s (errno: %d)\n",
+ mysql_error(mysql), mysql_errno(mysql));
+ exit(1);
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+struct st_mysql_client_plugin *plugin;
+char *name = "auth_test_plugin";
+
+#if (MYSQL_VERSION_ID < 50507)
+ print_error (NULL, "This program requires MySQL 5.5.7 or higher");
+ exit (1);
+#endif
+ /* initialize client library */
+ if (mysql_library_init (0, NULL, NULL))
+ {
+ print_error (NULL, "mysql_library_init() failed");
+ exit (1);
+ }
+
+ /* initialize connection handler */
+ mysql = mysql_init (NULL);
+ if (mysql == NULL)
+ {
+ print_error (NULL, "mysql_init() failed (probably out of memory)");
+ exit (1);
+ }
+
+ plugin = mysql_load_plugin (mysql, name,
+ MYSQL_CLIENT_AUTHENTICATION_PLUGIN, 0);
+ if (plugin == NULL)
+ {
+ print_error (mysql, "Cannot load plugin");
+ exit (1);
+ }
+
+ plugin = mysql_client_find_plugin (mysql, name,
+ MYSQL_CLIENT_AUTHENTICATION_PLUGIN);
+ if (plugin == NULL)
+ {
+ print_error (mysql, "Cannot find plugin");
+ exit (1);
+ }
+
+ /* terminate client library */
+ mysql_library_end ();
+ exit (0);
+}
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r23576 - in trunk: . sample-programs | paul.dubois | 4 Nov |