Converted the browser database to a ubi_dLinkList. This should reduce code
authorChristopher R. Hertel <crh@samba.org>
Fri, 24 Jul 1998 19:03:11 +0000 (19:03 +0000)
committerChristopher R. Hertel <crh@samba.org>
Fri, 24 Jul 1998 19:03:11 +0000 (19:03 +0000)
size, etc.  Also did a bit of work to add comments.
Chris -)-----

source/include/nameserv.h
source/include/proto.h
source/nmbd/nmbd_browserdb.c
source/nmbd/nmbd_browsesync.c

index 0ba7acda189dca4a4db15e07b1f42f74ef01464b..80d9667d1c35f162f5327ae832dc6a16bee97c1c 100644 (file)
@@ -189,11 +189,10 @@ struct nmb_data
   time_t refresh_time; /* The time the record should be refreshed. */
 };
 
-/* This is the structure used for the local netbios name list. */
+/* This structure represents an entry in a local netbios name list. */
 struct name_record
   {
   ubi_trNode            node[1];
-
   struct subnet_record *subnet;
   struct nmb_name       name;    /* The netbios name. */
   struct nmb_data       data;    /* The netbios data. */
@@ -201,16 +200,14 @@ struct name_record
 
 /* Browser cache for synchronising browse lists. */
 struct browse_cache_record
-{
-  struct browse_cache_record *next;
-  struct browse_cache_record *prev;
-
-  pstring lmb_name;
-  pstring work_group;
+  {
+  ubi_dlNode     node[1];
+  pstring        lmb_name;
+  pstring        work_group;
   struct in_addr ip;
-  time_t sync_time;
-  time_t death_time; /* The time the record must be removed. */
-};
+  time_t         sync_time;
+  time_t         death_time; /* The time the record must be removed. */
+  };
 
 /* This is used to hold the list of servers in my domain, and is
    contained within lists of domains. */
index 5819d1aadcbf6297e0a2008e90276cdb43ebe8f9..8adfb70d38cb559b54cf853a9d020f2da71a71ae 100644 (file)
@@ -1270,13 +1270,13 @@ void set_workgroup_local_master_browser_name( struct work_record *work, char *ne
 
 /*The following definitions come from  nmbd_browserdb.c  */
 
-void remove_lmb_browser_entry(struct browse_cache_record *browc);
-void update_browser_death_time(struct browse_cache_record *browc);
-struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name, 
-                                                        struct in_addr ip);
+void update_browser_death_time( struct browse_cache_record *browc );
+struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, 
+                                                         char *browser_name, 
+                                                         struct in_addr ip );
 struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
-void expire_lmb_browsers(time_t t);
-void remove_workgroup_lmb_browsers(char *work_group);
+void expire_lmb_browsers( time_t t );
+void remove_workgroup_lmb_browsers( char *work_group );
 
 /*The following definitions come from  nmbd_browsesync.c  */
 
index ee3e4e4bde151bc506870399818bcb00d98d3048..293a129d429c757d233775d6373f96d29a57da9d 100644 (file)
@@ -5,6 +5,7 @@
    Copyright (C) Andrew Tridgell 1994-1998
    Copyright (C) Luke Kenneth Casson Leighton 1994-1998
    Copyright (C) Jeremy Allison 1994-1998
+   Copyright (C) Christopher R. Hertel 1998
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
 */
+/* -------------------------------------------------------------------------- **
+ * Modified July 1998 by CRH.
+ *  I converted this module to use the canned doubly-linked lists.  I also
+ *  added comments above the functions where possible.
+ */
 
 #include "includes.h"
-#include "smb.h"
 
 extern int DEBUGLEVEL;
 
