~drizzle-trunk/drizzle/development

1 by brian
clean slate
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
994.2.4 by Monty Taylor
Blast. Fixed some make distcheck issues.
16
#include "mysys/mysys_priv.h"
212.5.18 by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype.
17
#include <mystrings/m_string.h>
1 by brian
clean slate
18
19
/*
20
  List of file names that causes problem on windows
21
22
  NOTE that one can also not have file names of type CON.TXT
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
23
1 by brian
clean slate
24
  NOTE: it is important to keep "CLOCK$" on the first place,
25
  we skip it in check_if_legal_tablename.
26
*/
27
static const char *reserved_names[]=
28
{
29
  "CLOCK$",
30
  "CON", "PRN", "AUX", "NUL",
31
  "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
32
  "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
461 by Monty Taylor
Removed NullS. bu-bye.
33
  NULL
1 by brian
clean slate
34
};
35
36
37
/*
38
  Looks up a null-terminated string in a list,
39
  case insensitively.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
40
1 by brian
clean slate
41
  SYNOPSIS
42
    str_list_find()
43
    list        list of items
44
    str         item to find
45
46
  RETURN
47
    0  ok
48
    1  reserved file name
49
*/
50
static int str_list_find(const char **list, const char *str)
51
{
52
  const char **name;
53
  for (name= list; *name; name++)
54
  {
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
55
    if (!my_strcasecmp(&my_charset_utf8_general_ci, *name, str))
1 by brian
clean slate
56
      return 1;
57
  }
58
  return 0;
59
}
60
61
62
/*
63
  A map for faster reserved_names lookup,
64
  helps to avoid loops in many cases.
65
  1 - can be the first letter
66
  2 - can be the second letter
67
  4 - can be the third letter
68
*/
69
static char reserved_map[256]=
70
{
71
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
72
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
73
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*  !"#$%&'()*+,-./ */
74
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0123456789:;<=>? */
75
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
76
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\]^_ */
77
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* bcdefghijklmno */
78
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
79
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
80
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
81
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
82
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
83
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
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
};
88
89
90
/*
91
  Check if a table name may cause problems
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
92
1 by brian
clean slate
93
  SYNOPSIS
94
    check_if_legal_tablename
95
    name 	Table name (without any extensions)
96
97
  DESCRIPTION
98
    We don't check 'CLOCK$' because dollar sign is encoded as @0024,
99
    making table file name 'CLOCK@0024', which is safe.
100
    This is why we start lookup from the second element
101
    (i.e. &reserver_name[1])
102
103
  RETURN
104
    0  ok
105
    1  reserved file name
106
*/
107
108
int check_if_legal_tablename(const char *name)
109
{
481 by Brian Aker
Remove all of uchar.
110
  return((reserved_map[(unsigned char) name[0]] & 1) &&
111
              (reserved_map[(unsigned char) name[1]] & 2) &&
112
              (reserved_map[(unsigned char) name[2]] & 4) &&
1 by brian
clean slate
113
              str_list_find(&reserved_names[1], name));
114
}
115
116