VirtualBox

Changeset 10142 in vbox for trunk


Ignore:
Timestamp:
Jul 3, 2008 9:18:18 AM (16 years ago)
Author:
vboxsync
Message:

Additions/WINNT: make the VBoxControl guest property functions utf8-safe

Location:
trunk/src/VBox/Additions/WINNT/VBoxControl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxControl/Makefile.kmk

    r10129 r10142  
    3636        VBoxControl.cpp \
    3737        VBoxControl.rc
     38VBoxControl_LIBS    += \
     39        $(VBOX_LIB_IPRT_GUEST_R3)
    3840
    3941# VBoxControl.cpp uses VBOX_SVN_REV.
  • trunk/src/VBox/Additions/WINNT/VBoxControl/VBoxControl.cpp

    r10094 r10142  
    2323#include <malloc.h>
    2424
     25#include <iprt/string.h>
     26#include <iprt/stream.h>
    2527#include <VBox/VBoxGuest.h>
    2628#include <VBox/version.h>
     
    951953    if (!VALID_PTR(pszKey))
    952954        return VERR_INVALID_POINTER;
    953     if (!VALID_PTR(pszValue) && (pszValue != NULL));
     955    if ((pszValue != NULL) && !VALID_PTR(pszValue))
     956        return VERR_INVALID_POINTER;
    954957    int rc;
    955958
     
    10141017static int handleGetGuestProperty(int argc, char *argv[])
    10151018{
     1019    HANDLE hDevice = INVALID_HANDLE_VALUE;
     1020    uint32_t u32ClientID = 0;
     1021    int rc = VINF_SUCCESS;
     1022    char *pszKey = NULL;
     1023    char szValue[svcInfo::KEY_MAX_VALUE_LEN];
     1024
    10161025    if (argc != 1)
    10171026    {
     
    10191028        return 1;
    10201029    }
    1021     char szValue[svcInfo::KEY_MAX_VALUE_LEN];
    1022     HANDLE hDevice = INVALID_HANDLE_VALUE;
    1023     uint32_t u32ClientID = 0;
    1024     int rc = openGuestDevice(&hDevice);
     1030    rc = RTStrCurrentCPToUtf8(&pszKey, argv[0]);
    10251031    if (!RT_SUCCESS(rc))
    1026         printf("Failed to open the VirtualBox device, RT error %d\n", rc);
     1032        RTPrintf("Failed to convert the key name to Utf8, error %Rrc\n", rc);
     1033    if (RT_SUCCESS(rc))
     1034    {
     1035        rc = openGuestDevice(&hDevice);
     1036        if (!RT_SUCCESS(rc))
     1037            RTPrintf("Failed to open the VirtualBox device, error %Rrc\n", rc);
     1038    }
    10271039    if (RT_SUCCESS(rc))
    10281040    {
    10291041        rc = hgcmConnect(hDevice, "VBoxSharedInfoSvc", &u32ClientID);
    10301042        if (!RT_SUCCESS(rc))
    1031             printf("Failed to connect to the host/guest registry service, RT error %d\n", rc);
     1043            RTPrintf("Failed to connect to the host/guest registry service, error %Rrc\n", rc);
    10321044    }
    10331045    if (RT_SUCCESS(rc))
    10341046    {
    1035         rc = hgcmInfoSvcGetProp(hDevice, u32ClientID, argv[0], szValue,
     1047        rc = hgcmInfoSvcGetProp(hDevice, u32ClientID, pszKey, szValue,
    10361048                                sizeof(szValue), NULL);
    10371049        if (!RT_SUCCESS(rc) && (rc != VERR_NOT_FOUND))
    1038             printf("Failed to retrieve the property value, RT error %d\n", rc);
    1039     }
    1040     if (RT_SUCCESS(rc) || (VERR_NOT_FOUND == rc))
    1041     {
    1042         if (RT_SUCCESS(rc))
    1043             printf("Value: %s\n", szValue);
    1044         else
    1045             printf("No value set!\n");
    1046     }
     1050            RTPrintf("Failed to retrieve the property value, error %Rrc\n", rc);
     1051    }
     1052    if (VERR_NOT_FOUND == rc)
     1053        RTPrintf("No value set!\n");
     1054    if (RT_SUCCESS(rc))
     1055        RTPrintf("Value: %S\n", szValue);
    10471056    if (u32ClientID != 0)
    10481057        hgcmDisconnect(hDevice, u32ClientID);
    10491058    if (hDevice != INVALID_HANDLE_VALUE)
    10501059        CloseHandle(hDevice);
     1060    RTStrFree(pszKey);
    10511061    return rc;
    10521062}
     
    10641074static int handleSetGuestProperty(int argc, char *argv[])
    10651075{
     1076    HANDLE hDevice = INVALID_HANDLE_VALUE;
     1077    uint32_t u32ClientID = 0;
     1078    int rc = VINF_SUCCESS;
     1079    char *pszKey = NULL;
     1080    char *pszValue = NULL;
     1081
    10661082    if (argc != 1 && argc != 2)
    10671083    {
     
    10691085        return 1;
    10701086    }
    1071     HANDLE hDevice = INVALID_HANDLE_VALUE;
    1072     char *pszValue = NULL;
    1073     if (2 == argc)
    1074         pszValue = argv[1];
    1075     uint32_t u32ClientID = 0;
    1076     int rc = openGuestDevice(&hDevice);
     1087    rc = RTStrCurrentCPToUtf8(&pszKey, argv[0]);
    10771088    if (!RT_SUCCESS(rc))
    1078         printf("Failed to open the VirtualBox device, RT error %d\n", rc);
     1089        RTPrintf("Failed to convert the key name to Utf8, error %Rrc\n", rc);
     1090    if (RT_SUCCESS(rc) && (2 == argc))
     1091    {
     1092        rc = RTStrCurrentCPToUtf8(&pszValue, argv[1]);
     1093        if (!RT_SUCCESS(rc))
     1094            RTPrintf("Failed to convert the key value to Utf8, error %Rrc\n", rc);
     1095    }
     1096    if (RT_SUCCESS(rc))
     1097    {
     1098        rc = openGuestDevice(&hDevice);
     1099        if (!RT_SUCCESS(rc))
     1100            RTPrintf("Failed to open the VirtualBox device, error %Rrc\n", rc);
     1101    }
    10791102    if (RT_SUCCESS(rc))
    10801103    {
    10811104        rc = hgcmConnect(hDevice, "VBoxSharedInfoSvc", &u32ClientID);
    10821105        if (!RT_SUCCESS(rc))
    1083             printf("Failed to connect to the host/guest registry service, RT error %d\n", rc);
     1106            RTPrintf("Failed to connect to the host/guest registry service, error %Rrc\n", rc);
    10841107    }
    10851108    if (RT_SUCCESS(rc))
    10861109    {
    1087         rc = hgcmInfoSvcSetProp(hDevice, u32ClientID, argv[0], pszValue);
     1110        rc = hgcmInfoSvcSetProp(hDevice, u32ClientID, pszKey, pszValue);
    10881111        if (!RT_SUCCESS(rc))
    1089             printf("Failed to store the property value, RT error %d\n", rc);
     1112            RTPrintf("Failed to store the property value, error %Rrc\n", rc);
    10901113    }
    10911114    if (u32ClientID != 0)
     
    10931116    if (hDevice != INVALID_HANDLE_VALUE)
    10941117        CloseHandle(hDevice);
     1118    RTStrFree(pszKey);
     1119    RTStrFree(pszValue);
    10951120    return rc;
    10961121}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette