[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/config configuration.c
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/config configuration.c |
Date: |
Fri, 08 Jun 2001 13:06:52 -0700 |
CVSROOT: /cvs
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/06/08 13:06:52
Modified files:
geas/src/config: configuration.c
Log message:
finished code cleanup
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/config/configuration.c.diff?cvsroot=OldCVS&tr1=1.13&tr2=1.14&r1=text&r2=text
Patches:
Index: gnue/geas/src/config/configuration.c
diff -u gnue/geas/src/config/configuration.c:1.13
gnue/geas/src/config/configuration.c:1.14
--- gnue/geas/src/config/configuration.c:1.13 Wed Jun 6 15:12:12 2001
+++ gnue/geas/src/config/configuration.c Fri Jun 8 13:06:52 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: configuration.c,v 1.13 2001/06/06 22:12:12 reinhard Exp $
+ $Id: configuration.c,v 1.14 2001/06/08 20:06:52 reinhard Exp $
*/
/* ------------------------------------------------------------------------- *\
@@ -237,8 +237,8 @@
* Add a key/value pair to a database configuration
\* ------------------------------------------------------------------------- */
static void
-add_database_option (configuration_data *c,
- const char *name, const char *key, const char *value)
+add_database_option (configuration_data *c, const char *name, const char *key,
+ const char *value)
{
configuration_data *i;
@@ -261,18 +261,25 @@
}
/* ------------------------------------------------------------------------- *\
- *
+ * Read the password for the databases and the admin password from the
+ * shadowpwfile and insert the values into the configuration structs in
+ * memory as if they were in the normal config file
\* ------------------------------------------------------------------------- */
static void
read_shadow_password (configuration_data * c, const char *shadowpwfile)
{
- const char *adminuser = get_global_option (c, "adminuser");
+ const char *adminuser;
int errdone = 0;
char *p, *q;
-
char buf[256];
- FILE *fp = fopen (shadowpwfile, "r");
+ FILE *fp;
+
+ g_assert (c);
+ g_assert (shadowpwfile);
+
+ adminuser = get_global_option (c, "adminuser");
+ fp = fopen (shadowpwfile, "r");
if (!fp)
return;
buf[255] = '\0';
@@ -322,18 +329,19 @@
}
/* ------------------------------------------------------------------------- *\
- *
+ * Print the current configuration (for debugging purposes)
\* ------------------------------------------------------------------------- */
static void
-real_show_configuration (configuration config,
- int indent, gboolean show_passwords)
+real_show_configuration (configuration config, int indent,
+ gboolean show_passwords)
{
configuration_data *c = (configuration_data *) config;
GList *l;
-
int loop;
config_item *i;
+ g_return_if_fail (config);
+
if (c)
{
for (loop = 0; loop < indent; loop++)
@@ -378,14 +386,16 @@
}
/* ------------------------------------------------------------------------- *\
- *
+ * Read a line from the config file
\* ------------------------------------------------------------------------- */
static char *
-read_line (FILE * fp)
+read_line (FILE *fp)
{
char buf[1024];
char *p, *q, *retval;
+ g_assert (fp);
+
buf[1023] = '\0';
while (1)
{
@@ -436,24 +446,29 @@
}
/* ------------------------------------------------------------------------- *\
- *
+ * What part of the config file are we in?
\* ------------------------------------------------------------------------- */
-#define MODE_UNKNOWN 0
+#define MODE_UNKNOWN 0
#define MODE_DATABASE 1
-#define MODE_GLOBAL 2
+#define MODE_GLOBAL 2
/* ------------------------------------------------------------------------- *\
- *
+ * Read the main configuration file, which contains all configuration data
+ * except the passwords
\* ------------------------------------------------------------------------- */
static void
-read_main_configuration (configuration_data * c, const char *filename)
+read_main_configuration (configuration_data *c, const char *filename)
{
int mode = MODE_GLOBAL;
char *p, *q, *tmp;
- FILE *fp = fopen (filename, "r");
+ FILE *fp;
int done = 0;
char *dbname = NULL;
+ g_assert (c);
+ g_assert (filename);
+
+ fp = fopen (filename, "r");
if (!fp)
{
add_section_option (c, "configfile", "unknown");
@@ -574,34 +589,26 @@
}
/* ------------------------------------------------------------------------- *\
- * load configuration file
+ * load the whole configuration
\* ------------------------------------------------------------------------- */
configuration
load_configuration_file (const char *filename, const char *shadowpwfile)
{
configuration_data *c = alloc_configuration_data ("global options");
-
- /* Instructions for altering this module:
- to add a global option: call add_section_option(c,key,value)
-
- to add a database specific option: call
- add_database_option(c,databasename,key,value)
+ /* read main configuration file */
+ if (filename != NULL)
+ {
+ read_main_configuration (c, filename);
+ }
- */
+ /* set defaults: function ignores if already set */
+ enter_default_properties (c);
- if (c)
+ /* read shadow password file */
+ if (shadowpwfile != NULL)
{
- /* read main configuration file */
- if (filename != NULL)
- read_main_configuration (c, filename);
-
- /* set defaults: function ignores if already set */
- enter_default_properties (c);
-
- /* read shadow password file */
- if (shadowpwfile != NULL)
- read_shadow_password (c, shadowpwfile);
+ read_shadow_password (c, shadowpwfile);
}
/* if anything failed, return nothing */
@@ -622,18 +629,19 @@
{
configuration_data *c = (configuration_data *) config;
GList *l;
+ config_item *i;
if (c)
{
/* free name */
if (c->name)
g_free (c->name);
+
/* free options in this section */
l = c->globals;
while (l)
{
- config_item *i = (config_item *) l->data;
-
+ i = (config_item *) l->data;
free_config_item (i);
l = g_list_next (l);
}
@@ -647,6 +655,7 @@
l = g_list_next (l);
}
g_list_free (c->database);
+
/* free data */
g_free (c);
}
@@ -662,18 +671,15 @@
real_show_configuration (config, 0, show_passwords);
}
-/* ---------------------------------------------------------------------- *\
+/* ------------------------------------------------------------------------- *\
* count databases in the file
\* ------------------------------------------------------------------------- */
int
count_configured_databases (configuration config)
{
- int l;
- if (config == NO_CONFIGURATION)
- return (0);
- l = g_list_length (((configuration_data *) config)->database);
+ g_return_val_if_fail (config, 0);
- return (l);
+ return (g_list_length (((configuration_data *) config)->database));
}
/* ------------------------------------------------------------------------- *\
@@ -684,6 +690,8 @@
{
configuration_data *c = (configuration_data *) config;
+ g_return_val_if_fail (config, NULL);
+
/* validate index */
if (index < 0 || index >= count_configured_databases (config))
return (NULL);
@@ -785,15 +793,17 @@
get_database_option (configuration tree, const char *database,
const char *key)
{
- configuration_data *c = find_database ((configuration_data *) tree,
- database);
- if (c)
- {
- // self_test_message( "database option: db = %s, opt = %s, val = %s" ,
database , key , get_global_option(c,key) );
- return (get_global_option (c, key));
- }
- // self_test_message( "unknown database: %s" , database );
- return (NULL);
+ configuration_data *c;
+
+ g_return_val_if_fail (tree, NULL);
+ g_return_val_if_fail (database, NULL);
+ g_return_val_if_fail (key, NULL);
+
+ c = find_database ((configuration_data *) tree, database);
+
+ g_return_val_if_fail (c, NULL);
+
+ return (get_global_option (c, key));
}
/* ------------------------------------------------------------------------- *\