1 /*
2  Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation.  The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23  */
24 
25 /* CharsetMapImpl
26  *
27  * The private singleton implementation behind the public CharsetMap class
28  *
29  */
30 
31 #include "NdbMutex.h"
32 
33 #define CHARSET_MAP_HASH_TABLE_SIZE 256
34 
35 class MapTableItem
36 {
37 public:
MapTableItem()38     MapTableItem() : name(0), value(0), next(0) {};
39     const char *name;
40     const char *value;
41     MapTableItem *next;
42 };
43 
44 
45 class CharsetMapImpl : public NdbLockable
46 {
47 public:
CharsetMapImpl()48     CharsetMapImpl() : NdbLockable() , ready(0) , collisions(0) {};
49 
50     /** getName() returns a character set name that in most cases
51      will be a preferred name from
52      http://www.iana.org/assignments/character-sets and will be recognized
53      and usable by Java (e.g. java.nio, java.io, and java.lang).
54      However it may return "binary" if a column is BLOB / BINARY / VARBINARY,
55      or it may return the name of an uncommon, rarely-used MySQL character set
56      such as "keybcs2" or "dec8".
57      */
58     const char * getName(int);
59 
60     const char * mysql_charset_name[256];
61 
62     int UTF16Charset;
63     int UTF8Charset;
64 
65     void build_map();
66     int ready;
67     int collisions;
68     int n_items;
69 
70 private:
71     void put(const char *, const char *);
72     const char * get(const char *) const;
73     int hash(const char *) const;
74     MapTableItem map[CHARSET_MAP_HASH_TABLE_SIZE];
75 };
76