My Project
|
00001 #ifndef ITEM_INETFUNC_INCLUDED 00002 #define ITEM_INETFUNC_INCLUDED 00003 00004 /* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; version 2 of the License. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00018 00019 00020 #include "item.h" 00021 00022 /************************************************************************* 00023 Item_func_inet_aton implements INET_ATON() SQL-function. 00024 *************************************************************************/ 00025 00026 class Item_func_inet_aton : public Item_int_func 00027 { 00028 public: 00029 inline Item_func_inet_aton(Item *arg) 00030 : Item_int_func(arg) 00031 {} 00032 00033 public: 00034 virtual longlong val_int(); 00035 00036 virtual const char *func_name() const 00037 { return "inet_aton"; } 00038 00039 virtual void fix_length_and_dec() 00040 { 00041 decimals= 0; 00042 max_length= 21; 00043 maybe_null= 1; 00044 unsigned_flag= 1; 00045 } 00046 }; 00047 00048 00049 /************************************************************************* 00050 Item_func_inet_ntoa implements INET_NTOA() SQL-function. 00051 *************************************************************************/ 00052 00053 class Item_func_inet_ntoa : public Item_str_func 00054 { 00055 public: 00056 inline Item_func_inet_ntoa(Item *arg) 00057 : Item_str_func(arg) 00058 { } 00059 00060 public: 00061 virtual String* val_str(String* str); 00062 00063 virtual const char *func_name() const 00064 { return "inet_ntoa"; } 00065 00066 virtual void fix_length_and_dec() 00067 { 00068 decimals= 0; 00069 fix_length_and_charset(3 * 8 + 7, default_charset()); 00070 maybe_null= 1; 00071 } 00072 }; 00073 00074 00075 /************************************************************************* 00076 Item_func_inet_bool_base implements common code for INET6/IP-related 00077 functions returning boolean value. 00078 *************************************************************************/ 00079 00080 class Item_func_inet_bool_base : public Item_bool_func 00081 { 00082 public: 00083 inline Item_func_inet_bool_base(Item *ip_addr) 00084 : Item_bool_func(ip_addr) 00085 { 00086 null_value= false; 00087 } 00088 00089 public: 00090 virtual longlong val_int(); 00091 00092 protected: 00093 virtual bool calc_value(const String *arg) = 0; 00094 }; 00095 00096 00097 /************************************************************************* 00098 Item_func_inet_str_base implements common code for INET6/IP-related 00099 functions returning string value. 00100 *************************************************************************/ 00101 00102 class Item_func_inet_str_base : public Item_str_ascii_func 00103 { 00104 public: 00105 inline Item_func_inet_str_base(Item *arg) 00106 : Item_str_ascii_func(arg) 00107 { } 00108 00109 public: 00110 virtual String *val_str_ascii(String *buffer); 00111 00112 protected: 00113 virtual bool calc_value(String *arg, String *buffer) = 0; 00114 }; 00115 00116 00117 /************************************************************************* 00118 Item_func_inet6_aton implements INET6_ATON() SQL-function. 00119 *************************************************************************/ 00120 00121 class Item_func_inet6_aton : public Item_func_inet_str_base 00122 { 00123 public: 00124 inline Item_func_inet6_aton(Item *ip_addr) 00125 : Item_func_inet_str_base(ip_addr) 00126 { } 00127 00128 public: 00129 virtual const char *func_name() const 00130 { return "inet6_aton"; } 00131 00132 virtual void fix_length_and_dec() 00133 { 00134 decimals= 0; 00135 fix_length_and_charset(16, &my_charset_bin); 00136 maybe_null= 1; 00137 } 00138 00139 protected: 00140 virtual bool calc_value(String *arg, String *buffer); 00141 }; 00142 00143 00144 /************************************************************************* 00145 Item_func_inet6_ntoa implements INET6_NTOA() SQL-function. 00146 *************************************************************************/ 00147 00148 class Item_func_inet6_ntoa : public Item_func_inet_str_base 00149 { 00150 public: 00151 inline Item_func_inet6_ntoa(Item *ip_addr) 00152 : Item_func_inet_str_base(ip_addr) 00153 { } 00154 00155 public: 00156 virtual const char *func_name() const 00157 { return "inet6_ntoa"; } 00158 00159 virtual void fix_length_and_dec() 00160 { 00161 decimals= 0; 00162 00163 // max length: IPv6-address -- 16 bytes 00164 // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter 00165 // 4 symbols per group 00166 fix_length_and_charset(8 * 4 + 7, default_charset()); 00167 00168 maybe_null= 1; 00169 } 00170 00171 protected: 00172 virtual bool calc_value(String *arg, String *buffer); 00173 }; 00174 00175 00176 /************************************************************************* 00177 Item_func_is_ipv4 implements IS_IPV4() SQL-function. 00178 *************************************************************************/ 00179 00180 class Item_func_is_ipv4 : public Item_func_inet_bool_base 00181 { 00182 public: 00183 inline Item_func_is_ipv4(Item *ip_addr) 00184 : Item_func_inet_bool_base(ip_addr) 00185 { } 00186 00187 public: 00188 virtual const char *func_name() const 00189 { return "is_ipv4"; } 00190 00191 protected: 00192 virtual bool calc_value(const String *arg); 00193 }; 00194 00195 00196 /************************************************************************* 00197 Item_func_is_ipv6 implements IS_IPV6() SQL-function. 00198 *************************************************************************/ 00199 00200 class Item_func_is_ipv6 : public Item_func_inet_bool_base 00201 { 00202 public: 00203 inline Item_func_is_ipv6(Item *ip_addr) 00204 : Item_func_inet_bool_base(ip_addr) 00205 { } 00206 00207 public: 00208 virtual const char *func_name() const 00209 { return "is_ipv6"; } 00210 00211 protected: 00212 virtual bool calc_value(const String *arg); 00213 }; 00214 00215 00216 /************************************************************************* 00217 Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function. 00218 *************************************************************************/ 00219 00220 class Item_func_is_ipv4_compat : public Item_func_inet_bool_base 00221 { 00222 public: 00223 inline Item_func_is_ipv4_compat(Item *ip_addr) 00224 : Item_func_inet_bool_base(ip_addr) 00225 { } 00226 00227 public: 00228 virtual const char *func_name() const 00229 { return "is_ipv4_compat"; } 00230 00231 protected: 00232 virtual bool calc_value(const String *arg); 00233 }; 00234 00235 00236 /************************************************************************* 00237 Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function. 00238 *************************************************************************/ 00239 00240 class Item_func_is_ipv4_mapped : public Item_func_inet_bool_base 00241 { 00242 public: 00243 inline Item_func_is_ipv4_mapped(Item *ip_addr) 00244 : Item_func_inet_bool_base(ip_addr) 00245 { } 00246 00247 public: 00248 virtual const char *func_name() const 00249 { return "is_ipv4_mapped"; } 00250 00251 protected: 00252 virtual bool calc_value(const String *arg); 00253 }; 00254 00255 #endif // ITEM_INETFUNC_INCLUDED