~drizzle-trunk/drizzle/development

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
#include <drizzled/server_includes.h>
#include <drizzled/logging.h>

int logging_initializer(st_plugin_int *plugin)
{
  logging_t *p;

  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
	  __func__, plugin->name.str, plugin->plugin_dl->dl.str);

  p= (logging_t *) malloc(sizeof(logging_t));
  if (p == NULL) return 1;
  memset(p, 0, sizeof(logging_t));

  plugin->data= (void *)p;

  if (plugin->plugin->init)
  {
    if (plugin->plugin->init((void *)p))
    {
      sql_print_error("Logging plugin '%s' init function returned error.",
                      plugin->name.str);
      goto err;
    }
  }
  return 0;

err:
  free(p);
  return 1;
}

int logging_finalizer(st_plugin_int *plugin)
{ 
  logging_t *p = (logging_t *) plugin->data;

  fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
	  __func__, plugin->name.str, plugin->plugin_dl->dl.str);

  if (plugin->plugin->deinit)
  {
    if (plugin->plugin->deinit((void *)p))
    {
      sql_print_error("Logging plugin '%s' deinit function returned error.",
                      plugin->name.str);
    }
  }

  if (p) free(p);

  return 0;
}

static bool logging_pre_iterate (THD *thd, plugin_ref plugin,
				 void *stuff __attribute__ ((__unused__)))
{
  logging_t *l= plugin_data(plugin, logging_t *);

  if (l && l->logging_pre)
  {
    if (l->logging_pre(thd))
      return true;
  }
  return false;
}

void logging_pre_do (THD *thd)
{
  if (plugin_foreach(thd, logging_pre_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
  {
    sql_print_error("Logging plugin pre had an error.");
  }
  return;
}

static bool logging_post_iterate (THD *thd, plugin_ref plugin, 
				  void *stuff __attribute__ ((__unused__)))
{
  logging_t *l= plugin_data(plugin, logging_t *);

  if (l && l->logging_post)
  {
    if (l->logging_post(thd))
      return true;
  }
  return false;
}

void logging_post_do (THD *thd)
{
  if (plugin_foreach(thd, logging_post_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
  {
    sql_print_error("Logging plugin post had an error.");
  }
  return;
}