[mapguide-commits] r6062 - trunk/MgDev/Common/MapGuideCommon/Services

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Aug 13 04:06:08 EDT 2011


Author: liuar
Date: 2011-08-13 01:06:08 -0700 (Sat, 13 Aug 2011)
New Revision: 6062

Modified:
   trunk/MgDev/Common/MapGuideCommon/Services/SiteInfo.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/SiteManager.cpp
Log:
Submit on behalf of Mars Wu
Implements RFC 118 - IPv6 Support
Ticket: http://trac.osgeo.org/mapguide/ticket/1767
++++++++++++++++++++++++++++
Fix a logic problem of extracting the target ip address from session id.
swscanf(...) behaves differely on Linux from on Windows if the type tag is %s. Then use wstring::substr() to get the Base64 encoded target and hexed port numbers from the hexString instead. 

Modified: trunk/MgDev/Common/MapGuideCommon/Services/SiteInfo.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SiteInfo.cpp	2011-08-12 05:42:28 UTC (rev 6061)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SiteInfo.cpp	2011-08-13 08:06:08 UTC (rev 6062)
@@ -62,25 +62,30 @@
     m_target(L""),
     m_status(Uninitialized)
     {
-        // Compose a format string to extract the target address and the ports from the hexstring
-        INT32 targetlen = (INT32) hexString.length() - HexPortsStringLength;
-        wchar_t format[20] = {0};
-        swprintf(format, 20, L"%%%ds%%4X%%4X%%4X", targetlen);
+        // The length of the Base64 encoded target string
+        INT32 targetlen = (INT32) hexString.length() - MgSiteInfo::HexPortsStringLength;
+        // Get the encoded target
+        STRING targetHex = hexString.substr(0, targetlen);
+        // Get the hexed port numbers
+        STRING portHex = hexString.substr(targetlen, MgSiteInfo::HexPortsStringLength); 
 
-        wchar_t targetHex[100] = {0};
-        if (::swscanf(hexString.c_str(), format, targetHex, &m_sitePort, &m_clientPort, &m_adminPort) == 4)
+        if (3 == ::swscanf (portHex.c_str(), L"%4X%4X%4X", &m_sitePort, &m_clientPort, &m_adminPort))
         {
-            char buffer[100] = {0};
             INT32 hexLength = targetlen;
-            STRING targetHexOriginal = targetHex;
             // There were alignment "=" removed. They should be appended back to do decoding
             if (0 != targetlen % 4)
             {
-                targetHexOriginal.append(L"===");
+                targetHex.append(L"===");
+                // Get the length of the string which has the alignment "=" restored.
+                // Please note that targetHex.length() >= hexLength.
+                // Suppose targetHex is "abcdefg", then the new version targetHex which has 3 "=" appended is "abcdefg==="
+                // And the length of the original base64 string is 8. When doing Base64::Decode() below, 
+                // only the first 8 chars of "abcdefg===" is considered.
                 hexLength = 4 * (targetlen / 4 + 1);
             }
 
-            Base64::Decode((unsigned char*)buffer, ACE_Wide_To_Ascii(targetHexOriginal.c_str()).char_rep(), hexLength);
+            char buffer[100] = {0};
+            Base64::Decode((unsigned char*)buffer, ACE_Wide_To_Ascii(targetHex.c_str()).char_rep(), hexLength);
             m_target = ACE_Ascii_To_Wide(buffer).wchar_rep();
             m_status = Ok;
         }

Modified: trunk/MgDev/Common/MapGuideCommon/Services/SiteManager.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SiteManager.cpp	2011-08-12 05:42:28 UTC (rev 6061)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SiteManager.cpp	2011-08-13 08:06:08 UTC (rev 6062)
@@ -501,26 +501,31 @@
 
     INT32 sitePort, clientPort, adminPort;
     STRING target;
-
-    // Compose a format string to extract the target address and the ports from the hexstring
+    // The length of the Base64 encoded target string
     INT32 targetlen = (INT32) hexString.length() - MgSiteInfo::HexPortsStringLength;
-    wchar_t format[20] = {0};
-    swprintf(format, 20, L"%%%ds%%4X%%4X%%4X", targetlen);
+    // Get the encoded target
+    STRING targetHex = hexString.substr(0, targetlen);
+    // Get the hexed port numbers
+    STRING portHex = hexString.substr(targetlen, MgSiteInfo::HexPortsStringLength); 
 
-    wchar_t targetHex[100] = {0};
-    if (::swscanf(hexString.c_str(), format, targetHex, &sitePort, &clientPort, &adminPort) == 4)
+    if (3 == ::swscanf (portHex.c_str(), L"%4X%4X%4X", &sitePort, &clientPort, &adminPort))
     {
-        char buffer[100] = {0};
         INT32 hexLength = targetlen;
-        STRING targetHexOriginal = targetHex;
-        // There were alignment "=" removed during encoding. They should be appended back to do decoding
+        // There were alignment "=" removed. They should be appended back to do decoding
         if (0 != targetlen % 4)
         {
-            targetHexOriginal.append(L"===");
+            // There could be at most 3 alignment "="
+            targetHex.append(L"===");
+            // Get the length of the string which has the alignment "=" restored.
+            // Please note that targetHex.length() >= hexLength.
+            // Suppose targetHex is "abcdefg", then the new version targetHex which has 3 "=" appended is "abcdefg==="
+            // And the length of the original base64 string is 8. When doing Base64::Decode() below, 
+            // only the first 8 chars of "abcdefg===" is considered.
             hexLength = 4 * (targetlen / 4 + 1);
         }
 
-        Base64::Decode((unsigned char*)buffer, ACE_Wide_To_Ascii(targetHexOriginal.c_str()).char_rep(), hexLength);
+        char buffer[100] = {0};
+        Base64::Decode((unsigned char*)buffer, ACE_Wide_To_Ascii(targetHex.c_str()).char_rep(), hexLength);
         target = ACE_Ascii_To_Wide(buffer).wchar_rep();
     }
 



More information about the mapguide-commits mailing list