⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_iface.c

📁 这是国外的resip协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
		/* QAM can't be done as a subdatabase. */		if (type == DB_QUEUE) {			__db_err(dbenv, "Queue databases must be one-per-file");			return (EINVAL);		}	}	return (0);}/* * __db_pget_pp -- *	DB->pget pre/post processing. * * PUBLIC: int __db_pget_pp * PUBLIC:     __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)); */int__db_pget_pp(dbp, txn, skey, pkey, data, flags)	DB *dbp;	DB_TXN *txn;	DBT *skey, *pkey, *data;	u_int32_t flags;{	DB_ENV *dbenv;	int handle_check, ret;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->pget");	if ((ret = __db_pget_arg(dbp, pkey, flags)) != 0)		return (ret);	if ((ret = __db_get_arg(dbp, skey, data, flags)) != 0)		return (ret);	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check && (ret = __db_rep_enter(dbp, 1, 0, txn != NULL)) != 0)		return (ret);	ret = __db_pget(dbp, txn, skey, pkey, data, flags);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_pget -- *	DB->pget. * * PUBLIC: int __db_pget * PUBLIC:     __P((DB *, DB_TXN *, DBT *, DBT *, DBT *, u_int32_t)); */int__db_pget(dbp, txn, skey, pkey, data, flags)	DB *dbp;	DB_TXN *txn;	DBT *skey, *pkey, *data;	u_int32_t flags;{	DBC *dbc;	int ret, t_ret;	if ((ret = __db_cursor(dbp, txn, &dbc, 0)) != 0)		return (ret);	SET_RET_MEM(dbc, dbp);	DEBUG_LREAD(dbc, txn, "__db_pget", skey, NULL, flags);	/*	 * !!!	 * The actual method call is simple, do it inline.	 *	 * The underlying cursor pget will fill in a default DBT for null	 * pkeys, and use the cursor's returned-key memory internally to	 * store any intermediate primary keys.  However, we've just set	 * the returned-key memory to the DB handle's key memory, which	 * is unsafe to use if the DB handle is threaded.  If the pkey	 * argument is NULL, use the DBC-owned returned-key memory	 * instead;  it'll go away when we close the cursor before we	 * return, but in this case that's just fine, as we're not	 * returning the primary key.	 */	if (pkey == NULL)		dbc->rkey = &dbc->my_rkey;	/*	 * The cursor is just a perfectly ordinary secondary database cursor.	 * Call its c_pget() method to do the dirty work.	 */	if (flags == 0 || flags == DB_RMW)		flags |= DB_SET;	ret = __db_c_pget(dbc, skey, pkey, data, flags);	if ((t_ret = __db_c_close(dbc)) != 0 && ret == 0)		ret = t_ret;	return (ret);}/* * __db_pget_arg -- *	Check DB->pget arguments. */static int__db_pget_arg(dbp, pkey, flags)	DB *dbp;	DBT *pkey;	u_int32_t flags;{	DB_ENV *dbenv;	int ret;	dbenv = dbp->dbenv;	if (!F_ISSET(dbp, DB_AM_SECONDARY)) {		__db_err(dbenv,		    "DB->pget may only be used on secondary indices");		return (EINVAL);	}	if (LF_ISSET(DB_MULTIPLE | DB_MULTIPLE_KEY)) {		__db_err(dbenv,	"DB_MULTIPLE and DB_MULTIPLE_KEY may not be used on secondary indices");		return (EINVAL);	}	/* DB_CONSUME makes no sense on a secondary index. */	LF_CLR(DB_RMW);	switch (flags) {	case DB_CONSUME:	case DB_CONSUME_WAIT:		return (__db_ferr(dbenv, "DB->pget", 0));	default:		/* __db_get_arg will catch the rest. */		break;	}	/*	 * We allow the pkey field to be NULL, so that we can make the	 * two-DBT get calls into wrappers for the three-DBT ones.	 */	if (pkey != NULL &&	    (ret = __dbt_ferr(dbp, "primary key", pkey, 1)) != 0)		return (ret);	/* But the pkey field can't be NULL if we're doing a DB_GET_BOTH. */	if (pkey == NULL && flags == DB_GET_BOTH) {		__db_err(dbenv,		    "DB_GET_BOTH on a secondary index requires a primary key");		return (EINVAL);	}	return (0);}/* * __db_put_pp -- *	DB->put pre/post processing. * * PUBLIC: int __db_put_pp __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t)); */int__db_put_pp(dbp, txn, key, data, flags)	DB *dbp;	DB_TXN *txn;	DBT *key, *data;	u_int32_t flags;{	DB_ENV *dbenv;	int handle_check, ret, txn_local;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->put");	if ((ret = __db_put_arg(dbp, key, data, flags)) != 0)		return (ret);	/* Create local transaction as necessary. */	if (IS_AUTO_COMMIT(dbenv, txn, flags)) {		if ((ret = __db_txn_auto_init(dbenv, &txn)) != 0)			return (ret);		txn_local = 1;		LF_CLR(DB_AUTO_COMMIT);	} else		txn_local = 0;	/* Check for consistent transaction usage. */	if ((ret = __db_check_txn(dbp, txn, DB_LOCK_INVALIDID, 0)) != 0)		goto err;	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check && (ret = __db_rep_enter(dbp, 1, 0, txn != NULL)) != 0)		goto err;	ret = __db_put(dbp, txn, key, data, flags);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);err:	return (txn_local ? __db_txn_auto_resolve(dbenv, txn, 0, ret) : ret);}/* * __db_put_arg -- *	Check DB->put arguments. */static int__db_put_arg(dbp, key, data, flags)	DB *dbp;	DBT *key, *data;	u_int32_t flags;{	DB_ENV *dbenv;	int ret, returnkey;	dbenv = dbp->dbenv;	returnkey = 0;	/* Check for changes to a read-only tree. */	if (IS_READONLY(dbp))		return (__db_rdonly(dbenv, "put"));	/* Check for puts on a secondary. */	if (F_ISSET(dbp, DB_AM_SECONDARY)) {		__db_err(dbenv, "DB->put forbidden on secondary indices");		return (EINVAL);	}	/* Check for invalid function flags. */	LF_CLR(DB_AUTO_COMMIT);	switch (flags) {	case 0:	case DB_NOOVERWRITE:		break;	case DB_APPEND:		if (dbp->type != DB_RECNO && dbp->type != DB_QUEUE)			goto err;		returnkey = 1;		break;	case DB_NODUPDATA:		if (F_ISSET(dbp, DB_AM_DUPSORT))			break;		/* FALLTHROUGH */	default:err:		return (__db_ferr(dbenv, "DB->put", 0));	}	/* Check for invalid key/data flags. */	if ((ret = __dbt_ferr(dbp, "key", key, returnkey)) != 0)		return (ret);	if ((ret = __dbt_ferr(dbp, "data", data, 0)) != 0)		return (ret);	/* Keys shouldn't have partial flags during a put. */	if (F_ISSET(key, DB_DBT_PARTIAL))		return (__db_ferr(dbenv, "key DBT", 0));	/* Check for partial puts in the presence of duplicates. */	if (F_ISSET(data, DB_DBT_PARTIAL) &&	    (F_ISSET(dbp, DB_AM_DUP) || F_ISSET(key, DB_DBT_DUPOK))) {		__db_err(dbenv,"a partial put in the presence of duplicates requires a cursor operation");		return (EINVAL);	}	return (0);}/* * __db_sync_pp -- *	DB->sync pre/post processing. * * PUBLIC: int __db_sync_pp __P((DB *, u_int32_t)); */int__db_sync_pp(dbp, flags)	DB *dbp;	u_int32_t flags;{	DB_ENV *dbenv;	int handle_check, ret;	dbenv = dbp->dbenv;	PANIC_CHECK(dbp->dbenv);	DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->sync");	/*	 * !!!	 * The actual argument checking is simple, do it inline.	 */	if (flags != 0)		return (__db_ferr(dbenv, "DB->sync", 0));	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check && (ret = __db_rep_enter(dbp, 1, 0, 0)) != 0)		return (ret);	ret = __db_sync(dbp);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_c_close_pp -- *	DBC->c_close pre/post processing. * * PUBLIC: int __db_c_close_pp __P((DBC *)); */int__db_c_close_pp(dbc)	DBC *dbc;{	DB_ENV *dbenv;	DB *dbp;	int handle_check, ret;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	/*	 * If the cursor is already closed we have a serious problem, and we	 * assume that the cursor isn't on the active queue.  Don't do any of	 * the remaining cursor close processing.	 */	if (!F_ISSET(dbc, DBC_ACTIVE)) {		if (dbp != NULL)			__db_err(dbenv, "Closing already-closed cursor");		DB_ASSERT(0);		return (EINVAL);	}	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check &&	    (ret = __db_rep_enter(dbp, 0, 0, dbc->txn != NULL)) != 0)		return (ret);	ret = __db_c_close(dbc);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_c_count_pp -- *	DBC->c_count pre/post processing. * * PUBLIC: int __db_c_count_pp __P((DBC *, db_recno_t *, u_int32_t)); */int__db_c_count_pp(dbc, recnop, flags)	DBC *dbc;	db_recno_t *recnop;	u_int32_t flags;{	DB_ENV *dbenv;	DB *dbp;	int handle_check, ret;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	/*	 * !!!	 * The actual argument checking is simple, do it inline.	 */	if (flags != 0)		return (__db_ferr(dbenv, "DBcursor->count", 0));	/*	 * The cursor must be initialized, return EINVAL for an invalid cursor,	 * otherwise 0.	 */	if (!IS_INITIALIZED(dbc))		return (__db_curinval(dbenv));	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check &&	    (ret = __db_rep_enter(dbp, 1, 0, dbc->txn != NULL)) != 0)		return (ret);	ret = __db_c_count(dbc, recnop);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_c_del_pp -- *	DBC->c_del pre/post processing. * * PUBLIC: int __db_c_del_pp __P((DBC *, u_int32_t)); */int__db_c_del_pp(dbc, flags)	DBC *dbc;	u_int32_t flags;{	DB *dbp;	DB_ENV *dbenv;	int handle_check, ret;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	if ((ret = __db_c_del_arg(dbc, flags)) != 0)		return (ret);	/* Check for consistent transaction usage. */	if ((ret = __db_check_txn(dbp, dbc->txn, dbc->locker, 0)) != 0)		return (ret);	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check &&	    (ret = __db_rep_enter(dbp, 1, 0, dbc->txn != NULL)) != 0)		return (ret);	DEBUG_LWRITE(dbc, dbc->txn, "DBcursor->del", NULL, NULL, flags);	ret = __db_c_del(dbc, flags);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_c_del_arg -- *	Check DBC->c_del arguments. * * PUBLIC: int __db_c_del_arg __P((DBC *, u_int32_t)); */int__db_c_del_arg(dbc, flags)	DBC *dbc;	u_int32_t flags;{	DB *dbp;	DB_ENV *dbenv;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	/* Check for changes to a read-only tree. */	if (IS_READONLY(dbp))		return (__db_rdonly(dbenv, "DBcursor->del"));	/* Check for invalid function flags. */	switch (flags) {	case 0:		break;	case DB_UPDATE_SECONDARY:		DB_ASSERT(F_ISSET(dbp, DB_AM_SECONDARY));		break;	default:		return (__db_ferr(dbenv, "DBcursor->del", 0));	}	/*	 * The cursor must be initialized, return EINVAL for an invalid cursor,	 * otherwise 0.	 */	if (!IS_INITIALIZED(dbc))		return (__db_curinval(dbenv));	return (0);}/* * __db_c_dup_pp -- *	DBC->c_dup pre/post processing. * * PUBLIC: int __db_c_dup_pp __P((DBC *, DBC **, u_int32_t)); */int__db_c_dup_pp(dbc, dbcp, flags)	DBC *dbc, **dbcp;	u_int32_t flags;{	DB *dbp;	DB_ENV *dbenv;	int handle_check, ret;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	/*	 * !!!	 * The actual argument checking is simple, do it inline.	 */	if (flags != 0 && flags != DB_POSITION)		return (__db_ferr(dbenv, "DBcursor->dup", 0));	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check &&	    (ret = __db_rep_enter(dbp, 1, 0, dbc->txn != NULL)) != 0)		return (ret);	ret = __db_c_dup(dbc, dbcp, flags);	/* Release replication block. */	if (handle_check)		__env_db_rep_exit(dbenv);	return (ret);}/* * __db_c_get_pp -- *	DBC->c_get pre/post processing. * * PUBLIC: int __db_c_get_pp __P((DBC *, DBT *, DBT *, u_int32_t)); */int__db_c_get_pp(dbc, key, data, flags)	DBC *dbc;	DBT *key, *data;	u_int32_t flags;{	DB *dbp;	DB_ENV *dbenv;	int handle_check, ret;	dbp = dbc->dbp;	dbenv = dbp->dbenv;	PANIC_CHECK(dbenv);	if ((ret = __db_c_get_arg(dbc, key, data, flags)) != 0)		return (ret);	/* Check for replication block. */	handle_check = IS_REPLICATED(dbenv, dbp);	if (handle_check &&	    (ret = __db_rep_enter(dbp, 1, 0, dbc->txn != NULL)) != 0)		return (ret);	DEBUG_LREAD(dbc, dbc->txn, "DBcursor->get",	    flags == DB_SET || flags == DB_SET_RANGE ? key : NULL, NULL, flags);	ret = __db_c_get(dbc, key, data, flags);	/* Release replication block. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -