message.c 18.3 KB
Newer Older
Ted Lemon's avatar
Ted Lemon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* message.c

   Subroutines for dealing with message 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:
 *
 *             http://www.isc.org/isc-license-1.0.html. 
 *
 * 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.
 *
 * Support and other services are available for ISC products - see
 * http://www.isc.org for more information.
 */

23
#include <omapip/omapip_p.h>
Ted Lemon's avatar
Ted Lemon committed
24 25 26

omapi_message_object_t *omapi_registered_messages;

Ted Lemon's avatar
Ted Lemon committed
27
isc_result_t omapi_message_new (omapi_object_t **o, const char *file, int line)
Ted Lemon's avatar
Ted Lemon committed
28 29
{
	omapi_message_object_t *m;
30
	omapi_object_t *g;
Ted Lemon's avatar
Ted Lemon committed
31 32
	isc_result_t status;

33
	m = dmalloc (sizeof *m, file, line);
Ted Lemon's avatar
Ted Lemon committed
34 35 36 37
	if (!m)
		return ISC_R_NOMEMORY;
	memset (m, 0, sizeof *m);
	m -> type = omapi_type_message;
38
	rc_register (file, line, &m, m, m -> refcnt);
Ted Lemon's avatar
Ted Lemon committed
39 40
	m -> refcnt = 1;

41
	g = (omapi_object_t *)0;
Ted Lemon's avatar
Ted Lemon committed
42
	status = omapi_generic_new (&g, file, line);
43
	if (status != ISC_R_SUCCESS) {
44
		dfree (m, file, line);
45 46
		return status;
	}
Ted Lemon's avatar
Ted Lemon committed
47
	status = omapi_object_reference (&m -> inner, g, file, line);
48
	if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
49
		omapi_object_dereference ((omapi_object_t **)&m, file, line);
50
		omapi_object_dereference (&g, file, line);
51 52 53
		return status;
	}
	status = omapi_object_reference (&g -> outer,
Ted Lemon's avatar
Ted Lemon committed
54
					 (omapi_object_t *)m, file, line);
55 56

	if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
57
		omapi_object_dereference ((omapi_object_t **)&m, file, line);
58
		omapi_object_dereference (&g, file, line);
59 60 61
		return status;
	}

Ted Lemon's avatar
Ted Lemon committed
62 63 64
	status = omapi_object_reference (o, (omapi_object_t *)m, file, line);
	omapi_object_dereference ((omapi_object_t **)&m, file, line);
	omapi_object_dereference (&g, file, line);
65 66 67
	if (status != ISC_R_SUCCESS)
		return status;

Ted Lemon's avatar
Ted Lemon committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
	return status;
}

isc_result_t omapi_message_set_value (omapi_object_t *h,
				      omapi_object_t *id,
				      omapi_data_string_t *name,
				      omapi_typed_data_t *value)
{
	omapi_message_object_t *m;
	isc_result_t status;

	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
	m = (omapi_message_object_t *)h;

	/* Can't set authlen. */

	/* Can set authenticator, but the value must be typed data. */
	if (!omapi_ds_strcmp (name, "authenticator")) {
		if (m -> authenticator)
88 89 90
			omapi_typed_data_dereference (&m -> authenticator,
						      MDL);
		omapi_typed_data_reference (&m -> authenticator, value, MDL);
Ted Lemon's avatar
Ted Lemon committed
91 92
		return ISC_R_SUCCESS;

93 94 95 96
	} else if (!omapi_ds_strcmp (name, "object")) {
		if (value -> type != omapi_datatype_object)
			return ISC_R_INVALIDARG;
		if (m -> object)
97 98
			omapi_object_dereference (&m -> object, MDL);
		omapi_object_reference (&m -> object, value -> u.object, MDL);
99 100
		return ISC_R_SUCCESS;

101 102 103 104
	} else if (!omapi_ds_strcmp (name, "notify-object")) {
		if (value -> type != omapi_datatype_object)
			return ISC_R_INVALIDARG;
		if (m -> notify_object)
105
			omapi_object_dereference (&m -> notify_object, MDL);
106
		omapi_object_reference (&m -> notify_object,
Ted Lemon's avatar
Ted Lemon committed
107
					value -> u.object, MDL);
108 109
		return ISC_R_SUCCESS;

Ted Lemon's avatar
Ted Lemon committed
110 111 112 113 114
	/* Can set authid, but it has to be an integer. */
	} else if (!omapi_ds_strcmp (name, "authid")) {
		if (value -> type != omapi_datatype_int)
			return ISC_R_INVALIDARG;
		m -> authid = value -> u.integer;
115
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
116 117 118 119 120 121

	/* Can set op, but it has to be an integer. */
	} else if (!omapi_ds_strcmp (name, "op")) {
		if (value -> type != omapi_datatype_int)
			return ISC_R_INVALIDARG;
		m -> op = value -> u.integer;
122
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
123 124 125 126 127 128

	/* Handle also has to be an integer. */
	} else if (!omapi_ds_strcmp (name, "handle")) {
		if (value -> type != omapi_datatype_int)
			return ISC_R_INVALIDARG;
		m -> h = value -> u.integer;
129
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
130 131 132 133 134 135

	/* Transaction ID has to be an integer. */
	} else if (!omapi_ds_strcmp (name, "id")) {
		if (value -> type != omapi_datatype_int)
			return ISC_R_INVALIDARG;
		m -> id = value -> u.integer;
136
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
137 138 139 140 141 142

	/* Remote transaction ID has to be an integer. */
	} else if (!omapi_ds_strcmp (name, "rid")) {
		if (value -> type != omapi_datatype_int)
			return ISC_R_INVALIDARG;
		m -> rid = value -> u.integer;
143
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
	}

	/* Try to find some inner object that can take the value. */
	if (h -> inner && h -> inner -> type -> set_value) {
		status = ((*(h -> inner -> type -> set_value))
			  (h -> inner, id, name, value));
		if (status == ISC_R_SUCCESS)
			return status;
	}
			  
	return ISC_R_NOTFOUND;
}

