Skip to content

Latest commit

 

History

History
193 lines (178 loc) · 7 KB

ssu.h

File metadata and controls

193 lines (178 loc) · 7 KB
 
Oct 8, 2012
Oct 8, 2012
1
2
3
4
5
6
7
8
9
10
/**
* @file ssu.h
* @copyright 2012 Jolla Ltd.
* @author Bernd Wachter <bernd.wachter@jollamobile.com>
* @date 2012
*/
#ifndef _Ssu_H
#define _Ssu_H
Apr 4, 2013
Apr 4, 2013
11
#include <QDateTime>
Oct 8, 2012
Oct 8, 2012
12
13
14
#include <QObject>
#include <QDebug>
Apr 4, 2013
Apr 4, 2013
15
16
class QNetworkAccessManager;
class QNetworkReply;
Oct 7, 2013
Oct 7, 2013
17
class QDomDocument;
Mar 19, 2013
Mar 19, 2013
18
Oct 8, 2012
Oct 8, 2012
19
20
21
class Ssu: public QObject {
Q_OBJECT
Apr 9, 2013
Apr 9, 2013
22
23
friend class UrlResolverTest;
Oct 8, 2012
Oct 8, 2012
24
public:
Mar 30, 2013
Mar 30, 2013
25
Ssu();
Oct 8, 2012
Oct 8, 2012
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Find a username/password pair for the given scope
* @return a QPair with username and password, or an empty QPair if scope is invalid
*/
QPair<QString, QString> credentials(QString scope);
/**
* Get the scope for a repository, taking into account different scopes for
* release and RnD repositories
*
* Please note that variable scope is not yet implemented -- one default scope is
* read from the configuration file.
*
* @return a string containing the scope; it can be used to look up login credentials using credentials()
*/
QString credentialsScope(QString repoName, bool rndRepo=false);
Oct 24, 2012
Oct 24, 2012
41
42
43
44
/**
* Return the URL for which credentials scope is valid
*/
QString credentialsUrl(QString scope);
Oct 8, 2012
Oct 8, 2012
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Returns if the last operation was successful
* @retval true last operation was successful
* @retval false last operation failed, you should check lastError() for details
*/
Q_INVOKABLE bool error();
/**
* Return an error message for the last error encountered. The message
* will not be cleared, check error() to see if the last operation was
* successful.
*/
Q_INVOKABLE QString lastError();
/**
* Resolve a repository url
* @return the repository URL on success, an empty string on error
*/
Mar 28, 2013
Mar 28, 2013
61
62
63
QString repoUrl(QString repoName, bool rndRepo=false,
QHash<QString, QString> repoParameters=QHash<QString, QString>(),
QHash<QString, QString> parametersOverride=QHash<QString, QString>());
Oct 8, 2012
Oct 8, 2012
64
65
66
67
68
69
70
/**
* Unregister a device. This will clean all registration data from a device,
* though will not touch the information on SSU server; the information there
* has to be manually cleaned for a device we don't own anymore, but will be
* overwritten next time the device gets registered
*/
Q_INVOKABLE void unregister();
Mar 30, 2013
Mar 30, 2013
71
72
73
74
75
76
77
78
79
// wrappers around SsuCoreConfig
// not all of those belong into SsuCoreConfig, but will go there
// in the first phase of refactoring
/// See SsuCoreConfig::flavour
Q_INVOKABLE QString flavour();
/// See SsuCoreConfig::deviceMode
Q_INVOKABLE int deviceMode();
Jul 5, 2013
Jul 5, 2013
80
/// See SsuCoreConfig::domain; returns printable version
Mar 30, 2013
Mar 30, 2013
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Q_INVOKABLE QString domain();
/// See SsuCoreConfig::isRegistered
Q_INVOKABLE bool isRegistered();
/// See SsuCoreConfig::lastCredentialsUpdate
Q_INVOKABLE QDateTime lastCredentialsUpdate();
/// See SsuCoreConfig::release
Q_INVOKABLE QString release(bool rnd=false);
/// See SsuCoreConfig::setDeviceMode
Q_INVOKABLE void setDeviceMode(int mode, int editMode=Replace);
/// See SsuCoreConfig::setFlavour
Q_INVOKABLE void setFlavour(QString flavour);
/// See SsuCoreConfig::setRelease
Q_INVOKABLE void setRelease(QString release, bool rnd=false);
/// See SsuCoreConfig::setDomain
Q_INVOKABLE void setDomain(QString domain);
/// See SsuCoreConfig::useSslVerify
Oct 8, 2012
Oct 8, 2012
97
98
Q_INVOKABLE bool useSslVerify();
Oct 6, 2013
Oct 6, 2013
99
100
101
102
103
104
105
106
107
/**
* Filters to control the output of the repository lookup methods
*/
enum RepoFilter {
NoFilter, ///< All repositories (global + user)
UserFilter, ///< Only user configured repositories
BoardFilter, ///< Only global repositories, with user blacklist ignored
BoardFilterUserBlacklist ///< Only global repositories, with user blacklist applied
};
Mar 29, 2013
Mar 29, 2013
108
109
110
111
112
113
114
/**
* List of possible device modes
*
* ReleaseMode is defined to make a switch to allowing RnD and Release
* repositories on a device at the same time easy, if ever needed. Right
* now any mode where RndMode is not set is treated as ReleaseMode.
*/
Mar 28, 2013
Mar 28, 2013
115
enum DeviceMode {
Mar 30, 2013
Mar 30, 2013
116
117
118
DisableRepoManager = 0x1, ///< Disable automagic repository management
RndMode = 0x2, ///< Enable RnD mode for device
ReleaseMode = 0x4, ///< Enable Release mode
Mar 31, 2013
Mar 31, 2013
119
LenientMode = 0x8 ///< Disable strict mode (i.e., keep unmanaged repositories)
Mar 28, 2013
Mar 28, 2013
120
};
Oct 24, 2013
Oct 24, 2013
121
122
123
124
125
126
127
128
/**
* A list of types ssu provides shiny values suitable for displaying
*/
enum DisplayType {
DeviceManufacturer = 0, ///< Manufacturer, like ACME Corp. Board mappings key "deviceManufacturer"
DeviceModel, ///< Marketed device name, like Pogoblaster 3000. Board mappings key "prettyModel"
DeviceDesignation, ///< Type designation, like NCC-1701. Beard mappings key "deviceDesignation"
};
Mar 28, 2013
Mar 28, 2013
129
Mar 29, 2013
Mar 29, 2013
130
131
132
/**
* Edit modes for variables containing bitmasks
*/
Mar 28, 2013
Mar 28, 2013
133
enum EditMode {
Mar 29, 2013
Mar 29, 2013
134
135
136
Replace = 0x1, ///< Replace the old value with the new one
Add = 0x2, ///< Make sure the given value is set in the bitmask
Remove = 0x4 ///< Make sure the given value is not set in the bitmask
Mar 28, 2013
Mar 28, 2013
137
};
Mar 19, 2013
Mar 19, 2013
138
Oct 8, 2012
Oct 8, 2012
139
private:
Mar 30, 2013
Mar 30, 2013
140
QString errorString;
Oct 8, 2012
Oct 8, 2012
141
142
bool errorFlag;
QNetworkAccessManager *manager;
Nov 4, 2012
Nov 4, 2012
143
int pendingRequests;
Oct 8, 2012
Oct 8, 2012
144
145
146
bool registerDevice(QDomDocument *response);
bool setCredentials(QDomDocument *response);
bool verifyResponse(QDomDocument *response);
Nov 4, 2012
Nov 4, 2012
147
void storeAuthorizedKeys(QByteArray data);
Oct 8, 2012
Oct 8, 2012
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
private slots:
void requestFinished(QNetworkReply *reply);
/**
* Set errorString returned by lastError to errorMessage, set
* errorFlag returned by error() to true, and emit done()
*/
void setError(QString errorMessage);
public slots:
/**
* Attempt RND device registration, using @a username and @a password supplied
* @param username Jolla username
* @param password Jolla password
*
* When the operation has finished the done() signal will be sent. You can call
* error() to check if an error occured, and use lastError() to retrieve the last
* error message.
*/
void sendRegistration(QString username, QString password);
/**
* Try to update the RND repository credentials. The device needs to be registered
* for this to work. updateCredentials remembers the time of the last credentials
* update, and skips updating if only little time has elapsed since the last update.
* An update may be forced by setting @a force to true
* @param force force credentials updating
*
* When the operation has finished the done() signal will be sent. You can call
* error() to check if an error occured, and use lastError() to retrieve the last
* error message.
*/
void updateCredentials(bool force=false);
signals:
/**
* Emitted after an asynchronous operation finished
*/
void done();
Mar 30, 2013
Mar 30, 2013
186
187
188
/**
* Emitted after the devices registration status has changed
*/
Oct 8, 2012
Oct 8, 2012
189
190
191
192
193
void registrationStatusChanged();
void credentialsChanged();
};
#endif