@@ -105,6 +105,15 @@ int nwipe_conf_init()
105
105
setting = config_setting_add ( group_organisation , "Op_Tech_Name" , CONFIG_TYPE_STRING );
106
106
config_setting_set_string ( setting , "Not Applicable (OTN)" );
107
107
108
+ /* Add PDF Certificate/Report settings */
109
+ group_organisation = config_setting_add ( root , "PDF_Certificate" , CONFIG_TYPE_GROUP );
110
+
111
+ setting = config_setting_add ( group_organisation , "PDF_Enable" , CONFIG_TYPE_STRING );
112
+ config_setting_set_string ( setting , "ENABLED" );
113
+
114
+ setting = config_setting_add ( group_organisation , "PDF_Preview" , CONFIG_TYPE_STRING );
115
+ config_setting_set_string ( setting , "DISABLED" );
116
+
108
117
/**
109
118
* The currently selected customer that will be printed on the report
110
119
*/
@@ -340,6 +349,108 @@ void save_selected_customer( char** customer )
340
349
}
341
350
}
342
351
352
+ int nwipe_conf_update_setting ( char * group_name_setting_name , char * setting_value )
353
+ {
354
+ /* You would call this function of you wanted to update an existing setting in nwipe.conf, i.e
355
+ *
356
+ * nwipe_conf_update_setting( "PDF_Certificate.PDF_Enable", "ENABLED" )
357
+ *
358
+ * It is NOT used for creating a new group or setting name.
359
+ */
360
+
361
+ /* -------------------------------------------------------------
362
+ * Write the field to nwipe's config file /etc/nwipe/nwipe.conf
363
+ */
364
+ if ( ( setting = config_lookup ( & nwipe_cfg , group_name_setting_name ) ) )
365
+ {
366
+ config_setting_set_string ( setting , setting_value );
367
+ }
368
+ else
369
+ {
370
+ nwipe_log (
371
+ NWIPE_LOG_ERROR , "Can't find group.setting_name %s in %s" , group_name_setting_name , nwipe_config_file );
372
+ return 1 ;
373
+ }
374
+
375
+ /* Write the new configuration to nwipe.conf
376
+ */
377
+ if ( !config_write_file ( & nwipe_cfg , nwipe_config_file ) )
378
+ {
379
+ nwipe_log ( NWIPE_LOG_ERROR , "Failed to write %s to %s" , group_name_setting_name , nwipe_config_file );
380
+ return 2 ;
381
+ }
382
+ else
383
+ {
384
+ nwipe_log ( NWIPE_LOG_INFO ,
385
+ "Updated %s with value %s in %s" ,
386
+ group_name_setting_name ,
387
+ setting_value ,
388
+ nwipe_config_file );
389
+ }
390
+
391
+ return 0 ;
392
+
393
+ } // end nwipe_conf_update_setting()
394
+
395
+ int nwipe_conf_read_setting ( char * group_name_setting_name , const char * * setting_value )
396
+ {
397
+ /* You would call this function if you wanted to read a settings value in nwipe.conf, i.e
398
+ *
399
+ * const char ** pReturnString;
400
+ * nwipe_conf_read_setting( "PDF_Certificate", "PDF_Enable", pReturnString );
401
+ *
402
+ */
403
+
404
+ /* Separate group_name_setting_name i.e "PDF_Certificate.PDF_Enable" string
405
+ * into two separate strings by replacing the period with a NULL.
406
+ */
407
+
408
+ int return_status ;
409
+ int length = strlen ( group_name_setting_name );
410
+
411
+ char * group_name = malloc ( length );
412
+ char * setting_name = malloc ( length );
413
+
414
+ int idx = 0 ;
415
+
416
+ while ( group_name_setting_name [idx ] != 0 && group_name_setting_name [idx ] != '.' )
417
+ {
418
+ if ( group_name_setting_name [idx ] == '.' )
419
+ {
420
+ break ;
421
+ }
422
+ idx ++ ;
423
+ }
424
+ memcpy ( group_name , group_name_setting_name , idx );
425
+ strcpy ( setting_name , & group_name_setting_name [idx + 1 ] );
426
+
427
+ if ( !( setting = config_lookup ( & nwipe_cfg , group_name ) ) )
428
+ {
429
+ nwipe_log ( NWIPE_LOG_ERROR , "Can't find group name %s.%s in %s" , group_name , setting_name , nwipe_config_file );
430
+ return_status = -1 ;
431
+ }
432
+ else
433
+ {
434
+ /* Retrieve data from nwipe.conf */
435
+ if ( CONFIG_TRUE == config_setting_lookup_string ( setting , setting_name , setting_value ) )
436
+ {
437
+ nwipe_log ( NWIPE_LOG_INFO , "setting_value = %s" , * setting_value );
438
+ return_status = 0 ; /* Success */
439
+ }
440
+ else
441
+ {
442
+ nwipe_log (
443
+ NWIPE_LOG_ERROR , "Can't find setting_name %s.%s in %s" , group_name , setting_name , nwipe_config_file );
444
+ return_status = -2 ;
445
+ }
446
+ }
447
+
448
+ free ( group_name );
449
+ free ( setting_name );
450
+ return ( return_status );
451
+
452
+ } // end nwipe_conf_read_setting()
453
+
343
454
void nwipe_conf_close ()
344
455
{
345
456
config_destroy ( & nwipe_cfg );
0 commit comments