Drizzled Public API Documentation

my_access.cc
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 
00018 #include <drizzled/charset.h>
00019 #include <drizzled/internal/my_sys.h>
00020 #include <drizzled/internal/m_string.h>
00021 
00022 namespace drizzled {
00023 namespace internal {
00024 
00025 /*
00026   List of file names that causes problem on windows
00027 
00028   NOTE that one can also not have file names of type CON.TXT
00029 
00030   NOTE: it is important to keep "CLOCK$" on the first place,
00031   we skip it in check_if_legal_tablename.
00032 */
00033 static const char *reserved_names[]=
00034 {
00035   "CLOCK$",
00036   "CON", "PRN", "AUX", "NUL",
00037   "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
00038   "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
00039   NULL
00040 };
00041 
00042 
00043 /*
00044   Looks up a null-terminated string in a list,
00045   case insensitively.
00046 
00047   SYNOPSIS
00048     str_list_find()
00049     list        list of items
00050     str         item to find
00051 
00052   RETURN
00053     0  ok
00054     1  reserved file name
00055 */
00056 static int str_list_find(const char **list, const char *str)
00057 {
00058   for (const char** name= list; *name; name++)
00059   {
00060     if (!my_charset_utf8_general_ci.strcasecmp(*name, str))
00061       return 1;
00062   }
00063   return 0;
00064 }
00065 
00066 
00067 /*
00068   A map for faster reserved_names lookup,
00069   helps to avoid loops in many cases.
00070   1 - can be the first letter
00071   2 - can be the second letter
00072   4 - can be the third letter
00073 */
00074 static char reserved_map[256]=
00075 {
00076   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00077   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00078   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*  !"#$%&'()*+,-./ */
00079   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0123456789:;<=>? */
00080   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
00081   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\]^_ */
00082   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* bcdefghijklmno */
00083   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
00084   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00085   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00086   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00087   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00088   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00089   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00090   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00091   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  /* ................ */
00092 };
00093 
00094 
00095 /*
00096   Check if a table name may cause problems
00097 
00098   SYNOPSIS
00099     check_if_legal_tablename
00100     name  Table name (without any extensions)
00101 
00102   DESCRIPTION
00103     We don't check 'CLOCK$' because dollar sign is encoded as @0024,
00104     making table file name 'CLOCK@0024', which is safe.
00105     This is why we start lookup from the second element
00106     (i.e. &reserver_name[1])
00107 
00108   RETURN
00109     0  ok
00110     1  reserved file name
00111 */
00112 
00113 int check_if_legal_tablename(const char *name)
00114 {
00115   return((reserved_map[(unsigned char) name[0]] & 1) &&
00116               (reserved_map[(unsigned char) name[1]] & 2) &&
00117               (reserved_map[(unsigned char) name[2]] & 4) &&
00118               str_list_find(&reserved_names[1], name));
00119 }
00120 
00121 
00122 } /* namespace internal */
00123 } /* namespace drizzled */