isc_result_t omapi_message_get_value (omapi_object_t *h,
				      omapi_object_t *id,
				      omapi_data_string_t *name,
				      omapi_value_t **value)
{
	omapi_message_object_t *m;
	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
	m = (omapi_message_object_t *)h;

	/* Look for values that are in the message data structure. */
	if (!omapi_ds_strcmp (name, "authlen"))
169
		return omapi_make_int_value (value, name, (int)m -> authlen,
Ted Lemon's avatar
Ted Lemon committed
170
					     MDL);
Ted Lemon's avatar
Ted Lemon committed
171 172
	else if (!omapi_ds_strcmp (name, "authenticator")) {
		if (m -> authenticator)
Ted Lemon's avatar
Ted Lemon committed
173 174
			return omapi_make_value (value, name,
						 m -> authenticator, MDL);
Ted Lemon's avatar
Ted Lemon committed
175 176 177
		else
			return ISC_R_NOTFOUND;
	} else if (!omapi_ds_strcmp (name, "authid")) {
Ted Lemon's avatar
Ted Lemon committed
178 179
		return omapi_make_int_value (value,
					     name, (int)m -> authid, MDL);
Ted Lemon's avatar
Ted Lemon committed
180
	} else if (!omapi_ds_strcmp (name, "op")) {
Ted Lemon's avatar
Ted Lemon committed
181
		return omapi_make_int_value (value, name, (int)m -> op, MDL);
Ted Lemon's avatar
Ted Lemon committed
182
	} else if (!omapi_ds_strcmp (name, "handle")) {
Ted Lemon's avatar
Ted Lemon committed
183
		return omapi_make_int_value (value, name, (int)m -> h, MDL);
Ted Lemon's avatar
Ted Lemon committed
184
	} else if (!omapi_ds_strcmp (name, "id")) {
Ted Lemon's avatar
Ted Lemon committed
185
		return omapi_make_int_value (value, name, (int)m -> id, MDL);
Ted Lemon's avatar
Ted Lemon committed
186
	} else if (!omapi_ds_strcmp (name, "rid")) {
Ted Lemon's avatar
Ted Lemon committed
187
		return omapi_make_int_value (value, name, (int)m -> rid, MDL);
Ted Lemon's avatar
Ted Lemon committed
188 189 190 191 192 193 194 195 196
	}

	/* See if there's an inner object that has the value. */
	if (h -> inner && h -> inner -> type -> get_value)
		return (*(h -> inner -> type -> get_value))
			(h -> inner, id, name, value);
	return ISC_R_NOTFOUND;
}

Ted Lemon's avatar
Ted Lemon committed
197 198
isc_result_t omapi_message_destroy (omapi_object_t *h,
				    const char *file, int line)
