]> git.ipfire.org Git - thirdparty/dhcp.git/blobdiff - omapip/handle.c
Moved the call to isc_app_ctxstart() to not get signal block by all threads
[thirdparty/dhcp.git] / omapip / handle.c
index 23a4aaa54fbeca32884aa3fa969c50506b2fbd5d..cae5ec25d638dcba23d47a00b8ba32a6c05fffbc 100644 (file)
@@ -3,23 +3,32 @@
    Functions for maintaining handles on objects. */
 
 /*
- * Copyright (c) 1996-1999 Internet Software Consortium.
- * Use is subject to license terms which appear in the file named
- * ISC-LICENSE that should have accompanied this file when you
- * received it.   If a file named ISC-LICENSE did not accompany this
- * file, or you are not sure the one you have is correct, you may
- * obtain an applicable copy of the license at:
+ * Copyright (c) 2009-2010,2012,2014 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004-2007 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 1999-2003 by Internet Software Consortium
  *
- *             http://www.isc.org/isc-license-1.0.html. 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * This file is part of the ISC DHCP distribution.   The documentation
- * associated with this file is listed in the file DOCUMENTATION,
- * included in the top-level directory of this release.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ *   Internet Systems Consortium, Inc.
+ *   950 Charter Street
+ *   Redwood City, CA 94063
+ *   <info@isc.org>
+ *   https://www.isc.org/
  *
- * Support and other services are available for ISC products - see
- * http://www.isc.org for more information.
  */
 
+#include "dhcpd.h"
+
 #include <omapip/omapip_p.h>
 
 /* The handle table is a hierarchical tree designed for quick mapping
 omapi_handle_table_t *omapi_handle_table;
 omapi_handle_t omapi_next_handle = 1;  /* Next handle to be assigned. */
 
+#define FIND_HAND  0
+#define CLEAR_HAND 1
+
 static isc_result_t omapi_handle_lookup_in (omapi_object_t **,
                                            omapi_handle_t,
-                                           omapi_handle_table_t *);
+                                           omapi_handle_table_t *,
+                                           int);
 static isc_result_t omapi_object_handle_in_table (omapi_handle_t,
                                                  omapi_handle_table_t *,
                                                  omapi_object_t *);
@@ -59,7 +72,6 @@ static isc_result_t omapi_handle_table_enclose (omapi_handle_table_t **);
 
 isc_result_t omapi_object_handle (omapi_handle_t *h, omapi_object_t *o)
 {
-       int tabix;
        isc_result_t status;
 
        if (o -> handle) {
@@ -226,58 +238,65 @@ static isc_result_t omapi_handle_table_enclose (omapi_handle_table_t **table)
 
 isc_result_t omapi_handle_lookup (omapi_object_t **o, omapi_handle_t h)
 {
-       return omapi_handle_lookup_in (o, h, omapi_handle_table);
+       return(omapi_handle_lookup_in(o, h, omapi_handle_table, FIND_HAND));
 }
 
 static isc_result_t omapi_handle_lookup_in (omapi_object_t **o,
                                            omapi_handle_t h,
-                                           omapi_handle_table_t *table)
-
+                                           omapi_handle_table_t *table,
+                                           int op)
 {
-       omapi_handle_table_t *inner;
        omapi_handle_t scale, index;
 
-       if (!table || table -> first > h || table -> limit <= h)
-               return ISC_R_NOTFOUND;
+       if (!table || table->first > h || table->limit <= h)
+               return(ISC_R_NOTFOUND);
        
        /* If this is a leaf table, just grab the object. */
-       if (table -> leafp) {
+       if (table->leafp) {
                /* Not there? */
-               if (!table -> children [h - table -> first].object)
-                       return ISC_R_NOTFOUND;
-               return omapi_object_reference
-                       (o, table -> children [h - table -> first].object,
-                        MDL);
+               if (!table->children[h - table->first].object)
+                       return(ISC_R_NOTFOUND);
+               if (op == CLEAR_HAND) {
+                       table->children[h - table->first].object = NULL;
+                       return(ISC_R_SUCCESS);
+               } else {
+                       return(omapi_object_reference
+                              (o, table->children[h - table->first].object,
+                               MDL));
+               }
        }
 
        /* Scale is the number of handles represented by each child of this
           table.   For a leaf table, scale would be 1.   For a first level
           of indirection, 120.   For a second, 120 * 120.   Et cetera. */
-       scale = (table -> limit - table -> first) / OMAPI_HANDLE_TABLE_SIZE;
+       scale = (table->limit - table->first) / OMAPI_HANDLE_TABLE_SIZE;
 
        /* So the next most direct table from this one that contains the
           handle must be the subtable of this table whose index into this
           table's array of children is the handle divided by the scale. */
-       index = (h - table -> first) / scale;
-       inner = table -> children [index].table;
+       index = (h - table->first) / scale;
 
-       return omapi_handle_lookup_in (o, h, table -> children [index].table);
+       return(omapi_handle_lookup_in(o, h, table->children[index].table, op));
 }
 
 /* For looking up objects based on handles that have been sent on the wire. */
 isc_result_t omapi_handle_td_lookup (omapi_object_t **obj,
                                     omapi_typed_data_t *handle)
 {
-       isc_result_t status;
        omapi_handle_t h;
 
-       if (handle -> type == omapi_datatype_int)
-               h = handle -> u.integer;
-       else if (handle -> type == omapi_datatype_data &&
-                handle -> u.buffer.len == sizeof h) {
-               memcpy (&h, handle -> u.buffer.value, sizeof h);
-               h = ntohl (h);
+       if (handle->type == omapi_datatype_int)
+               h = handle->u.integer;
+       else if (handle->type == omapi_datatype_data &&
+                handle->u.buffer.len == sizeof h) {
+               memcpy(&h, handle->u.buffer.value, sizeof h);
+               h = ntohl(h);
        } else
-               return ISC_R_INVALIDARG;
-       return omapi_handle_lookup (obj, h);
+               return(DHCP_R_INVALIDARG);
+       return(omapi_handle_lookup(obj, h));
+}
+
+isc_result_t omapi_handle_clear(omapi_handle_t h)
+{
+       return(omapi_handle_lookup_in(NULL, h, omapi_handle_table, CLEAR_HAND));
 }