[libvirt] [PATCH 2/3] Support for vrdp/sdl/gui while dumping xml
Daniel P. Berrange
berrange at redhat.com
Mon May 11 10:23:49 UTC 2009
On Thu, May 07, 2009 at 03:49:38PM +0200, Pritesh Kothari wrote:
>
> Hi All,
>
> I have added support for vrdp/sdl/gui modes for VirtualBox driver in libvirt.
> Tha patch's are as below:
>
> [PATCH 1/3]: contains support for vrdp/sdl/gui while defining a machine.
> [PATCH 2/3]: contains support for vrdp/sdl/gui while dumping xml
> [PATCH 3/3]: contains support for vrdp/sdl/gui while starting the machine
>
> Regards,
> Pritesh
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index 87db6ab..223009a 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> +
> + if (valueDisplayUtf16) {
> + data->pFuncs->pfnUtf16ToUtf8(valueDisplayUtf16, &valueDisplayUtf8);
> + data->pFuncs->pfnUtf16Free(valueDisplayUtf16);
> +
> + if (strlen(valueDisplayUtf8) <= 0) {
> + data->pFuncs->pfnUtf8Free(valueDisplayUtf8);
> + valueDisplayUtf8 = getenv("DISPLAY");
> + valueDisplayFree = 0;
> + }
> } else {
> - 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.
>
> - 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;
> + sdlDisplay = strdup(valueDisplayUtf8);
> + totalPresent++;
> }
>
> - VRDPServer->vtbl->GetAuthType(VRDPServer, &authType);
> - if (authType == VRDPAuthType_External) {
> - PRUint32 authTimeout = 0;
> + if (STREQ(valueTypeUtf8, "gui")) {
> + guiPresent = 1;
> + guiDisplay = strdup(valueDisplayUtf8);
> + totalPresent++;
> + }
> + if (valueDisplayFree)
> + 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;
> + 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;
> + 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"));
> + totalPresent++;
> + def->ngraphics++;
> + }
> + }
> +
> + machine->vtbl->GetVRDPServer(machine, &VRDPServer);
> + if (VRDPServer) {
> + VRDPServer->vtbl->GetEnabled(VRDPServer, &VRDPEnabled);
> + if (VRDPEnabled) {
>
> + totalPresent++;
>
> - VRDPServer->vtbl->GetAllowMultiConnection(VRDPServer, &allowMultiConnection);
> - if (allowMultiConnection) {
> - def->graphics->data.rdp.multiconnections = 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;
>
> - VRDPServer->vtbl->GetReuseSingleConnection(VRDPServer, &reuseSingleConnection);
> - if (reuseSingleConnection) {
> - def->graphics->data.rdp.reuseconnection = 1;
> - }
> + def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_RDP;
>
> - 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->GetPort(VRDPServer, &VRDPport);
> + if (VRDPport) {
> + def->graphics[def->ngraphics]->data.rdp.port = VRDPport;
> + } else {
> + def->graphics[def->ngraphics]->data.rdp.autoport = 1;
> }
> - data->pFuncs->pfnUtf16Free(sessionTypeUtf16);
> - data->pFuncs->pfnUtf8Free(sessionTypeUtf8);
> +
> + 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);
> + }
> +
> + 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
There's generally quite a few uses of strdup() here without OOM
checking
Regards,
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
More information about the libvir-list
mailing list