00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #ifndef RPL_FILTER_H 00018 #define RPL_FILTER_H 00019 00020 #include "mysql.h" 00021 00022 typedef struct st_table_rule_ent 00023 { 00024 char* db; 00025 char* tbl_name; 00026 uint key_len; 00027 } TABLE_RULE_ENT; 00028 00029 /* 00030 Rpl_filter 00031 00032 Inclusion and exclusion rules of tables and databases. 00033 Also handles rewrites of db. 00034 Used for replication and binlogging. 00035 */ 00036 class Rpl_filter 00037 { 00038 public: 00039 Rpl_filter(); 00040 ~Rpl_filter(); 00041 Rpl_filter(Rpl_filter const&); 00042 Rpl_filter& operator=(Rpl_filter const&); 00043 00044 /* Checks - returns true if ok to replicate/log */ 00045 00046 bool tables_ok(const char* db, TABLE_LIST* tables); 00047 bool db_ok(const char* db); 00048 bool db_ok_with_wild_table(const char *db); 00049 00050 bool is_on(); 00051 00052 /* Setters - add filtering rules */ 00053 00054 int add_do_table(const char* table_spec); 00055 int add_ignore_table(const char* table_spec); 00056 00057 int add_wild_do_table(const char* table_spec); 00058 int add_wild_ignore_table(const char* table_spec); 00059 00060 void add_do_db(const char* db_spec); 00061 void add_ignore_db(const char* db_spec); 00062 00063 void add_db_rewrite(const char* from_db, const char* to_db); 00064 00065 /* Getters - to get information about current rules */ 00066 00067 void get_do_table(String* str); 00068 void get_ignore_table(String* str); 00069 00070 void get_wild_do_table(String* str); 00071 void get_wild_ignore_table(String* str); 00072 00073 const char* get_rewrite_db(const char* db, uint *new_len); 00074 00075 I_List<i_string>* get_do_db(); 00076 I_List<i_string>* get_ignore_db(); 00077 00078 private: 00079 bool table_rules_on; 00080 00081 void init_table_rule_hash(HASH* h, bool* h_inited); 00082 void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited); 00083 00084 int add_table_rule(HASH* h, const char* table_spec); 00085 int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec); 00086 00087 void free_string_array(DYNAMIC_ARRAY *a); 00088 00089 void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited); 00090 void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a, 00091 bool inited); 00092 TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len); 00093 00094 /* 00095 Those 4 structures below are uninitialized memory unless the 00096 corresponding *_inited variables are "true". 00097 */ 00098 HASH do_table; 00099 HASH ignore_table; 00100 DYNAMIC_ARRAY wild_do_table; 00101 DYNAMIC_ARRAY wild_ignore_table; 00102 00103 bool do_table_inited; 00104 bool ignore_table_inited; 00105 bool wild_do_table_inited; 00106 bool wild_ignore_table_inited; 00107 00108 I_List<i_string> do_db; 00109 I_List<i_string> ignore_db; 00110 00111 I_List<i_string_pair> rewrite_db; 00112 }; 00113 00114 extern Rpl_filter *rpl_filter; 00115 extern Rpl_filter *binlog_filter; 00116 00117 #endif // RPL_FILTER_H
1.4.7

