message.c 18.2 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 33 34 35 36 37 38 39
	isc_result_t status;

	m = malloc (sizeof *m);
	if (!m)
		return ISC_R_NOMEMORY;
	memset (m, 0, sizeof *m);
	m -> type = omapi_type_message;
	m -> refcnt = 1;

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

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

Ted Lemon's avatar
Ted Lemon committed
61 62 63
	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);
64 65 66
	if (status != ISC_R_SUCCESS)
		return status;

Ted Lemon's avatar
Ted Lemon committed
67 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)
			omapi_typed_data_dereference
Ted Lemon's avatar
Ted Lemon committed
88
				(&m -> authenticator, MDL);
Ted Lemon's avatar
Ted Lemon committed
89
		omapi_typed_data_reference (&m -> authenticator,
Ted Lemon's avatar
Ted Lemon committed
90
					    value, MDL);
Ted Lemon's avatar
Ted Lemon committed
91 92
		return ISC_R_SUCCESS;

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

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

Ted Lemon's avatar
Ted Lemon committed
113 114 115 116 117
	/* 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;
118
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
119 120 121 122 123 124

	/* 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;
125
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
126 127 128 129 130 131

	/* 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;
132
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
133 134 135 136 137 138

	/* 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;
139
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
140 141 142 143 144 145

	/* 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;
146
		return ISC_R_SUCCESS;
Ted Lemon's avatar
Ted Lemon committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
	}

	/* 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"))
172
		return omapi_make_int_value (value, name, (int)m -> authlen,
Ted Lemon's avatar
Ted Lemon committed
173
					     MDL);
Ted Lemon's avatar
Ted Lemon committed
174 175
	else if (!omapi_ds_strcmp (name, "authenticator")) {
		if (m -> authenticator)
Ted Lemon's avatar
Ted Lemon committed
176 177
			return omapi_make_value (value, name,
						 m -> authenticator, MDL);
Ted Lemon's avatar
Ted Lemon committed
178 179 180
		else
			return ISC_R_NOTFOUND;
	} else if (!omapi_ds_strcmp (name, "authid")) {
Ted Lemon's avatar
Ted Lemon committed
181 182
		return omapi_make_int_value (value,
					     name, (int)m -> authid, MDL);
Ted Lemon's avatar
Ted Lemon committed
183
	} else if (!omapi_ds_strcmp (name, "op")) {
Ted Lemon's avatar
Ted Lemon committed
184
		return omapi_make_int_value (value, name, (int)m -> op, MDL);
Ted Lemon's avatar
Ted Lemon committed
185
	} else if (!omapi_ds_strcmp (name, "handle")) {
Ted Lemon's avatar
Ted Lemon committed
186
		return omapi_make_int_value (value, name, (int)m -> h, MDL);
Ted Lemon's avatar
Ted Lemon committed
187
	} else if (!omapi_ds_strcmp (name, "id")) {
Ted Lemon's avatar
Ted Lemon committed
188
		return omapi_make_int_value (value, name, (int)m -> id, MDL);
Ted Lemon's avatar
Ted Lemon committed
189
	} else if (!omapi_ds_strcmp (name, "rid")) {
Ted Lemon's avatar
Ted Lemon committed
190
		return omapi_make_int_value (value, name, (int)m -> rid, MDL);
Ted Lemon's avatar
Ted Lemon committed
191 192 193 194 195 196 197 198 199
	}

	/* 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
200 201
isc_result_t omapi_message_destroy (omapi_object_t *h,
				    const char *file, int line)
Ted Lemon's avatar
Ted Lemon committed
202 203 204 205 206 207
{
	int i;

	omapi_message_object_t *m;
	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
Ted Lemon's avatar
Ted Lemon committed
208
	m = (omapi_message_object *)h;
Ted Lemon's avatar
Ted Lemon committed
209
	if (m -> authenticator) {
Ted Lemon's avatar
Ted Lemon committed
210
		omapi_typed_data_dereference (&m -> authenticator, file, line);
Ted Lemon's avatar
Ted Lemon committed
211 212 213 214 215
	}
	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
216
					  file, line);
Ted Lemon's avatar
Ted Lemon committed
217 218
	if (m -> object)
		omapi_object_dereference ((omapi_object_t **)&m -> object,
Ted Lemon's avatar
Ted Lemon committed
219
					  file, line);
Ted Lemon's avatar
Ted Lemon committed
220 221 222 223
	return ISC_R_SUCCESS;
}

isc_result_t omapi_message_signal_handler (omapi_object_t *h,
224
					   const char *name, va_list ap)
Ted Lemon's avatar
Ted Lemon committed
225
{
Ted Lemon's avatar
Ted Lemon committed
226
	omapi_message_object_t *m;
Ted Lemon's avatar
Ted Lemon committed
227 228
	if (h -> type != omapi_type_message)
		return ISC_R_INVALIDARG;
Ted Lemon's avatar
Ted Lemon committed
229
	m = (omapi_message_object_t *)h;
Ted Lemon's avatar
Ted Lemon committed
230
	
231 232 233 234 235 236 237 238
	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
239
	}
Ted Lemon's avatar
Ted Lemon committed
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 276 277 278 279
	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,
			 (omapi_object_t *)omapi_registered_messages,
Ted Lemon's avatar
Ted Lemon committed
280
			 file, line);
Ted Lemon's avatar
Ted Lemon committed
281 282
		omapi_object_reference
			((omapi_object_t **)&omapi_registered_messages -> prev,
Ted Lemon's avatar
Ted Lemon committed
283
			 (omapi_object_t *)m, file, line);
Ted Lemon's avatar
Ted Lemon committed
284 285
		omapi_object_dereference
			((omapi_object_t **)&omapi_registered_messages,
Ted Lemon's avatar
Ted Lemon committed
286
			 file, line);
Ted Lemon's avatar
Ted Lemon committed
287 288 289
	}
	omapi_object_reference
		((omapi_object_t **)&omapi_registered_messages,
Ted Lemon's avatar
Ted Lemon committed
290
		 (omapi_object_t *)m, file, line);
Ted Lemon's avatar
Ted Lemon committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
	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
310 311
					(omapi_object_t *)m -> next, MDL);
		omapi_object_dereference ((omapi_object_t **)&m -> next, MDL);
Ted Lemon's avatar
Ted Lemon committed
312 313 314 315
	}
	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
316 317
					(omapi_object_t *)m -> prev, MDL);
		omapi_object_dereference ((omapi_object_t **)&m -> prev, MDL);
Ted Lemon's avatar
Ted Lemon committed
318 319
		if (tmp -> next)
			omapi_object_dereference
Ted Lemon's avatar
Ted Lemon committed
320
				((omapi_object_t **)&tmp -> next, MDL);
Ted Lemon's avatar
Ted Lemon committed
321 322 323
		if (n)
			omapi_object_reference
				((omapi_object_t **)&tmp -> next,
Ted Lemon's avatar
Ted Lemon committed
324 325
				 (omapi_object_t *)n, MDL);
		omapi_object_dereference ((omapi_object_t **)&tmp, MDL);
Ted Lemon's avatar
Ted Lemon committed
326 327
	} else {
		omapi_object_dereference
Ted Lemon's avatar
Ted Lemon committed
328
			((omapi_object_t **)&omapi_registered_messages, MDL);
Ted Lemon's avatar
Ted Lemon committed
329 330 331
		if (n)
			omapi_object_reference
				((omapi_object_t **)&omapi_registered_messages,
Ted Lemon's avatar
Ted Lemon committed
332
				 (omapi_object_t *)n, MDL);
Ted Lemon's avatar
Ted Lemon committed
333 334
	}
	if (n)
Ted Lemon's avatar
Ted Lemon committed
335
		omapi_object_dereference ((omapi_object_t **)&n, MDL);
Ted Lemon's avatar
Ted Lemon committed
336 337
	return ISC_R_SUCCESS;
}
338 339 340 341 342

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
343
	omapi_value_t *tv = (omapi_value_t *)0;
344 345
	unsigned long create, update, exclusive;
	unsigned long wsi;
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	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
362 363
	} else
		m = (omapi_message_object_t *)0;
364 365 366 367

	switch (message -> op) {
	      case OMAPI_OP_OPEN:
		if (m) {
Ted Lemon's avatar
Ted Lemon committed
368 369 370
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0, ISC_R_INVALIDARG,
				 message -> id, "OPEN can't be a response");
371 372 373 374
		}

		/* Get the type of the requested object, if one was
		   specified. */
