1
0
mirror of https://github.com/samba-team/samba.git synced 2025-12-13 16:23:50 +03:00

Converted the browser database to a ubi_dLinkList. This should reduce code

size, etc.  Also did a bit of work to add comments.
Chris -)-----
This commit is contained in:
Christopher R. Hertel
-
parent 16f0ad0c91
commit d8b0a2104c
4 changed files with 173 additions and 139 deletions

View File

@@ -189,11 +189,10 @@ struct nmb_data
time_t refresh_time; /* The time the record should be refreshed. */ 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 struct name_record
{ {
ubi_trNode node[1]; ubi_trNode node[1];
struct subnet_record *subnet; struct subnet_record *subnet;
struct nmb_name name; /* The netbios name. */ struct nmb_name name; /* The netbios name. */
struct nmb_data data; /* The netbios data. */ struct nmb_data data; /* The netbios data. */
@@ -202,9 +201,7 @@ struct name_record
/* Browser cache for synchronising browse lists. */ /* Browser cache for synchronising browse lists. */
struct browse_cache_record struct browse_cache_record
{ {
struct browse_cache_record *next; ubi_dlNode node[1];
struct browse_cache_record *prev;
pstring lmb_name; pstring lmb_name;
pstring work_group; pstring work_group;
struct in_addr ip; struct in_addr ip;

View File

@@ -1270,9 +1270,9 @@ void set_workgroup_local_master_browser_name( struct work_record *work, char *ne
/*The following definitions come from nmbd_browserdb.c */ /*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 ); 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 browse_cache_record *create_browser_in_lmb_cache( char *work_name,
char *browser_name,
struct in_addr ip ); struct in_addr ip );
struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ); struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name );
void expire_lmb_browsers( time_t t ); void expire_lmb_browsers( time_t t );

View File

@@ -5,6 +5,7 @@
Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Luke Kenneth Casson Leighton 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998
Copyright (C) Jeremy Allison 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 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 it under the terms of the GNU General Public License as published by
@@ -21,71 +22,70 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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 "includes.h"
#include "smb.h"
extern int DEBUGLEVEL; extern int DEBUGLEVEL;
/* This is our local master browser list database. */ /* -------------------------------------------------------------------------- **
struct browse_cache_record *lmb_browserlist = NULL; * Variables...
*
* lmb_browserlist - This is our local master browser list.
*/
/*************************************************************************** ubi_dlNewList( lmb_browserlist );
Add a browser into the lmb list.
**************************************************************************/
static void add_to_lmb_browse_cache(struct browse_cache_record *browc)
/* -------------------------------------------------------------------------- **
* 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 )
{ {
struct browse_cache_record *browc2; free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) );
} /* remove_lmb_browser_entry */
if (lmb_browserlist == NULL)
{
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.
****************************************************************************/
/* ************************************************************************** **
* 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 ) void update_browser_death_time( struct browse_cache_record *browc )
{ {
/* Allow the new lmb to miss an announce period before we remove it. */ /* Allow the new lmb to miss an announce period before we remove it. */
browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60; browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
} } /* update_browser_death_time */
/**************************************************************************** /* ************************************************************************** **
Create a browser entry. * Create a browser entry and add it to the local master browser list.
****************************************************************************/ *
* Input: work_name
struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_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 in_addr ip )
{ {
struct browse_cache_record *browc; struct browse_cache_record *browc;
@@ -93,7 +93,7 @@ struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *b
browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
if (browc == NULL) if( NULL == browc )
{ {
DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
return( NULL ); return( NULL );
@@ -103,12 +103,12 @@ struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *b
/* For a new lmb entry we want to sync with it after one minute. This /* 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 will allow it time to send out a local announce and build its
browse list. */ browse list.
*/
browc->sync_time = now + 60; browc->sync_time = now + 60;
/* Allow the new lmb to miss an announce period before we remove it. */ /* 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->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 ); StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 );
@@ -117,68 +117,103 @@ struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *b
browc->ip = ip; browc->ip = ip;
add_to_lmb_browse_cache(browc); (void)ubi_dlAddTail( lmb_browserlist, browc );
DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n", if( DEBUGLVL( 3 ) )
browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time)); {
Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" );
return(browc); 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 );
Find a browser entry. } /* 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 *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) 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 ) ) if( strequal( browser_name, browc->lmb_name ) )
break; break;
return browc; return( browc );
} } /* find_browser_in_lmb_cache */
/*******************************************************************
Expire timed out browsers in the browserlist.
******************************************************************/
/* ************************************************************************** **
* 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 ) void expire_lmb_browsers( time_t t )
{ {
struct browse_cache_record *browc; struct browse_cache_record *browc;
struct browse_cache_record *nextbrowc; struct browse_cache_record *nextbrowc;
for (browc = lmb_browserlist; browc; browc = nextbrowc) for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
browc;
browc = nextbrowc )
{ {
nextbrowc = browc->next; nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
if( browc->death_time < t ) if( browc->death_time < t )
{ {
DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name)); 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_lmb_browser_entry( browc );
} }
} }
} } /* expire_lmb_browsers */
/*******************************************************************
Remove browsers from a named workgroup in the browserlist.
******************************************************************/
/* ************************************************************************** **
* 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 ) void remove_workgroup_lmb_browsers( char *work_group )
{ {
struct browse_cache_record *browc; struct browse_cache_record *browc;
struct browse_cache_record *nextbrowc; struct browse_cache_record *nextbrowc;
for (browc = lmb_browserlist; browc; browc = nextbrowc) for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist );
browc;
browc = nextbrowc )
{ {
nextbrowc = browc->next; nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc );
if( strequal( work_group, browc->work_group ) ) if( strequal( work_group, browc->work_group ) )
{ {
DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name)); 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_lmb_browser_entry(browc);
} }
} }
} } /* remove_workgroup_lmb_browsers */
/* ========================================================================== */

View File

@@ -215,7 +215,9 @@ void dmb_expire_and_sync_browser_lists(time_t t)
expire_lmb_browsers(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) if (browc->sync_time < t)
sync_with_lmb(browc); sync_with_lmb(browc);