[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 2/3] Support for vrdp/sdl/gui while dumping xml



> > -                                def->graphics->data.rdp.autoport = 1;
> > +                                valueDisplayUtf8 = getenv("DISPLAY");
> > +                                valueDisplayFree = 0;
> >                              }
>
> Using getenv() here is not right, since that's running in the context of
> the app using libvirt. If there's no display available via virtualbox's
> API, then just leave this attribute blank when generating the XML.
>
>
> There's generally quite a few  uses of strdup() here without OOM
> checking

Fixed these two and reposting the patch.

Regards,
Pritesh
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4ef1488..85a336a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1366,9 +1366,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                 PRBool PAEEnabled                   = PR_FALSE;
                 PRBool ACPIEnabled                  = PR_FALSE;
                 PRBool IOAPICEnabled                = PR_FALSE;
-#if 0
                 PRBool VRDPEnabled                  = PR_FALSE;
-#endif
                 PRInt32 hddNum                      = 0;
                 PRUint32 CPUCount                   = 0;
                 PRUint32 memorySize                 = 0;
@@ -1387,9 +1385,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                 IHardDisk *hardDiskPS               = NULL;
                 IHardDisk *hardDiskSS               = NULL;
                 PRUnichar *hddBusUtf16              = NULL;
-#if 0
                 IVRDPServer *VRDPServer             = NULL;
-#endif
                 IFloppyDrive *floppyDrive           = NULL;
                 IAudioAdapter *audioAdapter         = NULL;
                 IUSBController *USBController       = NULL;
@@ -1482,83 +1478,162 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
                  * so locatime is always true here */
                 def->localtime = 1;
 
