Skip to content

Commit 0bb9ee3

Browse files
Merge pull request martijnvanbrummelen#499 from PartialVolume/PDFGen36_Add_Optional_Org_Customer_Preview_Prior_To_Drive_Selection
PDFGen36_Add_Optional_Org_Customer_Preview_Prior_To_Drive_Selection.
2 parents 525cf03 + f12ee92 commit 0bb9ee3

File tree

7 files changed

+374
-37
lines changed

7 files changed

+374
-37
lines changed

src/conf.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ int nwipe_conf_init()
105105
setting = config_setting_add( group_organisation, "Op_Tech_Name", CONFIG_TYPE_STRING );
106106
config_setting_set_string( setting, "Not Applicable (OTN)" );
107107

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+
108117
/**
109118
* The currently selected customer that will be printed on the report
110119
*/
@@ -340,6 +349,108 @@ void save_selected_customer( char** customer )
340349
}
341350
}
342351

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+
343454
void nwipe_conf_close()
344455
{
345456
config_destroy( &nwipe_cfg );

src/conf.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ void nwipe_conf_close();
2222

2323
void save_selected_customer( char** );
2424

25+
/**
26+
* int nwipe_conf_update_setting( char *, char * );
27+
* Use this function to update a setting in nwipe.conf
28+
* @param char * this is the group name and setting name separated by a period '.'
29+
* i.e "PDF_Certificate.PDF_Enable"
30+
* @param char * this is the setting, i.e ENABLED
31+
* @return int 0 = Success
32+
* 1 = Unable to update memory copy
33+
* 2 = Unable to write new configuration to /etc/nwipe/nwipe.conf
34+
*/
35+
int nwipe_conf_update_setting( char*, char* );
36+
37+
/**
38+
* int nwipe_conf_read_setting( char *, char *, const char ** )
39+
* Use this function to read a setting value in nwipe.conf
40+
* @param char * this is the group name
41+
* @param char * this is the setting name
42+
* @param char ** this is a pointer to the setting value
43+
* @return int 0 = Success
44+
* -1 = Unable to find the specified group name
45+
* -2 = Unable to find the specified setting name
46+
*/
47+
int nwipe_conf_read_setting( char*, const char** );
48+
2549
#define FIELD_LENGTH 256
2650
#define NUMBER_OF_FIELDS 4
2751

0 commit comments

Comments
 (0)