1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 15 16 #ifndef RPL_FILTER_H 17 #define RPL_FILTER_H 18 19 #include "mysql.h" 20 #include "mysqld.h" 21 #include "sql_list.h" /* I_List */ 22 #include "hash.h" /* HASH */ 23 24 class String; 25 struct TABLE_LIST; 26 typedef struct st_dynamic_array DYNAMIC_ARRAY; 27 28 typedef struct st_table_rule_ent 29 { 30 char* db; 31 char* tbl_name; 32 uint key_len; 33 } TABLE_RULE_ENT; 34 35 /* 36 Rpl_filter 37 38 Inclusion and exclusion rules of tables and databases. 39 Also handles rewrites of db. 40 Used for replication and binlogging. 41 */ 42 class Rpl_filter 43 { 44 public: 45 Rpl_filter(); 46 ~Rpl_filter(); 47 Rpl_filter(Rpl_filter const&); 48 Rpl_filter& operator=(Rpl_filter const&); 49 50 /* Checks - returns true if ok to replicate/log */ 51 52 #ifndef MYSQL_CLIENT 53 bool tables_ok(const char* db, TABLE_LIST *tables); 54 #endif 55 bool db_ok(const char* db); 56 bool db_ok_with_wild_table(const char *db); 57 58 bool is_on(); 59 60 /* Setters - add filtering rules */ 61 62 int add_do_table(const char* table_spec); 63 int add_ignore_table(const char* table_spec); 64 65 int set_do_table(const char* table_spec); 66 int set_ignore_table(const char* table_spec); 67 68 int add_wild_do_table(const char* table_spec); 69 int add_wild_ignore_table(const char* table_spec); 70 71 int set_wild_do_table(const char* table_spec); 72 int set_wild_ignore_table(const char* table_spec); 73 74 int add_do_db(const char* db_spec); 75 int add_ignore_db(const char* db_spec); 76 77 int set_do_db(const char* db_spec); 78 int set_ignore_db(const char* db_spec); 79 80 void set_parallel_mode(enum_slave_parallel_mode mode) 81 { 82 parallel_mode= mode; 83 } 84 /* Return given parallel mode or if one is not given, the default mode */ 85 enum_slave_parallel_mode get_parallel_mode() 86 { 87 return parallel_mode; 88 } 89 90 void add_db_rewrite(const char* from_db, const char* to_db); 91 92 /* Getters - to get information about current rules */ 93 94 void get_do_table(String* str); 95 void get_ignore_table(String* str); 96 97 void get_wild_do_table(String* str); 98 void get_wild_ignore_table(String* str); 99 100 bool rewrite_db_is_empty(); 101 const char* get_rewrite_db(const char* db, size_t *new_len); 102 void copy_rewrite_db(Rpl_filter *from); 103 104 I_List<i_string>* get_do_db(); 105 I_List<i_string>* get_ignore_db(); 106 107 void get_do_db(String* str); 108 void get_ignore_db(String* str); 109 110 private: 111 112 void init_table_rule_hash(HASH* h, bool* h_inited); 113 void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited); 114 115 int add_table_rule(HASH* h, const char* table_spec); 116 int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec); 117 118 typedef int (Rpl_filter::*Add_filter)(char const*); 119 120 int parse_filter_rule(const char* spec, Add_filter func); 121 122 void free_string_array(DYNAMIC_ARRAY *a); 123 void free_string_list(I_List<i_string> *l); 124 125 void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited); 126 void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a, 127 bool inited); 128 void db_rule_ent_list_to_str(String* s, I_List<i_string>* l); 129 TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len); 130 131 int add_string_list(I_List<i_string> *list, const char* spec); 132 133 /* 134 Those 4 structures below are uninitialized memory unless the 135 corresponding *_inited variables are "true". 136 */ 137 HASH do_table; 138 HASH ignore_table; 139 DYNAMIC_ARRAY wild_do_table; 140 DYNAMIC_ARRAY wild_ignore_table; 141 enum_slave_parallel_mode parallel_mode; 142 143 bool table_rules_on; 144 bool do_table_inited; 145 bool ignore_table_inited; 146 bool wild_do_table_inited; 147 bool wild_ignore_table_inited; 148 149 I_List<i_string> do_db; 150 I_List<i_string> ignore_db; 151 152 I_List<i_string_pair> rewrite_db; 153 }; 154 155 extern Rpl_filter *global_rpl_filter; 156 extern Rpl_filter *binlog_filter; 157 158 #endif // RPL_FILTER_H 159