dhcpctl.c 17.5 KB
Newer Older
Ted Lemon's avatar
Ted Lemon committed
1 2 3 4 5
/* dhcpctl.c

   Subroutines providing general support for objects. */

/*
David Hankins's avatar
David Hankins committed
6
 * Copyright (c) 2004,2007 by Internet Systems Consortium, Inc. ("ISC")
7
 * Copyright (c) 1999-2003 by Internet Software Consortium
Ted Lemon's avatar
Ted Lemon committed
8
 *
9 10 11
 * 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.
Ted Lemon's avatar
Ted Lemon committed
12
 *
13 14 15 16 17 18 19
 * 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.
Ted Lemon's avatar
Ted Lemon committed
20
 *
21 22 23 24 25
 *   Internet Systems Consortium, Inc.
 *   950 Charter Street
 *   Redwood City, CA 94063
 *   <info@isc.org>
 *   http://www.isc.org/
Ted Lemon's avatar
Ted Lemon committed
26
 *
27
 * This software has been written for Internet Systems Consortium
Ted Lemon's avatar
Ted Lemon committed
28
 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29
 * To learn more about Internet Systems Consortium, see
Ted Lemon's avatar
Ted Lemon committed
30 31 32
 * ``http://www.isc.org/''.  To learn more about Vixie Enterprises,
 * see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
 * ``http://www.nominum.com''.
Ted Lemon's avatar
Ted Lemon committed
33 34
 */

35 36
#ifndef lint
static char copyright[] =
David Hankins's avatar
David Hankins committed
37
"$Id: dhcpctl.c,v 1.27 2007/05/19 19:16:24 dhankins Exp $ Copyright (c) 2004,2007 Internet Systems Consortium.  All rights reserved.\n";
38 39
#endif /* not lint */

40
#include "dhcpd.h"
41
#include <omapip/omapip_p.h>
Ted Lemon's avatar
Ted Lemon committed
42 43 44
#include "dhcpctl.h"

omapi_object_type_t *dhcpctl_callback_type;
45
omapi_object_type_t *dhcpctl_remote_type;
Ted Lemon's avatar
Ted Lemon committed
46 47 48 49 50 51 52

/* dhcpctl_initialize ()

   Must be called before any other dhcpctl function. */

dhcpctl_status dhcpctl_initialize ()
{
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
	isc_result_t status;

	status = omapi_init();
	if (status != ISC_R_SUCCESS)
		return status;

	status = omapi_object_type_register (&dhcpctl_callback_type,
					     "dhcpctl-callback",
					     dhcpctl_callback_set_value,
					     dhcpctl_callback_get_value,
					     dhcpctl_callback_destroy,
					     dhcpctl_callback_signal_handler,
					     dhcpctl_callback_stuff_values,
					     0, 0, 0, 0, 0, 0,
					     sizeof
68 69
					     (dhcpctl_callback_object_t), 0,
					     RC_MISC);
70 71 72 73 74 75 76 77 78 79 80
	if (status != ISC_R_SUCCESS)
		return status;

	status = omapi_object_type_register (&dhcpctl_remote_type,
					     "dhcpctl-remote",
					     dhcpctl_remote_set_value,
					     dhcpctl_remote_get_value,
					     dhcpctl_remote_destroy,
					     dhcpctl_remote_signal_handler,
					     dhcpctl_remote_stuff_values,
					     0, 0, 0, 0, 0, 0,
81
					     sizeof (dhcpctl_remote_object_t),
82
					     0, RC_MISC);
83 84 85
	if (status != ISC_R_SUCCESS)
		return status;

Ted Lemon's avatar
Ted Lemon committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
	return ISC_R_SUCCESS;
}

/* dhcpctl_connect

   synchronous
   returns nonzero status code if it didn't connect, zero otherwise
   stores connection handle through connection, which can be used
   for subsequent access to the specified server. 
   server_name is the name of the server, and port is the TCP
   port on which it is listening.
   authinfo is the handle to an object containing authentication
   information. */

