499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
499.2.10
by Mark Atwood
add editor format hints, and other useful metadata comments |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
3 |
*
|
499.2.10
by Mark Atwood
add editor format hints, and other useful metadata comments |
4 |
* Copyright (C) 2008 Mark Atwood
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
20 |
#include <drizzled/server_includes.h> |
21 |
#include <drizzled/errmsg.h> |
|
549
by Monty Taylor
Took gettext.h out of header files. |
22 |
#include <drizzled/gettext.h> |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
23 |
|
24 |
int errmsg_initializer(st_plugin_int *plugin) |
|
25 |
{
|
|
26 |
errmsg_t *p; |
|
27 |
||
28 |
p= (errmsg_t *) malloc(sizeof(errmsg_t)); |
|
29 |
if (p == NULL) return 1; |
|
30 |
memset(p, 0, sizeof(errmsg_t)); |
|
31 |
||
32 |
plugin->data= (void *)p; |
|
33 |
||
34 |
if (plugin->plugin->init) |
|
35 |
{
|
|
36 |
if (plugin->plugin->init((void *)p)) |
|
37 |
{
|
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
38 |
/* we're doing the errmsg plugin api,
|
39 |
so we can't trust the errmsg api to emit our error messages
|
|
40 |
so we will emit error messages to stderr */
|
|
41 |
/* TRANSLATORS: The leading word "errmsg" is the name
|
|
42 |
of the plugin api, and so should not be translated. */
|
|
43 |
fprintf(stderr, |
|
44 |
_("errmsg plugin '%s' init() failed."), |
|
45 |
plugin->name.str); |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
46 |
goto err; |
47 |
}
|
|
48 |
}
|
|
49 |
return 0; |
|
50 |
||
51 |
err: |
|
52 |
free(p); |
|
53 |
return 1; |
|
54 |
}
|
|
55 |
||
56 |
int errmsg_finalizer(st_plugin_int *plugin) |
|
57 |
{
|
|
58 |
errmsg_t *p = (errmsg_t *) plugin->data; |
|
59 |
||
60 |
if (plugin->plugin->deinit) |
|
61 |
{
|
|
62 |
if (plugin->plugin->deinit((void *)p)) |
|
63 |
{
|
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
64 |
/* we're doing the errmsg plugin api,
|
65 |
so we can't trust the errmsg api to emit our error messages
|
|
66 |
so we will emit error messages to stderr */
|
|
67 |
/* TRANSLATORS: The leading word "errmsg" is the name
|
|
68 |
of the plugin api, and so should not be translated. */
|
|
69 |
fprintf(stderr, |
|
70 |
_("errmsg plugin '%s' deinit() failed."), |
|
71 |
plugin->name.str); |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
72 |
}
|
73 |
}
|
|
74 |
||
75 |
if (p) free(p); |
|
76 |
||
77 |
return 0; |
|
78 |
}
|
|
79 |
||
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
80 |
/* The plugin_foreach() iterator requires that we
|
81 |
convert all the parameters of a plugin api entry point
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
82 |
into just one single void ptr, plus the session.
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
83 |
So we will take all the additional paramters of errmsg_vprintf,
|
84 |
and marshall them into a struct of this type, and
|
|
85 |
then just pass in a pointer to it.
|
|
86 |
*/
|
|
87 |
typedef struct errmsg_parms_st |
|
88 |
{
|
|
89 |
int priority; |
|
90 |
const char *format; |
|
91 |
va_list ap; |
|
92 |
} errmsg_parms_t; |
|
93 |
||
94 |
||
95 |
/* This gets called by plugin_foreach once for each loaded errmsg plugin */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
96 |
static bool errmsg_iterate (Session *session, plugin_ref plugin, void *p) |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
97 |
{
|
98 |
errmsg_t *l= plugin_data(plugin, errmsg_t *); |
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
99 |
errmsg_parms_t *parms= (errmsg_parms_t *) p; |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
100 |
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
101 |
if (l && l->errmsg_func) |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
102 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
103 |
if (l->errmsg_func(session, parms->priority, parms->format, parms->ap)) |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
104 |
{
|
105 |
/* we're doing the errmsg plugin api,
|
|
106 |
so we can't trust the errmsg api to emit our error messages
|
|
107 |
so we will emit error messages to stderr */
|
|
108 |
/* TRANSLATORS: The leading word "errmsg" is the name
|
|
109 |
of the plugin api, and so should not be translated. */
|
|
110 |
fprintf(stderr, |
|
111 |
_("errmsg plugin '%s' errmsg_func() failed"), |
|
112 |
(char *)plugin_name(plugin)); |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
113 |
return true; |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
114 |
}
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
115 |
}
|
116 |
return false; |
|
117 |
}
|
|
118 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
119 |
bool errmsg_vprintf (Session *session, int priority, const char *format, va_list ap) |
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
120 |
{
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
121 |
bool foreach_rv; |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
122 |
errmsg_parms_t parms; |
123 |
||
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
124 |
/* marshall the parameters so they will fit into the foreach */
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
125 |
parms.priority= priority; |
126 |
parms.format= format; |
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
127 |
va_copy(parms.ap, ap); |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
128 |
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
129 |
/* call errmsg_iterate
|
130 |
once for each loaded errmsg plugin */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
131 |
foreach_rv= plugin_foreach(session, |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
132 |
errmsg_iterate, |
133 |
DRIZZLE_ERRMSG_PLUGIN, |
|
134 |
(void *) &parms); |
|
135 |
return foreach_rv; |
|
499.2.1
by Mark Atwood
add hooks for errmsg plugin type |
136 |
}
|
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
137 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
138 |
bool errmsg_printf (Session *session, int priority, const char *format, ...) |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
139 |
{
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
140 |
bool rv; |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
141 |
va_list args; |
142 |
va_start(args, format); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
143 |
rv= errmsg_vprintf(session, priority, format, args); |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
144 |
va_end(args); |
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
145 |
return rv; |
499.2.2
by Mark Atwood
va_list handing and other fixes for errmsg plugin |
146 |
}
|