diff src/client.c @ 250:93d5d8b098da noffle

[svn] *** empty log message ***
author mirkol
date Wed, 05 Jun 2002 23:03:44 +0100
parents fbff73fe5b40
children f049f8639dc0
line wrap: on
line diff
--- a/src/client.c	Tue May 14 15:25:45 2002 +0100
+++ b/src/client.c	Wed Jun 05 23:03:44 2002 +0100
@@ -1,7 +1,7 @@
 /*
   client.c
 
-  $Id: client.c 371 2002-02-26 17:13:31Z bears $
+  $Id: client.c 382 2002-06-05 22:03:44Z mirkol $
 */
 
 #if HAVE_CONFIG_H
@@ -44,23 +44,6 @@
   in C.Lindsay, "News Article Format", <draft-ietf-usefor-article-03.txt>.
 */
 
-struct ForbiddenGroupName
-{
-    const char *pattern;
-    Bool match;
-} forbiddenGroupNames[] =
-{
-    { "*.*", FALSE },			/* Single component */
-    { "control.*", TRUE },		/* control.* groups */
-    { "to.*", TRUE },			/* to.* groups */
-    { "*.all", TRUE },			/* 'all' as a component */
-    { "*.all.*", TRUE },
-    { "all.*", TRUE },
-    { "*.ctl", TRUE },			/* 'ctl' as a component */
-    { "*.ctl.*", TRUE },
-    { "ctl.*", TRUE }
-};
-
 struct
 {
     FILE* in;       /* Receiving socket from server */
@@ -268,7 +251,7 @@
     Str line;
     Bool err;
 
-    res = new_DynStr(2048);
+    res = new_DynStr( MAXCHAR );
     if ( res == NULL )
 	return NULL;
 
@@ -418,51 +401,35 @@
 }
 
 static Bool
-isForbiddenGroupName( const char *name )
-{
-    size_t i;
-
-    for ( i = 0;
-	  i < sizeof( forbiddenGroupNames ) /
-	      sizeof( struct ForbiddenGroupName );
-	  i++ )
-    {
-	/* Negate result of Wld_match to ensure it is 1 or 0. */
-	if ( forbiddenGroupNames[i].match !=
-	     ( ! Wld_match( name, forbiddenGroupNames[i].pattern ) ) )
-	    return TRUE;
-    }
-
-    return FALSE;
-}
-
-static void
-processGrps( const char *lines, Bool noServerPattern )
+processGrps( Bool noServerPattern )
 {
     char postAllow;
+    Bool groupupdate;
+    Bool err;
     int first, last;
-    Str grp, line, file;
-    Bool groupupdate;
+    Str grp, file;
+    Str line;
 
     ASSERT( ! Lock_gotLock() );
     if ( ! Lock_openDatabases() )
-	return;
+	return TRUE;    /* silently ignore */
 
     groupupdate = FALSE;
-    while ( ( lines = Utl_getLn( line, lines) ) != NULL )
+
+    while ( getTxtLn( line, &err ) && !err )
     {
-        if ( sscanf( line, "%s %d %d %c",
+        if ( sscanf( line, MAXCHAR_FMT " %d %d %c",
                      grp, &last, &first, &postAllow ) != 4 )
         {
             Log_err( "Unknown reply to LIST or NEWGROUPS: %s", line );
             continue;
         }
-        if ( ! Grp_isValidGroupName( grp ) )
+        if ( ! Grp_isValidName( grp ) )
         {
             Log_inf( "Group name %s invalid", grp );
             continue;
         }
-	if ( isForbiddenGroupName( grp ) )
+	if ( Grp_isForbiddenName( grp ) )
 	{
 	    Log_inf( "Group %s forbidden", grp );
 	    continue;
@@ -513,7 +480,13 @@
 		  Cfg_spoolDir() );
 	Utl_stamp( file );
     }
+
+    /* I'm absolutely not sure about this. */
+    if ( err && groupupdate )
+            Log_err( "Group list may be corrupted with bogus data." );
+
     Lock_closeDatabases();
+    return !err;
 }
 
 void
@@ -531,7 +504,6 @@
 {
     Str cmd;
     int stat;
-    DynStr *response;
 
     Utl_cpyStr( cmd, "LIST ACTIVE" );
     if ( pattern[ 0 ] != '\0' )
@@ -564,12 +536,10 @@
 	return stat;
     }
 
-    response = collectTxt();
-    if ( response == NULL )
+    
+    if ( processGrps( *noServerPattern ) == FALSE )
 	return STAT_CONNECTION_LOST;
-    
-    processGrps( DynStr_str( response ), *noServerPattern );
-    del_DynStr( response );
+
     return STAT_OK;
 }
 
@@ -650,7 +620,7 @@
     result = STAT_OK;
     while ( ( lines = Utl_getLn( line, lines) ) != NULL )
     {
-        if ( sscanf( line, "%s", name ) != 1 )
+        if ( sscanf( line, MAXCHAR_FMT, name ) != 1 )
         {
             Log_err( "Unknown reply to LIST NEWSGROUPS: %s", line );
 	    result = STAT_PROGRAM_FAULT;
@@ -703,7 +673,6 @@
 {
     Str s;
     const char *p;
-    DynStr *response;
     int stat;
 
     ASSERT( *lastTime > 0 );
@@ -723,12 +692,9 @@
         return stat;
     }
 
-    response = collectTxt();
-    if ( response == NULL )
+    if( processGrps( TRUE ) == FALSE )
 	return STAT_CONNECTION_LOST;
-    
-    processGrps( DynStr_str( response ), TRUE );
-    del_DynStr( response );
+
     return STAT_OK;
 }