-/* This is our local master browser list database. */
-struct browse_cache_record *lmb_browserlist = NULL;
-
-/***************************************************************************
-Add a browser into the lmb list.
-**************************************************************************/
-
-static void add_to_lmb_browse_cache(struct browse_cache_record *browc)
-{
-  struct browse_cache_record *browc2;
-
-  if (lmb_browserlist == NULL)
+/* -------------------------------------------------------------------------- **
+ * Variables...
+ *
+ *  lmb_browserlist - This is our local master browser list. 
+ */
+
+ubi_dlNewList( lmb_browserlist );
+
+
+/* -------------------------------------------------------------------------- **
+ * Functions...
+ */
+
+/* ************************************************************************** **
+ * Remove and free a browser list entry.
+ *
+ *  Input:  browc - A pointer to the entry to be removed from the list and
+ *                  freed.
+ *  Output: none.
+ *
+ * ************************************************************************** **
+ */
+static void remove_lmb_browser_entry( struct browse_cache_record *browc )
+  {
+  free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) );
+  } /* remove_lmb_browser_entry */
+
+/* ************************************************************************** **
+ * Update a browser death time.
+ *
+ *  Input:  browc - Pointer to the entry to be updated.
+ *  Output: none.
+ *
+ * ************************************************************************** **
+ */
+void update_browser_death_time( struct browse_cache_record *browc )
   {
-    lmb_browserlist = browc;
-    browc->prev = NULL;
-    browc->next = NULL;
-    return;
-  }
-  
-  for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next)
-    ;
-  
-  browc2->next = browc;
-  browc->next = NULL;
-  browc->prev = browc2;
-}
-
-/*******************************************************************
-Remove a lmb browser entry.
-******************************************************************/
-
-void remove_lmb_browser_entry(struct browse_cache_record *browc)
-{
-  if (browc->prev)
-    browc->prev->next = browc->next;
-  if (browc->next)
-    browc->next->prev = browc->prev;
-
-  if (lmb_browserlist == browc)
-    lmb_browserlist = browc->next; 
-         
-  free((char *)browc);
-}
-
-/****************************************************************************
-Update a browser death time.
-****************************************************************************/
-
-void update_browser_death_time(struct browse_cache_record *browc)
-{
   /* Allow the new lmb to miss an announce period before we remove it. */
-  browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
-}
-
-/****************************************************************************
-Create a browser entry.
-****************************************************************************/
-
-struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name, 
-                                                        struct in_addr ip)
-{
+  browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
+  } /* update_browser_death_time */
+
+/* ************************************************************************** **
+ * Create a browser entry and add it to the local master browser list.
+ *
+ *  Input:  work_name
+ *          browser_name
+ *          ip
+ *
+ *  Output: Pointer to the new entry, or NULL if malloc() failed.
+ *
+ * ************************************************************************** **
+ */
+struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, 
+                                                         char *browser_name, 
+                                                         struct in_addr ip )
+  {
   struct browse_cache_record *browc;
-  time_t now = time(NULL);
+  time_t now = time( NULL );
 
-  browc = (struct browse_cache_record *)malloc(sizeof(*browc));
-     
-  if (browc == NULL)
-  {
-    DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n"));
-    return(NULL);
-  }
+  browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
 
-  bzero((char *)browc,sizeof(*browc));
+  if( NULL == browc )
+    {
+    DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
+    return( NULL );
+    }
+
+  bzero( (char *)browc, sizeof( *browc ) );
   
   /* For a new lmb entry we want to sync with it after one minute. This
      will allow it time to send out a local announce and build its
-     browse list. */
-
+     browse list.
+   */
   browc->sync_time = now + 60;
 
   /* Allow the new lmb to miss an announce period before we remove it. */
-  browc->death_time = now + (CHECK_TIME_MST_ANNOUNCE + 2)*60;
+  browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
 
-  StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1);
-  StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1);
-  strupper(browc->lmb_name);
-  strupper(browc->work_group);
+  StrnCpy(  browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
+  StrnCpy(  browc->work_group, work_name, sizeof(browc->work_group)-1 );
+  strupper( browc->lmb_name );
+  strupper( browc->work_group );
   
   browc->ip = ip;
  
-  add_to_lmb_browse_cache(browc);
-      
-  DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n",
-            browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time));
-  
-  return(browc);
-}
-
-/****************************************************************************
-Find a browser entry.
-****************************************************************************/
+  (void)ubi_dlAddTail( lmb_browserlist, browc );
 
