mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-08-31 06:15:55 +00:00
Add hash_foreach, et al.
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"$Id: hash.c,v 1.23 2000/05/17 16:15:38 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
|
||||
"$Id: hash.c,v 1.24 2000/06/06 23:46:31 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "dhcpd.h"
|
||||
@@ -229,6 +229,27 @@ int hash_lookup (vp, table, name, len, file, line)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hash_foreach (struct hash_table *table, hash_foreach_func func)
|
||||
{
|
||||
int i;
|
||||
struct hash_bucket *bp, *next;
|
||||
int count = 0;
|
||||
|
||||
if (!table)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < table -> hash_count; i++) {
|
||||
bp = table -> buckets [i];
|
||||
while (bp) {
|
||||
next = bp -> next;
|
||||
(*func) (bp -> name, bp -> len, bp -> value);
|
||||
bp = next;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int casecmp (const void *v1, const void *v2, unsigned long len)
|
||||
{
|
||||
unsigned i;
|
||||
|
@@ -1521,6 +1521,7 @@ void delete_hash_entry PROTO ((struct hash_table *, const unsigned char *,
|
||||
unsigned, const char *, int));
|
||||
int hash_lookup PROTO ((hashed_object_t **, struct hash_table *,
|
||||
const unsigned char *, unsigned, const char *, int));
|
||||
int hash_foreach (struct hash_table *, hash_foreach_func);
|
||||
int casecmp (const void *s, const void *t, unsigned long len);
|
||||
HASH_FUNCTIONS_DECL (group, const char *, struct group_object)
|
||||
HASH_FUNCTIONS_DECL (universe, const char *, struct universe)
|
||||
@@ -2133,6 +2134,8 @@ void uid_hash_delete PROTO ((struct lease *));
|
||||
void hw_hash_add PROTO ((struct lease *));
|
||||
void hw_hash_delete PROTO ((struct lease *));
|
||||
void write_leases PROTO ((void));
|
||||
int lease_enqueue (struct lease *);
|
||||
void lease_instantiate (const unsigned char *, unsigned, struct lease *);
|
||||
void expire_all_pools PROTO ((void));
|
||||
void dump_subnets PROTO ((void));
|
||||
HASH_FUNCTIONS_DECL (lease, const unsigned char *, struct lease)
|
||||
@@ -2205,6 +2208,8 @@ isc_result_t dhcp_failover_set_state (dhcp_failover_state_t *,
|
||||
int dhcp_failover_pool_rebalance (dhcp_failover_state_t *);
|
||||
int dhcp_failover_pool_check (struct pool *);
|
||||
int dhcp_failover_state_pool_check (dhcp_failover_state_t *);
|
||||
void dhcp_failover_timeout (void *);
|
||||
void dhcp_failover_send_contact (void *);
|
||||
isc_result_t dhcp_failover_send_updates (dhcp_failover_state_t *);
|
||||
int dhcp_failover_queue_update (struct lease *, int);
|
||||
void dhcp_failover_ack_queue_remove (dhcp_failover_state_t *, struct lease *);
|
||||
|
@@ -48,6 +48,8 @@ typedef struct {
|
||||
int foo;
|
||||
} hashed_object_t;
|
||||
|
||||
typedef void (*hash_foreach_func) (const unsigned char *,
|
||||
unsigned, hashed_object_t *);
|
||||
typedef int (*hash_reference) (hashed_object_t **, hashed_object_t *,
|
||||
const char *, int);
|
||||
typedef int (*hash_dereference) (hashed_object_t **, const char *, int);
|
||||
@@ -82,7 +84,10 @@ void name##_hash_add (struct hash_table *, bufarg, unsigned, type *, \
|
||||
void name##_hash_delete (struct hash_table *, bufarg, unsigned, \
|
||||
const char *, int); \
|
||||
int name##_hash_lookup (type **, struct hash_table *, bufarg, unsigned, \
|
||||
const char *, int);
|
||||
const char *, int); \
|
||||
int name##_hash_foreach (struct hash_table *, \
|
||||
void (*) (bufarg, unsigned, type *));
|
||||
|
||||
|
||||
#define HASH_FUNCTIONS(name, bufarg, type) \
|
||||
void name##_hash_add (struct hash_table *table, \
|
||||
@@ -106,6 +111,12 @@ int name##_hash_lookup (type **ptr, struct hash_table *table, \
|
||||
{ \
|
||||
return hash_lookup ((hashed_object_t **)ptr, table, \
|
||||
(const unsigned char *)buf, len, file, line); \
|
||||
} \
|
||||
\
|
||||
int name##_hash_foreach (struct hash_table *table, \
|
||||
void (*func) (bufarg, unsigned, type *)) \
|
||||
{ \
|
||||
return hash_foreach (table, (hash_foreach_func)func); \
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user