]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/lists.c
Match list patterns case-insensitive
[ngircd-alex.git] / src / ngircd / lists.c
index fce351a9ea52fcdaadca8096c9f73b5d344c4b15..247344e508a6e3daf3fc164d1e47ddbdc0e98152 100644 (file)
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
  *
  * 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
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
- *
- * Management of IRC lists: ban, invite, ...
  */
 
-
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: lists.c,v 1.16 2005/01/26 13:23:24 alex Exp $";
+/**
+ * @file
+ * Management of IRC lists: ban, invite, etc.
+ */
 
-#include "imp.h"
 #include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <time.h>
 
-#include "defines.h"
 #include "conn.h"
-#include "client.h"
-#include "channel.h"
 #include "log.h"
 #include "match.h"
-#include "messages.h"
-#include "irc-write.h"
 
-#include <stdlib.h>
-#include <string.h>
-#include <strings.h>
-
-#include "exp.h"
 #include "lists.h"
 
+struct list_elem {
+       struct list_elem *next; /** pointer to next list element */
+       char mask[MASK_LEN];    /** IRC mask */
+       char *reason;           /** Optional "reason" text */
+       time_t valid_until;     /** 0: unlimited; 1: once; t(>1): until t */
+};
 
-#define MASK_LEN 2*CLIENT_HOST_LEN
-
-
-typedef struct _C2C
-{
-       struct _C2C *next;
-       CHAR mask[MASK_LEN];
-       CHANNEL *channel;
-       BOOLEAN onlyonce;
-} C2C;
-
-
-LOCAL C2C *My_Invites, *My_Bans;
-
-
-LOCAL C2C *New_C2C PARAMS(( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce ));
-
-LOCAL BOOLEAN Check_List PARAMS(( C2C **Cl2Chan, CLIENT *Client, CHANNEL *Chan ));
-LOCAL BOOLEAN Already_Registered PARAMS(( C2C *Cl2Chan, CHAR *Mask, CHANNEL *Chan ));
-
-
-
-GLOBAL VOID
-Lists_Init( VOID )
-{
-       /* Modul initialisieren */
-
-       My_Invites = My_Bans = NULL;
-} /* Lists_Init */
-
-
-GLOBAL VOID
-Lists_Exit( VOID )
+/**
+ * Get IRC mask stored in list element.
+ *
+ * @param list_elem List element.
+ * @return Pointer to IRC mask
+ */
+GLOBAL const char *
+Lists_GetMask(const struct list_elem *e)
 {
-       /* Modul abmelden */
-
-       C2C *c2c, *next;
-
-       /* Invite-Lists freigeben */
-       c2c = My_Invites;
-       while( c2c )
-       {
-               next = c2c->next;
-               free( c2c );
-               c2c = next;
-       }
+       assert(e != NULL);
+       return e->mask;
+}
 
-       /* Ban-Lists freigeben */
-       c2c = My_Bans;
-       while( c2c )
-       {
-               next = c2c->next;
-               free( c2c );
-               c2c = next;
-       }
-} /* Lists_Exit */
-
-
-GLOBAL BOOLEAN
-Lists_CheckInvited( CLIENT *Client, CHANNEL *Chan )
+/**
+ * Get optional "reason" text stored in list element.
+ *
+ * @param list_elem List element.
+ * @return Pointer to "reason" text or empty string ("").
+ */
+GLOBAL const char *
+Lists_GetReason(const struct list_elem *e)
 {
-       return Check_List( &My_Invites, Client, Chan );
-} /* Lists_CheckInvited */
-
+       assert(e != NULL);
+       return e->reason ? e->reason : "";
+}
 
-GLOBAL BOOLEAN
-Lists_IsInviteEntry( CHAR *Mask, CHANNEL *Chan )
+/**
+ * Get "validity" value stored in list element.
+ *
+ * @param list_elem List element.
+ * @return Validity: 0=unlimited, 1=once, >1 until this time stamp.
+ */
+GLOBAL time_t
+Lists_GetValidity(const struct list_elem *e)
 {
-       assert( Mask != NULL );
-       assert( Chan != NULL );
-       
-       return Already_Registered( My_Invites, Mask, Chan );
-} /* Lists_IsInviteEntry */
+       assert(e != NULL);
+       return e->valid_until;
+}
 
