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

📄 db_pr.c

📁 这是国外的resip协议栈
💻 C
📖 第 1 页 / 共 3 页
字号:
				    recno, dataret.data, dataret.size);			else				DB_MULTIPLE_KEY_NEXT(pointer,				    &data, keyret.data,				    keyret.size, dataret.data, dataret.size);			if (dataret.data == NULL)				break;			if ((keyflag &&			    (ret = __db_prdbt(&keyret, pflag, " ",			    handle, callback, is_recno)) != 0) ||			    (ret = __db_prdbt(&dataret, pflag, " ",			    handle, callback, 0)) != 0)				goto err;		}	}	if (ret == DB_BUFFER_SMALL) {		data.size = (u_int32_t)DB_ALIGN(data.size, 1024);		if ((ret = __os_realloc(dbenv, data.size, &data.data)) != 0)			goto err;		data.ulen = data.size;		goto retry;	}	(void)__db_prfooter(handle, callback);err:	if ((t_ret = __db_c_close(dbcp)) != 0 && ret == 0)		ret = t_ret;	if (data.data != NULL)		__os_free(dbenv, data.data);	return (ret);}/* * __db_prdbt -- *	Print out a DBT data element. * * PUBLIC: int __db_prdbt __P((DBT *, int, const char *, void *, * PUBLIC:     int (*)(void *, const void *), int)); */int__db_prdbt(dbtp, checkprint, prefix, handle, callback, is_recno)	DBT *dbtp;	int checkprint;	const char *prefix;	void *handle;	int (*callback) __P((void *, const void *));	int is_recno;{	static const u_char hex[] = "0123456789abcdef";	db_recno_t recno;	size_t len;	int ret;#define	DBTBUFLEN	100	u_int8_t *p, *hp;	char buf[DBTBUFLEN], hbuf[DBTBUFLEN];	/*	 * !!!	 * This routine is the routine that dumps out items in the format	 * used by db_dump(1) and db_load(1).  This means that the format	 * cannot change.	 */	if (prefix != NULL && (ret = callback(handle, prefix)) != 0)		return (ret);	if (is_recno) {		/*		 * We're printing a record number, and this has to be done		 * in a platform-independent way.  So we use the numeral in		 * straight ASCII.		 */		(void)__ua_memcpy(&recno, dbtp->data, sizeof(recno));		snprintf(buf, DBTBUFLEN, "%lu", (u_long)recno);		/* If we're printing data as hex, print keys as hex too. */		if (!checkprint) {			for (len = strlen(buf), p = (u_int8_t *)buf,			    hp = (u_int8_t *)hbuf; len-- > 0; ++p) {				*hp++ = hex[(u_int8_t)(*p & 0xf0) >> 4];				*hp++ = hex[*p & 0x0f];			}			*hp = '\0';			ret = callback(handle, hbuf);		} else			ret = callback(handle, buf);		if (ret != 0)			return (ret);	} else if (checkprint) {		for (len = dbtp->size, p = dbtp->data; len--; ++p)			if (isprint((int)*p)) {				if (*p == '\\' &&				    (ret = callback(handle, "\\")) != 0)					return (ret);				snprintf(buf, DBTBUFLEN, "%c", *p);				if ((ret = callback(handle, buf)) != 0)					return (ret);			} else {				snprintf(buf, DBTBUFLEN, "\\%c%c",				    hex[(u_int8_t)(*p & 0xf0) >> 4],				    hex[*p & 0x0f]);				if ((ret = callback(handle, buf)) != 0)					return (ret);			}	} else		for (len = dbtp->size, p = dbtp->data; len--; ++p) {			snprintf(buf, DBTBUFLEN, "%c%c",			    hex[(u_int8_t)(*p & 0xf0) >> 4],			    hex[*p & 0x0f]);			if ((ret = callback(handle, buf)) != 0)				return (ret);		}	return (callback(handle, "\n"));}/* * __db_prheader -- *	Write out header information in the format expected by db_load. * * PUBLIC: int	__db_prheader __P((DB *, const char *, int, int, void *, * PUBLIC:     int (*)(void *, const void *), VRFY_DBINFO *, db_pgno_t)); */int__db_prheader(dbp, subname, pflag, keyflag, handle, callback, vdp, meta_pgno)	DB *dbp;	const char *subname;	int pflag, keyflag;	void *handle;	int (*callback) __P((void *, const void *));	VRFY_DBINFO *vdp;	db_pgno_t meta_pgno;{	DBT dbt;	DB_ENV *dbenv;	DBTYPE dbtype;	VRFY_PAGEINFO *pip;	u_int32_t flags, tmp_u_int32;	size_t buflen;	char *buf;	int using_vdp, ret, t_ret, tmp_int;	ret = 0;	buf = NULL;	COMPQUIET(buflen, 0);	/*	 * If dbp is NULL, then pip is guaranteed to be non-NULL; we only ever	 * call __db_prheader with a NULL dbp from one case inside __db_prdbt,	 * and this is a special subdatabase for "lost" items.  In this case	 * we have a vdp (from which we'll get a pip).  In all other cases, we	 * will have a non-NULL dbp (and vdp may or may not be NULL depending	 * on whether we're salvaging).	 */	DB_ASSERT(dbp != NULL || vdp != NULL);	if (dbp == NULL)		dbenv = NULL;	else		dbenv = dbp->dbenv;	/*	 * If we've been passed a verifier statistics object, use that;  we're	 * being called in a context where dbp->stat is unsafe.	 *	 * Also, the verifier may set the pflag on a per-salvage basis.  If so,	 * respect that.	 */	if (vdp != NULL) {		if ((ret = __db_vrfy_getpageinfo(vdp, meta_pgno, &pip)) != 0)			return (ret);		if (F_ISSET(vdp, SALVAGE_PRINTABLE))			pflag = 1;		using_vdp = 1;	} else {		pip = NULL;		using_vdp = 0;	}	/*	 * If dbp is NULL, make it a btree.  Otherwise, set dbtype to whatever	 * appropriate type for the specified meta page, or the type of the dbp.	 */	if (dbp == NULL)		dbtype = DB_BTREE;	else if (using_vdp)		switch (pip->type) {		case P_BTREEMETA:			if (F_ISSET(pip, VRFY_IS_RECNO))				dbtype = DB_RECNO;			else				dbtype = DB_BTREE;			break;		case P_HASHMETA:			dbtype = DB_HASH;			break;		case P_QAMMETA:			dbtype = DB_QUEUE;			break;		default:			/*			 * If the meta page is of a bogus type, it's because			 * we have a badly corrupt database.  (We must be in			 * the verifier for pip to be non-NULL.) Pretend we're			 * a Btree and salvage what we can.			 */			DB_ASSERT(F_ISSET(dbp, DB_AM_VERIFYING));			dbtype = DB_BTREE;			break;		}	else		dbtype = dbp->type;	if ((ret = callback(handle, "VERSION=3\n")) != 0)		goto err;	if (pflag) {		if ((ret = callback(handle, "format=print\n")) != 0)			goto err;	} else if ((ret = callback(handle, "format=bytevalue\n")) != 0)		goto err;	/*	 * 64 bytes is long enough, as a minimum bound, for any of the	 * fields besides subname.  Subname uses __db_prdbt and therefore	 * does not need buffer space here.	 */	buflen = 64;	if ((ret = __os_malloc(dbenv, buflen, &buf)) != 0)		goto err;	if (subname != NULL) {		snprintf(buf, buflen, "database=");		if ((ret = callback(handle, buf)) != 0)			goto err;		memset(&dbt, 0, sizeof(dbt));		dbt.data = (char *)subname;		dbt.size = (u_int32_t)strlen(subname);		if ((ret = __db_prdbt(&dbt, 1, NULL, handle, callback, 0)) != 0)			goto err;	}	switch (dbtype) {	case DB_BTREE:		if ((ret = callback(handle, "type=btree\n")) != 0)			goto err;		if (using_vdp) {			if (F_ISSET(pip, VRFY_HAS_RECNUMS))				if ((ret =				    callback(handle, "recnum=1\n")) != 0)					goto err;			if (pip->bt_maxkey != 0) {				snprintf(buf, buflen,				    "bt_maxkey=%lu\n", (u_long)pip->bt_maxkey);				if ((ret = callback(handle, buf)) != 0)					goto err;			}			if (pip->bt_minkey != 0 &&			    pip->bt_minkey != DEFMINKEYPAGE) {				snprintf(buf, buflen,				    "bt_minkey=%lu\n", (u_long)pip->bt_minkey);				if ((ret = callback(handle, buf)) != 0)					goto err;			}			break;		}		if ((ret = __db_get_flags(dbp, &flags)) != 0) {			__db_err(dbenv, "DB->get_flags: %s", db_strerror(ret));			goto err;		}		if (F_ISSET(dbp, DB_AM_RECNUM))			if ((ret = callback(handle, "recnum=1\n")) != 0)				goto err;		if ((ret = __bam_get_bt_minkey(dbp, &tmp_u_int32)) != 0) {			__db_err(dbenv,			    "DB->get_bt_minkey: %s", db_strerror(ret));			goto err;		}		if (tmp_u_int32 != 0 && tmp_u_int32 != DEFMINKEYPAGE) {			snprintf(buf, buflen,			    "bt_minkey=%lu\n", (u_long)tmp_u_int32);			if ((ret = callback(handle, buf)) != 0)				goto err;		}		break;	case DB_HASH:#ifdef HAVE_HASH		if ((ret = callback(handle, "type=hash\n")) != 0)			goto err;		if (using_vdp) {			if (pip->h_ffactor != 0) {				snprintf(buf, buflen,				    "h_ffactor=%lu\n", (u_long)pip->h_ffactor);				if ((ret = callback(handle, buf)) != 0)					goto err;			}			if (pip->h_nelem != 0) {				snprintf(buf, buflen,				    "h_nelem=%lu\n", (u_long)pip->h_nelem);				if ((ret = callback(handle, buf)) != 0)					goto err;			}			break;		}		if ((ret = __ham_get_h_ffactor(dbp, &tmp_u_int32)) != 0) {			__db_err(dbenv,			    "DB->get_h_ffactor: %s", db_strerror(ret));			goto err;		}		if (tmp_u_int32 != 0) {			snprintf(buf, buflen,			    "h_ffactor=%lu\n", (u_long)tmp_u_int32);			if ((ret = callback(handle, buf)) != 0)				goto err;		}		if ((ret = __ham_get_h_nelem(dbp, &tmp_u_int32)) != 0) {			__db_err(dbenv,			    "DB->get_h_nelem: %s", db_strerror(ret));			goto err;		}		if (tmp_u_int32 != 0) {			snprintf(buf, buflen,			    "h_nelem=%lu\n", (u_long)tmp_u_int32);			if ((ret = callback(handle, buf)) != 0)				goto err;		}		break;#else		ret = __db_no_hash_am(dbenv);		goto err;#endif	case DB_QUEUE:#ifdef HAVE_QUEUE		if ((ret = callback(handle, "type=queue\n")) != 0)			goto err;		if (vdp != NULL) {			snprintf(buf,			    buflen, "re_len=%lu\n", (u_long)vdp->re_len);			if ((ret = callback(handle, buf)) != 0)				goto err;			break;		}		if ((ret = __ram_get_re_len(dbp, &tmp_u_int32)) != 0) {			__db_err(dbenv,			    "DB->get_re_len: %s", db_strerror(ret));			goto err;		}		snprintf(buf, buflen, "re_len=%lu\n", (u_long)tmp_u_int32);		if ((ret = callback(handle, buf)) != 0)			goto err;		if ((ret = __ram_get_re_pad(dbp, &tmp_int)) != 0) {			__db_err(dbenv,			    "DB->get_re_pad: %s", db_strerror(ret));			goto err;		}		if (tmp_int != 0 && tmp_int != ' ') {			snprintf(buf, buflen, "re_pad=%#x\n", tmp_int);			if ((ret = callback(handle, buf)) != 0)				goto err;		}		if ((ret = __qam_get_extentsize(dbp, &tmp_u_int32)) != 0) {			__db_err(dbenv,			    "DB->get_q_extentsize: %s", db_strerror(ret));			goto err;		}		if (tmp_u_int32 != 0) {			snprintf(buf, buflen,			    "extentsize=%lu\n", (u_long)tmp_u_int32);			if ((ret = callback(handle, buf)) != 0)				goto err;		}		break;#else		ret = __db_no_queue_am(dbenv);		goto err;#endif	case DB_RECNO:		if ((ret = callback(handle, "type=recno\n")) != 0)			goto err;		if (using_vdp) {			if (F_ISSET(pip, VRFY_IS_RRECNO))				if ((ret =				    callback(handle, "renumber=1\n")) != 0)					goto err;			if (pip->re_len > 0) {				snprintf(buf, buflen,				    "re_len=%lu\n", (u_long)pip->re_len);				if ((ret = callback(handle, buf)) != 0)					goto err;			}			break;		}		if (F_ISSET(dbp, DB_AM_RENUMBER))			if ((ret = callback(handle, "renumber=1\n")) != 0)				goto err;		if (F_ISSET(dbp, DB_AM_FIXEDLEN)) {			if ((ret = __ram_get_re_len(dbp, &tmp_u_int32)) != 0) {				__db_err(dbenv,				    "DB->get_re_len: %s", db_strerror(ret));				goto err;			}			snprintf(buf, buflen,			    "re_len=%lu\n", (u_long)tmp_u_int32);			if ((ret = callback(handle, buf)) != 0)				goto err;			if ((ret = __ram_get_re_pad(dbp, &tmp_int)) != 0) {				__db_err(dbenv,				    "DB->get_re_pad: %s", db_strerror(ret));				goto err;			}			if (tmp_int != 0 && tmp_int != ' ') {				snprintf(buf,				    buflen, "re_pad=%#x\n", (u_int)tmp_int);				if ((ret = callback(handle, buf)) != 0)					goto err;			}		}		break;	case DB_UNKNOWN:		DB_ASSERT(0);			/* Impossible. */		__db_err(dbenv,		    "Unknown or unsupported DB type in __db_prheader");		ret = EINVAL;		goto err;	}	if (using_vdp) {		if (F_ISSET(pip, VRFY_HAS_DUPS))			if ((ret = callback(handle, "duplicates=1\n")) != 0)				goto err;		if (F_ISSET(pip, VRFY_HAS_DUPSORT))			if ((ret = callback(handle, "dupsort=1\n")) != 0)				goto err;		/* We should handle page size. XXX */	} else {		if (F_ISSET(dbp, DB_AM_CHKSUM))			if ((ret = callback(handle, "chksum=1\n")) != 0)				goto err;		if (F_ISSET(dbp, DB_AM_DUP))			if ((ret = callback(handle, "duplicates=1\n")) != 0)				goto err;		if (F_ISSET(dbp, DB_AM_DUPSORT))			if ((ret = callback(handle, "dupsort=1\n")) != 0)				goto err;		if (!F_ISSET(dbp, DB_AM_PGDEF)) {			snprintf(buf, buflen,			    "db_pagesize=%lu\n", (u_long)dbp->pgsize);			if ((ret = callback(handle, buf)) != 0)				goto err;		}	}	if (keyflag && (ret = callback(handle, "keys=1\n")) != 0)		goto err;	ret = callback(handle, "HEADER=END\n");err:	if (using_vdp &&	    (t_ret = __db_vrfy_putpageinfo(dbenv, vdp, pip)) != 0 && ret == 0)		ret = t_ret;	if (buf != NULL)		__os_free(dbenv, buf);	return (ret);}/* * __db_prfooter -- *	Print the footer that marks the end of a DB dump.  This is trivial, *	but for consistency's sake we don't want to put its literal contents *	in multiple places. * * PUBLIC: int __db_prfooter __P((void *, int (*)(void *, const void *))); */int__db_prfooter(handle, callback)	void *handle;	int (*callback) __P((void *, const void *));{	return (callback(handle, "DATA=END\n"));}/* * __db_pr_callback -- *	Callback function for using pr_* functions from C. * * PUBLIC: int  __db_pr_callback __P((void *, const void *)); */int__db_pr_callback(handle, str_arg)	void *handle;	const void *str_arg;{	char *str;	FILE *f;	str = (char *)str_arg;	f = (FILE *)handle;	if (fprintf(f, "%s", str) != (int)strlen(str))		return (EIO);	return (0);}/* * __db_dbtype_to_string -- *	Return the name of the database type. * * PUBLIC: const char * __db_dbtype_to_string __P((DBTYPE)); */const char *__db_dbtype_to_string(type)	DBTYPE type;{	switch (type) {	case DB_BTREE:		return ("btree");	case DB_HASH:		return ("hash");	case DB_RECNO:		return ("recno");	case DB_QUEUE:		return ("queue");	case DB_UNKNOWN:	default:		break;	}	return ("UNKNOWN TYPE");}

⌨️ 快捷键说明

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