1 /* Copyright (c) 2015, 2019, 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, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef BOOTSTRAP_IMPL_H 24 #define BOOTSTRAP_IMPL_H 1 25 #include <string> 26 27 #include "sql/sql_bootstrap.h" // MAX_BOOTSTRAP_QUERY_SIZE 28 29 namespace bootstrap { 30 31 /** Abstract interface to reading bootstrap commands */ 32 class Command_iterator { 33 public: 34 typedef void (*log_function_t)(const char *message); 35 36 /** 37 start processing the iterator 38 @retval false Success 39 @retval true failure 40 */ begin(void)41 virtual bool begin(void) { return false; } 42 43 /** 44 Get the next query string. 45 46 @param[out] query return the query 47 @return one of the READ_BOOTSTRAP 48 */ 49 virtual int next(std::string &query) = 0; 50 51 virtual void report_error_details(log_function_t log) = 0; 52 53 /** End processing the iterator */ end(void)54 virtual void end(void) {} 55 56 protected: Command_iterator()57 Command_iterator() {} ~Command_iterator()58 ~Command_iterator() {} 59 }; 60 61 /** File bootstrap command reader */ 62 class File_command_iterator : public Command_iterator { 63 public: File_command_iterator(const char * file_name,MYSQL_FILE * input,fgets_fn_t fgets_fn)64 File_command_iterator(const char *file_name, MYSQL_FILE *input, 65 fgets_fn_t fgets_fn) 66 : m_input(input), m_fgets_fn(fgets_fn) { 67 m_parser_state.init(file_name); 68 } 69 virtual ~File_command_iterator(); 70 71 int next(std::string &query) override; 72 73 void report_error_details(log_function_t log) override; 74 75 protected: 76 bootstrap_parser_state m_parser_state; 77 MYSQL_FILE *m_input; 78 fgets_fn_t m_fgets_fn; 79 }; 80 81 } // namespace bootstrap 82 83 #endif /* BOOTSTRAP_IMPL_H */ 84