checkpoint

This commit is contained in:
David Lawrence 2000-01-06 03:36:32 +00:00
parent a928d61917
commit 3eab41102f
15 changed files with 802 additions and 607 deletions

View file

@ -31,14 +31,14 @@ CDEFINES =
CWARNINGS =
# Alphabetically
OBJS = buffer.@O@ connection.@O@ data.@O@ dispatch.@O@ generic.@O@ \
handle.@O@ listener.@O@ message.@O@ object.@O@ protocol.@O@ \
support.@O@ version.@O@
OBJS = connection.@O@ data.@O@ dispatch.@O@ generic.@O@ \
handle.@O@ lib.@O@ listener.@O@ message.@O@ object.@O@ \
protocol.@O@ result.@O@ support.@O@ version.@O@
# Alphabetically
SRCS = buffer.c connection.c data.c dispatch.c generic.c \
handle.c listener.c message.c object.c protocol.c \
support.c version.c
SRCS = connection.c data.c dispatch.c generic.c \
handle.c lib.c listener.c message.c object.c \
protocol.c result.c support.c version.c
LIBS = @LIBS@

View file

@ -1,333 +0,0 @@
/*
* 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.
*/
/* $Id: buffer.c,v 1.3 2000/01/04 20:04:37 tale Exp $ */
/* Principal Author: Ted Lemon */
/*
* Buffer access functions for the object management protocol.
*/
#include <errno.h>
#include <stddef.h> /* NULL */
#include <unistd.h> /* read */
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/socket.h>
#include <omapi/private.h>
void
omapi_connection_read(isc_task_t *task, isc_event_t *event) {
isc_buffer_t *buffer;
isc_socket_t *socket;
isc_socketevent_t *socketevent;
omapi_connection_object_t *connection;
socket = event->sender;
socketevent = (isc_socketevent_t *)event;
connection = event->arg;
buffer = ISC_LIST_HEAD(socketevent->bufferlist);
if (socketevent->result != ISC_R_SUCCESS) {
/*
* Abandon this socket.
*/
isc_socket_detach(&socket);
/* XXXDCL nope, not right at all */
ISC_LIST_UNLINK(socketevent->bufferlist, buffer, link);
isc_buffer_free(&buffer);
isc_event_free(&event);
isc_task_shutdown(task);
return;
}
connection->in_bytes += socketevent->n;
/* XXXDCL more screwage */
while (buffer != NULL) {
ISC_LIST_APPEND(connection->input_buffers, buffer, link);
buffer = ISC_LIST_NEXT(buffer, link);
}
while (connection->bytes_needed <= connection->in_bytes)
omapi_signal(event->arg, "ready", connection);
/*
* Queue up another recv task.
*/
isc_socket_recvv(socket, &connection->input_buffers,
connection->bytes_needed - connection->in_bytes,
task, omapi_connection_read, connection);
isc_event_free(&event);
}
void
omapi_connection_written(isc_task_t *task, isc_event_t *event) {
isc_buffer_t *buffer;
isc_socket_t *socket;
isc_socketevent_t *socketevent;
omapi_connection_object_t *connection;
socket = event->sender;
socketevent = (isc_socketevent_t *)event;
connection = event->arg;
/* XXXDCL more screwage */
buffer = ISC_LIST_HEAD(socketevent->bufferlist);
while (buffer != NULL) {
ISC_LIST_ENQUEUE(connection->output_buffers, buffer, link);
buffer = ISC_LIST_NEXT(buffer, link);
}
buffer = ISC_LIST_HEAD(connection->output_buffers);
if (socketevent->result != ISC_R_SUCCESS) {
/*
* Abandon this socket.
*/
isc_socket_detach(&socket);
/* XXXDCL nope, not right at all */
ISC_LIST_UNLINK(connection->output_buffers, buffer, link);
isc_buffer_free(&buffer);
isc_event_free(&event);
isc_task_shutdown(task);
OBJECT_DEREF(&connection, "omapi_connection_written");
return;
}
connection->out_bytes -= socketevent->n;
isc_buffer_compact(buffer);
if (connection->out_bytes > 0)
isc_socket_sendv(socket, &connection->output_buffers, task,
omapi_connection_written, connection);
return;
}
/*
* Put some bytes into the output buffer for a connection.
*/
isc_result_t
omapi_connection_copyin(omapi_object_t *h, unsigned char *bufp,
unsigned int len)
{
omapi_connection_object_t *connection;
isc_buffer_t *obuffer;
REQUIRE(h != NULL && h->type == omapi_type_connection);
connection = (omapi_connection_object_t *)h;
obuffer = ISC_LIST_HEAD(connection->output_buffers);
/* XXXDCL check for space first */
isc_buffer_putmem(obuffer, bufp, len);
connection->out_bytes += len;
return (ISC_R_SUCCESS);
}
/*
* Copy some bytes from the input buffer, and advance the input buffer
* pointer beyond the bytes copied out.
*/
isc_result_t
omapi_connection_copyout(unsigned char *buf, omapi_object_t *h,
unsigned int size)
{
omapi_connection_object_t *connection;
isc_buffer_t *ibuffer;
REQUIRE(h != NULL && h->type == omapi_type_connection);
connection = (omapi_connection_object_t *)h;
if (size > connection->in_bytes)
return (ISC_R_NOMORE);
ibuffer = ISC_LIST_HEAD(connection->input_buffers);
(void)memcpy(buf, ibuffer->base, size);
isc_buffer_forward(ibuffer, size);
isc_buffer_compact(ibuffer);
connection->in_bytes -= size;
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_get_uint32(omapi_object_t *c, isc_uint32_t *value) {
isc_uint32_t inbuf;
isc_result_t result;
result = omapi_connection_copyout((unsigned char *)&inbuf, c,
sizeof(inbuf));
if (result != ISC_R_SUCCESS)
return (result);
*value = ntohl(inbuf);
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_put_uint32(omapi_object_t *c, isc_uint32_t value) {
isc_uint32_t inbuf;
inbuf = htonl(value);
return (omapi_connection_copyin(c, (unsigned char *)&inbuf,
sizeof(inbuf)));
}
isc_result_t
omapi_connection_get_uint16(omapi_object_t *c, isc_uint16_t *value) {
isc_uint16_t inbuf;
isc_result_t result;
result = omapi_connection_copyout((unsigned char *)&inbuf, c,
sizeof(inbuf));
if (result != ISC_R_SUCCESS)
return (result);
*value = ntohs (inbuf);
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_put_uint16(omapi_object_t *c, isc_uint32_t value) {
isc_uint16_t inbuf;
REQUIRE(value < 65536);
inbuf = htons((isc_uint16_t)value);
return (omapi_connection_copyin(c, (unsigned char *)&inbuf,
sizeof(inbuf)));
}
isc_result_t
omapi_connection_write_typed_data(omapi_object_t *c, omapi_typed_data_t *data)
{
isc_result_t result;
omapi_handle_t handle;
REQUIRE(data != NULL &&
(data->type == omapi_datatype_int ||
data->type == omapi_datatype_string ||
data->type == omapi_datatype_data ||
data->type == omapi_datatype_object));
switch (data->type) {
case omapi_datatype_int:
result = omapi_connection_put_uint32(c, sizeof(isc_uint32_t));
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_put_uint32(c, ((isc_uint32_t)
(data->u.integer))));
case omapi_datatype_string:
case omapi_datatype_data:
result = omapi_connection_put_uint32(c, data->u.buffer.len);
if (result != ISC_R_SUCCESS)
return (result);
if (data->u.buffer.len > 0)
return (omapi_connection_copyin(c,
data->u.buffer.value,
data->u.buffer.len));
return (ISC_R_SUCCESS);
case omapi_datatype_object:
if (data->u.object != NULL) {
result = omapi_object_handle(&handle, data->u.object);
if (result != ISC_R_SUCCESS)
return (result);
} else
handle = 0;
result = omapi_connection_put_uint32(c, sizeof(handle));
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_put_uint32(c, handle));
}
UNEXPECTED_ERROR(__FILE__, __LINE__,
"unknown type in omapi_connection_write_typed_data: "
"%d\n", data->type);
return (ISC_R_UNEXPECTED);
}
isc_result_t
omapi_connection_put_name(omapi_object_t *c, const char *name) {
isc_result_t result;
unsigned int len = strlen(name);
if (len > 65535)
/* XXXDCL better error? */
return (ISC_R_FAILURE);
result = omapi_connection_put_uint16(c, len);
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_copyin(c, (char *)name, len));
}
isc_result_t
omapi_connection_put_string(omapi_object_t *c, const char *string) {
isc_result_t result;
unsigned int len;
if (string != NULL)
len = strlen(string);
else
len = 0;
result = omapi_connection_put_uint32(c, len);
if (result == ISC_R_SUCCESS && len > 0)
result = omapi_connection_copyin(c, (char *)string, len);
return (result);
}
isc_result_t
omapi_connection_put_handle(omapi_object_t *c, omapi_object_t *h) {
isc_result_t result;
omapi_handle_t handle;
if (h != NULL) {
result = omapi_object_handle(&handle, h);
if (result != ISC_R_SUCCESS)
return (result);
} else
handle = 0; /* The null handle. */
result = omapi_connection_put_uint32(c, sizeof(handle));
if (result == ISC_R_SUCCESS)
result = omapi_connection_put_uint32(c, handle);
return (result);
}

