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

📄 rdataslab.c

📁 bind 源码 最新实现 linux/unix/windows平台
💻 C
📖 第 1 页 / 共 2 页
字号:
	 * XXX  Need parameter to allow "delete rdatasets in nslab" merge,	 * or perhaps another merge routine for this purpose.	 */	REQUIRE(tslabp != NULL && *tslabp == NULL);	REQUIRE(oslab != NULL && nslab != NULL);	ocurrent = oslab + reservelen;	ocount = *ocurrent++ * 256;	ocount += *ocurrent++;	ostart = ocurrent;	ncurrent = nslab + reservelen;	ncount = *ncurrent++ * 256;	ncount += *ncurrent++;	INSIST(ocount > 0 && ncount > 0);	/*	 * Yes, this is inefficient!	 */	/*	 * Figure out the length of the old slab's data.	 */	olength = 0;	for (count = 0; count < ocount; count++) {		length = *ocurrent++ * 256;		length += *ocurrent++;		olength += length + 2;		ocurrent += length;	}	/*	 * Start figuring out the target length and count.	 */	tlength = reservelen + 2 + olength;	tcount = ocount;	/*	 * Add in the length of rdata in the new slab that aren't in	 * the old slab.	 */	do {		nregion.length = *ncurrent++ * 256;		nregion.length += *ncurrent++;		nregion.base = ncurrent;		dns_rdata_init(&nrdata);		dns_rdata_fromregion(&nrdata, rdclass, type, &nregion);		if (!rdata_in_slab(oslab, reservelen, rdclass, type, &nrdata))		{			/*			 * This rdata isn't in the old slab.			 */			tlength += nregion.length + 2;			tcount++;			nncount++;			added_something = ISC_TRUE;		}		ncurrent += nregion.length;		ncount--;	} while (ncount > 0);	ncount = nncount;	if (((flags & DNS_RDATASLAB_EXACT) != 0) &&	    (tcount != ncount + ocount))		return (DNS_R_NOTEXACT);	if (!added_something && (flags & DNS_RDATASLAB_FORCE) == 0)		return (DNS_R_UNCHANGED);	/*	 * Ensure that singleton types are actually singletons.	 */	if (tcount > 1 && dns_rdatatype_issingleton(type)) {		/*		 * We have a singleton type, but there's more than one		 * RR in the rdataset.		 */		return (DNS_R_SINGLETON);	}	/*	 * Copy the reserved area from the new slab.	 */	tstart = isc_mem_get(mctx, tlength);	if (tstart == NULL)		return (ISC_R_NOMEMORY);	memcpy(tstart, nslab, reservelen);	tcurrent = tstart + reservelen;	/*	 * Write the new count.	 */	*tcurrent++ = (tcount & 0xff00) >> 8;	*tcurrent++ = (tcount & 0x00ff);	/*	 * Merge the two slabs.	 */	ocurrent = ostart;	INSIST(ocount != 0);	rdata_from_slab(&ocurrent, rdclass, type, &ordata);	ncurrent = nslab + reservelen + 2;	if (ncount > 0) {		do {			dns_rdata_reset(&nrdata);       			rdata_from_slab(&ncurrent, rdclass, type, &nrdata);		} while (rdata_in_slab(oslab, reservelen, rdclass,				       type, &nrdata));	}	while (oadded < ocount || nadded < ncount) {		isc_boolean_t fromold;		if (oadded == ocount)			fromold = ISC_FALSE;		else if (nadded == ncount)			fromold = ISC_TRUE;		else			fromold = ISC_TF(compare_rdata(&ordata, &nrdata) < 0);		if (fromold) {			length = ordata.length;			*tcurrent++ = (length & 0xff00) >> 8;			*tcurrent++ = (length & 0x00ff);			memcpy(tcurrent, ordata.data, length);			tcurrent += length;			oadded++;			if (oadded < ocount) {				dns_rdata_reset(&ordata);       				rdata_from_slab(&ocurrent, rdclass, type,						&ordata);			}		} else {			length = nrdata.length;			*tcurrent++ = (length & 0xff00) >> 8;			*tcurrent++ = (length & 0x00ff);			memcpy(tcurrent, nrdata.data, length);			tcurrent += length;			nadded++;			if (nadded < ncount) {				do {					dns_rdata_reset(&nrdata);       					rdata_from_slab(&ncurrent, rdclass,							type, &nrdata);				} while (rdata_in_slab(oslab, reservelen,						       rdclass, type,						       &nrdata));			}		}	}	INSIST(tcurrent == tstart + tlength);	*tslabp = tstart;	return (ISC_R_SUCCESS);}isc_result_tdns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,		       unsigned int reservelen, isc_mem_t *mctx,		       dns_rdataclass_t rdclass, dns_rdatatype_t type,		       unsigned int flags, unsigned char **tslabp){	unsigned char *mcurrent, *sstart, *scurrent, *tstart, *tcurrent;	unsigned int mcount, scount, rcount ,count, tlength, tcount;	dns_rdata_t srdata = DNS_RDATA_INIT;	dns_rdata_t mrdata = DNS_RDATA_INIT;	REQUIRE(tslabp != NULL && *tslabp == NULL);	REQUIRE(mslab != NULL && sslab != NULL);	mcurrent = mslab + reservelen;	mcount = *mcurrent++ * 256;	mcount += *mcurrent++;	scurrent = sslab + reservelen;	scount = *scurrent++ * 256;	scount += *scurrent++;	sstart = scurrent;	INSIST(mcount > 0 && scount > 0);	/*	 * Yes, this is inefficient!	 */	/*	 * Start figuring out the target length and count.	 */	tlength = reservelen + 2;	tcount = 0;	rcount = 0;	/*	 * Add in the length of rdata in the mslab that aren't in	 * the sslab.	 */	do {		unsigned char *mrdatabegin = mcurrent;		rdata_from_slab(&mcurrent, rdclass, type, &mrdata);		scurrent = sstart;		for (count = 0; count < scount; count++) {			dns_rdata_reset(&srdata);			rdata_from_slab(&scurrent, rdclass, type, &srdata);			if (dns_rdata_compare(&mrdata, &srdata) == 0)				break;		}		if (count == scount) {			/*			 * This rdata isn't in the sslab, and thus isn't			 * being subtracted.			 */			tlength += mcurrent - mrdatabegin;			tcount++;		} else			rcount++;		mcount--;		dns_rdata_reset(&mrdata);	} while (mcount > 0);	/*	 * Check that all the records originally existed.  The numeric 	 * check only works as rdataslabs do not contain duplicates.	 */	if (((flags & DNS_RDATASLAB_EXACT) != 0) && (rcount != scount))		return (DNS_R_NOTEXACT);	/*	 * Don't continue if the new rdataslab would be empty.	 */	if (tcount == 0)		return (DNS_R_NXRRSET);	/*	 * If nothing is going to change, we can stop.	 */	if (rcount == 0)		return (DNS_R_UNCHANGED);	/*	 * Copy the reserved area from the mslab.	 */	tstart = isc_mem_get(mctx, tlength);	if (tstart == NULL)		return (ISC_R_NOMEMORY);	memcpy(tstart, mslab, reservelen);	tcurrent = tstart + reservelen;	/*	 * Write the new count.	 */	*tcurrent++ = (tcount & 0xff00) >> 8;	*tcurrent++ = (tcount & 0x00ff);	/*	 * Copy the parts of mslab not in sslab.	 */	mcurrent = mslab + reservelen;	mcount = *mcurrent++ * 256;	mcount += *mcurrent++;	do {		unsigned char *mrdatabegin = mcurrent;		rdata_from_slab(&mcurrent, rdclass, type, &mrdata);		scurrent = sstart;		for (count = 0; count < scount; count++) {			dns_rdata_reset(&srdata);			rdata_from_slab(&scurrent, rdclass, type, &srdata);			if (dns_rdata_compare(&mrdata, &srdata) == 0)				break;		}		if (count == scount) {			/*			 * This rdata isn't in the sslab, and thus should be			 * copied to the tslab.			 */			unsigned int length = mcurrent - mrdatabegin;			memcpy(tcurrent, mrdatabegin, length);			tcurrent += length;		}		dns_rdata_reset(&mrdata);		mcount--;	} while (mcount > 0);	INSIST(tcurrent == tstart + tlength);	*tslabp = tstart;	return (ISC_R_SUCCESS);}isc_boolean_tdns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,		    unsigned int reservelen){	unsigned char *current1, *current2;	unsigned int count1, count2;	unsigned int length1, length2;	current1 = slab1 + reservelen;	count1 = *current1++ * 256;	count1 += *current1++;	current2 = slab2 + reservelen;	count2 = *current2++ * 256;	count2 += *current2++;	if (count1 != count2)		return (ISC_FALSE);	while (count1 > 0) {		length1 = *current1++ * 256;		length1 += *current1++;		length2 = *current2++ * 256;		length2 += *current2++;		if (length1 != length2 ||		    memcmp(current1, current2, length1) != 0)			return (ISC_FALSE);		current1 += length1;		current2 += length1;		count1--;	}	return (ISC_TRUE);}isc_boolean_tdns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2,		     unsigned int reservelen, dns_rdataclass_t rdclass,		     dns_rdatatype_t type){	unsigned char *current1, *current2;	unsigned int count1, count2;	dns_rdata_t rdata1 = DNS_RDATA_INIT;	dns_rdata_t rdata2 = DNS_RDATA_INIT;	current1 = slab1 + reservelen;	count1 = *current1++ * 256;	count1 += *current1++;	current2 = slab2 + reservelen;	count2 = *current2++ * 256;	count2 += *current2++;	if (count1 != count2)		return (ISC_FALSE);	while (count1-- > 0) {		rdata_from_slab(&current1, rdclass, type, &rdata1);		rdata_from_slab(&current2, rdclass, type, &rdata2);		if (dns_rdata_compare(&rdata1, &rdata2) != 0)			return (ISC_FALSE);		dns_rdata_reset(&rdata1);		dns_rdata_reset(&rdata2);	}	return (ISC_TRUE);}

⌨️ 快捷键说明

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