MySQL 9.1.0
Source Code Documentation
item_inetfunc.h
Go to the documentation of this file.
1#ifndef ITEM_INETFUNC_INCLUDED
2#define ITEM_INETFUNC_INCLUDED
3
4/* Copyright (c) 2011, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include "my_inttypes.h"
29#include "sql/item_cmpfunc.h" // Item_bool_func
30#include "sql/item_func.h"
31#include "sql/item_strfunc.h" // Item_str_func
32#include "sql/parse_location.h" // POS
33
34class Item;
35class String;
36class THD;
37
38/*************************************************************************
39 Item_func_inet_aton implements INET_ATON() SQL-function.
40*************************************************************************/
41
43 public:
44 inline Item_func_inet_aton(const POS &pos, Item *arg)
45 : Item_int_func(pos, arg) {}
46
47 public:
48 longlong val_int() override;
49
50 const char *func_name() const override { return "inet_aton"; }
51
52 bool resolve_type(THD *thd) override {
53 if (param_type_is_default(thd, 0, 1)) return true;
54 set_nullable(true);
55 unsigned_flag = true;
56 return false;
57 }
58};
59
60/*************************************************************************
61 Item_func_inet_ntoa implements INET_NTOA() SQL-function.
62*************************************************************************/
63
65 public:
66 inline Item_func_inet_ntoa(const POS &pos, Item *arg)
67 : Item_str_func(pos, arg) {}
68
69 public:
70 String *val_str(String *str) override;
71
72 const char *func_name() const override { return "inet_ntoa"; }
73
74 bool resolve_type(THD *thd) override {
75 if (param_type_is_default(thd, 0, 1, MYSQL_TYPE_LONGLONG)) return true;
77 set_nullable(true);
78 return false;
79 }
80};
81
82/*************************************************************************
83 Item_func_inet_bool_base implements common code for INET6/IP-related
84 functions returning boolean value.
85*************************************************************************/
86
88 public:
89 Item_func_inet_bool_base(const POS &pos, Item *ip_addr)
90 : Item_bool_func(pos, ip_addr) {
91 null_value = false;
92 }
93
94 public:
95 longlong val_int() override;
96
97 protected:
98 virtual bool calc_value(const String *arg) const = 0;
99};
100
101/*************************************************************************
102 Item_func_inet_str_base implements common code for INET6/IP-related
103 functions returning string value.
104*************************************************************************/
105
107 public:
109 : Item_str_ascii_func(pos, arg) {}
110
111 public:
112 String *val_str_ascii(String *buffer) override;
113
114 protected:
115 virtual bool calc_value(String *arg, String *buffer) = 0;
116};
117
118/*************************************************************************
119 Item_func_inet6_aton implements INET6_ATON() SQL-function.
120*************************************************************************/
121
123 public:
124 Item_func_inet6_aton(const POS &pos, Item *ip_addr)
125 : Item_func_inet_str_base(pos, ip_addr) {}
126
127 public:
128 const char *func_name() const override { return "inet6_aton"; }
129
130 bool resolve_type(THD *thd) override {
131 if (param_type_is_default(thd, 0, 1)) return true;
133 set_nullable(true);
134 return false;
135 }
136
137 protected:
138 bool calc_value(String *arg, String *buffer) override;
139};
140
141/*************************************************************************
142 Item_func_inet6_ntoa implements INET6_NTOA() SQL-function.
143*************************************************************************/
144
146 public:
147 Item_func_inet6_ntoa(const POS &pos, Item *ip_addr)
148 : Item_func_inet_str_base(pos, ip_addr) {}
149
150 public:
151 const char *func_name() const override { return "inet6_ntoa"; }
152
153 bool resolve_type(THD *thd) override {
154 if (param_type_is_default(thd, 0, 1)) return true;
155 // max length: IPv6-address -- 16 bytes
156 // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter
157 // 4 symbols per group
159
160 set_nullable(true);
161 return false;
162 }
163
164 protected:
165 bool calc_value(String *arg, String *buffer) override;
166};
167
168/*************************************************************************
169 Item_func_is_ipv4 implements IS_IPV4() SQL-function.
170*************************************************************************/
171
173 public:
174 Item_func_is_ipv4(const POS &pos, Item *ip_addr)
175 : Item_func_inet_bool_base(pos, ip_addr) {}
176
177 public:
178 const char *func_name() const override { return "is_ipv4"; }
179
180 protected:
181 bool calc_value(const String *arg) const override;
182};
183
184/*************************************************************************
185 Item_func_is_ipv6 implements IS_IPV6() SQL-function.
186*************************************************************************/
187
189 public:
190 Item_func_is_ipv6(const POS &pos, Item *ip_addr)
191 : Item_func_inet_bool_base(pos, ip_addr) {}
192
193 public:
194 const char *func_name() const override { return "is_ipv6"; }
195
196 protected:
197 bool calc_value(const String *arg) const override;
198};
199
200/*************************************************************************
201 Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function.
202*************************************************************************/
203
205 public:
206 Item_func_is_ipv4_compat(const POS &pos, Item *ip_addr)
207 : Item_func_inet_bool_base(pos, ip_addr) {}
208
209 public:
210 const char *func_name() const override { return "is_ipv4_compat"; }
211
212 protected:
213 bool calc_value(const String *arg) const override;
214};
215
216/*************************************************************************
217 Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function.
218*************************************************************************/
219
221 public:
222 Item_func_is_ipv4_mapped(const POS &pos, Item *ip_addr)
223 : Item_func_inet_bool_base(pos, ip_addr) {}
224
225 public:
226 const char *func_name() const override { return "is_ipv4_mapped"; }
227
228 protected:
229 bool calc_value(const String *arg) const override;
230};
231
232#endif // ITEM_INETFUNC_INCLUDED
Definition: item_cmpfunc.h:294
Definition: item_inetfunc.h:122
const char * func_name() const override
Definition: item_inetfunc.h:128
Item_func_inet6_aton(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:124
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:130
bool calc_value(String *arg, String *buffer) override
Converts IP-address-string to IP-address-data.
Definition: item_inetfunc.cc:695
Definition: item_inetfunc.h:145
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:153
bool calc_value(String *arg, String *buffer) override
Converts IP-address-data to IP-address-string.
Definition: item_inetfunc.cc:732
Item_func_inet6_ntoa(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:147
const char * func_name() const override
Definition: item_inetfunc.h:151
Definition: item_inetfunc.h:42
const char * func_name() const override
Definition: item_inetfunc.h:50
Item_func_inet_aton(const POS &pos, Item *arg)
Definition: item_inetfunc.h:44
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:52
longlong val_int() override
Definition: item_inetfunc.cc:59
Definition: item_inetfunc.h:87
longlong val_int() override
Check the function argument, handle errors properly.
Definition: item_inetfunc.cc:195
virtual bool calc_value(const String *arg) const =0
Item_func_inet_bool_base(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:89
Definition: item_inetfunc.h:64
Item_func_inet_ntoa(const POS &pos, Item *arg)
Definition: item_inetfunc.h:66
String * val_str(String *str) override
Definition: item_inetfunc.cc:131
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_inetfunc.h:74
const char * func_name() const override
Definition: item_inetfunc.h:72
Definition: item_inetfunc.h:106
virtual bool calc_value(String *arg, String *buffer)=0
String * val_str_ascii(String *buffer) override
Check the function argument, handle errors properly.
Definition: item_inetfunc.cc:224
Item_func_inet_str_base(const POS &pos, Item *arg)
Definition: item_inetfunc.h:108
Definition: item_inetfunc.h:204
Item_func_is_ipv4_compat(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:206
const char * func_name() const override
Definition: item_inetfunc.h:210
bool calc_value(const String *arg) const override
Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
Definition: item_inetfunc.cc:807
Definition: item_inetfunc.h:220
bool calc_value(const String *arg) const override
Checks if the passed IPv6-address is an IPv4-mapped IPv6-address.
Definition: item_inetfunc.cc:828
Item_func_is_ipv4_mapped(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:222
const char * func_name() const override
Definition: item_inetfunc.h:226
Definition: item_inetfunc.h:172
Item_func_is_ipv4(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:174
bool calc_value(const String *arg) const override
Checks if the passed string represents an IPv4-address.
Definition: item_inetfunc.cc:771
const char * func_name() const override
Definition: item_inetfunc.h:178
Definition: item_inetfunc.h:188
Item_func_is_ipv6(const POS &pos, Item *ip_addr)
Definition: item_inetfunc.h:190
const char * func_name() const override
Definition: item_inetfunc.h:194
bool calc_value(const String *arg) const override
Checks if the passed string represents an IPv6-address.
Definition: item_inetfunc.cc:789
bool param_type_is_default(THD *thd, uint start, uint end, uint step, enum_field_types def)
For arguments of this Item_func ("args" array), in range [start, start+step, start+2*step,...
Definition: item_func.cc:528
Definition: item_func.h:1020
Definition: item_strfunc.h:148
Definition: item_strfunc.h:76
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
void set_nullable(bool nullable)
Definition: item.h:3687
static const CHARSET_INFO * default_charset()
Definition: item.cc:1760
bool null_value
True if item is null.
Definition: item.h:3712
bool unsigned_flag
Definition: item.h:3713
void set_data_type_string(uint32 max_l)
Set the Item to be variable length string.
Definition: item.h:1600
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:64
A better implementation of the UNIX ctype(3) library.
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:500
Some integer typedefs for easier portability.
long long int longlong
Definition: my_inttypes.h:55
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1105
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
Bison "location" class.
Definition: parse_location.h:43