/* Do not edit: automatically built by gen_rpc.awk. */
#include "db_config.h"

#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>

#include <rpc/rpc.h>
#include <rpc/xdr.h>

#include <errno.h>
#include <string.h>
#endif

#include "db_int.h"
#include "db_server.h"
#include "db_server_int.h"
#include "rpc_server_ext.h"

#include "gen_server_ext.h"

__envcachesize_reply *
__db_envcachesize_1(req)
	__envcachesize_msg *req;
{
	static __envcachesize_reply reply; /* must be static */

	__envcachesize_1_proc(req->dbenvcl_id,
	    req->gbytes,
	    req->bytes,
	    req->ncache,
	    &reply);

	return (&reply);
}

__envclose_reply *
__db_envclose_1(req)
	__envclose_msg *req;
{
	static __envclose_reply reply; /* must be static */

	__envclose_1_proc(req->dbenvcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__envcreate_reply *
__db_envcreate_1(req)
	__envcreate_msg *req;
{
	static __envcreate_reply reply; /* must be static */

	__envcreate_1_proc(req->timeout,
	    &reply);

	return (&reply);
}

__envopen_reply *
__db_envopen_1(req)
	__envopen_msg *req;
{
	static __envopen_reply reply; /* must be static */

	__envopen_1_proc(req->dbenvcl_id,
	    (*req->home == '\0') ? NULL : req->home,
	    req->flags,
	    req->mode,
	    &reply);

	return (&reply);
}

__envremove_reply *
__db_envremove_1(req)
	__envremove_msg *req;
{
	static __envremove_reply reply; /* must be static */

	__envremove_1_proc(req->dbenvcl_id,
	    (*req->home == '\0') ? NULL : req->home,
	    req->flags,
	    &reply);

	return (&reply);
}

__txnabort_reply *
__db_txnabort_1(req)
	__txnabort_msg *req;
{
	static __txnabort_reply reply; /* must be static */

	__txnabort_1_proc(req->txnpcl_id,
	    &reply);

	return (&reply);
}

__txnbegin_reply *
__db_txnbegin_1(req)
	__txnbegin_msg *req;
{
	static __txnbegin_reply reply; /* must be static */

	__txnbegin_1_proc(req->envpcl_id,
	    req->parentcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__txncommit_reply *
__db_txncommit_1(req)
	__txncommit_msg *req;
{
	static __txncommit_reply reply; /* must be static */

	__txncommit_1_proc(req->txnpcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbbtmaxkey_reply *
__db_dbbtmaxkey_1(req)
	__dbbtmaxkey_msg *req;
{
	static __dbbtmaxkey_reply reply; /* must be static */

	__dbbtmaxkey_1_proc(req->dbpcl_id,
	    req->maxkey,
	    &reply);

	return (&reply);
}

__dbbtminkey_reply *
__db_dbbtminkey_1(req)
	__dbbtminkey_msg *req;
{
	static __dbbtminkey_reply reply; /* must be static */

	__dbbtminkey_1_proc(req->dbpcl_id,
	    req->minkey,
	    &reply);

	return (&reply);
}

__dbclose_reply *
__db_dbclose_1(req)
	__dbclose_msg *req;
{
	static __dbclose_reply reply; /* must be static */

	__dbclose_1_proc(req->dbpcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbcreate_reply *
__db_dbcreate_1(req)
	__dbcreate_msg *req;
{
	static __dbcreate_reply reply; /* must be static */

	__dbcreate_1_proc(req->flags,
	    req->envpcl_id,
	    &reply);

	return (&reply);
}

__dbdel_reply *
__db_dbdel_1(req)
	__dbdel_msg *req;
{
	static __dbdel_reply reply; /* must be static */

	__dbdel_1_proc(req->dbpcl_id,
	    req->txnpcl_id,
	    req->keydlen,
	    req->keydoff,
	    req->keyflags,
	    req->keydata.keydata_val,
	    req->keydata.keydata_len,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbflags_reply *
__db_dbflags_1(req)
	__dbflags_msg *req;
{
	static __dbflags_reply reply; /* must be static */

	__dbflags_1_proc(req->dbpcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbget_reply *
__db_dbget_1(req)
	__dbget_msg *req;
{
	static __dbget_reply reply; /* must be static */
	static int __dbget_free = 0; /* must be static */

	if (__dbget_free)
		xdr_free((xdrproc_t)xdr___dbget_reply, (void *)&reply);
	__dbget_free = 0;
	
	/* Reinitialize allocated fields */
	reply.keydata.keydata_val = NULL;
	reply.datadata.datadata_val = NULL;

	__dbget_1_proc(req->dbpcl_id,
	    req->txnpcl_id,
	    req->keydlen,
	    req->keydoff,
	    req->keyflags,
	    req->keydata.keydata_val,
	    req->keydata.keydata_len,
	    req->datadlen,
	    req->datadoff,
	    req->dataflags,
	    req->datadata.datadata_val,
	    req->datadata.datadata_len,
	    req->flags,
	    &reply,
	    &__dbget_free);
	return (&reply);
}

__dbhffactor_reply *
__db_dbhffactor_1(req)
	__dbhffactor_msg *req;
{
	static __dbhffactor_reply reply; /* must be static */

	__dbhffactor_1_proc(req->dbpcl_id,
	    req->ffactor,
	    &reply);

	return (&reply);
}

__dbhnelem_reply *
__db_dbhnelem_1(req)
	__dbhnelem_msg *req;
{
	static __dbhnelem_reply reply; /* must be static */

	__dbhnelem_1_proc(req->dbpcl_id,
	    req->nelem,
	    &reply);

	return (&reply);
}

__dblorder_reply *
__db_dblorder_1(req)
	__dblorder_msg *req;
{
	static __dblorder_reply reply; /* must be static */

	__dblorder_1_proc(req->dbpcl_id,
	    req->lorder,
	    &reply);

	return (&reply);
}

__dbopen_reply *
__db_dbopen_1(req)
	__dbopen_msg *req;
{
	static __dbopen_reply reply; /* must be static */

	__dbopen_1_proc(req->dbpcl_id,
	    (*req->name == '\0') ? NULL : req->name,
	    (*req->subdb == '\0') ? NULL : req->subdb,
	    req->type,
	    req->flags,
	    req->mode,
	    &reply);

	return (&reply);
}

__dbpagesize_reply *
__db_dbpagesize_1(req)
	__dbpagesize_msg *req;
{
	static __dbpagesize_reply reply; /* must be static */

	__dbpagesize_1_proc(req->dbpcl_id,
	    req->pagesize,
	    &reply);

	return (&reply);
}

__dbput_reply *
__db_dbput_1(req)
	__dbput_msg *req;
{
	static __dbput_reply reply; /* must be static */
	static int __dbput_free = 0; /* must be static */

	if (__dbput_free)
		xdr_free((xdrproc_t)xdr___dbput_reply, (void *)&reply);
	__dbput_free = 0;
	
	/* Reinitialize allocated fields */
	reply.keydata.keydata_val = NULL;

	__dbput_1_proc(req->dbpcl_id,
	    req->txnpcl_id,
	    req->keydlen,
	    req->keydoff,
	    req->keyflags,
	    req->keydata.keydata_val,
	    req->keydata.keydata_len,
	    req->datadlen,
	    req->datadoff,
	    req->dataflags,
	    req->datadata.datadata_val,
	    req->datadata.datadata_len,
	    req->flags,
	    &reply,
	    &__dbput_free);
	return (&reply);
}

__dbredelim_reply *
__db_dbredelim_1(req)
	__dbredelim_msg *req;
{
	static __dbredelim_reply reply; /* must be static */

	__dbredelim_1_proc(req->dbpcl_id,
	    req->delim,
	    &reply);

	return (&reply);
}

__dbrelen_reply *
__db_dbrelen_1(req)
	__dbrelen_msg *req;
{
	static __dbrelen_reply reply; /* must be static */

	__dbrelen_1_proc(req->dbpcl_id,
	    req->len,
	    &reply);

	return (&reply);
}

__dbrepad_reply *
__db_dbrepad_1(req)
	__dbrepad_msg *req;
{
	static __dbrepad_reply reply; /* must be static */

	__dbrepad_1_proc(req->dbpcl_id,
	    req->pad,
	    &reply);

	return (&reply);
}

__dbremove_reply *
__db_dbremove_1(req)
	__dbremove_msg *req;
{
	static __dbremove_reply reply; /* must be static */

	__dbremove_1_proc(req->dbpcl_id,
	    (*req->name == '\0') ? NULL : req->name,
	    (*req->subdb == '\0') ? NULL : req->subdb,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbstat_reply *
__db_dbstat_1(req)
	__dbstat_msg *req;
{
	static __dbstat_reply reply; /* must be static */
	static int __dbstat_free = 0; /* must be static */

	if (__dbstat_free)
		xdr_free((xdrproc_t)xdr___dbstat_reply, (void *)&reply);
	__dbstat_free = 0;
	
	/* Reinitialize allocated fields */
	reply.statslist = NULL;

	__dbstat_1_proc(req->dbpcl_id,
	    req->flags,
	    &reply,
	    &__dbstat_free);
	return (&reply);
}

__dbswapped_reply *
__db_dbswapped_1(req)
	__dbswapped_msg *req;
{
	static __dbswapped_reply reply; /* must be static */

	__dbswapped_1_proc(req->dbpcl_id,
	    &reply);

	return (&reply);
}

__dbsync_reply *
__db_dbsync_1(req)
	__dbsync_msg *req;
{
	static __dbsync_reply reply; /* must be static */

	__dbsync_1_proc(req->dbpcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbcursor_reply *
__db_dbcursor_1(req)
	__dbcursor_msg *req;
{
	static __dbcursor_reply reply; /* must be static */

	__dbcursor_1_proc(req->dbpcl_id,
	    req->txnpcl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

int __db_dbjoin_curslist __P((__dbjoin_curslist *, u_int32_t **));
void __db_dbjoin_cursfree __P((u_int32_t *));

__dbjoin_reply *
__db_dbjoin_1(req)
	__dbjoin_msg *req;
{
	u_int32_t *__db_curslist;
	int ret;
	static __dbjoin_reply reply; /* must be static */

	if ((ret = __db_dbjoin_curslist(req->curslist, &__db_curslist)) != 0)
		goto out;

	__dbjoin_1_proc(req->dbpcl_id,
	    __db_curslist,
	    req->flags,
	    &reply);

	__db_dbjoin_cursfree(__db_curslist);

out:
	return (&reply);
}

int
__db_dbjoin_curslist(locp, ppp)
	__dbjoin_curslist *locp;
	u_int32_t **ppp;
{
	u_int32_t *pp;
	int cnt, ret, size;
	__dbjoin_curslist *nl;

	for (cnt = 0, nl = locp; nl != NULL; cnt++, nl = nl->next)
		;

	if (cnt == 0) {
		*ppp = NULL;
		return (0);
	}
	size = sizeof(*pp) * (cnt + 1);
	if ((ret = __os_malloc(size, NULL, ppp)) != 0)
		return (ret);
	memset(*ppp, 0, size);
	for (pp = *ppp, nl = locp; nl != NULL; nl = nl->next, pp++) {
		*pp = *(u_int32_t *)nl->ent.ent_val;
	}
	return (0);
}

void
__db_dbjoin_cursfree(pp)
	u_int32_t *pp;
{
	size_t size;
	u_int32_t *p;

	if (pp == NULL)
		return;
	size = sizeof(*p);
	for (p = pp; *p != 0; p++) {
		size += sizeof(*p);
	}
	__os_free(pp, size);
}

__dbc_close_reply *
__db_dbc_close_1(req)
	__dbc_close_msg *req;
{
	static __dbc_close_reply reply; /* must be static */

	__dbc_close_1_proc(req->dbccl_id,
	    &reply);

	return (&reply);
}

__dbc_count_reply *
__db_dbc_count_1(req)
	__dbc_count_msg *req;
{
	static __dbc_count_reply reply; /* must be static */

	__dbc_count_1_proc(req->dbccl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbc_del_reply *
__db_dbc_del_1(req)
	__dbc_del_msg *req;
{
	static __dbc_del_reply reply; /* must be static */

	__dbc_del_1_proc(req->dbccl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbc_dup_reply *
__db_dbc_dup_1(req)
	__dbc_dup_msg *req;
{
	static __dbc_dup_reply reply; /* must be static */

	__dbc_dup_1_proc(req->dbccl_id,
	    req->flags,
	    &reply);

	return (&reply);
}

__dbc_get_reply *
__db_dbc_get_1(req)
	__dbc_get_msg *req;
{
	static __dbc_get_reply reply; /* must be static */
	static int __dbc_get_free = 0; /* must be static */

	if (__dbc_get_free)
		xdr_free((xdrproc_t)xdr___dbc_get_reply, (void *)&reply);
	__dbc_get_free = 0;
	
	/* Reinitialize allocated fields */
	reply.keydata.keydata_val = NULL;
	reply.datadata.datadata_val = NULL;

	__dbc_get_1_proc(req->dbccl_id,
	    req->keydlen,
	    req->keydoff,
	    req->keyflags,
	    req->keydata.keydata_val,
	    req->keydata.keydata_len,
	    req->datadlen,
	    req->datadoff,
	    req->dataflags,
	    req->datadata.datadata_val,
	    req->datadata.datadata_len,
	    req->flags,
	    &reply,
	    &__dbc_get_free);
	return (&reply);
}

__dbc_put_reply *
__db_dbc_put_1(req)
	__dbc_put_msg *req;
{
	static __dbc_put_reply reply; /* must be static */

	__dbc_put_1_proc(req->dbccl_id,
	    req->keydlen,
	    req->keydoff,
	    req->keyflags,
	    req->keydata.keydata_val,
	    req->keydata.keydata_len,
	    req->datadlen,
	    req->datadoff,
	    req->dataflags,
	    req->datadata.datadata_val,
	    req->datadata.datadata_len,
	    req->flags,
	    &reply);

	return (&reply);
}

