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

📄 checkheaders.cpp

📁 基于widcomm的蓝牙传输功能程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		{
			if (wcslen(val_description) + 1 != length)
				return ("FAIL description length verify");
			p_array = (WCHAR *)malloc((length+1)*sizeof(WCHAR));
			if (!hdrs.GetDescription(p_array))
				return ("FAIL description present verify");
			if (wcsncmp(val_description, p_array, wcslen(val_description)))
			{
				free (p_array);
				return ("FAIL description verify");
			}
			free (p_array);
		}
		else
			return ("FAIL description present");
	}

	// target header
	{
		int ii;
		UINT32 length_out = 0;
		BOOL failed = FALSE;
		UINT8 *p_val_out = NULL;
		UINT8 *p_val_in = NULL;
		char err_msg[256];

		for (ii = 0; ii < OBEX_MAX_TARGET; ii++)
		{
			if (!hdrs.GetTargetLength(&length_out, ii))
			{
				sprintf(err_msg, "FAIL target %d should exist", ii + 1);
				failed = TRUE;
				break;
			}

			p_val_out = (UINT8 *)malloc (length_out);
			if (p_val_out == NULL)
			{
				sprintf(err_msg, "FAIL GetTarget %d malloc fail in verify ", ii + 1);
				failed = TRUE;
				break;
			}

			// fetch the value for the current index
			if ( !hdrs.GetTarget(p_val_out, ii))
			{
				sprintf(err_msg, "FAIL GetTarget %d", ii + 1);
				failed = TRUE;
				break;
			}
			
			// build expected value the same as when added
			p_val_in = (UINT8 *)malloc (val_target_base_len + OBEX_MAX_TARGET + 1);
			if (p_val_in == NULL)
			{
				sprintf(err_msg, "FAIL GetTarget %d malloc in compare", ii + 1);
				failed = TRUE;
				break;
			}

			strcpy((char *)p_val_in, val_target_base);
			UINT8 suffix[2];
			sprintf((char *)suffix,"%d", ii + 1);	// suffix shows which element 

			// make each target different value and length
			for (int jj = 0; jj < ii + 1; jj++)
				strcat((char *)p_val_in, (char *)suffix);

			// they should match in length and content, fail if not
			if (length_out != strlen((char *)p_val_in))
			{
				sprintf(err_msg, "FAIL target %d length in compare", ii + 1);
				failed = TRUE;
				break;
			}

			if (strncmp((char *)p_val_in, (char *)p_val_out, length_out) != 0)
			{
				sprintf(err_msg, "FAIL target %d match in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// free malloced arrays
			if (p_val_in != NULL)
			{
				free (p_val_in);
				p_val_in = NULL;
			}
			if (p_val_out != NULL)
			{
				free (p_val_out);
				p_val_out = NULL;
			}
		}

		// free malloced arrays
		if (p_val_in != NULL)
			free (p_val_in);
		if (p_val_out != NULL)
			free (p_val_out);

		if (failed)
			return (err_msg);
	}

	// http header
	{
		int ii;
		UINT32 length_out = 0;
		BOOL failed = FALSE;
		UINT8 *p_val_out = NULL;
		UINT8 *p_val_in = NULL;
		char err_msg[256];

		for (ii = 0; ii < OBEX_MAX_HTTP; ii++)
		{
			if (!hdrs.GetHttpLength(&length_out, ii))
			{
				sprintf(err_msg, "FAIL http %d should exist", ii + 1);
				failed = TRUE;
				break;
			}

			p_val_out = (UINT8 *)malloc (length_out);
			if (p_val_out == NULL)
			{
				sprintf(err_msg, "FAIL GetHttp %d malloc fail in verify ", ii + 1);
				failed = TRUE;
				break;
			}

			// fetch the value for the current index
			if ( !hdrs.GetHttp(p_val_out, ii))
			{
				sprintf(err_msg, "FAIL GetHttp %d", ii + 1);
				failed = TRUE;
				break;
			}
			
			// build expected value the same as when added
			p_val_in = (UINT8 *)malloc (val_http_base_len + OBEX_MAX_HTTP + 1);
			if (p_val_in == NULL)
			{
				sprintf(err_msg, "FAIL GetHttp %d malloc in compare", ii + 1);
				failed = TRUE;
				break;
			}

			strcpy((char *)p_val_in, val_http_base);
			UINT8 suffix[2];
			sprintf((char *)suffix,"%d", ii + 1);	// suffix shows which element 

			// make each http different value and length
			for (int jj = 0; jj < ii + 1; jj++)
				strcat((char *)p_val_in, (char *)suffix);

			// they should match in length and content, fail if not
			if (length_out != strlen((char *)p_val_in))
			{
				sprintf(err_msg, "FAIL http %d length in compare", ii + 1);
				failed = TRUE;
				break;
			}

			if (strncmp((char *)p_val_in, (char *)p_val_out, length_out) != 0)
			{
				sprintf(err_msg, "FAIL http %d match in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// free malloced arrays
			if (p_val_in != NULL)
			{
				free (p_val_in);
				p_val_in = NULL;
			}
			if (p_val_out != NULL)
			{
				free (p_val_out);
				p_val_out = NULL;
			}
		}

		// free malloced arrays
		if (p_val_in != NULL)
			free (p_val_in);
		if (p_val_out != NULL)
			free (p_val_out);

		if (failed)
			return (err_msg);
	}

	// body header
	{	unsigned char *p_octets = NULL;
		UINT32 length = 0;

		if (hdrs.GetBodyLength(&length))
		{
			BOOL body_end_out;
			if (sizeof(val_body) != length)
				return ("FAIL body length verify");
			p_octets = (unsigned char *)malloc(length);
			if (!hdrs.GetBody(p_octets, &body_end_out))
			{
				free (p_octets);
				return ("FAIL body present verify");
			}
			if (val_body_end != body_end_out)
			{
				free (p_octets);
				return ("FAIL body end flag verify");
			}
			if (memcmp(val_body, p_octets, sizeof(val_body)))
			{
				free (p_octets);
				return ("FAIL body verify");
			}
			free (p_octets);
		}
		else
			return ("FAIL body present");
	}
	
	// who header
	{	unsigned char *p_octets = NULL;
		UINT32 length = 0;
		if (hdrs.GetWhoLength(&length))
		{
			if (sizeof(val_who) != length)
				return ("FAIL who length verify");
			p_octets = (unsigned char *)malloc(length);
			if (!hdrs.GetWho(p_octets))
				return ("FAIL who present verify");
			if (memcmp(val_who, p_octets, sizeof(val_who)))
			{
				free (p_octets);
				return ("FAIL who verify");
			}
			free (p_octets);
		}
		else
			return ("FAIL who present");
	}

	// app param header
	{
		int ii;
		UINT8 length_out = 0;
		BOOL failed = FALSE;
		UINT8 *p_val_out = NULL;
		UINT8 *p_val_in = NULL;
		UINT8 tag;
		char err_msg[256];

		for (ii = 0; ii < OBEX_MAX_APP_PARAM; ii++)
		{
			if (!hdrs.GetAppParamLength(&length_out, ii))
			{
				sprintf(err_msg, "FAIL app param %d should exist", ii + 1);
				failed = TRUE;
				break;
			}

			p_val_out = (UINT8 *)malloc (length_out);
			if (p_val_out == NULL)
			{
				sprintf(err_msg, "FAIL GetAppParam %d malloc fail in verify ", ii + 1);
				failed = TRUE;
				break;
			}

			// fetch the value for the current index
			if ( !hdrs.GetAppParam(&tag, p_val_out, ii))
			{
				sprintf(err_msg, "FAIL GetAppParam %d", ii + 1);
				failed = TRUE;
				break;
			}

			// build expected value the same as when added
			p_val_in = (UINT8 *)malloc (val_app_param_base_len + OBEX_MAX_APP_PARAM + 1);
			if (p_val_in == NULL)
			{
				sprintf(err_msg, "FAIL GetAppParam %d malloc in compare", ii + 1);
				failed = TRUE;
				break;
			}

			strcpy((char *)p_val_in, val_app_param_base);
			UINT8 suffix[2];
			sprintf((char *)suffix,"%d", ii + 1);	// suffix shows which element 

			// make each http different value and length and each tag value different
			for (int jj = 0; jj < ii + 1; jj++)
				strcat((char *)p_val_in, (char *)suffix);

			// verify tag value; each is different
			if (tag != val_app_param_tag_base + ii)
			{
				sprintf(err_msg, "FAIL GetAppParam %d tag in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// they should match in length and content, fail if not
			if (length_out != strlen((char *)p_val_in))
			{
				sprintf(err_msg, "FAIL app param %d length in compare", ii + 1);
				failed = TRUE;
				break;
			}

			if (strncmp((char *)p_val_in, (char *)p_val_out, length_out) != 0)
			{
				sprintf(err_msg, "FAIL app param %d match in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// free malloced arrays
			if (p_val_in != NULL)
			{
				free (p_val_in);
				p_val_in = NULL;
			}
			if (p_val_out != NULL)
			{
				free (p_val_out);
				p_val_out = NULL;
			}
		}

		// free malloced arrays
		if (p_val_in != NULL)
			free (p_val_in);
		if (p_val_out != NULL)
			free (p_val_out);

		if (failed)
			return (err_msg);
	}

	// auth challenge header
	{
		int ii;
		UINT8 length_out = 0;
		BOOL failed = FALSE;
		UINT8 *p_val_out = NULL;
		UINT8 *p_val_in = NULL;
		UINT8 tag;
		char err_msg[256];

		for (ii = 0; ii < OBEX_MAX_AUTH_CHALLENGE; ii++)
		{
			if (!hdrs.GetAuthChallengeLength(&length_out, ii))
			{
				sprintf(err_msg, "FAIL auth challenge %d should exist", ii + 1);
				failed = TRUE;
				break;
			}

			p_val_out = (UINT8 *)malloc (length_out);
			if (p_val_out == NULL)
			{
				sprintf(err_msg, "FAIL GetAuthChallenge %d malloc fail in verify ", ii + 1);
				failed = TRUE;
				break;
			}

			// fetch the value for the current index
			if ( !hdrs.GetAuthChallenge(&tag, p_val_out, ii))
			{
				sprintf(err_msg, "FAIL GetAuthChallenge %d", ii + 1);
				failed = TRUE;
				break;
			}

			// build expected value the same as when added
			p_val_in = (UINT8 *)malloc (val_auth_challenge_base_len + OBEX_MAX_AUTH_CHALLENGE + 1);
			if (p_val_in == NULL)
			{
				sprintf(err_msg, "FAIL GetAuthChallenge %d malloc in compare", ii + 1);
				failed = TRUE;
				break;
			}

			strcpy((char *)p_val_in, val_auth_challenge_base);
			UINT8 suffix[2];
			sprintf((char *)suffix,"%d", ii + 1);	// suffix shows which element 

			// make each http different value and length and each tag value different
			for (int jj = 0; jj < ii + 1; jj++)
				strcat((char *)p_val_in, (char *)suffix);

			// verify tag value; each is different
			if (tag != val_auth_challenge_tag_base + ii)
			{
				sprintf(err_msg, "FAIL GetAuthChallenge %d tag in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// they should match in length and content, fail if not
			if (length_out != strlen((char *)p_val_in))
			{
				sprintf(err_msg, "FAIL auth challenge %d length in compare", ii + 1);
				failed = TRUE;
				break;
			}

			if (strncmp((char *)p_val_in, (char *)p_val_out, length_out) != 0)
			{
				sprintf(err_msg, "FAIL auth challenge %d match in compare", ii + 1);
				failed = TRUE;
				break;
			}

			// free malloced arrays
			if (p_val_in != NULL)
			{
				free (p_val_in);
				p_val_in = NULL;
			}
			if (p_val_out != NULL)
			{
				free (p_val_out);
				p_val_out = NULL;
			}
		}

		// free malloced arrays
		if (p_val_in != NULL)
			free (p_val_in);
		if (p_val_out != NULL)
			free (p_val_out);

		if (failed)
			return (err_msg);
	}

⌨️ 快捷键说明

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