drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
my_access.cc
1/* Copyright (C) 2000 MySQL AB
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 as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#include <config.h>
17
18#include <drizzled/charset.h>
19#include <drizzled/internal/my_sys.h>
20#include <drizzled/internal/m_string.h>
21
22namespace drizzled {
23namespace internal {
24
25/*
26 List of file names that causes problem on windows
27
28 NOTE that one can also not have file names of type CON.TXT
29
30 NOTE: it is important to keep "CLOCK$" on the first place,
31 we skip it in check_if_legal_tablename.
32*/
33static const char *reserved_names[]=
34{
35 "CLOCK$",
36 "CON", "PRN", "AUX", "NUL",
37 "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
38 "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
39 NULL
40};
41
42
43/*
44 Looks up a null-terminated string in a list,
45 case insensitively.
46
47 SYNOPSIS
48 str_list_find()
49 list list of items
50 str item to find
51
52 RETURN
53 0 ok
54 1 reserved file name
55*/
56static int str_list_find(const char **list, const char *str)
57{
58 for (const char** name= list; *name; name++)
59 {
60 if (!my_charset_utf8_general_ci.strcasecmp(*name, str))
61 return 1;
62 }
63 return 0;
64}
65
66
67/*
68 A map for faster reserved_names lookup,
69 helps to avoid loops in many cases.
70 1 - can be the first letter
71 2 - can be the second letter
72 4 - can be the third letter
73*/
74static char reserved_map[256]=
75{
76 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
77 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
78 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* !"#$%&'()*+,-./ */
79 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0123456789:;<=>? */
80 0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
81 3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\‍]^_ */
82 0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* ␁bcdefghijklmno */
83 3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
84 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
85 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
86 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
87 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
89 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
90 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
91 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* ................ */
92};
93
94
95/*
96 Check if a table name may cause problems
97
98 SYNOPSIS
99 check_if_legal_tablename
100 name Table name (without any extensions)
101
102 DESCRIPTION
103 We don't check 'CLOCK$' because dollar sign is encoded as @0024,
104 making table file name 'CLOCK@0024', which is safe.
105 This is why we start lookup from the second element
106 (i.e. &reserver_name[1])
107
108 RETURN
109 0 ok
110 1 reserved file name
111*/
112
113int check_if_legal_tablename(const char *name)
114{
115 return((reserved_map[(unsigned char) name[0]] & 1) &&
116 (reserved_map[(unsigned char) name[1]] & 2) &&
117 (reserved_map[(unsigned char) name[2]] & 4) &&
118 str_list_find(&reserved_names[1], name));
119}
120
121
122} /* namespace internal */
123} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.