1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1996, 1997, 1998, 1999 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
/*
|
1999-11-02 04:01:34 +00:00
|
|
|
* Subroutines for dealing with message objects.
|
1999-10-27 22:24:32 +00:00
|
|
|
*/
|
1999-11-02 04:01:34 +00:00
|
|
|
#include <stddef.h> /* NULL */
|
|
|
|
#include <string.h> /* memset */
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-04 20:04:42 +00:00
|
|
|
#include <omapi/private.h>
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
omapi_message_object_t *omapi_registered_messages;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
2000-01-17 18:02:11 +00:00
|
|
|
omapi_message_new(omapi_object_t **o) {
|
2000-01-06 23:56:51 +00:00
|
|
|
omapi_message_object_t *message = NULL;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_object_t *g;
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
result = omapi_object_create((omapi_object_t **)&message,
|
|
|
|
omapi_type_message, sizeof(*message));
|
2000-01-06 23:56:51 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
g = NULL;
|
2000-01-17 18:02:11 +00:00
|
|
|
result = omapi_object_create(&g, NULL, 0);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&message);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&message->inner, g);
|
|
|
|
OBJECT_REF(&g->outer, message);
|
|
|
|
OBJECT_REF(o, message);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&message);
|
|
|
|
OBJECT_DEREF(&g);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
void
|
|
|
|
omapi_message_register(omapi_object_t *h) {
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_message_object_t *m;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_message);
|
|
|
|
|
|
|
|
m = (omapi_message_object_t *)h;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Already registered?
|
|
|
|
*/
|
|
|
|
REQUIRE(m->prev == NULL && m->next == NULL &&
|
|
|
|
omapi_registered_messages != m);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (omapi_registered_messages != NULL) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&m->next, omapi_registered_messages);
|
|
|
|
OBJECT_REF(&omapi_registered_messages->prev, m);
|
|
|
|
OBJECT_DEREF(&omapi_registered_messages);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-04 20:04:42 +00:00
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&omapi_registered_messages, m);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
static void
|
1999-11-02 04:01:34 +00:00
|
|
|
omapi_message_unregister(omapi_object_t *h) {
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_message_object_t *m;
|
|
|
|
omapi_message_object_t *n;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_message);
|
|
|
|
|
|
|
|
m = (omapi_message_object_t *)h;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Not registered?
|
|
|
|
*/
|
|
|
|
REQUIRE(! (m->prev == NULL && omapi_registered_messages != m));
|
|
|
|
|
|
|
|
n = NULL;
|
|
|
|
if (m->next != NULL) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&n, m->next);
|
|
|
|
OBJECT_DEREF(&m->next);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (m->prev != NULL) {
|
|
|
|
omapi_message_object_t *tmp = NULL;
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&tmp, m->prev);
|
|
|
|
OBJECT_DEREF(&m->prev);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (tmp->next != NULL)
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&tmp->next);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (n != NULL)
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&tmp->next, n);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&tmp);
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-10-27 22:24:32 +00:00
|
|
|
} else {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&omapi_registered_messages);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (n != NULL)
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&omapi_registered_messages, n);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-04 20:04:42 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (n != NULL)
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&n);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t
|
|
|
|
omapi_message_process(omapi_object_t *mo, omapi_object_t *po) {
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_message_object_t *message, *m;
|
1999-11-02 04:01:34 +00:00
|
|
|
omapi_object_t *object = NULL;
|
|
|
|
omapi_value_t *tv = NULL;
|
1999-10-27 22:24:32 +00:00
|
|
|
unsigned long create, update, exclusive;
|
|
|
|
unsigned long wsi;
|
1999-11-02 04:01:34 +00:00
|
|
|
isc_result_t result, waitstatus;
|
1999-10-27 22:24:32 +00:00
|
|
|
omapi_object_type_t *type;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
REQUIRE(mo != NULL && mo->type == omapi_type_message);
|
|
|
|
|
1999-10-27 22:24:32 +00:00
|
|
|
message = (omapi_message_object_t *)mo;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (message->rid != 0) {
|
|
|
|
for (m = omapi_registered_messages; m != NULL; m = m->next)
|
|
|
|
if (m->id == message->rid)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* 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 == NULL)
|
|
|
|
return (ISC_R_NOTFOUND);
|
1999-10-27 22:24:32 +00:00
|
|
|
} else
|
1999-11-02 04:01:34 +00:00
|
|
|
m = NULL;
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
switch (message->op) {
|
1999-10-27 22:24:32 +00:00
|
|
|
case OMAPI_OP_OPEN:
|
1999-11-02 04:01:34 +00:00
|
|
|
if (m != NULL) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
2000-01-06 23:56:51 +00:00
|
|
|
OMAPI_R_INVALIDARG,
|
1999-11-02 04:01:34 +00:00
|
|
|
message->id,
|
|
|
|
"OPEN can't be "
|
|
|
|
"a response"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Get the type of the requested object, if one was
|
|
|
|
* specified.
|
|
|
|
*/
|
|
|
|
result = omapi_get_value_str(mo, NULL, "type", &tv);
|
|
|
|
if (result == ISC_R_SUCCESS &&
|
|
|
|
(tv->value->type == omapi_datatype_data ||
|
|
|
|
tv->value->type == omapi_datatype_string)) {
|
1999-10-27 22:24:32 +00:00
|
|
|
for (type = omapi_object_types;
|
1999-11-02 04:01:34 +00:00
|
|
|
type != NULL; type = type->next)
|
|
|
|
if (omapi_td_strcmp(tv->value, type->name)
|
|
|
|
== 0)
|
1999-10-27 22:24:32 +00:00
|
|
|
break;
|
|
|
|
} else
|
1999-11-02 04:01:34 +00:00
|
|
|
type = NULL;
|
|
|
|
if (tv != NULL)
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the create flag.
|
|
|
|
*/
|
|
|
|
result = omapi_get_value_str(mo, NULL, "create", &tv);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = omapi_get_int_value(&create, tv->value);
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"invalid create flag value"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
create = 0;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Get the update flag.
|
|
|
|
*/
|
|
|
|
result = omapi_get_value_str(mo, NULL, "update", &tv);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = omapi_get_int_value(&update, tv->value);
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"invalid update flag value"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
update = 0;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Get the exclusive flag.
|
|
|
|
*/
|
|
|
|
result = omapi_get_value_str(mo, NULL, "exclusive", &tv);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = omapi_get_int_value(&exclusive, tv->value);
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"invalid exclusive flag value"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
exclusive = 0;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we weren't given a type, look the object up with
|
|
|
|
* the handle.
|
|
|
|
*/
|
|
|
|
if (type == NULL) {
|
|
|
|
if (create != 0) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
2000-01-14 23:10:04 +00:00
|
|
|
OMAPI_R_INVALIDARG,
|
|
|
|
message->id,
|
1999-11-02 04:01:34 +00:00
|
|
|
"type required on create"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
goto refresh;
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If the type doesn't provide a lookup method, we can't
|
|
|
|
* look up the object.
|
|
|
|
*/
|
|
|
|
if (type->lookup == NULL) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_NOTIMPLEMENTED, message->id,
|
|
|
|
"unsearchable object type"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (message->object == NULL) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_NOTFOUND, message->id,
|
|
|
|
"no lookup key specified"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
result = (*(type->lookup))(&object, NULL, message->object);
|
|
|
|
|
|
|
|
if (result != ISC_R_SUCCESS &&
|
|
|
|
result != ISC_R_NOTFOUND &&
|
2000-01-06 23:56:51 +00:00
|
|
|
result != OMAPI_R_NOKEYS) {
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"object lookup failed"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we didn't find the object and we aren't supposed to
|
|
|
|
* create it, return an error.
|
|
|
|
*/
|
|
|
|
if (result == ISC_R_NOTFOUND && create == 0) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_NOTFOUND, message->id,
|
|
|
|
"no object matches specification"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* 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 (result == ISC_R_SUCCESS && create != 0 && exclusive != 0) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&object);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_EXISTS, message->id,
|
|
|
|
"specified object already exists"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we're creating the object, do it now.
|
|
|
|
*/
|
|
|
|
if (object == NULL) {
|
2000-01-17 18:02:11 +00:00
|
|
|
if (type->create == NULL)
|
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
|
|
|
result = (*(type->create))(&object, NULL);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"can't create new object"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* If we're updating it, do so now.
|
|
|
|
*/
|
|
|
|
if (create != 0 || update != 0) {
|
|
|
|
result = omapi_object_update(object, NULL,
|
|
|
|
message->object,
|
|
|
|
message->handle);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&object);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"can't update object"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* Now send the new contents of the object back in response.
|
|
|
|
*/
|
1999-10-27 22:24:32 +00:00
|
|
|
goto send;
|
|
|
|
|
|
|
|
case OMAPI_OP_REFRESH:
|
|
|
|
refresh:
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_handle_lookup(&object, message->handle);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"no matching handle"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
send:
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_protocol_send_update(po, NULL,
|
|
|
|
message->id, object);
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&object);
|
1999-11-02 04:01:34 +00:00
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
case OMAPI_OP_UPDATE:
|
1999-11-02 04:01:34 +00:00
|
|
|
if (m->object != NULL) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_REF(&object, m->object);
|
1999-10-27 22:24:32 +00:00
|
|
|
} else {
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_handle_lookup(&object, message->handle);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"no matching handle"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_object_update(object, NULL, message->object,
|
|
|
|
message->handle);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&object);
|
1999-11-02 04:01:34 +00:00
|
|
|
if (message->rid == 0)
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"can't update object"));
|
|
|
|
if (m != NULL)
|
|
|
|
omapi_signal((omapi_object_t *)m,
|
|
|
|
"status", result, NULL);
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
if (message->rid == 0)
|
|
|
|
result = omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_SUCCESS,
|
|
|
|
message->id, NULL);
|
|
|
|
if (m != NULL)
|
|
|
|
omapi_signal((omapi_object_t *)m, "status",
|
|
|
|
ISC_R_SUCCESS, NULL);
|
|
|
|
return (result);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
case OMAPI_OP_NOTIFY:
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_NOTIMPLEMENTED,
|
|
|
|
message->id,
|
|
|
|
"notify not implemented yet"));
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
case OMAPI_OP_STATUS:
|
1999-11-02 04:01:34 +00:00
|
|
|
/*
|
|
|
|
* The return status of a request.
|
|
|
|
*/
|
|
|
|
if (m == NULL)
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the wait status.
|
|
|
|
*/
|
|
|
|
result = omapi_get_value_str(mo, NULL, "result", &tv);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = omapi_get_int_value(&wsi, tv->value);
|
1999-10-27 22:24:32 +00:00
|
|
|
waitstatus = wsi;
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-10-27 22:24:32 +00:00
|
|
|
waitstatus = ISC_R_UNEXPECTED;
|
|
|
|
} else
|
|
|
|
waitstatus = ISC_R_UNEXPECTED;
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_get_value_str(mo, NULL, "message", &tv);
|
|
|
|
omapi_signal((omapi_object_t *)m, "status", waitstatus, tv);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
2000-01-04 20:04:42 +00:00
|
|
|
omapi_data_valuedereference(&tv,
|
|
|
|
"omapi_message_process");
|
1999-11-02 04:01:34 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
|
|
|
case OMAPI_OP_DELETE:
|
1999-11-02 04:01:34 +00:00
|
|
|
result = omapi_handle_lookup(&object, message->handle);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
result, message->id,
|
|
|
|
"no matching handle"));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
if (object->type->remove == NULL)
|
|
|
|
return (omapi_protocol_send_status(po, NULL,
|
|
|
|
ISC_R_NOTIMPLEMENTED, message->id,
|
|
|
|
"no remove method for object"));
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
result = (*(object->type->remove))(object, NULL);
|
2000-01-17 18:02:11 +00:00
|
|
|
OBJECT_DEREF(&object);
|
1999-10-27 22:24:32 +00:00
|
|
|
|
1999-11-02 04:01:34 +00:00
|
|
|
return (omapi_protocol_send_status(po, NULL, result,
|
|
|
|
message->id, NULL));
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
1999-11-02 04:01:34 +00:00
|
|
|
return (ISC_R_NOTIMPLEMENTED);
|
1999-10-27 22:24:32 +00:00
|
|
|
}
|
2000-01-17 18:02:11 +00:00
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
message_setvalue(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name, omapi_typed_data_t *value)
|
|
|
|
{
|
|
|
|
omapi_message_object_t *m;
|
|
|
|
|
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_message);
|
|
|
|
|
|
|
|
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") == 0) {
|
|
|
|
if (m->authenticator != NULL)
|
|
|
|
omapi_data_dereference(&m->authenticator);
|
|
|
|
omapi_data_reference(&m->authenticator, value,
|
|
|
|
"omapi_message_set_value");
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
} else if (omapi_ds_strcmp(name, "object") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_object);
|
|
|
|
|
|
|
|
if (m->object != NULL)
|
|
|
|
OBJECT_DEREF(&m->object);
|
|
|
|
OBJECT_REF(&m->object, value->u.object);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
} else if (omapi_ds_strcmp(name, "notify-object") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_object);
|
|
|
|
|
|
|
|
if (m->notify_object != NULL)
|
|
|
|
OBJECT_DEREF(&m->notify_object);
|
|
|
|
OBJECT_REF(&m->notify_object, value->u.object);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can set authid, but it has to be an integer.
|
|
|
|
*/
|
|
|
|
} else if (omapi_ds_strcmp(name, "authid") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_int);
|
|
|
|
|
|
|
|
m->authid = value->u.integer;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Can set op, but it has to be an integer.
|
|
|
|
*/
|
|
|
|
} else if (omapi_ds_strcmp(name, "op") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_int);
|
|
|
|
|
|
|
|
m->op = value->u.integer;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle also has to be an integer.
|
|
|
|
*/
|
|
|
|
} else if (omapi_ds_strcmp(name, "handle") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_int);
|
|
|
|
|
|
|
|
m->h = value->u.integer;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transaction ID has to be an integer.
|
|
|
|
*/
|
|
|
|
} else if (omapi_ds_strcmp(name, "id") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_int);
|
|
|
|
|
|
|
|
m->id = value->u.integer;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remote transaction ID has to be an integer.
|
|
|
|
*/
|
|
|
|
} else if (omapi_ds_strcmp(name, "rid") == 0) {
|
|
|
|
INSIST(value != NULL && value->type == omapi_datatype_int);
|
|
|
|
|
|
|
|
m->rid = value->u.integer;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find some inner object that can take the value.
|
|
|
|
*/
|
|
|
|
PASS_SETVALUE(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
message_getvalue(omapi_object_t *h, omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name, omapi_value_t **value)
|
|
|
|
{
|
|
|
|
omapi_message_object_t *m;
|
|
|
|
|
|
|
|
REQUIRE(h != NULL && h->type == omapi_type_message);
|
|
|
|
|
|
|
|
m = (omapi_message_object_t *)h;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for values that are in the message data structure.
|
|
|
|
*/
|
|
|
|
if (omapi_ds_strcmp(name, "authlen") == 0)
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->authlen,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
else if (omapi_ds_strcmp(name, "authenticator") == 0) {
|
|
|
|
if (m->authenticator != NULL)
|
|
|
|
return (omapi_make_value(value, name, m->authenticator,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
else
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
} else if (omapi_ds_strcmp(name, "authid") == 0) {
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->authid,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
} else if (omapi_ds_strcmp(name, "op") == 0) {
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->op,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
} else if (omapi_ds_strcmp(name, "handle") == 0) {
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->handle,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
} else if (omapi_ds_strcmp(name, "id") == 0) {
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->id,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
} else if (omapi_ds_strcmp(name, "rid") == 0) {
|
|
|
|
return (omapi_make_int_value(value, name, (int)m->rid,
|
|
|
|
"omapi_message_get_value"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if there's an inner object that has the value.
|
|
|
|
*/
|
|
|
|
PASS_GETVALUE(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
message_destroy(omapi_object_t *handle) {
|
|
|
|
omapi_message_object_t *message;
|
|
|
|
|
|
|
|
REQUIRE(handle != NULL && handle->type == omapi_type_message);
|
|
|
|
|
|
|
|
message = (omapi_message_object_t *)handle;
|
|
|
|
|
|
|
|
if (message->authenticator != NULL)
|
|
|
|
omapi_data_dereference(&message->authenticator);
|
|
|
|
|
|
|
|
if (message->prev == NULL && omapi_registered_messages != message)
|
|
|
|
omapi_message_unregister(handle);
|
|
|
|
if (message->prev != NULL)
|
|
|
|
OBJECT_DEREF(&message->prev);
|
|
|
|
if (message->next != NULL)
|
|
|
|
OBJECT_DEREF(&message->next);
|
|
|
|
if (message->id_object != NULL)
|
|
|
|
OBJECT_DEREF(&message->id_object);
|
|
|
|
if (message->object != NULL)
|
|
|
|
OBJECT_DEREF(&message->object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
message_signalhandler(omapi_object_t *handle, const char *name,
|
|
|
|
va_list ap) {
|
|
|
|
omapi_message_object_t *message;
|
|
|
|
|
|
|
|
REQUIRE(handle != NULL && handle->type == omapi_type_message);
|
|
|
|
|
|
|
|
message = (omapi_message_object_t *)handle;
|
|
|
|
|
|
|
|
if (strcmp(name, "status") == 0 &&
|
|
|
|
(message->object != NULL || message->notify_object != NULL)) {
|
|
|
|
if (message->object != NULL)
|
|
|
|
return ((message->object->type->signal_handler))
|
|
|
|
(message->object, name, ap);
|
|
|
|
else
|
|
|
|
return ((message->notify_object->type->signal_handler))
|
|
|
|
(message->notify_object, name, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
PASS_SIGNAL(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write all the published values associated with the object through the
|
|
|
|
* specified connection.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
message_stuffvalues(omapi_object_t *connection, omapi_object_t *id,
|
|
|
|
omapi_object_t *message)
|
|
|
|
{
|
|
|
|
REQUIRE(message != NULL && message->type == omapi_type_message);
|
|
|
|
|
|
|
|
PASS_STUFFVALUES(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
omapi_message_init(void) {
|
|
|
|
return (omapi_object_register(&omapi_type_message,
|
|
|
|
"message",
|
|
|
|
message_setvalue,
|
|
|
|
message_getvalue,
|
|
|
|
message_destroy,
|
|
|
|
message_signalhandler,
|
|
|
|
message_stuffvalues,
|
|
|
|
NULL, NULL, NULL));
|
|
|
|
}
|