~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/internal/my_access.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "config.h"
 
17
 
 
18
#include "drizzled/internal/my_sys.h"
 
19
#include "drizzled/internal/m_string.h"
 
20
 
 
21
namespace drizzled
 
22
{
 
23
namespace internal
 
24
{
 
25
 
 
26
/*
 
27
  List of file names that causes problem on windows
 
28
 
 
29
  NOTE that one can also not have file names of type CON.TXT
 
30
 
 
31
  NOTE: it is important to keep "CLOCK$" on the first place,
 
32
  we skip it in check_if_legal_tablename.
 
33
*/
 
34
static const char *reserved_names[]=
 
35
{
 
36
  "CLOCK$",
 
37
  "CON", "PRN", "AUX", "NUL",
 
38
  "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
 
39
  "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
 
40
  NULL
 
41
};
 
42
 
 
43
 
 
44
/*
 
45
  Looks up a null-terminated string in a list,
 
46
  case insensitively.
 
47
 
 
48
  SYNOPSIS
 
49
    str_list_find()
 
50
    list        list of items
 
51
    str         item to find
 
52
 
 
53
  RETURN
 
54
    0  ok
 
55
    1  reserved file name
 
56
*/
 
57
static int str_list_find(const char **list, const char *str)
 
58
{
 
59
  const char **name;
 
60
  for (name= list; *name; name++)
 
61
  {
 
62
    if (!my_strcasecmp(&my_charset_utf8_general_ci, *name, str))
 
63
      return 1;
 
64
  }
 
65
  return 0;
 
66
}
 
67
 
 
68
 
 
69
/*
 
70
  A map for faster reserved_names lookup,
 
71
  helps to avoid loops in many cases.
 
72
  1 - can be the first letter
 
73
  2 - can be the second letter
 
74
  4 - can be the third letter
 
75
*/
 
76
static char reserved_map[256]=
 
77
{
 
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, /* ................ */
 
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, /* 0123456789:;<=>? */
 
82
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
 
83
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\]^_ */
 
84
  0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* bcdefghijklmno */
 
85
  3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
 
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
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
 
93
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  /* ................ */
 
94
};
 
95
 
 
96
 
 
97
/*
 
98
  Check if a table name may cause problems
 
99
 
 
100
  SYNOPSIS
 
101
    check_if_legal_tablename
 
102
    name        Table name (without any extensions)
 
103
 
 
104
  DESCRIPTION
 
105
    We don't check 'CLOCK$' because dollar sign is encoded as @0024,
 
106
    making table file name 'CLOCK@0024', which is safe.
 
107
    This is why we start lookup from the second element
 
108
    (i.e. &reserver_name[1])
 
109
 
 
110
  RETURN
 
111
    0  ok
 
112
    1  reserved file name
 
113
*/
 
114
 
 
115
int check_if_legal_tablename(const char *name)
 
116
{
 
117
  return((reserved_map[(unsigned char) name[0]] & 1) &&
 
118
              (reserved_map[(unsigned char) name[1]] & 2) &&
 
119
              (reserved_map[(unsigned char) name[2]] & 4) &&
 
120
              str_list_find(&reserved_names[1], name));
 
121
}
 
122
 
 
123
 
 
124
} /* namespace internal */
 
125
} /* namespace drizzled */