dhcpctl_status dhcpctl_connect (dhcpctl_handle *connection,
101
				const char *server_name, int port,
Ted Lemon's avatar
Ted Lemon committed
102 103 104
				dhcpctl_handle authinfo)
{
	isc_result_t status;
105
	dhcpctl_status waitstatus;
Ted Lemon's avatar
Ted Lemon committed
106

107
	status = omapi_generic_new (connection, MDL);
Ted Lemon's avatar
Ted Lemon committed
108 109 110 111 112
	if (status != ISC_R_SUCCESS) {
		return status;
	}

	status = omapi_protocol_connect (*connection, server_name,
Ted Lemon's avatar
Ted Lemon committed
113
					 (unsigned)port, authinfo);
114 115 116
	if (status == ISC_R_SUCCESS)
		return status;
	if (status != ISC_R_INCOMPLETE) {
117
		omapi_object_dereference (connection, MDL);
Ted Lemon's avatar
Ted Lemon committed
118 119 120 121 122
		return status;
	}

	status = omapi_wait_for_completion (*connection, 0);
	if (status != ISC_R_SUCCESS) {
123
		omapi_object_dereference (connection, MDL);
Ted Lemon's avatar
Ted Lemon committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		return status;
	}

	return status;
}

/* dhcpctl_wait_for_completion

   synchronous
   returns zero if the callback completes, a nonzero status if
   there was some problem relating to the wait operation.   The
   status of the queued request will be stored through s, and
   will also be either zero for success or nonzero for some kind
   of failure.    Never returns until completion or until the
   connection to the server is lost.   This performs the same
   function as dhcpctl_set_callback and the subsequent callback,
   for programs that want to do inline execution instead of using
   callbacks. */

dhcpctl_status dhcpctl_wait_for_completion (dhcpctl_handle h,
					    dhcpctl_status *s)
{
146 147 148 149 150 151 152
	isc_result_t status;
	status = omapi_wait_for_completion (h, 0);
	if (status != ISC_R_SUCCESS)
		return status;
	if (h -> type == dhcpctl_remote_type)
		*s = ((dhcpctl_remote_object_t *)h) -> waitstatus;
	return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
}

/* dhcpctl_get_value

   synchronous
   returns zero if the call succeeded, a nonzero status code if
   it didn't. 
   result is the address of an empty data string (initialized
   with bzero or cleared with data_string_forget).   On
   successful completion, the addressed data string will contain
   the value that was fetched.
   dhcpctl_handle refers to some dhcpctl item
   value_name refers to some value related to that item - e.g.,
   for a handle associated with a completed host lookup, value
   could be one of "hardware-address", "dhcp-client-identifier",
   "known" or "client-hostname". */

