summaryrefslogtreecommitdiff
path: root/src/gmcerts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmcerts.c')
-rw-r--r--src/gmcerts.c60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/gmcerts.c b/src/gmcerts.c
index 0c6d709c..cffa744f 100644
--- a/src/gmcerts.c
+++ b/src/gmcerts.c
@@ -61,50 +61,38 @@ iDefineClass(TrustEntry)
61 61
62/*----------------------------------------------------------------------------------------------*/ 62/*----------------------------------------------------------------------------------------------*/
63 63
64static int cmpUrl_GmIdentity_(const void *a, const void *b) { 64static int cmpUrl_GmIdentity_(const iString *a, const iString *b) {
65 return cmpStringCase_String((const iString *) a, (const iString *) b); 65 return cmpStringCase_String(a, b);
66} 66}
67 67
68void init_GmIdentity(iGmIdentity *d) { 68void init_GmIdentity(iGmIdentity *d) {
69 d->icon = 0x1f511; /* key */ 69 d->icon = 0x1f511; /* key */
70 d->flags = 0; 70 d->flags = 0;
71 d->cert = new_TlsCertificate(); 71 d->cert = new_TlsCertificate();
72// init_String(&d->fileName);
73 init_Block(&d->fingerprint, 0); 72 init_Block(&d->fingerprint, 0);
74 init_SortedArray(&d->useUrls, sizeof(iString), cmpUrl_GmIdentity_); 73 d->useUrls = newCmp_StringSet(cmpUrl_GmIdentity_);
75 init_String(&d->notes); 74 init_String(&d->notes);
76} 75}
77 76
78static void clear_GmIdentity_(iGmIdentity *d) {
79 iForEach(Array, i, &d->useUrls.values) {
80 deinit_String(i.value);
81 }
82 clear_SortedArray(&d->useUrls);
83}
84
85void deinit_GmIdentity(iGmIdentity *d) { 77void deinit_GmIdentity(iGmIdentity *d) {
86 clear_GmIdentity_(d); 78 iRelease(d->useUrls);
87 deinit_String(&d->notes); 79 deinit_String(&d->notes);
88 deinit_SortedArray(&d->useUrls);
89 delete_TlsCertificate(d->cert); 80 delete_TlsCertificate(d->cert);
90 deinit_Block(&d->fingerprint); 81 deinit_Block(&d->fingerprint);
91// deinit_String(&d->fileName);
92} 82}
93 83
94void serialize_GmIdentity(const iGmIdentity *d, iStream *outs) { 84void serialize_GmIdentity(const iGmIdentity *d, iStream *outs) {
95// serialize_String(&d->fileName, outs);
96 serialize_Block(&d->fingerprint, outs); 85 serialize_Block(&d->fingerprint, outs);
97 writeU32_Stream(outs, d->icon); 86 writeU32_Stream(outs, d->icon);
98 serialize_String(&d->notes, outs); 87 serialize_String(&d->notes, outs);
99 write32_Stream(outs, d->flags); 88 write32_Stream(outs, d->flags);
100 writeU32_Stream(outs, size_SortedArray(&d->useUrls)); 89 writeU32_Stream(outs, size_StringSet(d->useUrls));
101 iConstForEach(Array, i, &d->useUrls.values) { 90 iConstForEach(StringSet, i, d->useUrls) {
102 serialize_String(i.value, outs); 91 serialize_String(i.value, outs);
103 } 92 }
104} 93}
105 94
106void deserialize_GmIdentity(iGmIdentity *d, iStream *ins) { 95void deserialize_GmIdentity(iGmIdentity *d, iStream *ins) {
107// deserialize_String(&d->fileName, ins);
108 deserialize_Block(&d->fingerprint, ins); 96 deserialize_Block(&d->fingerprint, ins);
109 d->icon = readU32_Stream(ins); 97 d->icon = readU32_Stream(ins);
110 deserialize_String(&d->notes, ins); 98 deserialize_String(&d->notes, ins);
@@ -114,7 +102,8 @@ void deserialize_GmIdentity(iGmIdentity *d, iStream *ins) {
114 iString url; 102 iString url;
115 init_String(&url); 103 init_String(&url);
116 deserialize_String(&url, ins); 104 deserialize_String(&url, ins);
117 insert_SortedArray(&d->useUrls, &url); 105 insert_StringSet(d->useUrls, &url);
106 deinit_String(&url);
118 } 107 }
119} 108}
120 109
@@ -149,7 +138,36 @@ static iBool writeTextFile_(const iString *path, const iString *content) {
149} 138}
150 139
151iBool isUsed_GmIdentity(const iGmIdentity *d) { 140iBool isUsed_GmIdentity(const iGmIdentity *d) {
152 return d && !isEmpty_SortedArray(&d->useUrls); 141 return d && !isEmpty_StringSet(d->useUrls);
142}
143
144iBool isUsedOn_GmIdentity(const iGmIdentity *d, const iString *url) {
145 size_t pos = iInvalidPos;
146 locate_StringSet(d->useUrls, url, &pos);
147 if (pos < size_StringSet(d->useUrls)) {
148 return startsWithCase_String(url, cstr_String(constAt_StringSet(d->useUrls, pos)));
149 }
150 return iFalse;
151}
152
153void setUse_GmIdentity(iGmIdentity *d, const iString *url, iBool use) {
154 if (use && isUsedOn_GmIdentity(d, url)) {
155 return; /* Redudant. */
156 }
157 if (use) {
158#if !defined (NDEBUG)
159 const iBool wasInserted =
160#endif
161 insert_StringSet(d->useUrls, url);
162 iAssert(wasInserted);
163 }
164 else {
165 remove_StringSet(d->useUrls, url);
166 }
167}
168
169void clearUse_GmIdentity(iGmIdentity *d) {
170 clear_StringSet(d->useUrls);
153} 171}
154 172
155iDefineTypeConstruction(GmIdentity) 173iDefineTypeConstruction(GmIdentity)
@@ -375,7 +393,7 @@ iBool checkTrust_GmCerts(iGmCerts *d, iRangecc domain, const iTlsCertificate *ce
375const iGmIdentity *identityForUrl_GmCerts(const iGmCerts *d, const iString *url) { 393const iGmIdentity *identityForUrl_GmCerts(const iGmCerts *d, const iString *url) {
376 iConstForEach(PtrArray, i, &d->idents) { 394 iConstForEach(PtrArray, i, &d->idents) {
377 const iGmIdentity *ident = i.ptr; 395 const iGmIdentity *ident = i.ptr;
378 iConstForEach(Array, j, &ident->useUrls.values) { 396 iConstForEach(StringSet, j, ident->useUrls) {
379 const iString *used = j.value; 397 const iString *used = j.value;
380 if (startsWithCase_String(url, cstr_String(used))) { 398 if (startsWithCase_String(url, cstr_String(used))) {
381 return ident; 399 return ident;