-
-GLOBAL BOOLEAN
-Lists_AddInvited( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce )
+/**
+ * Get first list element of a list.
+ *
+ * @param h List head.
+ * @return Pointer to first list element.
+ */
+GLOBAL struct list_elem*
+Lists_GetFirst(const struct list_head *h)
 {
-       C2C *c2c;
-
-       assert( Mask != NULL );
-       assert( Chan != NULL );
-
-       if( Already_Registered( My_Invites, Mask, Chan )) return TRUE;
-       
-       c2c = New_C2C( Mask, Chan, OnlyOnce );
-       if( ! c2c )
-       {
-               Log( LOG_ERR, "Can't add new invite list entry!" );
-               return FALSE;
-       }
-
-       /* verketten */
-       c2c->next = My_Invites;
-       My_Invites = c2c;
-
-       Log( LOG_DEBUG, "Added \"%s\" to invite list for \"%s\".", Mask, Channel_Name( Chan ));
-       return TRUE;
-} /* Lists_AddInvited */
-
+       assert(h != NULL);
+       return h->first;
+}
 
-GLOBAL VOID
-Lists_DelInvited( CHAR *Mask, CHANNEL *Chan )
+/**
+ * Get next list element of a list.
+ *
+ * @param e Current list element.
+ * @return Pointer to next list element.
+ */
+GLOBAL struct list_elem*
+Lists_GetNext(const struct list_elem *e)
 {
-       C2C *c2c, *last, *next;
-
-       assert( Mask != NULL );
-       assert( Chan != NULL );
-
-       last = NULL;
-       c2c = My_Invites;
-       while( c2c )
-       {
-               next = c2c->next;
-               if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 ))
-               {
-                       /* dieser Eintrag muss geloescht werden */
-                       Log( LOG_DEBUG, "Deleted \"%s\" from invite list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-                       if( last ) last->next = next;
-                       else My_Invites = next;
-                       free( c2c );
-               }
-               else last = c2c;
-               c2c = next;
-       }
-} /* Lists_DelInvited */
+       assert(e != NULL);
+       return e->next;
+}
 