Ted Lemon's avatar
Ted Lemon committed
375
		status = omapi_get_value_str (mo, (omapi_object_t *)0,
376 377 378 379 380 381 382 383 384 385 386 387
					      "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
388
			omapi_value_dereference (&tv, MDL);
389 390

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

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

		/* Get the exclusive flag. */
Ted Lemon's avatar
Ted Lemon committed
423
		status = omapi_get_value_str (mo,
424 425 426
					      (omapi_object_t *)0,
					      "exclusive", &tv);
		if (status == ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
427
			status = omapi_get_int_value (&exclusive, tv -> value);
Ted Lemon's avatar
Ted Lemon committed
428
			omapi_value_dereference (&tv, MDL);
429
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
430 431 432
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
433 434 435 436 437 438 439 440 441
					 "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
442 443 444
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 ISC_R_INVALIDARG, message -> id,
445 446 447 448 449 450 451 452
					 "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
453 454 455
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTIMPLEMENTED, message -> id,
456 457
				 "unsearchable object type");
		}
458 459 460 461 462 463 464

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

468 469 470
		if (status != ISC_R_SUCCESS &&
		    status != ISC_R_NOTFOUND &&
		    status != ISC_R_NOKEYS) {
Ted Lemon's avatar
Ted Lemon committed
471 472 473
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 status, message -> id,
474 475 476 477 478 479
				 "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
480 481 482
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTFOUND, message -> id,
483 484 485 486 487 488 489
				 "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
490
			omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
491 492 493
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_EXISTS, message -> id,
494 495 496 497 498
				 "specified object already exists");
		}

		/* If we're creating the object, do it now. */
		if (!object) {
Ted Lemon's avatar
Ted Lemon committed
499 500 501
			status = omapi_object_create (&object,
						      (omapi_object_t *)0,
						      type);
502
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
503 504 505
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
506 507 508 509 510 511 512
					 "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
513
						      (omapi_object_t *)0,
514
						      message -> object,
Ted Lemon's avatar
Ted Lemon committed
515
						      message -> h);
