Fossil SCM

Restructure /json/settings/get output from an array of objects to a map of objects, keyed on setting name, per forum discussion.

stephan 2023-01-19 23:32 json-settings-command
Commit d0bf9682a91eaedd2f29ff84e3b4113b13bf8cabb935f1322e942e75e4b92a5c
1 file changed +3 -4
--- src/json_config.c
+++ src/json_config.c
@@ -208,11 +208,11 @@
208208
209209
/*
210210
** Impl of /json/settings/get.
211211
*/
212212
static cson_value * json_settings_get(void){
213
- cson_array * pay = cson_new_array(); /* output payload */
213
+ cson_object * pay = cson_new_object(); /* output payload */
214214
int nSetting, i; /* setting count and loop var */
215215
const Setting *aSetting = setting_info(&nSetting);
216216
const char * zRevision = 0; /* revision to look for
217217
versioned settings in */
218218
char * zUuid = 0; /* Resolved UUID of zRevision */
@@ -254,12 +254,11 @@
254254
for(i=0; i<nSetting; ++i){
255255
const Setting *pSet = &aSetting[i];
256256
cson_object * jSet;
257257
cson_value * pVal = 0, * pSrc = 0;
258258
jSet = cson_new_object();
259
- cson_array_append(pay, cson_object_value(jSet));
260
- cson_object_set(jSet, "name", json_new_string(pSet->name));
259
+ cson_object_set(pay, pSet->name, cson_object_value(jSet));
261260
cson_object_set(jSet, "versionable", cson_value_new_bool(pSet->versionable));
262261
cson_object_set(jSet, "sensitive", cson_value_new_bool(pSet->sensitive));
263262
cson_object_set(jSet, "defaultValue", (pSet->def && pSet->def[0])
264263
? json_new_string(pSet->def)
265264
: cson_value_null());
@@ -314,9 +313,9 @@
314313
cson_object_set(jSet, "value", pVal ? pVal : cson_value_null());
315314
}/*aSetting loop*/
316315
db_finalize(&q);
317316
db_finalize(&qFoci);
318317
fossil_free(zUuid);
319
- return cson_array_value(pay);
318
+ return cson_object_value(pay);
320319
}
321320
322321
#endif /* FOSSIL_ENABLE_JSON */
323322
--- src/json_config.c
+++ src/json_config.c
@@ -208,11 +208,11 @@
208
209 /*
210 ** Impl of /json/settings/get.
211 */
212 static cson_value * json_settings_get(void){
213 cson_array * pay = cson_new_array(); /* output payload */
214 int nSetting, i; /* setting count and loop var */
215 const Setting *aSetting = setting_info(&nSetting);
216 const char * zRevision = 0; /* revision to look for
217 versioned settings in */
218 char * zUuid = 0; /* Resolved UUID of zRevision */
@@ -254,12 +254,11 @@
254 for(i=0; i<nSetting; ++i){
255 const Setting *pSet = &aSetting[i];
256 cson_object * jSet;
257 cson_value * pVal = 0, * pSrc = 0;
258 jSet = cson_new_object();
259 cson_array_append(pay, cson_object_value(jSet));
260 cson_object_set(jSet, "name", json_new_string(pSet->name));
261 cson_object_set(jSet, "versionable", cson_value_new_bool(pSet->versionable));
262 cson_object_set(jSet, "sensitive", cson_value_new_bool(pSet->sensitive));
263 cson_object_set(jSet, "defaultValue", (pSet->def && pSet->def[0])
264 ? json_new_string(pSet->def)
265 : cson_value_null());
@@ -314,9 +313,9 @@
314 cson_object_set(jSet, "value", pVal ? pVal : cson_value_null());
315 }/*aSetting loop*/
316 db_finalize(&q);
317 db_finalize(&qFoci);
318 fossil_free(zUuid);
319 return cson_array_value(pay);
320 }
321
322 #endif /* FOSSIL_ENABLE_JSON */
323
--- src/json_config.c
+++ src/json_config.c
@@ -208,11 +208,11 @@
208
209 /*
210 ** Impl of /json/settings/get.
211 */
212 static cson_value * json_settings_get(void){
213 cson_object * pay = cson_new_object(); /* output payload */
214 int nSetting, i; /* setting count and loop var */
215 const Setting *aSetting = setting_info(&nSetting);
216 const char * zRevision = 0; /* revision to look for
217 versioned settings in */
218 char * zUuid = 0; /* Resolved UUID of zRevision */
@@ -254,12 +254,11 @@
254 for(i=0; i<nSetting; ++i){
255 const Setting *pSet = &aSetting[i];
256 cson_object * jSet;
257 cson_value * pVal = 0, * pSrc = 0;
258 jSet = cson_new_object();
259 cson_object_set(pay, pSet->name, cson_object_value(jSet));
 
260 cson_object_set(jSet, "versionable", cson_value_new_bool(pSet->versionable));
261 cson_object_set(jSet, "sensitive", cson_value_new_bool(pSet->sensitive));
262 cson_object_set(jSet, "defaultValue", (pSet->def && pSet->def[0])
263 ? json_new_string(pSet->def)
264 : cson_value_null());
@@ -314,9 +313,9 @@
313 cson_object_set(jSet, "value", pVal ? pVal : cson_value_null());
314 }/*aSetting loop*/
315 db_finalize(&q);
316 db_finalize(&qFoci);
317 fossil_free(zUuid);
318 return cson_object_value(pay);
319 }
320
321 #endif /* FOSSIL_ENABLE_JSON */
322

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button