VirtualBox

source: vbox/trunk/src/VBox/HostServices/GuestControl/gctrl.cpp@ 62800

最後變更 在這個檔案從62800是 62800,由 vboxsync 提交於 9 年 前

GuestCtrl/Service: warnings

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.8 KB
 
1/* $Id: gctrl.cpp 62800 2016-08-01 09:41:36Z vboxsync $ */
2/** @file
3 * Guest Control Service: Internal function used by service, Main and testcase.
4 */
5
6/*
7 * Copyright (C) 2010-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_HGCM
23#include <VBox/HostServices/GuestControlSvc.h>
24
25/** @todo Remove unused header files below! */
26#include <iprt/alloca.h>
27#include <iprt/initterm.h>
28#include <iprt/crc.h>
29#include <iprt/ctype.h>
30#include <iprt/env.h>
31#include <iprt/file.h>
32#include <iprt/getopt.h>
33#include <iprt/handle.h>
34#include <iprt/mem.h>
35#include <iprt/message.h>
36#include <iprt/param.h>
37#include <iprt/path.h>
38#include <iprt/pipe.h>
39#include <iprt/poll.h>
40#include <iprt/process.h>
41#include <iprt/stream.h>
42#include <iprt/thread.h>
43
44#include "gctrl.h"
45
46namespace guestControl {
47
48#if 0 /* unused */
49/**
50 * Creates the argument list as an array used for executing a program.
51 *
52 * @returns VBox status code.
53 */
54int gctrlPrepareExecArgv(char *pszArgs, void **ppvList, uint32_t *pcbList, uint32_t *pcArgs)
55{
56 char **ppaArg;
57 int cArgs;
58 int rc = RTGetOptArgvFromString(&ppaArg, &cArgs, pszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH, NULL);
59 if (RT_SUCCESS(rc))
60 {
61 /** @todo calc size first, allocate buffer, copy stuff. */
62 char *pszTemp = NULL;
63 *pcbList = 0;
64 for (int i = 0; i < cArgs; i++)
65 {
66 if (i > 0) /* Insert space as delimiter. */
67 {
68 rc = RTStrAAppendN(&pszTemp, " ", 1);
69 if (RT_FAILURE(rc))
70 break;
71 }
72 rc = RTStrAAppendN(&pszTemp, ppaArg[i], strlen(ppaArg[i]));
73 if (RT_FAILURE(rc))
74 break;
75 }
76
77 RTGetOptArgvFree(ppaArg);
78
79 if (RT_SUCCESS(rc))
80 {
81 *ppvList = pszTemp;
82 *pcArgs = cArgs;
83 *pcbList = (uint32_t)(strlen(pszTemp) + 1); /* Include zero termination. */
84 }
85 else
86 RTStrFree(pszTemp);
87 }
88 return rc;
89}
90#endif
91
92
93#if 0 /* unused */
94/**
95 * Appends environment variables to the environment block.
96 *
97 * Each var=value pair is separated by NULL (\0) sequence. The whole block will
98 * be stored in one blob and disassembled on the guest side later to fit into
99 * the HGCM param structure.
100 *
101 * @returns VBox status code.
102 *
103 * @todo Write proper documentation
104 * @remarks currently not used.
105 */
106int gctrlAddToExecEnvv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv)
107{
108 int rc = VINF_SUCCESS;
109 size_t cchLen = strlen(pszEnv);
110 if (*ppvList)
111 {
112 size_t cbNewLen = *pcbList + cchLen + 1; /* Include zero termination. */
113 char *pvTmp = (char*)RTMemRealloc(*ppvList, cbNewLen);
114 if (NULL == pvTmp)
115 {
116 rc = VERR_NO_MEMORY;
117 }
118 else
119 {
120 memcpy(pvTmp + *pcbList, pszEnv, cchLen);
121 pvTmp[cbNewLen - 1] = '\0'; /* Add zero termination. */
122 *ppvList = (void**)pvTmp;
123 }
124 }
125 else
126 {
127 char *pcTmp;
128 if (RTStrAPrintf(&pcTmp, "%s", pszEnv) > 0)
129 {
130 *ppvList = (void**)pcTmp;
131 /* Reset counters. */
132 *pcEnv = 0;
133 *pcbList = 0;
134 }
135 }
136 if (RT_SUCCESS(rc))
137 {
138 *pcbList += (uint32_t)(cchLen + 1); /* Include zero termination. */
139 *pcEnv += 1; /* Increase env pairs count. */
140 }
141 return rc;
142}
143#endif /* unused */
144
145/*
146int gctrlAllocateExecBlock(PVBOXGUESTCTRLEXECBLOCK *ppBlock,
147 const char *pszCmd, uint32_t fFlags,
148 uint32_t cArgs, const char * const *papszArgs,
149 uint32_t cEnvVars, const char * const *papszEnv,
150 const char *pszStdIn, const char *pszStdOut, const char *pszStdErr,
151 const char *pszUsername, const char *pszPassword, RTMSINTERVAL cMillies)
152{
153 PVBOXGUESTCTRLEXECBLOCK pNewBlock = (VBOXGUESTCTRLEXECBLOCK*)RTMemAlloc(sizeof(VBOXGUESTCTRLEXECBLOCK));
154 int rc;
155 if (pNewBlock)
156 {
157
158
159 *ppBlock = pNewBlock;
160 rc = VINF_SUCCESS;
161 }
162 else
163 rc = VERR_NO_MEMORY;
164 return rc;
165}
166
167
168int gctrlFreeExecBlock(PVBOXGUESTCTRLEXECBLOCK pBlock)
169{
170 AssertPtr(pBlock);
171
172 RTStrFree(pBlock->pszCmd);
173 RTMemFree(pBlock->pvArgs);
174 RTMemFree(pBlock->pvEnv);
175 RTStrFree(pBlock->pszStdIn);
176 RTStrFree(pBlock->pszStdOut);
177 RTStrFree(pBlock->pszStdErr);
178 RTStrFree(pBlock->pszUsername);
179 RTStrFree(pBlock->pszPassword);
180
181 RT_ZERO(*pBlock);
182 return VINF_SUCCESS;
183}
184
185
186int gctrlPrepareHostCmdExec(PVBOXHGCMSVCPARM *ppaParms, uint32_t *pcParms,
187 PVBOXGUESTCTRLEXECBLOCK pBlock)
188{
189 AssertPtr(ppaParms);
190 AssertPtr(pBlock);
191
192 PVBOXHGCMSVCPARM pNewParms =
193 (VBOXHGCMSVCPARM*)RTMemAlloc(sizeof(VBOXHGCMSVCPARM) * 13);
194
195 int rc;
196 if (pNewParms)
197 {
198 pNewParms[0].setUInt32(HOST_EXEC_CMD);
199 pNewParms[1].setUInt32(pBlock->u32Flags);
200 pNewParms[2].setPointer((void*)pBlock->pszCmd, (uint32_t)strlen(pBlock->pszCmd) + 1);
201 pNewParms[3].setUInt32(pBlock->u32Args);
202 pNewParms[4].setPointer((void*)pBlock->pvArgs, pBlock->cbArgs);
203 pNewParms[5].setUInt32(pBlock->u32EnvVars);
204 pNewParms[6].setPointer((void*)pBlock->pvEnv, pBlock->cbEnv);
205 pNewParms[7].setPointer((void*)pBlock->pszStdIn, (uint32_t)strlen(pBlock->pszStdIn) + 1);
206 pNewParms[8].setPointer((void*)pBlock->pszStdOut, (uint32_t)strlen(pBlock->pszStdOut) + 1);
207 pNewParms[9].setPointer((void*)pBlock->pszStdErr, (uint32_t)strlen(pBlock->pszStdErr) + 1);
208 pNewParms[10].setPointer((void*)pBlock->pszUsername, (uint32_t)strlen(pBlock->pszUsername) + 1);
209 pNewParms[11].setPointer((void*)pBlock->pszPassword, (uint32_t)strlen(pBlock->pszPassword) + 1);
210 pNewParms[12].setUInt32(pBlock->cMillies);
211
212 *ppaParms = pNewParms;
213 rc = VINF_SUCCESS;
214 }
215 else
216 rc = VERR_NO_MEMORY;
217
218 if (pcParms)
219 *pcParms = 13;
220
221 return rc;
222}
223
224
225void gctrlFreeHostCmd(PVBOXHGCMSVCPARM paParms)
226{
227 RTMemFree(paParms);
228}
229*/
230
231}
232
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette