gen_client_ret.c 17.1 KB
Newer Older
1 2 3
/*-
 * See the file LICENSE for redistribution information.
 *
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
4 5
 * Copyright (c) 2000-2002
 *	Sleepycat Software.  All rights reserved.
6 7 8 9 10
 */

#include "db_config.h"

#ifndef lint
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
11
static const char revid[] = "$Id: gen_client_ret.c,v 1.57 2002/08/06 06:18:37 bostic Exp $";
12 13 14 15 16 17 18 19 20 21 22 23
#endif /* not lint */

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

#include <rpc/rpc.h>

#include <string.h>
#endif

#include "db_int.h"
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
24 25 26
#include "dbinc/db_page.h"
#include "dbinc/db_am.h"
#include "dbinc/txn.h"
27

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
28 29
#include "dbinc_auto/db_server.h"
#include "dbinc_auto/rpc_client_ext.h"
30

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
31 32 33 34
/*
 * PUBLIC: int __dbcl_env_close_ret
 * PUBLIC:     __P((DB_ENV *, u_int32_t, __env_close_reply *));
 */
35 36 37 38 39 40 41 42 43 44 45
int
__dbcl_env_close_ret(dbenv, flags, replyp)
	DB_ENV *dbenv;
	u_int32_t flags;
	__env_close_reply *replyp;
{
	int ret;

	COMPQUIET(flags, 0);

	ret = __dbcl_refresh(dbenv);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
46
	__os_free(NULL, dbenv);
47 48 49 50 51 52
	if (replyp->status == 0 && ret != 0)
		return (ret);
	else
		return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/*
 * PUBLIC: int __dbcl_env_create_ret
 * PUBLIC:     __P((DB_ENV *, long, __env_create_reply *));
 */
int
__dbcl_env_create_ret(dbenv, timeout, replyp)
	DB_ENV * dbenv;
	long timeout;
	__env_create_reply *replyp;
{

	COMPQUIET(timeout, 0);

	if (replyp->status != 0)
		return (replyp->status);
	dbenv->cl_id = replyp->envcl_id;
	return (replyp->status);
}

/*
 * PUBLIC: int __dbcl_env_open_ret __P((DB_ENV *,
 * PUBLIC:     const char *, u_int32_t, int, __env_open_reply *));
 */
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
int
__dbcl_env_open_ret(dbenv, home, flags, mode, replyp)
	DB_ENV *dbenv;
	const char *home;
	u_int32_t flags;
	int mode;
	__env_open_reply *replyp;
{
	DB_TXNMGR *tmgrp;
	int ret;

	COMPQUIET(home, NULL);
	COMPQUIET(mode, 0);

	/*
	 * If error, return it.
	 */
	if (replyp->status != 0)
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
96
	dbenv->cl_id = replyp->envcl_id;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	/*
	 * If the user requested transactions, then we have some
	 * local client-side setup to do also.
	 */
	if (LF_ISSET(DB_INIT_TXN)) {
		if ((ret = __os_calloc(dbenv,
		    1, sizeof(DB_TXNMGR), &tmgrp)) != 0)
			return (ret);
		TAILQ_INIT(&tmgrp->txn_chain);
		tmgrp->dbenv = dbenv;
		dbenv->tx_handle = tmgrp;
	}

	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
113 114 115 116
/*
 * PUBLIC: int __dbcl_env_remove_ret
 * PUBLIC:     __P((DB_ENV *, const char *, u_int32_t, __env_remove_reply *));
 */
117 118 119 120 121 122 123 124 125 126 127 128 129
int
__dbcl_env_remove_ret(dbenv, home, flags, replyp)
	DB_ENV *dbenv;
	const char *home;
	u_int32_t flags;
	__env_remove_reply *replyp;
{
	int ret;

	COMPQUIET(home, NULL);
	COMPQUIET(flags, 0);

	ret = __dbcl_refresh(dbenv);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
130
	__os_free(NULL, dbenv);
131 132 133 134 135 136
	if (replyp->status == 0 && ret != 0)
		return (ret);
	else
		return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
137 138 139
/*
 * PUBLIC: int __dbcl_txn_abort_ret __P((DB_TXN *, __txn_abort_reply *));
 */
140 141 142 143 144 145 146 147 148
int
__dbcl_txn_abort_ret(txnp, replyp)
	DB_TXN *txnp;
	__txn_abort_reply *replyp;
{
	__dbcl_txn_end(txnp);
	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
149 150 151 152
/*
 * PUBLIC: int __dbcl_txn_begin_ret __P((DB_ENV *,
 * PUBLIC:     DB_TXN *, DB_TXN **, u_int32_t, __txn_begin_reply *));
 */
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
int
__dbcl_txn_begin_ret(envp, parent, txnpp, flags, replyp)
	DB_ENV *envp;
	DB_TXN *parent, **txnpp;
	u_int32_t flags;
	__txn_begin_reply *replyp;
{
	DB_TXN *txn;
	int ret;

	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);

	if ((ret = __os_calloc(envp, 1, sizeof(DB_TXN), &txn)) != 0)
		return (ret);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
170
	__dbcl_txn_setup(envp, txn, parent, replyp->txnidcl_id);
171 172 173 174
	*txnpp = txn;
	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
175 176 177 178
/*
 * PUBLIC: int __dbcl_txn_commit_ret
 * PUBLIC:     __P((DB_TXN *, u_int32_t, __txn_commit_reply *));
 */
179 180 181 182 183 184 185 186 187 188 189 190
int
__dbcl_txn_commit_ret(txnp, flags, replyp)
	DB_TXN *txnp;
	u_int32_t flags;
	__txn_commit_reply *replyp;
{
	COMPQUIET(flags, 0);

	__dbcl_txn_end(txnp);
	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
/*
 * PUBLIC: int __dbcl_txn_discard_ret __P((DB_TXN *, u_int32_t,
 * PUBLIC:      __txn_discard_reply *));
 */
int
__dbcl_txn_discard_ret(txnp, flags, replyp)
	DB_TXN * txnp;
	u_int32_t flags;
	__txn_discard_reply *replyp;
{
	COMPQUIET(flags, 0);

	__dbcl_txn_end(txnp);
	return (replyp->status);
}

/*
 * PUBLIC: int __dbcl_txn_recover_ret __P((DB_ENV *, DB_PREPLIST *, long,
 * PUBLIC:      long *, u_int32_t, __txn_recover_reply *));
 */
int
__dbcl_txn_recover_ret(dbenv, preplist, count, retp, flags, replyp)
	DB_ENV * dbenv;
	DB_PREPLIST * preplist;
	long count;
	long * retp;
	u_int32_t flags;
	__txn_recover_reply *replyp;
{
	DB_PREPLIST *prep;
	DB_TXN *txnarray, *txn;
	u_int32_t i, *txnid;
	int ret;
	u_int8_t *gid;

	COMPQUIET(flags, 0);
	COMPQUIET(count, 0);

	if (replyp->status != 0)
		return (replyp->status);

	*retp = (long) replyp->retcount;

	if (replyp->retcount == 0)
		return (replyp->status);

	if ((ret = __os_calloc(dbenv, replyp->retcount, sizeof(DB_TXN),
	    &txnarray)) != 0)
		return (ret);
	/*
	 * We have a bunch of arrays that need to iterate in
	 * lockstep with each other.
	 */
	i = 0;
	txn = txnarray;
	txnid = (u_int32_t *)replyp->txn.txn_val;
	gid = (u_int8_t *)replyp->gid.gid_val;
	prep = preplist;
	while (i++ < replyp->retcount) {
		__dbcl_txn_setup(dbenv, txn, NULL, *txnid);
		prep->txn = txn;
		memcpy(&prep->gid, gid, DB_XIDDATASIZE);
		/*
		 * Now increment all our array pointers.
		 */
		txn++;
		gid += DB_XIDDATASIZE;
		txnid++;
		prep++;
	}

	return (0);
}

/*
 * PUBLIC: int __dbcl_db_close_ret __P((DB *, u_int32_t, __db_close_reply *));
 */
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
int
__dbcl_db_close_ret(dbp, flags, replyp)
	DB *dbp;
	u_int32_t flags;
	__db_close_reply *replyp;
{
	int ret;

	COMPQUIET(flags, 0);

	ret = __dbcl_dbclose_common(dbp);

	if (replyp->status != 0)
		return (replyp->status);
	else
		return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
/*
 * PUBLIC: int __dbcl_db_create_ret
 * PUBLIC:     __P((DB *, DB_ENV *, u_int32_t, __db_create_reply *));
 */
int
__dbcl_db_create_ret(dbp, dbenv, flags, replyp)
	DB * dbp;
	DB_ENV * dbenv;
	u_int32_t flags;
	__db_create_reply *replyp;
{
	COMPQUIET(dbenv, NULL);
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);
	dbp->cl_id = replyp->dbcl_id;
	return (replyp->status);
}

/*
 * PUBLIC: int __dbcl_db_get_ret
 * PUBLIC:     __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t, __db_get_reply *));
 */
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
int
__dbcl_db_get_ret(dbp, txnp, key, data, flags, replyp)
	DB *dbp;
	DB_TXN *txnp;
	DBT *key, *data;
	u_int32_t flags;
	__db_get_reply *replyp;
{
	DB_ENV *dbenv;
	int ret;
	void *oldkey;

	COMPQUIET(txnp, NULL);
	COMPQUIET(flags, 0);

	ret = 0;
	if (replyp->status != 0)
		return (replyp->status);

	dbenv = dbp->dbenv;

	oldkey = key->data;
	ret = __dbcl_retcopy(dbenv, key, replyp->keydata.keydata_val,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
333 334
	    replyp->keydata.keydata_len, &dbp->my_rkey.data,
	    &dbp->my_rkey.ulen);
335 336 337
	if (ret)
		return (ret);
	ret = __dbcl_retcopy(dbenv, data, replyp->datadata.datadata_val,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
338 339
	    replyp->datadata.datadata_len, &dbp->my_rdata.data,
	    &dbp->my_rdata.ulen);
340 341 342 343 344
	/*
	 * If an error on copying 'data' and we allocated for 'key'
	 * free it before returning the error.
	 */
	if (ret && oldkey != NULL)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
345
		__os_free(dbenv, key->data);
346 347 348
	return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
349 350 351 352
/*
 * PUBLIC: int __dbcl_db_key_range_ret __P((DB *, DB_TXN *,
 * PUBLIC:     DBT *, DB_KEY_RANGE *, u_int32_t, __db_key_range_reply *));
 */
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
int
__dbcl_db_key_range_ret(dbp, txnp, key, range, flags, replyp)
	DB *dbp;
	DB_TXN *txnp;
	DBT *key;
	DB_KEY_RANGE *range;
	u_int32_t flags;
	__db_key_range_reply *replyp;
{
	COMPQUIET(dbp, NULL);
	COMPQUIET(txnp, NULL);
	COMPQUIET(key, NULL);
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);
	range->less = replyp->less;
	range->equal = replyp->equal;
	range->greater = replyp->greater;
	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
375 376 377 378
/*
 * PUBLIC: int __dbcl_db_open_ret __P((DB *, DB_TXN *, const char *,
 * PUBLIC:     const char *, DBTYPE, u_int32_t, int, __db_open_reply *));
 */
379
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
380
__dbcl_db_open_ret(dbp, txn, name, subdb, type, flags, mode, replyp)
381
	DB *dbp;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
382
	DB_TXN *txn;
383 384 385 386 387 388
	const char *name, *subdb;
	DBTYPE type;
	u_int32_t flags;
	int mode;
	__db_open_reply *replyp;
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
389
	COMPQUIET(txn, NULL);
390 391 392 393 394 395
	COMPQUIET(name, NULL);
	COMPQUIET(subdb, NULL);
	COMPQUIET(type, 0);
	COMPQUIET(flags, 0);
	COMPQUIET(mode, 0);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
	if (replyp->status == 0) {
		dbp->cl_id = replyp->dbcl_id;
		dbp->type = replyp->type;
		/*
		 * We get back the database's byteorder on the server.
		 * Determine if our byteorder is the same or not by
		 * calling __db_set_lorder.
		 *
		 * XXX
		 * This MUST come before we set the flags because
		 * __db_set_lorder checks that it is called before
		 * the open flag is set.
		 */
		(void)__db_set_lorder(dbp, replyp->lorder);

		/*
		 * XXX
		 * This is only for Tcl which peeks at the dbp flags.
		 * When dbp->get_flags exists, this should go away.
		 */
		dbp->flags = replyp->dbflags;
	}
	return (replyp->status);
}

/*
 * PUBLIC: int __dbcl_db_pget_ret __P((DB *, DB_TXN *, DBT *, DBT *, DBT *,
 * PUBLIC:      u_int32_t, __db_pget_reply *));
 */
int
__dbcl_db_pget_ret(dbp, txnp, skey, pkey, data, flags, replyp)
	DB * dbp;
	DB_TXN * txnp;
	DBT * skey;
	DBT * pkey;
	DBT * data;
	u_int32_t flags;
	__db_pget_reply *replyp;
{
	DB_ENV *dbenv;
	int ret;
	void *oldskey, *oldpkey;

	COMPQUIET(txnp, NULL);
	COMPQUIET(flags, 0);
441

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
	ret = 0;
	if (replyp->status != 0)
		return (replyp->status);

	dbenv = dbp->dbenv;

	oldskey = skey->data;
	ret = __dbcl_retcopy(dbenv, skey, replyp->skeydata.skeydata_val,
	    replyp->skeydata.skeydata_len, &dbp->my_rskey.data,
	    &dbp->my_rskey.ulen);
	if (ret)
		return (ret);

	oldpkey = pkey->data;
	ret = __dbcl_retcopy(dbenv, pkey, replyp->pkeydata.pkeydata_val,
	    replyp->pkeydata.pkeydata_len, &dbp->my_rkey.data,
	    &dbp->my_rkey.ulen);
	if (ret && oldskey != NULL) {
		__os_free(dbenv, skey->data);
		return (ret);
	}
	ret = __dbcl_retcopy(dbenv, data, replyp->datadata.datadata_val,
	    replyp->datadata.datadata_len, &dbp->my_rdata.data,
	    &dbp->my_rdata.ulen);
466
	/*
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
467 468
	 * If an error on copying 'data' and we allocated for '*key'
	 * free it before returning the error.
469
	 */
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
470 471 472 473 474 475 476
	if (ret) {
		if (oldskey != NULL)
			__os_free(dbenv, skey->data);
		if (oldpkey != NULL)
			__os_free(dbenv, pkey->data);
	}
	return (ret);
477 478
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
479 480 481 482
/*
 * PUBLIC: int __dbcl_db_put_ret
 * PUBLIC:     __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t, __db_put_reply *));
 */
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
int
__dbcl_db_put_ret(dbp, txnp, key, data, flags, replyp)
	DB *dbp;
	DB_TXN *txnp;
	DBT *key, *data;
	u_int32_t flags;
	__db_put_reply *replyp;
{
	int ret;

	COMPQUIET(dbp, NULL);
	COMPQUIET(txnp, NULL);
	COMPQUIET(data, NULL);

	ret = replyp->status;
	if (replyp->status == 0 && (flags == DB_APPEND))
		*(db_recno_t *)key->data =
		    *(db_recno_t *)replyp->keydata.keydata_val;
	return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
504 505 506 507
/*
 * PUBLIC: int __dbcl_db_remove_ret __P((DB *,
 * PUBLIC:     const char *, const char *, u_int32_t, __db_remove_reply *));
 */
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
int
__dbcl_db_remove_ret(dbp, name, subdb, flags, replyp)
	DB *dbp;
	const char *name, *subdb;
	u_int32_t flags;
	__db_remove_reply *replyp;
{
	int ret;

	COMPQUIET(name, 0);
	COMPQUIET(subdb, 0);
	COMPQUIET(flags, 0);

	ret = __dbcl_dbclose_common(dbp);

	if (replyp->status != 0)
		return (replyp->status);
	else
		return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
529 530 531 532
/*
 * PUBLIC: int __dbcl_db_rename_ret __P((DB *, const char *,
 * PUBLIC:     const char *, const char *, u_int32_t, __db_rename_reply *));
 */
533 534 535 536 537
int
__dbcl_db_rename_ret(dbp, name, subdb, newname, flags, replyp)
	DB *dbp;
	const char *name, *subdb, *newname;
	u_int32_t flags;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
538
	__db_rename_reply *replyp;
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
{
	int ret;

	COMPQUIET(name, 0);
	COMPQUIET(subdb, 0);
	COMPQUIET(newname, 0);
	COMPQUIET(flags, 0);

	ret = __dbcl_dbclose_common(dbp);

	if (replyp->status != 0)
		return (replyp->status);
	else
		return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
555 556 557 558
/*
 * PUBLIC: int __dbcl_db_stat_ret
 * PUBLIC:     __P((DB *, void *, u_int32_t, __db_stat_reply *));
 */
559
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
560
__dbcl_db_stat_ret(dbp, sp, flags, replyp)
561 562 563 564 565
	DB *dbp;
	void *sp;
	u_int32_t flags;
	__db_stat_reply *replyp;
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
566 567
	int len, ret;
	u_int32_t i, *q, *p, *retsp;
568 569 570

	COMPQUIET(flags, 0);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
571
	if (replyp->status != 0 || sp == NULL)
572 573
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
574 575
	len = replyp->stats.stats_len * sizeof(u_int32_t);
	if ((ret = __os_umalloc(dbp->dbenv, len, &retsp)) != 0)
576
		return (ret);
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
577 578 579 580
	for (i = 0, q = retsp, p = (u_int32_t *)replyp->stats.stats_val;
	    i < replyp->stats.stats_len; i++, q++, p++)
		*q = *p;
	*(u_int32_t **)sp = retsp;
581 582 583
	return (0);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
584 585 586 587 588 589 590 591 592 593
/*
 * PUBLIC: int __dbcl_db_truncate_ret __P((DB *, DB_TXN *, u_int32_t  *,
 * PUBLIC:      u_int32_t, __db_truncate_reply *));
 */
int
__dbcl_db_truncate_ret(dbp, txnp, countp, flags, replyp)
	DB *dbp;
	DB_TXN *txnp;
	u_int32_t *countp, flags;
	__db_truncate_reply *replyp;
594
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
595 596 597
	COMPQUIET(dbp, NULL);
	COMPQUIET(txnp, NULL);
	COMPQUIET(flags, 0);
598

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
599 600 601
	if (replyp->status != 0)
		return (replyp->status);
	*countp = replyp->count;
602

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
603
	return (replyp->status);
604 605
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
606 607 608 609
/*
 * PUBLIC: int __dbcl_db_cursor_ret
 * PUBLIC:     __P((DB *, DB_TXN *, DBC **, u_int32_t, __db_cursor_reply *));
 */
610
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
611
__dbcl_db_cursor_ret(dbp, txnp, dbcp, flags, replyp)
612 613
	DB *dbp;
	DB_TXN *txnp;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
614
	DBC **dbcp;
615 616 617 618 619 620 621 622 623
	u_int32_t flags;
	__db_cursor_reply *replyp;
{
	COMPQUIET(txnp, NULL);
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
624
	return (__dbcl_c_setup(replyp->dbcidcl_id, dbp, dbcp));
625 626
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
627 628 629 630
/*
 * PUBLIC: int __dbcl_db_join_ret
 * PUBLIC:     __P((DB *, DBC **, DBC **, u_int32_t, __db_join_reply *));
 */
631
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
632
__dbcl_db_join_ret(dbp, curs, dbcp, flags, replyp)
633
	DB *dbp;
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
634
	DBC **curs, **dbcp;
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
	u_int32_t flags;
	__db_join_reply *replyp;
{
	COMPQUIET(curs, NULL);
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);

	/*
	 * We set this up as a normal cursor.  We do not need
	 * to treat a join cursor any differently than a normal
	 * cursor, even though DB itself must.  We only need the
	 * client-side cursor/db relationship to know what cursors
	 * are open in the db, and to store their ID.  Nothing else.
	 */
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
651
	return (__dbcl_c_setup(replyp->dbcidcl_id, dbp, dbcp));
652 653
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
654 655 656
/*
 * PUBLIC: int __dbcl_dbc_close_ret __P((DBC *, __dbc_close_reply *));
 */
657
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
658 659
__dbcl_dbc_close_ret(dbc, replyp)
	DBC *dbc;
660 661
	__dbc_close_reply *replyp;
{
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
662
	__dbcl_c_refresh(dbc);
663 664 665
	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
666 667 668 669
/*
 * PUBLIC: int __dbcl_dbc_count_ret
 * PUBLIC:     __P((DBC *, db_recno_t *, u_int32_t, __dbc_count_reply *));
 */
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
int
__dbcl_dbc_count_ret(dbc, countp, flags, replyp)
	DBC *dbc;
	db_recno_t *countp;
	u_int32_t flags;
	__dbc_count_reply *replyp;
{
	COMPQUIET(dbc, NULL);
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);
	*countp = replyp->dupcount;

	return (replyp->status);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
687 688 689 690
/*
 * PUBLIC: int __dbcl_dbc_dup_ret
 * PUBLIC:     __P((DBC *, DBC **, u_int32_t, __dbc_dup_reply *));
 */
691
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
692 693
__dbcl_dbc_dup_ret(dbc, dbcp, flags, replyp)
	DBC *dbc, **dbcp;
694 695 696 697 698 699 700 701
	u_int32_t flags;
	__dbc_dup_reply *replyp;
{
	COMPQUIET(flags, 0);

	if (replyp->status != 0)
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
702
	return (__dbcl_c_setup(replyp->dbcidcl_id, dbc->dbp, dbcp));
703 704
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
705 706 707 708
/*
 * PUBLIC: int __dbcl_dbc_get_ret
 * PUBLIC:     __P((DBC *, DBT *, DBT *, u_int32_t, __dbc_get_reply *));
 */
709
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
710 711
__dbcl_dbc_get_ret(dbc, key, data, flags, replyp)
	DBC *dbc;
712 713 714 715 716 717 718 719 720 721 722 723 724 725
	DBT *key, *data;
	u_int32_t flags;
	__dbc_get_reply *replyp;
{
	DB_ENV *dbenv;
	int ret;
	void *oldkey;

	COMPQUIET(flags, 0);

	ret = 0;
	if (replyp->status != 0)
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
726
	dbenv = dbc->dbp->dbenv;
727 728
	oldkey = key->data;
	ret = __dbcl_retcopy(dbenv, key, replyp->keydata.keydata_val,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
729 730
	    replyp->keydata.keydata_len, &dbc->my_rkey.data,
	    &dbc->my_rkey.ulen);
731 732 733
	if (ret)
		return (ret);
	ret = __dbcl_retcopy(dbenv, data, replyp->datadata.datadata_val,
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
734 735
	    replyp->datadata.datadata_len, &dbc->my_rdata.data,
	    &dbc->my_rdata.ulen);
736 737 738 739 740 741

	/*
	 * If an error on copying 'data' and we allocated for 'key'
	 * free it before returning the error.
	 */
	if (ret && oldkey != NULL)
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
742
		__os_free(dbenv, key->data);
743 744 745
	return (ret);
}

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
746 747 748 749
/*
 * PUBLIC: int __dbcl_dbc_pget_ret __P((DBC *, DBT *, DBT *, DBT *, u_int32_t,
 * PUBLIC:      __dbc_pget_reply *));
 */
750
int
ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
__dbcl_dbc_pget_ret(dbc, skey, pkey, data, flags, replyp)
	DBC * dbc;
	DBT * skey;
	DBT * pkey;
	DBT * data;
	u_int32_t flags;
	__dbc_pget_reply *replyp;
{
	DB_ENV *dbenv;
	int ret;
	void *oldskey, *oldpkey;

	COMPQUIET(flags, 0);

	ret = 0;
	if (replyp->status != 0)
		return (replyp->status);

	dbenv = dbc->dbp->dbenv;

	oldskey = skey->data;
	ret = __dbcl_retcopy(dbenv, skey, replyp->skeydata.skeydata_val,
	    replyp->skeydata.skeydata_len, &dbc->my_rskey.data,
	    &dbc->my_rskey.ulen);
	if (ret)
		return (ret);

	oldpkey = pkey->data;
	ret = __dbcl_retcopy(dbenv, pkey, replyp->pkeydata.pkeydata_val,
	    replyp->pkeydata.pkeydata_len, &dbc->my_rkey.data,
	    &dbc->my_rkey.ulen);
	if (ret && oldskey != NULL) {
		__os_free(dbenv, skey->data);
		return (ret);
	}
	ret = __dbcl_retcopy(dbenv, data, replyp->datadata.datadata_val,
	    replyp->datadata.datadata_len, &dbc->my_rdata.data,
	    &dbc->my_rdata.ulen);
	/*
	 * If an error on copying 'data' and we allocated for '*key'
	 * free it before returning the error.
	 */
	if (ret) {
		if (oldskey != NULL)
			__os_free(dbenv, skey->data);
		if (oldpkey != NULL)
			__os_free(dbenv, pkey->data);
	}
	return (ret);
}

/*
 * PUBLIC: int __dbcl_dbc_put_ret
 * PUBLIC:     __P((DBC *, DBT *, DBT *, u_int32_t, __dbc_put_reply *));
 */
int
__dbcl_dbc_put_ret(dbc, key, data, flags, replyp)
	DBC *dbc;
809 810 811 812 813 814 815 816 817
	DBT *key, *data;
	u_int32_t flags;
	__dbc_put_reply *replyp;
{
	COMPQUIET(data, NULL);

	if (replyp->status != 0)
		return (replyp->status);

ram@mysql.r18.ru's avatar
ram@mysql.r18.ru committed
818
	if (replyp->status == 0 && dbc->dbp->type == DB_RECNO &&
819 820 821 822 823 824
	    (flags == DB_AFTER || flags == DB_BEFORE))
		*(db_recno_t *)key->data =
		    *(db_recno_t *)replyp->keydata.keydata_val;
	return (replyp->status);
}
#endif /* HAVE_RPC */