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

📄 t_names.c

📁 package of develop dns
💻 C
📖 第 1 页 / 共 4 页
字号:
			cnt = bustline(p, Tokens);			if (cnt == 4) {				/*				 * test_name1, test_name2, test_origin,				 * downcase.				 */				result = test_dns_name_fromtext(Tokens[0],								Tokens[1],								Tokens[2],							   atoi(Tokens[3])								== 0 ?								ISC_FALSE :								ISC_TRUE);			} else {				t_info("bad format at line %d\n", line);			}			(void)free(p);			t_result(result);		}		(void)fclose(fp);	} else {		t_info("Missing datafile dns_name_fromtext\n");		t_result(result);	}}static const char *a41 =		"dns_name_totext(name, omit_final_dot, target) converts "		"the DNS name 'name' in wire format to textual format "		"at target, and adds a final '.' to the name if "		"omit_final_dot is false";static inttest_dns_name_totext(char *test_name, isc_boolean_t omit_final) {	int		result;	int		len;	int		order;	unsigned int	nlabels;	unsigned char	junk1[BUFLEN];	unsigned char	junk2[BUFLEN];	unsigned char	junk3[BUFLEN];	isc_buffer_t	buf1;	isc_buffer_t	buf2;	isc_buffer_t	buf3;	dns_name_t	dns_name1;	dns_name_t	dns_name2;	isc_result_t	dns_result;	dns_namereln_t	dns_namereln;	result = T_UNRESOLVED;	t_info("testing %s\n", test_name);	len = strlen(test_name);	isc_buffer_init(&buf1, test_name, len);	isc_buffer_add(&buf1, len);	dns_name_init(&dns_name1, NULL);	isc_buffer_init(&buf2, junk2, BUFLEN);	/*	 * Out of the data file to dns_name1.	 */	dns_result = dns_name_fromtext(&dns_name1, &buf1, NULL, ISC_FALSE,				       &buf2);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_name_fromtext failed, result == %s\n",		       dns_result_totext(dns_result));		return (T_UNRESOLVED);	}	/*	 * From dns_name1 into a text buffer.	 */	isc_buffer_invalidate(&buf1);	isc_buffer_init(&buf1, junk1, BUFLEN);	dns_result = dns_name_totext(&dns_name1, omit_final, &buf1);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_name_totext failed, result == %s\n",		       dns_result_totext(dns_result));		return (T_FAIL);	}	/*	 * From the text buffer into dns_name2.	 */	dns_name_init(&dns_name2, NULL);	isc_buffer_init(&buf3, junk3, BUFLEN);	dns_result = dns_name_fromtext(&dns_name2, &buf1, NULL, ISC_FALSE,				       &buf3);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_name_fromtext failed, result == %s\n",		       dns_result_totext(dns_result));		return (T_UNRESOLVED);	}	dns_namereln = dns_name_fullcompare(&dns_name1, &dns_name2,					    &order, &nlabels);	if (dns_namereln == dns_namereln_equal)		result = T_PASS;	else {		t_info("dns_name_fullcompare returned %s\n",		       dns_namereln_to_text(dns_namereln));		result = T_FAIL;	}	return (result);}static voidt_dns_name_totext(void) {	int		line;	int		cnt;	int		result;	char		*p;	FILE		*fp;	t_assert("dns_name_totext", 1, T_REQUIRED, a41);	result = T_UNRESOLVED;	fp = fopen("dns_name_totext_data", "r");	if (fp != NULL) {		line = 0;		while ((p = t_fgetbs(fp)) != NULL) {			++line;			/*			 * Skip comment lines.			 */			if ((isspace((unsigned char)*p)) || (*p == '#'))				continue;			cnt = bustline(p, Tokens);			if (cnt == 2) {				/*				 * test_name, omit_final.				 */				result = test_dns_name_totext(Tokens[0],							 atoi(Tokens[1]) == 0 ?							      ISC_FALSE :							      ISC_TRUE);			} else {				t_info("bad format at line %d\n", line);			}			(void)free(p);			t_result(result);		}		(void)fclose(fp);	} else {		t_info("Missing datafile dns_name_totext\n");		t_result(result);	}}static const char *a42 =		"dns_name_fromwire(name, source, dctx, downcase, target) "		"converts the possibly compressed DNS name 'name' in wire "		"format to canonicalized form at target, performing upper to "		"lower case conversion if downcase is true, and returns "		"ISC_R_SUCCESS";#if 0	/*	 * XXXRTH these tests appear to be broken, so I have	 * disabled them.	 */static const char *a43 =		"when a label length is invalid, dns_name_fromwire() "		"returns DNS_R_FORMERR";static const char *a44 =		"when a label type is invalid, dns_name_fromwire() "		"returns DNS_R_BADLABELTYPE";#endifstatic const char *a45 =		"when a name length is invalid, dns_name_fromwire() "		"returns DNS_R_FORMERR";static const char *a46 =		"when a compression type is invalid, dns_name_fromwire() "		"returns DNS_R_DISALLOWED";static const char *a47 =		"when a bad compression pointer is encountered, "		"dns_name_fromwire() returns DNS_R_BADPOINTER";static const char *a48 =		"when input ends unexpected, dns_name_fromwire() "		"returns ISC_R_UNEXPECTEDEND";static const char *a49 =		"when there are too many compression pointers, "		"dns_name_fromwire() returns DNS_R_TOOMANYHOPS";static const char *a50 =		"when there is not enough space in target, "		"dns_name_fromwire(name, source, dcts, downcase, target) "		"returns ISC_R_NOSPACE";static inttest_dns_name_fromwire(char *datafile_name, int testname_offset, int downcase,		       unsigned int dc_method, char *exp_name,		       isc_result_t exp_result, size_t buflen){	int			result;	int			order;	unsigned int		nlabels;	int			len;	unsigned char		buf1[BIGBUFLEN];	char			buf2[BUFLEN];	isc_buffer_t		iscbuf1;	isc_buffer_t		iscbuf2;	dns_name_t		dns_name1;	dns_name_t		dns_name2;	isc_result_t		dns_result;	dns_namereln_t		dns_namereln;	dns_decompress_t	dctx;	result = T_UNRESOLVED;	t_info("testing using %s\n", datafile_name);	len = getmsg(datafile_name, buf1, BIGBUFLEN, &iscbuf1);	isc_buffer_setactive(&iscbuf1, len);	iscbuf1.current = testname_offset;	isc_buffer_init(&iscbuf2, buf2, buflen);	dns_name_init(&dns_name1, NULL);	dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_STRICT);	dns_decompress_setmethods(&dctx, dc_method);	dns_result = dns_name_fromwire(&dns_name1, &iscbuf1,				       &dctx, downcase ? ISC_TRUE : ISC_FALSE,				       &iscbuf2);	if ((dns_result == exp_result) && (exp_result == ISC_R_SUCCESS)) {		dns_result = dname_from_tname(exp_name, &dns_name2);		if (dns_result == ISC_R_SUCCESS) {			dns_namereln = dns_name_fullcompare(&dns_name1,							    &dns_name2,							    &order, &nlabels);			if (dns_namereln != dns_namereln_equal) {				t_info("dns_name_fullcompare  returned %s\n",				       dns_namereln_to_text(dns_namereln));				result = T_FAIL;			} else {				result = T_PASS;			}		} else {			t_info("dns_name_fromtext %s failed, result = %s\n",			       exp_name, dns_result_totext(dns_result));			result = T_UNRESOLVED;		}	} else if (dns_result == exp_result) {		result = T_PASS;	} else {		t_info("dns_name_fromwire returned %s\n",		       dns_result_totext(dns_result));		result = T_FAIL;	}	return (result);}static voidt_dns_name_fromwire_x(const char *testfile, size_t buflen) {	int		line;	int		cnt;	int		result;	unsigned int	dc_method;	isc_result_t	exp_result;	char		*p;	char		*tok;	FILE		*fp;	result = T_UNRESOLVED;	fp = fopen(testfile, "r");	if (fp != NULL) {		line = 0;		while ((p = t_fgetbs(fp)) != NULL) {			++line;			/*			 * Skip comment lines.			 */			if ((isspace((unsigned char)*p)) || (*p == '#'))				continue;			cnt = bustline(p, Tokens);			if (cnt == 6) {				/*				 *	datafile_name, testname_offset,				 *	downcase, dc_method,				 *	exp_name, exp_result.				 */				tok = Tokens[5];				exp_result = ISC_R_SUCCESS;				if (! strcmp(tok, "ISC_R_SUCCESS"))					exp_result = ISC_R_SUCCESS;				else if (! strcmp(tok, "ISC_R_NOSPACE"))					exp_result = ISC_R_NOSPACE;				else if (! strcmp(tok, "DNS_R_BADLABELTYPE"))					exp_result = DNS_R_BADLABELTYPE;				else if (! strcmp(tok, "DNS_R_FORMERR"))					exp_result = DNS_R_FORMERR;				else if (! strcmp(tok, "DNS_R_BADPOINTER"))					exp_result = DNS_R_BADPOINTER;				else if (! strcmp(tok, "ISC_R_UNEXPECTEDEND"))					exp_result = ISC_R_UNEXPECTEDEND;				else if (! strcmp(tok, "DNS_R_TOOMANYHOPS"))					exp_result = DNS_R_TOOMANYHOPS;				else if (! strcmp(tok, "DNS_R_DISALLOWED"))					exp_result = DNS_R_DISALLOWED;				else if (! strcmp(tok, "DNS_R_NAMETOOLONG"))					exp_result = DNS_R_NAMETOOLONG;				tok = Tokens[3];				dc_method = DNS_COMPRESS_NONE;				if (! strcmp(tok, "DNS_COMPRESS_GLOBAL14"))					dc_method = DNS_COMPRESS_GLOBAL14;				else if (! strcmp(tok, "DNS_COMPRESS_ALL"))					dc_method = DNS_COMPRESS_ALL;				result = test_dns_name_fromwire(Tokens[0],							   atoi(Tokens[1]),							   atoi(Tokens[2]),								dc_method,								Tokens[4],								exp_result,								buflen);			} else {				t_info("bad format at line %d\n", line);			}			(void)free(p);			t_result(result);		}		(void)fclose(fp);	} else {		t_info("Missing datafile %s\n", testfile);		t_result(result);	}}static voidt_dns_name_fromwire(void) {	t_assert("dns_name_fromwire", 1, T_REQUIRED, a42);	t_dns_name_fromwire_x("dns_name_fromwire_1_data", BUFLEN);#if 0	/*	 * XXXRTH these tests appear to be broken, so I have	 * disabled them.	 */	t_assert("dns_name_fromwire", 2, T_REQUIRED, a43);	t_dns_name_fromwire_x("dns_name_fromwire_2_data", BUFLEN);	t_assert("dns_name_fromwire", 3, T_REQUIRED, a44);	t_dns_name_fromwire_x("dns_name_fromwire_3_data", BUFLEN);#endif	t_assert("dns_name_fromwire", 4, T_REQUIRED, a45);	t_dns_name_fromwire_x("dns_name_fromwire_4_data", BUFLEN);	t_assert("dns_name_fromwire", 5, T_REQUIRED, a46);	t_dns_name_fromwire_x("dns_name_fromwire_5_data", BUFLEN);	t_assert("dns_name_fromwire", 6, T_REQUIRED, a47);	t_dns_name_fromwire_x("dns_name_fromwire_6_data", BUFLEN);	t_assert("dns_name_fromwire", 7, T_REQUIRED, a48);	t_dns_name_fromwire_x("dns_name_fromwire_7_data", BUFLEN);	t_assert("dns_name_fromwire", 8, T_REQUIRED, a49);	t_dns_name_fromwire_x("dns_name_fromwire_8_data", BUFLEN);	t_assert("dns_name_fromwire", 9, T_REQUIRED, a50);	t_dns_name_fromwire_x("dns_name_fromwire_9_data", 2);}static const char *a51 =		"dns_name_towire(name, cctx, target) converts the DNS name "		"'name' into wire format, compresses it as specified "		"by the compression context cctx, stores the result in "		"target and returns DNS_SUCCESS";static const char *a52 =		"when not enough space exists in target, "		"dns_name_towire(name, cctx, target) returns ISC_R_NOSPACE";static inttest_dns_name_towire(char *testname, unsigned int dc_method, char *exp_data,		     int exp_data_len, isc_result_t exp_result, size_t buflen){	int			result;	int			val;	int			len;	unsigned char		buf2[BUFLEN];	unsigned char		buf3[BUFLEN];	isc_buffer_t		iscbuf1;	isc_buffer_t		iscbuf2;	isc_buffer_t		iscbuf3;	dns_name_t		dns_name;	isc_result_t		dns_result;	isc_result_t		isc_result;	dns_compress_t		cctx;	isc_mem_t		*mctx;	t_info("testing using %s\n", testname);	result = T_UNRESOLVED;	mctx = NULL;	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed\n");		return (result);	}	dns_compress_init(&cctx, -1, mctx);	dns_compress_setmethods(&cctx, dc_method);	dns_name_init(&dns_name, NULL);	len = strlen(testname);	isc_buffer_init(&iscbuf1, testname, len);	isc_buffer_add(&iscbuf1, len);	isc_buffer_init(&iscbuf2, buf2, BUFLEN);	dns_result = dns_name_fromtext(&dns_name, &iscbuf1, NULL, ISC_FALSE,				       &iscbuf2);	if (dns_result == ISC_R_SUCCESS) {		isc_buffer_init(&iscbuf3, buf3, buflen);		dns_result = dns_name_towire(&dns_name, &cctx, &iscbuf3);		if (dns_result == exp_result) {			if (exp_result == ISC_R_SUCCESS) {				/*				 * Compare results with expected data.				 */				val = chkdata(buf3, iscbuf3.used, exp_data,					      exp_data_len);				if (val == 0)					result = T_PASS;				else					result = T_FAIL;			} else				result = T_PASS;		} else {			t_info("dns_name_towire unexpectedly returned %s\n",			       dns_result_totext(dns_result));			result = T_FAIL;		}	} else {		t_info("dns_name_fromtext %s failed, result = %s\n",				testname, dns_result_totext(dns_result));	}	return (result);}static voidt_dns_name_towire_x(const char *testfile, size_t buflen) {	int		line;	int		cnt;	int		result;	unsigned int	dc_method;	isc_result_t	exp_result;	char		*p;	FILE		*fp;	result = T_UNRESOLVED;	fp = fopen(testfile, "r");	if (fp != NULL) {		line = 0;		while ((p = t_fgetbs(fp)) != NULL) {			++line;			/*			 * Skip comment lines.			 */			if ((isspace((unsigned char)*p)) || (*p == '#'))				continue;			cnt = bustline(p, Tokens);			if (cnt == 5) {				/*				 *	testname, dc_method,				 *	exp_data, exp_data_len,				 *	exp_result.				 */				dc_method = t_dc_method_fromtext(Tokens[3]);				exp_result = t_dns_result_fromtext(Tokens[4]);				result = test_dns_name_towire(Tokens[0],							      dc_method,							      Tokens[2],							      atoi(Tokens[3]),							      exp_result,							      buflen);			} else {				t_info("bad format at line %d\n", line);			}			(void)free(p);			t_result(result);		}		(void)fclose(fp);	} else {		t_info("Missing datafile %s\n", testfile);		t_result(result);	}}static voidt_dns_name_towire_1(void) {	t_assert("dns_name_towire", 1, T_REQUIRED, a51);	t_dns_name_towire_x("dns_name_towire_1_data", BUFLEN);}static voidt_dns_name_towire_2(void) {	t_assert("dns_name_towire", 2, T_REQUIRED, a52);	t_dns_name_towire_x("dns_name_towire_2_data", 2);}static voidt_dns_name_towire(void) {	t_dns_name_towire_1();	t_dns_name_towire_2();}#if 0 /* This is silly.  A test should either exist, or not, but not       * one that just returns "UNTESTED."       */static const char *a53 =		"dns_name_concatenate(prefix, suffix, name, target) "		"concatenates prefix and suffix, stores the result "		"in target, canonicalizes any bitstring labels "		"and returns ISC_R_SUCCESS";static voidt_dns_name_concatenate(void) {	t_assert("dns_name_concatenate", 1, T_REQUIRED, a53);	t_result(T_UNTESTED);}#endiftestspec_t T_testlist[] = {	{	t_dns_name_init,		"dns_name_init"		},	{	t_dns_name_invalidate,		"dns_name_invalidate"	},	{	t_dns_name_setbuffer,		"dns_name_setbuffer"	},	{	t_dns_name_hasbuffer,		"dns_name_hasbuffer"	},	{	t_dns_name_isabsolute,		"dns_name_isabsolute"	},	{	t_dns_name_hash,		"dns_name_hash"		},	{	t_dns_name_fullcompare,		"dns_name_fullcompare"	},	{	t_dns_name_compare,		"dns_name_compare"	},	{	t_dns_name_rdatacompare,	"dns_name_rdatacompare"	},	{	t_dns_name_issubdomain,		"dns_name_issubdomain"	},	{	t_dns_name_countlabels,		"dns_name_countlabels"	},	{	t_dns_name_getlabel,		"dns_name_getlabel"	},	{	t_dns_name_getlabelsequence,	"dns_name_getlabelsequence" },	{	t_dns_name_fromregion,		"dns_name_fromregion"	},	{	t_dns_name_toregion,		"dns_name_toregion"	},	{	t_dns_name_fromwire,		"dns_name_fromwire"	},	{	t_dns_name_towire,		"dns_name_towire"	},	{	t_dns_name_fromtext,		"dns_name_fromtext"	},	{	t_dns_name_totext,		"dns_name_totext"	},#if 0	{	t_dns_name_concatenate,		"dns_name_concatenate"	},#endif	{	NULL,				NULL			}};

⌨️ 快捷键说明

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