1 /* -*- C++ -*- */ 2 /* Copyright (c) 2004, 2021, Oracle and/or its affiliates. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 23 24 #ifndef _PARSE_FILE_H_ 25 #define _PARSE_FILE_H_ 26 27 #include "my_global.h" // uchar 28 #include "mysql/mysql_lex_string.h" // LEX_STRING 29 #include "sql_alloc.h" 30 31 class THD; 32 33 typedef struct st_mem_root MEM_ROOT; 34 typedef struct st_mysql_lex_string LEX_STRING; 35 36 #define PARSE_FILE_TIMESTAMPLENGTH 19 37 38 enum file_opt_type { 39 FILE_OPTIONS_STRING, /**< String (LEX_STRING) */ 40 FILE_OPTIONS_ESTRING, /**< Escaped string (LEX_STRING) */ 41 FILE_OPTIONS_ULONGLONG, /**< ulonglong parameter (ulonglong) */ 42 FILE_OPTIONS_TIMESTAMP, /**< timestamp (LEX_STRING have to be 43 allocated with length 20 (19+1) */ 44 FILE_OPTIONS_STRLIST, /**< list of escaped strings 45 (List<LEX_STRING>) */ 46 FILE_OPTIONS_ULLLIST /**< list of ulonglong values 47 (List<ulonglong>) */ 48 }; 49 50 struct File_option 51 { 52 LEX_STRING name; /**< Name of the option */ 53 size_t offset; /**< offset to base address of value */ 54 file_opt_type type; /**< Option type */ 55 }; 56 57 58 /** 59 This hook used to catch no longer supported keys and process them for 60 backward compatibility. 61 */ 62 63 class Unknown_key_hook 64 { 65 public: Unknown_key_hook()66 Unknown_key_hook() {} /* Remove gcc warning */ ~Unknown_key_hook()67 virtual ~Unknown_key_hook() {} /* Remove gcc warning */ 68 virtual bool process_unknown_string(const char *&unknown_key, uchar* base, 69 MEM_ROOT *mem_root, const char *end)= 0; 70 }; 71 72 73 /** Dummy hook for parsers which do not need hook for unknown keys. */ 74 75 class File_parser_dummy_hook: public Unknown_key_hook 76 { 77 public: File_parser_dummy_hook()78 File_parser_dummy_hook() {} /* Remove gcc warning */ 79 virtual bool process_unknown_string(const char *&unknown_key, uchar* base, 80 MEM_ROOT *mem_root, const char *end); 81 }; 82 83 extern File_parser_dummy_hook file_parser_dummy_hook; 84 85 bool get_file_options_ulllist(const char *&ptr, const char *end, 86 const char *line, uchar* base, 87 File_option *parameter, 88 MEM_ROOT *mem_root); 89 90 const char * 91 parse_escaped_string(const char *ptr, const char *end, MEM_ROOT *mem_root, 92 LEX_STRING *str); 93 94 class File_parser; 95 File_parser *sql_parse_prepare(const LEX_STRING *file_name, 96 MEM_ROOT *mem_root, bool bad_format_errors); 97 98 my_bool 99 sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, 100 const LEX_STRING *type, 101 uchar* base, File_option *parameters); 102 my_bool rename_in_schema_file(THD *thd, 103 const char *schema, const char *old_name, 104 const char *new_db, const char *new_name); 105 106 class File_parser: public Sql_alloc 107 { 108 const char *start, *end; 109 LEX_STRING file_type; 110 my_bool content_ok; 111 public: File_parser()112 File_parser() :start(0), end(0), content_ok(0) 113 { file_type.str= 0; file_type.length= 0; } 114 ok()115 my_bool ok() { return content_ok; } type()116 const LEX_STRING *type() const { return &file_type; } 117 my_bool parse(uchar* base, MEM_ROOT *mem_root, 118 struct File_option *parameters, uint required, 119 Unknown_key_hook *hook) const; 120 121 friend File_parser *sql_parse_prepare(const LEX_STRING *file_name, 122 MEM_ROOT *mem_root, 123 bool bad_format_errors); 124 }; 125 #endif /* _PARSE_FILE_H_ */ 126