dhcpctl_status dhcpctl_get_value (dhcpctl_data_string *result,
171
				  dhcpctl_handle h, const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
172 173 174 175
{
	isc_result_t status;
	omapi_value_t *tv = (omapi_value_t *)0;
	omapi_data_string_t *value = (omapi_data_string_t *)0;
176
	unsigned len;
Ted Lemon's avatar
Ted Lemon committed
177 178
	int ip;

Ted Lemon's avatar
Ted Lemon committed
179
	status = omapi_get_value_str (h, (omapi_object_t *)0, value_name, &tv);
Ted Lemon's avatar
Ted Lemon committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
	if (status != ISC_R_SUCCESS)
		return status;

	switch (tv -> value -> type) {
	      case omapi_datatype_int:
		len = sizeof (int);
		break;

	      case omapi_datatype_string:
	      case omapi_datatype_data:
		len = tv -> value -> u.buffer.len;
		break;

	      case omapi_datatype_object:
		len = sizeof (omapi_handle_t);
		break;

	      default:
198
		omapi_typed_data_dereference (&tv -> value, MDL);
Ted Lemon's avatar
Ted Lemon committed
199 200 201
		return ISC_R_UNEXPECTED;
	}

202
	status = omapi_data_string_new (result, len, MDL);
Ted Lemon's avatar
Ted Lemon committed
203
	if (status != ISC_R_SUCCESS) {
204
		omapi_typed_data_dereference (&tv -> value, MDL);
Ted Lemon's avatar
Ted Lemon committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
		return status;
	}

	switch (tv -> value -> type) {
	      case omapi_datatype_int:
		ip = htonl (tv -> value -> u.integer);
		memcpy ((*result) -> value, &ip, sizeof ip);
		break;

	      case omapi_datatype_string:
	      case omapi_datatype_data:
		memcpy ((*result) -> value,
			tv -> value -> u.buffer.value,
			tv -> value -> u.buffer.len);
		break;

	      case omapi_datatype_object:
		ip = htonl (tv -> value -> u.object -> handle);
		memcpy ((*result) -> value, &ip, sizeof ip);
		break;
	}

227
	omapi_value_dereference (&tv, MDL);
Ted Lemon's avatar
Ted Lemon committed
228 229 230 231 232 233 234 235 236
	return ISC_R_SUCCESS;
}

/* dhcpctl_get_boolean

   like dhcpctl_get_value, but more convenient for boolean
   values, since no data_string needs to be dealt with. */

dhcpctl_status dhcpctl_get_boolean (int *result,
237
				    dhcpctl_handle h, const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
238 239 240 241 242 243 244 245 246
{
	isc_result_t status;
	dhcpctl_data_string data = (dhcpctl_data_string)0;
	int rv;
	
	status = dhcpctl_get_value (&data, h, value_name);
	if (status != ISC_R_SUCCESS)
		return status;
	if (data -> len != sizeof rv) {
247
		omapi_data_string_dereference (&data, MDL);
Ted Lemon's avatar
Ted Lemon committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261
		return ISC_R_UNEXPECTED;
	}
	memcpy (&rv, data -> value, sizeof rv);
	*result = ntohl (rv);
	return ISC_R_SUCCESS;
}

/* dhcpctl_set_value

   Sets a value on an object referred to by a dhcpctl_handle.
   The opposite of dhcpctl_get_value.   Does not update the
   server - just sets the value on the handle. */

dhcpctl_status dhcpctl_set_value (dhcpctl_handle h, dhcpctl_data_string value,
262
				  const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
263 264 265 266 267 268
{
	isc_result_t status;
	omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	int len;

269
	status = omapi_data_string_new (&name, strlen (value_name), MDL);
Ted Lemon's avatar
Ted Lemon committed
270 271
	if (status != ISC_R_SUCCESS)
		return status;
Ted Lemon's avatar
Ted Lemon committed
272
	memcpy (name -> value, value_name, strlen (value_name));
Ted Lemon's avatar
Ted Lemon committed
273

274
	status = omapi_typed_data_new (MDL, &tv, omapi_datatype_data,
Ted Lemon's avatar
Ted Lemon committed
275 276
				       value -> len);
	if (status != ISC_R_SUCCESS) {
277
		omapi_data_string_dereference (&name, MDL);
Ted Lemon's avatar
Ted Lemon committed
278 279 280 281 282
		return status;
	}
	memcpy (tv -> u.buffer.value, value -> value, value -> len);

	status = omapi_set_value (h, (omapi_object_t *)0, name, tv);
283 284
	omapi_data_string_dereference (&name, MDL);
	omapi_typed_data_dereference (&tv, MDL);
Ted Lemon's avatar
Ted Lemon committed
285 286 287 288 289 290 291 292 293 294
	return status;
}

/* dhcpctl_set_string_value

   Sets a NUL-terminated ASCII value on an object referred to by
   a dhcpctl_handle.   like dhcpctl_set_value, but saves the
   trouble of creating a data_string for a NUL-terminated string.
   Does not update the server - just sets the value on the handle. */

295 296
dhcpctl_status dhcpctl_set_string_value (dhcpctl_handle h, const char *value,
					 const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
297 298 299 300 301 302
{
	isc_result_t status;
	omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	int len;

303
	status = omapi_data_string_new (&name, strlen (value_name), MDL);
Ted Lemon's avatar
Ted Lemon committed
304 305
	if (status != ISC_R_SUCCESS)
		return status;
Ted Lemon's avatar
Ted Lemon committed
306
	memcpy (name -> value, value_name, strlen (value_name));
Ted Lemon's avatar
Ted Lemon committed
307

308
	status = omapi_typed_data_new (MDL, &tv, omapi_datatype_string, value);
Ted Lemon's avatar
Ted Lemon committed
309
	if (status != ISC_R_SUCCESS) {
310
		omapi_data_string_dereference (&name, MDL);
Ted Lemon's avatar
Ted Lemon committed
311 312 313 314
		return status;
	}

	status = omapi_set_value (h, (omapi_object_t *)0, name, tv);
315 316
	omapi_data_string_dereference (&name, MDL);
	omapi_typed_data_dereference (&tv, MDL);
Ted Lemon's avatar
Ted Lemon committed
317 318 319
	return status;
}

Ted Lemon's avatar
Ted Lemon committed
320 321
/* dhcpctl_set_buffer_value

322 323 324 325
   Sets a value on an object referred to by a dhcpctl_handle.  like
   dhcpctl_set_value, but saves the trouble of creating a data_string
   for string for which we have a buffer and length.  Does not update
   the server - just sets the value on the handle. */
Ted Lemon's avatar
Ted Lemon committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

dhcpctl_status dhcpctl_set_data_value (dhcpctl_handle h,
				       const char *value, unsigned len,
				       const char *value_name)
{
	isc_result_t status;
	omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	unsigned ll;

	ll = strlen (value_name);
	status = omapi_data_string_new (&name, ll, MDL);
	if (status != ISC_R_SUCCESS)
		return status;
	memcpy (name -> value, value_name, ll);

	status = omapi_typed_data_new (MDL, &tv,
				       omapi_datatype_data, len, value);
	if (status != ISC_R_SUCCESS) {
		omapi_data_string_dereference (&name, MDL);
		return status;
	}
	memcpy (tv -> u.buffer.value, value, len);

	status = omapi_set_value (h, (omapi_object_t *)0, name, tv);
	omapi_data_string_dereference (&name, MDL);
	omapi_typed_data_dereference (&tv, MDL);
	return status;
}

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
/* dhcpctl_set_null_value

   Sets a null value on an object referred to by a dhcpctl_handle. */

dhcpctl_status dhcpctl_set_null_value (dhcpctl_handle h,
				       const char *value_name)
{
	isc_result_t status;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	unsigned ll;

	ll = strlen (value_name);
	status = omapi_data_string_new (&name, ll, MDL);
	if (status != ISC_R_SUCCESS)
		return status;
	memcpy (name -> value, value_name, ll);

	status = omapi_set_value (h, (omapi_object_t *)0, name,
				  (omapi_typed_data_t *)0);
	omapi_data_string_dereference (&name, MDL);
	return status;
}

Ted Lemon's avatar
Ted Lemon committed
379 380 381 382 383 384
/* dhcpctl_set_boolean_value

   Sets a boolean value on an object - like dhcpctl_set_value,
   only more convenient for booleans. */

dhcpctl_status dhcpctl_set_boolean_value (dhcpctl_handle h, int value,
385
					  const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
386 387 388 389 390 391
{
	isc_result_t status;
	omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	int len;

392
	status = omapi_data_string_new (&name, strlen (value_name), MDL);
Ted Lemon's avatar
Ted Lemon committed
393 394 395 396
	if (status != ISC_R_SUCCESS)
		return status;
	memcpy (name -> value, value_name, strlen (value_name));

397
	status = omapi_typed_data_new (MDL, &tv, omapi_datatype_int, value);
Ted Lemon's avatar
Ted Lemon committed
398
	if (status != ISC_R_SUCCESS) {
399
		omapi_data_string_dereference (&name, MDL);
Ted Lemon's avatar
Ted Lemon committed
400 401 402 403
		return status;
	}

	status = omapi_set_value (h, (omapi_object_t *)0, name, tv);
404 405
	omapi_data_string_dereference (&name, MDL);
	omapi_typed_data_dereference (&tv, MDL);
Ted Lemon's avatar
Ted Lemon committed
406 407 408 409
	return status;
}

/* dhcpctl_set_int_value
Ted Lemon's avatar
Ted Lemon committed
410 411 412 413

   Sets a boolean value on an object - like dhcpctl_set_value,
   only more convenient for booleans. */

Ted Lemon's avatar
Ted Lemon committed
414
dhcpctl_status dhcpctl_set_int_value (dhcpctl_handle h, int value,
415
				      const char *value_name)
Ted Lemon's avatar
Ted Lemon committed
416 417 418 419 420 421
{
	isc_result_t status;
	omapi_typed_data_t *tv = (omapi_typed_data_t *)0;
	omapi_data_string_t *name = (omapi_data_string_t *)0;
	int len;

422
	status = omapi_data_string_new (&name, strlen (value_name), MDL);
Ted Lemon's avatar
Ted Lemon committed
423 424
	if (status != ISC_R_SUCCESS)
		return status;
Ted Lemon's avatar
Ted Lemon committed
425
	memcpy (name -> value, value_name, strlen (value_name));
Ted Lemon's avatar
Ted Lemon committed
426

427
	status = omapi_typed_data_new (MDL, &tv, omapi_datatype_int, value);
Ted Lemon's avatar
Ted Lemon committed
428
	if (status != ISC_R_SUCCESS) {
429
		omapi_data_string_dereference (&name, MDL);
Ted Lemon's avatar
Ted Lemon committed
430 431 432 433
		return status;
	}

	status = omapi_set_value (h, (omapi_object_t *)0, name, tv);
434 435
	omapi_data_string_dereference (&name, MDL);
	omapi_typed_data_dereference (&tv, MDL);
Ted Lemon's avatar
Ted Lemon committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449
	return status;
}

/* dhcpctl_object_update

   Queues an update on the object referenced by the handle (there
   can't be any other work in progress on the handle).   An
   update means local parameters will be sent to the server. */

dhcpctl_status dhcpctl_object_update (dhcpctl_handle connection,
				      dhcpctl_handle h)
{
	isc_result_t status;
	omapi_object_t *message = (omapi_object_t *)0;
450 451 452 453 454
	dhcpctl_remote_object_t *ro;

	if (h -> type != dhcpctl_remote_type)
		return ISC_R_INVALIDARG;
	ro = (dhcpctl_remote_object_t *)h;
Ted Lemon's avatar
Ted Lemon committed
455

456
	status = omapi_message_new (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
457
	if (status != ISC_R_SUCCESS) {
458
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
459 460
		return status;
	}
Ted Lemon's avatar
Ted Lemon committed
461 462
	status = omapi_set_int_value (message, (omapi_object_t *)0,
				      "op", OMAPI_OP_UPDATE);
Ted Lemon's avatar
Ted Lemon committed
463
	if (status != ISC_R_SUCCESS) {
464
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
465 466
		return status;
	}
467

Ted Lemon's avatar
Ted Lemon committed
468 469
	status = omapi_set_object_value (message, (omapi_object_t *)0,
					 "object", h);
Ted Lemon's avatar
Ted Lemon committed
470
	if (status != ISC_R_SUCCESS) {
471
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
472 473 474
		return status;
	}

475 476 477 478 479 480 481
	status = omapi_set_int_value (message, (omapi_object_t *)0, "handle",
				      (int)(ro -> remote_handle));
	if (status != ISC_R_SUCCESS) {
		omapi_object_dereference (&message, MDL);
		return status;
	}

Ted Lemon's avatar
Ted Lemon committed
482 483 484 485
	omapi_message_register (message);
	status = omapi_protocol_send_message (connection -> outer,
					      (omapi_object_t *)0,
					      message, (omapi_object_t *)0);
486
	omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
487 488 489 490 491 492 493 494 495 496 497 498
	return status;
}

/* Requests a refresh on the object referenced by the handle (there
   can't be any other work in progress on the handle).   A
   refresh means local parameters are updated from the server. */

dhcpctl_status dhcpctl_object_refresh (dhcpctl_handle connection,
				       dhcpctl_handle h)
{
	isc_result_t status;
	omapi_object_t *message = (omapi_object_t *)0;
499 500 501 502 503
	dhcpctl_remote_object_t *ro;

	if (h -> type != dhcpctl_remote_type)
		return ISC_R_INVALIDARG;
	ro = (dhcpctl_remote_object_t *)h;
Ted Lemon's avatar
Ted Lemon committed
504

505
	status = omapi_message_new (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
506
	if (status != ISC_R_SUCCESS) {
507
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
508 509
		return status;
	}
Ted Lemon's avatar
Ted Lemon committed
510 511
	status = omapi_set_int_value (message, (omapi_object_t *)0,
				      "op", OMAPI_OP_REFRESH);
Ted Lemon's avatar
Ted Lemon committed
512
	if (status != ISC_R_SUCCESS) {
513
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
514 515
		return status;
	}
Ted Lemon's avatar
Ted Lemon committed
516
	status = omapi_set_int_value (message, (omapi_object_t *)0,
517
				      "handle", (int)(ro -> remote_handle));
Ted Lemon's avatar
Ted Lemon committed
518
	if (status != ISC_R_SUCCESS) {
519
		omapi_object_dereference (&message, MDL);
520 521 522 523 524 525 526
		return status;
	}

	omapi_message_register (message);
	status = omapi_protocol_send_message (connection -> outer,
					      (omapi_object_t *)0,
					      message, (omapi_object_t *)0);
527 528 529 530 531 532 533 534 535 536 537

	/* We don't want to send the contents of the object down the
	   wire, but we do need to reference it so that we know what
	   to do with the update. */
	status = omapi_set_object_value (message, (omapi_object_t *)0,
					 "object", h);
	if (status != ISC_R_SUCCESS) {
		omapi_object_dereference (&message, MDL);
		return status;
	}

538
	omapi_object_dereference (&message, MDL);
539 540 541
	return status;
}

542
/* Requests the removal of the object referenced by the handle (there
543
   can't be any other work in progress on the handle).   A
544 545
   removal means that all searchable references to the object on the
   server are deleted. */
546

547
dhcpctl_status dhcpctl_object_remove (dhcpctl_handle connection,
548 549 550 551 552 553 554 555 556 557
				      dhcpctl_handle h)
{
	isc_result_t status;
	omapi_object_t *message = (omapi_object_t *)0;
	dhcpctl_remote_object_t *ro;

	if (h -> type != dhcpctl_remote_type)
		return ISC_R_INVALIDARG;
	ro = (dhcpctl_remote_object_t *)h;

558
	status = omapi_message_new (&message, MDL);
559
	if (status != ISC_R_SUCCESS) {
560
		omapi_object_dereference (&message, MDL);
561 562 563 564 565
		return status;
	}
	status = omapi_set_int_value (message, (omapi_object_t *)0,
				      "op", OMAPI_OP_DELETE);
	if (status != ISC_R_SUCCESS) {
566
		omapi_object_dereference (&message, MDL);
567 568 569 570
		return status;
	}

	status = omapi_set_int_value (message, (omapi_object_t *)0, "handle",
571
				      (int)(ro -> remote_handle));
572
	if (status != ISC_R_SUCCESS) {
573
		omapi_object_dereference (&message, MDL);
574 575 576 577 578 579
		return status;
	}

	status = omapi_set_object_value (message, (omapi_object_t *)0,
					 "notify-object", h);
	if (status != ISC_R_SUCCESS) {
580
		omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
581 582 583 584 585 586 587
		return status;
	}

	omapi_message_register (message);
	status = omapi_protocol_send_message (connection -> outer,
					      (omapi_object_t *)0,
					      message, (omapi_object_t *)0);
588
	omapi_object_dereference (&message, MDL);
Ted Lemon's avatar
Ted Lemon committed
589 590 591
	return status;
}

592
isc_result_t dhcpctl_data_string_dereference (dhcpctl_data_string *vp,
593
					      const char *file, int line)
594
{
595
	return omapi_data_string_dereference (vp, file, line);
596
}