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/internal/my_sys.h>
00019 #include <drizzled/internal/m_string.h>
00020 
00021 namespace drizzled
00022 {
00023 namespace internal
00024 {
00025 
00026 /*
00027   List of file names that causes problem on windows
00028 
00029   NOTE that one can also not have file names of type CON.TXT
00030 
00031   NOTE: it is important to keep "CLOCK$" on the first place,
00032   we skip it in check_if_legal_tablename.
00033 */
00034 static const char *reserved_names[]=
00035 {
00036   "CLOCK$",
00037   "CON", "PRN", "AUX", "NUL",
00038   "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
00039   "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
00040   NULL
00041 };
00042 
00043 
00044 /*
00045   Looks up a null-terminated string in a list,
00046   case insensitively.
00047 
00048   SYNOPSIS
00049     str_list_find()
00050     list        list of items
00051     str         item to find
00052 
00053   RETURN
00054     0  ok
00055     1  reserved file name
00056 */
00057 static int str_list_find(const char **list, const char *str)
00058 {
00059   const char **name;
00060   for (name= list; *name; name++)
00061   {
00062     if (!my_strcasecmp(&my_charset_utf8_general_ci, *name, str))
00063       return 1;
00064   }
00065   return 0;
00066 }
00067 
00068 
00069 /*
00070   A map for faster reserved_names lookup,
00071   helps to avoid loops in many cases.
00072   1 - can be the first letter
00073   2 - can be the second letter
00074   4 - can be the third letter
00075 */
00076 static char reserved_map[256]=
00077 {
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, /* ................ */
00080   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /*  !"#$%&'()*+,-./ */
00081   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0123456789:;<=>? */
00082   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* @ABCDEFGHIJKLMNO */
00083   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* PQRSTUVWXYZ[\]^_ */
00084   0,1,0,1,0,0,0,0,0,0,0,0,7,4,5,2, /* bcdefghijklmno */
00085   3,0,2,0,4,2,0,0,4,0,0,0,0,0,0,0, /* pqrstuvwxyz{|}~. */
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   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* ................ */
00093   0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  /* ................ */
00094 };
00095 
00096 
00097 /*
00098   Check if a table name may cause problems
00099 
00100   SYNOPSIS
00101     check_if_legal_tablename
00102     name  Table name (without any extensions)
00103 
00104   DESCRIPTION
00105     We don't check 'CLOCK$' because dollar sign is encoded as @0024,
00106     making table file name 'CLOCK@0024', which is safe.
00107     This is why we start lookup from the second element
00108     (i.e. &reserver_name[1])
00109 
00110   RETURN
00111     0  ok
00112     1  reserved file name
00113 */
00114 
00115 int check_if_legal_tablename(const char *name)
00116 {
00117   return((reserved_map[(unsigned char) name[0]] & 1) &&
00118               (reserved_map[(unsigned char) name[1]] & 2) &&
00119               (reserved_map[(unsigned char) name[2]] & 4) &&
00120               str_list_find(&reserved_names[1], name));
00121 }
00122 
00123 
00124 } /* namespace internal */
00125 } /* namespace drizzled */