-#if 0
-                machine->vtbl->GetVRDPServer(machine, &VRDPServer);
-                if (VRDPServer) {
-                    VRDPServer->vtbl->GetEnabled(VRDPServer, &VRDPEnabled);
-                    if (VRDPEnabled) {
-                        if (VIR_ALLOC(def->graphics) >= 0) {
-                            PRUint32 VRDPport            = 0;
-                            PRUnichar *netAddressUtf16   = NULL;
-                            PRUnichar *sessionTypeUtf16  = NULL;
-                            char *sessionTypeUtf8        = NULL;
-                            char *netAddressUtf8         = NULL;
-                            PRUint32 authType            = VRDPAuthType_Null;
-                            PRBool allowMultiConnection  = PR_FALSE;
-                            PRBool reuseSingleConnection = PR_FALSE;
-
-                            def->graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_RDP;
-
-                            VRDPServer->vtbl->GetPort(VRDPServer, &VRDPport);
-                            if (VRDPport) {
-                                def->graphics->data.rdp.port = VRDPport;
-                            } else {
-                                def->graphics->data.rdp.autoport = 1;
+                /* dump display options vrdp/gui/sdl */
+                {
+                    int vrdpPresent           = 0;
+                    int sdlPresent            = 0;
+                    int guiPresent            = 0;
+                    int totalPresent          = 0;
+                    char *guiDisplay          = NULL;
+                    char *sdlDisplay          = NULL;
+                    PRUnichar *keyTypeUtf16   = NULL;
+                    PRUnichar *valueTypeUtf16 = NULL;
+                    char      *valueTypeUtf8  = NULL;
+
+                    def->ngraphics = 0;
+
+                    data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Type", &keyTypeUtf16);
+                    machine->vtbl->GetExtraData(machine, keyTypeUtf16, &valueTypeUtf16);
+                    data->pFuncs->pfnUtf16Free(keyTypeUtf16);
+
+                    if (valueTypeUtf16) {
+                        data->pFuncs->pfnUtf16ToUtf8(valueTypeUtf16, &valueTypeUtf8);
+                        data->pFuncs->pfnUtf16Free(valueTypeUtf16);
+
+                        if ( STREQ(valueTypeUtf8, "sdl") || STREQ(valueTypeUtf8, "gui") ) {
+                            PRUnichar *keyDislpayUtf16   = NULL;
+                            PRUnichar *valueDisplayUtf16 = NULL;
+                            char      *valueDisplayUtf8  = NULL;
+
+                            data->pFuncs->pfnUtf8ToUtf16("FRONTEND/Display", &keyDislpayUtf16);
+                            machine->vtbl->GetExtraData(machine, keyDislpayUtf16, &valueDisplayUtf16);
+                            data->pFuncs->pfnUtf16Free(keyDislpayUtf16);
+
+                            if (valueDisplayUtf16) {
+                                data->pFuncs->pfnUtf16ToUtf8(valueDisplayUtf16, &valueDisplayUtf8);
+                                data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
+
+                                if (strlen(valueDisplayUtf8) <= 0) {
+                                    data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+                                    valueDisplayUtf8 = NULL;
+                                }
                             }
 
-                            VRDPServer->vtbl->GetNetAddress(VRDPServer, &netAddressUtf16);
-                            if (netAddressUtf16) {
-                                data->pFuncs->pfnUtf16ToUtf8(netAddressUtf16, &netAddressUtf8);
-                                if (STRNEQ(netAddressUtf8, ""))
-                                        def->graphics->data.rdp.listenAddr = strdup(netAddressUtf8);
-                                data->pFuncs->pfnUtf16Free(netAddressUtf16);
-                                data->pFuncs->pfnUtf8Free(netAddressUtf8);
+                            if (STREQ(valueTypeUtf8, "sdl")) {
+                                sdlPresent = 1;
+                                if (valueDisplayUtf8)
+                                    sdlDisplay = strdup(valueDisplayUtf8);
+                                if (sdlDisplay == NULL) {
+                                    vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+                                    /* just don't go to cleanup yet as it is ok to have
+                                     * sdlDisplay as NULL and we check it below if it
+                                     * exist and then only use it there
+                                     */
+                                }
+                                totalPresent++;
                             }
 
-                            VRDPServer->vtbl->GetAuthType(VRDPServer, &authType);
-                            if (authType == VRDPAuthType_External) {
-                                PRUint32 authTimeout = 0;
+                            if (STREQ(valueTypeUtf8, "gui")) {
+                                guiPresent = 1;
+                                if (valueDisplayUtf8)
+                                    guiDisplay = strdup(valueDisplayUtf8);
+                                if (guiDisplay == NULL) {
+                                    vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+                                    /* just don't go to cleanup yet as it is ok to have
+                                     * guiDisplay as NULL and we check it below if it
+                                     * exist and then only use it there
+                                     */
+                                }
+                                totalPresent++;
+                            }
+                            if (valueDisplayUtf8)
+                                data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
+                        }
 
-                                VRDPServer->vtbl->GetAuthTimeout(VRDPServer, &authTimeout);
+                        if (STREQ(valueTypeUtf8, "vrdp"))
+                            vrdpPresent = 1;
 
-                                def->graphics->data.rdp.auth = strdup("external");
-                                def->graphics->data.rdp.authtimeout = authTimeout;
-                            } else if (authType == VRDPAuthType_Guest) {
-                                PRUint32 authTimeout = 0;
+                        data->pFuncs->pfnUtf8Free(valueTypeUtf8);
+                    }
 
-                                VRDPServer->vtbl->GetAuthTimeout(VRDPServer, &authTimeout);
+                    if ((totalPresent > 0) && (VIR_ALLOC_N(def->graphics, totalPresent) >= 0)) {
+                        if ((guiPresent) && (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
+                            if (guiDisplay)
+                                def->graphics[def->ngraphics]->data.desktop.display = guiDisplay;
+                            def->ngraphics++;
+                        }
 
-                                def->graphics->data.rdp.auth = strdup("guest");
-                                def->graphics->data.rdp.authtimeout = authTimeout;
+                        if ((sdlPresent) && (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
+                            if (sdlDisplay)
+                                def->graphics[def->ngraphics]->data.sdl.display = sdlDisplay;
+                            def->ngraphics++;
+                        }
+                    } else if ((vrdpPresent != 1) && (totalPresent == 0) && (VIR_ALLOC_N(def->graphics, 1) >= 0)) {
+                        if (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0) {
+                            def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
+                            def->graphics[def->ngraphics]->data.desktop.display = strdup(getenv("DISPLAY"));
+                            if (def->graphics[def->ngraphics]->data.desktop.display == NULL) {
+                                vboxError(dom->conn, VIR_ERR_SYSTEM_ERROR, "%s", "strdup failed");
+                                /* just don't go to cleanup yet as it is ok to have
+                                 * display as NULL
+                                 */
                             }
+                            totalPresent++;
+                            def->ngraphics++;
+                        }
+                    }
 
+                    machine->vtbl->GetVRDPServer(machine, &VRDPServer);
+                    if (VRDPServer) {
+                        VRDPServer->vtbl->GetEnabled(VRDPServer, &VRDPEnabled);
+                        if (VRDPEnabled) {
 
-                            VRDPServer->vtbl->GetAllowMultiConnection(VRDPServer, &allowMultiConnection);
-                            if (allowMultiConnection) {
-                                def->graphics->data.rdp.multiconnections = 1;
-                            }
+                            totalPresent++;
 
-                            VRDPServer->vtbl->GetReuseSingleConnection(VRDPServer, &reuseSingleConnection);
-                            if (reuseSingleConnection) {
-                                def->graphics->data.rdp.reuseconnection = 1;
-                            }
+                            if ((VIR_REALLOC_N(def->graphics, totalPresent) >= 0) &&
+                                (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0)) {
+                                PRUint32 VRDPport            = 0;
+                                PRUnichar *netAddressUtf16   = NULL;
+                                char      *netAddressUtf8    = NULL;
+                                PRBool allowMultiConnection  = PR_FALSE;
+                                PRBool reuseSingleConnection = PR_FALSE;
+
+                                def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_RDP;
+
+                                VRDPServer->vtbl->GetPort(VRDPServer, &VRDPport);
+                                if (VRDPport) {
+                                    def->graphics[def->ngraphics]->data.rdp.port = VRDPport;
+                                } else {
+                                    def->graphics[def->ngraphics]->data.rdp.autoport = 1;
+                                }
 
-                            machine->vtbl->GetSessionType(machine, &sessionTypeUtf16);
-                            DEBUG0("Session Type:");
-                            if (sessionTypeUtf16) {
-                                data->pFuncs->pfnUtf16ToUtf8(sessionTypeUtf16, &sessionTypeUtf8);
-                                DEBUG("Session Type: %s", sessionTypeUtf8);
-                                if (STREQ(sessionTypeUtf8, "vrdp")) {
-                                    def->graphics->data.rdp.headless = 1;
+                                VRDPServer->vtbl->GetNetAddress(VRDPServer, &netAddressUtf16);
+                                if (netAddressUtf16) {
+                                    data->pFuncs->pfnUtf16ToUtf8(netAddressUtf16, &netAddressUtf8);
+                                    if (STRNEQ(netAddressUtf8, ""))
+                                            def->graphics[def->ngraphics]->data.rdp.listenAddr = strdup(netAddressUtf8);
+                                    data->pFuncs->pfnUtf16Free(netAddressUtf16);
+                                    data->pFuncs->pfnUtf8Free(netAddressUtf8);
                                 }
-                                data->pFuncs->pfnUtf16Free(sessionTypeUtf16);
-                                data->pFuncs->pfnUtf8Free(sessionTypeUtf8);
+
+                                VRDPServer->vtbl->GetAllowMultiConnection(VRDPServer, &allowMultiConnection);
+                                if (allowMultiConnection) {
+                                    def->graphics[def->ngraphics]->data.rdp.multiUser = 1;
+                                }
+
+                                VRDPServer->vtbl->GetReuseSingleConnection(VRDPServer, &reuseSingleConnection);
+                                if (reuseSingleConnection) {
+                                    def->graphics[def->ngraphics]->data.rdp.replaceUser = 1;
+                                }
+
+                                def->ngraphics++;
                             }
                         }
+                        VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
                     }
-                    VRDPServer->vtbl->nsisupports.Release((nsISupports *)VRDPServer);
                 }
-#endif
 
                 /* dump IDE hdds if present */
                 data->pFuncs->pfnUtf8ToUtf16(hddBus, &hddBusUtf16);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]