summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-07-30 14:05:50 -0400
committerDmitri Pal <dpal@redhat.com>2010-08-10 12:51:32 -0400
commit3f87dcf6c1986e031807ca1afb2cdc3e9e40e1de (patch)
tree1250932c9c6a27c72bce2d468e40292c6e1f0076
parenta55980ddf7cb6c8a1252c7d891fe95b6713b2431 (diff)
downloadsssd-3f87dcf6c1986e031807ca1afb2cdc3e9e40e1de.tar.gz
sssd-3f87dcf6c1986e031807ca1afb2cdc3e9e40e1de.tar.xz
sssd-3f87dcf6c1986e031807ca1afb2cdc3e9e40e1de.zip
[INI] Starting to consolidate the new interface in one place
I realized that the new high level interface should be defined in one file instead of being scattered in many headers. I would have to eventuallu eliminate ini_configobj.h too and move everything to the new interface in ini_config.h. This patch renames couple functions to be consistent with the naming convention and removes ini_parse.h header.
-rw-r--r--common/ini/Makefile.am1
-rw-r--r--common/ini/ini_config.c167
-rw-r--r--common/ini/ini_configobj.h11
-rw-r--r--common/ini/ini_parse.c166
-rw-r--r--common/ini/ini_parse.h53
-rw-r--r--common/ini/ini_parse_ut.c5
-rw-r--r--common/ini/ini_serialize.c2
7 files changed, 180 insertions, 225 deletions
diff --git a/common/ini/Makefile.am b/common/ini/Makefile.am
index 23f90ca..4e900f9 100644
--- a/common/ini/Makefile.am
+++ b/common/ini/Makefile.am
@@ -43,7 +43,6 @@ libini_config_la_SOURCES = \
ini_list.c \
ini_print.c \
ini_parse.c \
- ini_parse.h \
ini_metadata.c \
ini_metadata.h \
ini_defines.h \
diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index 7ed82b1..f1e7cfd 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -24,16 +24,181 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include "config.h"
#include "trace.h"
#include "collection.h"
#include "collection_tools.h"
#include "path_utils.h"
#include "ini_defines.h"
-#include "ini_parse.h"
#include "ini_metadata.h"
#include "ini_config.h"
+/* Temporarily move the parsing function here */
+/* THIS FUNCTION WILL BE REMOVED AS SOON AS WE SWITCH TO THE NEW INTERFACE */
+/* Reads a line from the file */
+int read_line(FILE *file,
+ char *buf,
+ int read_size,
+ char **key, char **value,
+ int *length,
+ int *ext_error)
+{
+
+ char *res;
+ int len;
+ char *buffer;
+ int i;
+ char *eq;
+
+ TRACE_FLOW_STRING("read_line", "Entry");
+
+ *ext_error = 0;
+
+ buffer = buf;
+
+ /* Get data from file */
+ res = fgets(buffer, read_size - 1, file);
+ if (res == NULL) {
+ TRACE_ERROR_STRING("Read nothing", "");
+ return RET_EOF;
+ }
+
+ /* Make sure the buffer is NULL terminated */
+ buffer[read_size - 1] = '\0';
+
+ len = strlen(buffer);
+ if (len == 0) {
+ TRACE_ERROR_STRING("Nothing was read.", "");
+ return RET_EMPTY;
+ }
+
+ /* Added \r just in case we deal with Windows in future */
+ if ((buffer[len - 1] != '\n') && (buffer[len - 1] != '\r')) {
+ TRACE_ERROR_STRING("String it too big!", "");
+ *ext_error = ERR_LONGDATA;
+ return RET_ERROR;
+ }
+
+ /* Ingnore comments */
+ if ((*buffer == ';') || (*buffer == '#')) {
+ TRACE_FLOW_STRING("Comment", buf);
+ return RET_COMMENT;
+ }
+
+ TRACE_INFO_STRING("BUFFER before trimming:", buffer);
+
+ /* Trucate trailing spaces and CRs */
+ /* Make sure not to step before the beginning */
+ while (len && isspace(buffer[len - 1])) {
+ buffer[len - 1] = '\0';
+ len--;
+ }
+
+ TRACE_INFO_STRING("BUFFER after trimming trailing spaces:", buffer);
+
+ /* Trucate leading spaces */
+ while (isspace(*buffer)) {
+ buffer++;
+ len--;
+ }
+
+ TRACE_INFO_STRING("BUFFER after trimming leading spaces:", buffer);
+ TRACE_INFO_NUMBER("BUFFER length:", len);
+
+ /* Empty line */
+ if (len == 0) {
+ TRACE_FLOW_STRING("Empty line", buf);
+ return RET_EMPTY;
+ }
+
+ /* Section */
+ if (*buffer == '[') {
+ if (buffer[len-1] != ']') {
+ TRACE_ERROR_STRING("Invalid format for section", buf);
+ *ext_error = ERR_NOCLOSESEC;
+ return RET_ERROR;
+ }
+ buffer++;
+ len--;
+ while (isspace(*buffer)) {
+ buffer++;
+ len--;
+ }
+ if (len == 0) {
+ TRACE_ERROR_STRING("Invalid format for section", buf);
+ *ext_error = ERR_NOSECTION;
+ return RET_ERROR;
+ }
+
+ buffer[len - 1] = '\0';
+ len--;
+ while (isspace(buffer[len - 1])) {
+ buffer[len - 1] = '\0';
+ len--;
+ }
+ if (len >= MAX_KEY) {
+ TRACE_ERROR_STRING("Section name is too long", buf);
+ *ext_error = ERR_SECTIONLONG;
+ return RET_ERROR;
+ }
+
+ *key = buffer;
+ return RET_SECTION;
+ }
+
+ /* Assume we are dealing with the K-V here */
+ /* Find "=" */
+ eq = strchr(buffer, '=');
+ if (eq == NULL) {
+ TRACE_ERROR_STRING("No equal sign", buf);
+ *ext_error = ERR_NOEQUAL;
+ return RET_INVALID;
+ }
+
+ len -= eq-buffer;
+
+ /* Strip spaces around "=" */
+ i = eq - buffer - 1;
+ while ((i >= 0) && isspace(buffer[i])) i--;
+ if (i < 0) {
+ TRACE_ERROR_STRING("No key", buf);
+ *ext_error = ERR_NOKEY;
+ return RET_INVALID;
+ }
+
+ /* Copy key into provided buffer */
+ if(i >= MAX_KEY) {
+ TRACE_ERROR_STRING("Key name is too long", buf);
+ *ext_error = ERR_LONGKEY;
+ return RET_INVALID;
+ }
+ *key = buffer;
+ buffer[i + 1] = '\0';
+ TRACE_INFO_STRING("KEY:", *key);
+
+ eq++;
+ len--;
+ while (isspace(*eq)) {
+ eq++;
+ len--;
+ }
+
+ *value = eq;
+ /* Make sure we include trailing 0 into data */
+ *length = len + 1;
+
+ TRACE_INFO_STRING("VALUE:", *value);
+ TRACE_INFO_NUMBER("LENGTH:", *length);
+
+ TRACE_FLOW_STRING("read_line", "Exit");
+ return RET_PAIR;
+}
+
+/************************************************************/
+/* REMOVE FUNCTION ABOVE */
+/************************************************************/
+
/***************************************************************************/
/* Function to read single ini file and pupulate
diff --git a/common/ini/ini_configobj.h b/common/ini/ini_configobj.h
index 21f9754..4b1b31f 100644
--- a/common/ini/ini_configobj.h
+++ b/common/ini/ini_configobj.h
@@ -27,6 +27,7 @@
/********************************************************************/
/* THIS IS A BEGINNING OF THE THE NEW CONFIG OBJECT INTERFACE - TBD */
+/* It will be moved to the ini_config.h when it is ready */
/********************************************************************/
struct configobj;
@@ -38,8 +39,16 @@ int ini_config_create(struct configobj **ini_config);
void ini_config_destroy(struct configobj *ini_config);
/* Serialize configuration object into provided buffer */
-int ini_serialize_config(struct configobj *ini_config,
+int ini_config_serialize(struct configobj *ini_config,
struct simplebuffer *sbobj);
+int ini_config_parse(FILE *file,
+ const char *config_filename,
+ struct configobj *ini_config,
+ int error_level,
+ struct collection_item **error_list,
+ uint32_t boundary);
+
+
#endif
diff --git a/common/ini/ini_parse.c b/common/ini/ini_parse.c
index adc678e..843acf2 100644
--- a/common/ini/ini_parse.c
+++ b/common/ini/ini_parse.c
@@ -28,7 +28,6 @@
#define _(String) gettext (String)
#include "config.h"
#include "trace.h"
-#include "ini_parse.h"
#include "ini_defines.h"
#include "ini_config.h"
#include "ini_valueobj.h"
@@ -81,169 +80,6 @@ typedef int (*action_fn)(struct parser_obj *);
#define PARSE_DONE 4 /* We are done */
-/* THIS FUNCTION WILL BE REMOVED AS SOON AS WE SWITCH TO THE NEW INTERFACE */
-/* Reads a line from the file */
-int read_line(FILE *file,
- char *buf,
- int read_size,
- char **key, char **value,
- int *length,
- int *ext_error)
-{
-
- char *res;
- int len;
- char *buffer;
- int i;
- char *eq;
-
- TRACE_FLOW_STRING("read_line", "Entry");
-
- *ext_error = 0;
-
- buffer = buf;
-
- /* Get data from file */
- res = fgets(buffer, read_size - 1, file);
- if (res == NULL) {
- TRACE_ERROR_STRING("Read nothing", "");
- return RET_EOF;
- }
-
- /* Make sure the buffer is NULL terminated */
- buffer[read_size - 1] = '\0';
-
- len = strlen(buffer);
- if (len == 0) {
- TRACE_ERROR_STRING("Nothing was read.", "");
- return RET_EMPTY;
- }
-
- /* Added \r just in case we deal with Windows in future */
- if ((buffer[len - 1] != '\n') && (buffer[len - 1] != '\r')) {
- TRACE_ERROR_STRING("String it too big!", "");
- *ext_error = ERR_LONGDATA;
- return RET_ERROR;
- }
-
- /* Ingnore comments */
- if ((*buffer == ';') || (*buffer == '#')) {
- TRACE_FLOW_STRING("Comment", buf);
- return RET_COMMENT;
- }
-
- TRACE_INFO_STRING("BUFFER before trimming:", buffer);
-
- /* Trucate trailing spaces and CRs */
- /* Make sure not to step before the beginning */
- while (len && isspace(buffer[len - 1])) {
- buffer[len - 1] = '\0';
- len--;
- }
-
- TRACE_INFO_STRING("BUFFER after trimming trailing spaces:", buffer);
-
- /* Trucate leading spaces */
- while (isspace(*buffer)) {
- buffer++;
- len--;
- }
-
- TRACE_INFO_STRING("BUFFER after trimming leading spaces:", buffer);
- TRACE_INFO_NUMBER("BUFFER length:", len);
-
- /* Empty line */
- if (len == 0) {
- TRACE_FLOW_STRING("Empty line", buf);
- return RET_EMPTY;
- }
-
- /* Section */
- if (*buffer == '[') {
- if (buffer[len-1] != ']') {
- TRACE_ERROR_STRING("Invalid format for section", buf);
- *ext_error = ERR_NOCLOSESEC;
- return RET_ERROR;
- }
- buffer++;
- len--;
- while (isspace(*buffer)) {
- buffer++;
- len--;
- }
- if (len == 0) {
- TRACE_ERROR_STRING("Invalid format for section", buf);
- *ext_error = ERR_NOSECTION;
- return RET_ERROR;
- }
-
- buffer[len - 1] = '\0';
- len--;
- while (isspace(buffer[len - 1])) {
- buffer[len - 1] = '\0';
- len--;
- }
- if (len >= MAX_KEY) {
- TRACE_ERROR_STRING("Section name is too long", buf);
- *ext_error = ERR_SECTIONLONG;
- return RET_ERROR;
- }
-
- *key = buffer;
- return RET_SECTION;
- }
-
- /* Assume we are dealing with the K-V here */
- /* Find "=" */
- eq = strchr(buffer, '=');
- if (eq == NULL) {
- TRACE_ERROR_STRING("No equal sign", buf);
- *ext_error = ERR_NOEQUAL;
- return RET_INVALID;
- }
-
- len -= eq-buffer;
-
- /* Strip spaces around "=" */
- i = eq - buffer - 1;
- while ((i >= 0) && isspace(buffer[i])) i--;
- if (i < 0) {
- TRACE_ERROR_STRING("No key", buf);
- *ext_error = ERR_NOKEY;
- return RET_INVALID;
- }
-
- /* Copy key into provided buffer */
- if(i >= MAX_KEY) {
- TRACE_ERROR_STRING("Key name is too long", buf);
- *ext_error = ERR_LONGKEY;
- return RET_INVALID;
- }
- *key = buffer;
- buffer[i + 1] = '\0';
- TRACE_INFO_STRING("KEY:", *key);
-
- eq++;
- len--;
- while (isspace(*eq)) {
- eq++;
- len--;
- }
-
- *value = eq;
- /* Make sure we include trailing 0 into data */
- *length = len + 1;
-
- TRACE_INFO_STRING("VALUE:", *value);
- TRACE_INFO_NUMBER("LENGTH:", *length);
-
- TRACE_FLOW_STRING("read_line", "Exit");
- return RET_PAIR;
-}
-
-/************************************************************/
-/* REMOVE FUNCTION ABOVE */
-/************************************************************/
/* Destroy parser object */
void parser_destroy(struct parser_obj *po)
@@ -1147,7 +983,7 @@ int parser_run(struct parser_obj *po)
}
/* Top level wrapper around the parser */
-int ini_parse_config(FILE *file,
+int ini_config_parse(FILE *file,
const char *config_filename,
struct configobj *ini_config,
int error_level,
diff --git a/common/ini/ini_parse.h b/common/ini/ini_parse.h
deleted file mode 100644
index 7eb9fdc..0000000
--- a/common/ini/ini_parse.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- INI LIBRARY
-
- Header file for the internal parsing functions.
-
- Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
-
- INI Library is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- INI Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with INI Library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef INI_PARSE_H
-#define INI_PARSE_H
-
-#include <stdio.h>
-#include "collection.h"
-#include "ini_configobj.h"
-
-/* Internal function to read line from INI file */
-int read_line(FILE *file,
- char *buf,
- int read_size,
- char **key,
- char **value,
- int *length,
- int *ext_error);
-
-/*************************************************************************/
-/* THIS INTERFACE WILL CHANGE WHEN THE FILE CONTEXT OBJECT IS INTRODUCED */
-/*************************************************************************/
-/* NOTE: Consider moving the boundary into the config object rather than
- * have it as a part of the parser - TBD.
- */
-
-/* Parse a configration file */
-int ini_parse_config(FILE *file,
- const char *config_filename,
- struct configobj *ini_config,
- int error_level,
- struct collection_item **error_list,
- uint32_t boundary);
-
-#endif
diff --git a/common/ini/ini_parse_ut.c b/common/ini/ini_parse_ut.c
index c66d250..af67e06 100644
--- a/common/ini/ini_parse_ut.c
+++ b/common/ini/ini_parse_ut.c
@@ -24,7 +24,6 @@
#include <errno.h>
#include <stdlib.h>
#include "ini_defines.h"
-#include "ini_parse.h"
#include "ini_config.h"
#include "ini_configobj.h"
#include "simplebuffer.h"
@@ -69,7 +68,7 @@ int test_one_file(const char *filename)
return error;
}
- error = ini_parse_config(ff,
+ error = ini_config_parse(ff,
filename,
ini_config,
INI_STOP_ON_NONE,
@@ -89,7 +88,7 @@ int test_one_file(const char *filename)
return error;
}
- error = ini_serialize_config(ini_config, sbobj);
+ error = ini_config_serialize(ini_config, sbobj);
if (error != EOK) {
printf("Failed to parse configuration. Error %d.\n", error);
ini_config_destroy(ini_config);
diff --git a/common/ini/ini_serialize.c b/common/ini/ini_serialize.c
index 542da98..9738be9 100644
--- a/common/ini/ini_serialize.c
+++ b/common/ini/ini_serialize.c
@@ -63,7 +63,7 @@ static int ini_serialize_cb(const char *property,
}
/* Traverse the collection and build the serialization object */
-int ini_serialize_config(struct configobj *ini_config,
+int ini_config_serialize(struct configobj *ini_config,
struct simplebuffer *sbobj)
{
int error = EOK;