Skip to content

Commit bdaa7fa

Browse files
committed
cleanup: move most of type_inet plugin implementation into the server
factor out the the common code for all plugin types that have a fixed-length native binary representation and a possibly variable-length string representation.
1 parent 12eb8ad commit bdaa7fa

File tree

5 files changed

+1927
-2108
lines changed

5 files changed

+1927
-2108
lines changed

plugin/type_inet/item_inetfunc.cc

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ String *Item_func_inet6_aton::val_str(String *buffer)
158158
return buffer;
159159
}
160160

161-
Inet6_null ipv6(*tmp.string());
161+
Inet6Bundle::Fbt_null ipv6(*tmp.string());
162162
if (!ipv6.is_null())
163163
{
164164
ipv6.to_binary(buffer);
@@ -197,7 +197,7 @@ String *Item_func_inet6_ntoa::val_str_ascii(String *buffer)
197197
return buffer;
198198
}
199199

200-
Inet6_null ipv6(static_cast<const Binary_string&>(*tmp.string()));
200+
Inet6Bundle::Fbt_null ipv6(static_cast<const Binary_string&>(*tmp.string()));
201201
if (!ipv6.is_null())
202202
{
203203
ipv6.to_string(buffer);
@@ -221,6 +221,22 @@ longlong Item_func_is_ipv4::val_int()
221221
return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null();
222222
}
223223

224+
class IP6 : public Inet6Bundle::Fbt_null
225+
{
226+
public:
227+
IP6(Item* arg) : Inet6Bundle::Fbt_null(arg) {}
228+
bool is_v4compat() const
229+
{
230+
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
231+
return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) m_buffer);
232+
}
233+
bool is_v4mapped() const
234+
{
235+
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
236+
return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) m_buffer);
237+
}
238+
};
239+
224240

225241
/**
226242
Checks if the passed string represents an IPv6-address.
@@ -230,17 +246,16 @@ longlong Item_func_is_ipv6::val_int()
230246
{
231247
DBUG_ASSERT(fixed());
232248
String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]);
233-
return !tmp.is_null() && !Inet6_null(*tmp.string()).is_null();
249+
return !tmp.is_null() && !Inet6Bundle::Fbt_null(*tmp.string()).is_null();
234250
}
235251

236-
237252
/**
238253
Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
239254
*/
240255

241256
longlong Item_func_is_ipv4_compat::val_int()
242257
{
243-
Inet6_null ip6(args[0]);
258+
IP6 ip6(args[0]);
244259
return !ip6.is_null() && ip6.is_v4compat();
245260
}
246261

@@ -251,6 +266,6 @@ longlong Item_func_is_ipv4_compat::val_int()
251266

252267
longlong Item_func_is_ipv4_mapped::val_int()
253268
{
254-
Inet6_null ip6(args[0]);
269+
IP6 ip6(args[0]);
255270
return !ip6.is_null() && ip6.is_v4mapped();
256271
}

plugin/type_inet/plugin.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019 MariaDB Corporation
1+
/* Copyright (c) 2019,2021 MariaDB Corporation
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -21,14 +21,10 @@
2121
#include <mysql/plugin_data_type.h>
2222
#include <mysql/plugin_function.h>
2323

24-
25-
Type_handler_inet6 type_handler_inet6;
26-
27-
2824
static struct st_mariadb_data_type plugin_descriptor_type_inet6=
2925
{
3026
MariaDB_DATA_TYPE_INTERFACE_VERSION,
31-
&type_handler_inet6
27+
Inet6Bundle::type_handler_fbt()
3228
};
3329

3430

0 commit comments

Comments
 (0)