[openrtm-commit:02310] r2882 - branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 1月 22日 (日) 16:37:48 JST


Author: n-ando
Date: 2017-01-22 16:37:48 +0900 (Sun, 22 Jan 2017)
New Revision: 2882

Modified:
   branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.cpp
   branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.h
Log:
[incompat] isIPv4, isIPv6 functions have been added for Manager::setEndpointProperty(). refs #3836

Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.cpp	2017-01-20 07:31:55 UTC (rev 2881)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.cpp	2017-01-22 07:37:48 UTC (rev 2882)
@@ -499,6 +499,51 @@
       return true;
     return false;
   }
+  bool isIPv4(const std::string& str)
+  {
+    coil::vstring tmp = coil::split(str, ":");
+    coil::vstring ipv4 = coil::split(str, ".");
+    if (ipv4.size() != 4) { return false; }
+    for (size_t i(0); i < ipv4.size(); ++i)
+      {
+        unsigned short int dec;
+        if (!coil::stringTo(dec, ipv4[i].c_str())) { return false; }
+        if (dec < 0 || dec > 255) { return false; }
+      }
+    return true;
+  }
+  bool isIPv6(const std::string& str)
+  {
+    // IPv6 address must be
+    // 1111:1111:1111:1111:1111:1111:1111:1111 (addr)
+    // [1111:1111:1111:1111:1111:1111:1111:1111]:11111 (addr, port)
+    coil::vstring tmp = coil::split(str, "]:");
+    if (tmp.size() > 2) { return false; }
+    if (tmp.size() == 2)
+      {
+        if (tmp[0][0] != '[') { return false; }
+        tmp[0].erase(0, 1);
+      }
+    
+    coil::vstring ipv6 = coil::split(tmp[0], ":");
+    if (ipv6.size() > 8) { return false; }
+    for (size_t i(0); i < ipv6.size(); ++i)
+      {
+        try
+          {
+            if (ipv6[i].empty()) { continue; }
+            char* endptr = 0;
+            long int hexval = std::strtol(ipv6[i].c_str(), &endptr, 16);
+            if (errno == ERANGE) { return false; }
+            if (hexval < 0x0 || hexval > 0xFFFF) { return false; }
+          }
+        catch (...)
+          {
+            return false;
+          }
+      }
+    return true;
+  }
   
   /*!
    * @if jp

Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.h	2017-01-20 07:31:55 UTC (rev 2881)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/coil/common/stringutil.h	2017-01-22 07:37:48 UTC (rev 2882)
@@ -23,6 +23,9 @@
 #include <string>
 #include <vector>
 #include <sstream>
+#include <cassert>
+#include <errno.h>
+#include <cstdlib>
 
 #if defined (_MSC_VER) && (_MSC_VER <=1500) // VC2008(VC9.0) or before
 #else
@@ -544,7 +547,9 @@
    * @endif
    */
   bool isURL(const std::string& str);
-  
+  bool isIPv4(const std::string& str);
+  bool isIPv6(const std::string& str);
+
   /*!
    * @if jp
    * @brief 与えられたオブジェクトをstd::stringに変換
@@ -607,7 +612,7 @@
     if ((s >> val).fail()) { return false; }
     return true;
   }
-  
+
   /*!
    * @if jp
    * @brief 与えられた文字列をstd::stringに変換



More information about the openrtm-commit mailing list