+  if( DEBUGLVL( 3 ) )
+    {
+    Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" );
+    Debug1( "  Added lmb cache entry for workgroup %s ", browc->work_group );
+    Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) );
+    Debug1( "ttl %d\n", browc->death_time );
+    }
+  
+  return( browc );
+  } /* create_browser_in_lmb_cache */
+
+/* ************************************************************************** **
+ * Find a browser entry in the local master browser list.
+ *
+ *  Input:  browser_name  - The name for which to search.
+ *
+ *  Output: A pointer to the matching entry, or NULL if no match was found.
+ *
+ * ************************************************************************** **
+ */
 struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name )
-{
-  struct browse_cache_record *browc = NULL;
+  {
+  struct browse_cache_record *browc;
 
-  for( browc = lmb_browserlist; browc; browc = browc->next)
-    if(strequal( browser_name, browc->lmb_name))
+  for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+       browc;
+       browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
+    if( strequal( browser_name, browc->lmb_name ) )
       break;
 
-  return browc;
-}
-
-/*******************************************************************
-  Expire timed out browsers in the browserlist.
-******************************************************************/
-
-void expire_lmb_browsers(time_t t)
-{
+  return( browc );
+  } /* find_browser_in_lmb_cache */
+
+/* ************************************************************************** **
+ *  Expire timed out browsers in the browserlist.
+ *
+ *  Input:  t - Expiration time.  Entries with death times less than this
+ *              value will be removed from the list.
+ *  Output: none.
+ *
+ * ************************************************************************** **
+ */
+void expire_lmb_browsers( time_t t )
+  {
   struct browse_cache_record *browc;
   struct browse_cache_record *nextbrowc;
 
-  for (browc = lmb_browserlist; browc; browc = nextbrowc)
-  {
-    nextbrowc = browc->next;
-
-    if (browc->death_time < t)
+  for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+       browc;
+       browc = nextbrowc )
     {
-      DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name));
-      remove_lmb_browser_entry(browc);
+    nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
+
+    if( browc->death_time < t )
+      {
+      if( DEBUGLVL( 3 ) )
+        {
+        Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" );
+        Debug1( "  Removing timed out lmb entry %s\n", browc->lmb_name );
+        }
+      remove_lmb_browser_entry( browc );
+      }
     }
-  }
-}
-
-/*******************************************************************
-  Remove browsers from a named workgroup in the browserlist.
-******************************************************************/
-
-void remove_workgroup_lmb_browsers(char *work_group)
+  } /* expire_lmb_browsers */
+
+/* ************************************************************************** **
+ *  Remove browsers from a named workgroup in the browserlist.
+ *
+ *  Input:  work_group  - The name of the work group which is to be removed
+ *                        from the browse list.
+ *  Output: none.
+ *
+ * ************************************************************************** **
+ */
+void remove_workgroup_lmb_browsers( char *work_group )
 {
   struct browse_cache_record *browc;
   struct browse_cache_record *nextbrowc;
 
-  for (browc = lmb_browserlist; browc; browc = nextbrowc)
-  {
-    nextbrowc = browc->next;
-
-    if (strequal(work_group, browc->work_group))
+  for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+       browc;
+       browc = nextbrowc )
     {
-      DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name));
+    nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
+
+    if( strequal( work_group, browc->work_group ) )
+      {
+      if( DEBUGLVL( 3 ) )
+        {
+        Debug1( "nmbd_browserdb:remove_workgroup_browsers()\n" );
+        Debug1( "Removing lmb entry %s\n", browc->lmb_name );
+        }
       remove_lmb_browser_entry(browc);
+      }
     }
-  }
-}
+  } /* remove_workgroup_lmb_browsers */
 
+/* ========================================================================== */
index c1f6aa5a6c4b86a6756ee85b7f81730ef5ddbc9a..dd4a82d7f62f0e1726bbad9e7b0820978f5f9a0d 100644 (file)
@@ -215,7 +215,9 @@ void dmb_expire_and_sync_browser_lists(time_t t)
 
   expire_lmb_browsers(t);
 
-  for (browc = lmb_browserlist; browc; browc = browc->next)
+  for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
+       browc;
+       browc = (struct browse_cache_record *)ubi_dlNext( browc ) )
   {
     if (browc->sync_time < t)
       sync_with_lmb(browc);