diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 9dca1c70719087fdd721223aec0a9ad93e7fe110..20be6bafc4975d4bd18a37839eb023b1406d3f59 100644 --- a/samples/vboxwrapper/vbox.cpp +++ b/samples/vboxwrapper/vbox.cpp @@ -920,19 +920,22 @@ int VBOX_VM::create_vm() { // set up port forwarding // - if (pf_guest_port) { - PORT_FORWARD pf; - pf.guest_port = pf_guest_port; - pf.host_port = pf_host_port; - if (!pf_host_port) { - retval = boinc_get_port(false, pf.host_port); - if (retval) return retval; - pf_host_port = pf.host_port; - } - port_forwards.push_back(pf); - } for (unsigned int i=0; i<port_forwards.size(); i++) { PORT_FORWARD& pf = port_forwards[i]; + + // Web application support means apache is running within the VM. + // It also means we need to persist the host port number across multiple + // restarts of vboxwrapper. This code chunk really needs to be moved to + // vboxwrapper.cpp. + if (pf.web_application) { + if (!pf.host_port) { + retval = boinc_get_port(false, pf.host_port); + if (retval) return retval; + pf_host_port = pf.host_port; + pf_guest_port = pf.guest_port; + } + } + fprintf( stderr, "%s forwarding host port %d to guest port %d\n", diff --git a/samples/vboxwrapper/vbox.h b/samples/vboxwrapper/vbox.h index 7f09df9845e4508f3a6f3bca44c4a172b5b748d5..2010fd943468adb6875820b36d61b7f7fac1386e 100644 --- a/samples/vboxwrapper/vbox.h +++ b/samples/vboxwrapper/vbox.h @@ -74,13 +74,14 @@ struct PORT_FORWARD { int host_port; // 0 means assign dynamically int guest_port; bool is_remote; + bool web_application; PORT_FORWARD() { host_port = 0; guest_port = 0; is_remote = false; + web_application = false; } - int get_host_port(); // assign host port }; // represents a VirtualBox VM @@ -214,8 +215,6 @@ public: #endif int initialize(); - int parse_port_forward(XML_PARSER&); - void set_web_graphics_url(); void poll(bool log_state = true); int create_vm(); diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index d9b90e2b472d747aa776d7c9145eea3970895892..3a9d114dd2c01230f28058174f0bbc4caae447b2 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -126,36 +126,39 @@ char* vboxwrapper_msg_prefix(char* sbuf, int len) { return sbuf; } -int VBOX_VM::parse_port_forward(XML_PARSER& xp) { +int parse_port_forward(XML_PARSER& xp, VBOX_VM& vm) { int host_port=0, guest_port=0, nports=1; - bool is_remote; + bool is_remote = false, web_application = false; + char buf[256]; while (!xp.get_tag()) { if (xp.match_tag("/port_forward")) { - if (!host_port) { - fprintf(stderr, "parse_port_forward: unspecified host port\n"); - return ERR_XML_PARSE; - } if (!guest_port) { - fprintf(stderr, "parse_port_forward: unspecified guest port\n"); - return ERR_XML_PARSE; + fprintf(stderr, "%s parse_port_forward(): unspecified guest port\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)) + ); } PORT_FORWARD pf; pf.host_port = host_port; pf.guest_port = guest_port; pf.is_remote = is_remote; + pf.web_application = web_application; for (int i=0; i<nports; i++) { - port_forwards.push_back(pf); + vm.port_forwards.push_back(pf); pf.host_port++; pf.guest_port++; + pf.web_application = false; } return 0; } + else if (xp.parse_bool("web_application", web_application)) continue; else if (xp.parse_bool("is_remote", is_remote)) continue; else if (xp.parse_int("host_port", host_port)) continue; else if (xp.parse_int("guest_port", guest_port)) continue; else if (xp.parse_int("nports", nports)) continue; else { - fprintf(stderr, "parse_port_forward: unparsed %s\n", xp.parsed_tag); + fprintf(stderr, "%s parse_port_forward(): unexpected tag %s\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)), xp.parsed_tag + ); } } return ERR_XML_PARSE; @@ -164,6 +167,7 @@ int VBOX_VM::parse_port_forward(XML_PARSER& xp) { int parse_job_file(VBOX_VM& vm) { INTERMEDIATE_UPLOAD iu; MIOFILE mf; + int guest_port=0; string str; char buf[1024], buf2[256]; @@ -206,8 +210,15 @@ int parse_job_file(VBOX_VM& vm) { else if (xp.parse_bool("enable_cache_disk", vm.enable_cache_disk)) continue; else if (xp.parse_bool("enable_isocontextualization", vm.enable_isocontextualization)) continue; else if (xp.parse_bool("enable_remotedesktop", vm.enable_remotedesktop)) continue; - else if (xp.parse_int("pf_guest_port", vm.pf_guest_port)) continue; - else if (xp.parse_int("pf_host_port", vm.pf_host_port)) continue; + else if (xp.parse_int("pf_guest_port", guest_port)) { + PORT_FORWARD pf; + pf.host_port = 0; + pf.guest_port = guest_port; + pf.is_remote = false; + pf.web_application = true; + vm.port_forwards.push_back(pf); + continue; + } else if (xp.parse_string("copy_to_shared", str)) { vm.copy_to_shared.push_back(str); continue; @@ -231,11 +242,13 @@ int parse_job_file(VBOX_VM& vm) { continue; } else if (xp.match_tag("port_forward")) { - vm.parse_port_forward(xp); + parse_port_forward(xp, vm); + } + else { + fprintf(stderr, "%s parse_job_file(): unexpected tag %s\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)), xp.parsed_tag + ); } - fprintf(stderr, "%s parse_job_file(): unexpected tag %s\n", - vboxwrapper_msg_prefix(buf, sizeof(buf)), xp.parsed_tag - ); } fclose(f); return ERR_XML_PARSE; @@ -428,11 +441,11 @@ void set_floppy_image(APP_INIT_DATA& aid, VBOX_VM& vm) { // if there's a port for web graphics, tell the client about it // -void VBOX_VM::set_web_graphics_url() { +void set_web_graphics_url(VBOX_VM& vm) { char buf[256]; - for (unsigned int i=0; i<port_forwards.size(); i++) { - PORT_FORWARD& pf = port_forwards[i]; - if (pf.guest_port == pf_guest_port) { + for (unsigned int i=0; i<vm.port_forwards.size(); i++) { + PORT_FORWARD& pf = vm.port_forwards[i]; + if (pf.web_application) { sprintf(buf, "http://localhost:%d", pf.host_port); boinc_web_graphics_url(buf); break; @@ -1121,8 +1134,7 @@ int main(int argc, char** argv) { } set_floppy_image(aid, vm); - //set_port_forwarding_info(aid, vm); - vm.set_web_graphics_url(); + set_web_graphics_url(vm); set_remote_desktop_info(aid, vm); write_checkpoint(elapsed_time, current_cpu_time, vm); diff --git a/win_build/vboxwrapper.vcxproj b/win_build/vboxwrapper.vcxproj index 841b05df29184b7be6515b1b8c74bf875b4e639a..284de133b21d2b9e34c738c32eb94beb21089bde 100644 --- a/win_build/vboxwrapper.vcxproj +++ b/win_build/vboxwrapper.vcxproj @@ -89,6 +89,10 @@ <CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> <CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> + <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">vboxwrapper_26108_windows_intelx86</TargetName> + <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">vboxwrapper_26109_windows_intelx86</TargetName> + <TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">vboxwrapper_26108_windows_x86_64</TargetName> + <TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">vboxwrapper_26109_windows_x86_64</TargetName> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <Midl> @@ -129,12 +133,12 @@ </ResourceCompile> <Link> <AdditionalDependencies>libcmt.lib;libcpmt.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> - <OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_intelx86.exe</OutputFile> + <OutputFile>.\Build\$(Platform)\$(Configuration)\$(TargetFileName)</OutputFile> <SuppressStartupBanner>true</SuppressStartupBanner> <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs> <GenerateDebugInformation>true</GenerateDebugInformation> - <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_intelx86.pdb</ProgramDatabaseFile> + <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\$(TargetName).pdb</ProgramDatabaseFile> <SubSystem>Windows</SubSystem> <TargetMachine>MachineX86</TargetMachine> </Link> @@ -179,12 +183,12 @@ </ResourceCompile> <Link> <AdditionalDependencies>libcmt.lib;libcpmt.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> - <OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_x86_64.exe</OutputFile> + <OutputFile>.\Build\$(Platform)\$(Configuration)\$(TargetFileName)</OutputFile> <SuppressStartupBanner>true</SuppressStartupBanner> <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs> <GenerateDebugInformation>true</GenerateDebugInformation> - <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_x86_64.pdb</ProgramDatabaseFile> + <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\$(TargetName).pdb</ProgramDatabaseFile> <SubSystem>Windows</SubSystem> <TargetMachine>MachineX64</TargetMachine> </Link> @@ -225,12 +229,12 @@ </ResourceCompile> <Link> <AdditionalDependencies>libcmtd.lib;libcpmtd.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;psapi.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> - <OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_6.1_windows_intelx86.exe</OutputFile> + <OutputFile>.\Build\$(Platform)\$(Configuration)\$(TargetFileName)</OutputFile> <SuppressStartupBanner>true</SuppressStartupBanner> <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs> <GenerateDebugInformation>true</GenerateDebugInformation> - <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_6.1_windows_intelx86.pdb</ProgramDatabaseFile> + <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\$(TargetName).pdb</ProgramDatabaseFile> <SubSystem>Windows</SubSystem> <TargetMachine>MachineX86</TargetMachine> </Link> @@ -271,12 +275,12 @@ </ResourceCompile> <Link> <AdditionalDependencies>libcmtd.lib;libcpmtd.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies> - <OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26063_windows_x86_64.exe</OutputFile> + <OutputFile>.\Build\$(Platform)\$(Configuration)\$(TargetFileName)</OutputFile> <SuppressStartupBanner>true</SuppressStartupBanner> <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries> <DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs> <GenerateDebugInformation>true</GenerateDebugInformation> - <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26063_windows_x86_64.pdb</ProgramDatabaseFile> + <ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\$(TargetName).pdb</ProgramDatabaseFile> <SubSystem>Windows</SubSystem> <TargetMachine>MachineX64</TargetMachine> </Link>