[85683] | 1 | /* $Id: UpdateAgentImpl.h 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[94643] | 3 | * Update agent COM class implementation - Header
|
---|
[85683] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[96407] | 7 | * Copyright (C) 2020-2022 Oracle and/or its affiliates.
|
---|
[85683] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[85683] | 26 | */
|
---|
| 27 |
|
---|
[94643] | 28 | #ifndef MAIN_INCLUDED_UpdateAgentImpl_h
|
---|
| 29 | #define MAIN_INCLUDED_UpdateAgentImpl_h
|
---|
[85683] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
[94643] | 34 | #include <iprt/http.h>
|
---|
[85683] | 35 |
|
---|
[94643] | 36 | #include <VBox/settings.h>
|
---|
[85683] | 37 |
|
---|
[94704] | 38 | #include "EventImpl.h"
|
---|
[94643] | 39 | #include "UpdateAgentWrap.h"
|
---|
| 40 | #include "HostUpdateAgentWrap.h"
|
---|
| 41 |
|
---|
| 42 | class UpdateAgentTask;
|
---|
| 43 | struct UpdateAgentTaskParms;
|
---|
| 44 |
|
---|
| 45 | struct UpdateAgentTaskResult
|
---|
[85683] | 46 | {
|
---|
[94643] | 47 | Utf8Str strVer;
|
---|
| 48 | Utf8Str strWebUrl;
|
---|
| 49 | Utf8Str strDownloadUrl;
|
---|
| 50 | UpdateSeverity_T enmSeverity;
|
---|
| 51 | Utf8Str strReleaseNotes;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
[94650] | 54 | class UpdateAgentBase
|
---|
[94643] | 55 | {
|
---|
[94650] | 56 | protected: /* Not directly instancable. */
|
---|
| 57 |
|
---|
| 58 | UpdateAgentBase()
|
---|
| 59 | : m_VirtualBox(NULL)
|
---|
| 60 | , m(new settings::UpdateAgent) { }
|
---|
| 61 |
|
---|
[94704] | 62 | virtual ~UpdateAgentBase() { delete m; }
|
---|
[94650] | 63 |
|
---|
[85683] | 64 | public:
|
---|
[94650] | 65 |
|
---|
| 66 | /** @name Pure virtual public methods for internal purposes only
|
---|
| 67 | * (ensure there is a caller and a read lock before calling them!)
|
---|
| 68 | * @{ */
|
---|
| 69 | virtual HRESULT i_loadSettings(const settings::UpdateAgent &data) = 0;
|
---|
| 70 | virtual HRESULT i_saveSettings(settings::UpdateAgent &data) = 0;
|
---|
| 71 |
|
---|
| 72 | virtual HRESULT i_setCheckCount(ULONG aCount) = 0;
|
---|
| 73 | virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate) = 0;
|
---|
| 74 | /** @} */
|
---|
| 75 |
|
---|
| 76 | protected:
|
---|
| 77 |
|
---|
| 78 | /** @name Pure virtual internal task callbacks.
|
---|
| 79 | * @{ */
|
---|
| 80 | friend UpdateAgentTask;
|
---|
[94702] | 81 | virtual DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask) = 0;
|
---|
[94650] | 82 | /** @} */
|
---|
| 83 |
|
---|
| 84 | /** @name Static helper methods.
|
---|
| 85 | * @{ */
|
---|
| 86 | static Utf8Str i_getPlatformInfo(void);
|
---|
[94807] | 87 | const char *i_proxyModeToStr(ProxyMode_T enmMode);
|
---|
| 88 | bool i_urlSchemeIsSupported(const Utf8Str &strUrl) const;
|
---|
[94650] | 89 | /** @} */
|
---|
| 90 |
|
---|
| 91 | protected:
|
---|
[94704] | 92 | /** The update agent's event source. */
|
---|
| 93 | const ComObjPtr<EventSource> m_EventSource;
|
---|
| 94 | VirtualBox * const m_VirtualBox;
|
---|
[94650] | 95 |
|
---|
| 96 | /** @name Data members.
|
---|
| 97 | * @{ */
|
---|
| 98 | settings::UpdateAgent *m;
|
---|
| 99 |
|
---|
| 100 | struct Data
|
---|
| 101 | {
|
---|
[94723] | 102 | UpdateAgentTaskResult m_lastResult;
|
---|
| 103 | Utf8Str m_strName;
|
---|
| 104 | /** Vector of update channels this agent supports. */
|
---|
| 105 | const std::vector<UpdateChannel_T> m_enmChannels;
|
---|
| 106 | bool m_fHidden;
|
---|
| 107 | UpdateState_T m_enmState;
|
---|
| 108 | uint32_t m_uOrder;
|
---|
[94650] | 109 |
|
---|
| 110 | Data(void)
|
---|
| 111 | {
|
---|
| 112 | m_fHidden = true;
|
---|
| 113 | m_enmState = UpdateState_Invalid;
|
---|
| 114 | m_uOrder = UINT32_MAX;
|
---|
| 115 | }
|
---|
| 116 | } mData;
|
---|
| 117 | /** @} */
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | class ATL_NO_VTABLE UpdateAgent :
|
---|
| 121 | public UpdateAgentWrap,
|
---|
| 122 | public UpdateAgentBase
|
---|
| 123 | {
|
---|
| 124 | public:
|
---|
[94643] | 125 | DECLARE_COMMON_CLASS_METHODS(UpdateAgent)
|
---|
[85683] | 126 |
|
---|
[94643] | 127 | /** @name COM and internal init/term/mapping cruft.
|
---|
| 128 | * @{ */
|
---|
[85683] | 129 | HRESULT FinalConstruct();
|
---|
| 130 | void FinalRelease();
|
---|
| 131 |
|
---|
| 132 | HRESULT init(VirtualBox *aVirtualBox);
|
---|
[94643] | 133 | void uninit(void);
|
---|
| 134 | /** @} */
|
---|
[85683] | 135 |
|
---|
[94643] | 136 | /** @name Public methods for internal purposes only
|
---|
| 137 | * (ensure there is a caller and a read lock before calling them!) */
|
---|
| 138 | HRESULT i_loadSettings(const settings::UpdateAgent &data);
|
---|
| 139 | HRESULT i_saveSettings(settings::UpdateAgent &data);
|
---|
| 140 |
|
---|
| 141 | virtual HRESULT i_setCheckCount(ULONG aCount);
|
---|
| 142 | virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate);
|
---|
| 143 | /** @} */
|
---|
| 144 |
|
---|
| 145 | protected:
|
---|
[94685] | 146 |
|
---|
| 147 | /** @name Internal helper methods.
|
---|
[86530] | 148 | * @{ */
|
---|
[94756] | 149 | HRESULT i_getProxyMode(ProxyMode_T *aMode);
|
---|
| 150 | HRESULT i_getProxyURL(com::Utf8Str &aAddress);
|
---|
| 151 | HRESULT i_configureProxy(RTHTTP hHttp);
|
---|
[94685] | 152 | HRESULT i_commitSettings(AutoWriteLock &aLock);
|
---|
[94704] | 153 | HRESULT i_reportError(int vrc, const char *pcszMsgFmt, ...);
|
---|
[94685] | 154 | /** @} */
|
---|
| 155 |
|
---|
| 156 | protected:
|
---|
| 157 | /** @name Wrapped IUpdateAgent attributes and methods.
|
---|
| 158 | * @{ */
|
---|
[94670] | 159 | HRESULT checkFor(ComPtr<IProgress> &aProgress);
|
---|
[94654] | 160 | HRESULT download(ComPtr<IProgress> &aProgress);
|
---|
| 161 | HRESULT install(ComPtr<IProgress> &aProgress);
|
---|
| 162 | HRESULT rollback(void);
|
---|
[94643] | 163 |
|
---|
[94654] | 164 | HRESULT getName(com::Utf8Str &aName);
|
---|
[94704] | 165 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
[94654] | 166 | HRESULT getOrder(ULONG *aOrder);
|
---|
| 167 | HRESULT getDependsOn(std::vector<com::Utf8Str> &aDeps);
|
---|
| 168 | HRESULT getVersion(com::Utf8Str &aVer);
|
---|
| 169 | HRESULT getDownloadUrl(com::Utf8Str &aUrl);
|
---|
| 170 | HRESULT getWebUrl(com::Utf8Str &aUrl);
|
---|
| 171 | HRESULT getReleaseNotes(com::Utf8Str &aRelNotes);
|
---|
| 172 | HRESULT getEnabled(BOOL *aEnabled);
|
---|
| 173 | HRESULT setEnabled(BOOL aEnabled);
|
---|
| 174 | HRESULT getHidden(BOOL *aHidden);
|
---|
| 175 | HRESULT getState(UpdateState_T *aState);
|
---|
| 176 | HRESULT getCheckCount(ULONG *aCount);
|
---|
| 177 | HRESULT getCheckFrequency(ULONG *aFreqSeconds);
|
---|
| 178 | HRESULT setCheckFrequency(ULONG aFreqSeconds);
|
---|
| 179 | HRESULT getChannel(UpdateChannel_T *aChannel);
|
---|
| 180 | HRESULT setChannel(UpdateChannel_T aChannel);
|
---|
| 181 | HRESULT getRepositoryURL(com::Utf8Str &aRepo);
|
---|
| 182 | HRESULT setRepositoryURL(const com::Utf8Str &aRepo);
|
---|
| 183 | HRESULT getLastCheckDate(com::Utf8Str &aData);
|
---|
[94700] | 184 | HRESULT getIsCheckNeeded(BOOL *aCheckNeeded);
|
---|
[94723] | 185 | HRESULT getSupportedChannels(std::vector<UpdateChannel_T> &aSupportedChannels);
|
---|
[85729] | 186 | /** @} */
|
---|
[85683] | 187 | };
|
---|
| 188 |
|
---|
[94643] | 189 | /** @todo Put this into an own module, e.g. HostUpdateAgentImpl.[cpp|h]. */
|
---|
[85683] | 190 |
|
---|
[94643] | 191 | class ATL_NO_VTABLE HostUpdateAgent :
|
---|
| 192 | public UpdateAgent
|
---|
| 193 | {
|
---|
| 194 | public:
|
---|
| 195 | /** @name COM and internal init/term/mapping cruft.
|
---|
| 196 | * @{ */
|
---|
| 197 | DECLARE_COMMON_CLASS_METHODS(HostUpdateAgent)
|
---|
| 198 |
|
---|
| 199 | HRESULT init(VirtualBox *aVirtualBox);
|
---|
| 200 | void uninit(void);
|
---|
| 201 |
|
---|
| 202 | HRESULT FinalConstruct(void);
|
---|
| 203 | void FinalRelease(void);
|
---|
| 204 | /** @} */
|
---|
| 205 |
|
---|
| 206 | private:
|
---|
| 207 | /** @name Implemented (pure) virtual methods from UpdateAgent.
|
---|
| 208 | * @{ */
|
---|
[94670] | 209 | HRESULT checkFor(ComPtr<IProgress> &aProgress);
|
---|
[94648] | 210 |
|
---|
[94702] | 211 | DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask);
|
---|
[94643] | 212 | /** @} */
|
---|
| 213 |
|
---|
| 214 | HRESULT i_checkForUpdate(void);
|
---|
| 215 | HRESULT i_checkForUpdateInner(RTHTTP hHttp, com::Utf8Str const &strUrl, com::Utf8Str const &strUserAgent);
|
---|
| 216 | };
|
---|
| 217 |
|
---|
| 218 | #endif /* !MAIN_INCLUDED_UpdateAgentImpl_h */
|
---|
| 219 |
|
---|