summaryrefslogtreecommitdiff
path: root/server/omapi.c
diff options
context:
space:
mode:
authorShawn Routhier <sar@isc.org>2013-06-05 18:15:49 -0700
committerShawn Routhier <sar@isc.org>2013-06-05 18:15:49 -0700
commit08b2d347838a79446aea6a57e679d3c8b1e8f663 (patch)
tree71691c319c6b63f997c0f3c4050399a0d030b513 /server/omapi.c
parent360cc6d99356fcf2d2368193607f8c7032dac8da (diff)
downloadisc-dhcp-08b2d347838a79446aea6a57e679d3c8b1e8f663.tar.gz
[master]
Modify the class and subclass code to allow for dynamic addition and removal of subclasses. See 27452 for details.
Diffstat (limited to 'server/omapi.c')
-rw-r--r--server/omapi.c440
1 files changed, 210 insertions, 230 deletions
diff --git a/server/omapi.c b/server/omapi.c
index 9a44fc0b..3ecf6a77 100644
--- a/server/omapi.c
+++ b/server/omapi.c
@@ -3,7 +3,8 @@
OMAPI object interfaces for the DHCP server. */
/*
- * Copyright (c) 2004-2009,2012,2013 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2012-2013 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2009 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
@@ -68,7 +69,7 @@ void dhcp_db_objects_setup ()
dhcp_lease_destroy,
dhcp_lease_signal_handler,
dhcp_lease_stuff_values,
- dhcp_lease_lookup,
+ dhcp_lease_lookup,
dhcp_lease_create,
dhcp_lease_remove,
#if defined (COMPACT_LEASES)
@@ -91,7 +92,7 @@ void dhcp_db_objects_setup ()
dhcp_class_destroy,
dhcp_class_signal_handler,
dhcp_class_stuff_values,
- dhcp_class_lookup,
+ dhcp_class_lookup,
dhcp_class_create,
dhcp_class_remove, 0, 0, 0,
sizeof (struct class), 0,
@@ -107,7 +108,7 @@ void dhcp_db_objects_setup ()
dhcp_class_destroy,
dhcp_subclass_signal_handler,
dhcp_subclass_stuff_values,
- dhcp_subclass_lookup,
+ dhcp_subclass_lookup,
dhcp_subclass_create,
dhcp_subclass_remove, 0, 0, 0,
sizeof (struct class), 0, RC_MISC);
@@ -122,7 +123,7 @@ void dhcp_db_objects_setup ()
dhcp_pool_destroy,
dhcp_pool_signal_handler,
dhcp_pool_stuff_values,
- dhcp_pool_lookup,
+ dhcp_pool_lookup,
dhcp_pool_create,
dhcp_pool_remove, 0, 0, 0,
sizeof (struct pool), 0, RC_MISC);
@@ -138,7 +139,7 @@ void dhcp_db_objects_setup ()
dhcp_host_destroy,
dhcp_host_signal_handler,
dhcp_host_stuff_values,
- dhcp_host_lookup,
+ dhcp_host_lookup,
dhcp_host_create,
dhcp_host_remove, 0, 0, 0,
sizeof (struct host_decl),
@@ -156,7 +157,7 @@ void dhcp_db_objects_setup ()
dhcp_failover_state_destroy,
dhcp_failover_state_signal,
dhcp_failover_state_stuff,
- dhcp_failover_state_lookup,
+ dhcp_failover_state_lookup,
dhcp_failover_state_create,
dhcp_failover_state_remove,
0, 0, 0,
@@ -220,7 +221,7 @@ isc_result_t dhcp_lease_set_value (omapi_object_t *h,
status = omapi_get_int_value (&bar, value);
if (status != ISC_R_SUCCESS)
return status;
-
+
if (bar < 1 || bar > FTS_LAST)
return DHCP_R_INVALIDARG;
nls = binding_state_names [bar - 1];
@@ -229,7 +230,7 @@ isc_result_t dhcp_lease_set_value (omapi_object_t *h,
ols = binding_state_names [lease -> binding_state - 1];
else
ols = "unknown state";
-
+
if (lease -> binding_state != bar) {
lease -> next_binding_state = bar;
if (supersede_lease (lease, 0, 1, 1, 1)) {
@@ -312,7 +313,7 @@ isc_result_t dhcp_lease_set_value (omapi_object_t *h,
if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
return status;
}
-
+
if (!lease -> scope) {
if (!binding_scope_allocate (&lease -> scope, MDL))
return ISC_R_NOMEMORY;
@@ -514,15 +515,10 @@ isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,
/* Write out all the values. */
- status = omapi_connection_put_name (c, "state");
+ status = omapi_connection_put_named_uint32(c, "state",
+ lease->binding_state);
if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32 (c, sizeof (int));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32 (c, lease -> binding_state);
- if (status != ISC_R_SUCCESS)
- return status;
+ return (status);
status = omapi_connection_put_name (c, "ip-address");
if (status != ISC_R_SUCCESS)
@@ -615,16 +611,10 @@ isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,
if (status != ISC_R_SUCCESS)
return status;
- status = omapi_connection_put_name (c, "hardware-type");
+ status = omapi_connection_put_named_uint32(c, "hardware-type",
+ lease->hardware_addr.hbuf[0]);
if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32 (c, sizeof (int));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32
- (c, lease -> hardware_addr.hbuf [0]);
- if (status != ISC_R_SUCCESS)
- return status;
+ return (status);
}
/* TIME values may be 64-bit, depending on system architecture.
@@ -638,68 +628,32 @@ isc_result_t dhcp_lease_stuff_values (omapi_object_t *c,
* 32-bit, code.
*/
bouncer = (u_int32_t)lease->ends;
- status = omapi_connection_put_name(c, "ends");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
+ status = omapi_connection_put_named_uint32(c, "ends", bouncer);
if (status != ISC_R_SUCCESS)
- return status;
+ return (status);
bouncer = (u_int32_t)lease->starts;
- status = omapi_connection_put_name(c, "starts");
+ status = omapi_connection_put_named_uint32(c, "starts", bouncer);
if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
- if (status != ISC_R_SUCCESS)
- return status;
+ return (status);
bouncer = (u_int32_t)lease->tstp;
- status = omapi_connection_put_name(c, "tstp");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
+ status = omapi_connection_put_named_uint32(c, "tstp", bouncer);
if (status != ISC_R_SUCCESS)
- return status;
+ return (status);
bouncer = (u_int32_t)lease->tsfp;
- status = omapi_connection_put_name(c, "tsfp");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
+ status = omapi_connection_put_named_uint32(c, "tsfp", bouncer);
if (status != ISC_R_SUCCESS)
return status;
bouncer = (u_int32_t)lease->atsfp;
- status = omapi_connection_put_name(c, "atsfp");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
+ status = omapi_connection_put_named_uint32(c, "atsfp", bouncer);
if (status != ISC_R_SUCCESS)
return status;
bouncer = (u_int32_t)lease->cltt;
- status = omapi_connection_put_name(c, "cltt");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, sizeof(bouncer));
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32(c, bouncer);
+ status = omapi_connection_put_named_uint32(c, "cltt", bouncer);
if (status != ISC_R_SUCCESS)
return status;
@@ -794,7 +748,7 @@ isc_result_t dhcp_lease_lookup (omapi_object_t **lp,
tv->value->u.buffer.value,
tv->value->u.buffer.len, MDL);
omapi_value_dereference (&tv, MDL);
-
+
if (*lp && *lp != (omapi_object_t *)lease) {
omapi_object_dereference (lp, MDL);
lease_dereference (&lease, MDL);
@@ -921,13 +875,13 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
return DHCP_R_INVALIDARG;
host = (struct host_decl *)h;
- /* XXX For now, we can only set these values on new host objects.
+ /* XXX For now, we can only set these values on new host objects.
XXX Soon, we need to be able to update host objects. */
if (!omapi_ds_strcmp (name, "name")) {
if (host -> name)
return ISC_R_EXISTS;
if (value && (value -> type == omapi_datatype_data ||
- value -> type == omapi_datatype_string)) {
+ value -> type == omapi_datatype_string)) {
host -> name = dmalloc (value -> u.buffer.len + 1,
MDL);
if (!host -> name)
@@ -943,7 +897,7 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
if (!omapi_ds_strcmp (name, "group")) {
if (value && (value -> type == omapi_datatype_data ||
- value -> type == omapi_datatype_string)) {
+ value -> type == omapi_datatype_string)) {
struct group_object *group;
group = (struct group_object *)0;
group_hash_lookup (&group, group_name_hash,
@@ -969,7 +923,7 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
if (host -> interface.hlen)
return ISC_R_EXISTS;
if (value && (value -> type == omapi_datatype_data ||
- value -> type == omapi_datatype_string)) {
+ value -> type == omapi_datatype_string)) {
if (value -> u.buffer.len >
(sizeof host -> interface.hbuf) - 1)
return DHCP_R_INVALIDARG;
@@ -1005,7 +959,7 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
if (host -> client_identifier.data)
return ISC_R_EXISTS;
if (value && (value -> type == omapi_datatype_data ||
- value -> type == omapi_datatype_string)) {
+ value -> type == omapi_datatype_string)) {
if (!buffer_allocate (&host -> client_identifier.buffer,
value -> u.buffer.len, MDL))
return ISC_R_NOMEMORY;
@@ -1099,7 +1053,7 @@ isc_result_t dhcp_host_set_value (omapi_object_t *h,
if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
return status;
}
-
+
return DHCP_R_UNKNOWNATTRIBUTE;
}
@@ -1327,14 +1281,8 @@ isc_result_t dhcp_host_stuff_values (omapi_object_t *c,
if (status != ISC_R_SUCCESS)
return status;
- status = omapi_connection_put_name (c, "hardware-type");
- if (status != ISC_R_SUCCESS)
- return status;
- status = omapi_connection_put_uint32 (c, sizeof (int));
- if (status != ISC_R_SUCCESS)
- return status;
- status = (omapi_connection_put_uint32
- (c, host -> interface.hbuf [0]));
+ status = omapi_connection_put_named_uint32(c, "hardware-type",
+ host->interface.hbuf[0]);
if (status != ISC_R_SUCCESS)
return status;
}
@@ -1458,7 +1406,7 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp,
host = (struct host_decl *)0;
host_hash_lookup (&host, host_hw_addr_hash, haddr, len, MDL);
dfree (haddr, MDL);
-
+
if (*lp && *lp != (omapi_object_t *)host) {
omapi_object_dereference (lp, MDL);
if (host)
@@ -1500,7 +1448,7 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp,
host_hash_lookup (&host, host_hw_addr_hash,
l -> hardware_addr.hbuf,
l -> hardware_addr.hlen, MDL);
-
+
if (host && *lp && *lp != (omapi_object_t *)host) {
omapi_object_dereference (lp, MDL);
if (host)
@@ -1531,7 +1479,7 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp,
tv -> value -> u.buffer.value,
tv -> value -> u.buffer.len, MDL);
omapi_value_dereference (&tv, MDL);
-
+
if (*lp && *lp != (omapi_object_t *)host) {
omapi_object_dereference (lp, MDL);
if (host)
@@ -1540,7 +1488,7 @@ isc_result_t dhcp_host_lookup (omapi_object_t **lp,
} else if (!host || (host -> flags & HOST_DECL_DELETED)) {
if (host)
host_dereference (&host, MDL);
- return ISC_R_NOTFOUND;
+ return ISC_R_NOTFOUND;
} else if (!*lp) {
/* XXX fix so that hash lookup itself creates
XXX the reference. */
@@ -1608,7 +1556,7 @@ isc_result_t dhcp_pool_set_value (omapi_object_t *h,
if (status == ISC_R_SUCCESS || status == DHCP_R_UNCHANGED)
return status;
}
-
+
return DHCP_R_UNKNOWNATTRIBUTE;
}
@@ -1711,23 +1659,46 @@ isc_result_t dhcp_pool_stuff_values (omapi_object_t *c,
omapi_object_t *id,
omapi_object_t *h)
{
- /* h should point to (struct pool *) */
+ struct pool *pool;
isc_result_t status;
- if (h -> type != dhcp_type_pool)
- return DHCP_R_INVALIDARG;
+ if (h->type != dhcp_type_pool)
+ return (DHCP_R_INVALIDARG);
+ pool = (struct pool *)h;
- /* Can't stuff pool values yet. */
+ /*
+ * I don't think we can actually find a pool yet
+ * but include the output of interesting values
+ * for when we do
+ */
+ status = omapi_connection_put_named_uint32(c, "lease-count",
+ ((u_int32_t)
+ pool->lease_count));
+ if (status != ISC_R_SUCCESS)
+ return (status);
+
+ status = omapi_connection_put_named_uint32(c, "free-leases",
+ ((u_int32_t)
+ pool->free_leases));
+ if (status != ISC_R_SUCCESS)
+ return (status);
+
+ status = omapi_connection_put_named_uint32(c, "backup-leases",
+ ((u_int32_t)
+ pool->backup_leases));
+ if (status != ISC_R_SUCCESS)
+ return (status);
+ /* we could add time stamps but lets wait on those */
/* Write out the inner object, if any. */
- if (h -> inner && h -> inner -> type -> stuff_values) {
- status = ((*(h -> inner -> type -> stuff_values))
- (c, id, h -> inner));
+ if (h->inner && h->inner->type->stuff_values) {
+ status = ((*(h->inner->type->stuff_values))
+ (c, id, h->inner));
if (status == ISC_R_SUCCESS)
- return status;
+ return (status);
}
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
isc_result_t dhcp_pool_lookup (omapi_object_t **lp,
@@ -1789,10 +1760,25 @@ class_set_value (omapi_object_t *h,
if (class->superclass != NULL)
class_dereference(&class->superclass, MDL);
-
class_reference(&class->superclass, superclass, MDL);
- } else if (value -> type == omapi_datatype_data ||
- value -> type == omapi_datatype_string) {
+
+ if (class->group != NULL)
+ group_dereference(&class->group, MDL);
+ group_reference(&class->group, superclass->group, MDL);
+
+ class->lease_limit = superclass->lease_limit;
+ if (class->lease_limit != 0) {
+ class->billed_leases =
+ dmalloc(class->lease_limit *
+ sizeof(struct lease *),
+ MDL);
+ if (class->billed_leases == NULL) {
+ return ISC_R_NOMEMORY;
+ }
+ }
+
+ } else if (value->type == omapi_datatype_data ||
+ value->type == omapi_datatype_string) {
class->name = dmalloc(value->u.buffer.len + 1, MDL);
if (!class->name)
return ISC_R_NOMEMORY;
@@ -1883,7 +1869,7 @@ class_set_value (omapi_object_t *h,
} else
return DHCP_R_INVALIDARG;
- /*
+ /*
* Currently no way to get here, if we update the above
* code so that we do get here this return needs to be
* uncommented.
@@ -1946,10 +1932,8 @@ isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line)
if (h -> type != dhcp_type_class && h -> type != dhcp_type_subclass)
return DHCP_R_INVALIDARG;
-
-#if defined (DEBUG_MEMORY_LEAKAGE) || \
- defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
struct class *class = (struct class *)h;
+
if (class -> nic)
class_dereference (&class -> nic, file, line);
if (class -> superclass)
@@ -1986,7 +1970,6 @@ isc_result_t dhcp_class_destroy (omapi_object_t *h, const char *file, int line)
file, line);
if (class -> superclass)
class_dereference (&class -> superclass, file, line);
-#endif
return ISC_R_SUCCESS;
}
@@ -2000,46 +1983,45 @@ class_signal_handler(omapi_object_t *h,
int updatep = 0;
int issubclass;
- issubclass = (h -> type == dhcp_type_subclass);
+ issubclass = (h->type == dhcp_type_subclass);
if (!strcmp (name, "updated")) {
-
+
if (!issubclass) {
- if (class -> name == 0 || strlen(class -> name) == 0) {
+ if (class->name == 0 || strlen(class->name) == 0) {
return DHCP_R_INVALIDARG;
}
} else {
- if (class -> superclass == 0) {
+ if (class->superclass == 0) {
return DHCP_R_INVALIDARG; /* didn't give name */
}
- if (class -> hash_string.data == NULL) {
+ if (class->hash_string.data == NULL) {
return DHCP_R_INVALIDARG;
}
}
if (issubclass) {
- if (!class -> superclass -> hash)
+ if (!class->superclass->hash)
class_new_hash(&class->superclass->hash,
SCLASS_HASH_SIZE, MDL);
- add_hash (class -> superclass -> hash,
- class -> hash_string.data,
- class -> hash_string.len,
- (void *)class, MDL);
+ class_hash_add(class->superclass->hash,
+ (const char *)class->hash_string.data,
+ class->hash_string.len,
+ (void *)class, MDL);
}
-
-
+
#ifdef DEBUG_OMAPI
if (issubclass) {
log_debug ("OMAPI added subclass %s",
- class -> superclass -> name);
+ class->superclass->name);
} else {
- log_debug ("OMAPI added class %s", class -> name);
+ log_debug ("OMAPI added class %s", class->name);
}
#endif
-
+
status = enter_class (class, 1, 1);
if (status != ISC_R_SUCCESS)
return status;
@@ -2047,9 +2029,9 @@ class_signal_handler(omapi_object_t *h,
}
/* Try to find some inner object that can take the value. */
- if (h -> inner && h -> inner -> type -> signal_handler) {
- status = ((*(h -> inner -> type -> signal_handler))
- (h -> inner, name, ap));
+ if (h->inner && h->inner->type->signal_handler) {
+ status = ((*(h->inner->type->signal_handler))
+ (h->inner, name, ap));
if (status == ISC_R_SUCCESS)
return status;
}
@@ -2070,108 +2052,138 @@ isc_result_t dhcp_class_signal_handler (omapi_object_t *h,
return class_signal_handler(h, name, ap);
}
-isc_result_t dhcp_class_stuff_values (omapi_object_t *c,
- omapi_object_t *id,
- omapi_object_t *h)
+
+/*
+ * Routine to put out generic class & subclass information
+ */
+isc_result_t class_stuff_values (omapi_object_t *c,
+ omapi_object_t *id,
+ omapi_object_t *h)
{
- /* h should point to (struct class *) */
+ struct class *class;
isc_result_t status;
- if (h -> type != dhcp_type_class)
- return DHCP_R_INVALIDARG;
+ class = (struct class *)h;
- /* Can't stuff class values yet. */
+ status = omapi_connection_put_named_uint32(c, "lease-limit",
+ ((u_int32_t)
+ class->lease_limit));
+ if (status != ISC_R_SUCCESS)
+ return (status);
+
+ status = omapi_connection_put_named_uint32(c, "leases-used",
+ ((u_int32_t)
+ class->leases_consumed));
+ if (status != ISC_R_SUCCESS)
+ return (status);
/* Write out the inner object, if any. */
- if (h -> inner && h -> inner -> type -> stuff_values) {
- status = ((*(h -> inner -> type -> stuff_values))
- (c, id, h -> inner));
+ if (h->inner && h->inner->type->stuff_values) {
+ status = ((*(h->inner->type->stuff_values))
+ (c, id, h->inner));
if (status == ISC_R_SUCCESS)
- return status;
+ return (status);
}
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
+}
+
+
+isc_result_t dhcp_class_stuff_values (omapi_object_t *c,
+ omapi_object_t *id,
+ omapi_object_t *h)
+{
+ if (h->type != dhcp_type_class)
+ return (DHCP_R_INVALIDARG);
+
+ /* add any class specific items here */
+
+ return (class_stuff_values(c, id, h));
}
static isc_result_t class_lookup (omapi_object_t **lp,
omapi_object_t *id, omapi_object_t *ref,
omapi_object_type_t *typewanted)
{
- omapi_value_t *nv = (omapi_value_t *)0;
- omapi_value_t *hv = (omapi_value_t *)0;
+ omapi_value_t *nv = NULL;
+ omapi_value_t *hv = NULL;
isc_result_t status;
struct class *class = 0;
struct class *subclass = 0;
*lp = NULL;
-
+
+ if (ref == NULL)
+ return (DHCP_R_NOKEYS);
+
/* see if we have a name */
- status = omapi_get_value_str (ref, id, "name", &nv);
+ status = omapi_get_value_str(ref, id, "name", &nv);
if (status == ISC_R_SUCCESS) {
- char *name = dmalloc(nv -> value -> u.buffer.len + 1, MDL);
+ char *name = dmalloc(nv->value->u.buffer.len + 1, MDL);
memcpy (name,
- nv -> value -> u.buffer.value,
- nv -> value -> u.buffer.len);
+ nv->value->u.buffer.value,
+ nv->value->u.buffer.len);
- omapi_value_dereference (&nv, MDL);
+ omapi_value_dereference(&nv, MDL);
find_class(&class, name, MDL);
dfree(name, MDL);
-
+
if (class == NULL) {
- return ISC_R_NOTFOUND;
+ return (ISC_R_NOTFOUND);
}
if (typewanted == dhcp_type_subclass) {
- status = omapi_get_value_str (ref, id,
- "hashstring", &hv);
+ status = omapi_get_value_str(ref, id,
+ "hashstring", &hv);
if (status != ISC_R_SUCCESS) {
class_dereference(&class, MDL);
- return DHCP_R_NOKEYS;
+ return (DHCP_R_NOKEYS);
}
- if (hv -> value -> type != omapi_datatype_data &&
- hv -> value -> type != omapi_datatype_string) {
+ if (hv->value->type != omapi_datatype_data &&
+ hv->value->type != omapi_datatype_string) {
class_dereference(&class, MDL);
- omapi_value_dereference (&hv, MDL);
- return DHCP_R_NOKEYS;
+ omapi_value_dereference(&hv, MDL);
+ return (DHCP_R_NOKEYS);
}
-
- class_hash_lookup (&subclass, class -> hash,
- (const char *)
- hv -> value -> u.buffer.value,
- hv -> value -> u.buffer.len, MDL);
-
- omapi_value_dereference (&hv, MDL);
+
+ class_hash_lookup(&subclass, class->hash,
+ (const char *)
+ hv->value->u.buffer.value,
+ hv->value->u.buffer.len, MDL);
+
+ omapi_value_dereference(&hv, MDL);
class_dereference(&class, MDL);
-
+
if (subclass == NULL) {
- return ISC_R_NOTFOUND;
+ return (ISC_R_NOTFOUND);
}
class_reference(&class, subclass, MDL);
class_dereference(&subclass, MDL);
}
-
-
+
/* Don't return the object if the type is wrong. */
- if (class -> type != typewanted) {
- class_dereference (&class, MDL);
- return DHCP_R_INVALIDARG;
+ if (class->type != typewanted) {
+ class_dereference(&class, MDL);
+ return (DHCP_R_INVALIDARG);
}
-
- if (class -> flags & CLASS_DECL_DELETED) {
- class_dereference (&class, MDL);
+
+ if (class->flags & CLASS_DECL_DELETED) {
+ class_dereference(&class, MDL);
+ return (ISC_R_NOTFOUND);
}
omapi_object_reference(lp, (omapi_object_t *)class, MDL);
-
- return ISC_R_SUCCESS;
+ class_dereference(&class, MDL);
+
+ return (ISC_R_SUCCESS);
}
- return DHCP_R_NOKEYS;
+ return (DHCP_R_NOKEYS);
}
@@ -2186,16 +2198,16 @@ isc_result_t dhcp_class_create (omapi_object_t **lp,
{
struct class *cp = 0;
isc_result_t status;
-
+
status = class_allocate(&cp, MDL);
if (status != ISC_R_SUCCESS)
- return status;
-
- group_reference (&cp -> group, root_group, MDL);
- cp -> flags = CLASS_DECL_DYNAMIC;
- status = omapi_object_reference (lp, (omapi_object_t *)cp, MDL);
- class_dereference (&cp, MDL);
- return status;
+ return (status);
+
+ clone_group(&cp->group, root_group, MDL);
+ cp->flags = CLASS_DECL_DYNAMIC;
+ status = omapi_object_reference(lp, (omapi_object_t *)cp, MDL);
+ class_dereference(&cp, MDL);
+ return (status);
}
isc_result_t dhcp_class_remove (omapi_object_t *lp,
@@ -2209,7 +2221,7 @@ isc_result_t dhcp_class_remove (omapi_object_t *lp,
#ifdef DEBUG_OMAPI
log_debug ("OMAPI delete class %s", cp -> name);
#endif
-
+
delete_class (cp, 1);
return ISC_R_SUCCESS;
}
@@ -2238,7 +2250,7 @@ isc_result_t dhcp_subclass_get_value (omapi_object_t *h, omapi_object_t *id,
subclass = (struct class *)h;
if (subclass -> name != 0)
return DHCP_R_INVALIDARG;
-
+
/* XXXJAB No values to get yet. */
/* Try to find some inner object that can provide the value. */
@@ -2266,26 +2278,16 @@ isc_result_t dhcp_subclass_stuff_values (omapi_object_t *c,
omapi_object_t *h)
{
struct class *subclass;
- isc_result_t status;
- if (h -> type != dhcp_type_class)
- return DHCP_R_INVALIDARG;
+ if (h->type != dhcp_type_subclass)
+ return (DHCP_R_INVALIDARG);
subclass = (struct class *)h;
- if (subclass -> name != 0)
- return DHCP_R_INVALIDARG;
-
-
- /* Can't stuff subclass values yet. */
+ if (subclass->name != 0)
+ return (DHCP_R_INVALIDARG);
- /* Write out the inner object, if any. */
- if (h -> inner && h -> inner -> type -> stuff_values) {
- status = ((*(h -> inner -> type -> stuff_values))
- (c, id, h -> inner));
- if (status == ISC_R_SUCCESS)
- return status;
- }
+ /* add any subclass specific items here */
- return ISC_R_SUCCESS;
+ return (class_stuff_values(c, id, h));
}
isc_result_t dhcp_subclass_lookup (omapi_object_t **lp,
@@ -2303,26 +2305,13 @@ isc_result_t dhcp_subclass_create (omapi_object_t **lp,
struct class *cp = 0;
isc_result_t status;
-/*
- * XXX
- * NOTE: subclasses and classes have the same internal type, which makes it
- * difficult to tell them apart. Specifically, in this function we need to
- * create a class object (because there is no such thing as a subclass
- * object), but one field of the class object is the type (which has the
- * value dhcp_type_class), and it is from here that all the other omapi
- * functions are accessed. So, even though there's a whole suite of
- * subclass functions registered, they won't get used. Now we could change
- * the type pointer after creating the class object, but I'm not certain
- * that won't break something else.
- */
-
status = subclass_allocate(&cp, MDL);
if (status != ISC_R_SUCCESS)
return status;
- group_reference (&cp -> group, root_group, MDL);
+ group_reference (&cp->group, root_group, MDL);
+
+ cp->flags = CLASS_DECL_DYNAMIC;
- cp -> flags = CLASS_DECL_DYNAMIC;
-
status = omapi_object_reference (lp, (omapi_object_t *)cp, MDL);
subclass_dereference (&cp, MDL);
return status;
@@ -2331,13 +2320,6 @@ isc_result_t dhcp_subclass_create (omapi_object_t **lp,
isc_result_t dhcp_subclass_remove (omapi_object_t *lp,
omapi_object_t *id)
{
-#if 1
-
- log_fatal("calling dhcp_subclass_set_value");
- /* this should never be called see dhcp_subclass_create for why */
-
-#else
-
struct class *cp;
if (lp -> type != dhcp_type_subclass)
return DHCP_R_INVALIDARG;
@@ -2346,11 +2328,9 @@ isc_result_t dhcp_subclass_remove (omapi_object_t *lp,
#ifdef DEBUG_OMAPI
log_debug ("OMAPI delete subclass %s", cp -> name);
#endif
-
+
delete_class (cp, 1);
-#endif
-
return ISC_R_SUCCESS;
}
@@ -2370,7 +2350,7 @@ isc_result_t binding_scope_set_value (struct binding_scope *scope, int createp,
if (!bp && !createp) {
dfree (nname, MDL);
return DHCP_R_UNKNOWNATTRIBUTE;
- }
+ }
if (!value) {
dfree (nname, MDL);
if (!bp)
@@ -2492,7 +2472,7 @@ isc_result_t binding_scope_get_value (omapi_value_t **value,
omapi_typed_data_dereference (&td, MDL);
return status;
}
-
+
omapi_data_string_reference (&(*value) -> name, name, MDL);
omapi_typed_data_reference (&(*value) -> value, td, MDL);
omapi_typed_data_dereference (&td, MDL);