summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/include/UpdateAgentImpl.h
blob: 4381c517bb69dda6709b87af40b6a51732b3aa45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* $Id: UpdateAgentImpl.h $ */
/** @file
 * Update agent COM class implementation - Header
 */

/*
 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef MAIN_INCLUDED_UpdateAgentImpl_h
#define MAIN_INCLUDED_UpdateAgentImpl_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <iprt/http.h>

#include <VBox/settings.h>

#include "EventImpl.h"
#include "UpdateAgentWrap.h"
#include "HostUpdateAgentWrap.h"

class  UpdateAgentTask;
struct UpdateAgentTaskParms;

struct UpdateAgentTaskResult
{
    Utf8Str          strVer;
    Utf8Str          strWebUrl;
    Utf8Str          strDownloadUrl;
    UpdateSeverity_T enmSeverity;
    Utf8Str          strReleaseNotes;
};

class UpdateAgentBase
{
protected: /* Not directly instancable. */

    UpdateAgentBase()
        : m_VirtualBox(NULL)
        , m(new settings::UpdateAgent) { }

    virtual ~UpdateAgentBase() { delete m; }

public:

    /** @name Pure virtual public methods for internal purposes only
     *        (ensure there is a caller and a read lock before calling them!)
     * @{ */
    virtual HRESULT i_loadSettings(const settings::UpdateAgent &data) = 0;
    virtual HRESULT i_saveSettings(settings::UpdateAgent &data) = 0;

    virtual HRESULT i_setCheckCount(ULONG aCount) = 0;
    virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate) = 0;
    /** @} */

protected:

    /** @name Pure virtual internal task callbacks.
     * @{ */
    friend UpdateAgentTask;
    virtual DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask) = 0;
    /** @} */

    /** @name Static helper methods.
     * @{ */
    static Utf8Str i_getPlatformInfo(void);
    const char    *i_proxyModeToStr(ProxyMode_T enmMode);
    bool           i_urlSchemeIsSupported(const Utf8Str &strUrl) const;
    /** @} */

protected:
    /** The update agent's event source. */
    const ComObjPtr<EventSource> m_EventSource;
    VirtualBox * const           m_VirtualBox;

    /** @name Data members.
     * @{ */
    settings::UpdateAgent *m;

    struct Data
    {
        UpdateAgentTaskResult              m_lastResult;
        Utf8Str                            m_strName;
        /** Vector of update channels this agent supports. */
        const std::vector<UpdateChannel_T> m_enmChannels;
        bool                               m_fHidden;
        UpdateState_T                      m_enmState;
        uint32_t                           m_uOrder;

        Data(void)
        {
            m_fHidden  = true;
            m_enmState = UpdateState_Invalid;
            m_uOrder   = UINT32_MAX;
        }
    } mData;
    /** @} */
};

class ATL_NO_VTABLE UpdateAgent :
    public UpdateAgentWrap,
    public UpdateAgentBase
{
public:
    DECLARE_COMMON_CLASS_METHODS(UpdateAgent)

    /** @name COM and internal init/term/mapping cruft.
     * @{ */
    HRESULT FinalConstruct();
    void FinalRelease();

    HRESULT init(VirtualBox *aVirtualBox);
    void uninit(void);
    /** @}  */

    /** @name Public methods for internal purposes only
     *        (ensure there is a caller and a read lock before calling them!)
     * @{ */
    HRESULT i_loadSettings(const settings::UpdateAgent &data);
    HRESULT i_saveSettings(settings::UpdateAgent &data);

    virtual HRESULT i_setCheckCount(ULONG aCount);
    virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate);
    /** @} */

protected:

    /** @name Internal helper methods.
     * @{ */
    HRESULT i_getProxyMode(ProxyMode_T *aMode);
    HRESULT i_getProxyURL(com::Utf8Str &aAddress);
    HRESULT i_configureProxy(RTHTTP hHttp);
    HRESULT i_commitSettings(AutoWriteLock &aLock);
    HRESULT i_reportError(int vrc, const char *pcszMsgFmt, ...);
    /** @}  */

protected:
    /** @name Wrapped IUpdateAgent attributes and methods.
     * @{ */
    HRESULT checkFor(ComPtr<IProgress> &aProgress);
    HRESULT download(ComPtr<IProgress> &aProgress);
    HRESULT install(ComPtr<IProgress> &aProgress);
    HRESULT rollback(void);

    HRESULT getName(com::Utf8Str &aName);
    HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
    HRESULT getOrder(ULONG *aOrder);
    HRESULT getDependsOn(std::vector<com::Utf8Str> &aDeps);
    HRESULT getVersion(com::Utf8Str &aVer);
    HRESULT getDownloadUrl(com::Utf8Str &aUrl);
    HRESULT getWebUrl(com::Utf8Str &aUrl);
    HRESULT getReleaseNotes(com::Utf8Str &aRelNotes);
    HRESULT getEnabled(BOOL *aEnabled);
    HRESULT setEnabled(BOOL aEnabled);
    HRESULT getHidden(BOOL *aHidden);
    HRESULT getState(UpdateState_T *aState);
    HRESULT getCheckCount(ULONG *aCount);
    HRESULT getCheckFrequency(ULONG  *aFreqSeconds);
    HRESULT setCheckFrequency(ULONG aFreqSeconds);
    HRESULT getChannel(UpdateChannel_T *aChannel);
    HRESULT setChannel(UpdateChannel_T aChannel);
    HRESULT getRepositoryURL(com::Utf8Str &aRepo);
    HRESULT setRepositoryURL(const com::Utf8Str &aRepo);
    HRESULT getLastCheckDate(com::Utf8Str &aData);
    HRESULT getIsCheckNeeded(BOOL *aCheckNeeded);
    HRESULT getSupportedChannels(std::vector<UpdateChannel_T> &aSupportedChannels);
    /** @} */
};

/** @todo Put this into an own module, e.g. HostUpdateAgentImpl.[cpp|h]. */

class ATL_NO_VTABLE HostUpdateAgent :
    public UpdateAgent
{
public:
    /** @name COM and internal init/term/mapping cruft.
     * @{ */
    DECLARE_COMMON_CLASS_METHODS(HostUpdateAgent)

    HRESULT init(VirtualBox *aVirtualBox);
    void    uninit(void);

    HRESULT FinalConstruct(void);
    void    FinalRelease(void);
    /** @}  */

private:
    /** @name Implemented (pure) virtual methods from UpdateAgent.
     * @{ */
    HRESULT checkFor(ComPtr<IProgress> &aProgress);

    DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask);
    /** @}  */

    HRESULT i_checkForUpdate(void);
    HRESULT i_checkForUpdateInner(RTHTTP hHttp, com::Utf8Str const &strUrl, com::Utf8Str const &strUserAgent);
};

#endif /* !MAIN_INCLUDED_UpdateAgentImpl_h */