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

📄 xsupgui_request6.c

📁 linux 下通过802.1认证的安装包
💻 C
📖 第 1 页 / 共 3 页
字号:
	value = xmlNodeGetContent(n);

	if ((value == NULL) || (strlen(value) == 0))
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish;
	}

	numcerts = atoi(value);

	cas = (cert_enum *)Malloc((sizeof(cert_enum) * (numcerts+1)));
	if (cas == NULL)
	{
		done = IPC_ERROR_CANT_ALLOCATE_MEMORY;
		goto finish;
	}

	n = xsupgui_request_find_node(n, "Certificates");
	if (n == NULL)
	{
		free(cas);
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto finish;
	}

	n = n->children;

	for (i = 0; i < numcerts; i++)
	{
		t = xsupgui_request_find_node(n, "Certificate");
		if (t == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		t = t->children;

		b = xsupgui_request_find_node(t, "Store_Type");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].storetype = NULL;   // Which shouldn't EVER happen!
		}
		else
		{
			cas[i].storetype = value;
		}

		b = xsupgui_request_find_node(t, "Name");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].certname = NULL;
		}
		else
		{
			cas[i].certname = value;
		}

		b = xsupgui_request_find_node(t, "Friendly_Name");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].friendlyname = NULL;
		}
		else
		{
			cas[i].friendlyname = value;
		}

		b = xsupgui_request_find_node(t, "Issuer");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].issuer = NULL;
		}
		else
		{
			cas[i].issuer = value;
		}

		b = xsupgui_request_find_node(t, "CommonName");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].commonname = NULL;
		}
		else
		{
			cas[i].commonname = value;
		}

		b = xsupgui_request_find_node(t, "Location");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].location = NULL;
		}
		else
		{
			cas[i].location = value;
		}

		b = xsupgui_request_find_node(t, "Month");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].month = 0;
		}
		else
		{
			cas[i].month = atoi(value);
		}
		xmlFree(value);

		b = xsupgui_request_find_node(t, "Day");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].day = 0;
		}
		else
		{
			cas[i].day = atoi(value);
		}
		xmlFree(value);

		b = xsupgui_request_find_node(t, "Year");
		if (b == NULL)
		{
			free(cas);
			done = IPC_ERROR_BAD_RESPONSE_DATA;
			goto finish;
		}

		value = xmlNodeGetContent(b);

		if ((value == NULL) || (strlen(value) == 0))
		{
			cas[i].year = 0;
		}
		else
		{
			cas[i].year = atoi(value);
		}
		xmlFree(value);

		n = n->next;
	}

	(*casa) = cas;

finish:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}

/**
 * \brief Free the memory that was allocated to store the certificate enumeration.
 *
 * @param[in] numcas   The number of CAs that are represented in the enumeration.
 * @param[in] cas   The array of CA names.
 **/
void xsupgui_request_free_cert_enum(cert_enum **cas)
{
	cert_enum *casa = NULL;
	int i = 0;

	casa = (*cas);

	if (casa == NULL) return;

	while (casa[i].certname != NULL)
	{
		if (casa[i].certname != NULL) free(casa[i].certname);
		i++;
	}

	free((*cas));
	(*cas) = NULL;
}

/**
 * \brief Free all of the fields that are included in a cert_info structure.
 *
 * @param[in] cinfo   A pointer to the structure that we want to free the members of.
 **/
void xsupgui_request_free_cert_info(cert_info **incinfo)
{
	cert_info *cinfo = NULL;

	cinfo = (*incinfo);

	if (cinfo->C) free(cinfo->C);
	if (cinfo->CN) free(cinfo->CN);
	if (cinfo->O) free(cinfo->O);
	if (cinfo->L) free(cinfo->L);
	if (cinfo->OU) free(cinfo->OU);
	if (cinfo->S) free(cinfo->S);

	free((*incinfo));
}

/**
 * \brief Request the detailed information about a specific certificate.
 *
 * @param[in] storetype   The store type that we should be looking in.
 * 
 * @param[in] location   The location of the data in the store defined by the
 *                       storetype parameter.
 *
 * @param[in,out] cinfo   The structure that will contain the detailed 
 *                        information about the certificate.
 *
 * \retval REQUEST_FAILURE the request to the supplicant failed
 * \retval REQUEST_TIMEOUT the request timed out
 * \retval REQUEST_SUCCESS the request succeeded
 **/
int xsupgui_request_ca_certificate_info(char *storetype, char *location, cert_info **outcinfo)
{
	xmlDocPtr doc = NULL;
	xmlDocPtr retdoc = NULL;
	xmlNodePtr n = NULL, t = NULL;
	int err = 0;
	int done = REQUEST_SUCCESS;
	char *temp = NULL;
	cert_info *cinfo = NULL;

	(*outcinfo) = NULL;

	if ((storetype == NULL) || (location == NULL)) return IPC_ERROR_INVALID_PARAMETERS;

	doc = xsupgui_xml_common_build_msg();
	if (doc == NULL) return IPC_ERROR_CANT_CREATE_REQ_HDR;

	n = xmlDocGetRootElement(doc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_REQ_ROOT_NODE;
		goto done;
	}

	t = xmlNewChild(n, NULL, "Get_Certificate_Info", NULL);
	if (t == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		goto done;
	}

	xsupgui_xml_common_convert_amp(storetype, &temp);
	if (xmlNewChild(t, NULL, "Store_Type", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto done;
	}
	free(temp);

	xsupgui_xml_common_convert_amp(location, &temp);
	if (xmlNewChild(t, NULL, "Location", temp) == NULL)
	{
		done = IPC_ERROR_CANT_CREATE_REQUEST;
		free(temp);
		goto done;
	}
	free(temp);

	err = xsupgui_request_send(doc, &retdoc);
	if (err != REQUEST_SUCCESS)
	{
		done = err;
		goto done;
	}

	// Otherwise, parse it and see if we got what we wanted.

	// Check if we got errors.
	err = xsupgui_request_check_exceptions(retdoc);
	if (err != 0) 
	{
		done = err;
		goto done;
	}

	n = xmlDocGetRootElement(retdoc);
	if (n == NULL)
	{
		done = IPC_ERROR_CANT_FIND_RESP_ROOT_NODE;
		goto done;
	}

	n = xsupgui_request_find_node(n->children, "Certificate_Info");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE;
		goto done;
	}

	n = xsupgui_request_find_node(n->children, "Certificate");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	n = n->children;

	n = xsupgui_request_find_node(n, "O");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo = (cert_info *)malloc(sizeof(cert_info));
	if (cinfo == NULL)
	{
		done = IPC_ERROR_MALLOC;
		goto done;
	}

	cinfo->O = xmlNodeGetContent(n);

	n = xsupgui_request_find_node(n, "OU");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo->OU = xmlNodeGetContent(n);

	n = xsupgui_request_find_node(n, "S");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo->S = xmlNodeGetContent(n);

	n = xsupgui_request_find_node(n, "C");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo->C = xmlNodeGetContent(n);

	n = xsupgui_request_find_node(n, "CN");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo->CN = xmlNodeGetContent(n);

	n = xsupgui_request_find_node(n, "L");
	if (n == NULL)
	{
		done = IPC_ERROR_BAD_RESPONSE_DATA;
		goto done;
	}

	cinfo->L = xmlNodeGetContent(n);

	(*outcinfo) = cinfo;

done:
	xmlFreeDoc(doc);
	xmlFreeDoc(retdoc);

	return done;
}



⌨️ 快捷键说明

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