1 /*
2  * Copyright (c) 2015, 2021, Oracle and/or its affiliates.
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
23  * 02110-1301  USA
24  */
25 
26 #include "ngs_common/connection_type.h"
27 
28 
29 using namespace ngs;
30 
convert_type(const enum_vio_type type)31 Connection_type Connection_type_helper::convert_type(const enum_vio_type type)
32 {
33   switch (type)
34   {
35   case VIO_TYPE_SOCKET:
36     return Connection_unixsocket;
37 
38   case VIO_TYPE_SSL:
39     return Connection_tls;
40 
41   case VIO_TYPE_TCPIP:
42     return Connection_tcpip;
43 
44   case VIO_TYPE_NAMEDPIPE:
45     return Connection_namedpipe;
46 
47   default:
48     return Connection_notset;
49   }
50 }
51 
convert_type(const Connection_type type)52 enum_vio_type Connection_type_helper::convert_type(const Connection_type type)
53 {
54   for(int e = FIRST_VIO_TYPE; e <= LAST_VIO_TYPE; ++e)
55   {
56     if (type == convert_type(static_cast<enum_vio_type>(e)))
57       return static_cast<enum_vio_type>(e);
58   }
59 
60   return NO_VIO_TYPE;
61 }
62 
is_secure_type(const Connection_type type)63 bool Connection_type_helper::is_secure_type(const Connection_type type)
64 {
65   switch(type)
66   {
67   case ngs::Connection_tls:
68   case ngs::Connection_unixsocket: // fallthrough
69     return true;
70 
71   default:
72     return false;
73   }
74 }
75