~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2003 MySQL AB
2
   
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
   
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
   
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
#ifndef RPL_FILTER_H
17
#define RPL_FILTER_H
18
19
#include "mysql.h"
20
21
typedef struct st_table_rule_ent
22
{
23
  char* db;
24
  char* tbl_name;
25
  uint key_len;
26
} TABLE_RULE_ENT;
27
28
/*
29
  Rpl_filter
30
31
  Inclusion and exclusion rules of tables and databases.
32
  Also handles rewrites of db.
33
  Used for replication and binlogging.
34
 */
35
class Rpl_filter 
36
{
37
public:
38
  Rpl_filter();
39
  ~Rpl_filter();
40
  Rpl_filter(Rpl_filter const&);
41
  Rpl_filter& operator=(Rpl_filter const&);
42
 
43
  /* Checks - returns true if ok to replicate/log */
44
45
  bool tables_ok(const char* db, TABLE_LIST* tables);
46
  bool db_ok(const char* db);
47
  bool db_ok_with_wild_table(const char *db);
48
49
  bool is_on();
50
51
  /* Setters - add filtering rules */
52
53
  int add_do_table(const char* table_spec);
54
  int add_ignore_table(const char* table_spec);
55
56
  int add_wild_do_table(const char* table_spec);
57
  int add_wild_ignore_table(const char* table_spec);
58
59
  void add_do_db(const char* db_spec);
60
  void add_ignore_db(const char* db_spec);
61
62
  void add_db_rewrite(const char* from_db, const char* to_db);
63
64
  /* Getters - to get information about current rules */
65
66
  void get_do_table(String* str);
67
  void get_ignore_table(String* str);
68
69
  void get_wild_do_table(String* str);
70
  void get_wild_ignore_table(String* str);
71
72
  const char* get_rewrite_db(const char* db, size_t *new_len);
73
74
  I_List<i_string>* get_do_db();
75
  I_List<i_string>* get_ignore_db();
76
77
private:
78
  bool table_rules_on;
79
80
  void init_table_rule_hash(HASH* h, bool* h_inited);
81
  void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
82
83
  int add_table_rule(HASH* h, const char* table_spec);
84
  int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
85
86
  void free_string_array(DYNAMIC_ARRAY *a);
87
88
  void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited);
89
  void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a,
90
                                           bool inited);
91
  TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len);
92
93
  /*
94
    Those 4 structures below are uninitialized memory unless the
95
    corresponding *_inited variables are "true".
96
  */
97
  HASH do_table;
98
  HASH ignore_table;
99
  DYNAMIC_ARRAY wild_do_table;
100
  DYNAMIC_ARRAY wild_ignore_table;
101
102
  bool do_table_inited;
103
  bool ignore_table_inited;
104
  bool wild_do_table_inited;
105
  bool wild_ignore_table_inited;
106
107
  I_List<i_string> do_db;
108
  I_List<i_string> ignore_db;
109
110
  I_List<i_string_pair> rewrite_db;
111
};
112
113
extern Rpl_filter *rpl_filter;
114
extern Rpl_filter *binlog_filter;
115
116
#endif // RPL_FILTER_H