~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
16
#include "mysys_priv.h"
17
#include <m_string.h>
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
23
  
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",
33
  NullS
34
};
35
36
#define MAX_RESERVED_NAME_LENGTH 6
37
38
39
/*
40
  Looks up a null-terminated string in a list,
41
  case insensitively.
42
 
43
  SYNOPSIS
44
    str_list_find()
45
    list        list of items
46
    str         item to find
47
48
  RETURN
49
    0  ok
50
    1  reserved file name
51
*/
52
static int str_list_find(const char **list, const char *str)
53
{
54
  const char **name;
55
  for (name= list; *name; name++)
56
  {
57
    if (!my_strcasecmp(&my_charset_latin1, *name, str))
58
      return 1;
59
  }
60
  return 0;
61
}
62
63
64
/*
65
  A map for faster reserved_names lookup,
66
  helps to avoid loops in many cases.
67
  1 - can be the first letter
68
  2 - can be the second letter
69
  4 - can be the third letter
70
*/
71
static char reserved_map[256]=
72
{
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, /* ................ */
75
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*  !"#$%&'()*+,-./ */
76
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0123456789:;<=>? */
77
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
78
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\]^_ */
79
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* bcdefghijklmno */
80
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
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
  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
};
90
91
92
/*
93
  Check if a table name may cause problems
94
 
95
  SYNOPSIS
96
    check_if_legal_tablename
97
    name 	Table name (without any extensions)
98
99
  DESCRIPTION
100
    We don't check 'CLOCK$' because dollar sign is encoded as @0024,
101
    making table file name 'CLOCK@0024', which is safe.
102
    This is why we start lookup from the second element
103
    (i.e. &reserver_name[1])
104
105
  RETURN
106
    0  ok
107
    1  reserved file name
108
*/
109
110
int check_if_legal_tablename(const char *name)
111
{
112
  DBUG_ENTER("check_if_legal_tablename");
113
  DBUG_RETURN((reserved_map[(uchar) name[0]] & 1) &&
114
              (reserved_map[(uchar) name[1]] & 2) &&
115
              (reserved_map[(uchar) name[2]] & 4) &&
116
              str_list_find(&reserved_names[1], name));
117
}
118
119