2000-01-22 00:18:05 +00:00
|
|
|
/*
|
2000-02-03 23:17:52 +00:00
|
|
|
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Internet Software Consortium.
|
2000-01-22 00:18:05 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM 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.
|
|
|
|
*/
|
|
|
|
|
2000-02-03 23:17:52 +00:00
|
|
|
/* $Id: value.c,v 1.4 2000/02/03 23:14:35 halley Exp $ */
|
2000-01-22 00:18:05 +00:00
|
|
|
|
|
|
|
/* Principal Author: Ted Lemon */
|
|
|
|
|
|
|
|
#include <string.h> /* memset */
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
|
|
|
|
#include <omapi/private.h>
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_create(omapi_value_t **d) {
|
|
|
|
omapi_value_t *new;
|
|
|
|
|
|
|
|
new = isc_mem_get(omapi_mctx, sizeof(*new));
|
|
|
|
if (new == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
memset(new, 0, sizeof *new);
|
|
|
|
|
|
|
|
omapi_value_reference(d, new);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
omapi_value_reference(omapi_value_t **r, omapi_value_t *h) {
|
|
|
|
REQUIRE(r != NULL && h != NULL);
|
|
|
|
REQUIRE(*r == NULL);
|
|
|
|
|
|
|
|
*r = h;
|
|
|
|
h->refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
omapi_value_dereference(omapi_value_t **h) {
|
|
|
|
REQUIRE(h != NULL && *h != NULL);
|
|
|
|
REQUIRE((*h)->refcnt > 0);
|
|
|
|
|
|
|
|
if (--((*h)->refcnt) <= 0) {
|
|
|
|
if ((*h)->name != NULL)
|
|
|
|
omapi_string_dereference(&(*h)->name);
|
|
|
|
if ((*h)->value != NULL)
|
|
|
|
omapi_data_dereference(&(*h)->value);
|
2000-01-24 05:35:18 +00:00
|
|
|
isc_mem_put(omapi_mctx, *h, sizeof(omapi_value_t));
|
2000-01-22 00:18:05 +00:00
|
|
|
}
|
|
|
|
*h = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_storedata(omapi_value_t **vp, omapi_string_t *name,
|
|
|
|
omapi_data_t *value)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = omapi_value_create(vp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
omapi_string_reference(&(*vp)->name, name);
|
|
|
|
|
|
|
|
if (value != NULL)
|
|
|
|
omapi_data_reference(&(*vp)->value, value);
|
|
|
|
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_storemem(omapi_value_t **vp, omapi_string_t *name,
|
|
|
|
const unsigned char *value, unsigned int len)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = omapi_value_create(vp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
omapi_string_reference(&(*vp)->name, name);
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
result = omapi_data_create(&(*vp)->value,
|
|
|
|
omapi_datatype_data, len);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
memcpy((*vp)->value->u.buffer.value, value, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
omapi_value_dereference(vp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_storeint(omapi_value_t **vp, omapi_string_t *name, int value)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = omapi_value_create(vp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
omapi_string_reference(&(*vp)->name, name);
|
|
|
|
|
|
|
|
if (value != 0) {
|
|
|
|
result = omapi_data_create(&(*vp)->value, omapi_datatype_int);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
(*vp)->value->u.integer = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
omapi_value_dereference(vp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_storeobject(omapi_value_t **vp, omapi_string_t *name,
|
|
|
|
omapi_object_t *value)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = omapi_value_create(vp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
omapi_string_reference(&(*vp)->name, name);
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
result = omapi_data_create(&(*vp)->value, omapi_datatype_int);
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = object_gethandle((omapi_handle_t *)
|
|
|
|
&(*vp)->value->u.integer,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
omapi_value_dereference(vp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_value_storestr(omapi_value_t **vp, omapi_string_t *name, char *value)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = omapi_value_create(vp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
omapi_string_reference(&(*vp)->name, name);
|
|
|
|
|
|
|
|
if (value != NULL)
|
|
|
|
result = omapi_data_create(&(*vp)->value,
|
|
|
|
omapi_datatype_string, value);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
omapi_value_dereference(vp);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-01-31 14:59:23 +00:00
|
|
|
omapi_value_getint(omapi_value_t *value) {
|
|
|
|
REQUIRE(value != NULL && value->value != NULL);
|
|
|
|
REQUIRE(value->value->type == omapi_datatype_int ||
|
|
|
|
((value->value->type == omapi_datatype_data ||
|
|
|
|
(value->value->type == omapi_datatype_string)) &&
|
|
|
|
value->value->u.buffer.len == sizeof(isc_uint32_t)));
|
|
|
|
|
|
|
|
return (omapi_data_getint(value->value));
|
|
|
|
}
|
2000-01-22 00:18:05 +00:00
|
|
|
|
2000-01-31 14:59:23 +00:00
|
|
|
/*
|
|
|
|
* WARNING: The region is valid only as long as the value pointer
|
|
|
|
* is valid. See omapi.h.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
omapi_value_getregion(omapi_value_t *value, isc_region_t *region) {
|
|
|
|
REQUIRE(value != NULL && value->value != NULL);
|
|
|
|
REQUIRE(value->value->type == omapi_datatype_data ||
|
|
|
|
value->value->type == omapi_datatype_string);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Boy, the word "value" appears a lot. Almost like a Smurf song.
|
|
|
|
* La la la la la la, la la la la la.
|
|
|
|
*/
|
|
|
|
region->base = value->value->u.buffer.value;
|
|
|
|
region->length = value->value->u.buffer.len;
|
2000-01-22 00:18:05 +00:00
|
|
|
}
|
2000-01-31 14:59:23 +00:00
|
|
|
|