VirtualBox

Changeset 10143 in vbox for trunk/src/VBox/Additions/common


Ignore:
Timestamp:
Jul 3, 2008 9:19:25 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
32669
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r10111 r10143  
    113113    uint32_t u32ClientID = 0;
    114114    int rc = VINF_SUCCESS;
    115 
     115    char *pszKey = NULL;
    116116    char szValue[KEY_MAX_VALUE_LEN];
     117
    117118    if (argc != 1)
    118119    {
     
    120121        return 1;
    121122    }
    122     rc = VbglR3InfoSvcConnect(&u32ClientID);
     123    rc = RTStrCurrentCPToUtf8(&pszKey, argv[0]);
    123124    if (!RT_SUCCESS(rc))
    124         VBoxControlError("Failed to connect to the guest property service, error %Rrc\n", rc);
     125        VBoxControlError("Failed to convert the key name to Utf8, error %Rrc\n", rc);
     126    if (RT_SUCCESS(rc))
     127    {
     128        rc = VbglR3InfoSvcConnect(&u32ClientID);
     129        if (!RT_SUCCESS(rc))
     130            VBoxControlError("Failed to connect to the guest property service, error %Rrc\n", rc);
     131    }
    125132    if (RT_SUCCESS(rc))
    126133    {
     
    129136            VBoxControlError("Failed to retrieve the property value, error %Rrc\n", rc);
    130137    }
    131     if (RT_SUCCESS(rc) || (VERR_NOT_FOUND == rc))
    132     {
    133         if (RT_SUCCESS(rc))
    134             RTPrintf("Value: %s\n", szValue);
    135         else
    136             RTPrintf("No value set!\n");
    137     }
     138    if (VERR_NOT_FOUND == rc)
     139        RTPrintf("No value set!\n");
     140    if (RT_SUCCESS(rc))
     141        RTPrintf("Value: %S\n", szValue);
    138142    if (u32ClientID != 0)
    139143        VbglR3InfoSvcDisconnect(u32ClientID);
     144    RTStrFree(pszKey);
    140145    return RT_SUCCESS(rc) ? 0 : 1;
    141146}
     
    153158static int setGuestProperty(int argc, char *argv[])
    154159{
     160    uint32_t u32ClientID = 0;
     161    int rc = VINF_SUCCESS;
     162    char *pszKey = NULL;
     163    char *pszValue = NULL;
     164
    155165    if (argc != 1 && argc != 2)
    156166    {
     
    158168        return 1;
    159169    }
    160     char *pszValue = NULL;
    161     int rc = VINF_SUCCESS;
    162     uint32_t u32ClientID = 0;
    163 
    164     if (2 == argc)
    165     pszValue = argv[1];
    166     rc = VbglR3InfoSvcConnect(&u32ClientID);
     170    rc = RTStrCurrentCPToUtf8(&pszKey, argv[0]);
    167171    if (!RT_SUCCESS(rc))
    168         VBoxControlError("Failed to connect to the host/guest registry service, error %Rrc\n", rc);
     172        VBoxControlError("Failed to convert the key name to Utf8, error %Rrc\n", rc);
     173    if (RT_SUCCESS(rc) && (2 == argc))
     174    {
     175        rc = RTStrCurrentCPToUtf8(&pszValue, argv[1]);
     176        if (!RT_SUCCESS(rc))
     177            VBoxControlError("Failed to convert the key value to Utf8, error %Rrc\n", rc);
     178    }
     179    if (RT_SUCCESS(rc))
     180    {
     181        rc = VbglR3InfoSvcConnect(&u32ClientID);
     182        if (!RT_SUCCESS(rc))
     183            VBoxControlError("Failed to connect to the host/guest registry service, error %Rrc\n", rc);
     184    }
    169185    if (RT_SUCCESS(rc))
    170186    {
     
    175191    if (u32ClientID != 0)
    176192        VbglR3InfoSvcDisconnect(u32ClientID);
     193    RTStrFree(pszKey);
     194    RTStrFree(pszValue);
    177195    return RT_SUCCESS(rc) ? 0 : 1;
    178196}
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