View file

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: connection.c,v 1.3 2000/01/04 20:04:37 tale Exp $ */
/* $Id: connection.c,v 1.4 2000/01/06 03:36:27 tale Exp $ */
/* Principal Author: Ted Lemon */
@ -23,16 +23,22 @@
* Subroutines for dealing with connections.
*/
#include <errno.h>
#include <fcntl.h> /* F_SETFL, O_NONBLOCK */
#include <stddef.h> /* NULL */
#include <string.h> /* memset */
#include <unistd.h> /* close */
#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/netdb.h>
#include <omapi/private.h>
/*
* Forward declarations.
*/
void
connection_send(omapi_connection_object_t *connection);
/*
* Swiped from bin/tests/sdig.c.
*/
@ -71,39 +77,87 @@ get_address(const char *hostname, in_port_t port, isc_sockaddr_t *sockaddr) {
return (ISC_R_SUCCESS);
}
/*
* This is the function that is called when a CONNECT event is posted on
* the socket as a result of isc_socket_connect.
*/
static void
omapi_connection_connect(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
isc_socket_connev_t *connect_event;
omapi_connection_object_t *connection;
abandon_connection(omapi_connection_object_t *connection,
isc_event_t *event, isc_result_t result)
{
isc_buffer_t *buffer;
ENSURE(event->sender == connection->socket);
connect_event = (isc_socket_connev_t *)event;
if (connect_event->result != ISC_R_SUCCESS) {
isc_socket_detach(&connection->socket);
if (event != NULL)
isc_event_free(&event);
isc_task_shutdown(task);
if (connection->events_pending > 0) {
/*
* The only time CANCELED results should be generated is
* because this function already called isc_socket_cancel.
* If this isn't a CANCELED result, then the isc_socket_cancel
* needs to be done.
*/
if (result != ISC_R_CANCELED)
isc_socket_cancel(connection->socket, NULL,
ISC_SOCKCANCEL_ALL);
/*
* Technically not yet, but the end result is the same.
*/
connection->state = omapi_connection_unconnected;
return;
}
while ((buffer = ISC_LIST_HEAD(connection->input_buffers)) != NULL) {
ISC_LIST_UNLINK(connection->input_buffers, buffer, link);
isc_buffer_free(&buffer);
}
while ((buffer = ISC_LIST_HEAD(connection->output_buffers)) != NULL) {
ISC_LIST_UNLINK(connection->output_buffers, buffer, link);
isc_buffer_free(&buffer);
}
isc_task_destroy(&connection->task);
isc_socket_detach(&connection->socket);
OBJECT_DEREF(&connection, "abandon_connection");
return;
}
/*
* This is the function that is called when a connect event is posted on
* the socket as a result of isc_socket_connect.
*/
static void
connect_done(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
isc_socket_t *socket;
isc_socket_connev_t *connectevent;
omapi_connection_object_t *connection;
socket = event->sender;
connectevent = (isc_socket_connev_t *)event;
connection = event->arg;
ENSURE(socket == connection->socket && task == connection->task);
connection->events_pending--;
if (connectevent->result != ISC_R_SUCCESS) {
abandon_connection(connection, event, connectevent->result);
return;
}
result = isc_socket_getpeername(connection->socket,
&connection->remote_addr);
if (result != ISC_R_SUCCESS) {
OBJECT_DEREF(&connection, "omapi_connection_connect");
abandon_connection(connection, event, connectevent->result);
return;
}
result = isc_socket_getsockname(connection->socket,
&connection->local_addr);
if (result != ISC_R_SUCCESS) {
OBJECT_DEREF(&connection, "omapi_connection_connect");
abandon_connection(connection, event, connectevent->result);
return;
}
@ -114,20 +168,132 @@ omapi_connection_connect(isc_task_t *task, isc_event_t *event) {
return;
}
/*
* This is the function that is called when a recv event is posted on
* the socket as a result of isc_socket_recv*.
*/
static void
recv_done(isc_task_t *task, isc_event_t *event) {
isc_buffer_t *buffer;
isc_socket_t *socket;
isc_socketevent_t *socketevent;
omapi_connection_object_t *connection;
socket = event->sender;
socketevent = (isc_socketevent_t *)event;
connection = event->arg;
ENSURE(socket == connection->socket && task == connection->task);
connection->events_pending--;
/*
* Restore the input buffers to the connection object.
*/
for (buffer = ISC_LIST_HEAD(socketevent->bufferlist);
buffer != NULL;
buffer = ISC_LIST_NEXT(buffer, link))
ISC_LIST_APPEND(connection->input_buffers, buffer, link);
if (socketevent->result != ISC_R_SUCCESS) {
abandon_connection(connection, event, socketevent->result);
return;
}
connection->in_bytes += socketevent->n;
while (connection->bytes_needed <= connection->in_bytes &&
connection->bytes_needed > 0)
omapi_signal(event->arg, "ready", connection);
#if 0
/*
* XXXDCL it may be the case that another recv task should be queued,
* but I haven't thought it through fully.
*/
if (connection->bytes_needed > 0)
isc_socket_recvv(socket, &connection->input_buffers,
connection->bytes_needed -
connection->in_bytes,
task, recv_done, connection);
#endif
isc_event_free(&event);
}
/*
* This is the function that is called when a send event is posted on
* the socket as a result of isc_socket_send*.
*/
static void
send_done(isc_task_t *task, isc_event_t *event) {
isc_buffer_t *buffer;
isc_socket_t *socket;
isc_socketevent_t *socketevent;
omapi_connection_object_t *connection;
socket = event->sender;
socketevent = (isc_socketevent_t *)event;
connection = event->arg;
ENSURE(socket == connection->socket && task == connection->task);
connection->events_pending--;
/*
* Restore the bufferlist into the connection object.
*/
for (buffer = ISC_LIST_HEAD(socketevent->bufferlist);
buffer != NULL;
buffer = ISC_LIST_NEXT(buffer, link))
ISC_LIST_APPEND(connection->output_buffers, buffer, link);
if (socketevent->result != ISC_R_SUCCESS) {
abandon_connection(connection, event, socketevent->result);
return;
}
connection->out_bytes -= socketevent->n;
/*
* If there is still data to be written, another send event is queued.
*/
connection_send(connection);
isc_event_free(&event);
return;
}
void
connection_send(omapi_connection_object_t *connection) {
REQUIRE(connection != NULL &&
connection->type == omapi_type_connection);
if (connection->out_bytes > 0) {
ENSURE(!ISC_LIST_EMPTY(connection->output_buffers));
isc_socket_sendv(connection->socket,
&connection->output_buffers, connection->task,
send_done, connection);
connection->events_pending++;
}
}
/*
* Make an outgoing connection to an OMAPI server.
*/
isc_result_t
omapi_connection_toserver(omapi_object_t *c, const char *server_name, int port)
omapi_connection_toserver(omapi_object_t *protocol, const char *server_name,
int port)
{
isc_result_t result;
isc_buffer_t *ibuffer, *obuffer;
isc_task_t *task;
isc_sockaddr_t sockaddr;
omapi_connection_object_t *obj;
#if 0 /*XXXDCL*/
int flag;
#endif
isc_buffer_t *ibuffer = NULL, *obuffer = NULL;
isc_task_t *task = NULL;
omapi_connection_object_t *connection = NULL;
result = get_address(server_name, port, &sockaddr);
if (result != ISC_R_SUCCESS)
@ -136,82 +302,148 @@ omapi_connection_toserver(omapi_object_t *c, const char *server_name, int port)
/*
* Prepare the task that will wait for the connection to be made.
*/
task = NULL;
result = isc_task_create(omapi_taskmgr, NULL, 0, &task);
if (result != ISC_R_SUCCESS)
return (result);
ibuffer = NULL;
result = isc_buffer_allocate(omapi_mctx, &ibuffer, OMAPI_BUFFER_SIZE,
ISC_BUFFERTYPE_BINARY);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
isc_task_destroy(&task);
return (result);
}
obuffer = NULL;
result = isc_buffer_allocate(omapi_mctx, &obuffer, OMAPI_BUFFER_SIZE,
ISC_BUFFERTYPE_BINARY);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
isc_buffer_free(&ibuffer);
isc_task_destroy(&task);
return (result);
/*
* XXXDCL on errors I need to also blast the task and buffers.
*/
}
/*
* Create a new connection object.
*/
obj = isc_mem_get(omapi_mctx, sizeof(*obj));
if (obj == NULL)
return (ISC_R_NOMEMORY);
memset(obj, 0, sizeof(*obj));
obj->refcnt = 1;
obj->task = task;
obj->type = omapi_type_connection;
result = omapi_object_new((omapi_object_t **)&connection,
omapi_type_connection, sizeof(*connection));
if (result != ISC_R_SUCCESS) {
isc_buffer_free(&obuffer);
isc_buffer_free(&ibuffer);
isc_task_destroy(&task);
return (result);
}
connection->task = task;
ISC_LIST_INIT(obj->input_buffers);
ISC_LIST_APPEND(obj->input_buffers, ibuffer, link);
ISC_LIST_INIT(obj->output_buffers);
ISC_LIST_APPEND(obj->output_buffers, obuffer, link);
ISC_LIST_INIT(connection->input_buffers);
ISC_LIST_APPEND(connection->input_buffers, ibuffer, link);
ISC_LIST_INIT(connection->output_buffers);
ISC_LIST_APPEND(connection->output_buffers, obuffer, link);
/*
* Tie the new connection object to the protocol object.
*/
OBJECT_REF(&c->outer, obj, "omapi_connection_toserver");
OBJECT_REF(&obj->inner, c, "omapi_connection_toserver");
OBJECT_REF(&protocol->outer, connection, "omapi_connection_toserver");
OBJECT_REF(&connection->inner, protocol, "omapi_connection_toserver");
/*
* Create a socket on which to communicate.
*/
result = isc_socket_create(omapi_socketmgr, isc_sockaddr_pf(&sockaddr),
isc_sockettype_tcp, &obj->socket);
isc_sockettype_tcp, &connection->socket);
if (result != ISC_R_SUCCESS) {
/* XXXDCL this call and later will not free the connection obj
* because it has two refcnts, one for existing plus one
* for the tie to h->outer. This does not seem right to me.
*/
OBJECT_DEREF(&obj, "omapi_connection_toserver");
OBJECT_DEREF(&connection, "omapi_connection_toserver");
isc_buffer_free(&obuffer);
isc_buffer_free(&ibuffer);
isc_task_destroy(&task);
return (result);
}
#if 0 /*XXXDCL*/
#if 0
/*
* Set the SO_REUSEADDR flag (this should not fail).
* XXXDCL is this needed? isc_socket_* does not support it.
*/
flag = 1;
if (setsockopt(obj->socket, SOL_SOCKET, SO_REUSEADDR,
if (setsockopt(connection->socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&flag, sizeof(flag)) < 0) {
OBJECT_DEREF(&obj, "omapi_connect");
OBJECT_DEREF(&connection, "omapi_connect");
return (ISC_R_UNEXPECTED);
}
#endif
result = isc_socket_connect(obj->socket, &sockaddr, task,
omapi_connection_connect, obj);
if (result != ISC_R_SUCCESS)
OBJECT_DEREF(&obj, "omapi_connection_toserver");
result = isc_socket_connect(connection->socket, &sockaddr, task,
connect_done, connection);
if (result != ISC_R_SUCCESS) {
abandon_connection(connection, NULL, result);
return (result);
}
return (result);
}
/*
* Put some bytes into the output buffer for a connection.
*/
isc_result_t
omapi_connection_copyin(omapi_object_t *h, unsigned char *bufp,
unsigned int len)
{
omapi_connection_object_t *connection;
isc_buffer_t *buffer;
REQUIRE(h != NULL && h->type == omapi_type_connection);
connection = (omapi_connection_object_t *)h;
buffer = ISC_LIST_HEAD(connection->output_buffers);
if (ISC_BUFFER_AVAILABLECOUNT(buffer) < len)
isc_buffer_compact(buffer);
/* XXXDCL allocate new buffers */
ENSURE(ISC_BUFFER_AVAILABLECOUNT(buffer) >= len);
isc_buffer_putmem(buffer->base + buffer->used, bufp, len);
connection->out_bytes += len;
return (ISC_R_SUCCESS);
}
/*
* Copy some bytes from the input buffer, and advance the input buffer
* pointer beyond the bytes copied out.
*/
isc_result_t
omapi_connection_copyout(unsigned char *buffer, omapi_object_t *generic,
unsigned int size)
{
omapi_connection_object_t *connection;
isc_buffer_t *ibuffer;
REQUIRE(generic != NULL && generic->type == omapi_type_connection);
connection = (omapi_connection_object_t *)generic;
if (size > connection->in_bytes)
return (ISC_R_NOMORE);
ibuffer = ISC_LIST_HEAD(connection->input_buffers);
(void)memcpy(buffer, ibuffer->base, size);
isc_buffer_forward(ibuffer, size);
isc_buffer_compact(ibuffer);
connection->in_bytes -= size;
return (ISC_R_SUCCESS);
}
/*
* Disconnect a connection object from the remote end. If force is true,
* close the connection immediately. Otherwise, shut down the receiving end
@ -271,6 +503,10 @@ omapi_disconnect(omapi_object_t *generic, isc_boolean_t force) {
omapi_signal(generic, "disconnect", generic);
}
/*
* The caller wants a specific amount of bytes to be read. Queue up a
* recv for the socket.
*/
isc_result_t
omapi_connection_require(omapi_object_t *generic, unsigned int bytes) {
omapi_connection_object_t *connection;
@ -279,11 +515,77 @@ omapi_connection_require(omapi_object_t *generic, unsigned int bytes) {
connection = (omapi_connection_object_t *)generic;
connection->bytes_needed = bytes;
connection->bytes_needed += bytes;
if (connection->bytes_needed <= connection->in_bytes)
return (ISC_R_SUCCESS);
return (ISC_R_NOTYET);
if (connection->bytes_needed >
isc_bufferlist_availablecount(&connection->input_buffers)) {
/*
* Not enough space to put the required volume of information.
* See if the space can be attained by getting rid of the
* used buffer space.
*
* This could be made more efficient by not freeing
* the completely used buffers, but honestly the free/allocate
* code will probably *never* be used in practice; to even test
* the free/allocate stuff OMAPI_BUFFER_SIZE has to be set to
* an absurdly low value (like 4).
*/
isc_bufferlist_t bufferlist = connection->input_buffers;
isc_buffer_t *buffer;
isc_result_t result;
buffer = ISC_LIST_HEAD(bufferlist);
/*
* Lop off any completelyu used buffers, except the last one.
*/
while (ISC_BUFFER_AVAILABLECOUNT(buffer) == 0 &&
buffer != ISC_LIST_TAIL(bufferlist)) {
ISC_LIST_UNLINK(bufferlist, buffer, link);
isc_buffer_free(&buffer);
buffer = ISC_LIST_HEAD(bufferlist);
}
/*
* Reclaim any used space. (Any buffers after this one,
* if they exist at all, will be empty.)
*/
isc_buffer_compact(buffer);
/*
* Create as many new buffers as necessary to fit the
* entire size requirement.
*/
while (connection->bytes_needed >
isc_bufferlist_availablecount(&bufferlist)) {
buffer = NULL;
result = isc_buffer_allocate(omapi_mctx, &buffer,
OMAPI_BUFFER_SIZE,
ISC_BUFFERTYPE_BINARY);
if (result != ISC_R_SUCCESS)
return (result);
ISC_LIST_APPEND(bufferlist, buffer, link);
}
}
/*
* Queue the receive task.
* XXXDCL The "minimum" argument has not been fully thought out.
* It will *probably* work fine in a lockstep protocol, but I
* am not so sure what will happen when
*/
isc_socket_recvv(connection->socket, &connection->input_buffers,
connection->bytes_needed - connection->in_bytes,
connection->task, recv_done, connection);
return (OMAPI_R_NOTYET);
}
/*
@ -375,3 +677,156 @@ omapi_connection_stuff_values(omapi_object_t *c, omapi_object_t *id,
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_getuint32(omapi_object_t *c, isc_uint32_t *value) {
isc_uint32_t inbuf;
isc_result_t result;
result = omapi_connection_copyout((unsigned char *)&inbuf, c,
sizeof(inbuf));
if (result != ISC_R_SUCCESS)
return (result);
*value = ntohl(inbuf);
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_putuint32(omapi_object_t *c, isc_uint32_t value) {
isc_uint32_t inbuf;
inbuf = htonl(value);
return (omapi_connection_copyin(c, (unsigned char *)&inbuf,
sizeof(inbuf)));
}
isc_result_t
omapi_connection_getuint16(omapi_object_t *c, isc_uint16_t *value) {
isc_uint16_t inbuf;
isc_result_t result;
result = omapi_connection_copyout((unsigned char *)&inbuf, c,
sizeof(inbuf));
if (result != ISC_R_SUCCESS)
return (result);
*value = ntohs (inbuf);
return (ISC_R_SUCCESS);
}
isc_result_t
omapi_connection_putuint16(omapi_object_t *c, isc_uint32_t value) {
isc_uint16_t inbuf;
REQUIRE(value < 65536);
inbuf = htons((isc_uint16_t)value);
return (omapi_connection_copyin(c, (unsigned char *)&inbuf,
sizeof(inbuf)));
}
isc_result_t
omapi_connection_puttypeddata(omapi_object_t *c, omapi_typed_data_t *data)
{
isc_result_t result;
omapi_handle_t handle;
REQUIRE(data != NULL &&
(data->type == omapi_datatype_int ||
data->type == omapi_datatype_string ||
data->type == omapi_datatype_data ||
data->type == omapi_datatype_object));
switch (data->type) {
case omapi_datatype_int:
result = omapi_connection_putuint32(c, sizeof(isc_uint32_t));
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_putuint32(c, ((isc_uint32_t)
(data->u.integer))));
case omapi_datatype_string:
case omapi_datatype_data:
result = omapi_connection_putuint32(c, data->u.buffer.len);
if (result != ISC_R_SUCCESS)
return (result);
if (data->u.buffer.len > 0)
return (omapi_connection_copyin(c,
data->u.buffer.value,
data->u.buffer.len));
return (ISC_R_SUCCESS);
case omapi_datatype_object:
if (data->u.object != NULL) {
result = omapi_object_handle(&handle, data->u.object);
if (result != ISC_R_SUCCESS)
return (result);
} else
handle = 0;
result = omapi_connection_putuint32(c, sizeof(handle));
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_putuint32(c, handle));
}
UNEXPECTED_ERROR(__FILE__, __LINE__,
"unknown type in omapi_connection_puttypeddata: "
"%d\n", data->type);
return (ISC_R_UNEXPECTED);
}
isc_result_t
omapi_connection_putname(omapi_object_t *c, const char *name) {
isc_result_t result;
unsigned int len = strlen(name);
if (len > 65535)
/* XXXDCL better error? */
return (ISC_R_FAILURE);
result = omapi_connection_putuint16(c, len);
if (result != ISC_R_SUCCESS)
return (result);
return (omapi_connection_copyin(c, (char *)name, len));
}
isc_result_t
omapi_connection_putstring(omapi_object_t *c, const char *string) {
isc_result_t result;
unsigned int len;
if (string != NULL)
len = strlen(string);
else
len = 0;
result = omapi_connection_putuint32(c, len);
if (result == ISC_R_SUCCESS && len > 0)
result = omapi_connection_copyin(c, (char *)string, len);
return (result);
}
isc_result_t
omapi_connection_puthandle(omapi_object_t *c, omapi_object_t *h) {
isc_result_t result;
omapi_handle_t handle;
if (h != NULL) {
result = omapi_object_handle(&handle, h);
if (result != ISC_R_SUCCESS)
return (result);
} else
handle = 0; /* The null handle. */
result = omapi_connection_putuint32(c, sizeof(handle));
if (result == ISC_R_SUCCESS)
result = omapi_connection_putuint32(c, handle);
return (result);
}

View file

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dispatch.c,v 1.3 2000/01/04 20:04:38 tale Exp $ */
/* $Id: dispatch.c,v 1.4 2000/01/06 03:36:27 tale Exp $ */
/* Principal Author: Ted Lemon */
@ -51,10 +51,6 @@ isc_uint32_t cur_time;
isc_result_t
omapi_dispatch(struct timeval *t) {
#if 0 /*XXXDCL*/
return (omapi_wait_for_completion((omapi_object_t *)&omapi_io_states,
t));
#endif
/*
* XXXDCL sleep forever? The socket thread will be doing all the work.
*/
@ -285,7 +281,7 @@ omapi_io_set_value(omapi_object_t *h, omapi_object_t *id,
omapi_data_string_t *name, omapi_typed_data_t *value)
{
REQUIRE(h != NULL && h->type == omapi_type_io_object);
if (h->inner != NULL && h->inner->type->set_value != NULL)
return (*(h->inner->type->set_value))(h->inner, id,
name, value);

View file

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: generic.c,v 1.3 2000/01/04 20:04:38 tale Exp $ */
/* $Id: generic.c,v 1.4 2000/01/06 03:36:28 tale Exp $ */
/* Principal Author: Ted Lemon */
@ -250,7 +250,7 @@ omapi_generic_stuff_values(omapi_object_t *c, omapi_object_t *id,
for (i = 0; i < src->nvalues; i++) {
if (src->values[i] != NULL &&
src->values[i]->name->len != 0) {
result = omapi_connection_put_uint16(c,
result = omapi_connection_putuint16(c,
src->values[i]->name->len);
if (result != ISC_R_SUCCESS)
return (result);
@ -260,7 +260,7 @@ omapi_generic_stuff_values(omapi_object_t *c, omapi_object_t *id,
if (result != ISC_R_SUCCESS)
return (result);
result = omapi_connection_write_typed_data(c,
result = omapi_connection_puttypeddata(c,
src->values[i]->value);
if (result != ISC_R_SUCCESS)
return (result);

View file

@ -1,98 +0,0 @@
/*
* 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.
*/
/*****
***** Definitions for the object management API protocol buffering.
*****/
/*
* OMAPI buffers are ring buffers, which means that the beginning of the
* buffer and the end of the buffer chase each other around. As long as
* the tail never catches up to the head, there's room in the buffer for
* data.
*
* - If the tail and the head are equal, the buffer is empty.
*
* - If the tail is less than the head, the contents of the buffer
* are the bytes from the head to the end of buffer, and in addition,
* the bytes between the beginning of the buffer and the tail, not
* including the byte addressed by the tail.
*
* - If the tail is greater than the head, then the buffer contains
* valid bytes starting with the byte addressed by the head, and
* ending with the byte before the byte addressed by the tail.
*
* There will always be at least one byte of waste, because the tail can't
* increase so that it's equal to the head (that would represent an empty
* buffer.
*/
#ifndef OMAPI_BUFFER_H
#define OMAPI_BUFFER_H 1
#include <isc/lang.h>
#include <omapi/omapip.h>
ISC_LANG_BEGINDECLS
#define OMAPI_BUFFER_SIZE 4048
typedef struct omapi_buffer {
struct omapi_buffer *next; /* Buffers can be chained. */
isc_uint32_t refcnt; /* Buffers are reference counted. */
isc_uint16_t head, tail; /* Buffers are organized in a ring. */
char data[OMAPI_BUFFER_SIZE]; /* The actual buffer is included in
the buffer data structure. */
} omapi_buffer_t;
#define BUFFER_BYTES_FREE(x) \
((x)->tail > (x)->head \
? sizeof ((x)->data) - ((x)->tail - (x)->head) \
: (x)->head - (x)->tail)
#define BYTES_IN_BUFFER(x) \
((x)->tail > (x)->head \
? (x)->tail - (x)->head - 1 \
: sizeof ((x)->data) - ((x)->head - (x)->tail) - 1)
isc_result_t
omapi_connection_require(omapi_object_t *connection, unsigned int bytes);
isc_result_t
omapi_connection_copyout(unsigned char *data, omapi_object_t *connection,
unsigned int length);
isc_result_t
omapi_connection_copyin(omapi_object_t *connection, unsigned char *data,
unsigned int length);
isc_result_t
omapi_connection_get_uint32(omapi_object_t *connection, isc_uint32_t *value);
isc_result_t
omapi_connection_put_uint32(omapi_object_t *connection, isc_uint32_t value);
isc_result_t
omapi_connection_get_uint16(omapi_object_t *connection, isc_uint16_t *value);
isc_result_t
omapi_connection_put_uint16(omapi_object_t *connection, isc_uint32_t value);
ISC_LANG_ENDDECLS
#endif /* OMAPI_BUFFER_H */

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 1996, 1997, 1998, 1999 Internet Software Consortium.
* Copyright (C) 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
@ -15,29 +15,23 @@
* SOFTWARE.
*/
#ifndef OMAPI_ALLOC_H
#define OMAPI_ALLOC_H 1
/*****
***** Definitions for the object management API protocol memory allocation.
*****/
#ifndef OMAPI_LIB_H
#define OMAPI_LIB_H 1
#include <isc/types.h>
#include <isc/lang.h>
#include <omapi/omapip.h>
ISC_LANG_BEGINDECLS
isc_result_t
omapi_buffer_new(omapi_buffer_t **buffer, const char *name);
extern isc_msgcat_t *omapi_msgcat;
void
omapi_buffer_reference(omapi_buffer_t **bufferp, omapi_buffer_t *buffer,
const char *);
void
omapi_buffer_dereference(omapi_buffer_t **bufferp, const char *name);
omapi_lib_initmsgcat(void);
/*
* Initialize the OMAPI library's message catalog, omapi_msgcat, if it
* has not already been initialized.
*/
ISC_LANG_ENDDECLS
#endif /* OMAPI_ALLOC_H */
#endif /* OMAPI_LIB_H */

View file

@ -303,17 +303,40 @@ omapi_connection_stuff_values(omapi_object_t *connection, omapi_object_t *id,
omapi_object_t *object);
isc_result_t
omapi_connection_write_typed_data(omapi_object_t *connection,
omapi_connection_require(omapi_object_t *connection, unsigned int bytes);
isc_result_t
omapi_connection_copyout(unsigned char *data, omapi_object_t *connection,
unsigned int length);
isc_result_t
omapi_connection_copyin(omapi_object_t *connection, unsigned char *data,
unsigned int length);
isc_result_t
omapi_connection_getuint32(omapi_object_t *c, isc_uint32_t *value);
isc_result_t
omapi_connection_putuint32(omapi_object_t *c, isc_uint32_t value);
isc_result_t
omapi_connection_getuint16(omapi_object_t *c, isc_uint16_t *value);
isc_result_t
omapi_connection_putuint16(omapi_object_t *c, isc_uint32_t value);
isc_result_t
omapi_connection_puttypeddata(omapi_object_t *connection,
omapi_typed_data_t *data);
isc_result_t
omapi_connection_put_name(omapi_object_t *connection, const char *name);
omapi_connection_putname(omapi_object_t *connection, const char *name);
isc_result_t
omapi_connection_put_string(omapi_object_t *connection, const char *string);
omapi_connection_putstring(omapi_object_t *connection, const char *string);
isc_result_t
omapi_connection_put_handle(omapi_object_t *connection,
omapi_connection_puthandle(omapi_object_t *connection,
omapi_object_t *object);
/*
@ -585,6 +608,10 @@ omapi_handle_td_lookup(omapi_object_t **object, omapi_typed_data_t *data);
/*
* object.c
*/
isc_result_t
omapi_object_new(omapi_object_t **object, omapi_object_type_t *type,
size_t size);
void
omapi_object_reference(omapi_object_t **reference, omapi_object_t *object,
const char *name);

View file

@ -31,8 +31,7 @@
#include <isc/timer.h>
#include <omapi/omapip.h>
#include <omapi/buffer.h>
#include <omapi/alloc.h>
#include <omapi/result.h>
ISC_LANG_BEGINDECLS
@ -43,6 +42,8 @@ ISC_LANG_BEGINDECLS
#define OMAPI_OP_STATUS 5
#define OMAPI_OP_DELETE 6
#define OMAPI_BUFFER_SIZE 4096
typedef enum {
omapi_connection_unconnected,
omapi_connection_connecting,
@ -71,6 +72,7 @@ typedef struct omapi_connection_object {
OMAPI_OBJECT_PREAMBLE;
isc_socket_t *socket; /* Connection socket. */
isc_task_t *task;
unsigned int events_pending;
omapi_connection_state_t state;
isc_sockaddr_t remote_addr;
isc_sockaddr_t local_addr;
@ -83,10 +85,6 @@ typedef struct omapi_connection_object {
* XXXDCL isc_bufferlist_available() instead?
*/
isc_uint32_t in_bytes;
/*
* XXXDCL old style
*/
omapi_buffer_t * inbufs;
/*
* Input buffers.
*/
@ -95,8 +93,6 @@ typedef struct omapi_connection_object {
* Bytes of output in buffers.
*/
isc_uint32_t out_bytes;
omapi_buffer_t * outbufs;
isc_buffer_t * output_buffer;
isc_bufferlist_t output_buffers;
/*
* Listener that accepted this connection.
@ -136,7 +132,7 @@ extern isc_socketmgr_t *omapi_socketmgr;
extern isc_boolean_t omapi_ipv6;
void
omapi_connection_written(isc_task_t *task, isc_event_t *event);
connection_send(omapi_connection_object_t *connection);
#define OBJECT_REF(objectp, object, where) \
omapi_object_reference((omapi_object_t **)objectp, \

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 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.
*/
#ifndef OMAPI_RESULT_H
#define DNS_RESULT_H 1
#include <isc/lang.h>
#include <isc/result.h>
#include <isc/resultclass.h>
ISC_LANG_BEGINDECLS
#define OMAPI_R_NOTYET (ISC_RESULTCLASS_OMAPI + 0)
#define OMAPI_R_NOTCONNECTED (ISC_RESULTCLASS_OMAPI + 1)
#define OMAPI_R_NOKEYS (ISC_RESULTCLASS_OMAPI + 2)
#define OMAPI_R_INVALIDARG (ISC_RESULTCLASS_OMAPI + 3)
#define OMAPI_R_VERSIONMISMATCH (ISC_RESULTCLASS_OMAPI + 4)
#define OMAPI_R_PROTOCOLERROR (ISC_RESULTCLASS_OMAPI + 5)
#define OMAPI_R_NRESULTS 6 /* Number of results */
char * omapi_result_totext(isc_result_t);
void omapi_result_register(void);
ISC_LANG_ENDDECLS
#endif /* DNS_RESULT_H */

60
lib/omapi/lib.c Normal file
View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2000 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.
*/
#include <config.h>
#include <stddef.h>
#include <isc/once.h>
#include <isc/error.h>
#include <isc/msgcat.h>
#include <omapi/lib.h>
/***
*** Globals
***/
isc_msgcat_t * omapi_msgcat = NULL;
/***
*** Private
***/
static isc_once_t msgcat_once = ISC_ONCE_INIT;
/***
*** Functions
***/
static void
open_msgcat(void) {
isc_msgcat_open("libomapi.cat", &omapi_msgcat);
}
void
omapi_lib_initmsgcat(void) {
/*
* Initialize the OMAPI library's message catalog, omapi_msgcat, if it
* has not already been initialized.
*/
RUNTIME_CHECK(isc_once_do(&msgcat_once, open_msgcat) == ISC_R_SUCCESS);
}

View file

@ -42,9 +42,9 @@ static void
omapi_listener_accept(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
isc_buffer_t *ibuffer, *obuffer;
isc_task_t *recv_task;
isc_task_t *connection_task = NULL;
isc_socket_newconnev_t *incoming;
omapi_connection_object_t *connection;
omapi_connection_object_t *connection = NULL;
omapi_object_t *listener;
/*
@ -72,10 +72,9 @@ omapi_listener_accept(isc_task_t *task, isc_event_t *event) {
/*
* The new connection is good to go. Allocate the buffers for it and
* prepare the receive task.
* prepare its own task.
*/
recv_task = NULL;
if (isc_task_create(omapi_taskmgr, NULL, 0, &recv_task) !=
if (isc_task_create(omapi_taskmgr, NULL, 0, &connection_task) !=
ISC_R_SUCCESS)
return;
@ -94,30 +93,17 @@ omapi_listener_accept(isc_task_t *task, isc_event_t *event) {
/*
* Create a new connection object.
*/
connection = isc_mem_get(omapi_mctx, sizeof(*connection));
if (connection == NULL) {
/*
* XXXDCL at the moment, I am not confident this is
* the right way to forget all about this connection.
*/
isc_task_shutdown(recv_task);
#if 0 /*XXXDCL */
isc_socket_cancel(incoming->newsocket, recv_task,
ISC_SOCKCANCEL_RECV);
isc_socket_shutdown(incoming->newsocket, ISC_SOCKSHUT_ALL);
#endif
isc_buffer_free(&ibuffer);
result = omapi_object_new((omapi_object_t **)&connection,
omapi_type_connection, sizeof(*connection));
if (result != ISC_R_SUCCESS) {
/* XXXDCL cleanup */
isc_buffer_free(&obuffer);
isc_buffer_free(&ibuffer);
return;
}
memset(connection, 0, sizeof(*connection));
connection->object_size = sizeof(*connection);
connection->refcnt = 1;
connection->task = task;
connection->type = omapi_type_connection;
connection->task = connection_task;
connection->state = omapi_connection_connected;
connection->socket = incoming->newsocket;
ISC_LIST_INIT(connection->input_buffers);
@ -125,15 +111,6 @@ omapi_listener_accept(isc_task_t *task, isc_event_t *event) {
ISC_LIST_INIT(connection->output_buffers);
ISC_LIST_APPEND(connection->output_buffers, obuffer, link);
connection->output_buffer = obuffer;
/*
* Queue the receive task.
*/
isc_socket_recvv(incoming->newsocket, &connection->input_buffers, 1,
recv_task, omapi_connection_read, connection);
isc_task_detach(&recv_task);
/*
* Point the connection's listener member at the listener object.
* XXXDCL but why is this needed?

View file

@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: object.c,v 1.1 2000/01/04 20:04:40 tale Exp $ */
/* $Id: object.c,v 1.2 2000/01/06 03:36:29 tale Exp $ */
/* Principal Author: Ted Lemon */
@ -29,6 +29,29 @@
#include <omapi/private.h>
isc_result_t
omapi_object_new(omapi_object_t **object, omapi_object_type_t *type,
size_t size)
{
omapi_object_t *new;
REQUIRE(object != NULL && *object == NULL);
new = isc_mem_get(omapi_mctx, size);
if (new == NULL)
return (ISC_R_NOMEMORY);
memset(new, 0, size);
new->object_size = size;
new->refcnt = 1;
new->type = type;
*object = new;
return (ISC_R_SUCCESS);
}
void
omapi_object_reference(omapi_object_t **r, omapi_object_t *h,
const char *name)

View file

@ -132,12 +132,12 @@ omapi_protocol_send_intro(omapi_object_t *h, unsigned int ver,
if (h->outer == NULL || h->outer->type != omapi_type_connection)
return (ISC_R_NOTCONNECTED);
result = omapi_connection_put_uint32((omapi_object_t *)connection,
result = omapi_connection_putuint32((omapi_object_t *)connection,
ver);
if (result != ISC_R_SUCCESS)
return (result);
result = omapi_connection_put_uint32((omapi_object_t *)connection,
result = omapi_connection_putuint32((omapi_object_t *)connection,
hsize);
if (result != ISC_R_SUCCESS)
@ -149,7 +149,7 @@ omapi_protocol_send_intro(omapi_object_t *h, unsigned int ver,
*/
p->state = omapi_protocol_intro_wait;
result = omapi_connection_require((omapi_object_t *)connection, 8);
if (result != ISC_R_SUCCESS && result != ISC_R_NOTYET)
if (result != ISC_R_SUCCESS && result != OMAPI_R_NOTYET)
return (result);
/*
@ -158,16 +158,7 @@ omapi_protocol_send_intro(omapi_object_t *h, unsigned int ver,
*/
p->next_xid = random();
/*
* Send the intro.
*/
task = NULL;
result = isc_task_create(omapi_taskmgr, NULL, 0, &task);
if (result != ISC_R_SUCCESS)
return (result);
isc_socket_sendv(connection->socket, &connection->output_buffers,
task, omapi_connection_written, connection);
connection_send(connection);
return (ISC_R_SUCCESS);
}
@ -194,12 +185,12 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
om = (omapi_message_object_t *)omo;
/* XXXTL Write the authenticator length */
result = omapi_connection_put_uint32(c, 0);
result = omapi_connection_putuint32(c, 0);
if (result != ISC_R_SUCCESS)
return (result);
/* XXXTL Write the ID of the authentication key we're using. */
result = omapi_connection_put_uint32(c, 0);
result = omapi_connection_putuint32(c, 0);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -208,7 +199,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
/*
* Write the opcode.
*/
result = omapi_connection_put_uint32(c, m->op);
result = omapi_connection_putuint32(c, m->op);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -220,7 +211,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
* The caller is responsible for arranging for one of these handles
* to be set (or not).
*/
result = omapi_connection_put_uint32(c, (m->h ? m->h
result = omapi_connection_putuint32(c, (m->h ? m->h
: (m->object ?
m->object->handle
: 0)));
@ -233,7 +224,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
* Set and write the transaction ID.
*/
m->id = p->next_xid++;
result = omapi_connection_put_uint32(c, m->id);
result = omapi_connection_putuint32(c, m->id);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -243,7 +234,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
* Write the transaction ID of the message to which this is a
* response, if there is such a message.
*/
result = omapi_connection_put_uint32(c, om ? om->id : m->rid);
result = omapi_connection_putuint32(c, om ? om->id : m->rid);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -262,7 +253,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
* Write the zero-length name that terminates the list of name/value
* pairs specific to the message.
*/
result = omapi_connection_put_uint16(c, 0);
result = omapi_connection_putuint16(c, 0);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -284,7 +275,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
* Write the zero-length name that terminates the list of name/value
* pairs for the associated object.
*/
result = omapi_connection_put_uint16(c, 0);
result = omapi_connection_putuint16(c, 0);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(c, OMAPI_FORCE_DISCONNECT);
return (result);
@ -293,14 +284,7 @@ omapi_protocol_send_message(omapi_object_t *po, omapi_object_t *id,
/* XXXTL Write the authenticator... */
task = NULL;
result = isc_task_create(omapi_taskmgr, NULL, 0, &task);
if (result != ISC_R_SUCCESS)
return (result);
isc_socket_sendv(((omapi_connection_object_t *)c)->socket,
&((omapi_connection_object_t *)c)->output_buffers,
task, omapi_connection_written, c);
connection_send((omapi_connection_object_t *)c);
return (ISC_R_SUCCESS);
}
@ -339,10 +323,10 @@ omapi_protocol_signal_handler(omapi_object_t *h, const char *name, va_list ap)
* Get protocol version and header size in network
* byte order.
*/
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)
&p->protocol_version);
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->header_size);
/*
@ -392,19 +376,19 @@ omapi_protocol_signal_handler(omapi_object_t *h, const char *name, va_list ap)
/*
* Swap in the header.
*/
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->authid);
/* XXXTL bind the authenticator here! */
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->authlen);
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->op);
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->handle);
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->id);
omapi_connection_get_uint32(connection,
omapi_connection_getuint32(connection,
(isc_uint32_t *)&p->message->rid);
/*
@ -445,7 +429,7 @@ omapi_protocol_signal_handler(omapi_object_t *h, const char *name, va_list ap)
*/
case omapi_protocol_name_length_wait:
result = omapi_connection_get_uint16(connection, &nlen);
result = omapi_connection_getuint16(connection, &nlen);
if (result != ISC_R_SUCCESS) {
omapi_disconnect(connection, OMAPI_FORCE_DISCONNECT);
return (result);
@ -532,7 +516,7 @@ omapi_protocol_signal_handler(omapi_object_t *h, const char *name, va_list ap)
*/
case omapi_protocol_value_length_wait:
omapi_connection_get_uint32(connection, &vlen);
omapi_connection_getuint32(connection, &vlen);
/*
* Zero-length values are allowed - if we get one, we

73
lib/omapi/result.c Normal file
View file

@ -0,0 +1,73 @@
/*
* Copyright (C) 2000 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.
*/
/* $Id: result.c,v 1.3 2000/01/06 03:36:30 tale Exp $ */
#include <config.h>
#include <stddef.h>
#include <isc/resultclass.h>
#include <isc/once.h>
#include <isc/error.h>
#include <omapi/result.h>
#include <omapi/lib.h>
static char *text[OMAPI_R_NRESULTS] = {
"data not yet available", /* 0 */
"not connected", /* 1 */
"no key specified", /* 2 */
"invalid argument", /* 3 */
"protocol version mismatch", /* 4 */
"protocol error", /* 5 */
};
#define OMAPI_RESULT_RESULTSET 2
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_OMAPI, OMAPI_R_NRESULTS,
text, omapi_msgcat,
OMAPI_RESULT_RESULTSET);
if (result != ISC_R_SUCCESS)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
static void
initialize(void) {
omapi_lib_initmsgcat();
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
char *
omapi_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
omapi_result_register(void) {
initialize();
}