Ted Lemon's avatar
Ted Lemon committed
199 200 201 202 203 204
{
	int i;

	omapi_message_object_t *m;
	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
205
	m = (omapi_message_object_t *)h;
Ted Lemon's avatar
Ted Lemon committed
206
	if (m -> authenticator) {
Ted Lemon's avatar
Ted Lemon committed
207
		omapi_typed_data_dereference (&m -> authenticator, file, line);
Ted Lemon's avatar
Ted Lemon committed
208 209 210 211 212
	}
	if (!m -> prev && omapi_registered_messages != m)
		omapi_message_unregister (h);
	if (m -> id_object)
		omapi_object_dereference ((omapi_object_t **)&m -> id_object,
Ted Lemon's avatar
Ted Lemon committed
213
					  file, line);
Ted Lemon's avatar
Ted Lemon committed
214 215
	if (m -> object)
		omapi_object_dereference ((omapi_object_t **)&m -> object,
Ted Lemon's avatar
Ted Lemon committed
216
					  file, line);
Ted Lemon's avatar
Ted Lemon committed
217 218 219 220
	return ISC_R_SUCCESS;
}

isc_result_t omapi_message_signal_handler (omapi_object_t *h,
221
					   const char *name, va_list ap)
Ted Lemon's avatar
Ted Lemon committed
222
{
Ted Lemon's avatar
Ted Lemon committed
223
	omapi_message_object_t *m;
Ted Lemon's avatar
Ted Lemon committed
224 225
	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
Ted Lemon's avatar
Ted Lemon committed
226
	m = (omapi_message_object_t *)h;
Ted Lemon's avatar
Ted Lemon committed
227
	
228 229 230 231 232 233 234 235
	if (!strcmp (name, "status") && 
	    (m -> object || m -> notify_object)) {
		if (m -> object)
			return ((m -> object -> type -> signal_handler))
				(m -> object, name, ap);
		else
			return ((m -> notify_object -> type -> signal_handler))
				(m -> notify_object, name, ap);
Ted Lemon's avatar
Ted Lemon committed
236
	}
Ted Lemon's avatar
Ted Lemon committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
	if (h -> inner && h -> inner -> type -> signal_handler)
		return (*(h -> inner -> type -> signal_handler)) (h -> inner,
								  name, ap);
	return ISC_R_NOTFOUND;
}

/* Write all the published values associated with the object through the
   specified connection. */

isc_result_t omapi_message_stuff_values (omapi_object_t *c,
					 omapi_object_t *id,
					 omapi_object_t *m)
{
	int i;

	if (m -> type != omapi_type_message)
		return ISC_R_INVALIDARG;

	if (m -> inner && m -> inner -> type -> stuff_values)
		return (*(m -> inner -> type -> stuff_values)) (c, id,
								m -> inner);
	return ISC_R_SUCCESS;
}

