1 |
|
---|
2 | /* $Id: GuestSessionImpl.h 42530 2012-08-02 12:11:44Z vboxsync $ */
|
---|
3 | /** @file
|
---|
4 | * VirtualBox Main - XXX.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ____H_GUESTSESSIONIMPL
|
---|
20 | #define ____H_GUESTSESSIONIMPL
|
---|
21 |
|
---|
22 | #include "VirtualBoxBase.h"
|
---|
23 |
|
---|
24 | #include "GuestCtrlImplPrivate.h"
|
---|
25 | #include "GuestProcessImpl.h"
|
---|
26 | #include "GuestDirectoryImpl.h"
|
---|
27 | #include "GuestFileImpl.h"
|
---|
28 | #include "GuestFsObjInfoImpl.h"
|
---|
29 |
|
---|
30 | class Guest;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * TODO
|
---|
34 | */
|
---|
35 | class ATL_NO_VTABLE GuestSession :
|
---|
36 | public VirtualBoxBase,
|
---|
37 | VBOX_SCRIPTABLE_IMPL(IGuestSession)
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /** @name COM and internal init/term/mapping cruft.
|
---|
41 | * @{ */
|
---|
42 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestSession, IGuestSession)
|
---|
43 | DECLARE_NOT_AGGREGATABLE(GuestSession)
|
---|
44 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
45 | BEGIN_COM_MAP(GuestSession)
|
---|
46 | VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestSession)
|
---|
47 | END_COM_MAP()
|
---|
48 | DECLARE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
49 |
|
---|
50 | int init(Guest *aGuest, ULONG aSessionID, Utf8Str aUser, Utf8Str aPassword, Utf8Str aDomain, Utf8Str aName);
|
---|
51 | void uninit(void);
|
---|
52 | HRESULT FinalConstruct(void);
|
---|
53 | void FinalRelease(void);
|
---|
54 | /** @} */
|
---|
55 |
|
---|
56 | /** @name IGuestSession properties.
|
---|
57 | * @{ */
|
---|
58 | STDMETHOD(COMGETTER(User))(BSTR *aName);
|
---|
59 | STDMETHOD(COMGETTER(Domain))(BSTR *aDomain);
|
---|
60 | STDMETHOD(COMGETTER(Name))(BSTR *aName);
|
---|
61 | STDMETHOD(COMGETTER(Id))(ULONG *aId);
|
---|
62 | STDMETHOD(COMGETTER(Timeout))(ULONG *aTimeout);
|
---|
63 | STDMETHOD(COMSETTER(Timeout))(ULONG aTimeout);
|
---|
64 | STDMETHOD(COMGETTER(Environment))(ComSafeArrayOut(BSTR, aEnvironment));
|
---|
65 | STDMETHOD(COMGETTER(Processes))(ComSafeArrayOut(IGuestProcess *, aProcesses));
|
---|
66 | STDMETHOD(COMGETTER(Directories))(ComSafeArrayOut(IGuestDirectory *, aDirectories));
|
---|
67 | STDMETHOD(COMGETTER(Files))(ComSafeArrayOut(IGuestFile *, aFiles));
|
---|
68 | /** @} */
|
---|
69 |
|
---|
70 | /** @name IGuestSession methods.
|
---|
71 | * @{ */
|
---|
72 | STDMETHOD(Close)(void);
|
---|
73 | STDMETHOD(CopyFrom)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress);
|
---|
74 | STDMETHOD(CopyTo)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(ULONG, aFlags), IProgress **aProgress);
|
---|
75 | STDMETHOD(DirectoryCreate)(IN_BSTR aPath, ULONG aMode, ComSafeArrayIn(DirectoryCreateFlag_T, aFlags), IGuestDirectory **aDirectory);
|
---|
76 | STDMETHOD(DirectoryCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestDirectory **aDirectory);
|
---|
77 | STDMETHOD(DirectoryExists)(IN_BSTR aPath, BOOL *aExists);
|
---|
78 | STDMETHOD(DirectoryOpen)(IN_BSTR aPath, IN_BSTR aFilter, IN_BSTR aFlags, IGuestDirectory **aDirectory);
|
---|
79 | STDMETHOD(DirectoryQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
|
---|
80 | STDMETHOD(DirectoryRemove)(IN_BSTR aPath);
|
---|
81 | STDMETHOD(DirectoryRemoveRecursive)(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress);
|
---|
82 | STDMETHOD(DirectoryRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
|
---|
83 | STDMETHOD(DirectorySetACL)(IN_BSTR aPath, IN_BSTR aACL);
|
---|
84 | STDMETHOD(EnvironmentClear)(void);
|
---|
85 | STDMETHOD(EnvironmentGet)(IN_BSTR aName, BSTR *aValue);
|
---|
86 | STDMETHOD(EnvironmentSet)(IN_BSTR aName, IN_BSTR aValue);
|
---|
87 | STDMETHOD(EnvironmentSetArray)(ComSafeArrayIn(IN_BSTR, aValues));
|
---|
88 | STDMETHOD(EnvironmentUnset)(IN_BSTR aName);
|
---|
89 | STDMETHOD(FileCreateTemp)(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aName, IGuestFile **aFile);
|
---|
90 | STDMETHOD(FileExists)(IN_BSTR aPath, BOOL *aExists);
|
---|
91 | STDMETHOD(FileOpen)(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile);
|
---|
92 | STDMETHOD(FileQueryInfo)(IN_BSTR aPath, IGuestFsObjInfo **aInfo);
|
---|
93 | STDMETHOD(FileQuerySize)(IN_BSTR aPath, LONG64 *aSize);
|
---|
94 | STDMETHOD(FileRemove)(IN_BSTR aPath);
|
---|
95 | STDMETHOD(FileRename)(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags));
|
---|
96 | STDMETHOD(FileSetACL)(IN_BSTR aPath, IN_BSTR aACL);
|
---|
97 | STDMETHOD(ProcessCreate)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
98 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess);
|
---|
99 | STDMETHOD(ProcessCreateEx)(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
100 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
|
---|
101 | ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
|
---|
102 | IGuestProcess **aProcess);
|
---|
103 | STDMETHOD(ProcessGet)(ULONG aPID, IGuestProcess **aProcess);
|
---|
104 | #if 0
|
---|
105 | STDMETHOD(SetTimeout)(ULONG aTimeoutMS);
|
---|
106 | #endif
|
---|
107 | STDMETHOD(SymlinkCreate)(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType);
|
---|
108 | STDMETHOD(SymlinkExists)(IN_BSTR aSymlink, BOOL *aExists);
|
---|
109 | STDMETHOD(SymlinkRead)(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget);
|
---|
110 | STDMETHOD(SymlinkRemoveDirectory)(IN_BSTR aPath);
|
---|
111 | STDMETHOD(SymlinkRemoveFile)(IN_BSTR aFile);
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 | private:
|
---|
115 |
|
---|
116 | typedef std::vector <ComObjPtr<GuestDirectory> > SessionDirectories;
|
---|
117 | typedef std::vector <ComObjPtr<GuestFile> > SessionFiles;
|
---|
118 | /** Map of guest processes. The key specifies the internal process number.
|
---|
119 | * To retrieve the process' guest PID use the Id() method of the IProcess interface. */
|
---|
120 | typedef std::map <uint32_t, ComObjPtr<GuestProcess> > SessionProcesses;
|
---|
121 |
|
---|
122 | public:
|
---|
123 | /** @name Public internal methods.
|
---|
124 | * @{ */
|
---|
125 | int directoryClose(ComObjPtr<GuestDirectory> pDirectory);
|
---|
126 | int directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory);
|
---|
127 | int dispatchToProcess(uint32_t uContextID, uint32_t uFunction, void *pvData, size_t cbData);
|
---|
128 | int fileClose(ComObjPtr<GuestFile> pFile);
|
---|
129 | int fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData);
|
---|
130 | int fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize);
|
---|
131 | const GuestCredentials &getCredentials(void);
|
---|
132 | const GuestEnvironment &getEnvironment(void);
|
---|
133 | uint32_t getProtocolVersion(void) { return mData.mProtocolVersion; }
|
---|
134 | int processClose(ComObjPtr<GuestProcess> pProcess);
|
---|
135 | int processCreateExInteral(GuestProcessInfo &procInfo, ComObjPtr<GuestProcess> &pProgress);
|
---|
136 | inline bool processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess);
|
---|
137 | inline int processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess);
|
---|
138 | int queryInfo(void);
|
---|
139 | /** @} */
|
---|
140 |
|
---|
141 | private:
|
---|
142 |
|
---|
143 | struct Data
|
---|
144 | {
|
---|
145 | /** Guest control protocol version to be used.
|
---|
146 | * Guest Additions < VBox 4.2 have version 1,
|
---|
147 | * any newer version will have version 2. */
|
---|
148 | uint32_t mProtocolVersion;
|
---|
149 | /** Flag indicating if this is an internal session
|
---|
150 | * or not. Internal session are not accessible by clients. */
|
---|
151 | bool fInternal;
|
---|
152 | /** Pointer to the parent (Guest). */
|
---|
153 | Guest *mParent;
|
---|
154 | /** The session credentials. */
|
---|
155 | GuestCredentials mCredentials;
|
---|
156 | /** The (optional) session name. */
|
---|
157 | Utf8Str mName;
|
---|
158 | /** The session ID. */
|
---|
159 | ULONG mId;
|
---|
160 | /** The session timeout. Default is 30s. */
|
---|
161 | ULONG mTimeout;
|
---|
162 | /** The next process ID for assignment. */
|
---|
163 | ULONG mNextProcessID;
|
---|
164 | /** The session's environment block. Can be
|
---|
165 | * overwritten/extended by ProcessCreate(Ex). */
|
---|
166 | GuestEnvironment mEnvironment;
|
---|
167 | /** Directory objects bound to this session. */
|
---|
168 | SessionDirectories mDirectories;
|
---|
169 | /** File objects bound to this session. */
|
---|
170 | SessionFiles mFiles;
|
---|
171 | /** Process objects bound to this session. */
|
---|
172 | SessionProcesses mProcesses;
|
---|
173 | } mData;
|
---|
174 | };
|
---|
175 |
|
---|
176 | #endif /* !____H_GUESTSESSIONIMPL */
|
---|
177 |
|
---|