Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ssu
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mer-core
ssu
Commits
268affd1
Commit
268affd1
authored
Oct 21, 2012
by
Aard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ssu.ini versioned, allow adding new keys/update unchanged default values
parent
b1410bd7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
7 deletions
+82
-7
constants.h
constants.h
+2
-0
libssu/ssu.cpp
libssu/ssu.cpp
+63
-6
ssu-defaults.ini
ssu-defaults.ini
+16
-0
ssu.pro
ssu.pro
+1
-1
No files found.
constants.h
View file @
268affd1
...
...
@@ -14,6 +14,8 @@
#define SSU_CONFIGURATION "/etc/ssu/ssu.ini"
/// Path to the main SSU configuration file
#define SSU_REPO_CONFIGURATION "/usr/share/ssu/repos.ini"
/// Path to the main SSU configuration file
#define SSU_DEFAULT_CONFIGURATION "/usr/share/ssu/ssu-defaults.ini"
/// The SSU protocol version used by the ssu client libraries
#define SSU_PROTOCOL_VERSION "1"
#endif
libssu/ssu.cpp
View file @
268affd1
...
...
@@ -31,12 +31,69 @@ Ssu::Ssu(): QObject(){
settings
=
new
QSettings
(
SSU_CONFIGURATION
,
QSettings
::
IniFormat
);
repoSettings
=
new
QSettings
(
SSU_REPO_CONFIGURATION
,
QSettings
::
IniFormat
);
bool
initialized
=
settings
->
value
(
"initialized"
).
toBool
();
if
(
!
initialized
){
// FIXME, there's currently no fallback for missing configuration
settings
->
setValue
(
"initialized"
,
true
);
settings
->
setValue
(
"flavour"
,
"testing"
);
QSettings
defaultSettings
(
SSU_DEFAULT_CONFIGURATION
,
QSettings
::
IniFormat
);
int
configVersion
=
0
;
int
defaultConfigVersion
=
0
;
if
(
settings
->
contains
(
"configVersion"
))
configVersion
=
settings
->
value
(
"configVersion"
).
toInt
();
if
(
defaultSettings
.
contains
(
"configVersion"
))
defaultConfigVersion
=
defaultSettings
.
value
(
"configVersion"
).
toInt
();
if
(
configVersion
<
defaultConfigVersion
){
qDebug
()
<<
"Configuration is outdated, updating from "
<<
configVersion
<<
" to "
<<
defaultConfigVersion
;
for
(
int
i
=
configVersion
+
1
;
i
<=
defaultConfigVersion
;
i
++
){
QStringList
defaultKeys
;
QString
currentSection
=
QString
(
"%1/"
).
arg
(
i
);
qDebug
()
<<
"Processing configuration version "
<<
i
;
defaultSettings
.
beginGroup
(
currentSection
);
defaultKeys
=
defaultSettings
.
allKeys
();
defaultSettings
.
endGroup
();
foreach
(
const
QString
&
key
,
defaultKeys
){
if
(
!
settings
->
contains
(
key
)){
// Add new keys..
settings
->
setValue
(
key
,
defaultSettings
.
value
(
currentSection
+
key
));
qDebug
()
<<
"Adding new key: "
<<
key
;
}
else
{
// ... or update the ones where default values has changed.
QVariant
oldValue
;
// check if an old value exists in an older configuration version
for
(
int
j
=
i
-
1
;
j
>
0
;
j
--
){
if
(
defaultSettings
.
contains
(
QString
(
"%1/"
).
arg
(
j
)
+
key
)){
oldValue
=
defaultSettings
.
value
(
QString
(
"%1/"
).
arg
(
j
)
+
key
);
break
;
}
}
// skip updating if there is no old value, since we can't check if the
// default value has changed
if
(
oldValue
.
isNull
())
continue
;
QVariant
newValue
=
defaultSettings
.
value
(
currentSection
+
key
);
if
(
oldValue
==
newValue
){
// old and new value match, no need to do anything, apart from beating the
// person who added a useless key
continue
;
}
else
{
// default value has changed, so check if the configuration is still
// using the old default value...
QVariant
currentValue
=
settings
->
value
(
key
);
// testcase: handles properly default update of thing with changed value in ssu.ini?
if
(
currentValue
==
oldValue
){
// ...and update the key if it does
settings
->
setValue
(
key
,
newValue
);
qDebug
()
<<
"Updating "
<<
key
<<
" from "
<<
currentValue
<<
" to "
<<
newValue
;
}
}
}
}
settings
->
setValue
(
"configVersion"
,
i
);
}
}
#ifdef TARGET_ARCH
...
...
ssu-defaults.ini
0 → 100644
View file @
268affd1
[General]
configVersion
=
2
[1]
flavour
=
testing
registered
=
false
rndRelease
=
latest
release
=
adaptation
=
ca-certificate
=
credentials-url
=
https://example.com/ssu/device/%1/credentials.xml
register-url
=
https://example.com/ssu/device/%1/register.xml
credentials-scope
=
example
[2]
release
=
latest
ssu.pro
View file @
268affd1
...
...
@@ -20,7 +20,7 @@ tests.depends = libssu
config
.
files
=
ssu
.
ini
config
.
path
=
/
etc
/
ssu
static_config
.
files
=
repos
.
ini
static_config
.
files
=
repos
.
ini
ssu
-
defaults
.
ini
static_config
.
path
=
/
usr
/
share
/
ssu
INSTALLS
+=
config
static_config
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment