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