List:Commits« Previous MessageNext Message »
From:Alexander Nozdrin Date:March 29 2011 1:25pm
Subject:bzr commit into mysql-trunk branch (alexander.nozdrin:3329) WL#5787
View as plain text  
#At file:///home/alik/MySQL/bzr/00/wl5787/mysql-trunk-wl5787/ based on revid:sven.sandberg@stripped

 3329 Alexander Nozdrin	2011-03-29
      Preliminatry patch for WL#5787 (IPv6-capable INET_ATON and
      INET_NTOA functions).
      
      The patch just moves Item_func_inet_aton and Item_func_inet_ntoa
      implementations into new files item_inetfunc.h and
      item_inetfunc.cc. Those new files will be used to hold
      implementations of new functions in the next patch.

    added:
      sql/item_inetfunc.cc
      sql/item_inetfunc.h
    modified:
      sql/CMakeLists.txt
      sql/item_create.cc
      sql/item_func.cc
      sql/item_func.h
      sql/item_strfunc.cc
      sql/item_strfunc.h
=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2011-02-02 08:30:13 +0000
+++ b/sql/CMakeLists.txt	2011-03-29 13:25:20 +0000
@@ -64,6 +64,7 @@ SET(SQL_SHARED_SOURCES
   item_sum.cc
   item_timefunc.cc 
   item_xmlfunc.cc 
+  item_inetfunc.cc
   key.cc
   keycaches.cc
   lock.cc

=== modified file 'sql/item_create.cc'
--- a/sql/item_create.cc	2011-03-09 20:54:55 +0000
+++ b/sql/item_create.cc	2011-03-29 13:25:20 +0000
@@ -30,6 +30,7 @@
 #include "set_var.h"
 #include "sp_head.h"
 #include "sp.h"
+#include "item_inetfunc.h"
 
 /*
 =============================================================================

=== modified file 'sql/item_func.cc'
--- a/sql/item_func.cc	2011-03-24 08:00:03 +0000
+++ b/sql/item_func.cc	2011-03-29 13:25:20 +0000
@@ -5705,61 +5705,6 @@ void Item_func_get_system_var::cleanup()
 }
 
 
-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;
-}
-
-
 void Item_func_match::init_search(bool no_order)
 {
   DBUG_ENTER("Item_func_match::init_search");

=== modified file 'sql/item_func.h'
--- a/sql/item_func.h	2011-03-22 11:44:40 +0000
+++ b/sql/item_func.h	2011-03-29 13:25:20 +0000
@@ -1610,17 +1610,6 @@ public:
 };
 
 
-class Item_func_inet_aton : public Item_int_func
-{
-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;}
-};
-
-
 /* for fulltext search */
 #include <ft_global.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-03-29 13:25:20 +0000
@@ -0,0 +1,125 @@
+/* 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 <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include "item_inetfunc.h"
+
+#include "violite.h"  // vio_getnameinfo()
+#include "log.h"      // sql_print_warning()
+
+
+///////////////////////////////////////////////////////////////////////////
+
+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-03-29 13:25:20 +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

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2011-03-24 10:37:16 +0000
+++ b/sql/item_strfunc.cc	2011-03-29 13:25:20 +0000
@@ -3512,48 +3512,6 @@ void Item_func_export_set::fix_length_an
   fix_char_length(length * 64 + sep_length * 63);
 }
 
-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;
-}
-
 
 #define get_esc_bit(mask, num) (1 & (*((mask) + ((num) >> 3))) >> ((num) & 7))
 

=== modified file 'sql/item_strfunc.h'
--- a/sql/item_strfunc.h	2011-03-22 11:44:40 +0000
+++ b/sql/item_strfunc.h	2011-03-29 13:25:20 +0000
@@ -780,22 +780,6 @@ class Item_func_export_set: public Item_
   const char *func_name() const { return "export_set"; }
 };
 
-class Item_func_inet_ntoa : public Item_str_func
-{
-public:
-  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()); 
-    maybe_null= 1;
-  }
-};
-
 class Item_func_quote :public Item_str_func
 {
   String tmp_value;


Attachment: [text/bzr-bundle] bzr/alexander.nozdrin@oracle.com-20110329132520-xpyje7whwtob7xx1.bundle
Thread
bzr commit into mysql-trunk branch (alexander.nozdrin:3329) WL#5787Alexander Nozdrin29 Mar
  • Re: bzr commit into mysql-trunk branch (alexander.nozdrin:3329) WL#5787Magne Mæhre4 Apr