isc_result_t omapi_message_register (omapi_object_t *mo)
{
	omapi_message_object_t *m;

	if (mo -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
	m = (omapi_message_object_t *)mo;
	
	/* Already registered? */
	if (m -> prev || m -> next || omapi_registered_messages == m)
		return ISC_R_INVALIDARG;

	if (omapi_registered_messages) {
		omapi_object_reference
			((omapi_object_t **)&m -> next,
276
			 (omapi_object_t *)omapi_registered_messages, MDL);
Ted Lemon's avatar
Ted Lemon committed
277 278
		omapi_object_reference
			((omapi_object_t **)&omapi_registered_messages -> prev,
279
			 (omapi_object_t *)m, MDL);
Ted Lemon's avatar
Ted Lemon committed
280
		omapi_object_dereference
281
			((omapi_object_t **)&omapi_registered_messages, MDL);
Ted Lemon's avatar
Ted Lemon committed
282 283 284
	}
	omapi_object_reference
		((omapi_object_t **)&omapi_registered_messages,
285
		 (omapi_object_t *)m, MDL);
Ted Lemon's avatar
Ted Lemon committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
	return ISC_R_SUCCESS;;
}

isc_result_t omapi_message_unregister (omapi_object_t *mo)
{
	omapi_message_object_t *m;
	omapi_message_object_t *n;

	if (mo -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
	m = (omapi_message_object_t *)mo;
	
	/* Not registered? */
	if (!m -> prev && omapi_registered_messages != m)
		return ISC_R_INVALIDARG;

	n = (omapi_message_object_t *)0;
	if (m -> next) {
		omapi_object_reference ((omapi_object_t **)&n,
Ted Lemon's avatar
Ted Lemon committed
305 306
					(omapi_object_t *)m -> next, MDL);
		omapi_object_dereference ((omapi_object_t **)&m -> next, MDL);
Ted Lemon's avatar
Ted Lemon committed
307 308 309 310
	}
	if (m -> prev) {
		omapi_message_object_t *tmp = (omapi_message_object_t *)0;
		omapi_object_reference ((omapi_object_t **)&tmp,
Ted Lemon's avatar
Ted Lemon committed
311 312
					(omapi_object_t *)m -> prev, MDL);
		omapi_object_dereference ((omapi_object_t **)&m -> prev, MDL);
Ted Lemon's avatar
Ted Lemon committed
313 314
		if (tmp -> next)
			omapi_object_dereference
Ted Lemon's avatar
Ted Lemon committed
315
				((omapi_object_t **)&tmp -> next, MDL);
Ted Lemon's avatar
Ted Lemon committed
316 317 318
		if (n)
			omapi_object_reference
				((omapi_object_t **)&tmp -> next,
Ted Lemon's avatar
Ted Lemon committed
319 320
				 (omapi_object_t *)n, MDL);
		omapi_object_dereference ((omapi_object_t **)&tmp, MDL);
Ted Lemon's avatar
Ted Lemon committed
321 322
	} else {
		omapi_object_dereference
Ted Lemon's avatar
Ted Lemon committed
323
			((omapi_object_t **)&omapi_registered_messages, MDL);
Ted Lemon's avatar
Ted Lemon committed
324 325 326
		if (n)
			omapi_object_reference
				((omapi_object_t **)&omapi_registered_messages,
Ted Lemon's avatar
Ted Lemon committed
327
				 (omapi_object_t *)n, MDL);
Ted Lemon's avatar
Ted Lemon committed
328 329
	}
	if (n)
Ted Lemon's avatar
Ted Lemon committed
330
		omapi_object_dereference ((omapi_object_t **)&n, MDL);
Ted Lemon's avatar
Ted Lemon committed
331 332
	return ISC_R_SUCCESS;
}
333 334 335 336 337

isc_result_t omapi_message_process (omapi_object_t *mo, omapi_object_t *po)
{
	omapi_message_object_t *message, *m;
	omapi_object_t *object = (omapi_object_t *)0;
Ted Lemon's avatar
Ted Lemon committed
338
	omapi_value_t *tv = (omapi_value_t *)0;
339 340
	unsigned long create, update, exclusive;
	unsigned long wsi;
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
	isc_result_t status, waitstatus;
	omapi_object_type_t *type;

	if (mo -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
	message = (omapi_message_object_t *)mo;

	if (message -> rid) {
		for (m = omapi_registered_messages; m; m = m -> next)
			if (m -> id == message -> rid)
				break;
		/* If we don't have a real message corresponding to
		   the message ID to which this message claims it is a
		   response, something's fishy. */
		if (!m)
			return ISC_R_NOTFOUND;
Ted Lemon's avatar
Ted Lemon committed
357 358
	} else
		m = (omapi_message_object_t *)0;
359 360 361 362

	switch (message -> op) {
	      case OMAPI_OP_OPEN:
		if (m) {
Ted Lemon's avatar
Ted Lemon committed
363 364 365
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0, ISC_R_INVALIDARG,
				 message -> id, "OPEN can't be a response");
366 367 368 369
		}

		/* Get the type of the requested object, if one was
		   specified. */
Ted Lemon's avatar
Ted Lemon committed
370
		status = omapi_get_value_str (mo, (omapi_object_t *)0,
371 372 373 374 375 376 377 378 379 380 381 382
					      "type", &tv);
		if (status == ISC_R_SUCCESS &&
		    (tv -> value -> type == omapi_datatype_data ||
		     tv -> value -> type == omapi_datatype_string)) {
			for (type = omapi_object_types;
			     type; type = type -> next)
				if (!omapi_td_strcmp (tv -> value,
						      type -> name))
					break;
		} else
			type = (omapi_object_type_t *)0;
		if (tv)
Ted Lemon's avatar
Ted Lemon committed
383
			omapi_value_dereference (&tv, MDL);
384 385

		/* Get the create flag. */
Ted Lemon's avatar
Ted Lemon committed
386
		status = omapi_get_value_str (mo,
387 388 389
					      (omapi_object_t *)0,
					      "create", &tv);
		if (status == ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
390
			status = omapi_get_int_value (&create, tv -> value);
Ted Lemon's avatar
Ted Lemon committed
391
			omapi_value_dereference (&tv, MDL);
392
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
393 394 395
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
396 397 398 399 400 401
					 "invalid create flag value");
			}
		} else
			create = 0;

		/* Get the update flag. */
Ted Lemon's avatar
Ted Lemon committed
402
		status = omapi_get_value_str (mo,
403 404 405
					      (omapi_object_t *)0,
					      "update", &tv);
		if (status == ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
406
			status = omapi_get_int_value (&update, tv -> value);
Ted Lemon's avatar
Ted Lemon committed
407
			omapi_value_dereference (&tv, MDL);
408
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
409 410 411
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
412 413 414 415 416 417
					 "invalid update flag value");
			}
		} else
			update = 0;

		/* Get the exclusive flag. */
