| 113 | 5. '''Change the way encoding Site IpAddress into SessionId''' |
| 114 | MapGuide Server encodes the IP address of site server into the Session Id so that it could pick the right site server from the list by comparing the IP address. |
| 115 | The encoding logic currently is: '''{{{(INTERNAL_API)}}}''' |
| 116 | {{{ |
| 117 | STRING MgSiteInfo::ToHexString() |
| 118 | { |
| 119 | STRING hexString; |
| 120 | UINT32 n1, n2, n3, n4; |
| 121 | wchar_t buffer[30]; |
| 122 | if (4 == ::swscanf(m_target.c_str(), L"%u.%u.%u.%u", &n1, &n2, &n3, &n4)) |
| 123 | { |
| 124 | swprintf(buffer, 30, L"%.2X%.2X%.2X%.2X%.4X%.4X%.4X", n1, n2, n3, n4, |
| 125 | m_sitePort, m_clientPort, m_adminPort); |
| 126 | hexString = buffer; |
| 127 | } |
| 128 | |
| 129 | return hexString; |
| 130 | } |
| 131 | }}} |
| 132 | Then it works for only IPv4. And for IPv6, because the valid format is really complicated, then convert it to a hex string is difficult. |
| 133 | The solution is: encode the IP as Base64 string. The port numbers will still be converted to hex string so that they could be easily decoded. |
| 134 | Then the new method will be like: |
| 135 | {{{ |
| 136 | STRING MgSiteInfo::ToHexString() |
| 137 | { |
| 138 | STRING hexString; |
| 139 | |
| 140 | char buf[100] = {0}; |
| 141 | char* target = ACE_Wide_To_Ascii(m_target.c_str()).char_rep(); |
| 142 | Base64::Encode(buf, (unsigned char*)target, (unsigned long)strlen(target)); |
| 143 | |
| 144 | wchar_t buffer[100] = {0}; |
| 145 | swprintf(buffer, L"%s%.4X%.4X%.4X", ACE_Ascii_To_Wide(buf).wchar_rep(), |
| 146 | m_sitePort, m_clientPort, m_adminPort); |
| 147 | hexString = buffer; |
| 148 | |
| 149 | return hexString; |
| 150 | } |
| 151 | }}} |
| 152 | One thing that needs attention is: A Base64 string might have “=” appended at the end for alignment. But “=” is treated as a reserved character. The solutions is: we remove all appending “=” when doing encoding, and then append them back when doing decoding |
| 153 | |