[MSTSC]
authorKamil Hornicek <kamil.hornicek@reactos.org>
Wed, 18 Jan 2012 13:09:18 +0000 (13:09 +0000)
committerKamil Hornicek <kamil.hornicek@reactos.org>
Wed, 18 Jan 2012 13:09:18 +0000 (13:09 +0000)
- Fix some corner cases for settings parsing (empty values, values containing delimiters).
- If provided, take port number into account.

svn path=/trunk/; revision=55003

reactos/base/applications/mstsc/settings.c
reactos/base/applications/mstsc/win32.c

index 29a6d47..535f8ef 100644 (file)
@@ -230,6 +230,7 @@ ParseSettings(PRDPSETTINGS pRdpSettings,
 {
     LPWSTR lpStr = lpBuffer;
     WCHAR szSeps[] = L":\r\n";
+    WCHAR szNewline[] = L"\r\n";
     LPWSTR lpToken;
     BOOL bFound;
     INT i;
@@ -258,7 +259,7 @@ ParseSettings(PRDPSETTINGS pRdpSettings,
                 else if (lpToken[0] == L's')
                 {
                     pRdpSettings->pSettings[i].Type = lpToken[0];
-                    lpToken = wcstok(NULL, szSeps);
+                    lpToken = wcstok(NULL, szNewline);
                     if (lpToken != NULL)
                         wcscpy(pRdpSettings->pSettings[i].Value.s, lpToken);
                 }
@@ -268,10 +269,7 @@ ParseSettings(PRDPSETTINGS pRdpSettings,
 
         /* move past the type and value */
         if (!bFound)
-        {
-            lpToken = wcstok(NULL, szSeps);
-            lpToken = wcstok(NULL, szSeps);
-        }
+            lpToken = wcstok(NULL, szNewline);
 
         /* move to next key */
         lpToken = wcstok(NULL, szSeps);
index c7c4e63..8c9a9e1 100644 (file)
@@ -958,6 +958,29 @@ mi_paint_rect(char * data, int width, int height, int x, int y, int cx, int cy)
 
 }
 
+static INT
+GetPortNumber(PCHAR szAddress)
+{
+    PCHAR szPort;
+    INT iPort = TCP_PORT_RDP;
+
+    szPort = strtok(szAddress, ":");
+
+    if (szPort != NULL)
+    {
+        szPort = strtok(NULL, ":");
+
+        if (szPort != NULL)
+        {
+            iPort = atoi(szPort);
+
+            if (iPort <= 0 || iPort > 0xFFFF)
+                iPort = TCP_PORT_RDP;
+        }
+    }
+
+    return iPort;
+}
 
 static BOOL
 ParseCommandLine(LPWSTR lpCmdLine,
@@ -1051,8 +1074,9 @@ wWinMain(HINSTANCE hInstance,
 
                     uni_to_str(szValue, GetStringFromSettings(pRdpSettings, L"full address"));
 
+                    /* GetPortNumber also removes possible trailing port number from address */
+                    g_tcp_port_rdp = GetPortNumber(szValue);
                     strcpy(g_servername, szValue);
-                    //g_port = 3389;
                     strcpy(g_username, "");
                     strcpy(g_password, "");
                     g_server_depth = GetIntegerFromSettings(pRdpSettings, L"session bpp");