From c58985ed3105ff7fc29fc0d53ba81ba55882e05e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 21 Nov 2021 14:35:32 +0200 Subject: 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 --- src/sitespec.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'src/sitespec.c') 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) struct Impl_SiteParams { iObject object; uint16_t titanPort; + iString titanIdentity; /* fingerprint */ int dismissWarnings; /* TODO: theme seed, style settings */ }; void init_SiteParams(iSiteParams *d) { - d->titanPort = 0; /* undefined */ + d->titanPort = 0; /* undefined */ + init_String(&d->titanIdentity); d->dismissWarnings = 0; } void deinit_SiteParams(iSiteParams *d) { - iUnused(d); + deinit_String(&d->titanIdentity); } iDefineClass(SiteParams) @@ -122,6 +124,9 @@ static void handleIniKeyValue_SiteSpec_(void *context, const iString *table, con if (!cmp_String(key, "titanPort")) { d->loadParams->titanPort = number_TomlValue(value); } + else if (!cmp_String(key, "titanIdentity") && value->type == string_TomlType) { + set_String(&d->loadParams->titanIdentity, value->value.string); + } else if (!cmp_String(key, "dismissWarnings") && value->type == int64_TomlType) { d->loadParams->dismissWarnings = value->value.int64; } @@ -152,6 +157,10 @@ static void save_SiteSpec_(iSiteSpec *d) { if (params->titanPort) { appendFormat_String(buf, "titanPort = %u\n", params->titanPort); } + if (!isEmpty_String(¶ms->titanIdentity)) { + appendFormat_String( + buf, "titanIdentity = \"%s\"\n", cstr_String(¶ms->titanIdentity)); + } if (params->dismissWarnings) { appendFormat_String(buf, "dismissWarnings = 0x%x\n", params->dismissWarnings); } @@ -205,6 +214,30 @@ void setValue_SiteSpec(const iString *site, enum iSiteSpecKey key, int value) { } } +void setValueString_SiteSpec(const iString *site, enum iSiteSpecKey key, const iString *value) { + iSiteSpec *d = &siteSpec_; + const iString *hashKey = collect_String(lower_String(site)); + iSiteParams *params = value_StringHash(&d->sites, hashKey); + if (!params) { + params = new_SiteParams(); + insert_StringHash(&d->sites, hashKey, params); + } + iBool needSave = iFalse; + switch (key) { + case titanIdentity_SiteSpecKey: + if (!equal_String(¶ms->titanIdentity, value)) { + needSave = iTrue; + set_String(¶ms->titanIdentity, value); + } + break; + default: + break; + } + if (needSave) { + save_SiteSpec_(d); + } +} + int value_SiteSpec(const iString *site, enum iSiteSpecKey key) { iSiteSpec *d = &siteSpec_; 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) { return 0; } } + +const iString *valueString_SiteSpec(const iString *site, enum iSiteSpecKey key) { + iSiteSpec *d = &siteSpec_; + const iSiteParams *params = constValue_StringHash(&d->sites, collect_String(lower_String(site))); + if (!params) { + return 0; + } + switch (key) { + case titanIdentity_SiteSpecKey: + return ¶ms->titanIdentity; + default: + return collectNew_String(); + } +} -- cgit v1.2.3