1 /* -*- C++ -*- */ 2 /* Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 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 Foundation, 22 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 23 24 #ifndef _PARSE_FILE_H_ 25 #define _PARSE_FILE_H_ 26 27 #include "my_global.h" // uchar 28 #include "sql_string.h" // LEX_STRING 29 #include "sql_alloc.h" 30 31 class THD; 32 33 typedef struct st_mem_root MEM_ROOT; 34 35 #define PARSE_FILE_TIMESTAMPLENGTH 19 36 37 enum file_opt_type { 38 FILE_OPTIONS_STRING, /**< String (LEX_STRING) */ 39 FILE_OPTIONS_ESTRING, /**< Escaped string (LEX_STRING) */ 40 FILE_OPTIONS_ULONGLONG, /**< ulonglong parameter (ulonglong) */ 41 FILE_OPTIONS_TIMESTAMP, /**< timestamp (LEX_STRING have to be 42 allocated with length 20 (19+1) */ 43 FILE_OPTIONS_STRLIST, /**< list of escaped strings 44 (List<LEX_STRING>) */ 45 FILE_OPTIONS_ULLLIST /**< list of ulonglong values 46 (List<ulonglong>) */ 47 }; 48 49 struct File_option 50 { 51 LEX_STRING name; /**< Name of the option */ 52 size_t offset; /**< offset to base address of value */ 53 file_opt_type type; /**< Option type */ 54 }; 55 56 57 /** 58 This hook used to catch no longer supported keys and process them for 59 backward compatibility. 60 */ 61 62 class Unknown_key_hook 63 { 64 public: Unknown_key_hook()65 Unknown_key_hook() {} /* Remove gcc warning */ ~Unknown_key_hook()66 virtual ~Unknown_key_hook() {} /* Remove gcc warning */ 67 virtual bool process_unknown_string(const char *&unknown_key, uchar* base, 68 MEM_ROOT *mem_root, const char *end)= 0; 69 }; 70 71 72 /** Dummy hook for parsers which do not need hook for unknown keys. */ 73 74 class File_parser_dummy_hook: public Unknown_key_hook 75 { 76 public: File_parser_dummy_hook()77 File_parser_dummy_hook() {} /* Remove gcc warning */ 78 virtual bool process_unknown_string(const char *&unknown_key, uchar* base, 79 MEM_ROOT *mem_root, const char *end); 80 }; 81 82 extern File_parser_dummy_hook file_parser_dummy_hook; 83 84 bool get_file_options_ulllist(const char *&ptr, const char *end, 85 const char *line, uchar* base, 86 File_option *parameter, 87 MEM_ROOT *mem_root); 88 89 const char * 90 parse_escaped_string(const char *ptr, const char *end, MEM_ROOT *mem_root, 91 LEX_STRING *str); 92 93 class File_parser; 94 File_parser *sql_parse_prepare(const LEX_STRING *file_name, 95 MEM_ROOT *mem_root, bool bad_format_errors); 96 97 my_bool 98 sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, 99 const LEX_STRING *type, 100 uchar* base, File_option *parameters); 101 my_bool rename_in_schema_file(THD *thd, 102 const char *schema, const char *old_name, 103 const char *new_db, const char *new_name); 104 105 class File_parser: public Sql_alloc 106 { 107 const char *start, *end; 108 LEX_STRING file_type; 109 my_bool content_ok; 110 public: File_parser()111 File_parser() :start(0), end(0), content_ok(0) 112 { file_type.str= 0; file_type.length= 0; } 113 ok()114 my_bool ok() { return content_ok; } type()115 const LEX_STRING *type() const { return &file_type; } 116 my_bool parse(uchar* base, MEM_ROOT *mem_root, 117 struct File_option *parameters, uint required, 118 Unknown_key_hook *hook) const; 119 120 friend File_parser *sql_parse_prepare(const LEX_STRING *file_name, 121 MEM_ROOT *mem_root, 122 bool bad_format_errors); 123 }; 124 #endif /* _PARSE_FILE_H_ */ 125