summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-12-26 19:21:32 -0500
committerDmitri Pal <dpal@redhat.com>2011-01-03 15:00:43 -0500
commit7030e51bb22e62e6f5d63b0faa923d2151336818 (patch)
tree3f409af41b5d6f6afbc6d57f775e545c9fad22e0
parent29e4a0a028b802eaa3bb1dfbc7a9080fc7f21f4b (diff)
downloadding-libs-7030e51bb22e62e6f5d63b0faa923d2151336818.tar.gz
ding-libs-7030e51bb22e62e6f5d63b0faa923d2151336818.tar.xz
ding-libs-7030e51bb22e62e6f5d63b0faa923d2151336818.zip
[INI] Metadata collection is gone
After some more thinking I decided not to use metadata collection. It seems to be an overhead. Patch does following: * Replaces metadata collection in file context structure with standard file stats * Removes all operations against old metadata collection * Defines new flags for data to collect * Creates a function that consolidates common operations between open and reopen functions.
-rw-r--r--ini/ini_config_priv.h11
-rw-r--r--ini/ini_configobj.h20
-rw-r--r--ini/ini_fileobj.c121
3 files changed, 75 insertions, 77 deletions
diff --git a/ini/ini_config_priv.h b/ini/ini_config_priv.h
index 1880c3f..84742c7 100644
--- a/ini/ini_config_priv.h
+++ b/ini/ini_config_priv.h
@@ -22,6 +22,9 @@
#ifndef INI_CONFIG_PRIV_H
#define INI_CONFIG_PRIV_H
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "collection.h"
/* Configuration object */
@@ -45,21 +48,19 @@ struct ini_cfgfile {
char *filename;
/* File stream */
FILE *file;
- /* File descriptor that is passed in */
- int fd;
/* Error level */
int error_level;
/* Collision flags - define how to merge things */
uint32_t collision_flags;
- /* Collision flags - define how to merge things */
+ /* What meta data to collect */
uint32_t metadata_flags;
/**********************/
/* Internal variables */
/**********************/
/* Collection of errors detected during parsing */
struct collection_item *error_list;
- /* Metadata about the file */
- struct collection_item *metadata;
+ /* File stats */
+ struct stat file_stats;
/* Count of error lines */
unsigned count;
};
diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h
index 3321bd3..8984402 100644
--- a/ini/ini_configobj.h
+++ b/ini/ini_configobj.h
@@ -82,6 +82,26 @@
/** @brief Size of the error array. */
#define ERR_MAXPARSE ERR_DUPSECTION
+/**
+ * @}
+ */
+
+/**
+ * @defgroup metacollect Constants that define what meta data to collect
+ *
+ * Constants in this section define what meta data to collect
+ *
+ *
+ * @{
+ */
+/** @brief Do not collect any data. */
+#define INI_META_NONE 0
+/** @brief Collect file stats. */
+#define INI_META_STATS 1
+
+/**
+ * @}
+ */
/**
* @defgroup collisionflags Flags that define collision resolution logic.
diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c
index 200c7af..c10b4bf 100644
--- a/ini/ini_fileobj.c
+++ b/ini/ini_fileobj.c
@@ -96,7 +96,6 @@ void ini_config_file_destroy(struct ini_cfgfile *file_ctx)
if(file_ctx) {
free(file_ctx->filename);
col_destroy_collection(file_ctx->error_list);
- col_destroy_collection(file_ctx->metadata);
if(file_ctx->file) fclose(file_ctx->file);
free(file_ctx);
}
@@ -104,6 +103,47 @@ void ini_config_file_destroy(struct ini_cfgfile *file_ctx)
TRACE_FLOW_EXIT();
}
+/* Internal common initialization part */
+static int common_file_init(struct ini_cfgfile *file_ctx)
+{
+ int error = EOK;
+
+ TRACE_FLOW_ENTRY();
+
+ /* Open file */
+ TRACE_INFO_STRING("File", file_ctx->filename);
+ errno = 0;
+ file_ctx->file = fopen(file_ctx->filename, "r");
+ if (!(file_ctx->file)) {
+ error = errno;
+ TRACE_ERROR_NUMBER("Failed to open file", error);
+ return error;
+ }
+
+ /* Create internal collections */
+ error = col_create_collection(&(file_ctx->error_list),
+ INI_ERROR,
+ COL_CLASS_INI_PERROR);
+ if (error) {
+ TRACE_ERROR_NUMBER("Failed to create error list", error);
+ return error;
+ }
+
+ /* Collect stats */
+ if (file_ctx->metadata_flags & INI_META_STATS) {
+ errno = 0;
+ if (fstat(fileno(file_ctx->file),
+ &(file_ctx->file_stats)) < 0) {
+ error = errno;
+ TRACE_ERROR_NUMBER("Failed to get file stats.", error);
+ return error;
+ }
+ }
+
+ TRACE_FLOW_EXIT();
+ return EOK;
+}
+
/* Create a file object for parsing a config file */
int ini_config_file_open(const char *filename,
int error_level,
@@ -135,16 +175,9 @@ int ini_config_file_open(const char *filename,
return error;
}
-
new_ctx->filename = NULL;
new_ctx->file = NULL;
new_ctx->error_list = NULL;
- new_ctx->metadata = NULL;
-
- /* TBD - decide whether we actually need an FD.
- It will be done when we move the metadata
- processing into this function. */
- new_ctx->fd = -1;
/* Store flags */
new_ctx->error_level = error_level;
@@ -172,39 +205,14 @@ int ini_config_file_open(const char *filename,
return error;
}
- /* Open file */
- TRACE_INFO_STRING("File", new_ctx->filename);
- errno = 0;
- new_ctx->file = fopen(new_ctx->filename, "r");
- if (!(new_ctx->file)) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to open file", error);
- ini_config_file_destroy(new_ctx);
- return error;
- }
-
- /* Create internal collections */
- error = col_create_collection(&(new_ctx->error_list),
- INI_ERROR,
- COL_CLASS_INI_PERROR);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to create error list", error);
- ini_config_file_destroy(new_ctx);
- return error;
- }
-
- error = col_create_collection(&(new_ctx->metadata),
- INI_METADATA,
- COL_CLASS_INI_META);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to create metadata collection", error);
+ /* Do common init */
+ error = common_file_init(new_ctx);
+ if(error) {
+ TRACE_ERROR_NUMBER("Failed to do common init", error);
ini_config_file_destroy(new_ctx);
return error;
}
-
- /* TBD - Add metadata processing here */
-
*file_ctx = new_ctx;
TRACE_FLOW_EXIT();
return error;
@@ -236,12 +244,6 @@ int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
new_ctx->filename = NULL;
new_ctx->file = NULL;
new_ctx->error_list = NULL;
- new_ctx->metadata = NULL;
-
- /* TBD - decide whether we actually need an FD.
- It will be done when we move the metadata
- processing into this function. */
- new_ctx->fd = -1;
/* Store flags */
new_ctx->error_level = file_ctx_in->error_level;
@@ -259,39 +261,14 @@ int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
return error;
}
- /* Open file */
- TRACE_INFO_STRING("File", new_ctx->filename);
- errno = 0;
- new_ctx->file = fopen(new_ctx->filename, "r");
- if (!(new_ctx->file)) {
- error = errno;
- TRACE_ERROR_NUMBER("Failed to open file", error);
- ini_config_file_destroy(new_ctx);
- return error;
- }
-
- /* Create internal collections */
- error = col_create_collection(&(new_ctx->error_list),
- INI_ERROR,
- COL_CLASS_INI_PERROR);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to create error list", error);
- ini_config_file_close(new_ctx);
- return error;
- }
-
- error = col_create_collection(&(new_ctx->metadata),
- INI_METADATA,
- COL_CLASS_INI_META);
- if (error) {
- TRACE_ERROR_NUMBER("Failed to create metadata collection", error);
+ /* Do common init */
+ error = common_file_init(new_ctx);
+ if(error) {
+ TRACE_ERROR_NUMBER("Failed to do common init", error);
ini_config_file_destroy(new_ctx);
return error;
}
-
- /* TBD - Add metadata processing here */
-
*file_ctx_out = new_ctx;
TRACE_FLOW_EXIT();
return error;