#At file:///home/alik/MySQL/bzr/00/wl5787/mysql-trunk-wl5787.2/ based on revid:alexander.nozdrin@stripped
3322 Alexander Nozdrin 2011-04-15
Preliminary patch for WL#5787: add missing files.
added:
sql/item_inetfunc.cc
sql/item_inetfunc.h
=== added file 'sql/item_inetfunc.cc'
--- a/sql/item_inetfunc.cc 1970-01-01 00:00:00 +0000
+++ b/sql/item_inetfunc.cc 2011-04-15 09:39:46 +0000
@@ -0,0 +1,118 @@
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ 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
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include "item_inetfunc.h"
+
+#include "violite.h" // vio_getnameinfo()
+
+///////////////////////////////////////////////////////////////////////////
+
+longlong Item_func_inet_aton::val_int()
+{
+ DBUG_ASSERT(fixed == 1);
+ uint byte_result = 0;
+ ulonglong result = 0; // We are ready for 64 bit addresses
+ const char *p,* end;
+ char c = '.'; // we mark c to indicate invalid IP in case length is 0
+ char buff[36];
+ int dot_count= 0;
+
+ String *s, tmp(buff, sizeof(buff), &my_charset_latin1);
+ if (!(s = args[0]->val_str_ascii(&tmp))) // If null value
+ goto err;
+ null_value=0;
+
+ end= (p = s->ptr()) + s->length();
+ while (p < end)
+ {
+ c = *p++;
+ int digit = (int) (c - '0');
+ if (digit >= 0 && digit <= 9)
+ {
+ if ((byte_result = byte_result * 10 + digit) > 255)
+ goto err; // Wrong address
+ }
+ else if (c == '.')
+ {
+ dot_count++;
+ result= (result << 8) + (ulonglong) byte_result;
+ byte_result = 0;
+ }
+ else
+ goto err; // Invalid character
+ }
+ if (c != '.') // IP number can't end on '.'
+ {
+ /*
+ Handle short-forms addresses according to standard. Examples:
+ 127 -> 0.0.0.127
+ 127.1 -> 127.0.0.1
+ 127.2.1 -> 127.2.0.1
+ */
+ switch (dot_count) {
+ case 1: result<<= 8; /* Fall through */
+ case 2: result<<= 8; /* Fall through */
+ }
+ return (result << 8) + (ulonglong) byte_result;
+ }
+
+err:
+ null_value=1;
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+String* Item_func_inet_ntoa::val_str(String* str)
+{
+ DBUG_ASSERT(fixed == 1);
+ uchar buf[8], *p;
+ ulonglong n = (ulonglong) args[0]->val_int();
+ char num[4];
+
+ /*
+ We do not know if args[0] is NULL until we have called
+ some val function on it if args[0] is not a constant!
+
+ Also return null if n > 255.255.255.255
+ */
+ if ((null_value= (args[0]->null_value || n > (ulonglong) LL(4294967295))))
+ return 0; // Null value
+
+ str->set_charset(collation.collation);
+ str->length(0);
+ int4store(buf,n);
+
+ /* Now we can assume little endian. */
+
+ num[3]='.';
+ for (p=buf+4 ; p-- > buf ; )
+ {
+ uint c = *p;
+ uint n1,n2; // Try to avoid divisions
+ n1= c / 100; // 100 digits
+ c-= n1*100;
+ n2= c / 10; // 10 digits
+ c-=n2*10; // last digit
+ num[0]=(char) n1+'0';
+ num[1]=(char) n2+'0';
+ num[2]=(char) c+'0';
+ uint length= (n1 ? 4 : n2 ? 3 : 2); // Remove pre-zero
+ uint dot_length= (p <= buf) ? 1 : 0;
+ (void) str->append(num + 4 - length, length - dot_length,
+ &my_charset_latin1);
+ }
+ return str;
+}
=== added file 'sql/item_inetfunc.h'
--- a/sql/item_inetfunc.h 1970-01-01 00:00:00 +0000
+++ b/sql/item_inetfunc.h 2011-04-15 09:39:46 +0000
@@ -0,0 +1,74 @@
+#ifndef ITEM_INETFUNC_INCLUDED
+#define ITEM_INETFUNC_INCLUDED
+
+/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ 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
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+
+#include "item.h"
+
+/*************************************************************************
+ Item_func_inet_aton implements INET_ATON() SQL-function.
+*************************************************************************/
+
+class Item_func_inet_aton : public Item_int_func
+{
+public:
+ inline Item_func_inet_aton(Item *arg)
+ : Item_int_func(arg)
+ {}
+
+public:
+ virtual longlong val_int();
+
+ virtual const char *func_name() const
+ { return "inet_aton"; }
+
+ virtual void fix_length_and_dec()
+ {
+ decimals= 0;
+ max_length= 21;
+ maybe_null= 1;
+ unsigned_flag= 1;
+ }
+};
+
+
+/*************************************************************************
+ Item_func_inet_ntoa implements INET_NTOA() SQL-function.
+*************************************************************************/
+
+class Item_func_inet_ntoa : public Item_str_func
+{
+public:
+ inline Item_func_inet_ntoa(Item *arg)
+ : Item_str_func(arg)
+ { }
+
+public:
+ virtual String* val_str(String* str);
+
+ virtual const char *func_name() const
+ { return "inet_ntoa"; }
+
+ virtual void fix_length_and_dec()
+ {
+ decimals= 0;
+ fix_length_and_charset(3 * 8 + 7, default_charset());
+ maybe_null= 1;
+ }
+};
+
+#endif // ITEM_INETFUNC_INCLUDED
Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110415093946-2ltfssbkvqcg6eu5.bundle
| Thread |
|---|
| • bzr commit into mysql-trunk branch (alexander.nozdrin:3322) WL#5787 | Alexander Nozdrin | 15 Apr |