From 17f96bc1455acaf3015e337f99aaac7b58c55dbb Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 17 Jun 2010 11:11:57 +0100 Subject: Added calculate location directory diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 057c484..763392a 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c @@ -32,6 +32,7 @@ main (int argc, char **argv) state_key *temp_state_key = NULL; state_data *temp_state_data; time_t current_time; + char *temp_filename; plan_tests(81+23); @@ -259,10 +260,15 @@ main (int argc, char **argv) temp_string = np_state_generate_key(argv); ok(!strcmp(temp_string, "Ahash"), "Got hash" ); + temp_string = _np_state_calculate_location_prefix(); + ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" ); + ok(temp_state_key==NULL, "temp_state_key initially empty"); temp_state_key = np_state_init("check_test", temp_string, 54); ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); ok( !strcmp(temp_state_key->name, temp_string), "Got key name" ); + printf("Filename=%s\n", temp_state_key->_filename); + ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" ); ok( temp_state_key->data_version==54, "Version set" ); diff --git a/lib/utils_base.c b/lib/utils_base.c index fb44240..b717a99 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -321,6 +321,10 @@ char *np_state_generate_key(char **argv) { return "Ahash"; } +char* _np_state_calculate_location_prefix(){ + return NP_SHAREDSTATE_DIR; +} + /* * Initiatializer for state routines. * Sets variables. Generates filename. Returns np_state_key. die with @@ -328,6 +332,7 @@ char *np_state_generate_key(char **argv) { */ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_version) { state_key *this_state = NULL; + char *temp_filename = NULL; this_state = (state_key *) malloc(sizeof(state_key)); @@ -339,7 +344,8 @@ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_ver this_state->data_version=expected_data_version; /* Calculate filename */ - this_state->_filename="Tobedone"; + asprintf(&temp_filename, "%s/%s", _np_state_calculate_location_prefix(), plugin_name); + this_state->_filename=temp_filename; return this_state; } diff --git a/lib/utils_base.h b/lib/utils_base.h index bec6c66..b6eb57e 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -28,6 +28,7 @@ typedef struct thresholds_struct { range *critical; } thresholds; +#define NP_SHAREDSTATE_DIR "/tmp" #define STATE_FORMAT_VERSION "1" typedef struct state_data_struct { -- cgit v0.10-9-g596f