1 /* Copyright (c) 2015, 2021, Oracle and/or its affiliates. 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 #include "sql_bootstrap.h" // MAX_BOOTSTRAP_QUERY_SIZE 27 28 29 /** abstract interface to reading bootstrap commands */ 30 class Command_iterator 31 { 32 public: 33 /** start processing the iterator */ begin(void)34 virtual void begin(void) {} 35 36 /** 37 Get the next query string. 38 39 @param[out] query return the query 40 @param[out] read_error return the read error code 41 @param[out] query_source return the source of the query 42 (if it is from a file or a compiled one). 43 @return one of the READ_BOOTSTRAP 44 */ 45 virtual int next(std::string &query, int *read_error, int *query_source)= 0; 46 47 /** end processing the iterator */ end(void)48 virtual void end(void) {} 49 50 /** The current bootstrap command reader */ 51 static Command_iterator *current_iterator; 52 53 protected: 54 /** needed because of the virtual functions */ ~Command_iterator()55 virtual ~Command_iterator() {} 56 }; 57 58 /** File bootstrap command reader */ 59 class File_command_iterator : public Command_iterator 60 { 61 public: File_command_iterator(fgets_input_t input,fgets_fn_t fgets_fn)62 File_command_iterator(fgets_input_t input, fgets_fn_t fgets_fn) 63 : m_input(input), m_fgets_fn(fgets_fn), is_allocated(false) 64 {} 65 File_command_iterator(const char *file_name); 66 virtual ~File_command_iterator(); 67 68 int next(std::string &query, int *read_error, int *query_source); 69 void end(void); has_file()70 bool has_file() 71 { 72 return m_input != 0; 73 } 74 protected: 75 fgets_input_t m_input; 76 fgets_fn_t m_fgets_fn; 77 bool is_allocated; 78 }; 79 80 81 #endif /* BOOTSTRAP_IMPL_H */ 82