Ted Lemon's avatar
Ted Lemon committed
418
		status = omapi_get_value_str (mo,
419 420 421
					      (omapi_object_t *)0,
					      "exclusive", &tv);
		if (status == ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
422
			status = omapi_get_int_value (&exclusive, tv -> value);
Ted Lemon's avatar
Ted Lemon committed
423
			omapi_value_dereference (&tv, MDL);
424
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
425 426 427
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
428 429 430 431 432 433 434 435 436
					 "invalid exclusive flag value");
			}
		} else
			exclusive = 0;

		/* If we weren't given a type, look the object up with
                   the handle. */
		if (!type) {
			if (create) {
Ted Lemon's avatar
Ted Lemon committed
437 438 439
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 ISC_R_INVALIDARG, message -> id,
440 441 442 443 444 445 446 447
					 "type required on create");
			}
			goto refresh;
		}

		/* If the type doesn't provide a lookup method, we can't
		   look up the object. */
		if (!type -> lookup) {
Ted Lemon's avatar
Ted Lemon committed
448 449 450
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTIMPLEMENTED, message -> id,
451 452
				 "unsearchable object type");
		}
453 454 455 456 457 458 459

		if (!message -> object) {
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTFOUND, message -> id,
				 "no lookup key specified");
		}
460 461 462
		status = (*(type -> lookup)) (&object, (omapi_object_t *)0,
					      message -> object);

463 464 465
		if (status != ISC_R_SUCCESS &&
		    status != ISC_R_NOTFOUND &&
		    status != ISC_R_NOKEYS) {
Ted Lemon's avatar
Ted Lemon committed
466 467 468
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 status, message -> id,
469 470 471 472 473 474
				 "object lookup failed");
		}

		/* If we didn't find the object and we aren't supposed to
		   create it, return an error. */
		if (status == ISC_R_NOTFOUND && !create) {
Ted Lemon's avatar
Ted Lemon committed
475 476 477
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTFOUND, message -> id,
478 479 480 481 482 483 484
				 "no object matches specification");
		}			

		/* If we found an object, we're supposed to be creating an
		   object, and we're not supposed to have found an object,
		   return an error. */
		if (status == ISC_R_SUCCESS && create && exclusive) {
Ted Lemon's avatar
Ted Lemon committed
485
			omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
486 487 488
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_EXISTS, message -> id,
489 490 491 492 493
				 "specified object already exists");
		}

		/* If we're creating the object, do it now. */
		if (!object) {
Ted Lemon's avatar
Ted Lemon committed
494 495 496
			status = omapi_object_create (&object,
						      (omapi_object_t *)0,
						      type);
497
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
498 499 500
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
501 502 503 504 505 506 507
					 "can't create new object");
			}
		}

		/* If we're updating it, do so now. */
		if (create || update) {
			status = omapi_object_update (object,
Ted Lemon's avatar
Ted Lemon committed
508
						      (omapi_object_t *)0,
509
						      message -> object,
Ted Lemon's avatar
Ted Lemon committed
510
						      message -> h);
511
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
512
				omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
513 514 515
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
516 517 518 519 520 521 522 523 524 525
					 "can't update object");
			}
		}
		
		/* Now send the new contents of the object back in
		   response. */
		goto send;

	      case OMAPI_OP_REFRESH:
	      refresh:
Ted Lemon's avatar
Ted Lemon committed
526
		status = omapi_handle_lookup (&object, message -> h);
527
		if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
528 529 530
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 status, message -> id,
531 532 533
				 "no matching handle");
		}
	      send:		
