|
@@ -180,6 +180,11 @@ int generic_settings_fetch ( struct settings *settings,
|
180
|
180
|
if ( len > generic->data_len )
|
181
|
181
|
len = generic->data_len;
|
182
|
182
|
memcpy ( data, generic_setting_data ( generic ), len );
|
|
183
|
+
|
|
184
|
+ /* Set setting type, if not yet specified */
|
|
185
|
+ if ( ! setting->type )
|
|
186
|
+ setting->type = generic->setting.type;
|
|
187
|
+
|
183
|
188
|
return generic->data_len;
|
184
|
189
|
}
|
185
|
190
|
|
|
@@ -614,8 +619,12 @@ static int fetch_setting_and_origin ( struct settings *settings,
|
614
|
619
|
if ( setting_applies ( settings, setting ) &&
|
615
|
620
|
( ( ret = settings->op->fetch ( settings, setting,
|
616
|
621
|
data, len ) ) >= 0 ) ) {
|
|
622
|
+ /* Record origin, if applicable */
|
617
|
623
|
if ( origin )
|
618
|
624
|
*origin = settings;
|
|
625
|
+ /* Default to string setting type, if not yet specified */
|
|
626
|
+ if ( ! setting->type )
|
|
627
|
+ setting->type = &setting_type_string;
|
619
|
628
|
return ret;
|
620
|
629
|
}
|
621
|
630
|
|
|
@@ -1132,6 +1141,7 @@ static struct setting_type * find_setting_type ( const char *name ) {
|
1132
|
1141
|
* @v get_child Function to find or create child settings block
|
1133
|
1142
|
* @v settings Settings block to fill in
|
1134
|
1143
|
* @v setting Setting to fill in
|
|
1144
|
+ * @v default_type Default type to use, if none specified
|
1135
|
1145
|
* @v tmp_name Buffer for copy of setting name
|
1136
|
1146
|
* @ret rc Return status code
|
1137
|
1147
|
*
|
|
@@ -1147,6 +1157,7 @@ parse_setting_name ( const char *name,
|
1147
|
1157
|
struct settings * ( * get_child ) ( struct settings *,
|
1148
|
1158
|
const char * ),
|
1149
|
1159
|
struct settings **settings, struct setting *setting,
|
|
1160
|
+ struct setting_type *default_type,
|
1150
|
1161
|
char *tmp_name ) {
|
1151
|
1162
|
char *settings_name;
|
1152
|
1163
|
char *setting_name;
|
|
@@ -1157,7 +1168,7 @@ parse_setting_name ( const char *name,
|
1157
|
1168
|
*settings = &settings_root;
|
1158
|
1169
|
memset ( setting, 0, sizeof ( *setting ) );
|
1159
|
1170
|
setting->name = "";
|
1160
|
|
- setting->type = &setting_type_string;
|
|
1171
|
+ setting->type = default_type;
|
1161
|
1172
|
|
1162
|
1173
|
/* Split name into "[settings_name/]setting_name[:type_name]" */
|
1163
|
1174
|
strcpy ( tmp_name, name );
|
|
@@ -1226,14 +1237,45 @@ int setting_name ( struct settings *settings, struct setting *setting,
|
1226
|
1237
|
setting->name, setting->type->name );
|
1227
|
1238
|
}
|
1228
|
1239
|
|
|
1240
|
+/**
|
|
1241
|
+ * Store value of named setting
|
|
1242
|
+ *
|
|
1243
|
+ * @v name Name of setting
|
|
1244
|
+ * @v default_type Default type to use, if none specified
|
|
1245
|
+ * @v data Setting data, or NULL to clear setting
|
|
1246
|
+ * @v len Length of setting data
|
|
1247
|
+ * @ret rc Return status code
|
|
1248
|
+ */
|
|
1249
|
+int store_named_setting ( const char *name, struct setting_type *default_type,
|
|
1250
|
+ const void *data, size_t len ) {
|
|
1251
|
+ struct settings *settings;
|
|
1252
|
+ struct setting setting;
|
|
1253
|
+ char tmp_name[ strlen ( name ) + 1 ];
|
|
1254
|
+ int rc;
|
|
1255
|
+
|
|
1256
|
+ /* Parse setting name */
|
|
1257
|
+ if ( ( rc = parse_setting_name ( name, autovivify_child_settings,
|
|
1258
|
+ &settings, &setting, default_type,
|
|
1259
|
+ tmp_name ) ) != 0 )
|
|
1260
|
+ return rc;
|
|
1261
|
+
|
|
1262
|
+ /* Store setting */
|
|
1263
|
+ if ( ( rc = store_setting ( settings, &setting, data, len ) ) != 0 )
|
|
1264
|
+ return rc;
|
|
1265
|
+
|
|
1266
|
+ return 0;
|
|
1267
|
+}
|
|
1268
|
+
|
1229
|
1269
|
/**
|
1230
|
1270
|
* Parse and store value of named setting
|
1231
|
1271
|
*
|
1232
|
1272
|
* @v name Name of setting
|
|
1273
|
+ * @v default_type Default type to use, if none specified
|
1233
|
1274
|
* @v value Formatted setting data, or NULL
|
1234
|
1275
|
* @ret rc Return status code
|
1235
|
1276
|
*/
|
1236
|
|
-int storef_named_setting ( const char *name, const char *value ) {
|
|
1277
|
+int storef_named_setting ( const char *name, struct setting_type *default_type,
|
|
1278
|
+ const char *value ) {
|
1237
|
1279
|
struct settings *settings;
|
1238
|
1280
|
struct setting setting;
|
1239
|
1281
|
char tmp_name[ strlen ( name ) + 1 ];
|
|
@@ -1241,7 +1283,8 @@ int storef_named_setting ( const char *name, const char *value ) {
|
1241
|
1283
|
|
1242
|
1284
|
/* Parse setting name */
|
1243
|
1285
|
if ( ( rc = parse_setting_name ( name, autovivify_child_settings,
|
1244
|
|
- &settings, &setting, tmp_name )) != 0)
|
|
1286
|
+ &settings, &setting, default_type,
|
|
1287
|
+ tmp_name ) ) != 0 )
|
1245
|
1288
|
return rc;
|
1246
|
1289
|
|
1247
|
1290
|
/* Store setting */
|
|
@@ -1272,8 +1315,8 @@ int fetchf_named_setting ( const char *name,
|
1272
|
1315
|
int rc;
|
1273
|
1316
|
|
1274
|
1317
|
/* Parse setting name */
|
1275
|
|
- if ( ( rc = parse_setting_name ( name, find_child_settings,
|
1276
|
|
- &settings, &setting, tmp_name )) != 0)
|
|
1318
|
+ if ( ( rc = parse_setting_name ( name, find_child_settings, &settings,
|
|
1319
|
+ &setting, NULL, tmp_name ) ) != 0 )
|
1277
|
1320
|
return rc;
|
1278
|
1321
|
|
1279
|
1322
|
/* Fetch setting */
|