summaryrefslogtreecommitdiff
path: root/src/sitespec.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-21 14:35:32 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-21 14:35:32 +0200
commitc58985ed3105ff7fc29fc0d53ba81ba55882e05e (patch)
tree0dd4e254645ce7478a8fc6e01d7f7fa1e51784e4 /src/sitespec.c
parent67f1a5b152ca90fd8346bd39957905edaf3fb1cc (diff)
Site-specific Titan upload identity
The identity to be used for uploads is now in sitespec.ini, so it applies to an entire site root. This should match actual use cases better than having URL-specific identities. Also fixed an issue with native menus. Replacing the items with new ones was not implemented. IssueID #379
Diffstat (limited to 'src/sitespec.c')
-rw-r--r--src/sitespec.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/sitespec.c b/src/sitespec.c
index 0332af2d..6f4546f0 100644
--- a/src/sitespec.c
+++ b/src/sitespec.c
@@ -33,17 +33,19 @@ iDeclareObjectConstruction(SiteParams)
33struct Impl_SiteParams { 33struct Impl_SiteParams {
34 iObject object; 34 iObject object;
35 uint16_t titanPort; 35 uint16_t titanPort;
36 iString titanIdentity; /* fingerprint */
36 int dismissWarnings; 37 int dismissWarnings;
37 /* TODO: theme seed, style settings */ 38 /* TODO: theme seed, style settings */
38}; 39};
39 40
40void init_SiteParams(iSiteParams *d) { 41void init_SiteParams(iSiteParams *d) {
41 d->titanPort = 0; /* undefined */ 42 d->titanPort = 0; /* undefined */
43 init_String(&d->titanIdentity);
42 d->dismissWarnings = 0; 44 d->dismissWarnings = 0;
43} 45}
44 46
45void deinit_SiteParams(iSiteParams *d) { 47void deinit_SiteParams(iSiteParams *d) {
46 iUnused(d); 48 deinit_String(&d->titanIdentity);
47} 49}
48 50
49iDefineClass(SiteParams) 51iDefineClass(SiteParams)
@@ -122,6 +124,9 @@ static void handleIniKeyValue_SiteSpec_(void *context, const iString *table, con
122 if (!cmp_String(key, "titanPort")) { 124 if (!cmp_String(key, "titanPort")) {
123 d->loadParams->titanPort = number_TomlValue(value); 125 d->loadParams->titanPort = number_TomlValue(value);
124 } 126 }
127 else if (!cmp_String(key, "titanIdentity") && value->type == string_TomlType) {
128 set_String(&d->loadParams->titanIdentity, value->value.string);
129 }
125 else if (!cmp_String(key, "dismissWarnings") && value->type == int64_TomlType) { 130 else if (!cmp_String(key, "dismissWarnings") && value->type == int64_TomlType) {
126 d->loadParams->dismissWarnings = value->value.int64; 131 d->loadParams->dismissWarnings = value->value.int64;
127 } 132 }
@@ -152,6 +157,10 @@ static void save_SiteSpec_(iSiteSpec *d) {
152 if (params->titanPort) { 157 if (params->titanPort) {
153 appendFormat_String(buf, "titanPort = %u\n", params->titanPort); 158 appendFormat_String(buf, "titanPort = %u\n", params->titanPort);
154 } 159 }
160 if (!isEmpty_String(&params->titanIdentity)) {
161 appendFormat_String(
162 buf, "titanIdentity = \"%s\"\n", cstr_String(&params->titanIdentity));
163 }
155 if (params->dismissWarnings) { 164 if (params->dismissWarnings) {
156 appendFormat_String(buf, "dismissWarnings = 0x%x\n", params->dismissWarnings); 165 appendFormat_String(buf, "dismissWarnings = 0x%x\n", params->dismissWarnings);
157 } 166 }
@@ -205,6 +214,30 @@ void setValue_SiteSpec(const iString *site, enum iSiteSpecKey key, int value) {
205 } 214 }
206} 215}
207 216
217void setValueString_SiteSpec(const iString *site, enum iSiteSpecKey key, const iString *value) {
218 iSiteSpec *d = &siteSpec_;
219 const iString *hashKey = collect_String(lower_String(site));
220 iSiteParams *params = value_StringHash(&d->sites, hashKey);
221 if (!params) {
222 params = new_SiteParams();
223 insert_StringHash(&d->sites, hashKey, params);
224 }
225 iBool needSave = iFalse;
226 switch (key) {
227 case titanIdentity_SiteSpecKey:
228 if (!equal_String(&params->titanIdentity, value)) {
229 needSave = iTrue;
230 set_String(&params->titanIdentity, value);
231 }
232 break;
233 default:
234 break;
235 }
236 if (needSave) {
237 save_SiteSpec_(d);
238 }
239}
240
208int value_SiteSpec(const iString *site, enum iSiteSpecKey key) { 241int value_SiteSpec(const iString *site, enum iSiteSpecKey key) {
209 iSiteSpec *d = &siteSpec_; 242 iSiteSpec *d = &siteSpec_;
210 const iSiteParams *params = constValue_StringHash(&d->sites, collect_String(lower_String(site))); 243 const iSiteParams *params = constValue_StringHash(&d->sites, collect_String(lower_String(site)));
@@ -220,3 +253,17 @@ int value_SiteSpec(const iString *site, enum iSiteSpecKey key) {
220 return 0; 253 return 0;
221 } 254 }
222} 255}
256
257const iString *valueString_SiteSpec(const iString *site, enum iSiteSpecKey key) {
258 iSiteSpec *d = &siteSpec_;
259 const iSiteParams *params = constValue_StringHash(&d->sites, collect_String(lower_String(site)));
260 if (!params) {
261 return 0;
262 }
263 switch (key) {
264 case titanIdentity_SiteSpecKey:
265 return &params->titanIdentity;
266 default:
267 return collectNew_String();
268 }
269}