-
-GLOBAL BOOLEAN
-Lists_ShowInvites( CLIENT *Client, CHANNEL *Channel )
+/**
+ * Add a new mask to a list.
+ *
+ * @param h List head.
+ * @param Mask The IRC mask to add to the list.
+ * @param ValidUntil 0: unlimited, 1: only once, t>1: until given time_t.
+ * @param Reason Reason string or NULL, if no reason should be saved.
+ * @return true on success, false otherwise.
+ */
+bool
+Lists_Add(struct list_head *h, const char *Mask, time_t ValidUntil,
+         const char *Reason)
 {
-       C2C *c2c;
-
-       assert( Client != NULL );
-       assert( Channel != NULL );
-
-       c2c = My_Invites;
-       while( c2c )
-       {
-               if( c2c->channel == Channel )
-               {
-                       /* Eintrag fuer Channel gefunden; ausgeben: */
-                       if( ! IRC_WriteStrClient( Client, RPL_INVITELIST_MSG, Client_ID( Client ), Channel_Name( Channel ), c2c->mask )) return DISCONNECTED;
+       struct list_elem *e, *newelem;
+
+       assert(h != NULL);
+       assert(Mask != NULL);
+
+       e = Lists_CheckDupeMask(h, Mask);
+       if (e) {
+               e->valid_until = ValidUntil;
+               if (Reason) {
+                       if (e->reason)
+                               free(e->reason);
+                       e->reason = strdup(Reason);
                }
-               c2c = c2c->next;
+               return true;
        }
-       return IRC_WriteStrClient( Client, RPL_ENDOFINVITELIST_MSG, Client_ID( Client ), Channel_Name( Channel ));
-} /* Lists_ShowInvites */
 
+       e = Lists_GetFirst(h);
 
-GLOBAL BOOLEAN
-Lists_SendInvites( CLIENT *Client )
-{
-       C2C *c2c;
-       
-       assert( Client != NULL );
-       
-       c2c = My_Invites;
-       while( c2c )
-       {
-               if( ! IRC_WriteStrClient( Client, "MODE %s +I %s", Channel_Name( c2c->channel ), c2c->mask )) return DISCONNECTED;
-               c2c = c2c->next;
+       newelem = malloc(sizeof(struct list_elem));
+       if (!newelem) {
+               Log(LOG_EMERG,
+                   "Can't allocate memory for new list entry!");
+               return false;
        }
-       return CONNECTED;
-} /* Lists_SendInvites */
 
-
-GLOBAL BOOLEAN
-Lists_SendBans( CLIENT *Client )
-{
-       C2C *c2c;
-       
-       assert( Client != NULL );
-       
-       c2c = My_Bans;
-       while( c2c )
-       {
-               if( ! IRC_WriteStrClient( Client, "MODE %s +b %s", Channel_Name( c2c->channel ), c2c->mask )) return DISCONNECTED;
-               c2c = c2c->next;
+       strlcpy(newelem->mask, Mask, sizeof(newelem->mask));
+       if (Reason) {
+               newelem->reason = strdup(Reason);
+               if (!newelem->reason)
+                       Log(LOG_EMERG,
+                           "Can't allocate memory for new list reason text!");
        }
-       return CONNECTED;
-} /* Lists_SendBans */
+       else
+               newelem->reason = NULL;
+       newelem->valid_until = ValidUntil;
+       newelem->next = e;
+       h->first = newelem;
 
+       return true;
+}
 
-GLOBAL BOOLEAN
-Lists_CheckBanned( CLIENT *Client, CHANNEL *Chan )
-{
-       return Check_List( &My_Bans, Client, Chan );
-} /* Lists_CheckBanned */
-
-
-GLOBAL BOOLEAN
-Lists_IsBanEntry( CHAR *Mask, CHANNEL *Chan )
-{
-       assert( Mask != NULL );
-       assert( Chan != NULL );
-       
-       return Already_Registered( My_Bans, Mask, Chan );
-} /* Lists_IsBanEntry */
-
-
-GLOBAL BOOLEAN
-Lists_AddBanned( CHAR *Mask, CHANNEL *Chan )
+/**
+ * Delete a list element from a list.
+ *
+ * @param h List head.
+ * @param p Pointer to previous list element or NULL, if there is none.
+ * @param victim List element to delete.
+ */
+static void
+Lists_Unlink(struct list_head *h, struct list_elem *p, struct list_elem *victim)
 {
-       C2C *c2c;
+       assert(victim != NULL);
+       assert(h != NULL);
 
-       assert( Mask != NULL );
-       assert( Chan != NULL );
+       if (p)
+               p->next = victim->next;
+       else
+               h->first = victim->next;
 
-       if( Already_Registered( My_Bans, Mask, Chan )) return TRUE;
+       if (victim->reason)
+               free(victim->reason);
 
-       c2c = New_C2C( Mask, Chan, FALSE );
-       if( ! c2c )
-       {
-               Log( LOG_ERR, "Can't add new ban list entry!" );
-               return FALSE;
-       }
+       free(victim);
+}
 
-       /* verketten */
-       c2c->next = My_Bans;
-       My_Bans = c2c;
-
-       Log( LOG_DEBUG, "Added \"%s\" to ban list for \"%s\".", Mask, Channel_Name( Chan ));
-       return TRUE;
-} /* Lists_AddBanned */
-
-
-GLOBAL VOID
-Lists_DelBanned( CHAR *Mask, CHANNEL *Chan )
+/**
+ * Delete a given IRC mask from a list.
+ *
+ * @param h List head.
+ * @param Mask IRC mask to delete from the list.
+ */
+GLOBAL void
+Lists_Del(struct list_head *h, const char *Mask)
 {
-       C2C *c2c, *last, *next;
+       struct list_elem *e, *last, *victim;
 
-       assert( Mask != NULL );
-       assert( Chan != NULL );
+       assert(h != NULL);
+       assert(Mask != NULL);
 
        last = NULL;
-       c2c = My_Bans;
-       while( c2c )
-       {
-               next = c2c->next;
-               if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 ))
-               {
-                       /* dieser Eintrag muss geloescht werden */
-                       Log( LOG_DEBUG, "Deleted \"%s\" from ban list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-                       if( last ) last->next = next;
-                       else My_Bans = next;
-                       free( c2c );
+       e = Lists_GetFirst(h);
+       while (e) {
+               if (strcasecmp(e->mask, Mask) == 0) {
+                       LogDebug("Deleted \"%s\" from list", e->mask);
+                       victim = e;
+                       e = victim->next;
+                       Lists_Unlink(h, last, victim);
+                       continue;
                }
-               else last = c2c;
-               c2c = next;
+               last = e;
+               e = e->next;
        }
-} /* Lists_DelBanned */
-
+}
 
-GLOBAL BOOLEAN
-Lists_ShowBans( CLIENT *Client, CHANNEL *Channel )
+/**
+ * Free a complete list.
+ *
+ * @param head List head.
+ */
+GLOBAL void
+Lists_Free(struct list_head *head)
 {
-       C2C *c2c;
-
-       assert( Client != NULL );
-       assert( Channel != NULL );
-
-       c2c = My_Bans;
-       while( c2c )
-       {
-               if( c2c->channel == Channel )
-               {
-                       /* Eintrag fuer Channel gefunden; ausgeben: */
-                       if( ! IRC_WriteStrClient( Client, RPL_BANLIST_MSG, Client_ID( Client ), Channel_Name( Channel ), c2c->mask )) return DISCONNECTED;
-               }
-               c2c = c2c->next;
+       struct list_elem *e, *victim;
+
+       assert(head != NULL);
+
+       e = head->first;
+       head->first = NULL;
+       while (e) {
+               LogDebug("Deleted \"%s\" from list" , e->mask);
+               victim = e;
+               e = e->next;
+               if (victim->reason)
+                       free(victim->reason);
+               free(victim);
        }
-       return IRC_WriteStrClient( Client, RPL_ENDOFBANLIST_MSG, Client_ID( Client ), Channel_Name( Channel ));
-} /* Lists_ShowBans */
+}
 
-
-GLOBAL VOID
-Lists_DeleteChannel( CHANNEL *Chan )
+/**
+ * Check if an IRC mask is already contained in a list.
+ *
+ * @param h List head.
+ * @param Mask IRC mask to test.
+ * @return true if mask is already stored in the list, false otherwise.
+ */
+GLOBAL struct list_elem *
+Lists_CheckDupeMask(const struct list_head *h, const char *Mask )
 {
-       /* Channel wurde geloescht, Invite- und Ban-Lists aufraeumen */
-
-       C2C *c2c, *last, *next;
-
-       /* Invite-List */
-       last = NULL;
-       c2c = My_Invites;
-       while( c2c )
-       {
-               next = c2c->next;
-               if( c2c->channel == Chan )
-               {
-                       /* dieser Eintrag muss geloescht werden */
-                       Log( LOG_DEBUG, "Deleted \"%s\" from invite list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-                       if( last ) last->next = next;
-                       else My_Invites = next;
-                       free( c2c );
-               }
-               else last = c2c;
-               c2c = next;
+       struct list_elem *e;
+       e = h->first;
+       while (e) {
+               if (strcasecmp(e->mask, Mask) == 0)
+                       return e;
+               e = e->next;
        }
+       return NULL;
+}
 
-       /* Ban-List */
-       last = NULL;
-       c2c = My_Bans;
-       while( c2c )
-       {
-               next = c2c->next;
-               if( c2c->channel == Chan )
-               {
-                       /* dieser Eintrag muss geloescht werden */
-                       Log( LOG_DEBUG, "Deleted \"%s\" from ban list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-                       if( last ) last->next = next;
-                       else My_Bans = next;
-                       free( c2c );
-               }
-               else last = c2c;
-               c2c = next;
-       }
-} /* Lists_DeleteChannel */
-
-
-GLOBAL CHAR *
-Lists_MakeMask( CHAR *Pattern )
+/**
+ * Generate a valid IRC mask from "any" string given.
+ *
+ * @param Pattern Source string to generate an IRC mask for.
+ * @param mask    Buffer to store the mask.
+ * @param len     Size of the buffer.
+ */
+GLOBAL void
+Lists_MakeMask(const char *Pattern, char *mask, size_t len)
 {
-       /* This function generats a valid IRC mask of "any" string. This
-        * mask is only valid until the next call to Lists_MakeMask(),
-        * because a single global buffer is used. You have to copy the
-        * generated mask to some sane location yourself! */
-
-       STATIC CHAR TheMask[MASK_LEN];
-       CHAR *excl, *at;
-
-       assert( Pattern != NULL );
+       char *excl, *at;
 
-       excl = strchr( Pattern, '!' );
-       at = strchr( Pattern, '@' );
+       assert(Pattern != NULL);
 
-       if(( at ) && ( at < excl )) excl = NULL;
+       excl = strchr(Pattern, '!');
+       at = strchr(Pattern, '@');
 
-       if(( ! at ) && ( ! excl ))
-       {
-               /* Neither "!" nor "@" found: use string as nick name */
-               strlcpy( TheMask, Pattern, sizeof( TheMask ) - 5 );
-               strlcat( TheMask, "!*@*", sizeof( TheMask ));
-               return TheMask;
-       }
+       if (at && at < excl)
+               excl = NULL;
 
-       if(( ! at ) && ( excl ))
-       {
+       if (!at && !excl) {
+               /* Neither "!" nor "@" found: use string as nickname */
+               strlcpy(mask, Pattern, len - 5);
+               strlcat(mask, "!*@*", len);
+       } else if (!at && excl) {
                /* Domain part is missing */
-               strlcpy( TheMask, Pattern, sizeof( TheMask ) - 3 );
-               strlcat( TheMask, "@*", sizeof( TheMask ));
-               return TheMask;
-       }
-
-       if(( at ) && ( ! excl ))
-       {
+               strlcpy(mask, Pattern, len - 3);
+               strlcat(mask, "@*", len);
+       } else if (at && !excl) {
                /* User name is missing */
                *at = '\0'; at++;
-               strlcpy( TheMask, Pattern, sizeof( TheMask ) - 5 );
-               strlcat( TheMask, "!*@", sizeof( TheMask ));
-               strlcat( TheMask, at, sizeof( TheMask ));
-               return TheMask;
+               strlcpy(mask, Pattern, len - 5);
+               strlcat(mask, "!*@", len);
+               strlcat(mask, at, len);
+               at--; *at = '@';
+       } else {
+               /* All parts (nick, user and domain name) are given */
+               strlcpy(mask, Pattern, len);
        }
-
-       /* All parts (nick, user and domain name) are given */
-       strlcpy( TheMask, Pattern, sizeof( TheMask ));
-       return TheMask;
 } /* Lists_MakeMask */
 
-
-LOCAL C2C *
-New_C2C( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce )
+/**
+ * Check if a client is listed in a list.
+ *
+ * @param h List head.
+ * @param Client Client to check.
+ * @return true if client is listed, false if not.
+ */
+bool
+Lists_Check(struct list_head *h, CLIENT *Client)
 {
-       C2C *c2c;
-       
-       assert( Mask != NULL );
-       assert( Chan != NULL );
-
-       /* Speicher fuer Eintrag anfordern */
-       c2c = (C2C *)malloc( sizeof( C2C ));
-       if( ! c2c )
-       {
-               Log( LOG_EMERG, "Can't allocate memory! [New_C2C]" );
-               return NULL;
-       }
-
-       strlcpy( c2c->mask, Mask, sizeof( c2c->mask ));
-       c2c->channel = Chan;
-       c2c->onlyonce = OnlyOnce;
-
-       return c2c;
-} /* New_C2C */
-
+       return Lists_CheckReason(h, Client, NULL, 0);
+}
 
-LOCAL BOOLEAN
-Check_List( C2C **Cl2Chan, CLIENT *Client, CHANNEL *Chan )
+/**
+ * Check if a client is listed in a list and store the reason.
+ *
+ * @param h      List head.
+ * @param Client Client to check.
+ * @param reason Buffer to store the reason.
+ * @param len    Size of the buffer if reason should be saved.
+ * @return true if client is listed, false if not.
+ */
+bool
+Lists_CheckReason(struct list_head *h, CLIENT *Client, char *reason, size_t len)
 {
-       C2C *c2c, *last;
+       struct list_elem *e, *last, *next;
 
-       assert( Cl2Chan != NULL );
-       assert( Client != NULL );
-       assert( Chan != NULL );
+       assert(h != NULL);
 
-       c2c = *Cl2Chan;
+       e = h->first;
        last = NULL;
 
-       while( c2c )
-       {
-               if( c2c->channel == Chan )
-               {
-                       /* Ok, richtiger Channel. Passt die Maske? */
-                       if( Match( c2c->mask, Client_Mask( Client )))
-                       {
-                               /* Treffer! */
-                               if( c2c->onlyonce )
-                               {
-                                       /* Eintrag loeschen */
-                                       Log( LOG_DEBUG, "Deleted \"%s\" from %s list for \"%s\".", c2c->mask, *Cl2Chan == My_Invites ? "invite" : "ban", Channel_Name( Chan ));
-                                       if( last ) last->next = c2c->next;
-                                       else *Cl2Chan = c2c->next;
-                                       free( c2c );
-                               }
-                               return TRUE;
+       while (e) {
+               next = e->next;
+               if (MatchCaseInsensitive(e->mask, Client_MaskCloaked(Client))) {
+                       if (len && e->reason)
+                               strlcpy(reason, e->reason, len);
+                       if (e->valid_until == 1) {
+                               /* Entry is valid only once, delete it */
+                               LogDebug("Deleted \"%s\" from list (used).",
+                                        e->mask);
+                               Lists_Unlink(h, last, e);
                        }
+                       return true;
                }
-               last = c2c;
-               c2c = c2c->next;
+               last = e;
+               e = next;
        }
 
-       return FALSE;
-} /* Check_List */
+       return false;
+}
 
-
-LOCAL BOOLEAN
-Already_Registered( C2C *List, CHAR *Mask, CHANNEL *Chan )
+/**
+ * Check list and purge expired entries.
+ *
+ * @param h List head.
+ */
+GLOBAL void
+Lists_Expire(struct list_head *h, const char *ListName)
 {
-       C2C *c2c;
+       struct list_elem *e, *last, *next;
+       time_t now;
+
+       assert(h != NULL);
 
-       c2c = List;
-       while( c2c )
-       {
-               if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 )) return TRUE;
-               c2c = c2c->next;
+       e = h->first;
+       last = NULL;
+       now = time(NULL);
+
+       while (e) {
+               next = e->next;
+               if (e->valid_until > 1 && e->valid_until < now) {
+                       /* Entry is expired, delete it */
+                       if (e->reason)
+                               Log(LOG_INFO,
+                                   "Deleted \"%s\" (\"%s\") from %s list (expired).",
+                                   e->mask, e->reason, ListName);
+                       else
+                               Log(LOG_INFO,
+                                   "Deleted \"%s\" from %s list (expired).",
+                                   e->mask, ListName);
+                       Lists_Unlink(h, last, e);
+                       e = next;
+                       continue;
+               }
+               last = e;
+               e = next;
        }
-       return FALSE;
-} /* Already_Registered */
+}
 
+/**
+ * Return the number of entries of a list.
+ *
+ * @param h List head.
+ * @return Number of items.
+ */
+GLOBAL unsigned long
+Lists_Count(struct list_head *h)
+{
+       struct list_elem *e;
+       unsigned long count = 0;
+
+       assert(h != NULL);
+
+       e = h->first;
+       while (e) {
+               count++;
+               e = e->next;
+       }
+       return count;
+}
 
 /* -eof- */