diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-20 19:01:40 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-20 19:01:40 +0300 |
commit | 2052acf054291c2915ace9da9cc1a395c3abf832 (patch) | |
tree | 646d57659ffea2e9e143cf35928fea0a14446487 /src | |
parent | 33190c949f5249e211810cb57dced95eb3dfb39d (diff) |
Added timestamps to serialized responses
A new version of the binary serialization format that includes timestamps for GmResponse.
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 7 | ||||
-rw-r--r-- | src/defs.h | 35 | ||||
-rw-r--r-- | src/gmcerts.c | 10 | ||||
-rw-r--r-- | src/gmrequest.c | 7 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 3 |
5 files changed, 54 insertions, 8 deletions
@@ -22,6 +22,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
22 | 22 | ||
23 | #include "app.h" | 23 | #include "app.h" |
24 | #include "bookmarks.h" | 24 | #include "bookmarks.h" |
25 | #include "defs.h" | ||
25 | #include "embedded.h" | 26 | #include "embedded.h" |
26 | #include "gmcerts.h" | 27 | #include "gmcerts.h" |
27 | #include "gmdocument.h" | 28 | #include "gmdocument.h" |
@@ -255,9 +256,9 @@ static iBool loadState_App_(iApp *d) { | |||
255 | printf("%s: format not recognized\n", cstr_String(path_File(f))); | 256 | printf("%s: format not recognized\n", cstr_String(path_File(f))); |
256 | return iFalse; | 257 | return iFalse; |
257 | } | 258 | } |
258 | const int version = read32_File(f); | 259 | const uint32_t version = readU32_File(f); |
259 | /* Check supported versions. */ | 260 | /* Check supported versions. */ |
260 | if (version != 0) { | 261 | if (version > latest_FileVersion) { |
261 | printf("%s: unsupported version\n", cstr_String(path_File(f))); | 262 | printf("%s: unsupported version\n", cstr_String(path_File(f))); |
262 | return iFalse; | 263 | return iFalse; |
263 | } | 264 | } |
@@ -303,7 +304,7 @@ static void saveState_App_(const iApp *d) { | |||
303 | iFile *f = newCStr_File(concatPath_CStr(dataDir_App_, stateFileName_App_)); | 304 | iFile *f = newCStr_File(concatPath_CStr(dataDir_App_, stateFileName_App_)); |
304 | if (open_File(f, writeOnly_FileMode)) { | 305 | if (open_File(f, writeOnly_FileMode)) { |
305 | writeData_File(f, magicState_App_, 4); | 306 | writeData_File(f, magicState_App_, 4); |
306 | write32_File(f, 0); /* version */ | 307 | writeU32_File(f, latest_FileVersion); /* version */ |
307 | iConstForEach(ObjectList, i, iClob(listDocuments_App())) { | 308 | iConstForEach(ObjectList, i, iClob(listDocuments_App())) { |
308 | if (isInstance_Object(i.object, &Class_DocumentWidget)) { | 309 | if (isInstance_Object(i.object, &Class_DocumentWidget)) { |
309 | writeData_File(f, magicTabDocument_App_, 4); | 310 | writeData_File(f, magicTabDocument_App_, 4); |
diff --git a/src/defs.h b/src/defs.h new file mode 100644 index 00000000..3280667e --- /dev/null +++ b/src/defs.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /* Copyright 2020 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
2 | |||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions are met: | ||
5 | |||
6 | 1. Redistributions of source code must retain the above copyright notice, this | ||
7 | list of conditions and the following disclaimer. | ||
8 | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
9 | this list of conditions and the following disclaimer in the documentation | ||
10 | and/or other materials provided with the distribution. | ||
11 | |||
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
19 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
20 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | ||
22 | |||
23 | #pragma once | ||
24 | |||
25 | enum iFileVersion { | ||
26 | initial_FileVersion = 0, | ||
27 | addedResponseTimestamps_FileVersion = 1, | ||
28 | /* meta */ | ||
29 | latest_FileVersion = 1 | ||
30 | }; | ||
31 | |||
32 | /* Icons */ | ||
33 | |||
34 | #define openLock_CStr "\U0001f513" | ||
35 | #define closedLock_CStr "\U0001f512" | ||
diff --git a/src/gmcerts.c b/src/gmcerts.c index c358573c..b5b7b371 100644 --- a/src/gmcerts.c +++ b/src/gmcerts.c | |||
@@ -21,6 +21,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | 21 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
22 | 22 | ||
23 | #include "gmcerts.h" | 23 | #include "gmcerts.h" |
24 | #include "defs.h" | ||
24 | 25 | ||
25 | #include <the_Foundation/file.h> | 26 | #include <the_Foundation/file.h> |
26 | #include <the_Foundation/fileinfo.h> | 27 | #include <the_Foundation/fileinfo.h> |
@@ -202,7 +203,7 @@ static void saveIdentities_GmCerts_(const iGmCerts *d) { | |||
202 | iFile *f = new_File(collect_String(concatCStr_Path(&d->saveDir, identsFilename_GmCerts_))); | 203 | iFile *f = new_File(collect_String(concatCStr_Path(&d->saveDir, identsFilename_GmCerts_))); |
203 | if (open_File(f, writeOnly_FileMode)) { | 204 | if (open_File(f, writeOnly_FileMode)) { |
204 | writeData_File(f, magicIdMeta_GmCerts_, 4); | 205 | writeData_File(f, magicIdMeta_GmCerts_, 4); |
205 | writeU32_File(f, 0); /* version */ | 206 | writeU32_File(f, latest_FileVersion); /* version */ |
206 | iConstForEach(PtrArray, i, &d->idents) { | 207 | iConstForEach(PtrArray, i, &d->idents) { |
207 | const iGmIdentity *ident = i.ptr; | 208 | const iGmIdentity *ident = i.ptr; |
208 | if (~ident->flags & temporary_GmIdentityFlag) { | 209 | if (~ident->flags & temporary_GmIdentityFlag) { |
@@ -245,7 +246,12 @@ static void loadIdentities_GmCerts_(iGmCerts *d) { | |||
245 | printf("%s: format not recognized\n", cstr_String(path_File(f))); | 246 | printf("%s: format not recognized\n", cstr_String(path_File(f))); |
246 | return; | 247 | return; |
247 | } | 248 | } |
248 | setVersion_Stream(stream_File(f), readU32_File(f)); | 249 | const uint32_t version = readU32_File(f); |
250 | if (version > latest_FileVersion) { | ||
251 | printf("%s: unsupported version\n", cstr_String(path_File(f))); | ||
252 | return; | ||
253 | } | ||
254 | setVersion_Stream(stream_File(f), version); | ||
249 | while (!atEnd_File(f)) { | 255 | while (!atEnd_File(f)) { |
250 | readData_File(f, sizeof(magic), magic); | 256 | readData_File(f, sizeof(magic), magic); |
251 | if (!memcmp(magic, magicIdentity_GmCerts_, sizeof(magic))) { | 257 | if (!memcmp(magic, magicIdentity_GmCerts_, sizeof(magic))) { |
diff --git a/src/gmrequest.c b/src/gmrequest.c index 7b6414d2..3faa2833 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
26 | #include "app.h" /* dataDir_App() */ | 26 | #include "app.h" /* dataDir_App() */ |
27 | #include "embedded.h" | 27 | #include "embedded.h" |
28 | #include "ui/text.h" | 28 | #include "ui/text.h" |
29 | #include "defs.h" | ||
29 | 30 | ||
30 | #include <the_Foundation/file.h> | 31 | #include <the_Foundation/file.h> |
31 | #include <the_Foundation/mutex.h> | 32 | #include <the_Foundation/mutex.h> |
@@ -86,7 +87,7 @@ void serialize_GmResponse(const iGmResponse *d, iStream *outs) { | |||
86 | write32_Stream(outs, d->certFlags); | 87 | write32_Stream(outs, d->certFlags); |
87 | serialize_Date(&d->certValidUntil, outs); | 88 | serialize_Date(&d->certValidUntil, outs); |
88 | serialize_String(&d->certSubject, outs); | 89 | serialize_String(&d->certSubject, outs); |
89 | /* TODO: Include the timestamp. */ | 90 | writeU64_Stream(outs, d->when.ts.tv_sec); |
90 | } | 91 | } |
91 | 92 | ||
92 | void deserialize_GmResponse(iGmResponse *d, iStream *ins) { | 93 | void deserialize_GmResponse(iGmResponse *d, iStream *ins) { |
@@ -96,6 +97,10 @@ void deserialize_GmResponse(iGmResponse *d, iStream *ins) { | |||
96 | d->certFlags = read32_Stream(ins); | 97 | d->certFlags = read32_Stream(ins); |
97 | deserialize_Date(&d->certValidUntil, ins); | 98 | deserialize_Date(&d->certValidUntil, ins); |
98 | deserialize_String(&d->certSubject, ins); | 99 | deserialize_String(&d->certSubject, ins); |
100 | iZap(d->when); | ||
101 | if (version_Stream(ins) >= addedResponseTimestamps_FileVersion) { | ||
102 | d->when.ts.tv_sec = readU64_Stream(ins); | ||
103 | } | ||
99 | } | 104 | } |
100 | 105 | ||
101 | /*----------------------------------------------------------------------------------------------*/ | 106 | /*----------------------------------------------------------------------------------------------*/ |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index b56e9be8..558c320d 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -25,6 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
25 | #include "app.h" | 25 | #include "app.h" |
26 | #include "audio/player.h" | 26 | #include "audio/player.h" |
27 | #include "command.h" | 27 | #include "command.h" |
28 | #include "defs.h" | ||
28 | #include "gmdocument.h" | 29 | #include "gmdocument.h" |
29 | #include "gmrequest.h" | 30 | #include "gmrequest.h" |
30 | #include "gmutil.h" | 31 | #include "gmutil.h" |
@@ -868,8 +869,6 @@ static void fetch_DocumentWidget_(iDocumentWidget *d) { | |||
868 | } | 869 | } |
869 | 870 | ||
870 | static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response) { | 871 | static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response) { |
871 | #define openLock_CStr "\U0001f513" | ||
872 | #define closedLock_CStr "\U0001f512" | ||
873 | if (response) { | 872 | if (response) { |
874 | d->certFlags = response->certFlags; | 873 | d->certFlags = response->certFlags; |
875 | d->certExpiry = response->certValidUntil; | 874 | d->certExpiry = response->certValidUntil; |