summaryrefslogtreecommitdiff
path: root/sql/item_inetfunc.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2014-05-30 16:19:00 +0400
committerAlexander Barkov <bar@mariadb.org>2014-05-30 16:19:00 +0400
commit4211b1cd48c0ff315d40c37817211b31114080e1 (patch)
tree7e90331145ad0345c7c28dcfd5e362a397f79ddb /sql/item_inetfunc.h
parent1449d1d54fc4ea876e54bded79c29b51eb6be91d (diff)
downloadmariadb-git-4211b1cd48c0ff315d40c37817211b31114080e1.tar.gz
MDEV-4051 INET6_ATON() and INET6_NTOA()
Backporting functions from MySQL-5.6: - INET6_ATON() - INET6_NTOA() - IS_IPV4() - IS_IPV4_COMPAT() - IS_IPV4_MAPPED() - IS_IPV6()
Diffstat (limited to 'sql/item_inetfunc.h')
-rw-r--r--sql/item_inetfunc.h203
1 files changed, 195 insertions, 8 deletions
diff --git a/sql/item_inetfunc.h b/sql/item_inetfunc.h
index cebe36e34eb..3a85d367ff1 100644
--- a/sql/item_inetfunc.h
+++ b/sql/item_inetfunc.h
@@ -30,7 +30,13 @@ public:
Item_func_inet_aton(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "inet_aton"; }
- void fix_length_and_dec() { decimals= 0; max_length= 21; maybe_null= 1; unsigned_flag= 1;}
+ void fix_length_and_dec()
+ {
+ decimals= 0;
+ max_length= 21;
+ maybe_null= 1;
+ unsigned_flag= 1;
+ }
};
@@ -41,17 +47,198 @@ public:
class Item_func_inet_ntoa : public Item_str_func
{
public:
- Item_func_inet_ntoa(Item *a) :Item_str_func(a)
- {
- }
+ Item_func_inet_ntoa(Item *a)
+ : Item_str_func(a)
+ { }
String* val_str(String* str);
const char *func_name() const { return "inet_ntoa"; }
- void fix_length_and_dec()
- {
- decimals= 0;
- fix_length_and_charset(3 * 8 + 7, default_charset());
+ void fix_length_and_dec()
+ {
+ decimals= 0;
+ fix_length_and_charset(3 * 8 + 7, default_charset());
+ maybe_null= 1;
+ }
+};
+
+
+/*************************************************************************
+ Item_func_inet_bool_base implements common code for INET6/IP-related
+ functions returning boolean value.
+*************************************************************************/
+
+class Item_func_inet_bool_base : public Item_bool_func
+{
+public:
+ inline Item_func_inet_bool_base(Item *ip_addr)
+ : Item_bool_func(ip_addr)
+ {
+ null_value= false;
+ }
+
+public:
+ virtual longlong val_int();
+
+protected:
+ virtual bool calc_value(const String *arg) = 0;
+};
+
+
+/*************************************************************************
+ Item_func_inet_str_base implements common code for INET6/IP-related
+ functions returning string value.
+*************************************************************************/
+
+class Item_func_inet_str_base : public Item_str_ascii_func
+{
+public:
+ inline Item_func_inet_str_base(Item *arg)
+ : Item_str_ascii_func(arg)
+ { }
+
+public:
+ virtual String *val_str_ascii(String *buffer);
+
+protected:
+ virtual bool calc_value(String *arg, String *buffer) = 0;
+};
+
+
+/*************************************************************************
+ Item_func_inet6_aton implements INET6_ATON() SQL-function.
+*************************************************************************/
+
+class Item_func_inet6_aton : public Item_func_inet_str_base
+{
+public:
+ inline Item_func_inet6_aton(Item *ip_addr)
+ : Item_func_inet_str_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "inet6_aton"; }
+
+ virtual void fix_length_and_dec()
+ {
+ decimals= 0;
+ fix_length_and_charset(16, &my_charset_bin);
maybe_null= 1;
}
+
+protected:
+ virtual bool calc_value(String *arg, String *buffer);
+};
+
+
+/*************************************************************************
+ Item_func_inet6_ntoa implements INET6_NTOA() SQL-function.
+*************************************************************************/
+
+class Item_func_inet6_ntoa : public Item_func_inet_str_base
+{
+public:
+ inline Item_func_inet6_ntoa(Item *ip_addr)
+ : Item_func_inet_str_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "inet6_ntoa"; }
+
+ virtual void fix_length_and_dec()
+ {
+ decimals= 0;
+
+ // max length: IPv6-address -- 16 bytes
+ // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter
+ // 4 symbols per group
+ fix_length_and_charset(8 * 4 + 7, default_charset());
+
+ maybe_null= 1;
+ }
+
+protected:
+ virtual bool calc_value(String *arg, String *buffer);
+};
+
+
+/*************************************************************************
+ Item_func_is_ipv4 implements IS_IPV4() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4 : public Item_func_inet_bool_base
+{
+public:
+ inline Item_func_is_ipv4(Item *ip_addr)
+ : Item_func_inet_bool_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "is_ipv4"; }
+
+protected:
+ virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+ Item_func_is_ipv6 implements IS_IPV6() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv6 : public Item_func_inet_bool_base
+{
+public:
+ inline Item_func_is_ipv6(Item *ip_addr)
+ : Item_func_inet_bool_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "is_ipv6"; }
+
+protected:
+ virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+ Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4_compat : public Item_func_inet_bool_base
+{
+public:
+ inline Item_func_is_ipv4_compat(Item *ip_addr)
+ : Item_func_inet_bool_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "is_ipv4_compat"; }
+
+protected:
+ virtual bool calc_value(const String *arg);
+};
+
+
+/*************************************************************************
+ Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function.
+*************************************************************************/
+
+class Item_func_is_ipv4_mapped : public Item_func_inet_bool_base
+{
+public:
+ inline Item_func_is_ipv4_mapped(Item *ip_addr)
+ : Item_func_inet_bool_base(ip_addr)
+ { }
+
+public:
+ virtual const char *func_name() const
+ { return "is_ipv4_mapped"; }
+
+protected:
+ virtual bool calc_value(const String *arg);
};
#endif // ITEM_INETFUNC_INCLUDED