516
			if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
517
				omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
518 519 520
				return omapi_protocol_send_status
					(po, (omapi_object_t *)0,
					 status, message -> id,
521 522 523 524 525 526 527 528 529 530
					 "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
531
		status = omapi_handle_lookup (&object, message -> h);
532
		if (status != ISC_R_SUCCESS) {
Ted Lemon's avatar
Ted Lemon committed
533 534 535
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 status, message -> id,
536 537 538
				 "no matching handle");
		}
	      send:		
Ted Lemon's avatar
Ted Lemon committed
539 540
		status = omapi_protocol_send_update (po, (omapi_object_t *)0,
						     message -> id, object);
Ted Lemon's avatar
Ted Lemon committed
541
		omapi_object_dereference (&object, MDL);
Ted Lemon's avatar
Ted Lemon committed
542
		return status;
543 544

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

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

	      case OMAPI_OP_NOTIFY:
Ted Lemon's avatar
Ted Lemon committed
584 585 586
		return omapi_protocol_send_status
			(po, (omapi_object_t *)0, ISC_R_NOTIMPLEMENTED,
			 message -> id, "notify not implemented yet");
587

Ted Lemon's avatar
Ted Lemon committed
588 589
	      case OMAPI_OP_STATUS:
		/* The return status of a request. */
590 591 592 593
		if (!m)
			return ISC_R_UNEXPECTED;

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

Ted Lemon's avatar
Ted Lemon committed
606 607 608 609 610
		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
611
			omapi_value_dereference (&tv, MDL);
612
		return ISC_R_SUCCESS;
613 614

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

623
		if (!object -> type -> remove)
624 625 626
			return omapi_protocol_send_status
				(po, (omapi_object_t *)0,
				 ISC_R_NOTIMPLEMENTED, message -> id,
627
				 "no remove method for object");
628

629
		status = (*(object -> type -> remove)) (object,
630
							(omapi_object_t *)0);
Ted Lemon's avatar
Ted Lemon committed
631
		omapi_object_dereference (&object, MDL);
632 633 634 635

		return omapi_protocol_send_status (po, (omapi_object_t *)0,
						   status, message -> id,
						   (char *)0);
636 637 638
	}
	return ISC_R_NOTIMPLEMENTED;
}