Commit bdaa7fac authored by Sergei Golubchik's avatar Sergei Golubchik

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.
parent 12eb8ad7
...@@ -158,7 +158,7 @@ String *Item_func_inet6_aton::val_str(String *buffer) ...@@ -158,7 +158,7 @@ String *Item_func_inet6_aton::val_str(String *buffer)
return buffer; return buffer;
} }
Inet6_null ipv6(*tmp.string()); Inet6Bundle::Fbt_null ipv6(*tmp.string());
if (!ipv6.is_null()) if (!ipv6.is_null())
{ {
ipv6.to_binary(buffer); ipv6.to_binary(buffer);
...@@ -197,7 +197,7 @@ String *Item_func_inet6_ntoa::val_str_ascii(String *buffer) ...@@ -197,7 +197,7 @@ String *Item_func_inet6_ntoa::val_str_ascii(String *buffer)
return buffer; return buffer;
} }
Inet6_null ipv6(static_cast<const Binary_string&>(*tmp.string())); Inet6Bundle::Fbt_null ipv6(static_cast<const Binary_string&>(*tmp.string()));
if (!ipv6.is_null()) if (!ipv6.is_null())
{ {
ipv6.to_string(buffer); ipv6.to_string(buffer);
...@@ -221,6 +221,22 @@ longlong Item_func_is_ipv4::val_int() ...@@ -221,6 +221,22 @@ longlong Item_func_is_ipv4::val_int()
return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null(); return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null();
} }
class IP6 : public Inet6Bundle::Fbt_null
{
public:
IP6(Item* arg) : Inet6Bundle::Fbt_null(arg) {}
bool is_v4compat() const
{
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) m_buffer);
}
bool is_v4mapped() const
{
static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size");
return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) m_buffer);
}
};
/** /**
Checks if the passed string represents an IPv6-address. Checks if the passed string represents an IPv6-address.
...@@ -230,17 +246,16 @@ longlong Item_func_is_ipv6::val_int() ...@@ -230,17 +246,16 @@ longlong Item_func_is_ipv6::val_int()
{ {
DBUG_ASSERT(fixed()); DBUG_ASSERT(fixed());
String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]);
return !tmp.is_null() && !Inet6_null(*tmp.string()).is_null(); return !tmp.is_null() && !Inet6Bundle::Fbt_null(*tmp.string()).is_null();
} }
/** /**
Checks if the passed IPv6-address is an IPv4-compat IPv6-address. Checks if the passed IPv6-address is an IPv4-compat IPv6-address.
*/ */
longlong Item_func_is_ipv4_compat::val_int() longlong Item_func_is_ipv4_compat::val_int()
{ {
Inet6_null ip6(args[0]); IP6 ip6(args[0]);
return !ip6.is_null() && ip6.is_v4compat(); return !ip6.is_null() && ip6.is_v4compat();
} }
...@@ -251,6 +266,6 @@ longlong Item_func_is_ipv4_compat::val_int() ...@@ -251,6 +266,6 @@ longlong Item_func_is_ipv4_compat::val_int()
longlong Item_func_is_ipv4_mapped::val_int() longlong Item_func_is_ipv4_mapped::val_int()
{ {
Inet6_null ip6(args[0]); IP6 ip6(args[0]);
return !ip6.is_null() && ip6.is_v4mapped(); return !ip6.is_null() && ip6.is_v4mapped();
} }
/* Copyright (c) 2019 MariaDB Corporation /* Copyright (c) 2019,2021 MariaDB Corporation
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -21,14 +21,10 @@ ...@@ -21,14 +21,10 @@
#include <mysql/plugin_data_type.h> #include <mysql/plugin_data_type.h>
#include <mysql/plugin_function.h> #include <mysql/plugin_function.h>
Type_handler_inet6 type_handler_inet6;
static struct st_mariadb_data_type plugin_descriptor_type_inet6= static struct st_mariadb_data_type plugin_descriptor_type_inet6=
{ {
MariaDB_DATA_TYPE_INTERFACE_VERSION, MariaDB_DATA_TYPE_INTERFACE_VERSION,
&type_handler_inet6 Inet6Bundle::type_handler_fbt()
}; };
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment