aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/conf.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/conf.c')
-rw-r--r--daemon/conf.c134
1 files changed, 92 insertions, 42 deletions
diff --git a/daemon/conf.c b/daemon/conf.c
index 0166712..9dfb248 100644
--- a/daemon/conf.c
+++ b/daemon/conf.c
@@ -123,90 +123,140 @@ static void create_source( int line_number,
}
/******************************************************************************
- * create_destination
+ * init_file_dest
*
* read attributes of element, initialize destination structure and append
* it to the list of destinations
*/
-static void create_destination( int line_number,
+static gboolean init_file_dest( struct destination *dest,
+ int line_number,
const gchar** attribute_names,
const gchar** attribute_values )
{
const gchar *aname;
- struct destination *dest = g_malloc0( sizeof(struct destination) );
- /* at first, we must determine de*/
for( ; (aname = *attribute_names) != NULL; attribute_names++, attribute_values++ )
{
const gchar *aval = *attribute_values;
- if( strcmp( aname, "name" ) == 0 )
- dest->name = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
- else if( strcmp( aname, "file" ) == 0 )
- dest->file = normalize_pathname( aval );
+ if( strcmp( aname, "file" ) == 0 )
+ dest->u.file.name_pattern = normalize_pathname( aval );
else if( strcmp( aname, "rotate" ) == 0 )
{
if( strcmp( aval, "daily" ) == 0 )
- dest->rotate = RP_DAILY;
+ dest->u.file.rotate = RP_DAILY;
else if( strcmp( aval, "weekly" ) == 0 )
- dest->rotate = RP_WEEKLY;
+ dest->u.file.rotate = RP_WEEKLY;
else if( strcmp( aval, "monthly" ) == 0 )
- dest->rotate = RP_MONTHLY;
+ dest->u.file.rotate = RP_MONTHLY;
else
{
ERR( "Invalid rotation period at line %d\n", line_number );
- dest->rotate = RP_INVALID;
+ dest->u.file.rotate = RP_INVALID;
}
}
else if( strcmp( aname, "size" ) == 0 )
{
char *endptr;
- dest->size = strtoul( aval, &endptr, 0 );
+ dest->u.file.size = strtoul( aval, &endptr, 0 );
if( 'k' == *endptr )
- dest->size *= 1024;
+ dest->u.file.size *= 1024;
else if( 'M' == *endptr )
- dest->size *= 1024 * 1024;
+ dest->u.file.size *= 1024 * 1024;
}
else if( strcmp( aname, "backlogs" ) == 0 )
- dest->backlogs = strtoul( aval, NULL, 0 );
+ dest->u.file.backlogs = strtoul( aval, NULL, 0 );
else if( strcmp( aname, "ifempty" ) == 0 )
{
if( strcmp( aval, "yes" ) == 0 )
- dest->ifempty = TRUE;
+ dest->u.file.ifempty = TRUE;
else if( strcmp( aval, "no" ) == 0 )
- dest->ifempty = FALSE;
+ dest->u.file.ifempty = FALSE;
else
{
- dest->ifempty = TRUE;
+ dest->u.file.ifempty = TRUE;
ERR( "Invalid value \"%s\" of attribute \"%s\" at line %d; assumed \"yes\"\n",
aval, aname, line_number );
}
}
else if( strcmp( aname, "olddir" ) == 0 )
- dest->olddir = normalize_pathname( aval );
+ dest->u.file.olddir = normalize_pathname( aval );
else if( strcmp( aname, "compresscmd" ) == 0 )
- dest->compresscmd = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
+ dest->u.file.compresscmd = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
else if( strcmp( aname, "compressoptions" ) == 0 )
- dest->compressoptions = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
+ dest->u.file.compressoptions = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
}
- if( !dest->name )
- ERR( "Undefined destination name at line %d\n", line_number );
- if( !dest->file )
+ if( !dest->u.file.name_pattern )
ERR( "Undefined destination file at line %d\n", line_number );
- if( (!dest->name) || (!dest->file) || RP_INVALID == dest->rotate )
+ if( (!dest->u.file.name_pattern) || RP_INVALID == dest->u.file.rotate )
{
- if( dest->name ) g_free( dest->name );
- if( dest->file ) g_free( dest->file );
- if( dest->olddir ) g_free( dest->olddir );
- if( dest->compresscmd ) g_free( dest->compresscmd );
- if( dest->compressoptions ) g_free( dest->compressoptions );
+ if( dest->u.file.name_pattern ) g_free( dest->u.file.name_pattern );
+ if( dest->u.file.olddir ) g_free( dest->u.file.olddir );
+ if( dest->u.file.compresscmd ) g_free( dest->u.file.compresscmd );
+ if( dest->u.file.compressoptions ) g_free( dest->u.file.compressoptions );
+ return FALSE;
+ }
+
+ if( dest->u.file.compresscmd && !dest->u.file.compressoptions )
+ dest->u.file.compressoptions = g_strdup( "$PATHNAME" );
+
+ return init_destination_file( dest );
+}
+
+/******************************************************************************
+ * create_destination
+ *
+ * read attributes of element, initialize destination structure and append
+ * it to the list of destinations
+ */
+static void create_destination( int line_number,
+ const gchar** attribute_names,
+ const gchar** attribute_values )
+{
+ gboolean r = FALSE;
+ const gchar *aname;
+ struct destination *dest = g_malloc0( sizeof(struct destination) );
+
+ /* at first, we must determine destination type for selection of type-specific
+ structure that we'll fill later;
+ also, look for 'name' attribute and set the name of destination */
+ dest->type = DT_UNDEFINED;
+ for( ; (aname = *attribute_names) != NULL; attribute_names++, attribute_values++ )
+ {
+ const gchar *aval = *attribute_values;
+
+ if( strcmp( aname, "name" ) == 0 )
+ dest->name = g_locale_from_utf8( aval, -1, NULL, NULL, NULL );
+ else if( strcmp( aname, "file" ) == 0 )
+ {
+ dest->type = DT_FILE;
+ break;
+ }
+ }
+ if( !dest->name )
+ {
+ ERR( "Undefined destination name at line %d\n", line_number );
g_free( dest );
return;
}
- if( dest->compresscmd && !dest->compressoptions )
- dest->compressoptions = g_strdup( "$PATHNAME" );
- dest->file_writers = NULL;
- InitializeCriticalSection( &dest->cs_file_writers );
+ switch( dest->type )
+ {
+ case DT_FILE:
+ r = init_file_dest( dest, line_number, attribute_names, attribute_values );
+ break;
+
+ default:
+ ERR( "Undefined destination type at line %d\n", line_number );
+ break;
+ }
+
+ if( !r )
+ {
+ /* FIXME: call fini method? */
+ g_free( dest->name );
+ g_free( dest );
+ return;
+ }
destinations = g_list_append( destinations, dest );
}
@@ -687,14 +737,14 @@ static void dump_configuration()
TRACE( "\tname=%s\tfile=%s\n"
"\t\trotate=%s size=%d backlogs=%d ifempty=%s\n"
"\t\tolddir=%s compresscmd=%s\n",
- d->name, d->file,
- (d->rotate == RP_DAILY)? "daily"
- : (d->rotate == RP_WEEKLY)? "weekly"
- : (d->rotate == RP_MONTHLY)? "monthly"
+ d->name, d->u.file.name_pattern,
+ (d->u.file.rotate == RP_DAILY)? "daily"
+ : (d->u.file.rotate == RP_WEEKLY)? "weekly"
+ : (d->u.file.rotate == RP_MONTHLY)? "monthly"
: "undefined",
- d->size, d->backlogs, d->ifempty? "yes" : "no",
- d->olddir? d->olddir : "NULL",
- d->compresscmd? d->compresscmd : "NULL" );
+ d->u.file.size, d->u.file.backlogs, d->u.file.ifempty? "yes" : "no",
+ d->u.file.olddir? d->u.file.olddir : "NULL",
+ d->u.file.compresscmd? d->u.file.compresscmd : "NULL" );
}
TRACE( "Filters:\n" );
for( item = filters; item; item = item->next )