Changeset 40130 in vbox for trunk/src/VBox/Main/webservice
- Timestamp:
- Feb 14, 2012 3:17:35 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 76274
- Location:
- trunk/src/VBox/Main/webservice
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/webservice/Makefile.kmk
r39876 r40130 7 7 8 8 # 9 # Copyright (C) 2006-201 1Oracle Corporation9 # Copyright (C) 2006-2012 Oracle Corporation 10 10 # 11 11 # This file is part of VirtualBox Open Source Edition (OSE), as … … 212 212 $(VBOXWEB_OUT_DIR) \ 213 213 $(PATH_SUB_CURRENT) 214 ifdef VBOX_WITH_WEBSERVICES_SSL 215 vboxsoap_DEFS += WITH_OPENSSL 216 vboxsoap_SDKS += VBOX_OPENSSL2 217 endif 214 218 ifdef VBOX_WITHOUT_SPLIT_SOAPC 215 219 vboxsoap_SOURCES = \ … … 287 291 vboxwebsrv_LIBS += \ 288 292 $(PATH_STAGE_LIB)/vboxsoap$(VBOX_SUFF_LIB) \ 289 $(VBOX_GSOAP_CXX_LIBS) 293 $(VBOX_GSOAP_CXX_LIBS) \ 294 $(LIB_RUNTIME) 290 295 vboxwebsrv_LIBS.solaris += socket nsl 296 ifdef VBOX_WITH_WEBSERVICES_SSL 297 vboxwebsrv_DEFS += WITH_OPENSSL 298 vboxwebsrv_SDKS += VBOX_OPENSSL2 299 endif 291 300 vboxwebsrv_SOURCES = \ 292 301 vboxweb.cpp \ … … 430 439 webtest_LIBS += \ 431 440 $(PATH_STAGE_LIB)/vboxsoap$(VBOX_SUFF_LIB) \ 432 $(VBOX_GSOAP_CXX_LIBS) 441 $(VBOX_GSOAP_CXX_LIBS) \ 442 $(LIB_RUNTIME) 433 443 webtest_LIBS.solaris += nsl 444 ifdef VBOX_WITH_WEBSERVICES_SSL 445 webtest_DEFS += WITH_OPENSSL 446 webtest_SDKS += VBOX_OPENSSL2 447 endif 434 448 webtest_SOURCES = \ 435 449 webtest.cpp \ -
trunk/src/VBox/Main/webservice/vboxweb.cpp
r38802 r40130 6 6 * server, to which clients can connect. 7 7 * 8 * Copyright (C) 2006-201 1Oracle Corporation8 * Copyright (C) 2006-2012 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 23 23 #include <VBox/com/com.h> 24 24 #include <VBox/com/array.h> 25 #include <VBox/com/string.h> 25 26 #include <VBox/com/ErrorInfo.h> 26 27 #include <VBox/com/errorprint.h> … … 42 43 #include <iprt/rand.h> 43 44 #include <iprt/semaphore.h> 45 #include <iprt/critsect.h> 44 46 #include <iprt/string.h> 45 47 #include <iprt/thread.h> … … 48 50 #include <iprt/system.h> 49 51 #include <iprt/base64.h> 52 #include <iprt/stream.h> 50 53 51 54 // workaround for compile problems on gcc 4.1 … … 75 78 76 79 RT_C_DECLS_END 80 81 static void WebLogSoapError(struct soap *soap); 77 82 78 83 /**************************************************************************** … … 117 122 unsigned int g_uBindToPort = 18083; // port 118 123 unsigned int g_uBacklog = 100; // backlog = max queue size for requests 124 125 #ifdef WITH_OPENSSL 126 bool g_fSSL = false; // if SSL is enabled 127 const char *g_pcszKeyFile = NULL; // server key file 128 const char *g_pcszPassword = NULL; // password for server key 129 const char *g_pcszCACert = NULL; // file with trusted CA certificates 130 const char *g_pcszCAPath = NULL; // directory with trusted CA certificates 131 const char *g_pcszDHFile = NULL; // DH file name or DH key length in bits, NULL=use RSA 132 const char *g_pcszRandFile = NULL; // file with random data seed 133 const char *g_pcszSID = "vboxwebsrv"; // server ID for SSL session cache 134 #endif /* WITH_OPENSSL */ 135 119 136 unsigned int g_cMaxWorkerThreads = 100; // max. no. of worker threads 120 137 unsigned int g_cMaxKeepAlive = 100; // maximum number of soap requests in one connection 138 139 const char *g_pcszAuthentication = NULL; // web service authentication 121 140 122 141 uint32_t g_cHistory = 10; // enable log rotation, 10 files … … 180 199 { "--host", 'H', RTGETOPT_REQ_STRING }, 181 200 { "--port", 'p', RTGETOPT_REQ_UINT32 }, 201 #ifdef WITH_OPENSSL 202 { "--ssl", 's', RTGETOPT_REQ_NOTHING }, 203 { "--keyfile", 'K', RTGETOPT_REQ_STRING }, 204 { "--passwordfile", 'a', RTGETOPT_REQ_STRING }, 205 { "--cacert", 'c', RTGETOPT_REQ_STRING }, 206 { "--capath", 'C', RTGETOPT_REQ_STRING }, 207 { "--dhfile", 'D', RTGETOPT_REQ_STRING }, 208 { "--randfile", 'r', RTGETOPT_REQ_STRING }, 209 #endif /* WITH_OPENSSL */ 182 210 { "--timeout", 't', RTGETOPT_REQ_UINT32 }, 183 211 { "--check-interval", 'i', RTGETOPT_REQ_UINT32 }, 184 212 { "--threads", 'T', RTGETOPT_REQ_UINT32 }, 185 213 { "--keepalive", 'k', RTGETOPT_REQ_UINT32 }, 214 { "--authentication", 'A', RTGETOPT_REQ_STRING }, 186 215 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }, 187 216 { "--pidfile", 'P', RTGETOPT_REQ_STRING }, … … 226 255 break; 227 256 257 #ifdef WITH_OPENSSL 258 case 's': 259 pcszDescr = "Enable SSL/TLS encryption."; 260 break; 261 262 case 'K': 263 pcszDescr = "Server key and certificate file, PEM format (\"\")."; 264 break; 265 266 case 'a': 267 pcszDescr = "File name for password to server key (\"\")."; 268 break; 269 270 case 'c': 271 pcszDescr = "CA certificate file, PEM format (\"\")."; 272 break; 273 274 case 'C': 275 pcszDescr = "CA certificate path (\"\")."; 276 break; 277 278 case 'D': 279 pcszDescr = "DH file name or DH key length in bits (\"\")."; 280 break; 281 282 case 'r': 283 pcszDescr = "File containing seed for random number generator (\"\")."; 284 break; 285 #endif /* WITH_OPENSSL */ 286 228 287 case 't': 229 288 pcszDescr = "Session timeout in seconds; 0 = disable timeouts (" DEFAULT_TIMEOUT_SECS_STRING ")."; … … 236 295 case 'k': 237 296 pcszDescr = "Maximum number of requests before a socket will be closed (100)."; 297 break; 298 299 case 'A': 300 pcszDescr = "Authentication method for the webservice (\"\")."; 238 301 break; 239 302 … … 516 579 m_soap->recv_timeout = 60; 517 580 // process the request; this goes into the COM code in methodmaps.cpp 518 soap_serve(m_soap); 581 do { 582 #ifdef WITH_OPENSSL 583 if (g_fSSL && soap_ssl_accept(m_soap)) 584 { 585 WebLogSoapError(m_soap); 586 break; 587 } 588 #endif /* WITH_OPENSSL */ 589 soap_serve(m_soap); 590 } while (0); 519 591 520 592 soap_destroy(m_soap); // clean up class instances … … 632 704 * @param soap 633 705 */ 706 /*static*/ 634 707 void WebLogSoapError(struct soap *soap) 635 708 { … … 715 788 } 716 789 790 #ifdef WITH_OPENSSL 717 791 /**************************************************************************** 718 792 * 793 * OpenSSL convenience functions for multithread support 794 * 795 ****************************************************************************/ 796 797 static RTCRITSECT *g_pSSLMutexes = NULL; 798 799 struct CRYPTO_dynlock_value 800 { 801 RTCRITSECT mutex; 802 }; 803 804 static unsigned long CRYPTO_id_function() 805 { 806 return RTThreadNativeSelf(); 807 } 808 809 static void CRYPTO_locking_function(int mode, int n, const char * /*file*/, int /*line*/) 810 { 811 if (mode & CRYPTO_LOCK) 812 RTCritSectEnter(&g_pSSLMutexes[n]); 813 else 814 RTCritSectLeave(&g_pSSLMutexes[n]); 815 } 816 817 static struct CRYPTO_dynlock_value *CRYPTO_dyn_create_function(const char * /*file*/, int /*line*/) 818 { 819 struct CRYPTO_dynlock_value *value = (struct CRYPTO_dynlock_value *)RTMemAlloc(sizeof(struct CRYPTO_dynlock_value)); 820 if (value) 821 RTCritSectInit(&value->mutex); 822 823 return value; 824 } 825 826 static void CRYPTO_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *value, const char * /*file*/, int /*line*/) 827 { 828 if (mode & CRYPTO_LOCK) 829 RTCritSectEnter(&value->mutex); 830 else 831 RTCritSectLeave(&value->mutex); 832 } 833 834 static void CRYPTO_dyn_destroy_function(struct CRYPTO_dynlock_value *value, const char * /*file*/, int /*line*/) 835 { 836 if (value) 837 { 838 RTCritSectDelete(&value->mutex); 839 free(value); 840 } 841 } 842 843 static int CRYPTO_thread_setup() 844 { 845 int num_locks = CRYPTO_num_locks(); 846 g_pSSLMutexes = (RTCRITSECT *)RTMemAlloc(num_locks * sizeof(RTCRITSECT)); 847 if (!g_pSSLMutexes) 848 return SOAP_EOM; 849 850 for (int i = 0; i < num_locks; i++) 851 { 852 int rc = RTCritSectInit(&g_pSSLMutexes[i]); 853 if (RT_FAILURE(rc)) 854 { 855 for ( ; i >= 0; i--) 856 RTCritSectDelete(&g_pSSLMutexes[i]); 857 RTMemFree(g_pSSLMutexes); 858 g_pSSLMutexes = NULL; 859 return SOAP_EOM; 860 } 861 } 862 863 CRYPTO_set_id_callback(CRYPTO_id_function); 864 CRYPTO_set_locking_callback(CRYPTO_locking_function); 865 CRYPTO_set_dynlock_create_callback(CRYPTO_dyn_create_function); 866 CRYPTO_set_dynlock_lock_callback(CRYPTO_dyn_lock_function); 867 CRYPTO_set_dynlock_destroy_callback(CRYPTO_dyn_destroy_function); 868 869 return SOAP_OK; 870 } 871 872 static void CRYPTO_thread_cleanup() 873 { 874 if (!g_pSSLMutexes) 875 return; 876 877 CRYPTO_set_id_callback(NULL); 878 CRYPTO_set_locking_callback(NULL); 879 CRYPTO_set_dynlock_create_callback(NULL); 880 CRYPTO_set_dynlock_lock_callback(NULL); 881 CRYPTO_set_dynlock_destroy_callback(NULL); 882 883 int num_locks = CRYPTO_num_locks(); 884 for (int i = 0; i < num_locks; i++) 885 RTCritSectDelete(&g_pSSLMutexes[i]); 886 887 RTMemFree(g_pSSLMutexes); 888 g_pSSLMutexes = NULL; 889 } 890 #endif /* WITH_OPENSSL */ 891 892 /**************************************************************************** 893 * 719 894 * SOAP queue pumper thread 720 895 * … … 723 898 void doQueuesLoop() 724 899 { 900 #ifdef WITH_OPENSSL 901 if (g_fSSL && CRYPTO_thread_setup()) 902 { 903 WebLog("Failed to set up OpenSSL thread mutex!"); 904 exit(RTEXITCODE_FAILURE); 905 } 906 #endif /* WITH_OPENSSL */ 907 725 908 // set up gSOAP 726 909 struct soap soap; 727 910 soap_init(&soap); 911 912 #ifdef WITH_OPENSSL 913 if (g_fSSL && soap_ssl_server_context(&soap, SOAP_SSL_DEFAULT, g_pcszKeyFile, 914 g_pcszPassword, g_pcszCACert, g_pcszCAPath, 915 g_pcszDHFile, g_pcszRandFile, g_pcszSID)) 916 { 917 WebLogSoapError(&soap); 918 exit(RTEXITCODE_FAILURE); 919 } 920 #endif /* WITH_OPENSSL */ 728 921 729 922 soap.bind_flags |= SO_REUSEADDR; … … 739 932 else 740 933 { 741 WebLog("Socket connection successful: host = %s, port = %u, master socket = %d\n",934 WebLog("Socket connection successful: host = %s, port = %u, %smaster socket = %d\n", 742 935 (g_pcszBindToHost) ? g_pcszBindToHost : "default (localhost)", 743 936 g_uBindToPort, 937 #ifdef WITH_OPENSSL 938 g_fSSL ? "SSL, " : "", 939 #else /* !WITH_OPENSSL */ 940 "", 941 #endif /*!WITH_OPENSSL */ 744 942 m); 745 943 … … 766 964 } 767 965 soap_done(&soap); // close master socket and detach environment 966 967 #ifdef WITH_OPENSSL 968 if (g_fSSL) 969 CRYPTO_thread_cleanup(); 970 #endif /* WITH_OPENSSL */ 768 971 } 769 972 … … 840 1043 break; 841 1044 1045 #ifdef WITH_OPENSSL 1046 case 's': 1047 g_fSSL = true; 1048 break; 1049 1050 case 'K': 1051 g_pcszKeyFile = ValueUnion.psz; 1052 break; 1053 1054 case 'a': 1055 if (ValueUnion.psz[0] == '\0') 1056 g_pcszPassword = NULL; 1057 else 1058 { 1059 PRTSTREAM StrmIn; 1060 if (!strcmp(ValueUnion.psz, "-")) 1061 StrmIn = g_pStdIn; 1062 else 1063 { 1064 int vrc = RTStrmOpen(ValueUnion.psz, "r", &StrmIn); 1065 if (RT_FAILURE(vrc)) 1066 return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open password file (%s, %Rrc)", ValueUnion.psz, vrc); 1067 } 1068 char szPasswd[512]; 1069 int vrc = RTStrmGetLine(StrmIn, szPasswd, sizeof(szPasswd)); 1070 if (RT_FAILURE(vrc)) 1071 return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to read password (%s, %Rrc)", ValueUnion.psz, vrc); 1072 g_pcszPassword = RTStrDup(szPasswd); 1073 memset(szPasswd, '\0', sizeof(szPasswd)); 1074 if (StrmIn != g_pStdIn) 1075 RTStrmClose(StrmIn); 1076 } 1077 break; 1078 1079 case 'c': 1080 g_pcszCACert = ValueUnion.psz; 1081 break; 1082 1083 case 'C': 1084 g_pcszCAPath = ValueUnion.psz; 1085 break; 1086 1087 case 'D': 1088 g_pcszDHFile = ValueUnion.psz; 1089 break; 1090 1091 case 'r': 1092 g_pcszRandFile = ValueUnion.psz; 1093 break; 1094 #endif /* WITH_OPENSSL */ 1095 842 1096 case 't': 843 1097 g_iWatchdogTimeoutSecs = ValueUnion.u32; … … 874 1128 case 'k': 875 1129 g_cMaxKeepAlive = ValueUnion.u32; 1130 break; 1131 1132 case 'A': 1133 g_pcszAuthentication = ValueUnion.psz; 876 1134 break; 877 1135 … … 964 1222 #endif 965 1223 1224 // initialize SOAP SSL support if enabled 1225 #ifdef WITH_OPENSSL 1226 if (g_fSSL) 1227 soap_ssl_init(); 1228 #endif /* WITH_OPENSSL */ 1229 966 1230 // initialize COM/XPCOM 967 1231 HRESULT hrc = com::Initialize(); … … 989 1253 RTMsgError("Failed to get VirtualBox object (rc=%Rhrc)!", hrc); 990 1254 return RTEXITCODE_FAILURE; 1255 } 1256 1257 // set the authentication method if requested 1258 if (g_pVirtualBox && g_pcszAuthentication && g_pcszAuthentication[0]) 1259 { 1260 ComPtr<ISystemProperties> pSystemProperties; 1261 g_pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam()); 1262 if (pSystemProperties) 1263 pSystemProperties->COMSETTER(WebServiceAuthLibrary)(com::Bstr(g_pcszAuthentication).raw()); 991 1264 } 992 1265 … … 1114 1387 ++it; 1115 1388 } 1389 1390 // re-set the authentication method in case it has been changed 1391 if (g_pVirtualBox && g_pcszAuthentication && g_pcszAuthentication[0]) 1392 { 1393 ComPtr<ISystemProperties> pSystemProperties; 1394 g_pVirtualBox->COMGETTER(SystemProperties)(pSystemProperties.asOutParam()); 1395 if (pSystemProperties) 1396 pSystemProperties->COMSETTER(WebServiceAuthLibrary)(com::Bstr(g_pcszAuthentication).raw()); 1397 } 1116 1398 } 1117 1399 -
trunk/src/VBox/Main/webservice/webtest.cpp
r33451 r40130 4 4 * functionality of VBoxManage for testing purposes. 5 5 * 6 * Copyright (C) 2006-201 0Oracle Corporation6 * Copyright (C) 2006-2012 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 26 26 27 27 28 static void usage(int exitcode) 29 { 30 std::cout << 31 "webtest: VirtualBox webservice testcase.\n" 32 "\nUsage: webtest [options] [command]...\n" 33 "\nSupported options:\n" 34 " -h: print this help message and exit.\n" 35 " -c URL: specify the webservice server URL (default http://localhost:18083/).\n" 36 "\nSupported commands:\n" 37 " - IWebsessionManager:\n" 38 " - webtest logon <user> <pass>: IWebsessionManager::logon().\n" 39 " - webtest getsession <vboxref>: IWebsessionManager::getSessionObject().\n" 40 " - webtest logoff <vboxref>: IWebsessionManager::logoff().\n" 41 " - IVirtualBox:\n" 42 " - webtest version <vboxref>: IVirtualBox::getVersion().\n" 43 " - webtest gethost <vboxref>: IVirtualBox::getHost().\n" 44 " - webtest getpc <vboxref>: IVirtualBox::getPerformanceCollector().\n" 45 " - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n" 46 " - webtest createmachine <vboxref> <settingsPath> <name>: IVirtualBox::createMachine().\n" 47 " - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n" 48 " - IHost:\n" 49 " - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n" 50 " - IHostDVDDrive:\n" 51 " - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n" 52 " - IMachine:\n" 53 " - webtest getname <machineref>: IMachine::getName().\n" 54 " - webtest getid <machineref>: IMachine::getId().\n" 55 " - webtest getostype <machineref>: IMachine::getGuestOSType().\n" 56 " - webtest savesettings <machineref>: IMachine::saveSettings().\n" 57 " - IPerformanceCollector:\n" 58 " - webtest setupmetrics <pcref>: IPerformanceCollector::setupMetrics()\n" 59 " - webtest querymetricsdata <pcref>: IPerformanceCollector::QueryMetricsData()\n" 60 " - All managed object references:\n" 61 " - webtest getif <ref>: report interface of object.\n" 62 " - webtest release <ref>: IUnknown::Release().\n"; 63 exit(exitcode); 64 } 65 28 66 /** 29 67 * … … 34 72 int main(int argc, char* argv[]) 35 73 { 74 bool fSSL = false; 75 const char *pcszArgEndpoint = "http://localhost:18083/"; 76 77 int ap; 78 for (ap = 1; ap <= argc; ap++) 79 { 80 if (argv[ap][0] == '-') 81 { 82 if (!strcmp(argv[ap], "-h")) 83 usage(0); 84 else if (!strcmp(argv[ap], "-c")) 85 { 86 ap++; 87 if (ap > argc) 88 usage(1); 89 pcszArgEndpoint = argv[ap]; 90 fSSL = !strncmp(pcszArgEndpoint, "https://", 8); 91 } 92 else 93 usage(1); 94 } 95 else 96 break; 97 } 98 99 if (argc < 1 + ap) 100 usage(1); 101 102 #ifdef WITH_OPENSSL 103 if (fSSL) 104 soap_ssl_init(); 105 #endif /* WITH_OPENSSL */ 106 36 107 struct soap soap; // gSOAP runtime environment 37 108 soap_init(&soap); // initialize runtime environment (only once) 38 39 if (argc < 2) 40 { 41 std::cout << 42 "webtest: VirtualBox webservice testcase.\n" 43 "Usage:\n" 44 " - IWebsessionManager:\n" 45 " - webtest logon <user> <pass>: IWebsessionManager::logon().\n" 46 " - webtest getsession <vboxref>: IWebsessionManager::getSessionObject().\n" 47 " - webtest logoff <vboxref>: IWebsessionManager::logoff().\n" 48 " - IVirtualBox:\n" 49 " - webtest version <vboxref>: IVirtualBox::getVersion().\n" 50 " - webtest gethost <vboxref>: IVirtualBox::getHost().\n" 51 " - webtest getpc <vboxref>: IVirtualBox::getPerformanceCollector().\n" 52 " - webtest getmachines <vboxref>: IVirtualBox::getMachines().\n" 53 " - webtest createmachine <vboxref> <settingsPath> <name>: IVirtualBox::createMachine().\n" 54 " - webtest registermachine <vboxref> <machineref>: IVirtualBox::registerMachine().\n" 55 " - IHost:\n" 56 " - webtest getdvddrives <hostref>: IHost::getDVDDrives.\n" 57 " - IHostDVDDrive:\n" 58 " - webtest getdvdname <dvdref>: IHostDVDDrive::getname.\n" 59 " - IMachine:\n" 60 " - webtest getname <machineref>: IMachine::getName().\n" 61 " - webtest getid <machineref>: IMachine::getId().\n" 62 " - webtest getostype <machineref>: IMachine::getGuestOSType().\n" 63 " - webtest savesettings <machineref>: IMachine::saveSettings().\n" 64 " - IPerformanceCollector:\n" 65 " - webtest setupmetrics <pcref>: IPerformanceCollector::setupMetrics()\n" 66 " - webtest querymetricsdata <pcref>: IPerformanceCollector::QueryMetricsData()\n" 67 " - All managed object references:\n" 68 " - webtest getif <ref>: report interface of object.\n" 69 " - webtest release <ref>: IUnknown::Release().\n"; 109 #ifdef WITH_OPENSSL 110 // Use SOAP_SSL_NO_AUTHENTICATION here to accept broken server configs. 111 // In a real world setup please use at least SOAP_SSL_DEFAULT and provide 112 // the necessary CA certificate for validating the server's certificate. 113 if (fSSL && soap_ssl_client_context(&soap, SOAP_SSL_NO_AUTHENTICATION, 114 NULL /*clientkey*/, NULL /*password*/, 115 NULL /*cacert*/, NULL /*capath*/, 116 NULL /*randfile*/)) 117 { 118 soap_print_fault(&soap, stderr); 70 119 exit(1); 71 120 } 72 73 const char *pcszArgEndpoint = "localhost:18083"; 74 75 const char *pcszMode = argv[1]; 76 int soaprc = 2; 121 #endif /* WITH_OPENSSL */ 122 123 const char *pcszMode = argv[ap]; 124 int soaprc = SOAP_SVR_FAULT; 77 125 78 126 if (!strcmp(pcszMode, "logon")) 79 127 { 80 if (argc < 4)128 if (argc < 3 + ap) 81 129 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 82 130 else 83 131 { 84 132 _vbox__IWebsessionManager_USCORElogon req; 85 req.username = argv[ 2];86 req.password = argv[ 3];133 req.username = argv[ap + 1]; 134 req.password = argv[ap + 2]; 87 135 _vbox__IWebsessionManager_USCORElogonResponse resp; 88 136 … … 97 145 else if (!strcmp(pcszMode, "getsession")) 98 146 { 99 if (argc < 3)147 if (argc < 2 + ap) 100 148 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 101 149 else 102 150 { 103 151 _vbox__IWebsessionManager_USCOREgetSessionObject req; 104 req.refIVirtualBox = argv[ 2];152 req.refIVirtualBox = argv[ap + 1]; 105 153 _vbox__IWebsessionManager_USCOREgetSessionObjectResponse resp; 106 154 … … 115 163 else if (!strcmp(pcszMode, "logoff")) 116 164 { 117 if (argc < 3)165 if (argc < 2 + ap) 118 166 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 119 167 else 120 168 { 121 169 _vbox__IWebsessionManager_USCORElogoff req; 122 req.refIVirtualBox = argv[ 2];170 req.refIVirtualBox = argv[ap + 1]; 123 171 _vbox__IWebsessionManager_USCORElogoffResponse resp; 124 172 … … 135 183 else if (!strcmp(pcszMode, "version")) 136 184 { 137 if (argc < 3)185 if (argc < 2 + ap) 138 186 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 139 187 else 140 188 { 141 189 _vbox__IVirtualBox_USCOREgetVersion req; 142 req._USCOREthis = argv[ 2];190 req._USCOREthis = argv[ap + 1]; 143 191 _vbox__IVirtualBox_USCOREgetVersionResponse resp; 144 192 … … 153 201 else if (!strcmp(pcszMode, "gethost")) 154 202 { 155 if (argc < 3)203 if (argc < 2 + ap) 156 204 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 157 205 else 158 206 { 159 207 _vbox__IVirtualBox_USCOREgetHost req; 160 req._USCOREthis = argv[ 2];208 req._USCOREthis = argv[ap + 1]; 161 209 _vbox__IVirtualBox_USCOREgetHostResponse resp; 162 210 … … 173 221 else if (!strcmp(pcszMode, "getpc")) 174 222 { 175 if (argc < 3)223 if (argc < 2 + ap) 176 224 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 177 225 else 178 226 { 179 227 _vbox__IVirtualBox_USCOREgetPerformanceCollector req; 180 req._USCOREthis = argv[ 2];228 req._USCOREthis = argv[ap + 1]; 181 229 _vbox__IVirtualBox_USCOREgetPerformanceCollectorResponse resp; 182 230 … … 193 241 else if (!strcmp(pcszMode, "getmachines")) 194 242 { 195 if (argc < 3)243 if (argc < 2 + ap) 196 244 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 197 245 else 198 246 { 199 247 _vbox__IVirtualBox_USCOREgetMachines req; 200 req._USCOREthis = argv[ 2];248 req._USCOREthis = argv[ap + 1]; 201 249 _vbox__IVirtualBox_USCOREgetMachinesResponse resp; 202 250 … … 219 267 else if (!strcmp(pcszMode, "createmachine")) 220 268 { 221 if (argc < 5)269 if (argc < 4 + ap) 222 270 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 223 271 else 224 272 { 225 273 _vbox__IVirtualBox_USCOREcreateMachine req; 226 req._USCOREthis = argv[ 2];227 req.settingsFile = argv[ 3];228 req.name = argv[ 4];274 req._USCOREthis = argv[ap + 1]; 275 req.settingsFile = argv[ap + 2]; 276 req.name = argv[ap + 3]; 229 277 std::cout << "createmachine: settingsFile = \"" << req.settingsFile << "\", name = \"" << req.name << "\"\n"; 230 278 _vbox__IVirtualBox_USCOREcreateMachineResponse resp; … … 240 288 else if (!strcmp(pcszMode, "registermachine")) 241 289 { 242 if (argc < 4)290 if (argc < 3 + ap) 243 291 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 244 292 else 245 293 { 246 294 _vbox__IVirtualBox_USCOREregisterMachine req; 247 req._USCOREthis = argv[ 2];248 req.machine = argv[ 3];295 req._USCOREthis = argv[ap + 1]; 296 req.machine = argv[ap + 2]; 249 297 _vbox__IVirtualBox_USCOREregisterMachineResponse resp; 250 298 if (!(soaprc = soap_call___vbox__IVirtualBox_USCOREregisterMachine(&soap, … … 258 306 else if (!strcmp(pcszMode, "getdvddrives")) 259 307 { 260 if (argc < 3)308 if (argc < 2 + ap) 261 309 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 262 310 else 263 311 { 264 312 _vbox__IHost_USCOREgetDVDDrives req; 265 req._USCOREthis = argv[ 2];313 req._USCOREthis = argv[ap + 1]; 266 314 _vbox__IHost_USCOREgetDVDDrivesResponse resp; 267 315 if (!(soaprc = soap_call___vbox__IHost_USCOREgetDVDDrives(&soap, … … 283 331 else if (!strcmp(pcszMode, "getname")) 284 332 { 285 if (argc < 3)333 if (argc < 2 + ap) 286 334 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 287 335 else 288 336 { 289 337 _vbox__IMachine_USCOREgetName req; 290 req._USCOREthis = argv[ 2];338 req._USCOREthis = argv[ap + 1]; 291 339 _vbox__IMachine_USCOREgetNameResponse resp; 292 340 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetName(&soap, … … 300 348 else if (!strcmp(pcszMode, "getid")) 301 349 { 302 if (argc < 3)350 if (argc < 2 + ap) 303 351 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 304 352 else 305 353 { 306 354 _vbox__IMachine_USCOREgetId req; 307 req._USCOREthis = argv[ 2];355 req._USCOREthis = argv[ap + 1]; 308 356 _vbox__IMachine_USCOREgetIdResponse resp; 309 357 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetId(&soap, … … 317 365 else if (!strcmp(pcszMode, "getostypeid")) 318 366 { 319 if (argc < 3)367 if (argc < 2 + ap) 320 368 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 321 369 else 322 370 { 323 371 _vbox__IMachine_USCOREgetOSTypeId req; 324 req._USCOREthis = argv[ 2];372 req._USCOREthis = argv[ap + 1]; 325 373 _vbox__IMachine_USCOREgetOSTypeIdResponse resp; 326 374 if (!(soaprc = soap_call___vbox__IMachine_USCOREgetOSTypeId(&soap, … … 334 382 else if (!strcmp(pcszMode, "savesettings")) 335 383 { 336 if (argc < 3)384 if (argc < 2 + ap) 337 385 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 338 386 else 339 387 { 340 388 _vbox__IMachine_USCOREsaveSettings req; 341 req._USCOREthis = argv[ 2];389 req._USCOREthis = argv[ap + 1]; 342 390 _vbox__IMachine_USCOREsaveSettingsResponse resp; 343 391 if (!(soaprc = soap_call___vbox__IMachine_USCOREsaveSettings(&soap, … … 351 399 else if (!strcmp(pcszMode, "setupmetrics")) 352 400 { 353 if (argc < 3)401 if (argc < 2 + ap) 354 402 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 355 403 else 356 404 { 357 405 _vbox__IPerformanceCollector_USCOREsetupMetrics req; 358 req._USCOREthis = argv[ 2];406 req._USCOREthis = argv[ap + 1]; 359 407 // req.metricNames[0] = "*"; 360 408 // req.objects … … 380 428 else if (!strcmp(pcszMode, "querymetricsdata")) 381 429 { 382 if (argc < 3)430 if (argc < 2 + ap) 383 431 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 384 432 else 385 433 { 386 434 _vbox__IPerformanceCollector_USCOREqueryMetricsData req; 387 req._USCOREthis = argv[ 2];435 req._USCOREthis = argv[ap + 1]; 388 436 // req.metricNames[0] = "*"; 389 437 // req.objects … … 407 455 else if (!strcmp(pcszMode, "release")) 408 456 { 409 if (argc < 3)457 if (argc < 2 + ap) 410 458 std::cout << "Not enough arguments for \"" << pcszMode << "\" mode.\n"; 411 459 else 412 460 { 413 461 _vbox__IManagedObjectRef_USCORErelease req; 414 req._USCOREthis = argv[ 2];462 req._USCOREthis = argv[ap + 1]; 415 463 _vbox__IManagedObjectRef_USCOREreleaseResponse resp; 416 464 if (!(soaprc = soap_call___vbox__IManagedObjectRef_USCORErelease(&soap, … … 435 483 std::cout << "Bad object ID: " << soap.fault->detail->vbox__InvalidObjectFault->badObjectID << "\n"; 436 484 } 437 if (soap.fault->detail->vbox__RuntimeFault)485 else if (soap.fault->detail->vbox__RuntimeFault) 438 486 { 439 487 std::cout << "Result code: 0x" << std::hex << soap.fault->detail->vbox__RuntimeFault->resultCode << "\n"; … … 442 490 std::cout << "Interface ID: " << std::hex << soap.fault->detail->vbox__RuntimeFault->interfaceID << "\n"; 443 491 } 492 else 493 { 494 // generic fault 495 std::cerr << "Generic fault message:\n"; 496 soap_print_fault(&soap, stderr); // display the SOAP fault message on the stderr stream 497 } 444 498 } 445 499 else
Note:
See TracChangeset
for help on using the changeset viewer.