Ted Lemon's avatar
Ted Lemon committed
534 535
		status = omapi_protocol_send_update (po, (omapi_object_t *)0,
						     message -> id, object);
Ted Lemon's avatar
Ted Lemon committed
536
		omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
537
		return status;
538 539

	      case OMAPI_OP_UPDATE:
Ted Lemon's avatar
Ted Lemon committed
540
		if (m -> object) {
Ted Lemon's avatar
Ted Lemon committed
541
			omapi_object_reference (&object, m -> object, MDL);
542
		} else {
Ted Lemon's avatar
Ted Lemon committed
543
			status = omapi_handle_lookup (&object, message -> h);
544
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
545 546 547
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
548 549 550 551
					 "no matching handle");
			}
		}

Ted Lemon's avatar
Ted Lemon committed
552
		status = omapi_object_update (object, (omapi_object_t *)0,
553
					      message -> object,
Ted Lemon's avatar
Ted Lemon committed
554
					      message -> h);
555
		if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
556
			omapi_object_dereference (&object, MDL);
557
			if (!message -> rid)
Ted Lemon's avatar
Ted Lemon committed
558 559 560
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
561 562 563
					 "can't update object");
			if (m)
				omapi_signal ((omapi_object_t *)m,
Ted Lemon's avatar
Ted Lemon committed
564 565
					      "status", status,
					      (omapi_typed_data_t *)0);
566 567 568
			return ISC_R_SUCCESS;
		}
		if (!message -> rid)
Ted Lemon's avatar
Ted Lemon committed
569 570 571
			status = omapi_protocol_send_status
				(po, (omapi_object_t *)0, ISC_R_SUCCESS,
				 message -> id, (char *)0);
572 573
		if (m)
			omapi_signal ((omapi_object_t *)m,
Ted Lemon's avatar
Ted Lemon committed
574 575 576
				      "status", ISC_R_SUCCESS,
				      (omapi_typed_data_t *)0);
		return status;
577 578

	      case OMAPI_OP_NOTIFY:
Ted Lemon's avatar
Ted Lemon committed
579 580 581
		return omapi_protocol_send_status
			(po, (omapi_object_t *)0, ISC_R_NOTIMPLEMENTED,
			 message -> id, "notify not implemented yet");
582

Ted Lemon's avatar
Ted Lemon committed
583 584
	      case OMAPI_OP_STATUS:
		/* The return status of a request. */
585 586 587 588
		if (!m)
			return ISC_R_UNEXPECTED;

		/* Get the wait status. */
Ted Lemon's avatar
Ted Lemon committed
589
		status = omapi_get_value_str (mo,
590 591 592
					      (omapi_object_t *)0,
					      "result", &tv);
		if (status == ISC_R_SUCCESS) {
593 594
			status = omapi_get_int_value (&wsi, tv -> value);
			waitstatus = wsi;
Ted Lemon's avatar
Ted Lemon committed
595
			omapi_value_dereference (&tv, MDL);
596 597 598 599 600
			if (status != ISC_R_SUCCESS)
				waitstatus = ISC_R_UNEXPECTED;
		} else
			waitstatus = ISC_R_UNEXPECTED;

Ted Lemon's avatar
Ted Lemon committed
601 602 603 604 605
		status = omapi_get_value_str (mo,
					      (omapi_object_t *)0,
					      "message", &tv);
		omapi_signal ((omapi_object_t *)m, "status", waitstatus, tv);
		if (status == ISC_R_SUCCESS)
Ted Lemon's avatar
Ted Lemon committed
606
			omapi_value_dereference (&tv, MDL);
607
		return ISC_R_SUCCESS;
608 609

	      case OMAPI_OP_DELETE:
Ted Lemon's avatar
Ted Lemon committed
610
		status = omapi_handle_lookup (&object, message -> h);
611 612 613 614 615 616 617
		if (status != ISC_R_SUCCESS) {
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 status, message -> id,
				 "no matching handle");
		}

618
		if (!object -> type -> remove)
619 620 621
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTIMPLEMENTED, message -> id,
622
				 "no remove method for object");
623

624
		status = (*(object -> type -> remove)) (object,
625
							(omapi_object_t *)0);
Ted Lemon's avatar
Ted Lemon committed
626
		omapi_object_dereference (&object, MDL);
627 628 629 630

		return omapi_protocol_send_status (po, (omapi_object_t *)0,
						   status, message -> id,
						   (char *)0);
631 632 633
	}
	return ISC_R_NOTIMPLEMENTED;
}